@php-wasm/web 0.1.32 → 0.1.35

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.
@@ -33,7 +33,7 @@ class R {
33
33
  return new TextDecoder().decode(this.bytes);
34
34
  }
35
35
  }
36
- const K = [
36
+ const Q = [
37
37
  "8.2",
38
38
  "8.1",
39
39
  "8.0",
@@ -43,8 +43,8 @@ const K = [
43
43
  "7.1",
44
44
  "7.0",
45
45
  "5.6"
46
- ], Q = K[0];
47
- class X {
46
+ ], X = Q[0];
47
+ class Z {
48
48
  #e;
49
49
  #t;
50
50
  /**
@@ -130,7 +130,7 @@ class X {
130
130
  return e.join("; ");
131
131
  }
132
132
  }
133
- class Z {
133
+ class ee {
134
134
  constructor({ concurrency: e }) {
135
135
  this._running = 0, this.concurrency = e, this.queue = [];
136
136
  }
@@ -155,17 +155,17 @@ class Z {
155
155
  }
156
156
  }
157
157
  }
158
- const ee = "http://example.com";
159
- function M(t) {
158
+ const te = "http://example.com";
159
+ function L(t) {
160
160
  return t.toString().substring(t.origin.length);
161
161
  }
162
- function L(t, e) {
162
+ function N(t, e) {
163
163
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
164
164
  }
165
- function te(t, e) {
165
+ function re(t, e) {
166
166
  return !e || t.startsWith(e) ? t : e + t;
167
167
  }
168
- class re {
168
+ class ne {
169
169
  #e;
170
170
  #t;
171
171
  #s;
@@ -180,7 +180,7 @@ class re {
180
180
  * @param config - Request Handler configuration.
181
181
  */
182
182
  constructor(e, r = {}) {
183
- this.#a = new Z({ concurrency: 1 });
183
+ this.#a = new ee({ concurrency: 1 });
184
184
  const {
185
185
  documentRoot: n = "/www/",
186
186
  absoluteUrl: s = typeof location == "object" ? location?.href : "",
@@ -206,7 +206,7 @@ class re {
206
206
  /** @inheritDoc */
207
207
  internalUrlToPath(e) {
208
208
  const r = new URL(e);
209
- return r.pathname.startsWith(this.#r) && (r.pathname = r.pathname.slice(this.#r.length)), M(r);
209
+ return r.pathname.startsWith(this.#r) && (r.pathname = r.pathname.slice(this.#r.length)), L(r);
210
210
  }
211
211
  get isRequestRunning() {
212
212
  return this.#a.running > 0;
@@ -223,8 +223,8 @@ class re {
223
223
  async request(e) {
224
224
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL(
225
225
  e.url,
226
- r ? void 0 : ee
227
- ), s = L(
226
+ r ? void 0 : te
227
+ ), s = N(
228
228
  n.pathname,
229
229
  this.#r
230
230
  );
@@ -252,7 +252,7 @@ class re {
252
252
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
253
253
  // The code below won't return the correct mime-type if the extension
254
254
  // was tampered with.
255
- "content-type": [se(r)],
255
+ "content-type": [ie(r)],
256
256
  "accept-ranges": ["bytes"],
257
257
  "cache-control": ["public, max-age=0"]
258
258
  },
@@ -276,7 +276,7 @@ class re {
276
276
  let s = "GET";
277
277
  const a = {
278
278
  host: this.#i,
279
- ...W(e.headers || {})
279
+ ...z(e.headers || {})
280
280
  }, i = [];
281
281
  if (e.files && Object.keys(e.files).length) {
282
282
  s = "POST";
@@ -289,7 +289,7 @@ class re {
289
289
  data: new Uint8Array(await u.arrayBuffer())
290
290
  });
291
291
  }
292
- a["content-type"]?.startsWith("multipart/form-data") && (e.formData = ne(
292
+ a["content-type"]?.startsWith("multipart/form-data") && (e.formData = se(
293
293
  e.body || ""
294
294
  ), a["content-type"] = "application/x-www-form-urlencoded", delete e.body);
295
295
  }
@@ -297,8 +297,8 @@ class re {
297
297
  return e.formData !== void 0 ? (s = "POST", a["content-type"] = a["content-type"] || "application/x-www-form-urlencoded", o = new URLSearchParams(
298
298
  e.formData
299
299
  ).toString()) : o = e.body, await this.php.run({
300
- relativeUri: te(
301
- M(r),
300
+ relativeUri: re(
301
+ L(r),
302
302
  this.#r
303
303
  ),
304
304
  protocol: this.#t,
@@ -321,13 +321,13 @@ class re {
321
321
  * @returns The resolved filesystem path.
322
322
  */
323
323
  #d(e) {
324
- let r = L(e, this.#r);
324
+ let r = N(e, this.#r);
325
325
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
326
326
  const n = `${this.#e}${r}`;
327
327
  return this.php.fileExists(n) ? n : `${this.#e}/index.php`;
328
328
  }
329
329
  }
330
- function ne(t) {
330
+ function se(t) {
331
331
  const e = {}, r = t.match(/--(.*)\r\n/);
332
332
  if (!r)
333
333
  return e;
@@ -342,7 +342,7 @@ function ne(t) {
342
342
  }
343
343
  }), e;
344
344
  }
345
- function se(t) {
345
+ function ie(t) {
346
346
  switch (t.split(".").pop()) {
347
347
  case "css":
348
348
  return "text/css";
@@ -382,7 +382,7 @@ function se(t) {
382
382
  return "application-octet-stream";
383
383
  }
384
384
  }
385
- const N = {
385
+ const D = {
386
386
  0: "No error occurred. System call completed successfully.",
387
387
  1: "Argument list too long.",
388
388
  2: "Permission denied.",
@@ -469,8 +469,8 @@ function y(t = "") {
469
469
  return a.apply(this, i);
470
470
  } catch (o) {
471
471
  const l = typeof o == "object" ? o?.errno : null;
472
- if (l in N) {
473
- const u = N[l], d = typeof i[0] == "string" ? i[0] : null, g = d !== null ? t.replaceAll("{path}", d) : t;
472
+ if (l in D) {
473
+ const u = D[l], d = typeof i[0] == "string" ? i[0] : null, g = d !== null ? t.replaceAll("{path}", d) : t;
474
474
  throw new Error(`${g}: ${u}`, {
475
475
  cause: o
476
476
  });
@@ -480,13 +480,13 @@ function y(t = "") {
480
480
  };
481
481
  };
482
482
  }
483
- async function ie(t, e = {}, r = []) {
483
+ async function oe(t, e = {}, r = []) {
484
484
  let n, s;
485
485
  const a = new Promise((l) => {
486
486
  s = l;
487
487
  }), i = new Promise((l) => {
488
488
  n = l;
489
- }), o = t.init(ae, {
489
+ }), o = t.init(le, {
490
490
  onAbort(l) {
491
491
  console.error("WASM aborted: "), console.error(l);
492
492
  },
@@ -509,16 +509,16 @@ async function ie(t, e = {}, r = []) {
509
509
  return r.length || s(), await a, await i, O.push(o), O.length - 1;
510
510
  }
511
511
  const O = [];
512
- function oe(t) {
512
+ function ae(t) {
513
513
  return O[t];
514
514
  }
515
- const ae = function() {
515
+ const le = function() {
516
516
  return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
517
517
  }();
518
- var le = Object.defineProperty, ce = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
519
- for (var s = n > 1 ? void 0 : n ? ce(e, r) : e, a = t.length - 1, i; a >= 0; a--)
518
+ var ce = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, w = (t, e, r, n) => {
519
+ for (var s = n > 1 ? void 0 : n ? ue(e, r) : e, a = t.length - 1, i; a >= 0; a--)
520
520
  (i = t[a]) && (s = (n ? i(e, r, s) : i(s)) || s);
521
- return n && s && le(e, r, s), s;
521
+ return n && s && ce(e, r, s), s;
522
522
  };
523
523
  const f = "string", b = "number", c = Symbol("__private__dont__use");
524
524
  class m {
@@ -530,8 +530,8 @@ class m {
530
530
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
531
531
  */
532
532
  constructor(e, r) {
533
- this.#e = [], this.#t = !1, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new X(
534
- new re(this, r)
533
+ this.#e = [], this.#t = !1, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new Z(
534
+ new ne(this, r)
535
535
  ));
536
536
  }
537
537
  #e;
@@ -542,7 +542,7 @@ class m {
542
542
  }
543
543
  /** @inheritDoc */
544
544
  get documentRoot() {
545
- return this.requestHandler.requestHandler.absoluteUrl;
545
+ return this.requestHandler.requestHandler.documentRoot;
546
546
  }
547
547
  /** @inheritDoc */
548
548
  pathToInternalUrl(e) {
@@ -557,7 +557,7 @@ class m {
557
557
  initializeRuntime(e) {
558
558
  if (this[c])
559
559
  throw new Error("PHP runtime already initialized.");
560
- const r = oe(e);
560
+ const r = ae(e);
561
561
  if (!r)
562
562
  throw new Error("Invalid PHP runtime id.");
563
563
  this[c] = r;
@@ -594,7 +594,7 @@ class m {
594
594
  this.#t || (this.#s(), this.#t = !0), this.#c(e.scriptPath || ""), this.#i(e.relativeUri || ""), this.#o(e.method || "GET");
595
595
  const { host: r, ...n } = {
596
596
  host: "example.com:443",
597
- ...W(e.headers || {})
597
+ ...z(e.headers || {})
598
598
  };
599
599
  if (this.#r(r, e.protocol || "http"), this.#a(n), e.body && this.#l(e.body), e.fileInfos)
600
600
  for (const s of e.fileInfos)
@@ -856,7 +856,7 @@ w([
856
856
  w([
857
857
  y('Could not stat "{path}"')
858
858
  ], m.prototype, "fileExists", 1);
859
- function W(t) {
859
+ function z(t) {
860
860
  const e = {};
861
861
  for (const r in t)
862
862
  e[r.toLowerCase()] = t[r];
@@ -867,8 +867,8 @@ function W(t) {
867
867
  * Copyright 2019 Google LLC
868
868
  * SPDX-License-Identifier: Apache-2.0
869
869
  */
870
- const q = Symbol("Comlink.proxy"), ue = Symbol("Comlink.endpoint"), de = Symbol("Comlink.releaseProxy"), H = Symbol("Comlink.finalizer"), k = Symbol("Comlink.thrown"), z = (t) => typeof t == "object" && t !== null || typeof t == "function", he = {
871
- canHandle: (t) => z(t) && t[q],
870
+ const $ = Symbol("Comlink.proxy"), de = Symbol("Comlink.endpoint"), he = Symbol("Comlink.releaseProxy"), H = Symbol("Comlink.finalizer"), k = Symbol("Comlink.thrown"), j = (t) => typeof t == "object" && t !== null || typeof t == "function", fe = {
871
+ canHandle: (t) => j(t) && t[$],
872
872
  serialize(t) {
873
873
  const { port1: e, port2: r } = new MessageChannel();
874
874
  return F(t, e), [r, [r]];
@@ -876,8 +876,8 @@ const q = Symbol("Comlink.proxy"), ue = Symbol("Comlink.endpoint"), de = Symbol(
876
876
  deserialize(t) {
877
877
  return t.start(), I(t);
878
878
  }
879
- }, fe = {
880
- canHandle: (t) => z(t) && k in t,
879
+ }, pe = {
880
+ canHandle: (t) => j(t) && k in t,
881
881
  serialize({ value: t }) {
882
882
  let e;
883
883
  return t instanceof Error ? e = {
@@ -893,10 +893,10 @@ const q = Symbol("Comlink.proxy"), ue = Symbol("Comlink.endpoint"), de = Symbol(
893
893
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
894
894
  }
895
895
  }, S = /* @__PURE__ */ new Map([
896
- ["proxy", he],
897
- ["throw", fe]
896
+ ["proxy", fe],
897
+ ["throw", pe]
898
898
  ]);
899
- function pe(t, e) {
899
+ function me(t, e) {
900
900
  for (const r of t)
901
901
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
902
902
  return !0;
@@ -906,7 +906,7 @@ function F(t, e = globalThis, r = ["*"]) {
906
906
  e.addEventListener("message", function n(s) {
907
907
  if (!s || !s.data)
908
908
  return;
909
- if (!pe(r, s.origin)) {
909
+ if (!me(r, s.origin)) {
910
910
  console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
911
911
  return;
912
912
  }
@@ -927,13 +927,13 @@ function F(t, e = globalThis, r = ["*"]) {
927
927
  case "CONSTRUCT":
928
928
  {
929
929
  const p = new g(...l);
930
- u = G(p);
930
+ u = J(p);
931
931
  }
932
932
  break;
933
933
  case "ENDPOINT":
934
934
  {
935
935
  const { port1: p, port2: v } = new MessageChannel();
936
- F(t, v), u = Pe(p, [p]);
936
+ F(t, v), u = be(p, [p]);
937
937
  }
938
938
  break;
939
939
  case "RELEASE":
@@ -947,7 +947,7 @@ function F(t, e = globalThis, r = ["*"]) {
947
947
  }
948
948
  Promise.resolve(u).catch((d) => ({ value: d, [k]: 0 })).then((d) => {
949
949
  const [g, p] = C(d);
950
- e.postMessage(Object.assign(Object.assign({}, g), { id: a }), p), i === "RELEASE" && (e.removeEventListener("message", n), $(e), H in t && typeof t[H] == "function" && t[H]());
950
+ e.postMessage(Object.assign(Object.assign({}, g), { id: a }), p), i === "RELEASE" && (e.removeEventListener("message", n), B(e), H in t && typeof t[H] == "function" && t[H]());
951
951
  }).catch((d) => {
952
952
  const [g, p] = C({
953
953
  value: new TypeError("Unserializable return value"),
@@ -957,11 +957,11 @@ function F(t, e = globalThis, r = ["*"]) {
957
957
  });
958
958
  }), e.start && e.start();
959
959
  }
960
- function me(t) {
960
+ function ge(t) {
961
961
  return t.constructor.name === "MessagePort";
962
962
  }
963
- function $(t) {
964
- me(t) && t.close();
963
+ function B(t) {
964
+ ge(t) && t.close();
965
965
  }
966
966
  function I(t, e) {
967
967
  return U(t, [], e);
@@ -970,22 +970,22 @@ function _(t) {
970
970
  if (t)
971
971
  throw new Error("Proxy has been released and is not useable");
972
972
  }
973
- function j(t) {
973
+ function G(t) {
974
974
  return E(t, {
975
975
  type: "RELEASE"
976
976
  }).then(() => {
977
- $(t);
977
+ B(t);
978
978
  });
979
979
  }
980
980
  const x = /* @__PURE__ */ new WeakMap(), T = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
981
981
  const e = (x.get(t) || 0) - 1;
982
- x.set(t, e), e === 0 && j(t);
982
+ x.set(t, e), e === 0 && G(t);
983
983
  });
984
- function ge(t, e) {
984
+ function ye(t, e) {
985
985
  const r = (x.get(e) || 0) + 1;
986
986
  x.set(e, r), T && T.register(t, e, t);
987
987
  }
988
- function ye(t) {
988
+ function we(t) {
989
989
  T && T.unregister(t);
990
990
  }
991
991
  function U(t, e = [], r = function() {
@@ -993,9 +993,9 @@ function U(t, e = [], r = function() {
993
993
  let n = !1;
994
994
  const s = new Proxy(r, {
995
995
  get(a, i) {
996
- if (_(n), i === de)
996
+ if (_(n), i === he)
997
997
  return () => {
998
- ye(s), j(t), n = !0;
998
+ we(s), G(t), n = !0;
999
999
  };
1000
1000
  if (i === "then") {
1001
1001
  if (e.length === 0)
@@ -1020,13 +1020,13 @@ function U(t, e = [], r = function() {
1020
1020
  apply(a, i, o) {
1021
1021
  _(n);
1022
1022
  const l = e[e.length - 1];
1023
- if (l === ue)
1023
+ if (l === de)
1024
1024
  return E(t, {
1025
1025
  type: "ENDPOINT"
1026
1026
  }).then(P);
1027
1027
  if (l === "bind")
1028
1028
  return U(t, e.slice(0, -1));
1029
- const [u, d] = D(o);
1029
+ const [u, d] = W(o);
1030
1030
  return E(t, {
1031
1031
  type: "APPLY",
1032
1032
  path: e.map((g) => g.toString()),
@@ -1035,7 +1035,7 @@ function U(t, e = [], r = function() {
1035
1035
  },
1036
1036
  construct(a, i) {
1037
1037
  _(n);
1038
- const [o, l] = D(i);
1038
+ const [o, l] = W(i);
1039
1039
  return E(t, {
1040
1040
  type: "CONSTRUCT",
1041
1041
  path: e.map((u) => u.toString()),
@@ -1043,23 +1043,23 @@ function U(t, e = [], r = function() {
1043
1043
  }, l).then(P);
1044
1044
  }
1045
1045
  });
1046
- return ge(s, t), s;
1046
+ return ye(s, t), s;
1047
1047
  }
1048
- function we(t) {
1048
+ function Pe(t) {
1049
1049
  return Array.prototype.concat.apply([], t);
1050
1050
  }
1051
- function D(t) {
1051
+ function W(t) {
1052
1052
  const e = t.map(C);
1053
- return [e.map((r) => r[0]), we(e.map((r) => r[1]))];
1053
+ return [e.map((r) => r[0]), Pe(e.map((r) => r[1]))];
1054
1054
  }
1055
- const B = /* @__PURE__ */ new WeakMap();
1056
- function Pe(t, e) {
1057
- return B.set(t, e), t;
1055
+ const V = /* @__PURE__ */ new WeakMap();
1056
+ function be(t, e) {
1057
+ return V.set(t, e), t;
1058
1058
  }
1059
- function G(t) {
1060
- return Object.assign(t, { [q]: !0 });
1059
+ function J(t) {
1060
+ return Object.assign(t, { [$]: !0 });
1061
1061
  }
1062
- function V(t, e = globalThis, r = "*") {
1062
+ function Y(t, e = globalThis, r = "*") {
1063
1063
  return {
1064
1064
  postMessage: (n, s) => t.postMessage(n, r, s),
1065
1065
  addEventListener: e.addEventListener.bind(e),
@@ -1084,7 +1084,7 @@ function C(t) {
1084
1084
  type: "RAW",
1085
1085
  value: t
1086
1086
  },
1087
- B.get(t) || []
1087
+ V.get(t) || []
1088
1088
  ];
1089
1089
  }
1090
1090
  function P(t) {
@@ -1097,35 +1097,39 @@ function P(t) {
1097
1097
  }
1098
1098
  function E(t, e, r) {
1099
1099
  return new Promise((n) => {
1100
- const s = be();
1100
+ const s = Ee();
1101
1101
  t.addEventListener("message", function a(i) {
1102
1102
  !i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", a), n(i.data));
1103
1103
  }), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), r);
1104
1104
  });
1105
1105
  }
1106
- function be() {
1106
+ function Ee() {
1107
1107
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
1108
1108
  }
1109
- function ke(t) {
1110
- J();
1111
- const e = t instanceof Worker ? t : V(t);
1112
- return I(e);
1109
+ function xe(t) {
1110
+ K();
1111
+ const e = t instanceof Worker ? t : Y(t), r = I(e), n = M(r);
1112
+ return new Proxy(n, {
1113
+ get: (s, a) => a === "isConnected" ? () => r.isConnected() : r[a]
1114
+ });
1113
1115
  }
1114
- function xe(t, e) {
1115
- J();
1116
- let r;
1117
- const n = new Promise((i) => {
1118
- r = i;
1119
- }), s = Y(t), a = new Proxy(s, {
1120
- get: (i, o) => o === "isReady" ? () => n : o in i ? i[o] : e?.[o]
1116
+ function Te(t, e) {
1117
+ K();
1118
+ const r = Promise.resolve();
1119
+ let n;
1120
+ const s = new Promise((o) => {
1121
+ n = o;
1122
+ }), a = M(t), i = new Proxy(a, {
1123
+ get: (o, l) => l === "isConnected" ? () => r : l === "isReady" ? () => s : l in o ? o[l] : e?.[l]
1121
1124
  });
1122
1125
  return F(
1123
- a,
1124
- typeof window < "u" ? V(self.parent) : void 0
1125
- ), [r, a];
1126
+ i,
1127
+ typeof window < "u" ? Y(self.parent) : void 0
1128
+ ), [n, i];
1126
1129
  }
1127
- function J() {
1128
- S.set("EVENT", {
1130
+ let q = !1;
1131
+ function K() {
1132
+ q || (q = !0, S.set("EVENT", {
1129
1133
  canHandle: (t) => t instanceof CustomEvent,
1130
1134
  serialize: (t) => [
1131
1135
  {
@@ -1152,27 +1156,27 @@ function J() {
1152
1156
  deserialize(t) {
1153
1157
  return R.fromRawData(t);
1154
1158
  }
1155
- });
1159
+ }));
1156
1160
  }
1157
- function Y(t) {
1161
+ function M(t) {
1158
1162
  return new Proxy(t, {
1159
1163
  get(e, r) {
1160
1164
  switch (typeof e[r]) {
1161
1165
  case "function":
1162
1166
  return (...n) => e[r](...n);
1163
1167
  case "object":
1164
- return e[r] === null ? e[r] : Y(e[r]);
1168
+ return e[r] === null ? e[r] : M(e[r]);
1165
1169
  case "undefined":
1166
1170
  case "number":
1167
1171
  case "string":
1168
1172
  return e[r];
1169
1173
  default:
1170
- return G(e[r]);
1174
+ return J(e[r]);
1171
1175
  }
1172
1176
  }
1173
1177
  });
1174
1178
  }
1175
- async function Ee(t = Q) {
1179
+ async function Re(t = X) {
1176
1180
  switch (t) {
1177
1181
  case "8.2":
1178
1182
  return await import("php_8_2.js");
@@ -1221,11 +1225,11 @@ class A extends m {
1221
1225
  static loadSync(e, r = {}) {
1222
1226
  const n = new A(void 0, r.requestHandler), a = (async () => {
1223
1227
  const i = await Promise.all([
1224
- Ee(e),
1228
+ Re(e),
1225
1229
  ...r.dataModules || []
1226
1230
  ]), [o, ...l] = i;
1227
1231
  r.downloadMonitor?.setModules(i);
1228
- const u = await ie(
1232
+ const u = await oe(
1229
1233
  o,
1230
1234
  {
1231
1235
  ...r.emscriptenOptions || {},
@@ -1243,10 +1247,10 @@ class A extends m {
1243
1247
  }
1244
1248
  }
1245
1249
  const h = /* @__PURE__ */ new WeakMap();
1246
- class Te {
1250
+ class Ce {
1247
1251
  /** @inheritDoc */
1248
1252
  constructor(e, r) {
1249
- this.connected = Promise.resolve(), h.set(this, {
1253
+ h.set(this, {
1250
1254
  php: e,
1251
1255
  monitor: r
1252
1256
  }), this.absoluteUrl = e.absoluteUrl, this.documentRoot = e.documentRoot;
@@ -1260,7 +1264,7 @@ class Te {
1260
1264
  return h.get(this).php.internalUrlToPath(e);
1261
1265
  }
1262
1266
  async onDownloadProgress(e) {
1263
- h.get(this).monitor?.addEventListener("progress", e);
1267
+ return h.get(this).monitor?.addEventListener("progress", e);
1264
1268
  }
1265
1269
  /** @inheritDoc */
1266
1270
  mv(e, r) {
@@ -1288,15 +1292,15 @@ class Te {
1288
1292
  }
1289
1293
  /** @inheritDoc @php-wasm/web!WebPHP.setPhpIniEntry */
1290
1294
  setPhpIniEntry(e, r) {
1291
- h.get(this).php.setPhpIniEntry(e, r);
1295
+ return h.get(this).php.setPhpIniEntry(e, r);
1292
1296
  }
1293
1297
  /** @inheritDoc @php-wasm/web!WebPHP.mkdir */
1294
1298
  mkdir(e) {
1295
- h.get(this).php.mkdir(e);
1299
+ return h.get(this).php.mkdir(e);
1296
1300
  }
1297
1301
  /** @inheritDoc @php-wasm/web!WebPHP.mkdirTree */
1298
1302
  mkdirTree(e) {
1299
- h.get(this).php.mkdirTree(e);
1303
+ return h.get(this).php.mkdirTree(e);
1300
1304
  }
1301
1305
  /** @inheritDoc @php-wasm/web!WebPHP.readFileAsText */
1302
1306
  readFileAsText(e) {
@@ -1308,11 +1312,11 @@ class Te {
1308
1312
  }
1309
1313
  /** @inheritDoc @php-wasm/web!WebPHP.writeFile */
1310
1314
  writeFile(e, r) {
1311
- h.get(this).php.writeFile(e, r);
1315
+ return h.get(this).php.writeFile(e, r);
1312
1316
  }
1313
1317
  /** @inheritDoc @php-wasm/web!WebPHP.unlink */
1314
1318
  unlink(e) {
1315
- h.get(this).php.unlink(e);
1319
+ return h.get(this).php.unlink(e);
1316
1320
  }
1317
1321
  /** @inheritDoc @php-wasm/web!WebPHP.listFiles */
1318
1322
  listFiles(e) {
@@ -1327,20 +1331,20 @@ class Te {
1327
1331
  return h.get(this).php.fileExists(e);
1328
1332
  }
1329
1333
  }
1330
- function Re(t, e) {
1334
+ function ve(t, e) {
1331
1335
  return {
1332
1336
  type: "response",
1333
1337
  requestId: t,
1334
1338
  response: e
1335
1339
  };
1336
1340
  }
1337
- async function Ce(t, e, r, n) {
1341
+ async function Fe(t, e, r, n) {
1338
1342
  const s = navigator.serviceWorker;
1339
1343
  if (!s)
1340
1344
  throw new Error("Service workers are not supported in this browser.");
1341
1345
  const a = await s.getRegistrations();
1342
1346
  if (a.length > 0) {
1343
- const i = await ve();
1347
+ const i = await Se();
1344
1348
  if (n !== i) {
1345
1349
  console.debug(
1346
1350
  `[window] Reloading the currently registered Service Worker (expected version: ${n}, registered version: ${i})`
@@ -1368,34 +1372,34 @@ async function Ce(t, e, r, n) {
1368
1372
  if (console.debug("Message from ServiceWorker", o), e && o.data.scope !== e)
1369
1373
  return;
1370
1374
  const l = o.data.args || [], u = o.data.method, d = await t[u](...l);
1371
- o.source.postMessage(Re(o.data.requestId, d));
1375
+ o.source.postMessage(ve(o.data.requestId, d));
1372
1376
  }
1373
1377
  ), s.startMessages();
1374
1378
  }
1375
- async function ve() {
1379
+ async function Se() {
1376
1380
  try {
1377
1381
  return (await (await fetch("/version")).json()).version;
1378
1382
  } catch {
1379
1383
  return null;
1380
1384
  }
1381
1385
  }
1382
- function Fe() {
1386
+ function He() {
1383
1387
  const t = {};
1384
1388
  return typeof self?.location?.href < "u" && new URL(self.location.href).searchParams.forEach((r, n) => {
1385
1389
  t[n] = r;
1386
1390
  }), t;
1387
1391
  }
1388
- const He = function() {
1392
+ const Oe = function() {
1389
1393
  return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
1390
1394
  }();
1391
- async function Oe(t, e = "webworker", r = {}) {
1392
- if (t = Se(t, r), e === "webworker")
1395
+ async function Ue(t, e = "webworker", r = {}) {
1396
+ if (t = _e(t, r), e === "webworker")
1393
1397
  return new Worker(t, { type: "module" });
1394
1398
  if (e === "iframe")
1395
- return (await _e(t)).contentWindow;
1399
+ return (await ke(t)).contentWindow;
1396
1400
  throw new Error(`Unknown backendName: ${e}`);
1397
1401
  }
1398
- function Se(t, e) {
1402
+ function _e(t, e) {
1399
1403
  if (!Object.entries(e).length)
1400
1404
  return t + "";
1401
1405
  const r = new URL(t);
@@ -1403,7 +1407,7 @@ function Se(t, e) {
1403
1407
  r.searchParams.set(n, s);
1404
1408
  return r.toString();
1405
1409
  }
1406
- async function _e(t) {
1410
+ async function ke(t) {
1407
1411
  const e = document.createElement("iframe"), r = "/" + t.split("/").slice(-1)[0];
1408
1412
  return e.src = r, e.style.display = "none", document.body.appendChild(e), await new Promise((n) => {
1409
1413
  e.addEventListener("load", n);
@@ -1411,12 +1415,12 @@ async function _e(t) {
1411
1415
  }
1412
1416
  export {
1413
1417
  A as WebPHP,
1414
- Te as WebPHPEndpoint,
1415
- ke as consumeAPI,
1416
- xe as exposeAPI,
1417
- Ee as getPHPLoaderModule,
1418
- Fe as parseWorkerStartupOptions,
1419
- He as recommendedWorkerBackend,
1420
- Ce as registerServiceWorker,
1421
- Oe as spawnPHPWorkerThread
1418
+ Ce as WebPHPEndpoint,
1419
+ xe as consumeAPI,
1420
+ Te as exposeAPI,
1421
+ Re as getPHPLoaderModule,
1422
+ He as parseWorkerStartupOptions,
1423
+ Oe as recommendedWorkerBackend,
1424
+ Fe as registerServiceWorker,
1425
+ Ue as spawnPHPWorkerThread
1422
1426
  };
package/index.d.ts CHANGED
@@ -3,11 +3,19 @@
3
3
  import * as Comlink from 'comlink';
4
4
  import { Remote } from 'comlink';
5
5
 
6
- export type WithIsReady = {
7
- /** Resolves to true when the remote API is ready to be used */
6
+ export type WithAPIState = {
7
+ /**
8
+ * Resolves to true when the remote API is ready for
9
+ * Comlink communication, but not necessarily fully initialized yet.
10
+ */
11
+ isConnected: () => Promise<void>;
12
+ /**
13
+ * Resolves to true when the remote API is declares it's
14
+ * fully loaded and ready to be used.
15
+ */
8
16
  isReady: () => Promise<void>;
9
17
  };
10
- export type RemoteAPI<T> = Comlink.Remote<T & WithIsReady>;
18
+ export type RemoteAPI<T> = Comlink.Remote<T & WithAPIState>;
11
19
  export declare function consumeAPI<APIType>(remote: Worker | Window): RemoteAPI<APIType>;
12
20
  export type PublicAPI<Methods, PipedAPI = unknown> = RemoteAPI<Methods & PipedAPI>;
13
21
  export declare function exposeAPI<Methods, PipedAPI>(apiMethods?: Methods, pipedApi?: PipedAPI): [
@@ -160,7 +168,8 @@ export interface RequestHandler {
160
168
  */
161
169
  absoluteUrl: string;
162
170
  /**
163
- * The absolute URL of this PHPRequestHandler instance.
171
+ * The directory in the PHP filesystem where the server will look
172
+ * for the files to serve. Default: `/var/www`.
164
173
  */
165
174
  documentRoot: string;
166
175
  }
@@ -576,11 +585,6 @@ export declare class WebPHP extends BasePHP {
576
585
  * A PHP client that can be used to run PHP code in the browser.
577
586
  */
578
587
  export declare class WebPHPEndpoint implements IsomorphicLocalPHP {
579
- /**
580
- * A dummy promise that resolves immediately.
581
- * Used to assert that the PHPClient is ready for communication.
582
- */
583
- connected: Promise<void>;
584
588
  /** @inheritDoc */
585
589
  absoluteUrl: string;
586
590
  /** @inheritDoc */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.1.32",
3
+ "version": "0.1.35",
4
4
  "description": "PHP.wasm for the web",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,5 +29,5 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "868bafca7e77ad31e30c1500a0d4da8b1c2314cc"
32
+ "gitHead": "0962f89a2b1a438997960a25c26f5341db063a3e"
33
33
  }