@php-wasm/web 0.5.1 → 0.5.3

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
@@ -1,14 +1,73 @@
1
- var pe = (t, e, r) => {
1
+ var me = (t, e, r) => {
2
2
  if (!e.has(t))
3
3
  throw TypeError("Cannot " + r);
4
4
  };
5
- var c = (t, e, r) => (pe(t, e, "read from private field"), r ? r.call(t) : e.get(t)), d = (t, e, r) => {
5
+ var c = (t, e, r) => (me(t, e, "read from private field"), r ? r.call(t) : e.get(t)), d = (t, e, r) => {
6
6
  if (e.has(t))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
8
  e instanceof WeakSet ? e.add(t) : e.set(t, r);
9
- }, g = (t, e, r, n) => (pe(t, e, "write to private field"), n ? n.call(t, r) : e.set(t, r), r);
10
- var y = (t, e, r) => (pe(t, e, "access private method"), r);
11
- const ve = Symbol("error"), xe = Symbol("message");
9
+ }, y = (t, e, r, n) => (me(t, e, "write to private field"), n ? n.call(t, r) : e.set(t, r), r);
10
+ var g = (t, e, r) => (me(t, e, "access private method"), r);
11
+ if (typeof File > "u") {
12
+ class t extends Blob {
13
+ constructor(r, n, s) {
14
+ super(r);
15
+ let o;
16
+ s != null && s.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = n || "";
17
+ }
18
+ }
19
+ global.File = t;
20
+ }
21
+ function Me(t) {
22
+ return new Promise(function(e, r) {
23
+ t.onload = t.onerror = function(n) {
24
+ t.onload = t.onerror = null, n.type === "load" ? e(t.result) : r(new Error("Failed to read the blob/file"));
25
+ };
26
+ });
27
+ }
28
+ typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
29
+ const e = new FileReader();
30
+ return e.readAsArrayBuffer(this), Me(e);
31
+ });
32
+ typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
33
+ const e = new FileReader();
34
+ return e.readAsText(this), Me(e);
35
+ });
36
+ function ot() {
37
+ const t = new Uint8Array([1, 2, 3, 4]), r = new File([t], "test").stream();
38
+ try {
39
+ return r.getReader({ mode: "byob" }), r.getReader({ mode: "byob" }), !0;
40
+ } catch {
41
+ return !1;
42
+ }
43
+ }
44
+ (typeof Blob.prototype.stream > "u" || !ot()) && (Blob.prototype.stream = function() {
45
+ let t = 0;
46
+ const e = this;
47
+ return new ReadableStream({
48
+ type: "bytes",
49
+ // 0.5 MB seems like a reasonable chunk size, let's adjust
50
+ // this if needed.
51
+ autoAllocateChunkSize: 512 * 1024,
52
+ async pull(r) {
53
+ const n = r.byobRequest.view, o = await e.slice(t, t + n.byteLength).arrayBuffer(), i = new Uint8Array(o);
54
+ new Uint8Array(n.buffer).set(i);
55
+ const a = i.byteLength;
56
+ r.byobRequest.respond(a), t += a, t >= e.size && r.close();
57
+ }
58
+ });
59
+ });
60
+ if (typeof CustomEvent > "u") {
61
+ class t extends Event {
62
+ constructor(r, n = {}) {
63
+ super(r, n), this.detail = n.detail;
64
+ }
65
+ initCustomEvent() {
66
+ }
67
+ }
68
+ globalThis.CustomEvent = t;
69
+ }
70
+ const Re = Symbol("error"), xe = Symbol("message");
12
71
  class Pe extends Event {
13
72
  /**
14
73
  * Create a new `ErrorEvent`.
@@ -18,10 +77,10 @@ class Pe extends Event {
18
77
  * attributes via object members of the same name.
19
78
  */
20
79
  constructor(e, r = {}) {
21
- super(e), this[ve] = r.error === void 0 ? null : r.error, this[xe] = r.message === void 0 ? "" : r.message;
80
+ super(e), this[Re] = r.error === void 0 ? null : r.error, this[xe] = r.message === void 0 ? "" : r.message;
22
81
  }
23
82
  get error() {
24
- return this[ve];
83
+ return this[Re];
25
84
  }
26
85
  get message() {
27
86
  return this[xe];
@@ -29,11 +88,11 @@ class Pe extends Event {
29
88
  }
30
89
  Object.defineProperty(Pe.prototype, "error", { enumerable: !0 });
31
90
  Object.defineProperty(Pe.prototype, "message", { enumerable: !0 });
32
- const it = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : Pe;
33
- function ot(t) {
91
+ const at = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : Pe;
92
+ function ct(t) {
34
93
  return t instanceof Error ? "exitCode" in t && (t == null ? void 0 : t.exitCode) === 0 || (t == null ? void 0 : t.name) === "ExitStatus" && "status" in t && t.status === 0 : !1;
35
94
  }
36
- class at extends EventTarget {
95
+ class lt extends EventTarget {
37
96
  constructor() {
38
97
  super(...arguments), this.listenersCount = 0;
39
98
  }
@@ -47,11 +106,11 @@ class at extends EventTarget {
47
106
  return this.listenersCount > 0;
48
107
  }
49
108
  }
50
- function ct(t) {
109
+ function ut(t) {
51
110
  t.asm = {
52
111
  ...t.asm
53
112
  };
54
- const e = new at();
113
+ const e = new lt();
55
114
  for (const r in t.asm)
56
115
  if (typeof t.asm[r] == "function") {
57
116
  const n = t.asm[r];
@@ -62,38 +121,38 @@ function ct(t) {
62
121
  } catch (i) {
63
122
  if (!(i instanceof Error))
64
123
  throw i;
65
- const a = ut(
124
+ const a = dt(
66
125
  i,
67
126
  (o = t.lastAsyncifyStackSource) == null ? void 0 : o.stack
68
127
  );
69
128
  if (t.lastAsyncifyStackSource && (i.cause = t.lastAsyncifyStackSource), e.hasListeners()) {
70
129
  e.dispatchEvent(
71
- new it("error", {
130
+ new at("error", {
72
131
  error: i,
73
132
  message: a
74
133
  })
75
134
  );
76
135
  return;
77
136
  }
78
- throw ot(i) || ft(a), i;
137
+ throw ct(i) || mt(a), i;
79
138
  }
80
139
  };
81
140
  }
82
141
  return e;
83
142
  }
84
143
  let ge = [];
85
- function lt() {
144
+ function ht() {
86
145
  return ge;
87
146
  }
88
- function ut(t, e) {
147
+ function dt(t, e) {
89
148
  if (t.message === "unreachable") {
90
- let r = ht;
149
+ let r = ft;
91
150
  e || (r += `
92
151
 
93
152
  This stack trace is lacking. For a better one initialize
94
153
  the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
95
154
 
96
- `), ge = pt(
155
+ `), ge = yt(
97
156
  e || t.stack || ""
98
157
  );
99
158
  for (const n of ge)
@@ -103,7 +162,7 @@ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
103
162
  }
104
163
  return t.message;
105
164
  }
106
- const ht = `
165
+ const ft = `
107
166
  "unreachable" WASM instruction executed.
108
167
 
109
168
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -127,20 +186,20 @@ the Dockerfile, you'll need to trigger this error again with long stack
127
186
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
128
187
  CLI option:
129
188
 
130
- `, ke = "\x1B[41m", dt = "\x1B[1m", Re = "\x1B[0m", Se = "\x1B[K";
131
- let _e = !1;
132
- function ft(t) {
133
- if (!_e) {
134
- _e = !0, console.log(`${ke}
135
- ${Se}
136
- ${dt} WASM ERROR${Re}${ke}`);
189
+ `, Se = "\x1B[41m", pt = "\x1B[1m", ke = "\x1B[0m", _e = "\x1B[K";
190
+ let Te = !1;
191
+ function mt(t) {
192
+ if (!Te) {
193
+ Te = !0, console.log(`${Se}
194
+ ${_e}
195
+ ${pt} WASM ERROR${ke}${Se}`);
137
196
  for (const e of t.split(`
138
197
  `))
139
- console.log(`${Se} ${e} `);
140
- console.log(`${Re}`);
198
+ console.log(`${_e} ${e} `);
199
+ console.log(`${ke}`);
141
200
  }
142
201
  }
143
- function pt(t) {
202
+ function yt(t) {
144
203
  try {
145
204
  const e = t.split(`
146
205
  `).slice(1).map((r) => {
@@ -157,12 +216,54 @@ function pt(t) {
157
216
  return [];
158
217
  }
159
218
  }
160
- class A {
219
+ class Oe {
220
+ constructor({ concurrency: e }) {
221
+ this._running = 0, this.concurrency = e, this.queue = [];
222
+ }
223
+ get running() {
224
+ return this._running;
225
+ }
226
+ async acquire() {
227
+ for (; ; )
228
+ if (this._running >= this.concurrency)
229
+ await new Promise((e) => this.queue.push(e));
230
+ else {
231
+ this._running++;
232
+ let e = !1;
233
+ return () => {
234
+ e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
235
+ };
236
+ }
237
+ }
238
+ async run(e) {
239
+ const r = await this.acquire();
240
+ try {
241
+ return await e();
242
+ } finally {
243
+ r();
244
+ }
245
+ }
246
+ }
247
+ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
248
+ const t = this.getReader();
249
+ try {
250
+ for (; ; ) {
251
+ const { done: e, value: r } = await t.read();
252
+ if (e)
253
+ return;
254
+ yield r;
255
+ }
256
+ } finally {
257
+ t.releaseLock();
258
+ }
259
+ }, ReadableStream.prototype.iterate = // @ts-ignore
260
+ ReadableStream.prototype[Symbol.asyncIterator]);
261
+ class L {
161
262
  constructor(e, r, n, s = "", o = 0) {
162
263
  this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = o, this.errors = s;
163
264
  }
164
265
  static fromRawData(e) {
165
- return new A(
266
+ return new L(
166
267
  e.httpStatusCode,
167
268
  e.headers,
168
269
  e.bytes,
@@ -192,7 +293,7 @@ class A {
192
293
  return new TextDecoder().decode(this.bytes);
193
294
  }
194
295
  }
195
- const mt = [
296
+ const gt = [
196
297
  "8.3",
197
298
  "8.2",
198
299
  "8.1",
@@ -202,9 +303,9 @@ const mt = [
202
303
  "7.2",
203
304
  "7.1",
204
305
  "7.0"
205
- ], gt = mt[0];
306
+ ], wt = gt[0];
206
307
  var C, I;
207
- class yt {
308
+ class bt {
208
309
  /**
209
310
  * @param server - The PHP server to browse.
210
311
  * @param config - The browser configuration.
@@ -212,7 +313,7 @@ class yt {
212
313
  constructor(e, r = {}) {
213
314
  d(this, C, void 0);
214
315
  d(this, I, void 0);
215
- this.requestHandler = e, g(this, C, {}), g(this, I, {
316
+ this.requestHandler = e, y(this, C, {}), y(this, I, {
216
317
  handleRedirects: !1,
217
318
  maxRedirects: 4,
218
319
  ...r
@@ -291,46 +392,18 @@ class yt {
291
392
  }
292
393
  }
293
394
  C = new WeakMap(), I = new WeakMap();
294
- class Me {
295
- constructor({ concurrency: e }) {
296
- this._running = 0, this.concurrency = e, this.queue = [];
297
- }
298
- get running() {
299
- return this._running;
300
- }
301
- async acquire() {
302
- for (; ; )
303
- if (this._running >= this.concurrency)
304
- await new Promise((e) => this.queue.push(e));
305
- else {
306
- this._running++;
307
- let e = !1;
308
- return () => {
309
- e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
310
- };
311
- }
312
- }
313
- async run(e) {
314
- const r = await this.acquire();
315
- try {
316
- return await e();
317
- } finally {
318
- r();
319
- }
320
- }
321
- }
322
- const wt = "http://example.com";
323
- function Te(t) {
395
+ const Pt = "http://example.com";
396
+ function Ce(t) {
324
397
  return t.toString().substring(t.origin.length);
325
398
  }
326
- function Ce(t, e) {
399
+ function Fe(t, e) {
327
400
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
328
401
  }
329
- function Pt(t, e) {
402
+ function Et(t, e) {
330
403
  return !e || t.startsWith(e) ? t : e + t;
331
404
  }
332
- var x, N, j, H, U, k, $, W, X, Oe, Z, Ie, ee, Ne;
333
- class Et {
405
+ var E, N, z, F, U, v, $, W, Z, Ie, ee, Ne, te, Ue;
406
+ class vt {
334
407
  /**
335
408
  * @param php - The PHP instance.
336
409
  * @param config - Request Handler configuration.
@@ -342,7 +415,7 @@ class Et {
342
415
  * @param fsPath - Absolute path of the static file to serve.
343
416
  * @returns The response.
344
417
  */
345
- d(this, X);
418
+ d(this, Z);
346
419
  /**
347
420
  * Runs the requested PHP file with all the request and $_SERVER
348
421
  * superglobals populated.
@@ -350,7 +423,7 @@ class Et {
350
423
  * @param request - The request.
351
424
  * @returns The response.
352
425
  */
353
- d(this, Z);
426
+ d(this, ee);
354
427
  /**
355
428
  * Resolve the requested path to the filesystem path of the requested PHP file.
356
429
  *
@@ -360,31 +433,31 @@ class Et {
360
433
  * @throws {Error} If the requested path doesn't exist.
361
434
  * @returns The resolved filesystem path.
362
435
  */
363
- d(this, ee);
364
- d(this, x, void 0);
436
+ d(this, te);
437
+ d(this, E, void 0);
365
438
  d(this, N, void 0);
366
- d(this, j, void 0);
367
- d(this, H, void 0);
439
+ d(this, z, void 0);
440
+ d(this, F, void 0);
368
441
  d(this, U, void 0);
369
- d(this, k, void 0);
442
+ d(this, v, void 0);
370
443
  d(this, $, void 0);
371
444
  d(this, W, void 0);
372
- g(this, W, new Me({ concurrency: 1 }));
445
+ y(this, W, new Oe({ concurrency: 1 }));
373
446
  const {
374
447
  documentRoot: n = "/www/",
375
448
  absoluteUrl: s = typeof location == "object" ? location == null ? void 0 : location.href : ""
376
449
  } = r;
377
- this.php = e, g(this, x, n);
450
+ this.php = e, y(this, E, n);
378
451
  const o = new URL(s);
379
- g(this, j, o.hostname), g(this, H, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), g(this, N, (o.protocol || "").replace(":", ""));
380
- const i = c(this, H) !== 443 && c(this, H) !== 80;
381
- g(this, U, [
382
- c(this, j),
383
- i ? `:${c(this, H)}` : ""
384
- ].join("")), g(this, k, o.pathname.replace(/\/+$/, "")), g(this, $, [
452
+ y(this, z, o.hostname), y(this, F, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), y(this, N, (o.protocol || "").replace(":", ""));
453
+ const i = c(this, F) !== 443 && c(this, F) !== 80;
454
+ y(this, U, [
455
+ c(this, z),
456
+ i ? `:${c(this, F)}` : ""
457
+ ].join("")), y(this, v, o.pathname.replace(/\/+$/, "")), y(this, $, [
385
458
  `${c(this, N)}://`,
386
459
  c(this, U),
387
- c(this, k)
460
+ c(this, v)
388
461
  ].join(""));
389
462
  }
390
463
  /** @inheritDoc */
@@ -394,7 +467,7 @@ class Et {
394
467
  /** @inheritDoc */
395
468
  internalUrlToPath(e) {
396
469
  const r = new URL(e);
397
- return r.pathname.startsWith(c(this, k)) && (r.pathname = r.pathname.slice(c(this, k).length)), Te(r);
470
+ return r.pathname.startsWith(c(this, v)) && (r.pathname = r.pathname.slice(c(this, v).length)), Ce(r);
398
471
  }
399
472
  get isRequestRunning() {
400
473
  return c(this, W).running > 0;
@@ -405,23 +478,23 @@ class Et {
405
478
  }
406
479
  /** @inheritDoc */
407
480
  get documentRoot() {
408
- return c(this, x);
481
+ return c(this, E);
409
482
  }
410
483
  /** @inheritDoc */
411
484
  async request(e) {
412
485
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL(
413
486
  e.url,
414
- r ? void 0 : wt
415
- ), s = Ce(
487
+ r ? void 0 : Pt
488
+ ), s = Fe(
416
489
  n.pathname,
417
- c(this, k)
418
- ), o = `${c(this, x)}${s}`;
419
- return xt(o) ? await y(this, Z, Ie).call(this, e, n) : y(this, X, Oe).call(this, o);
490
+ c(this, v)
491
+ ), o = `${c(this, E)}${s}`;
492
+ return St(o) ? await g(this, ee, Ne).call(this, e, n) : g(this, Z, Ie).call(this, o);
420
493
  }
421
494
  }
422
- x = new WeakMap(), N = new WeakMap(), j = new WeakMap(), H = new WeakMap(), U = new WeakMap(), k = new WeakMap(), $ = new WeakMap(), W = new WeakMap(), X = new WeakSet(), Oe = function(e) {
495
+ E = new WeakMap(), N = new WeakMap(), z = new WeakMap(), F = new WeakMap(), U = new WeakMap(), v = new WeakMap(), $ = new WeakMap(), W = new WeakMap(), Z = new WeakSet(), Ie = function(e) {
423
496
  if (!this.php.fileExists(e))
424
- return new A(
497
+ return new L(
425
498
  404,
426
499
  // Let the service worker know that no static file was found
427
500
  // and that it's okay to issue a real fetch() to the server.
@@ -431,31 +504,31 @@ x = new WeakMap(), N = new WeakMap(), j = new WeakMap(), H = new WeakMap(), U =
431
504
  new TextEncoder().encode("404 File not found")
432
505
  );
433
506
  const r = this.php.readFileAsBuffer(e);
434
- return new A(
507
+ return new L(
435
508
  200,
436
509
  {
437
510
  "content-length": [`${r.byteLength}`],
438
511
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
439
512
  // The code below won't return the correct mime-type if the extension
440
513
  // was tampered with.
441
- "content-type": [vt(e)],
514
+ "content-type": [xt(e)],
442
515
  "accept-ranges": ["bytes"],
443
516
  "cache-control": ["public, max-age=0"]
444
517
  },
445
518
  r
446
519
  );
447
- }, Z = new WeakSet(), Ie = async function(e, r) {
520
+ }, ee = new WeakSet(), Ne = async function(e, r) {
448
521
  var s;
449
522
  const n = await c(this, W).acquire();
450
523
  try {
451
- this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, x)), this.php.addServerGlobalEntry(
524
+ this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, E)), this.php.addServerGlobalEntry(
452
525
  "HTTPS",
453
526
  c(this, $).startsWith("https://") ? "on" : ""
454
527
  );
455
528
  let o = "GET";
456
529
  const i = {
457
530
  host: c(this, U),
458
- ...Ke(e.headers || {})
531
+ ...Qe(e.headers || {})
459
532
  }, a = [];
460
533
  if (e.files && Object.keys(e.files).length) {
461
534
  o = "POST";
@@ -468,7 +541,7 @@ x = new WeakMap(), N = new WeakMap(), j = new WeakMap(), H = new WeakMap(), U =
468
541
  data: new Uint8Array(await m.arrayBuffer())
469
542
  });
470
543
  }
471
- (s = i["content-type"]) != null && s.startsWith("multipart/form-data") && (e.formData = bt(
544
+ (s = i["content-type"]) != null && s.startsWith("multipart/form-data") && (e.formData = Rt(
472
545
  e.body || ""
473
546
  ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
474
547
  }
@@ -478,18 +551,18 @@ x = new WeakMap(), N = new WeakMap(), j = new WeakMap(), H = new WeakMap(), U =
478
551
  ).toString()) : u = e.body;
479
552
  let l;
480
553
  try {
481
- l = y(this, ee, Ne).call(this, r.pathname);
554
+ l = g(this, te, Ue).call(this, r.pathname);
482
555
  } catch {
483
- return new A(
556
+ return new L(
484
557
  404,
485
558
  {},
486
559
  new TextEncoder().encode("404 File not found")
487
560
  );
488
561
  }
489
562
  return await this.php.run({
490
- relativeUri: Pt(
491
- Te(r),
492
- c(this, k)
563
+ relativeUri: Et(
564
+ Ce(r),
565
+ c(this, v)
493
566
  ),
494
567
  protocol: c(this, N),
495
568
  method: e.method || o,
@@ -501,17 +574,17 @@ x = new WeakMap(), N = new WeakMap(), j = new WeakMap(), H = new WeakMap(), U =
501
574
  } finally {
502
575
  n();
503
576
  }
504
- }, ee = new WeakSet(), Ne = function(e) {
505
- let r = Ce(e, c(this, k));
577
+ }, te = new WeakSet(), Ue = function(e) {
578
+ let r = Fe(e, c(this, v));
506
579
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
507
- const n = `${c(this, x)}${r}`;
580
+ const n = `${c(this, E)}${r}`;
508
581
  if (this.php.fileExists(n))
509
582
  return n;
510
- if (!this.php.fileExists(`${c(this, x)}/index.php`))
583
+ if (!this.php.fileExists(`${c(this, E)}/index.php`))
511
584
  throw new Error(`File not found: ${n}`);
512
- return `${c(this, x)}/index.php`;
585
+ return `${c(this, E)}/index.php`;
513
586
  };
514
- function bt(t) {
587
+ function Rt(t) {
515
588
  const e = {}, r = t.match(/--(.*)\r\n/);
516
589
  if (!r)
517
590
  return e;
@@ -526,7 +599,7 @@ function bt(t) {
526
599
  }
527
600
  }), e;
528
601
  }
529
- function vt(t) {
602
+ function xt(t) {
530
603
  switch (t.split(".").pop()) {
531
604
  case "css":
532
605
  return "text/css";
@@ -566,16 +639,16 @@ function vt(t) {
566
639
  return "application-octet-stream";
567
640
  }
568
641
  }
569
- function xt(t) {
570
- return kt(t) || Rt(t);
642
+ function St(t) {
643
+ return kt(t) || _t(t);
571
644
  }
572
645
  function kt(t) {
573
646
  return t.endsWith(".php") || t.includes(".php/");
574
647
  }
575
- function Rt(t) {
648
+ function _t(t) {
576
649
  return !t.split("/").pop().includes(".");
577
650
  }
578
- const He = {
651
+ const J = {
579
652
  0: "No error occurred. System call completed successfully.",
580
653
  1: "Argument list too long.",
581
654
  2: "Permission denied.",
@@ -654,7 +727,12 @@ const He = {
654
727
  75: "Cross-device link.",
655
728
  76: "Extension: Capabilities insufficient."
656
729
  };
657
- function b(t = "") {
730
+ function Tt(t) {
731
+ const e = typeof t == "object" ? t == null ? void 0 : t.errno : null;
732
+ if (e in J)
733
+ return J[e];
734
+ }
735
+ function R(t = "") {
658
736
  return function(r, n, s) {
659
737
  const o = s.value;
660
738
  s.value = function(...i) {
@@ -662,8 +740,8 @@ function b(t = "") {
662
740
  return o.apply(this, i);
663
741
  } catch (a) {
664
742
  const u = typeof a == "object" ? a == null ? void 0 : a.errno : null;
665
- if (u in He) {
666
- const l = He[u], h = typeof i[0] == "string" ? i[0] : null, m = h !== null ? t.replaceAll("{path}", h) : t;
743
+ if (u in J) {
744
+ const l = J[u], h = typeof i[0] == "string" ? i[0] : null, m = h !== null ? t.replaceAll("{path}", h) : t;
667
745
  throw new Error(`${m}: ${l}`, {
668
746
  cause: a
669
747
  });
@@ -673,9 +751,9 @@ function b(t = "") {
673
751
  };
674
752
  };
675
753
  }
676
- const St = Symbol("RuntimeId"), V = /* @__PURE__ */ new Map();
677
- async function _t(t, e = {}, r = []) {
678
- const [n, s, o] = Fe(), [i, a] = Fe(), u = t.init(Ct, {
754
+ const Ct = Symbol("RuntimeId"), V = /* @__PURE__ */ new Map();
755
+ async function Ft(t, e = {}, r = []) {
756
+ const [n, s, o] = He(), [i, a] = He(), u = t.init(At, {
679
757
  onAbort(h) {
680
758
  o(h), a(), console.error(h);
681
759
  },
@@ -701,28 +779,28 @@ async function _t(t, e = {}, r = []) {
701
779
  const l = V.size;
702
780
  return u.originalExit = u._exit, u._exit = function(h) {
703
781
  return V.delete(l), u.originalExit(h);
704
- }, u[St] = l, V.set(l, u), l;
782
+ }, u[Ct] = l, V.set(l, u), l;
705
783
  }
706
- function Tt(t) {
784
+ function Ht(t) {
707
785
  return V.get(t);
708
786
  }
709
- const Ct = function() {
787
+ const At = function() {
710
788
  var t;
711
789
  return typeof process < "u" && ((t = process.release) == null ? void 0 : t.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
712
- }(), Fe = () => {
790
+ }(), He = () => {
713
791
  const t = [], e = new Promise((r, n) => {
714
792
  t.push(r, n);
715
793
  });
716
794
  return t.unshift(e), t;
717
795
  };
718
- var Ht = Object.defineProperty, Ft = Object.getOwnPropertyDescriptor, v = (t, e, r, n) => {
719
- for (var s = n > 1 ? void 0 : n ? Ft(e, r) : e, o = t.length - 1, i; o >= 0; o--)
796
+ var Lt = Object.defineProperty, Mt = Object.getOwnPropertyDescriptor, x = (t, e, r, n) => {
797
+ for (var s = n > 1 ? void 0 : n ? Mt(e, r) : e, o = t.length - 1, i; o >= 0; o--)
720
798
  (i = t[o]) && (s = (n ? i(e, r, s) : i(s)) || s);
721
- return n && s && Ht(e, r, s), s;
799
+ return n && s && Lt(e, r, s), s;
722
800
  };
723
801
  const w = "string", M = "number", f = Symbol("__private__dont__use");
724
- var F, S, L, _, R, D, B, te, Ue, re, $e, ne, We, se, De, ie, qe, oe, ze, ae, je, ce, Be, le, Ge, ue, Ve, he, Ye, de, Je;
725
- class E {
802
+ var H, k, A, _, S, B, j, re, $e, ne, We, se, Be, ie, De, oe, qe, ae, ze, ce, je, le, Ge, ue, Ve, he, Ye, de, Je, fe, Ke;
803
+ class P {
726
804
  /**
727
805
  * Initializes a PHP runtime.
728
806
  *
@@ -731,7 +809,6 @@ class E {
731
809
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
732
810
  */
733
811
  constructor(e, r) {
734
- d(this, te);
735
812
  d(this, re);
736
813
  d(this, ne);
737
814
  d(this, se);
@@ -740,6 +817,7 @@ class E {
740
817
  d(this, ae);
741
818
  d(this, ce);
742
819
  d(this, le);
820
+ d(this, ue);
743
821
  /**
744
822
  * Adds file information to $_FILES superglobal in PHP.
745
823
  *
@@ -749,36 +827,36 @@ class E {
749
827
  *
750
828
  * @param fileInfo - File details
751
829
  */
752
- d(this, ue);
753
830
  d(this, he);
754
831
  d(this, de);
755
- d(this, F, void 0);
756
- d(this, S, void 0);
757
- d(this, L, void 0);
832
+ d(this, fe);
833
+ d(this, H, void 0);
834
+ d(this, k, void 0);
835
+ d(this, A, void 0);
758
836
  d(this, _, void 0);
759
- d(this, R, void 0);
760
- d(this, D, void 0);
837
+ d(this, S, void 0);
761
838
  d(this, B, void 0);
762
- g(this, F, []), g(this, S, !1), g(this, L, null), g(this, _, {}), g(this, R, /* @__PURE__ */ new Map()), g(this, D, []), g(this, B, new Me({ concurrency: 1 })), e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new yt(
763
- new Et(this, r)
839
+ d(this, j, void 0);
840
+ y(this, H, []), y(this, k, !1), y(this, A, null), y(this, _, {}), y(this, S, /* @__PURE__ */ new Map()), y(this, B, []), y(this, j, new Oe({ concurrency: 1 })), e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new bt(
841
+ new vt(this, r)
764
842
  ));
765
843
  }
766
844
  addEventListener(e, r) {
767
- c(this, R).has(e) || c(this, R).set(e, /* @__PURE__ */ new Set()), c(this, R).get(e).add(r);
845
+ c(this, S).has(e) || c(this, S).set(e, /* @__PURE__ */ new Set()), c(this, S).get(e).add(r);
768
846
  }
769
847
  removeEventListener(e, r) {
770
848
  var n;
771
- (n = c(this, R).get(e)) == null || n.delete(r);
849
+ (n = c(this, S).get(e)) == null || n.delete(r);
772
850
  }
773
851
  dispatchEvent(e) {
774
- const r = c(this, R).get(e.type);
852
+ const r = c(this, S).get(e.type);
775
853
  if (r)
776
854
  for (const n of r)
777
855
  n(e);
778
856
  }
779
857
  /** @inheritDoc */
780
858
  async onMessage(e) {
781
- c(this, D).push(e);
859
+ c(this, B).push(e);
782
860
  }
783
861
  /** @inheritDoc */
784
862
  async setSpawnHandler(e) {
@@ -805,21 +883,21 @@ class E {
805
883
  initializeRuntime(e) {
806
884
  if (this[f])
807
885
  throw new Error("PHP runtime already initialized.");
808
- const r = Tt(e);
886
+ const r = Ht(e);
809
887
  if (!r)
810
888
  throw new Error("Invalid PHP runtime id.");
811
889
  this[f] = r, r.onMessage = async (n) => {
812
- for (const s of c(this, D)) {
890
+ for (const s of c(this, B)) {
813
891
  const o = await s(n);
814
892
  if (o)
815
893
  return o;
816
894
  }
817
895
  return "";
818
- }, g(this, L, ct(r));
896
+ }, y(this, A, ut(r));
819
897
  }
820
898
  /** @inheritDoc */
821
899
  setPhpIniPath(e) {
822
- if (c(this, S))
900
+ if (c(this, k))
823
901
  throw new Error("Cannot set PHP ini path after calling run().");
824
902
  this[f].ccall(
825
903
  "wasm_set_phpini_path",
@@ -830,9 +908,9 @@ class E {
830
908
  }
831
909
  /** @inheritDoc */
832
910
  setPhpIniEntry(e, r) {
833
- if (c(this, S))
911
+ if (c(this, k))
834
912
  throw new Error("Cannot set PHP ini entries after calling run().");
835
- c(this, F).push([e, r]);
913
+ c(this, H).push([e, r]);
836
914
  }
837
915
  /** @inheritDoc */
838
916
  chdir(e) {
@@ -846,14 +924,14 @@ class E {
846
924
  }
847
925
  /** @inheritDoc */
848
926
  async run(e) {
849
- const r = await c(this, B).acquire();
927
+ const r = await c(this, j).acquire();
850
928
  try {
851
- c(this, S) || (y(this, te, Ue).call(this), g(this, S, !0)), y(this, ce, Be).call(this, e.scriptPath || ""), y(this, ne, We).call(this, e.relativeUri || ""), y(this, ie, qe).call(this, e.method || "GET");
852
- const n = Ke(e.headers || {}), s = n.host || "example.com:443";
853
- if (y(this, se, De).call(this, s, e.protocol || "http"), y(this, oe, ze).call(this, n), e.body && y(this, ae, je).call(this, e.body), e.fileInfos)
929
+ c(this, k) || (g(this, re, $e).call(this), y(this, k, !0)), g(this, le, Ge).call(this, e.scriptPath || ""), g(this, se, Be).call(this, e.relativeUri || ""), g(this, oe, qe).call(this, e.method || "GET");
930
+ const n = Qe(e.headers || {}), s = n.host || "example.com:443";
931
+ if (g(this, ie, De).call(this, s, e.protocol || "http"), g(this, ae, ze).call(this, n), e.body && g(this, ce, je).call(this, e.body), e.fileInfos)
854
932
  for (const o of e.fileInfos)
855
- y(this, ue, Ve).call(this, o);
856
- return e.code && y(this, he, Ye).call(this, " ?>" + e.code), y(this, le, Ge).call(this), await y(this, de, Je).call(this);
933
+ g(this, he, Ye).call(this, o);
934
+ return e.code && g(this, de, Je).call(this, " ?>" + e.code), g(this, ue, Ve).call(this), await g(this, fe, Ke).call(this);
857
935
  } finally {
858
936
  r(), this.dispatchEvent({
859
937
  type: "request.end"
@@ -897,8 +975,19 @@ class E {
897
975
  unlink(e) {
898
976
  this[f].FS.unlink(e);
899
977
  }
978
+ /** @inheritDoc */
900
979
  mv(e, r) {
901
- this[f].FS.rename(e, r);
980
+ try {
981
+ this[f].FS.rename(e, r);
982
+ } catch (n) {
983
+ const s = Tt(n);
984
+ throw s ? new Error(
985
+ `Could not move ${e} to ${r}: ${s}`,
986
+ {
987
+ cause: n
988
+ }
989
+ ) : n;
990
+ }
902
991
  }
903
992
  rmdir(e, r = { recursive: !0 }) {
904
993
  r != null && r.recursive && this.listFiles(e).forEach((n) => {
@@ -938,7 +1027,7 @@ class E {
938
1027
  return this[f]._exit(e);
939
1028
  }
940
1029
  }
941
- F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R = new WeakMap(), D = new WeakMap(), B = new WeakMap(), te = new WeakSet(), Ue = function() {
1030
+ H = new WeakMap(), k = new WeakMap(), A = new WeakMap(), _ = new WeakMap(), S = new WeakMap(), B = new WeakMap(), j = new WeakMap(), re = new WeakSet(), $e = function() {
942
1031
  if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
943
1032
  "/tmp/consts.php",
944
1033
  `<?php
@@ -950,8 +1039,8 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
950
1039
  }
951
1040
  }
952
1041
  }`
953
- ), c(this, F).length > 0) {
954
- const e = c(this, F).map(([r, n]) => `${r}=${n}`).join(`
1042
+ ), c(this, H).length > 0) {
1043
+ const e = c(this, H).map(([r, n]) => `${r}=${n}`).join(`
955
1044
  `) + `
956
1045
 
957
1046
  `;
@@ -963,7 +1052,7 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
963
1052
  );
964
1053
  }
965
1054
  this[f].ccall("php_wasm_init", null, [], []);
966
- }, re = new WeakSet(), $e = function() {
1055
+ }, ne = new WeakSet(), We = function() {
967
1056
  const e = "/tmp/headers.json";
968
1057
  if (!this.fileExists(e))
969
1058
  throw new Error(
@@ -980,7 +1069,7 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
980
1069
  headers: n,
981
1070
  httpStatusCode: r.status
982
1071
  };
983
- }, ne = new WeakSet(), We = function(e) {
1072
+ }, se = new WeakSet(), Be = function(e) {
984
1073
  if (this[f].ccall(
985
1074
  "wasm_set_request_uri",
986
1075
  null,
@@ -995,7 +1084,7 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
995
1084
  [r]
996
1085
  );
997
1086
  }
998
- }, se = new WeakSet(), De = function(e, r) {
1087
+ }, ie = new WeakSet(), De = function(e, r) {
999
1088
  this[f].ccall(
1000
1089
  "wasm_set_request_host",
1001
1090
  null,
@@ -1013,14 +1102,14 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1013
1102
  [M],
1014
1103
  [n]
1015
1104
  ), (r === "https" || !r && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
1016
- }, ie = new WeakSet(), qe = function(e) {
1105
+ }, oe = new WeakSet(), qe = function(e) {
1017
1106
  this[f].ccall(
1018
1107
  "wasm_set_request_method",
1019
1108
  null,
1020
1109
  [w],
1021
1110
  [e]
1022
1111
  );
1023
- }, oe = new WeakSet(), ze = function(e) {
1112
+ }, ae = new WeakSet(), ze = function(e) {
1024
1113
  e.cookie && this[f].ccall(
1025
1114
  "wasm_set_cookies",
1026
1115
  null,
@@ -1044,7 +1133,7 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1044
1133
  e[r]
1045
1134
  );
1046
1135
  }
1047
- }, ae = new WeakSet(), je = function(e) {
1136
+ }, ce = new WeakSet(), je = function(e) {
1048
1137
  this[f].ccall(
1049
1138
  "wasm_set_request_body",
1050
1139
  null,
@@ -1056,14 +1145,14 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1056
1145
  [M],
1057
1146
  [new TextEncoder().encode(e).length]
1058
1147
  );
1059
- }, ce = new WeakSet(), Be = function(e) {
1148
+ }, le = new WeakSet(), Ge = function(e) {
1060
1149
  this[f].ccall(
1061
1150
  "wasm_set_path_translated",
1062
1151
  null,
1063
1152
  [w],
1064
1153
  [e]
1065
1154
  );
1066
- }, le = new WeakSet(), Ge = function() {
1155
+ }, ue = new WeakSet(), Ve = function() {
1067
1156
  for (const e in c(this, _))
1068
1157
  this[f].ccall(
1069
1158
  "wasm_add_SERVER_entry",
@@ -1071,7 +1160,7 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1071
1160
  [w, w],
1072
1161
  [e, c(this, _)[e]]
1073
1162
  );
1074
- }, ue = new WeakSet(), Ve = function(e) {
1163
+ }, he = new WeakSet(), Ye = function(e) {
1075
1164
  const { key: r, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
1076
1165
  this.writeFile(i, o);
1077
1166
  const a = 0;
@@ -1081,14 +1170,14 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1081
1170
  [w, w, w, w, M, M],
1082
1171
  [r, n, s, i, a, o.byteLength]
1083
1172
  );
1084
- }, he = new WeakSet(), Ye = function(e) {
1173
+ }, de = new WeakSet(), Je = function(e) {
1085
1174
  this[f].ccall(
1086
1175
  "wasm_set_php_code",
1087
1176
  null,
1088
1177
  [w],
1089
1178
  [e]
1090
1179
  );
1091
- }, de = new WeakSet(), Je = async function() {
1180
+ }, fe = new WeakSet(), Ke = async function() {
1092
1181
  var o;
1093
1182
  let e, r;
1094
1183
  try {
@@ -1097,7 +1186,7 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1097
1186
  r = (h) => {
1098
1187
  const m = new Error("Rethrown");
1099
1188
  m.cause = h.error, m.betterMessage = h.message, a(m);
1100
- }, (l = c(this, L)) == null || l.addEventListener(
1189
+ }, (l = c(this, A)) == null || l.addEventListener(
1101
1190
  "error",
1102
1191
  r
1103
1192
  );
@@ -1117,14 +1206,14 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1117
1206
  "PHP runtime has crashed – see the earlier error for details."
1118
1207
  );
1119
1208
  });
1120
- this.functionsMaybeMissingFromAsyncify = lt();
1209
+ this.functionsMaybeMissingFromAsyncify = ht();
1121
1210
  const a = i, u = "betterMessage" in a ? a.betterMessage : a.message, l = new Error(u);
1122
1211
  throw l.cause = a, l;
1123
1212
  } finally {
1124
- (o = c(this, L)) == null || o.removeEventListener("error", r), g(this, _, {});
1213
+ (o = c(this, A)) == null || o.removeEventListener("error", r), y(this, _, {});
1125
1214
  }
1126
- const { headers: n, httpStatusCode: s } = y(this, re, $e).call(this);
1127
- return new A(
1215
+ const { headers: n, httpStatusCode: s } = g(this, ne, We).call(this);
1216
+ return new L(
1128
1217
  s,
1129
1218
  n,
1130
1219
  this.readFileAsBuffer("/tmp/stdout"),
@@ -1132,40 +1221,37 @@ F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R =
1132
1221
  e
1133
1222
  );
1134
1223
  };
1135
- v([
1136
- b('Could not create directory "{path}"')
1137
- ], E.prototype, "mkdir", 1);
1138
- v([
1139
- b('Could not create directory "{path}"')
1140
- ], E.prototype, "mkdirTree", 1);
1141
- v([
1142
- b('Could not read "{path}"')
1143
- ], E.prototype, "readFileAsText", 1);
1144
- v([
1145
- b('Could not read "{path}"')
1146
- ], E.prototype, "readFileAsBuffer", 1);
1147
- v([
1148
- b('Could not write to "{path}"')
1149
- ], E.prototype, "writeFile", 1);
1150
- v([
1151
- b('Could not unlink "{path}"')
1152
- ], E.prototype, "unlink", 1);
1153
- v([
1154
- b('Could not move "{path}"')
1155
- ], E.prototype, "mv", 1);
1156
- v([
1157
- b('Could not remove directory "{path}"')
1158
- ], E.prototype, "rmdir", 1);
1159
- v([
1160
- b('Could not list files in "{path}"')
1161
- ], E.prototype, "listFiles", 1);
1162
- v([
1163
- b('Could not stat "{path}"')
1164
- ], E.prototype, "isDir", 1);
1165
- v([
1166
- b('Could not stat "{path}"')
1167
- ], E.prototype, "fileExists", 1);
1168
- function Ke(t) {
1224
+ x([
1225
+ R('Could not create directory "{path}"')
1226
+ ], P.prototype, "mkdir", 1);
1227
+ x([
1228
+ R('Could not create directory "{path}"')
1229
+ ], P.prototype, "mkdirTree", 1);
1230
+ x([
1231
+ R('Could not read "{path}"')
1232
+ ], P.prototype, "readFileAsText", 1);
1233
+ x([
1234
+ R('Could not read "{path}"')
1235
+ ], P.prototype, "readFileAsBuffer", 1);
1236
+ x([
1237
+ R('Could not write to "{path}"')
1238
+ ], P.prototype, "writeFile", 1);
1239
+ x([
1240
+ R('Could not unlink "{path}"')
1241
+ ], P.prototype, "unlink", 1);
1242
+ x([
1243
+ R('Could not remove directory "{path}"')
1244
+ ], P.prototype, "rmdir", 1);
1245
+ x([
1246
+ R('Could not list files in "{path}"')
1247
+ ], P.prototype, "listFiles", 1);
1248
+ x([
1249
+ R('Could not stat "{path}"')
1250
+ ], P.prototype, "isDir", 1);
1251
+ x([
1252
+ R('Could not stat "{path}"')
1253
+ ], P.prototype, "fileExists", 1);
1254
+ function Qe(t) {
1169
1255
  const e = {};
1170
1256
  for (const r in t)
1171
1257
  e[r.toLowerCase()] = t[r];
@@ -1176,17 +1262,17 @@ function Ke(t) {
1176
1262
  * Copyright 2019 Google LLC
1177
1263
  * SPDX-License-Identifier: Apache-2.0
1178
1264
  */
1179
- const Qe = Symbol("Comlink.proxy"), Lt = Symbol("Comlink.endpoint"), At = Symbol("Comlink.releaseProxy"), me = Symbol("Comlink.finalizer"), Y = Symbol("Comlink.thrown"), Xe = (t) => typeof t == "object" && t !== null || typeof t == "function", Mt = {
1180
- canHandle: (t) => Xe(t) && t[Qe],
1265
+ const Xe = Symbol("Comlink.proxy"), Ot = Symbol("Comlink.endpoint"), It = Symbol("Comlink.releaseProxy"), ye = Symbol("Comlink.finalizer"), Y = Symbol("Comlink.thrown"), Ze = (t) => typeof t == "object" && t !== null || typeof t == "function", Nt = {
1266
+ canHandle: (t) => Ze(t) && t[Xe],
1181
1267
  serialize(t) {
1182
1268
  const { port1: e, port2: r } = new MessageChannel();
1183
- return fe(t, e), [r, [r]];
1269
+ return pe(t, e), [r, [r]];
1184
1270
  },
1185
1271
  deserialize(t) {
1186
1272
  return t.start(), Ee(t);
1187
1273
  }
1188
- }, Ot = {
1189
- canHandle: (t) => Xe(t) && Y in t,
1274
+ }, Ut = {
1275
+ canHandle: (t) => Ze(t) && Y in t,
1190
1276
  serialize({ value: t }) {
1191
1277
  let e;
1192
1278
  return t instanceof Error ? e = {
@@ -1201,28 +1287,28 @@ const Qe = Symbol("Comlink.proxy"), Lt = Symbol("Comlink.endpoint"), At = Symbol
1201
1287
  deserialize(t) {
1202
1288
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
1203
1289
  }
1204
- }, z = /* @__PURE__ */ new Map([
1205
- ["proxy", Mt],
1206
- ["throw", Ot]
1290
+ }, q = /* @__PURE__ */ new Map([
1291
+ ["proxy", Nt],
1292
+ ["throw", Ut]
1207
1293
  ]);
1208
- function It(t, e) {
1294
+ function $t(t, e) {
1209
1295
  for (const r of t)
1210
1296
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
1211
1297
  return !0;
1212
1298
  return !1;
1213
1299
  }
1214
- function fe(t, e = globalThis, r = ["*"]) {
1300
+ function pe(t, e = globalThis, r = ["*"]) {
1215
1301
  e.addEventListener("message", function n(s) {
1216
1302
  if (!s || !s.data)
1217
1303
  return;
1218
- if (!It(r, s.origin)) {
1304
+ if (!$t(r, s.origin)) {
1219
1305
  console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
1220
1306
  return;
1221
1307
  }
1222
1308
  const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), u = (s.data.argumentList || []).map(T);
1223
1309
  let l;
1224
1310
  try {
1225
- const h = a.slice(0, -1).reduce((P, q) => P[q], t), m = a.reduce((P, q) => P[q], t);
1311
+ const h = a.slice(0, -1).reduce((b, D) => b[D], t), m = a.reduce((b, D) => b[D], t);
1226
1312
  switch (i) {
1227
1313
  case "GET":
1228
1314
  l = m;
@@ -1235,14 +1321,14 @@ function fe(t, e = globalThis, r = ["*"]) {
1235
1321
  break;
1236
1322
  case "CONSTRUCT":
1237
1323
  {
1238
- const P = new m(...u);
1239
- l = rt(P);
1324
+ const b = new m(...u);
1325
+ l = nt(b);
1240
1326
  }
1241
1327
  break;
1242
1328
  case "ENDPOINT":
1243
1329
  {
1244
- const { port1: P, port2: q } = new MessageChannel();
1245
- fe(t, q), l = Dt(P, [P]);
1330
+ const { port1: b, port2: D } = new MessageChannel();
1331
+ pe(t, D), l = zt(b, [b]);
1246
1332
  }
1247
1333
  break;
1248
1334
  case "RELEASE":
@@ -1255,56 +1341,56 @@ function fe(t, e = globalThis, r = ["*"]) {
1255
1341
  l = { value: h, [Y]: 0 };
1256
1342
  }
1257
1343
  Promise.resolve(l).catch((h) => ({ value: h, [Y]: 0 })).then((h) => {
1258
- const [m, P] = Q(h);
1259
- e.postMessage(Object.assign(Object.assign({}, m), { id: o }), P), i === "RELEASE" && (e.removeEventListener("message", n), Ze(e), me in t && typeof t[me] == "function" && t[me]());
1344
+ const [m, b] = X(h);
1345
+ e.postMessage(Object.assign(Object.assign({}, m), { id: o }), b), i === "RELEASE" && (e.removeEventListener("message", n), et(e), ye in t && typeof t[ye] == "function" && t[ye]());
1260
1346
  }).catch((h) => {
1261
- const [m, P] = Q({
1347
+ const [m, b] = X({
1262
1348
  value: new TypeError("Unserializable return value"),
1263
1349
  [Y]: 0
1264
1350
  });
1265
- e.postMessage(Object.assign(Object.assign({}, m), { id: o }), P);
1351
+ e.postMessage(Object.assign(Object.assign({}, m), { id: o }), b);
1266
1352
  });
1267
1353
  }), e.start && e.start();
1268
1354
  }
1269
- function Nt(t) {
1355
+ function Wt(t) {
1270
1356
  return t.constructor.name === "MessagePort";
1271
1357
  }
1272
- function Ze(t) {
1273
- Nt(t) && t.close();
1358
+ function et(t) {
1359
+ Wt(t) && t.close();
1274
1360
  }
1275
1361
  function Ee(t, e) {
1276
- return ye(t, [], e);
1362
+ return we(t, [], e);
1277
1363
  }
1278
1364
  function G(t) {
1279
1365
  if (t)
1280
1366
  throw new Error("Proxy has been released and is not useable");
1281
1367
  }
1282
- function et(t) {
1368
+ function tt(t) {
1283
1369
  return O(t, {
1284
1370
  type: "RELEASE"
1285
1371
  }).then(() => {
1286
- Ze(t);
1372
+ et(t);
1287
1373
  });
1288
1374
  }
1289
- const J = /* @__PURE__ */ new WeakMap(), K = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
1290
- const e = (J.get(t) || 0) - 1;
1291
- J.set(t, e), e === 0 && et(t);
1375
+ const K = /* @__PURE__ */ new WeakMap(), Q = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
1376
+ const e = (K.get(t) || 0) - 1;
1377
+ K.set(t, e), e === 0 && tt(t);
1292
1378
  });
1293
- function Ut(t, e) {
1294
- const r = (J.get(e) || 0) + 1;
1295
- J.set(e, r), K && K.register(t, e, t);
1379
+ function Bt(t, e) {
1380
+ const r = (K.get(e) || 0) + 1;
1381
+ K.set(e, r), Q && Q.register(t, e, t);
1296
1382
  }
1297
- function $t(t) {
1298
- K && K.unregister(t);
1383
+ function Dt(t) {
1384
+ Q && Q.unregister(t);
1299
1385
  }
1300
- function ye(t, e = [], r = function() {
1386
+ function we(t, e = [], r = function() {
1301
1387
  }) {
1302
1388
  let n = !1;
1303
1389
  const s = new Proxy(r, {
1304
1390
  get(o, i) {
1305
- if (G(n), i === At)
1391
+ if (G(n), i === It)
1306
1392
  return () => {
1307
- $t(s), et(t), n = !0;
1393
+ Dt(s), tt(t), n = !0;
1308
1394
  };
1309
1395
  if (i === "then") {
1310
1396
  if (e.length === 0)
@@ -1315,11 +1401,11 @@ function ye(t, e = [], r = function() {
1315
1401
  }).then(T);
1316
1402
  return a.then.bind(a);
1317
1403
  }
1318
- return ye(t, [...e, i]);
1404
+ return we(t, [...e, i]);
1319
1405
  },
1320
1406
  set(o, i, a) {
1321
1407
  G(n);
1322
- const [u, l] = Q(a);
1408
+ const [u, l] = X(a);
1323
1409
  return O(t, {
1324
1410
  type: "SET",
1325
1411
  path: [...e, i].map((h) => h.toString()),
@@ -1329,13 +1415,13 @@ function ye(t, e = [], r = function() {
1329
1415
  apply(o, i, a) {
1330
1416
  G(n);
1331
1417
  const u = e[e.length - 1];
1332
- if (u === Lt)
1418
+ if (u === Ot)
1333
1419
  return O(t, {
1334
1420
  type: "ENDPOINT"
1335
1421
  }).then(T);
1336
1422
  if (u === "bind")
1337
- return ye(t, e.slice(0, -1));
1338
- const [l, h] = Le(a);
1423
+ return we(t, e.slice(0, -1));
1424
+ const [l, h] = Ae(a);
1339
1425
  return O(t, {
1340
1426
  type: "APPLY",
1341
1427
  path: e.map((m) => m.toString()),
@@ -1344,7 +1430,7 @@ function ye(t, e = [], r = function() {
1344
1430
  },
1345
1431
  construct(o, i) {
1346
1432
  G(n);
1347
- const [a, u] = Le(i);
1433
+ const [a, u] = Ae(i);
1348
1434
  return O(t, {
1349
1435
  type: "CONSTRUCT",
1350
1436
  path: e.map((l) => l.toString()),
@@ -1352,31 +1438,31 @@ function ye(t, e = [], r = function() {
1352
1438
  }, u).then(T);
1353
1439
  }
1354
1440
  });
1355
- return Ut(s, t), s;
1441
+ return Bt(s, t), s;
1356
1442
  }
1357
- function Wt(t) {
1443
+ function qt(t) {
1358
1444
  return Array.prototype.concat.apply([], t);
1359
1445
  }
1360
- function Le(t) {
1361
- const e = t.map(Q);
1362
- return [e.map((r) => r[0]), Wt(e.map((r) => r[1]))];
1446
+ function Ae(t) {
1447
+ const e = t.map(X);
1448
+ return [e.map((r) => r[0]), qt(e.map((r) => r[1]))];
1363
1449
  }
1364
- const tt = /* @__PURE__ */ new WeakMap();
1365
- function Dt(t, e) {
1366
- return tt.set(t, e), t;
1450
+ const rt = /* @__PURE__ */ new WeakMap();
1451
+ function zt(t, e) {
1452
+ return rt.set(t, e), t;
1367
1453
  }
1368
- function rt(t) {
1369
- return Object.assign(t, { [Qe]: !0 });
1454
+ function nt(t) {
1455
+ return Object.assign(t, { [Xe]: !0 });
1370
1456
  }
1371
- function nt(t, e = globalThis, r = "*") {
1457
+ function st(t, e = globalThis, r = "*") {
1372
1458
  return {
1373
1459
  postMessage: (n, s) => t.postMessage(n, r, s),
1374
1460
  addEventListener: e.addEventListener.bind(e),
1375
1461
  removeEventListener: e.removeEventListener.bind(e)
1376
1462
  };
1377
1463
  }
1378
- function Q(t) {
1379
- for (const [e, r] of z)
1464
+ function X(t) {
1465
+ for (const [e, r] of q)
1380
1466
  if (r.canHandle(t)) {
1381
1467
  const [n, s] = r.serialize(t);
1382
1468
  return [
@@ -1393,64 +1479,64 @@ function Q(t) {
1393
1479
  type: "RAW",
1394
1480
  value: t
1395
1481
  },
1396
- tt.get(t) || []
1482
+ rt.get(t) || []
1397
1483
  ];
1398
1484
  }
1399
1485
  function T(t) {
1400
1486
  switch (t.type) {
1401
1487
  case "HANDLER":
1402
- return z.get(t.name).deserialize(t.value);
1488
+ return q.get(t.name).deserialize(t.value);
1403
1489
  case "RAW":
1404
1490
  return t.value;
1405
1491
  }
1406
1492
  }
1407
1493
  function O(t, e, r) {
1408
1494
  return new Promise((n) => {
1409
- const s = qt();
1495
+ const s = jt();
1410
1496
  t.addEventListener("message", function o(i) {
1411
1497
  !i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", o), n(i.data));
1412
1498
  }), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), r);
1413
1499
  });
1414
1500
  }
1415
- function qt() {
1501
+ function jt() {
1416
1502
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
1417
1503
  }
1418
- function Jt(t) {
1419
- st();
1420
- const e = t instanceof Worker ? t : nt(t), r = Ee(e), n = be(r);
1504
+ function Xt(t) {
1505
+ it();
1506
+ const e = t instanceof Worker ? t : st(t), r = Ee(e), n = ve(r);
1421
1507
  return new Proxy(n, {
1422
1508
  get: (s, o) => o === "isConnected" ? async () => {
1423
1509
  for (let i = 0; i < 10; i++)
1424
1510
  try {
1425
- await zt(r.isConnected(), 200);
1511
+ await Gt(r.isConnected(), 200);
1426
1512
  break;
1427
1513
  } catch {
1428
1514
  }
1429
1515
  } : r[o]
1430
1516
  });
1431
1517
  }
1432
- async function zt(t, e) {
1518
+ async function Gt(t, e) {
1433
1519
  return new Promise((r, n) => {
1434
1520
  setTimeout(n, e), t.then(r);
1435
1521
  });
1436
1522
  }
1437
- function Kt(t, e) {
1438
- st();
1523
+ function Zt(t, e) {
1524
+ it();
1439
1525
  const r = Promise.resolve();
1440
1526
  let n, s;
1441
1527
  const o = new Promise((u, l) => {
1442
1528
  n = u, s = l;
1443
- }), i = be(t), a = new Proxy(i, {
1529
+ }), i = ve(t), a = new Proxy(i, {
1444
1530
  get: (u, l) => l === "isConnected" ? () => r : l === "isReady" ? () => o : l in u ? u[l] : e == null ? void 0 : e[l]
1445
1531
  });
1446
- return fe(
1532
+ return pe(
1447
1533
  a,
1448
- typeof window < "u" ? nt(self.parent) : void 0
1534
+ typeof window < "u" ? st(self.parent) : void 0
1449
1535
  ), [n, s, a];
1450
1536
  }
1451
- let Ae = !1;
1452
- function st() {
1453
- Ae || (Ae = !0, z.set("EVENT", {
1537
+ let Le = !1;
1538
+ function it() {
1539
+ Le || (Le = !0, q.set("EVENT", {
1454
1540
  canHandle: (t) => t instanceof CustomEvent,
1455
1541
  serialize: (t) => [
1456
1542
  {
@@ -1459,45 +1545,45 @@ function st() {
1459
1545
  []
1460
1546
  ],
1461
1547
  deserialize: (t) => t
1462
- }), z.set("FUNCTION", {
1548
+ }), q.set("FUNCTION", {
1463
1549
  canHandle: (t) => typeof t == "function",
1464
1550
  serialize(t) {
1465
1551
  console.debug("[Comlink][Performance] Proxying a function");
1466
1552
  const { port1: e, port2: r } = new MessageChannel();
1467
- return fe(t, e), [r, [r]];
1553
+ return pe(t, e), [r, [r]];
1468
1554
  },
1469
1555
  deserialize(t) {
1470
1556
  return t.start(), Ee(t);
1471
1557
  }
1472
- }), z.set("PHPResponse", {
1558
+ }), q.set("PHPResponse", {
1473
1559
  canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
1474
1560
  serialize(t) {
1475
1561
  return [t.toRawData(), []];
1476
1562
  },
1477
1563
  deserialize(t) {
1478
- return A.fromRawData(t);
1564
+ return L.fromRawData(t);
1479
1565
  }
1480
1566
  }));
1481
1567
  }
1482
- function be(t) {
1568
+ function ve(t) {
1483
1569
  return new Proxy(t, {
1484
1570
  get(e, r) {
1485
1571
  switch (typeof e[r]) {
1486
1572
  case "function":
1487
1573
  return (...n) => e[r](...n);
1488
1574
  case "object":
1489
- return e[r] === null ? e[r] : be(e[r]);
1575
+ return e[r] === null ? e[r] : ve(e[r]);
1490
1576
  case "undefined":
1491
1577
  case "number":
1492
1578
  case "string":
1493
1579
  return e[r];
1494
1580
  default:
1495
- return rt(e[r]);
1581
+ return nt(e[r]);
1496
1582
  }
1497
1583
  }
1498
1584
  });
1499
1585
  }
1500
- async function jt(t = gt, e = "light") {
1586
+ async function Vt(t = wt, e = "light") {
1501
1587
  if (e === "kitchen-sink")
1502
1588
  switch (t) {
1503
1589
  case "8.3":
@@ -1542,7 +1628,7 @@ async function jt(t = gt, e = "light") {
1542
1628
  }
1543
1629
  throw new Error(`Unsupported PHP version ${t}`);
1544
1630
  }
1545
- const Bt = () => ({
1631
+ const Yt = () => ({
1546
1632
  websocket: {
1547
1633
  decorator: (t) => class extends t {
1548
1634
  constructor() {
@@ -1557,7 +1643,7 @@ const Bt = () => ({
1557
1643
  }
1558
1644
  }
1559
1645
  });
1560
- class we extends E {
1646
+ class be extends P {
1561
1647
  /**
1562
1648
  * Creates a new PHP instance.
1563
1649
  *
@@ -1571,7 +1657,7 @@ class we extends E {
1571
1657
  * @returns A new PHP instance
1572
1658
  */
1573
1659
  static async load(e, r = {}) {
1574
- return await we.loadSync(e, r).phpReady;
1660
+ return await be.loadSync(e, r).phpReady;
1575
1661
  }
1576
1662
  /**
1577
1663
  * Does what load() does, but synchronously returns
@@ -1581,19 +1667,19 @@ class we extends E {
1581
1667
  * @see load
1582
1668
  */
1583
1669
  static loadSync(e, r = {}) {
1584
- const n = new we(void 0, r.requestHandler), s = r.loadAllExtensions ? "kitchen-sink" : "light", i = (async () => {
1585
- var m, P;
1670
+ const n = new be(void 0, r.requestHandler), s = r.loadAllExtensions ? "kitchen-sink" : "light", i = (async () => {
1671
+ var m, b;
1586
1672
  const a = await Promise.all([
1587
- jt(e, s),
1673
+ Vt(e, s),
1588
1674
  ...r.dataModules || []
1589
1675
  ]), [u, ...l] = a;
1590
1676
  (m = r.downloadMonitor) == null || m.setModules(a);
1591
- const h = await _t(
1677
+ const h = await Ft(
1592
1678
  u,
1593
1679
  {
1594
1680
  ...r.emscriptenOptions || {},
1595
- ...((P = r.downloadMonitor) == null ? void 0 : P.getEmscriptenOptions()) || {},
1596
- ...Bt()
1681
+ ...((b = r.downloadMonitor) == null ? void 0 : b.getEmscriptenOptions()) || {},
1682
+ ...Yt()
1597
1683
  },
1598
1684
  l
1599
1685
  );
@@ -1606,7 +1692,7 @@ class we extends E {
1606
1692
  }
1607
1693
  }
1608
1694
  const p = /* @__PURE__ */ new WeakMap();
1609
- class Xt {
1695
+ class tr {
1610
1696
  /** @inheritDoc */
1611
1697
  constructor(e, r) {
1612
1698
  p.set(this, {
@@ -1714,14 +1800,14 @@ class Xt {
1714
1800
  p.get(this).php.removeEventListener(e, r);
1715
1801
  }
1716
1802
  }
1717
- function Gt(t, e) {
1803
+ function Jt(t, e) {
1718
1804
  return {
1719
1805
  type: "response",
1720
1806
  requestId: t,
1721
1807
  response: e
1722
1808
  };
1723
1809
  }
1724
- async function Zt(t, e, r) {
1810
+ async function rr(t, e, r) {
1725
1811
  const n = navigator.serviceWorker;
1726
1812
  if (!n)
1727
1813
  throw new Error("Service workers are not supported in this browser.");
@@ -1735,12 +1821,12 @@ async function Zt(t, e, r) {
1735
1821
  if (console.debug("[window][sw] Message from ServiceWorker", i), e && i.data.scope !== e)
1736
1822
  return;
1737
1823
  const a = i.data.args || [], u = i.data.method, l = await t[u](...a);
1738
- i.source.postMessage(Gt(i.data.requestId, l));
1824
+ i.source.postMessage(Jt(i.data.requestId, l));
1739
1825
  }
1740
1826
  ), n.startMessages();
1741
1827
  }
1742
- async function er(t, e = {}) {
1743
- t = Vt(t, e);
1828
+ async function nr(t, e = {}) {
1829
+ t = Kt(t, e);
1744
1830
  const r = new Worker(t, { type: "module" });
1745
1831
  return new Promise((n, s) => {
1746
1832
  r.onerror = (i) => {
@@ -1755,7 +1841,7 @@ async function er(t, e = {}) {
1755
1841
  r.addEventListener("message", o);
1756
1842
  });
1757
1843
  }
1758
- function Vt(t, e) {
1844
+ function Kt(t, e) {
1759
1845
  if (!Object.entries(e).length)
1760
1846
  return t + "";
1761
1847
  const r = new URL(t);
@@ -1768,11 +1854,11 @@ function Vt(t, e) {
1768
1854
  return r.toString();
1769
1855
  }
1770
1856
  export {
1771
- we as WebPHP,
1772
- Xt as WebPHPEndpoint,
1773
- Jt as consumeAPI,
1774
- Kt as exposeAPI,
1775
- jt as getPHPLoaderModule,
1776
- Zt as registerServiceWorker,
1777
- er as spawnPHPWorkerThread
1857
+ be as WebPHP,
1858
+ tr as WebPHPEndpoint,
1859
+ Xt as consumeAPI,
1860
+ Zt as exposeAPI,
1861
+ Vt as getPHPLoaderModule,
1862
+ rr as registerServiceWorker,
1863
+ nr as spawnPHPWorkerThread
1778
1864
  };