@php-wasm/web 0.1.59 → 0.1.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -50,7 +50,7 @@ function ae(t) {
50
50
  throw o;
51
51
  if ("exitCode" in o && o?.exitCode === 0)
52
52
  return;
53
- const i = ce(
53
+ const i = le(
54
54
  o,
55
55
  t.lastAsyncifyStackSource?.stack
56
56
  );
@@ -67,11 +67,11 @@ function ae(t) {
67
67
  }
68
68
  return e;
69
69
  }
70
- let A = [];
71
- function le() {
72
- return A;
70
+ let M = [];
71
+ function ce() {
72
+ return M;
73
73
  }
74
- function ce(t, e) {
74
+ function le(t, e) {
75
75
  if (t.message === "unreachable") {
76
76
  let r = ue;
77
77
  e || (r += `
@@ -79,10 +79,10 @@ function ce(t, e) {
79
79
  This stack trace is lacking. For a better one initialize
80
80
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
81
81
 
82
- `), A = fe(
82
+ `), M = fe(
83
83
  e || t.stack || ""
84
84
  );
85
- for (const n of A)
85
+ for (const n of M)
86
86
  r += ` * ${n}
87
87
  `;
88
88
  return r;
@@ -286,10 +286,13 @@ class ye {
286
286
  for (; ; )
287
287
  if (this._running >= this.concurrency)
288
288
  await new Promise((e) => this.queue.push(e));
289
- else
290
- return this._running++, () => {
291
- this._running--, this.queue.length > 0 && this.queue.shift()();
289
+ else {
290
+ this._running++;
291
+ let e = !1;
292
+ return () => {
293
+ e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
292
294
  };
295
+ }
293
296
  }
294
297
  async run(e) {
295
298
  const r = await this.acquire();
@@ -319,7 +322,7 @@ class be {
319
322
  #s;
320
323
  #o;
321
324
  #a;
322
- #l;
325
+ #c;
323
326
  /**
324
327
  * @param php - The PHP instance.
325
328
  * @param config - Request Handler configuration.
@@ -331,7 +334,7 @@ class be {
331
334
  absoluteUrl: s = typeof location == "object" ? location?.href : "",
332
335
  isStaticFilePath: o = () => !1
333
336
  } = r;
334
- this.php = e, this.#e = n, this.#l = o;
337
+ this.php = e, this.#e = n, this.#c = o;
335
338
  const i = new URL(s);
336
339
  this.#n = i.hostname, this.#r = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
337
340
  const a = this.#r !== 443 && this.#r !== 80;
@@ -373,7 +376,7 @@ class be {
373
376
  n.pathname,
374
377
  this.#s
375
378
  );
376
- return this.#l(s) ? this.#c(s) : await this.#u(e, n);
379
+ return this.#c(s) ? this.#l(s) : await this.#u(e, n);
377
380
  }
378
381
  /**
379
382
  * Serves a static file from the PHP filesystem.
@@ -381,7 +384,7 @@ class be {
381
384
  * @param path - The requested static file path.
382
385
  * @returns The response.
383
386
  */
384
- #c(e) {
387
+ #l(e) {
385
388
  const r = `${this.#e}${e}`;
386
389
  if (!this.php.fileExists(r))
387
390
  return new b(
@@ -425,10 +428,10 @@ class be {
425
428
  }, i = [];
426
429
  if (e.files && Object.keys(e.files).length) {
427
430
  s = "POST";
428
- for (const c in e.files) {
429
- const h = e.files[c];
431
+ for (const l in e.files) {
432
+ const h = e.files[l];
430
433
  i.push({
431
- key: c,
434
+ key: l,
432
435
  name: h.name,
433
436
  type: h.type,
434
437
  data: new Uint8Array(await h.arrayBuffer())
@@ -442,9 +445,9 @@ class be {
442
445
  e.formData !== void 0 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
443
446
  e.formData
444
447
  ).toString()) : a = e.body;
445
- let l;
448
+ let c;
446
449
  try {
447
- l = this.#h(r.pathname);
450
+ c = this.#h(r.pathname);
448
451
  } catch {
449
452
  return new b(
450
453
  404,
@@ -461,7 +464,7 @@ class be {
461
464
  method: e.method || s,
462
465
  body: a,
463
466
  fileInfos: i,
464
- scriptPath: l,
467
+ scriptPath: c,
465
468
  headers: o
466
469
  });
467
470
  } finally {
@@ -496,10 +499,10 @@ function Ee(t) {
496
499
  return s.shift(), s.pop(), s.forEach((o) => {
497
500
  const i = o.indexOf(`\r
498
501
  \r
499
- `), a = o.substring(0, i).trim(), l = o.substring(i + 4).trim(), c = a.match(/name="([^"]+)"/);
500
- if (c) {
501
- const h = c[1];
502
- e[h] = l;
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;
503
506
  }
504
507
  }), e;
505
508
  }
@@ -629,10 +632,10 @@ function y(t = "") {
629
632
  try {
630
633
  return o.apply(this, i);
631
634
  } catch (a) {
632
- const l = typeof a == "object" ? a?.errno : null;
633
- if (l in V) {
634
- const c = V[l], h = typeof i[0] == "string" ? i[0] : null, g = h !== null ? t.replaceAll("{path}", h) : t;
635
- throw new Error(`${g}: ${c}`, {
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}`, {
636
639
  cause: a
637
640
  });
638
641
  }
@@ -643,37 +646,37 @@ function y(t = "") {
643
646
  }
644
647
  async function Re(t, e = {}, r = []) {
645
648
  let n, s;
646
- const o = new Promise((l) => {
647
- s = l;
648
- }), i = new Promise((l) => {
649
- n = l;
650
- }), a = t.init(ke, {
651
- onAbort(l) {
652
- console.error("WASM aborted: "), console.error(l);
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);
653
656
  },
654
657
  ENV: {},
655
658
  // Emscripten sometimes prepends a '/' to the path, which
656
659
  // breaks vite dev mode. An identity `locateFile` function
657
660
  // fixes it.
658
- locateFile: (l) => l,
661
+ locateFile: (c) => c,
659
662
  ...e,
660
663
  noInitialRun: !0,
661
664
  onRuntimeInitialized() {
662
665
  e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
663
666
  },
664
- monitorRunDependencies(l) {
665
- l === 0 && (delete a.monitorRunDependencies, s());
667
+ monitorRunDependencies(c) {
668
+ c === 0 && (delete a.monitorRunDependencies, s());
666
669
  }
667
670
  });
668
- for (const { default: l } of r)
669
- l(a);
670
- return r.length || s(), await o, await i, M.push(a), M.length - 1;
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;
671
674
  }
672
- const M = [];
673
- function Se(t) {
674
- return M[t];
675
+ const A = [];
676
+ function ke(t) {
677
+ return A[t];
675
678
  }
676
- const ke = function() {
679
+ const Se = function() {
677
680
  return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
678
681
  }();
679
682
  var xe = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
@@ -691,7 +694,7 @@ class m {
691
694
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
692
695
  */
693
696
  constructor(e, r) {
694
- this.#e = [], this.#t = !1, this.#n = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new ge(
697
+ this.#e = [], this.#t = !1, this.#n = null, this.#r = {}, this.#i = [], e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new ge(
695
698
  new be(this, r)
696
699
  ));
697
700
  }
@@ -699,6 +702,11 @@ class m {
699
702
  #t;
700
703
  #n;
701
704
  #r;
705
+ #i;
706
+ /** @inheritDoc */
707
+ async onMessage(e) {
708
+ this.#i.push(e);
709
+ }
702
710
  /** @inheritDoc */
703
711
  get absoluteUrl() {
704
712
  return this.requestHandler.requestHandler.absoluteUrl;
@@ -720,10 +728,13 @@ class m {
720
728
  initializeRuntime(e) {
721
729
  if (this[u])
722
730
  throw new Error("PHP runtime already initialized.");
723
- const r = Se(e);
731
+ const r = ke(e);
724
732
  if (!r)
725
733
  throw new Error("Invalid PHP runtime id.");
726
- this[u] = r, this.#n = ae(r);
734
+ this[u] = r, r.onMessage = (n) => {
735
+ for (const s of this.#i)
736
+ s(n);
737
+ }, this.#n = ae(r);
727
738
  }
728
739
  /** @inheritDoc */
729
740
  setPhpIniPath(e) {
@@ -754,17 +765,17 @@ class m {
754
765
  }
755
766
  /** @inheritDoc */
756
767
  async run(e) {
757
- this.#t || (this.#i(), this.#t = !0), this.#h(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#l(e.method || "GET");
768
+ this.#t || (this.#s(), this.#t = !0), this.#d(e.scriptPath || ""), this.#a(e.relativeUri || ""), this.#l(e.method || "GET");
758
769
  const { host: r, ...n } = {
759
770
  host: "example.com:443",
760
771
  ...K(e.headers || {})
761
772
  };
762
- if (this.#a(r, e.protocol || "http"), this.#c(n), e.body && this.#u(e.body), e.fileInfos)
773
+ if (this.#c(r, e.protocol || "http"), this.#u(n), e.body && this.#h(e.body), e.fileInfos)
763
774
  for (const s of e.fileInfos)
764
- this.#f(s);
765
- return e.code && this.#p(" ?>" + e.code), this.#d(), await this.#m();
775
+ this.#p(s);
776
+ return e.code && this.#m(" ?>" + e.code), this.#f(), await this.#g();
766
777
  }
767
- #i() {
778
+ #s() {
768
779
  if (this.#e.length > 0) {
769
780
  const e = this.#e.map(([r, n]) => `${r}=${n}`).join(`
770
781
  `) + `
@@ -779,7 +790,7 @@ class m {
779
790
  }
780
791
  this[u].ccall("php_wasm_init", null, [], []);
781
792
  }
782
- #s() {
793
+ #o() {
783
794
  const e = "/tmp/headers.json";
784
795
  if (!this.fileExists(e))
785
796
  throw new Error(
@@ -797,7 +808,7 @@ class m {
797
808
  httpStatusCode: r.status
798
809
  };
799
810
  }
800
- #o(e) {
811
+ #a(e) {
801
812
  if (this[u].ccall(
802
813
  "wasm_set_request_uri",
803
814
  null,
@@ -813,7 +824,7 @@ class m {
813
824
  );
814
825
  }
815
826
  }
816
- #a(e, r) {
827
+ #c(e, r) {
817
828
  this[u].ccall(
818
829
  "wasm_set_request_host",
819
830
  null,
@@ -840,7 +851,7 @@ class m {
840
851
  [e]
841
852
  );
842
853
  }
843
- #c(e) {
854
+ #u(e) {
844
855
  e.cookie && this[u].ccall(
845
856
  "wasm_set_cookies",
846
857
  null,
@@ -865,7 +876,7 @@ class m {
865
876
  );
866
877
  }
867
878
  }
868
- #u(e) {
879
+ #h(e) {
869
880
  this[u].ccall(
870
881
  "wasm_set_request_body",
871
882
  null,
@@ -878,7 +889,7 @@ class m {
878
889
  [new TextEncoder().encode(e).length]
879
890
  );
880
891
  }
881
- #h(e) {
892
+ #d(e) {
882
893
  this[u].ccall(
883
894
  "wasm_set_path_translated",
884
895
  null,
@@ -889,7 +900,7 @@ class m {
889
900
  addServerGlobalEntry(e, r) {
890
901
  this.#r[e] = r;
891
902
  }
892
- #d() {
903
+ #f() {
893
904
  for (const e in this.#r)
894
905
  this[u].ccall(
895
906
  "wasm_add_SERVER_entry",
@@ -907,7 +918,7 @@ class m {
907
918
  *
908
919
  * @param fileInfo - File details
909
920
  */
910
- #f(e) {
921
+ #p(e) {
911
922
  const { key: r, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
912
923
  this.writeFile(i, o);
913
924
  const a = 0;
@@ -918,7 +929,7 @@ class m {
918
929
  [r, n, s, i, a, o.byteLength]
919
930
  );
920
931
  }
921
- #p(e) {
932
+ #m(e) {
922
933
  this[u].ccall(
923
934
  "wasm_set_php_code",
924
935
  null,
@@ -926,13 +937,13 @@ class m {
926
937
  [e]
927
938
  );
928
939
  }
929
- async #m() {
940
+ async #g() {
930
941
  let e, r;
931
942
  try {
932
943
  e = await new Promise((o, i) => {
933
- r = (l) => {
934
- const c = new Error("Rethrown");
935
- c.cause = l.error, c.betterMessage = l.message, i(c);
944
+ r = (c) => {
945
+ const l = new Error("Rethrown");
946
+ l.cause = c.error, l.betterMessage = c.message, i(l);
936
947
  }, this.#n?.addEventListener(
937
948
  "error",
938
949
  r
@@ -946,19 +957,19 @@ class m {
946
957
  return a instanceof Promise ? a.then(o, i) : o(a);
947
958
  });
948
959
  } catch (o) {
949
- for (const c in this)
950
- typeof this[c] == "function" && (this[c] = () => {
960
+ for (const l in this)
961
+ typeof this[l] == "function" && (this[l] = () => {
951
962
  throw new Error(
952
963
  "PHP runtime has crashed – see the earlier error for details."
953
964
  );
954
965
  });
955
- this.functionsMaybeMissingFromAsyncify = le();
956
- const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
957
- throw l.cause = i, l;
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;
958
969
  } finally {
959
970
  this.#n?.removeEventListener("error", r), this.#r = {};
960
971
  }
961
- const { headers: n, httpStatusCode: s } = this.#s();
972
+ const { headers: n, httpStatusCode: s } = this.#o();
962
973
  return new b(
963
974
  s,
964
975
  n,
@@ -1092,11 +1103,11 @@ const Q = Symbol("Comlink.proxy"), _e = Symbol("Comlink.endpoint"), Ce = Symbol(
1092
1103
  deserialize(t) {
1093
1104
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
1094
1105
  }
1095
- }, S = /* @__PURE__ */ new Map([
1106
+ }, k = /* @__PURE__ */ new Map([
1096
1107
  ["proxy", Fe],
1097
1108
  ["throw", He]
1098
1109
  ]);
1099
- function Ae(t, e) {
1110
+ function Me(t, e) {
1100
1111
  for (const r of t)
1101
1112
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
1102
1113
  return !0;
@@ -1106,46 +1117,46 @@ function F(t, e = globalThis, r = ["*"]) {
1106
1117
  e.addEventListener("message", function n(s) {
1107
1118
  if (!s || !s.data)
1108
1119
  return;
1109
- if (!Ae(r, s.origin)) {
1120
+ if (!Me(r, s.origin)) {
1110
1121
  console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
1111
1122
  return;
1112
1123
  }
1113
- const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), l = (s.data.argumentList || []).map(P);
1114
- let c;
1124
+ const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), c = (s.data.argumentList || []).map(P);
1125
+ let l;
1115
1126
  try {
1116
1127
  const h = a.slice(0, -1).reduce((p, R) => p[R], t), g = a.reduce((p, R) => p[R], t);
1117
1128
  switch (i) {
1118
1129
  case "GET":
1119
- c = g;
1130
+ l = g;
1120
1131
  break;
1121
1132
  case "SET":
1122
- h[a.slice(-1)[0]] = P(s.data.value), c = !0;
1133
+ h[a.slice(-1)[0]] = P(s.data.value), l = !0;
1123
1134
  break;
1124
1135
  case "APPLY":
1125
- c = g.apply(h, l);
1136
+ l = g.apply(h, c);
1126
1137
  break;
1127
1138
  case "CONSTRUCT":
1128
1139
  {
1129
- const p = new g(...l);
1130
- c = re(p);
1140
+ const p = new g(...c);
1141
+ l = re(p);
1131
1142
  }
1132
1143
  break;
1133
1144
  case "ENDPOINT":
1134
1145
  {
1135
1146
  const { port1: p, port2: R } = new MessageChannel();
1136
- F(t, R), c = Ue(p, [p]);
1147
+ F(t, R), l = Ue(p, [p]);
1137
1148
  }
1138
1149
  break;
1139
1150
  case "RELEASE":
1140
- c = void 0;
1151
+ l = void 0;
1141
1152
  break;
1142
1153
  default:
1143
1154
  return;
1144
1155
  }
1145
1156
  } catch (h) {
1146
- c = { value: h, [x]: 0 };
1157
+ l = { value: h, [x]: 0 };
1147
1158
  }
1148
- Promise.resolve(c).catch((h) => ({ value: h, [x]: 0 })).then((h) => {
1159
+ Promise.resolve(l).catch((h) => ({ value: h, [x]: 0 })).then((h) => {
1149
1160
  const [g, p] = C(h);
1150
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]());
1151
1162
  }).catch((h) => {
@@ -1157,16 +1168,16 @@ function F(t, e = globalThis, r = ["*"]) {
1157
1168
  });
1158
1169
  }), e.start && e.start();
1159
1170
  }
1160
- function Me(t) {
1171
+ function Ae(t) {
1161
1172
  return t.constructor.name === "MessagePort";
1162
1173
  }
1163
1174
  function Z(t) {
1164
- Me(t) && t.close();
1175
+ Ae(t) && t.close();
1165
1176
  }
1166
1177
  function U(t, e) {
1167
1178
  return O(t, [], e);
1168
1179
  }
1169
- function k(t) {
1180
+ function S(t) {
1170
1181
  if (t)
1171
1182
  throw new Error("Proxy has been released and is not useable");
1172
1183
  }
@@ -1193,7 +1204,7 @@ function O(t, e = [], r = function() {
1193
1204
  let n = !1;
1194
1205
  const s = new Proxy(r, {
1195
1206
  get(o, i) {
1196
- if (k(n), i === Ce)
1207
+ if (S(n), i === Ce)
1197
1208
  return () => {
1198
1209
  Le(s), ee(t), n = !0;
1199
1210
  };
@@ -1202,45 +1213,45 @@ function O(t, e = [], r = function() {
1202
1213
  return { then: () => s };
1203
1214
  const a = v(t, {
1204
1215
  type: "GET",
1205
- path: e.map((l) => l.toString())
1216
+ path: e.map((c) => c.toString())
1206
1217
  }).then(P);
1207
1218
  return a.then.bind(a);
1208
1219
  }
1209
1220
  return O(t, [...e, i]);
1210
1221
  },
1211
1222
  set(o, i, a) {
1212
- k(n);
1213
- const [l, c] = C(a);
1223
+ S(n);
1224
+ const [c, l] = C(a);
1214
1225
  return v(t, {
1215
1226
  type: "SET",
1216
1227
  path: [...e, i].map((h) => h.toString()),
1217
- value: l
1218
- }, c).then(P);
1228
+ value: c
1229
+ }, l).then(P);
1219
1230
  },
1220
1231
  apply(o, i, a) {
1221
- k(n);
1222
- const l = e[e.length - 1];
1223
- if (l === _e)
1232
+ S(n);
1233
+ const c = e[e.length - 1];
1234
+ if (c === _e)
1224
1235
  return v(t, {
1225
1236
  type: "ENDPOINT"
1226
1237
  }).then(P);
1227
- if (l === "bind")
1238
+ if (c === "bind")
1228
1239
  return O(t, e.slice(0, -1));
1229
- const [c, h] = Y(a);
1240
+ const [l, h] = Y(a);
1230
1241
  return v(t, {
1231
1242
  type: "APPLY",
1232
1243
  path: e.map((g) => g.toString()),
1233
- argumentList: c
1244
+ argumentList: l
1234
1245
  }, h).then(P);
1235
1246
  },
1236
1247
  construct(o, i) {
1237
- k(n);
1238
- const [a, l] = Y(i);
1248
+ S(n);
1249
+ const [a, c] = Y(i);
1239
1250
  return v(t, {
1240
1251
  type: "CONSTRUCT",
1241
- path: e.map((c) => c.toString()),
1252
+ path: e.map((l) => l.toString()),
1242
1253
  argumentList: a
1243
- }, l).then(P);
1254
+ }, c).then(P);
1244
1255
  }
1245
1256
  });
1246
1257
  return Oe(s, t), s;
@@ -1267,7 +1278,7 @@ function ne(t, e = globalThis, r = "*") {
1267
1278
  };
1268
1279
  }
1269
1280
  function C(t) {
1270
- for (const [e, r] of S)
1281
+ for (const [e, r] of k)
1271
1282
  if (r.canHandle(t)) {
1272
1283
  const [n, s] = r.serialize(t);
1273
1284
  return [
@@ -1290,7 +1301,7 @@ function C(t) {
1290
1301
  function P(t) {
1291
1302
  switch (t.type) {
1292
1303
  case "HANDLER":
1293
- return S.get(t.name).deserialize(t.value);
1304
+ return k.get(t.name).deserialize(t.value);
1294
1305
  case "RAW":
1295
1306
  return t.value;
1296
1307
  }
@@ -1306,21 +1317,33 @@ function v(t, e, r) {
1306
1317
  function Ne() {
1307
1318
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
1308
1319
  }
1309
- function Be(t) {
1320
+ function je(t) {
1310
1321
  se();
1311
1322
  const e = t instanceof Worker ? t : ne(t), r = U(e), n = N(r);
1312
1323
  return new Proxy(n, {
1313
- get: (s, o) => o === "isConnected" ? () => r.isConnected() : r[o]
1324
+ get: (s, o) => o === "isConnected" ? async () => {
1325
+ for (let i = 0; i < 10; i++)
1326
+ try {
1327
+ await We(r.isConnected(), 200);
1328
+ break;
1329
+ } catch {
1330
+ }
1331
+ } : r[o]
1314
1332
  });
1315
1333
  }
1316
- function je(t, e) {
1334
+ async function We(t, e) {
1335
+ return new Promise((r, n) => {
1336
+ setTimeout(n, e), t.then(r);
1337
+ });
1338
+ }
1339
+ function Ge(t, e) {
1317
1340
  se();
1318
1341
  const r = Promise.resolve();
1319
1342
  let n;
1320
1343
  const s = new Promise((a) => {
1321
1344
  n = a;
1322
1345
  }), o = N(t), i = new Proxy(o, {
1323
- get: (a, l) => l === "isConnected" ? () => r : l === "isReady" ? () => s : l in a ? a[l] : e?.[l]
1346
+ get: (a, c) => c === "isConnected" ? () => r : c === "isReady" ? () => s : c in a ? a[c] : e?.[c]
1324
1347
  });
1325
1348
  return F(
1326
1349
  i,
@@ -1329,7 +1352,7 @@ function je(t, e) {
1329
1352
  }
1330
1353
  let J = !1;
1331
1354
  function se() {
1332
- J || (J = !0, S.set("EVENT", {
1355
+ J || (J = !0, k.set("EVENT", {
1333
1356
  canHandle: (t) => t instanceof CustomEvent,
1334
1357
  serialize: (t) => [
1335
1358
  {
@@ -1338,7 +1361,7 @@ function se() {
1338
1361
  []
1339
1362
  ],
1340
1363
  deserialize: (t) => t
1341
- }), S.set("FUNCTION", {
1364
+ }), k.set("FUNCTION", {
1342
1365
  canHandle: (t) => typeof t == "function",
1343
1366
  serialize(t) {
1344
1367
  console.debug("[Comlink][Performance] Proxying a function");
@@ -1348,7 +1371,7 @@ function se() {
1348
1371
  deserialize(t) {
1349
1372
  return t.start(), U(t);
1350
1373
  }
1351
- }), S.set("PHPResponse", {
1374
+ }), k.set("PHPResponse", {
1352
1375
  canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
1353
1376
  serialize(t) {
1354
1377
  return [t.toRawData(), []];
@@ -1376,7 +1399,7 @@ function N(t) {
1376
1399
  }
1377
1400
  });
1378
1401
  }
1379
- async function We(t = me) {
1402
+ async function $e(t = me) {
1380
1403
  switch (t) {
1381
1404
  case "8.2":
1382
1405
  return await import("./php_8_2.js");
@@ -1425,29 +1448,28 @@ class L extends m {
1425
1448
  static loadSync(e, r = {}) {
1426
1449
  const n = new L(void 0, r.requestHandler), o = (async () => {
1427
1450
  const i = await Promise.all([
1428
- We(e),
1451
+ $e(e),
1429
1452
  ...r.dataModules || []
1430
- ]), [a, ...l] = i;
1453
+ ]), [a, ...c] = i;
1431
1454
  r.downloadMonitor?.setModules(i);
1432
- const c = await Re(
1455
+ const l = await Re(
1433
1456
  a,
1434
1457
  {
1435
1458
  ...r.emscriptenOptions || {},
1436
1459
  ...r.downloadMonitor?.getEmscriptenOptions() || {}
1437
1460
  },
1438
- l
1461
+ c
1439
1462
  );
1440
- return n.initializeRuntime(c), { dataModules: l };
1463
+ n.initializeRuntime(l);
1441
1464
  })();
1442
1465
  return {
1443
1466
  php: n,
1444
- phpReady: o.then(() => n),
1445
- dataModules: o.then((i) => i.dataModules)
1467
+ phpReady: o.then(() => n)
1446
1468
  };
1447
1469
  }
1448
1470
  }
1449
1471
  const d = /* @__PURE__ */ new WeakMap();
1450
- class Ge {
1472
+ class Ve {
1451
1473
  /** @inheritDoc */
1452
1474
  constructor(e, r) {
1453
1475
  d.set(this, {
@@ -1533,34 +1555,38 @@ class Ge {
1533
1555
  fileExists(e) {
1534
1556
  return d.get(this).php.fileExists(e);
1535
1557
  }
1558
+ /** @inheritDoc @php-wasm/web!WebPHP.onMessage */
1559
+ onMessage(e) {
1560
+ d.get(this).php.onMessage(e);
1561
+ }
1536
1562
  }
1537
- function $e(t, e) {
1563
+ function De(t, e) {
1538
1564
  return {
1539
1565
  type: "response",
1540
1566
  requestId: t,
1541
1567
  response: e
1542
1568
  };
1543
1569
  }
1544
- async function Ve(t, e, r, n) {
1570
+ async function Ye(t, e, r, n) {
1545
1571
  const s = navigator.serviceWorker;
1546
1572
  if (!s)
1547
1573
  throw new Error("Service workers are not supported in this browser.");
1548
1574
  const o = await s.getRegistrations();
1549
1575
  if (o.length > 0) {
1550
- const i = await De();
1576
+ const i = await qe();
1551
1577
  if (n !== i) {
1552
1578
  console.debug(
1553
1579
  `[window] Reloading the currently registered Service Worker (expected version: ${n}, registered version: ${i})`
1554
1580
  );
1555
1581
  for (const a of o) {
1556
- let l = !1;
1582
+ let c = !1;
1557
1583
  try {
1558
1584
  await a.update();
1559
1585
  } catch {
1560
- l = !0;
1586
+ c = !0;
1561
1587
  }
1562
- const c = a.waiting || a.installing;
1563
- c && !l && (i !== null ? c.postMessage("skip-waiting") : l = !0), l && (await a.unregister(), window.location.reload());
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());
1564
1590
  }
1565
1591
  }
1566
1592
  } else
@@ -1574,35 +1600,35 @@ async function Ve(t, e, r, n) {
1574
1600
  async function(a) {
1575
1601
  if (console.debug("Message from ServiceWorker", a), e && a.data.scope !== e)
1576
1602
  return;
1577
- const l = a.data.args || [], c = a.data.method, h = await t[c](...l);
1578
- a.source.postMessage($e(a.data.requestId, h));
1603
+ const c = a.data.args || [], l = a.data.method, h = await t[l](...c);
1604
+ a.source.postMessage(De(a.data.requestId, h));
1579
1605
  }
1580
1606
  ), s.startMessages();
1581
1607
  }
1582
- async function De() {
1608
+ async function qe() {
1583
1609
  try {
1584
1610
  return (await (await fetch("/version")).json()).version;
1585
1611
  } catch {
1586
1612
  return null;
1587
1613
  }
1588
1614
  }
1589
- function Ye() {
1615
+ function Je() {
1590
1616
  const t = {};
1591
1617
  return typeof self?.location?.href < "u" && new URL(self.location.href).searchParams.forEach((r, n) => {
1592
1618
  t[n] = r;
1593
1619
  }), t;
1594
1620
  }
1595
- const Je = function() {
1621
+ const Ke = function() {
1596
1622
  return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
1597
1623
  }();
1598
- async function Ke(t, e = "webworker", r = {}) {
1599
- if (t = qe(t, r), e === "webworker")
1624
+ async function Qe(t, e = "webworker", r = {}) {
1625
+ if (t = ze(t, r), e === "webworker")
1600
1626
  return new Worker(t, { type: "module" });
1601
1627
  if (e === "iframe")
1602
- return (await ze(t)).contentWindow;
1628
+ return (await Be(t)).contentWindow;
1603
1629
  throw new Error(`Unknown backendName: ${e}`);
1604
1630
  }
1605
- function qe(t, e) {
1631
+ function ze(t, e) {
1606
1632
  if (!Object.entries(e).length)
1607
1633
  return t + "";
1608
1634
  const r = new URL(t);
@@ -1610,7 +1636,7 @@ function qe(t, e) {
1610
1636
  r.searchParams.set(n, s);
1611
1637
  return r.toString();
1612
1638
  }
1613
- async function ze(t) {
1639
+ async function Be(t) {
1614
1640
  const e = document.createElement("iframe"), r = "/" + t.split("/").slice(-1)[0];
1615
1641
  return e.src = r, e.style.display = "none", document.body.appendChild(e), await new Promise((n) => {
1616
1642
  e.addEventListener("load", n);
@@ -1618,12 +1644,12 @@ async function ze(t) {
1618
1644
  }
1619
1645
  export {
1620
1646
  L as WebPHP,
1621
- Ge as WebPHPEndpoint,
1622
- Be as consumeAPI,
1623
- je as exposeAPI,
1624
- We as getPHPLoaderModule,
1625
- Ye as parseWorkerStartupOptions,
1626
- Je as recommendedWorkerBackend,
1627
- Ve as registerServiceWorker,
1628
- Ke as spawnPHPWorkerThread
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
1629
1655
  };