@php-wasm/web 0.1.61 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.htaccess +0 -4
  2. package/README.md +4 -0
  3. package/index.d.ts +15 -19
  4. package/index.js +393 -371
  5. package/kitchen-sink/php_5_6.js +85 -0
  6. package/kitchen-sink/php_5_6.wasm +0 -0
  7. package/kitchen-sink/php_7_0.js +85 -0
  8. package/kitchen-sink/php_7_0.wasm +0 -0
  9. package/kitchen-sink/php_7_1.js +85 -0
  10. package/kitchen-sink/php_7_1.wasm +0 -0
  11. package/kitchen-sink/php_7_2.js +85 -0
  12. package/kitchen-sink/php_7_2.wasm +0 -0
  13. package/kitchen-sink/php_7_3.js +85 -0
  14. package/kitchen-sink/php_7_3.wasm +0 -0
  15. package/kitchen-sink/php_7_4.js +85 -0
  16. package/kitchen-sink/php_7_4.wasm +0 -0
  17. package/kitchen-sink/php_8_0.js +85 -0
  18. package/kitchen-sink/php_8_0.wasm +0 -0
  19. package/kitchen-sink/php_8_1.js +85 -0
  20. package/kitchen-sink/php_8_1.wasm +0 -0
  21. package/kitchen-sink/php_8_2.js +85 -0
  22. package/kitchen-sink/php_8_2.wasm +0 -0
  23. package/lib/worker-thread/spawn-php-worker-thread.d.ts +1 -9
  24. package/{php_5_6.js → light/php_5_6.js} +15 -1
  25. package/{php_5_6.wasm → light/php_5_6.wasm} +0 -0
  26. package/{php_7_0.js → light/php_7_0.js} +15 -1
  27. package/{php_7_0.wasm → light/php_7_0.wasm} +0 -0
  28. package/{php_7_1.js → light/php_7_1.js} +15 -1
  29. package/{php_7_1.wasm → light/php_7_1.wasm} +0 -0
  30. package/{php_7_2.js → light/php_7_2.js} +15 -1
  31. package/{php_7_2.wasm → light/php_7_2.wasm} +0 -0
  32. package/{php_7_3.js → light/php_7_3.js} +15 -1
  33. package/{php_7_3.wasm → light/php_7_3.wasm} +0 -0
  34. package/{php_7_4.js → light/php_7_4.js} +16 -2
  35. package/{php_7_4.wasm → light/php_7_4.wasm} +0 -0
  36. package/{php_8_0.js → light/php_8_0.js} +16 -2
  37. package/{php_8_0.wasm → light/php_8_0.wasm} +0 -0
  38. package/{php_8_1.js → light/php_8_1.js} +16 -2
  39. package/{php_8_1.wasm → light/php_8_1.wasm} +0 -0
  40. package/{php_8_2.js → light/php_8_2.js} +15 -1
  41. package/{php_8_2.wasm → light/php_8_2.wasm} +0 -0
  42. package/package.json +6 -2
  43. package/lib/worker-thread/parse-startup-options.d.ts +0 -1
package/index.js CHANGED
@@ -19,8 +19,11 @@ class I extends Event {
19
19
  }
20
20
  Object.defineProperty(I.prototype, "error", { enumerable: !0 });
21
21
  Object.defineProperty(I.prototype, "message", { enumerable: !0 });
22
- const ie = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : I;
23
- class oe extends EventTarget {
22
+ const oe = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : I;
23
+ function ae(t) {
24
+ return t instanceof Error ? "exitCode" in t && t?.exitCode === 0 || t?.name === "ExitStatus" && "status" in t && t.status === 0 : !1;
25
+ }
26
+ class ce extends EventTarget {
24
27
  constructor() {
25
28
  super(...arguments), this.listenersCount = 0;
26
29
  }
@@ -34,62 +37,62 @@ class oe extends EventTarget {
34
37
  return this.listenersCount > 0;
35
38
  }
36
39
  }
37
- function ae(t) {
40
+ function le(t) {
38
41
  t.asm = {
39
42
  ...t.asm
40
43
  };
41
- const e = new oe();
44
+ const e = new ce();
42
45
  for (const r in t.asm)
43
46
  if (typeof t.asm[r] == "function") {
44
47
  const n = t.asm[r];
45
48
  t.asm[r] = function(...s) {
46
49
  try {
47
50
  return n(...s);
48
- } catch (o) {
49
- if (!(o instanceof Error))
50
- throw o;
51
- if ("exitCode" in o && o?.exitCode === 0)
52
- return;
53
- const i = le(
54
- o,
51
+ } catch (i) {
52
+ if (!(i instanceof Error))
53
+ throw i;
54
+ const o = he(
55
+ i,
55
56
  t.lastAsyncifyStackSource?.stack
56
57
  );
57
- if (t.lastAsyncifyStackSource && (o.cause = t.lastAsyncifyStackSource), !e.hasListeners())
58
- throw de(i), o;
59
- e.dispatchEvent(
60
- new ie("error", {
61
- error: o,
62
- message: i
63
- })
64
- );
58
+ if (t.lastAsyncifyStackSource && (i.cause = t.lastAsyncifyStackSource), e.hasListeners()) {
59
+ e.dispatchEvent(
60
+ new oe("error", {
61
+ error: i,
62
+ message: o
63
+ })
64
+ );
65
+ return;
66
+ }
67
+ throw ae(i) || pe(o), i;
65
68
  }
66
69
  };
67
70
  }
68
71
  return e;
69
72
  }
70
- let M = [];
71
- function ce() {
72
- return M;
73
+ let A = [];
74
+ function ue() {
75
+ return A;
73
76
  }
74
- function le(t, e) {
77
+ function he(t, e) {
75
78
  if (t.message === "unreachable") {
76
- let r = ue;
79
+ let r = de;
77
80
  e || (r += `
78
81
 
79
82
  This stack trace is lacking. For a better one initialize
80
83
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
81
84
 
82
- `), M = fe(
85
+ `), A = me(
83
86
  e || t.stack || ""
84
87
  );
85
- for (const n of M)
88
+ for (const n of A)
86
89
  r += ` * ${n}
87
90
  `;
88
91
  return r;
89
92
  }
90
93
  return t.message;
91
94
  }
92
- const ue = `
95
+ const de = `
93
96
  "unreachable" WASM instruction executed.
94
97
 
95
98
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -113,20 +116,20 @@ the Dockerfile, you'll need to trigger this error again with long stack
113
116
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
114
117
  CLI option:
115
118
 
116
- `, D = "\x1B[41m", he = "\x1B[1m", q = "\x1B[0m", z = "\x1B[K";
119
+ `, D = "\x1B[41m", fe = "\x1B[1m", q = "\x1B[0m", z = "\x1B[K";
117
120
  let B = !1;
118
- function de(t) {
121
+ function pe(t) {
119
122
  if (!B) {
120
123
  B = !0, console.log(`${D}
121
124
  ${z}
122
- ${he} WASM ERROR${q}${D}`);
125
+ ${fe} WASM ERROR${q}${D}`);
123
126
  for (const e of t.split(`
124
127
  `))
125
128
  console.log(`${z} ${e} `);
126
129
  console.log(`${q}`);
127
130
  }
128
131
  }
129
- function fe(t) {
132
+ function me(t) {
130
133
  try {
131
134
  const e = t.split(`
132
135
  `).slice(1).map((r) => {
@@ -144,8 +147,8 @@ function fe(t) {
144
147
  }
145
148
  }
146
149
  class b {
147
- constructor(e, r, n, s = "", o = 0) {
148
- this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = o, this.errors = s;
150
+ constructor(e, r, n, s = "", i = 0) {
151
+ this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = i, this.errors = s;
149
152
  }
150
153
  static fromRawData(e) {
151
154
  return new b(
@@ -178,7 +181,7 @@ class b {
178
181
  return new TextDecoder().decode(this.bytes);
179
182
  }
180
183
  }
181
- const pe = [
184
+ const ge = [
182
185
  "8.2",
183
186
  "8.1",
184
187
  "8.0",
@@ -188,8 +191,8 @@ const pe = [
188
191
  "7.1",
189
192
  "7.0",
190
193
  "5.6"
191
- ], me = pe[0];
192
- class ge {
194
+ ], ye = ge[0];
195
+ class we {
193
196
  #e;
194
197
  #t;
195
198
  /**
@@ -262,8 +265,8 @@ class ge {
262
265
  try {
263
266
  if (!r.includes("="))
264
267
  continue;
265
- const n = r.indexOf("="), s = r.substring(0, n), o = r.substring(n + 1).split(";")[0];
266
- this.#e[s] = o;
268
+ const n = r.indexOf("="), s = r.substring(0, n), i = r.substring(n + 1).split(";")[0];
269
+ this.#e[s] = i;
267
270
  } catch (n) {
268
271
  console.error(n);
269
272
  }
@@ -275,7 +278,7 @@ class ge {
275
278
  return e.join("; ");
276
279
  }
277
280
  }
278
- class ye {
281
+ class Pe {
279
282
  constructor({ concurrency: e }) {
280
283
  this._running = 0, this.concurrency = e, this.queue = [];
281
284
  }
@@ -303,17 +306,17 @@ class ye {
303
306
  }
304
307
  }
305
308
  }
306
- const we = "http://example.com";
309
+ const be = "http://example.com";
307
310
  function j(t) {
308
311
  return t.toString().substring(t.origin.length);
309
312
  }
310
313
  function G(t, e) {
311
314
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
312
315
  }
313
- function Pe(t, e) {
316
+ function Ee(t, e) {
314
317
  return !e || t.startsWith(e) ? t : e + t;
315
318
  }
316
- class be {
319
+ class ke {
317
320
  #e;
318
321
  #t;
319
322
  #n;
@@ -322,25 +325,23 @@ class be {
322
325
  #s;
323
326
  #o;
324
327
  #a;
325
- #c;
326
328
  /**
327
329
  * @param php - The PHP instance.
328
330
  * @param config - Request Handler configuration.
329
331
  */
330
332
  constructor(e, r = {}) {
331
- this.#a = new ye({ concurrency: 1 });
333
+ this.#a = new Pe({ concurrency: 1 });
332
334
  const {
333
335
  documentRoot: n = "/www/",
334
- absoluteUrl: s = typeof location == "object" ? location?.href : "",
335
- isStaticFilePath: o = () => !1
336
+ absoluteUrl: s = typeof location == "object" ? location?.href : ""
336
337
  } = r;
337
- this.php = e, this.#e = n, this.#c = o;
338
+ this.php = e, this.#e = n;
338
339
  const i = new URL(s);
339
340
  this.#n = i.hostname, this.#r = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
340
- const a = this.#r !== 443 && this.#r !== 80;
341
+ const o = this.#r !== 443 && this.#r !== 80;
341
342
  this.#i = [
342
343
  this.#n,
343
- a ? `:${this.#r}` : ""
344
+ o ? `:${this.#r}` : ""
344
345
  ].join(""), this.#s = i.pathname.replace(/\/+$/, ""), this.#o = [
345
346
  `${this.#t}://`,
346
347
  this.#i,
@@ -371,40 +372,43 @@ class be {
371
372
  async request(e) {
372
373
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL(
373
374
  e.url,
374
- r ? void 0 : we
375
+ r ? void 0 : be
375
376
  ), s = G(
376
377
  n.pathname,
377
378
  this.#s
378
- );
379
- return this.#c(s) ? this.#l(s) : await this.#u(e, n);
379
+ ), i = `${this.#e}${s}`;
380
+ return xe(i) ? await this.#l(e, n) : this.#c(i);
380
381
  }
381
382
  /**
382
383
  * Serves a static file from the PHP filesystem.
383
384
  *
384
- * @param path - The requested static file path.
385
+ * @param fsPath - Absolute path of the static file to serve.
385
386
  * @returns The response.
386
387
  */
387
- #l(e) {
388
- const r = `${this.#e}${e}`;
389
- if (!this.php.fileExists(r))
388
+ #c(e) {
389
+ if (!this.php.fileExists(e))
390
390
  return new b(
391
391
  404,
392
- {},
392
+ // Let the service worker know that no static file was found
393
+ // and that it's okay to issue a real fetch() to the server.
394
+ {
395
+ "x-file-type": ["static"]
396
+ },
393
397
  new TextEncoder().encode("404 File not found")
394
398
  );
395
- const n = this.php.readFileAsBuffer(r);
399
+ const r = this.php.readFileAsBuffer(e);
396
400
  return new b(
397
401
  200,
398
402
  {
399
- "content-length": [`${n.byteLength}`],
403
+ "content-length": [`${r.byteLength}`],
400
404
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
401
405
  // The code below won't return the correct mime-type if the extension
402
406
  // was tampered with.
403
- "content-type": [ve(r)],
407
+ "content-type": [ve(e)],
404
408
  "accept-ranges": ["bytes"],
405
409
  "cache-control": ["public, max-age=0"]
406
410
  },
407
- n
411
+ r
408
412
  );
409
413
  }
410
414
  /**
@@ -414,7 +418,7 @@ class be {
414
418
  * @param request - The request.
415
419
  * @returns The response.
416
420
  */
417
- async #u(e, r) {
421
+ async #l(e, r) {
418
422
  const n = await this.#a.acquire();
419
423
  try {
420
424
  this.php.addServerGlobalEntry("DOCUMENT_ROOT", this.#e), this.php.addServerGlobalEntry(
@@ -422,32 +426,32 @@ class be {
422
426
  this.#o.startsWith("https://") ? "on" : ""
423
427
  );
424
428
  let s = "GET";
425
- const o = {
429
+ const i = {
426
430
  host: this.#i,
427
- ...K(e.headers || {})
428
- }, i = [];
431
+ ...Q(e.headers || {})
432
+ }, o = [];
429
433
  if (e.files && Object.keys(e.files).length) {
430
434
  s = "POST";
431
- for (const l in e.files) {
432
- const h = e.files[l];
433
- i.push({
434
- key: l,
435
+ for (const a in e.files) {
436
+ const h = e.files[a];
437
+ o.push({
438
+ key: a,
435
439
  name: h.name,
436
440
  type: h.type,
437
441
  data: new Uint8Array(await h.arrayBuffer())
438
442
  });
439
443
  }
440
- o["content-type"]?.startsWith("multipart/form-data") && (e.formData = Ee(
444
+ i["content-type"]?.startsWith("multipart/form-data") && (e.formData = Re(
441
445
  e.body || ""
442
- ), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);
446
+ ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
443
447
  }
444
- let a;
445
- e.formData !== void 0 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
446
- e.formData
447
- ).toString()) : a = e.body;
448
448
  let c;
449
+ e.formData !== void 0 ? (s = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", c = new URLSearchParams(
450
+ e.formData
451
+ ).toString()) : c = e.body;
452
+ let l;
449
453
  try {
450
- c = this.#h(r.pathname);
454
+ l = this.#u(r.pathname);
451
455
  } catch {
452
456
  return new b(
453
457
  404,
@@ -456,16 +460,16 @@ class be {
456
460
  );
457
461
  }
458
462
  return await this.php.run({
459
- relativeUri: Pe(
463
+ relativeUri: Ee(
460
464
  j(r),
461
465
  this.#s
462
466
  ),
463
467
  protocol: this.#t,
464
468
  method: e.method || s,
465
- body: a,
466
- fileInfos: i,
467
- scriptPath: c,
468
- headers: o
469
+ body: c,
470
+ fileInfos: o,
471
+ scriptPath: l,
472
+ headers: i
469
473
  });
470
474
  } finally {
471
475
  n();
@@ -480,7 +484,7 @@ class be {
480
484
  * @throws {Error} If the requested path doesn't exist.
481
485
  * @returns The resolved filesystem path.
482
486
  */
483
- #h(e) {
487
+ #u(e) {
484
488
  let r = G(e, this.#s);
485
489
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
486
490
  const n = `${this.#e}${r}`;
@@ -491,18 +495,18 @@ class be {
491
495
  return `${this.#e}/index.php`;
492
496
  }
493
497
  }
494
- function Ee(t) {
498
+ function Re(t) {
495
499
  const e = {}, r = t.match(/--(.*)\r\n/);
496
500
  if (!r)
497
501
  return e;
498
502
  const n = r[1], s = t.split(`--${n}`);
499
- return s.shift(), s.pop(), s.forEach((o) => {
500
- const i = o.indexOf(`\r
503
+ return s.shift(), s.pop(), s.forEach((i) => {
504
+ const o = i.indexOf(`\r
501
505
  \r
502
- `), a = o.substring(0, i).trim(), c = o.substring(i + 4).trim(), l = a.match(/name="([^"]+)"/);
503
- if (l) {
504
- const h = l[1];
505
- e[h] = c;
506
+ `), c = i.substring(0, o).trim(), l = i.substring(o + 4).trim(), a = c.match(/name="([^"]+)"/);
507
+ if (a) {
508
+ const h = a[1];
509
+ e[h] = l;
506
510
  }
507
511
  }), e;
508
512
  }
@@ -546,6 +550,15 @@ function ve(t) {
546
550
  return "application-octet-stream";
547
551
  }
548
552
  }
553
+ function xe(t) {
554
+ return Se(t) || Te(t);
555
+ }
556
+ function Se(t) {
557
+ return t.endsWith(".php") || t.includes(".php/");
558
+ }
559
+ function Te(t) {
560
+ return !t.split("/").pop().includes(".");
561
+ }
549
562
  const V = {
550
563
  0: "No error occurred. System call completed successfully.",
551
564
  1: "Argument list too long.",
@@ -627,62 +640,64 @@ const V = {
627
640
  };
628
641
  function y(t = "") {
629
642
  return function(r, n, s) {
630
- const o = s.value;
631
- s.value = function(...i) {
643
+ const i = s.value;
644
+ s.value = function(...o) {
632
645
  try {
633
- return o.apply(this, i);
634
- } catch (a) {
635
- const c = typeof a == "object" ? a?.errno : null;
636
- if (c in V) {
637
- const l = V[c], h = typeof i[0] == "string" ? i[0] : null, g = h !== null ? t.replaceAll("{path}", h) : t;
638
- throw new Error(`${g}: ${l}`, {
639
- cause: a
646
+ return i.apply(this, o);
647
+ } catch (c) {
648
+ const l = typeof c == "object" ? c?.errno : null;
649
+ if (l in V) {
650
+ const a = V[l], h = typeof o[0] == "string" ? o[0] : null, g = h !== null ? t.replaceAll("{path}", h) : t;
651
+ throw new Error(`${g}: ${a}`, {
652
+ cause: c
640
653
  });
641
654
  }
642
- throw a;
655
+ throw c;
643
656
  }
644
657
  };
645
658
  };
646
659
  }
647
- async function Re(t, e = {}, r = []) {
648
- let n, s;
649
- const o = new Promise((c) => {
650
- s = c;
651
- }), i = new Promise((c) => {
652
- n = c;
653
- }), a = t.init(Se, {
654
- onAbort(c) {
655
- console.error("WASM aborted: "), console.error(c);
660
+ async function _e(t, e = {}, r = []) {
661
+ const [n, s, i] = Y(), [o, c] = Y(), l = t.init(He, {
662
+ onAbort(a) {
663
+ i(a), c(), console.error(a);
656
664
  },
657
665
  ENV: {},
658
666
  // Emscripten sometimes prepends a '/' to the path, which
659
667
  // breaks vite dev mode. An identity `locateFile` function
660
668
  // fixes it.
661
- locateFile: (c) => c,
669
+ locateFile: (a) => a,
662
670
  ...e,
663
671
  noInitialRun: !0,
664
672
  onRuntimeInitialized() {
665
- e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
673
+ e.onRuntimeInitialized && e.onRuntimeInitialized(), s();
666
674
  },
667
- monitorRunDependencies(c) {
668
- c === 0 && (delete a.monitorRunDependencies, s());
675
+ monitorRunDependencies(a) {
676
+ a === 0 && (delete l.monitorRunDependencies, c());
669
677
  }
670
678
  });
671
- for (const { default: c } of r)
672
- c(a);
673
- return r.length || s(), await o, await i, A.push(a), A.length - 1;
679
+ return await Promise.all(
680
+ r.map(
681
+ ({ default: a }) => a(l)
682
+ )
683
+ ), r.length || c(), await o, await n, M.push(l), M.length - 1;
674
684
  }
675
- const A = [];
676
- function ke(t) {
677
- return A[t];
685
+ const M = [];
686
+ function Ce(t) {
687
+ return M[t];
678
688
  }
679
- const Se = function() {
689
+ const He = function() {
680
690
  return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
681
- }();
682
- var xe = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
683
- for (var s = n > 1 ? void 0 : n ? Te(e, r) : e, o = t.length - 1, i; o >= 0; o--)
684
- (i = t[o]) && (s = (n ? i(e, r, s) : i(s)) || s);
685
- return n && s && xe(e, r, s), s;
691
+ }(), Y = () => {
692
+ const t = [], e = new Promise((r, n) => {
693
+ t.push(r, n);
694
+ });
695
+ return t.unshift(e), t;
696
+ };
697
+ var Fe = Object.defineProperty, Ae = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
698
+ for (var s = n > 1 ? void 0 : n ? Ae(e, r) : e, i = t.length - 1, o; i >= 0; i--)
699
+ (o = t[i]) && (s = (n ? o(e, r, s) : o(s)) || s);
700
+ return n && s && Fe(e, r, s), s;
686
701
  };
687
702
  const f = "string", E = "number", u = Symbol("__private__dont__use");
688
703
  class m {
@@ -694,8 +709,8 @@ class m {
694
709
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
695
710
  */
696
711
  constructor(e, r) {
697
- this.#e = [], this.#t = !1, this.#n = null, this.#r = {}, this.#i = [], e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new ge(
698
- new be(this, r)
712
+ this.#e = [], this.#t = !1, this.#n = null, this.#r = {}, this.#i = [], e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new we(
713
+ new ke(this, r)
699
714
  ));
700
715
  }
701
716
  #e;
@@ -728,13 +743,13 @@ class m {
728
743
  initializeRuntime(e) {
729
744
  if (this[u])
730
745
  throw new Error("PHP runtime already initialized.");
731
- const r = ke(e);
746
+ const r = Ce(e);
732
747
  if (!r)
733
748
  throw new Error("Invalid PHP runtime id.");
734
749
  this[u] = r, r.onMessage = (n) => {
735
750
  for (const s of this.#i)
736
751
  s(n);
737
- }, this.#n = ae(r);
752
+ }, this.#n = le(r);
738
753
  }
739
754
  /** @inheritDoc */
740
755
  setPhpIniPath(e) {
@@ -768,7 +783,7 @@ class m {
768
783
  this.#t || (this.#s(), this.#t = !0), this.#d(e.scriptPath || ""), this.#a(e.relativeUri || ""), this.#l(e.method || "GET");
769
784
  const { host: r, ...n } = {
770
785
  host: "example.com:443",
771
- ...K(e.headers || {})
786
+ ...Q(e.headers || {})
772
787
  };
773
788
  if (this.#c(r, e.protocol || "http"), this.#u(n), e.body && this.#h(e.body), e.fileInfos)
774
789
  for (const s of e.fileInfos)
@@ -800,8 +815,8 @@ class m {
800
815
  for (const s of r.headers) {
801
816
  if (!s.includes(": "))
802
817
  continue;
803
- const o = s.indexOf(": "), i = s.substring(0, o).toLowerCase(), a = s.substring(o + 2);
804
- i in n || (n[i] = []), n[i].push(a);
818
+ const i = s.indexOf(": "), o = s.substring(0, i).toLowerCase(), c = s.substring(i + 2);
819
+ o in n || (n[o] = []), n[o].push(c);
805
820
  }
806
821
  return {
807
822
  headers: n,
@@ -919,14 +934,14 @@ class m {
919
934
  * @param fileInfo - File details
920
935
  */
921
936
  #p(e) {
922
- const { key: r, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
923
- this.writeFile(i, o);
924
- const a = 0;
937
+ const { key: r, name: n, type: s, data: i } = e, o = `/tmp/${Math.random().toFixed(20)}`;
938
+ this.writeFile(o, i);
939
+ const c = 0;
925
940
  this[u].ccall(
926
941
  "wasm_add_uploaded_file",
927
942
  null,
928
943
  [f, f, f, f, E, E],
929
- [r, n, s, i, a, o.byteLength]
944
+ [r, n, s, o, c, i.byteLength]
930
945
  );
931
946
  }
932
947
  #m(e) {
@@ -940,32 +955,32 @@ class m {
940
955
  async #g() {
941
956
  let e, r;
942
957
  try {
943
- e = await new Promise((o, i) => {
944
- r = (c) => {
945
- const l = new Error("Rethrown");
946
- l.cause = c.error, l.betterMessage = c.message, i(l);
958
+ e = await new Promise((i, o) => {
959
+ r = (l) => {
960
+ const a = new Error("Rethrown");
961
+ a.cause = l.error, a.betterMessage = l.message, o(a);
947
962
  }, this.#n?.addEventListener(
948
963
  "error",
949
964
  r
950
965
  );
951
- const a = this[u].ccall(
966
+ const c = this[u].ccall(
952
967
  "wasm_sapi_handle_request",
953
968
  E,
954
969
  [],
955
970
  []
956
971
  );
957
- return a instanceof Promise ? a.then(o, i) : o(a);
972
+ return c instanceof Promise ? c.then(i, o) : i(c);
958
973
  });
959
- } catch (o) {
960
- for (const l in this)
961
- typeof this[l] == "function" && (this[l] = () => {
974
+ } catch (i) {
975
+ for (const a in this)
976
+ typeof this[a] == "function" && (this[a] = () => {
962
977
  throw new Error(
963
978
  "PHP runtime has crashed – see the earlier error for details."
964
979
  );
965
980
  });
966
- this.functionsMaybeMissingFromAsyncify = ce();
967
- const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, c = new Error(a);
968
- throw c.cause = i, c;
981
+ this.functionsMaybeMissingFromAsyncify = ue();
982
+ const o = i, c = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(c);
983
+ throw l.cause = o, l;
969
984
  } finally {
970
985
  this.#n?.removeEventListener("error", r), this.#r = {};
971
986
  }
@@ -1014,7 +1029,7 @@ class m {
1014
1029
  );
1015
1030
  if (r.prependPath) {
1016
1031
  const s = e.replace(/\/$/, "");
1017
- return n.map((o) => `${s}/${o}`);
1032
+ return n.map((i) => `${s}/${i}`);
1018
1033
  }
1019
1034
  return n;
1020
1035
  } catch (n) {
@@ -1067,7 +1082,7 @@ w([
1067
1082
  w([
1068
1083
  y('Could not stat "{path}"')
1069
1084
  ], m.prototype, "fileExists", 1);
1070
- function K(t) {
1085
+ function Q(t) {
1071
1086
  const e = {};
1072
1087
  for (const r in t)
1073
1088
  e[r.toLowerCase()] = t[r];
@@ -1078,17 +1093,17 @@ function K(t) {
1078
1093
  * Copyright 2019 Google LLC
1079
1094
  * SPDX-License-Identifier: Apache-2.0
1080
1095
  */
1081
- const Q = Symbol("Comlink.proxy"), _e = Symbol("Comlink.endpoint"), Ce = Symbol("Comlink.releaseProxy"), H = Symbol("Comlink.finalizer"), x = Symbol("Comlink.thrown"), X = (t) => typeof t == "object" && t !== null || typeof t == "function", Fe = {
1082
- canHandle: (t) => X(t) && t[Q],
1096
+ const X = Symbol("Comlink.proxy"), Me = Symbol("Comlink.endpoint"), Le = Symbol("Comlink.releaseProxy"), F = Symbol("Comlink.finalizer"), S = Symbol("Comlink.thrown"), Z = (t) => typeof t == "object" && t !== null || typeof t == "function", Oe = {
1097
+ canHandle: (t) => Z(t) && t[X],
1083
1098
  serialize(t) {
1084
1099
  const { port1: e, port2: r } = new MessageChannel();
1085
- return F(t, e), [r, [r]];
1100
+ return H(t, e), [r, [r]];
1086
1101
  },
1087
1102
  deserialize(t) {
1088
1103
  return t.start(), U(t);
1089
1104
  }
1090
- }, He = {
1091
- canHandle: (t) => X(t) && x in t,
1105
+ }, Ie = {
1106
+ canHandle: (t) => Z(t) && S in t,
1092
1107
  serialize({ value: t }) {
1093
1108
  let e;
1094
1109
  return t instanceof Error ? e = {
@@ -1103,174 +1118,174 @@ const Q = Symbol("Comlink.proxy"), _e = Symbol("Comlink.endpoint"), Ce = Symbol(
1103
1118
  deserialize(t) {
1104
1119
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
1105
1120
  }
1106
- }, k = /* @__PURE__ */ new Map([
1107
- ["proxy", Fe],
1108
- ["throw", He]
1121
+ }, v = /* @__PURE__ */ new Map([
1122
+ ["proxy", Oe],
1123
+ ["throw", Ie]
1109
1124
  ]);
1110
- function Me(t, e) {
1125
+ function Ue(t, e) {
1111
1126
  for (const r of t)
1112
1127
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
1113
1128
  return !0;
1114
1129
  return !1;
1115
1130
  }
1116
- function F(t, e = globalThis, r = ["*"]) {
1131
+ function H(t, e = globalThis, r = ["*"]) {
1117
1132
  e.addEventListener("message", function n(s) {
1118
1133
  if (!s || !s.data)
1119
1134
  return;
1120
- if (!Me(r, s.origin)) {
1135
+ if (!Ue(r, s.origin)) {
1121
1136
  console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
1122
1137
  return;
1123
1138
  }
1124
- const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), c = (s.data.argumentList || []).map(P);
1125
- let l;
1139
+ const { id: i, type: o, path: c } = Object.assign({ path: [] }, s.data), l = (s.data.argumentList || []).map(P);
1140
+ let a;
1126
1141
  try {
1127
- const h = a.slice(0, -1).reduce((p, R) => p[R], t), g = a.reduce((p, R) => p[R], t);
1128
- switch (i) {
1142
+ const h = c.slice(0, -1).reduce((p, R) => p[R], t), g = c.reduce((p, R) => p[R], t);
1143
+ switch (o) {
1129
1144
  case "GET":
1130
- l = g;
1145
+ a = g;
1131
1146
  break;
1132
1147
  case "SET":
1133
- h[a.slice(-1)[0]] = P(s.data.value), l = !0;
1148
+ h[c.slice(-1)[0]] = P(s.data.value), a = !0;
1134
1149
  break;
1135
1150
  case "APPLY":
1136
- l = g.apply(h, c);
1151
+ a = g.apply(h, l);
1137
1152
  break;
1138
1153
  case "CONSTRUCT":
1139
1154
  {
1140
- const p = new g(...c);
1141
- l = re(p);
1155
+ const p = new g(...l);
1156
+ a = ne(p);
1142
1157
  }
1143
1158
  break;
1144
1159
  case "ENDPOINT":
1145
1160
  {
1146
1161
  const { port1: p, port2: R } = new MessageChannel();
1147
- F(t, R), l = Ue(p, [p]);
1162
+ H(t, R), a = qe(p, [p]);
1148
1163
  }
1149
1164
  break;
1150
1165
  case "RELEASE":
1151
- l = void 0;
1166
+ a = void 0;
1152
1167
  break;
1153
1168
  default:
1154
1169
  return;
1155
1170
  }
1156
1171
  } catch (h) {
1157
- l = { value: h, [x]: 0 };
1172
+ a = { value: h, [S]: 0 };
1158
1173
  }
1159
- Promise.resolve(l).catch((h) => ({ value: h, [x]: 0 })).then((h) => {
1174
+ Promise.resolve(a).catch((h) => ({ value: h, [S]: 0 })).then((h) => {
1160
1175
  const [g, p] = C(h);
1161
- e.postMessage(Object.assign(Object.assign({}, g), { id: o }), p), i === "RELEASE" && (e.removeEventListener("message", n), Z(e), H in t && typeof t[H] == "function" && t[H]());
1176
+ e.postMessage(Object.assign(Object.assign({}, g), { id: i }), p), o === "RELEASE" && (e.removeEventListener("message", n), ee(e), F in t && typeof t[F] == "function" && t[F]());
1162
1177
  }).catch((h) => {
1163
1178
  const [g, p] = C({
1164
1179
  value: new TypeError("Unserializable return value"),
1165
- [x]: 0
1180
+ [S]: 0
1166
1181
  });
1167
- e.postMessage(Object.assign(Object.assign({}, g), { id: o }), p);
1182
+ e.postMessage(Object.assign(Object.assign({}, g), { id: i }), p);
1168
1183
  });
1169
1184
  }), e.start && e.start();
1170
1185
  }
1171
- function Ae(t) {
1186
+ function Ne(t) {
1172
1187
  return t.constructor.name === "MessagePort";
1173
1188
  }
1174
- function Z(t) {
1175
- Ae(t) && t.close();
1189
+ function ee(t) {
1190
+ Ne(t) && t.close();
1176
1191
  }
1177
1192
  function U(t, e) {
1178
- return O(t, [], e);
1193
+ return L(t, [], e);
1179
1194
  }
1180
- function S(t) {
1195
+ function x(t) {
1181
1196
  if (t)
1182
1197
  throw new Error("Proxy has been released and is not useable");
1183
1198
  }
1184
- function ee(t) {
1185
- return v(t, {
1199
+ function te(t) {
1200
+ return k(t, {
1186
1201
  type: "RELEASE"
1187
1202
  }).then(() => {
1188
- Z(t);
1203
+ ee(t);
1189
1204
  });
1190
1205
  }
1191
1206
  const T = /* @__PURE__ */ new WeakMap(), _ = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
1192
1207
  const e = (T.get(t) || 0) - 1;
1193
- T.set(t, e), e === 0 && ee(t);
1208
+ T.set(t, e), e === 0 && te(t);
1194
1209
  });
1195
- function Oe(t, e) {
1210
+ function We(t, e) {
1196
1211
  const r = (T.get(e) || 0) + 1;
1197
1212
  T.set(e, r), _ && _.register(t, e, t);
1198
1213
  }
1199
- function Le(t) {
1214
+ function $e(t) {
1200
1215
  _ && _.unregister(t);
1201
1216
  }
1202
- function O(t, e = [], r = function() {
1217
+ function L(t, e = [], r = function() {
1203
1218
  }) {
1204
1219
  let n = !1;
1205
1220
  const s = new Proxy(r, {
1206
- get(o, i) {
1207
- if (S(n), i === Ce)
1221
+ get(i, o) {
1222
+ if (x(n), o === Le)
1208
1223
  return () => {
1209
- Le(s), ee(t), n = !0;
1224
+ $e(s), te(t), n = !0;
1210
1225
  };
1211
- if (i === "then") {
1226
+ if (o === "then") {
1212
1227
  if (e.length === 0)
1213
1228
  return { then: () => s };
1214
- const a = v(t, {
1229
+ const c = k(t, {
1215
1230
  type: "GET",
1216
- path: e.map((c) => c.toString())
1231
+ path: e.map((l) => l.toString())
1217
1232
  }).then(P);
1218
- return a.then.bind(a);
1233
+ return c.then.bind(c);
1219
1234
  }
1220
- return O(t, [...e, i]);
1235
+ return L(t, [...e, o]);
1221
1236
  },
1222
- set(o, i, a) {
1223
- S(n);
1224
- const [c, l] = C(a);
1225
- return v(t, {
1237
+ set(i, o, c) {
1238
+ x(n);
1239
+ const [l, a] = C(c);
1240
+ return k(t, {
1226
1241
  type: "SET",
1227
- path: [...e, i].map((h) => h.toString()),
1228
- value: c
1229
- }, l).then(P);
1242
+ path: [...e, o].map((h) => h.toString()),
1243
+ value: l
1244
+ }, a).then(P);
1230
1245
  },
1231
- apply(o, i, a) {
1232
- S(n);
1233
- const c = e[e.length - 1];
1234
- if (c === _e)
1235
- return v(t, {
1246
+ apply(i, o, c) {
1247
+ x(n);
1248
+ const l = e[e.length - 1];
1249
+ if (l === Me)
1250
+ return k(t, {
1236
1251
  type: "ENDPOINT"
1237
1252
  }).then(P);
1238
- if (c === "bind")
1239
- return O(t, e.slice(0, -1));
1240
- const [l, h] = Y(a);
1241
- return v(t, {
1253
+ if (l === "bind")
1254
+ return L(t, e.slice(0, -1));
1255
+ const [a, h] = J(c);
1256
+ return k(t, {
1242
1257
  type: "APPLY",
1243
1258
  path: e.map((g) => g.toString()),
1244
- argumentList: l
1259
+ argumentList: a
1245
1260
  }, h).then(P);
1246
1261
  },
1247
- construct(o, i) {
1248
- S(n);
1249
- const [a, c] = Y(i);
1250
- return v(t, {
1262
+ construct(i, o) {
1263
+ x(n);
1264
+ const [c, l] = J(o);
1265
+ return k(t, {
1251
1266
  type: "CONSTRUCT",
1252
- path: e.map((l) => l.toString()),
1253
- argumentList: a
1254
- }, c).then(P);
1267
+ path: e.map((a) => a.toString()),
1268
+ argumentList: c
1269
+ }, l).then(P);
1255
1270
  }
1256
1271
  });
1257
- return Oe(s, t), s;
1272
+ return We(s, t), s;
1258
1273
  }
1259
- function Ie(t) {
1274
+ function De(t) {
1260
1275
  return Array.prototype.concat.apply([], t);
1261
1276
  }
1262
- function Y(t) {
1277
+ function J(t) {
1263
1278
  const e = t.map(C);
1264
- return [e.map((r) => r[0]), Ie(e.map((r) => r[1]))];
1279
+ return [e.map((r) => r[0]), De(e.map((r) => r[1]))];
1265
1280
  }
1266
- const te = /* @__PURE__ */ new WeakMap();
1267
- function Ue(t, e) {
1268
- return te.set(t, e), t;
1281
+ const re = /* @__PURE__ */ new WeakMap();
1282
+ function qe(t, e) {
1283
+ return re.set(t, e), t;
1269
1284
  }
1270
- function re(t) {
1271
- return Object.assign(t, { [Q]: !0 });
1285
+ function ne(t) {
1286
+ return Object.assign(t, { [X]: !0 });
1272
1287
  }
1273
- function ne(t, e = globalThis, r = "*") {
1288
+ function se(t, e = globalThis, r = "*") {
1274
1289
  return {
1275
1290
  postMessage: (n, s) => t.postMessage(n, r, s),
1276
1291
  addEventListener: e.addEventListener.bind(e),
@@ -1278,7 +1293,7 @@ function ne(t, e = globalThis, r = "*") {
1278
1293
  };
1279
1294
  }
1280
1295
  function C(t) {
1281
- for (const [e, r] of k)
1296
+ for (const [e, r] of v)
1282
1297
  if (r.canHandle(t)) {
1283
1298
  const [n, s] = r.serialize(t);
1284
1299
  return [
@@ -1295,64 +1310,64 @@ function C(t) {
1295
1310
  type: "RAW",
1296
1311
  value: t
1297
1312
  },
1298
- te.get(t) || []
1313
+ re.get(t) || []
1299
1314
  ];
1300
1315
  }
1301
1316
  function P(t) {
1302
1317
  switch (t.type) {
1303
1318
  case "HANDLER":
1304
- return k.get(t.name).deserialize(t.value);
1319
+ return v.get(t.name).deserialize(t.value);
1305
1320
  case "RAW":
1306
1321
  return t.value;
1307
1322
  }
1308
1323
  }
1309
- function v(t, e, r) {
1324
+ function k(t, e, r) {
1310
1325
  return new Promise((n) => {
1311
- const s = Ne();
1312
- t.addEventListener("message", function o(i) {
1313
- !i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", o), n(i.data));
1326
+ const s = ze();
1327
+ t.addEventListener("message", function i(o) {
1328
+ !o.data || !o.data.id || o.data.id !== s || (t.removeEventListener("message", i), n(o.data));
1314
1329
  }), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), r);
1315
1330
  });
1316
1331
  }
1317
- function Ne() {
1332
+ function ze() {
1318
1333
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
1319
1334
  }
1320
- function je(t) {
1321
- se();
1322
- const e = t instanceof Worker ? t : ne(t), r = U(e), n = N(r);
1335
+ function Je(t) {
1336
+ ie();
1337
+ const e = t instanceof Worker ? t : se(t), r = U(e), n = N(r);
1323
1338
  return new Proxy(n, {
1324
- get: (s, o) => o === "isConnected" ? async () => {
1325
- for (let i = 0; i < 10; i++)
1339
+ get: (s, i) => i === "isConnected" ? async () => {
1340
+ for (let o = 0; o < 10; o++)
1326
1341
  try {
1327
- await We(r.isConnected(), 200);
1342
+ await Be(r.isConnected(), 200);
1328
1343
  break;
1329
1344
  } catch {
1330
1345
  }
1331
- } : r[o]
1346
+ } : r[i]
1332
1347
  });
1333
1348
  }
1334
- async function We(t, e) {
1349
+ async function Be(t, e) {
1335
1350
  return new Promise((r, n) => {
1336
1351
  setTimeout(n, e), t.then(r);
1337
1352
  });
1338
1353
  }
1339
- function Ge(t, e) {
1340
- se();
1354
+ function Ke(t, e) {
1355
+ ie();
1341
1356
  const r = Promise.resolve();
1342
- let n;
1343
- const s = new Promise((a) => {
1344
- n = a;
1345
- }), o = N(t), i = new Proxy(o, {
1346
- get: (a, c) => c === "isConnected" ? () => r : c === "isReady" ? () => s : c in a ? a[c] : e?.[c]
1357
+ let n, s;
1358
+ const i = new Promise((l, a) => {
1359
+ n = l, s = a;
1360
+ }), o = N(t), c = new Proxy(o, {
1361
+ get: (l, a) => a === "isConnected" ? () => r : a === "isReady" ? () => i : a in l ? l[a] : e?.[a]
1347
1362
  });
1348
- return F(
1349
- i,
1350
- typeof window < "u" ? ne(self.parent) : void 0
1351
- ), [n, i];
1363
+ return H(
1364
+ c,
1365
+ typeof window < "u" ? se(self.parent) : void 0
1366
+ ), [n, s, c];
1352
1367
  }
1353
- let J = !1;
1354
- function se() {
1355
- J || (J = !0, k.set("EVENT", {
1368
+ let K = !1;
1369
+ function ie() {
1370
+ K || (K = !0, v.set("EVENT", {
1356
1371
  canHandle: (t) => t instanceof CustomEvent,
1357
1372
  serialize: (t) => [
1358
1373
  {
@@ -1361,17 +1376,17 @@ function se() {
1361
1376
  []
1362
1377
  ],
1363
1378
  deserialize: (t) => t
1364
- }), k.set("FUNCTION", {
1379
+ }), v.set("FUNCTION", {
1365
1380
  canHandle: (t) => typeof t == "function",
1366
1381
  serialize(t) {
1367
1382
  console.debug("[Comlink][Performance] Proxying a function");
1368
1383
  const { port1: e, port2: r } = new MessageChannel();
1369
- return F(t, e), [r, [r]];
1384
+ return H(t, e), [r, [r]];
1370
1385
  },
1371
1386
  deserialize(t) {
1372
1387
  return t.start(), U(t);
1373
1388
  }
1374
- }), k.set("PHPResponse", {
1389
+ }), v.set("PHPResponse", {
1375
1390
  canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
1376
1391
  serialize(t) {
1377
1392
  return [t.toRawData(), []];
@@ -1394,35 +1409,72 @@ function N(t) {
1394
1409
  case "string":
1395
1410
  return e[r];
1396
1411
  default:
1397
- return re(e[r]);
1412
+ return ne(e[r]);
1398
1413
  }
1399
1414
  }
1400
1415
  });
1401
1416
  }
1402
- async function $e(t = me) {
1403
- switch (t) {
1404
- case "8.2":
1405
- return await import("./php_8_2.js");
1406
- case "8.1":
1407
- return await import("./php_8_1.js");
1408
- case "8.0":
1409
- return await import("./php_8_0.js");
1410
- case "7.4":
1411
- return await import("./php_7_4.js");
1412
- case "7.3":
1413
- return await import("./php_7_3.js");
1414
- case "7.2":
1415
- return await import("./php_7_2.js");
1416
- case "7.1":
1417
- return await import("./php_7_1.js");
1418
- case "7.0":
1419
- return await import("./php_7_0.js");
1420
- case "5.6":
1421
- return await import("./php_5_6.js");
1422
- }
1417
+ async function je(t = ye, e = "light") {
1418
+ if (e === "kitchen-sink")
1419
+ switch (t) {
1420
+ case "8.2":
1421
+ return await import("./php_8_2.js");
1422
+ case "8.1":
1423
+ return await import("./php_8_1.js");
1424
+ case "8.0":
1425
+ return await import("./php_8_0.js");
1426
+ case "7.4":
1427
+ return await import("./php_7_4.js");
1428
+ case "7.3":
1429
+ return await import("./php_7_3.js");
1430
+ case "7.2":
1431
+ return await import("./php_7_2.js");
1432
+ case "7.1":
1433
+ return await import("./php_7_1.js");
1434
+ case "7.0":
1435
+ return await import("./php_7_0.js");
1436
+ case "5.6":
1437
+ return await import("./php_5_6.js");
1438
+ }
1439
+ else
1440
+ switch (t) {
1441
+ case "8.2":
1442
+ return await import("./php_8_2.js");
1443
+ case "8.1":
1444
+ return await import("./php_8_1.js");
1445
+ case "8.0":
1446
+ return await import("./php_8_0.js");
1447
+ case "7.4":
1448
+ return await import("./php_7_4.js");
1449
+ case "7.3":
1450
+ return await import("./php_7_3.js");
1451
+ case "7.2":
1452
+ return await import("./php_7_2.js");
1453
+ case "7.1":
1454
+ return await import("./php_7_1.js");
1455
+ case "7.0":
1456
+ return await import("./php_7_0.js");
1457
+ case "5.6":
1458
+ return await import("./php_5_6.js");
1459
+ }
1423
1460
  throw new Error(`Unsupported PHP version ${t}`);
1424
1461
  }
1425
- class L extends m {
1462
+ const Ge = () => ({
1463
+ websocket: {
1464
+ decorator: (t) => class extends t {
1465
+ constructor() {
1466
+ try {
1467
+ super();
1468
+ } catch {
1469
+ }
1470
+ }
1471
+ send() {
1472
+ return null;
1473
+ }
1474
+ }
1475
+ }
1476
+ });
1477
+ class O extends m {
1426
1478
  /**
1427
1479
  * Creates a new PHP instance.
1428
1480
  *
@@ -1436,7 +1488,7 @@ class L extends m {
1436
1488
  * @returns A new PHP instance
1437
1489
  */
1438
1490
  static async load(e, r = {}) {
1439
- return await L.loadSync(e, r).phpReady;
1491
+ return await O.loadSync(e, r).phpReady;
1440
1492
  }
1441
1493
  /**
1442
1494
  * Does what load() does, but synchronously returns
@@ -1446,21 +1498,22 @@ class L extends m {
1446
1498
  * @see load
1447
1499
  */
1448
1500
  static loadSync(e, r = {}) {
1449
- const n = new L(void 0, r.requestHandler), o = (async () => {
1450
- const i = await Promise.all([
1451
- $e(e),
1501
+ const n = new O(void 0, r.requestHandler), s = r.loadAllExtensions ? "kitchen-sink" : "light", o = (async () => {
1502
+ const c = await Promise.all([
1503
+ je(e, s),
1452
1504
  ...r.dataModules || []
1453
- ]), [a, ...c] = i;
1454
- r.downloadMonitor?.setModules(i);
1455
- const l = await Re(
1456
- a,
1505
+ ]), [l, ...a] = c;
1506
+ r.downloadMonitor?.setModules(c);
1507
+ const h = await _e(
1508
+ l,
1457
1509
  {
1458
1510
  ...r.emscriptenOptions || {},
1459
- ...r.downloadMonitor?.getEmscriptenOptions() || {}
1511
+ ...r.downloadMonitor?.getEmscriptenOptions() || {},
1512
+ ...Ge()
1460
1513
  },
1461
- c
1514
+ a
1462
1515
  );
1463
- n.initializeRuntime(l);
1516
+ n.initializeRuntime(h);
1464
1517
  })();
1465
1518
  return {
1466
1519
  php: n,
@@ -1469,7 +1522,7 @@ class L extends m {
1469
1522
  }
1470
1523
  }
1471
1524
  const d = /* @__PURE__ */ new WeakMap();
1472
- class Ve {
1525
+ class Xe {
1473
1526
  /** @inheritDoc */
1474
1527
  constructor(e, r) {
1475
1528
  d.set(this, {
@@ -1560,96 +1613,65 @@ class Ve {
1560
1613
  d.get(this).php.onMessage(e);
1561
1614
  }
1562
1615
  }
1563
- function De(t, e) {
1616
+ function Ve(t, e) {
1564
1617
  return {
1565
1618
  type: "response",
1566
1619
  requestId: t,
1567
1620
  response: e
1568
1621
  };
1569
1622
  }
1570
- async function Ye(t, e, r, n) {
1571
- const s = navigator.serviceWorker;
1572
- if (!s)
1623
+ async function Ze(t, e, r) {
1624
+ const n = navigator.serviceWorker;
1625
+ if (!n)
1573
1626
  throw new Error("Service workers are not supported in this browser.");
1574
- const o = await s.getRegistrations();
1575
- if (o.length > 0) {
1576
- const i = await qe();
1577
- if (n !== i) {
1578
- console.debug(
1579
- `[window] Reloading the currently registered Service Worker (expected version: ${n}, registered version: ${i})`
1580
- );
1581
- for (const a of o) {
1582
- let c = !1;
1583
- try {
1584
- await a.update();
1585
- } catch {
1586
- c = !0;
1587
- }
1588
- const l = a.waiting || a.installing;
1589
- l && !c && (i !== null ? l.postMessage("skip-waiting") : c = !0), c && (await a.unregister(), window.location.reload());
1590
- }
1591
- }
1592
- } else
1593
- console.debug(
1594
- `[window] Creating a Service Worker registration (version: ${n})`
1595
- ), await s.register(r, {
1596
- type: "module"
1597
- });
1598
- navigator.serviceWorker.addEventListener(
1627
+ console.debug("[window][sw] Registering a Service Worker"), await (await n.register(r, {
1628
+ type: "module",
1629
+ // Always bypass HTTP cache when fetching the new Service Worker script:
1630
+ updateViaCache: "none"
1631
+ })).update(), navigator.serviceWorker.addEventListener(
1599
1632
  "message",
1600
- async function(a) {
1601
- if (console.debug("Message from ServiceWorker", a), e && a.data.scope !== e)
1633
+ async function(o) {
1634
+ if (console.debug("[window][sw] Message from ServiceWorker", o), e && o.data.scope !== e)
1602
1635
  return;
1603
- const c = a.data.args || [], l = a.data.method, h = await t[l](...c);
1604
- a.source.postMessage(De(a.data.requestId, h));
1636
+ const c = o.data.args || [], l = o.data.method, a = await t[l](...c);
1637
+ o.source.postMessage(Ve(o.data.requestId, a));
1605
1638
  }
1606
- ), s.startMessages();
1607
- }
1608
- async function qe() {
1609
- try {
1610
- return (await (await fetch("/version")).json()).version;
1611
- } catch {
1612
- return null;
1613
- }
1639
+ ), n.startMessages();
1614
1640
  }
1615
- function Je() {
1616
- const t = {};
1617
- return typeof self?.location?.href < "u" && new URL(self.location.href).searchParams.forEach((r, n) => {
1618
- t[n] = r;
1619
- }), t;
1620
- }
1621
- const Ke = function() {
1622
- return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
1623
- }();
1624
- async function Qe(t, e = "webworker", r = {}) {
1625
- if (t = ze(t, r), e === "webworker")
1626
- return new Worker(t, { type: "module" });
1627
- if (e === "iframe")
1628
- return (await Be(t)).contentWindow;
1629
- throw new Error(`Unknown backendName: ${e}`);
1641
+ async function et(t, e = {}) {
1642
+ t = Ye(t, e);
1643
+ const r = new Worker(t, { type: "module" });
1644
+ return new Promise((n, s) => {
1645
+ r.onerror = (o) => {
1646
+ const c = new Error(
1647
+ `WebWorker failed to load at ${t}. ${o.message ? `Original error: ${o.message}` : ""}`
1648
+ );
1649
+ c.filename = o.filename, s(c);
1650
+ };
1651
+ function i(o) {
1652
+ o.data === "worker-script-started" && (n(r), r.removeEventListener("message", i));
1653
+ }
1654
+ r.addEventListener("message", i);
1655
+ });
1630
1656
  }
1631
- function ze(t, e) {
1657
+ function Ye(t, e) {
1632
1658
  if (!Object.entries(e).length)
1633
1659
  return t + "";
1634
1660
  const r = new URL(t);
1635
1661
  for (const [n, s] of Object.entries(e))
1636
- r.searchParams.set(n, s);
1662
+ if (Array.isArray(s))
1663
+ for (const i of s)
1664
+ r.searchParams.append(n, i);
1665
+ else
1666
+ r.searchParams.set(n, s);
1637
1667
  return r.toString();
1638
1668
  }
1639
- async function Be(t) {
1640
- const e = document.createElement("iframe"), r = "/" + t.split("/").slice(-1)[0];
1641
- return e.src = r, e.style.display = "none", document.body.appendChild(e), await new Promise((n) => {
1642
- e.addEventListener("load", n);
1643
- }), e;
1644
- }
1645
1669
  export {
1646
- L as WebPHP,
1647
- Ve as WebPHPEndpoint,
1648
- je as consumeAPI,
1649
- Ge as exposeAPI,
1650
- $e as getPHPLoaderModule,
1651
- Je as parseWorkerStartupOptions,
1652
- Ke as recommendedWorkerBackend,
1653
- Ye as registerServiceWorker,
1654
- Qe as spawnPHPWorkerThread
1670
+ O as WebPHP,
1671
+ Xe as WebPHPEndpoint,
1672
+ Je as consumeAPI,
1673
+ Ke as exposeAPI,
1674
+ je as getPHPLoaderModule,
1675
+ Ze as registerServiceWorker,
1676
+ et as spawnPHPWorkerThread
1655
1677
  };