@php-wasm/web 0.9.13 → 0.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +230 -1287
  2. package/package.json +7 -7
package/index.js CHANGED
@@ -1,1019 +1,100 @@
1
- const K = function() {
2
- var e;
3
- return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
4
- // @ts-ignore
5
- typeof WorkerGlobalScope < "u" && // @ts-ignore
6
- self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
7
- );
8
- }();
9
- if (K === "NODE") {
10
- let e = function(r) {
11
- return new Promise(function(n, s) {
12
- r.onload = r.onerror = function(o) {
13
- r.onload = r.onerror = null, o.type === "load" ? n(r.result) : s(new Error("Failed to read the blob/file"));
14
- };
15
- });
16
- }, t = function() {
17
- const r = new Uint8Array([1, 2, 3, 4]), s = new File([r], "test").stream();
18
- try {
19
- return s.getReader({ mode: "byob" }), !0;
20
- } catch {
21
- return !1;
22
- }
23
- };
24
- if (typeof File > "u") {
25
- class r extends Blob {
26
- constructor(s, o, i) {
27
- super(s);
28
- let a;
29
- i != null && i.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = o || "";
30
- }
31
- }
32
- global.File = r;
33
- }
34
- typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
35
- const n = new FileReader();
36
- return n.readAsArrayBuffer(this), e(n);
37
- }), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
38
- const n = new FileReader();
39
- return n.readAsText(this), e(n);
40
- }), (typeof Blob.prototype.stream > "u" || !t()) && (Blob.prototype.stream = function() {
41
- let r = 0;
42
- const n = this;
43
- return new ReadableStream({
44
- type: "bytes",
45
- // 0.5 MB seems like a reasonable chunk size, let's adjust
46
- // this if needed.
47
- autoAllocateChunkSize: 512 * 1024,
48
- async pull(s) {
49
- const o = s.byobRequest.view, a = await n.slice(
50
- r,
51
- r + o.byteLength
52
- ).arrayBuffer(), u = new Uint8Array(a);
53
- new Uint8Array(o.buffer).set(u);
54
- const l = u.byteLength;
55
- s.byobRequest.respond(l), r += l, r >= n.size && s.close();
56
- }
57
- });
58
- });
59
- }
60
- if (K === "NODE" && typeof CustomEvent > "u") {
61
- class e extends Event {
62
- constructor(r, n = {}) {
63
- super(r, n), this.detail = n.detail;
64
- }
65
- initCustomEvent() {
66
- }
67
- }
68
- globalThis.CustomEvent = e;
69
- }
70
- const x = {
71
- 0: "No error occurred. System call completed successfully.",
72
- 1: "Argument list too long.",
73
- 2: "Permission denied.",
74
- 3: "Address in use.",
75
- 4: "Address not available.",
76
- 5: "Address family not supported.",
77
- 6: "Resource unavailable, or operation would block.",
78
- 7: "Connection already in progress.",
79
- 8: "Bad file descriptor.",
80
- 9: "Bad message.",
81
- 10: "Device or resource busy.",
82
- 11: "Operation canceled.",
83
- 12: "No child processes.",
84
- 13: "Connection aborted.",
85
- 14: "Connection refused.",
86
- 15: "Connection reset.",
87
- 16: "Resource deadlock would occur.",
88
- 17: "Destination address required.",
89
- 18: "Mathematics argument out of domain of function.",
90
- 19: "Reserved.",
91
- 20: "File exists.",
92
- 21: "Bad address.",
93
- 22: "File too large.",
94
- 23: "Host is unreachable.",
95
- 24: "Identifier removed.",
96
- 25: "Illegal byte sequence.",
97
- 26: "Operation in progress.",
98
- 27: "Interrupted function.",
99
- 28: "Invalid argument.",
100
- 29: "I/O error.",
101
- 30: "Socket is connected.",
102
- 31: "There is a directory under that path.",
103
- 32: "Too many levels of symbolic links.",
104
- 33: "File descriptor value too large.",
105
- 34: "Too many links.",
106
- 35: "Message too large.",
107
- 36: "Reserved.",
108
- 37: "Filename too long.",
109
- 38: "Network is down.",
110
- 39: "Connection aborted by network.",
111
- 40: "Network unreachable.",
112
- 41: "Too many files open in system.",
113
- 42: "No buffer space available.",
114
- 43: "No such device.",
115
- 44: "There is no such file or directory OR the parent directory does not exist.",
116
- 45: "Executable file format error.",
117
- 46: "No locks available.",
118
- 47: "Reserved.",
119
- 48: "Not enough space.",
120
- 49: "No message of the desired type.",
121
- 50: "Protocol not available.",
122
- 51: "No space left on device.",
123
- 52: "Function not supported.",
124
- 53: "The socket is not connected.",
125
- 54: "Not a directory or a symbolic link to a directory.",
126
- 55: "Directory not empty.",
127
- 56: "State not recoverable.",
128
- 57: "Not a socket.",
129
- 58: "Not supported, or operation not supported on socket.",
130
- 59: "Inappropriate I/O control operation.",
131
- 60: "No such device or address.",
132
- 61: "Value too large to be stored in data type.",
133
- 62: "Previous owner died.",
134
- 63: "Operation not permitted.",
135
- 64: "Broken pipe.",
136
- 65: "Protocol error.",
137
- 66: "Protocol not supported.",
138
- 67: "Protocol wrong type for socket.",
139
- 68: "Result too large.",
140
- 69: "Read-only file system.",
141
- 70: "Invalid seek.",
142
- 71: "No such process.",
143
- 72: "Reserved.",
144
- 73: "Connection timed out.",
145
- 74: "Text file busy.",
146
- 75: "Cross-device link.",
147
- 76: "Extension: Capabilities insufficient."
148
- };
149
- function ue(e) {
150
- const t = typeof e == "object" ? e == null ? void 0 : e.errno : null;
151
- if (t in x)
152
- return x[t];
153
- }
154
- function y(e = "") {
155
- return function(r, n, s) {
156
- const o = s.value;
157
- s.value = function(...i) {
158
- try {
159
- return o.apply(this, i);
160
- } catch (a) {
161
- const u = typeof a == "object" ? a == null ? void 0 : a.errno : null;
162
- if (u in x) {
163
- const l = x[u], c = typeof i[1] == "string" ? i[1] : null, d = c !== null ? e.replaceAll("{path}", c) : e;
164
- throw new Error(`${d}: ${l}`, {
165
- cause: a
166
- });
167
- }
168
- throw a;
169
- }
170
- };
171
- };
172
- }
173
- const le = "playground-log", B = (e, ...t) => {
174
- v.dispatchEvent(
175
- new CustomEvent(le, {
176
- detail: {
177
- log: e,
178
- args: t
179
- }
180
- })
181
- );
182
- }, de = (e, ...t) => {
183
- switch (typeof e.message == "string" ? e.message = W(e.message) : e.message.message && typeof e.message.message == "string" && (e.message.message = W(e.message.message)), e.severity) {
184
- case "Debug":
185
- console.debug(e.message, ...t);
186
- break;
187
- case "Info":
188
- console.info(e.message, ...t);
189
- break;
190
- case "Warn":
191
- console.warn(e.message, ...t);
192
- break;
193
- case "Error":
194
- console.error(e.message, ...t);
195
- break;
196
- case "Fatal":
197
- console.error(e.message, ...t);
198
- break;
199
- default:
200
- console.log(e.message, ...t);
201
- }
202
- }, fe = (e) => e instanceof Error ? [e.message, e.stack].join(`
203
- `) : JSON.stringify(e, null, 2), Y = [], $ = (e) => {
204
- Y.push(e);
205
- }, N = (e) => {
206
- if (e.raw === !0)
207
- $(e.message);
208
- else {
209
- const t = ye(
210
- typeof e.message == "object" ? fe(e.message) : e.message,
211
- e.severity ?? "Info",
212
- e.prefix ?? "JavaScript"
213
- );
214
- $(t);
215
- }
216
- };
217
- class me extends EventTarget {
218
- // constructor
219
- constructor(t = []) {
220
- super(), this.handlers = t, this.fatalErrorEvent = "playground-fatal-error";
221
- }
222
- /**
223
- * Get all logs.
224
- * @returns string[]
225
- */
226
- getLogs() {
227
- return this.handlers.includes(N) ? [...Y] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
228
- If you're using a custom logger instance, make sure to register logToMemory handler.
229
- `), []);
230
- }
231
- /**
232
- * Log message with severity.
233
- *
234
- * @param message any
235
- * @param severity LogSeverity
236
- * @param raw boolean
237
- * @param args any
238
- */
239
- logMessage(t, ...r) {
240
- for (const n of this.handlers)
241
- n(t, ...r);
242
- }
243
- /**
244
- * Log message
245
- *
246
- * @param message any
247
- * @param args any
248
- */
249
- log(t, ...r) {
250
- this.logMessage(
251
- {
252
- message: t,
253
- severity: void 0,
254
- prefix: "JavaScript",
255
- raw: !1
256
- },
257
- ...r
258
- );
259
- }
260
- /**
261
- * Log debug message
262
- *
263
- * @param message any
264
- * @param args any
265
- */
266
- debug(t, ...r) {
267
- this.logMessage(
268
- {
269
- message: t,
270
- severity: "Debug",
271
- prefix: "JavaScript",
272
- raw: !1
273
- },
274
- ...r
275
- );
276
- }
277
- /**
278
- * Log info message
279
- *
280
- * @param message any
281
- * @param args any
282
- */
283
- info(t, ...r) {
284
- this.logMessage(
285
- {
286
- message: t,
287
- severity: "Info",
288
- prefix: "JavaScript",
289
- raw: !1
290
- },
291
- ...r
292
- );
293
- }
294
- /**
295
- * Log warning message
296
- *
297
- * @param message any
298
- * @param args any
299
- */
300
- warn(t, ...r) {
301
- this.logMessage(
302
- {
303
- message: t,
304
- severity: "Warn",
305
- prefix: "JavaScript",
306
- raw: !1
307
- },
308
- ...r
309
- );
310
- }
311
- /**
312
- * Log error message
313
- *
314
- * @param message any
315
- * @param args any
316
- */
317
- error(t, ...r) {
318
- this.logMessage(
319
- {
320
- message: t,
321
- severity: "Error",
322
- prefix: "JavaScript",
323
- raw: !1
324
- },
325
- ...r
326
- );
327
- }
328
- }
329
- const pe = () => {
330
- try {
331
- if (process.env.NODE_ENV === "test")
332
- return [N, B];
333
- } catch {
334
- }
335
- return [N, de, B];
336
- }, v = new me(pe()), W = (e) => e.replace(/\t/g, ""), ye = (e, t, r) => {
337
- const n = /* @__PURE__ */ new Date(), s = new Intl.DateTimeFormat("en-GB", {
338
- year: "numeric",
339
- month: "short",
340
- day: "2-digit",
341
- timeZone: "UTC"
342
- }).format(n).replace(/ /g, "-"), o = new Intl.DateTimeFormat("en-GB", {
343
- hour: "2-digit",
344
- minute: "2-digit",
345
- second: "2-digit",
346
- hour12: !1,
347
- timeZone: "UTC",
348
- timeZoneName: "short"
349
- }).format(n), i = s + " " + o;
350
- return e = W(e), `[${i}] ${r} ${t}: ${e}`;
351
- }, Z = Symbol("SleepFinished");
352
- function he(e) {
353
- return new Promise((t) => {
354
- setTimeout(() => t(Z), e);
355
- });
356
- }
357
- class we extends Error {
358
- constructor() {
359
- super("Acquiring lock timed out");
360
- }
361
- }
362
- class ge {
363
- constructor({ concurrency: t, timeout: r }) {
364
- this._running = 0, this.concurrency = t, this.timeout = r, this.queue = [];
365
- }
366
- get remaining() {
367
- return this.concurrency - this.running;
368
- }
369
- get running() {
370
- return this._running;
371
- }
372
- async acquire() {
373
- for (; ; )
374
- if (this._running >= this.concurrency) {
375
- const t = new Promise((r) => {
376
- this.queue.push(r);
377
- });
378
- this.timeout !== void 0 ? await Promise.race([t, he(this.timeout)]).then(
379
- (r) => {
380
- if (r === Z)
381
- throw new we();
382
- }
383
- ) : await t;
384
- } else {
385
- this._running++;
386
- let t = !1;
387
- return () => {
388
- t || (t = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
389
- };
390
- }
391
- }
392
- async run(t) {
393
- const r = await this.acquire();
394
- try {
395
- return await t();
396
- } finally {
397
- r();
398
- }
399
- }
400
- }
401
- class j extends Error {
402
- constructor(t, r) {
403
- super(t), this.userFriendlyMessage = r, this.userFriendlyMessage || (this.userFriendlyMessage = t);
404
- }
405
- }
406
- function b(...e) {
407
- let t = e.join("/");
408
- const r = t[0] === "/", n = t.substring(t.length - 1) === "/";
409
- return t = H(t), !t && !r && (t = "."), t && n && (t += "/"), t;
410
- }
411
- function be(e) {
412
- if (e === "/")
413
- return "/";
414
- e = H(e);
415
- const t = e.lastIndexOf("/");
416
- return t === -1 ? "" : t === 0 ? "/" : e.substr(0, t);
417
- }
418
- function Ee(e) {
419
- if (e === "/")
420
- return "/";
421
- e = H(e);
422
- const t = e.lastIndexOf("/");
423
- return t === -1 ? e : e.substr(t + 1);
424
- }
425
- function H(e) {
426
- const t = e[0] === "/";
427
- return e = ke(
428
- e.split("/").filter((r) => !!r),
429
- !t
430
- ).join("/"), (t ? "/" : "") + e.replace(/\/$/, "");
431
- }
432
- function ke(e, t) {
433
- let r = 0;
434
- for (let n = e.length - 1; n >= 0; n--) {
435
- const s = e[n];
436
- s === "." ? e.splice(n, 1) : s === ".." ? (e.splice(n, 1), r++) : r && (e.splice(n, 1), r--);
437
- }
438
- if (t)
439
- for (; r; r--)
440
- e.unshift("..");
441
- return e;
442
- }
443
- var ve = Object.defineProperty, Pe = Object.getOwnPropertyDescriptor, h = (e, t, r, n) => {
444
- for (var s = n > 1 ? void 0 : n ? Pe(t, r) : t, o = e.length - 1, i; o >= 0; o--)
445
- (i = e[o]) && (s = (n ? i(t, r, s) : i(s)) || s);
446
- return n && s && ve(t, r, s), s;
447
- };
448
- const p = class m {
449
- static readFileAsText(t, r) {
450
- return new TextDecoder().decode(m.readFileAsBuffer(t, r));
451
- }
452
- static readFileAsBuffer(t, r) {
453
- return t.readFile(r);
454
- }
455
- static writeFile(t, r, n) {
456
- t.writeFile(r, n);
457
- }
458
- static unlink(t, r) {
459
- t.unlink(r);
460
- }
461
- /**
462
- * Moves a file or directory in the PHP filesystem to a
463
- * new location.
464
- *
465
- * @param oldPath The path to rename.
466
- * @param newPath The new path.
467
- */
468
- static mv(t, r, n) {
469
- try {
470
- const s = t.lookupPath(r).node.mount, o = m.fileExists(t, n) ? t.lookupPath(n).node.mount : t.lookupPath(be(n)).node.mount;
471
- s.mountpoint !== o.mountpoint ? (m.copyRecursive(t, r, n), m.rmdir(t, r, { recursive: !0 })) : t.rename(r, n);
472
- } catch (s) {
473
- const o = ue(s);
474
- throw o ? new Error(
475
- `Could not move ${r} to ${n}: ${o}`,
476
- {
477
- cause: s
478
- }
479
- ) : s;
480
- }
481
- }
482
- static rmdir(t, r, n = { recursive: !0 }) {
483
- n != null && n.recursive && m.listFiles(t, r).forEach((s) => {
484
- const o = `${r}/${s}`;
485
- m.isDir(t, o) ? m.rmdir(t, o, n) : m.unlink(t, o);
486
- }), t.rmdir(r);
487
- }
488
- static listFiles(t, r, n = { prependPath: !1 }) {
489
- if (!m.fileExists(t, r))
490
- return [];
491
- try {
492
- const s = t.readdir(r).filter(
493
- (o) => o !== "." && o !== ".."
494
- );
495
- if (n.prependPath) {
496
- const o = r.replace(/\/$/, "");
497
- return s.map((i) => `${o}/${i}`);
498
- }
499
- return s;
500
- } catch (s) {
501
- return v.error(s, { path: r }), [];
502
- }
503
- }
504
- static isDir(t, r) {
505
- return m.fileExists(t, r) ? t.isDir(t.lookupPath(r).node.mode) : !1;
506
- }
507
- static fileExists(t, r) {
508
- try {
509
- return t.lookupPath(r), !0;
510
- } catch {
511
- return !1;
512
- }
513
- }
514
- static mkdir(t, r) {
515
- t.mkdirTree(r);
516
- }
517
- static copyRecursive(t, r, n) {
518
- const s = t.lookupPath(r).node;
519
- if (t.isDir(s.mode)) {
520
- t.mkdirTree(n);
521
- const o = t.readdir(r).filter(
522
- (i) => i !== "." && i !== ".."
523
- );
524
- for (const i of o)
525
- m.copyRecursive(
526
- t,
527
- b(r, i),
528
- b(n, i)
529
- );
530
- } else
531
- t.writeFile(n, t.readFile(r));
532
- }
533
- };
534
- h([
535
- y('Could not read "{path}"')
536
- ], p, "readFileAsText", 1);
537
- h([
538
- y('Could not read "{path}"')
539
- ], p, "readFileAsBuffer", 1);
540
- h([
541
- y('Could not write to "{path}"')
542
- ], p, "writeFile", 1);
543
- h([
544
- y('Could not unlink "{path}"')
545
- ], p, "unlink", 1);
546
- h([
547
- y('Could not remove directory "{path}"')
548
- ], p, "rmdir", 1);
549
- h([
550
- y('Could not list files in "{path}"')
551
- ], p, "listFiles", 1);
552
- h([
553
- y('Could not stat "{path}"')
554
- ], p, "isDir", 1);
555
- h([
556
- y('Could not stat "{path}"')
557
- ], p, "fileExists", 1);
558
- h([
559
- y('Could not create directory "{path}"')
560
- ], p, "mkdir", 1);
561
- h([
562
- y('Could not copy files from "{path}"')
563
- ], p, "copyRecursive", 1);
564
- let R = p;
565
- const Te = {
566
- 500: "Internal Server Error",
567
- 502: "Bad Gateway",
568
- 404: "Not Found",
569
- 403: "Forbidden",
570
- 401: "Unauthorized",
571
- 400: "Bad Request",
572
- 301: "Moved Permanently",
573
- 302: "Found",
574
- 307: "Temporary Redirect",
575
- 308: "Permanent Redirect",
576
- 204: "No Content",
577
- 201: "Created",
578
- 200: "OK"
579
- };
580
- class O {
581
- constructor(t, r, n, s = "", o = 0) {
582
- this.httpStatusCode = t, this.headers = r, this.bytes = n, this.exitCode = o, this.errors = s;
583
- }
584
- static forHttpCode(t, r = "") {
585
- return new O(
586
- t,
587
- {},
588
- new TextEncoder().encode(
589
- r || Te[t] || ""
590
- )
591
- );
592
- }
593
- static fromRawData(t) {
594
- return new O(
595
- t.httpStatusCode,
596
- t.headers,
597
- t.bytes,
598
- t.errors,
599
- t.exitCode
600
- );
601
- }
602
- toRawData() {
603
- return {
604
- headers: this.headers,
605
- bytes: this.bytes,
606
- errors: this.errors,
607
- exitCode: this.exitCode,
608
- httpStatusCode: this.httpStatusCode
609
- };
610
- }
611
- /**
612
- * Response body as JSON.
613
- */
614
- get json() {
615
- return JSON.parse(this.text);
616
- }
617
- /**
618
- * Response body as text.
619
- */
620
- get text() {
621
- return new TextDecoder().decode(this.bytes);
622
- }
623
- }
624
- const Re = Symbol("RuntimeId"), _ = /* @__PURE__ */ new Map();
625
- let Ce = 0;
626
- async function xe(e, t = {}) {
627
- const [r, n, s] = Se(), o = e.init(Oe, {
628
- onAbort(a) {
629
- s(a), v.error(a);
630
- },
631
- ENV: {},
632
- // Emscripten sometimes prepends a '/' to the path, which
633
- // breaks vite dev mode. An identity `locateFile` function
634
- // fixes it.
635
- locateFile: (a) => a,
636
- ...t,
637
- noInitialRun: !0,
638
- onRuntimeInitialized() {
639
- t.onRuntimeInitialized && t.onRuntimeInitialized(), n();
640
- }
641
- });
642
- await r;
643
- const i = ++Ce;
644
- return o.id = i, o.originalExit = o._exit, o._exit = function(a) {
645
- return _.delete(i), o.originalExit(a);
646
- }, o[Re] = i, _.set(i, o), i;
647
- }
648
- const Oe = function() {
649
- var e;
650
- return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
651
- }(), Se = () => {
652
- const e = [], t = new Promise((r, n) => {
653
- e.push(r, n);
654
- });
655
- return e.unshift(t), e;
656
- }, w = Symbol("__private__dont__use");
657
- ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
658
- const e = this.getReader();
659
- try {
660
- for (; ; ) {
661
- const { done: t, value: r } = await e.read();
662
- if (t)
663
- return;
664
- yield r;
665
- }
666
- } finally {
667
- e.releaseLock();
668
- }
669
- }, ReadableStream.prototype.iterate = // @ts-ignore
670
- ReadableStream.prototype[Symbol.asyncIterator]);
671
- const De = [
672
- "8.3",
673
- "8.2",
674
- "8.1",
675
- "8.0",
676
- "7.4",
677
- "7.3",
678
- "7.2",
679
- "7.1",
680
- "7.0"
681
- ], Ae = De[0];
682
- /**
683
- * @license
684
- * Copyright 2019 Google LLC
685
- * SPDX-License-Identifier: Apache-2.0
686
- */
687
- const Q = Symbol("Comlink.proxy"), Me = Symbol("Comlink.endpoint"), Le = Symbol("Comlink.releaseProxy"), L = Symbol("Comlink.finalizer"), C = Symbol("Comlink.thrown"), X = (e) => typeof e == "object" && e !== null || typeof e == "function", Ne = {
688
- canHandle: (e) => X(e) && e[Q],
689
- serialize(e) {
690
- const { port1: t, port2: r } = new MessageChannel();
691
- return M(e, t), [r, [r]];
692
- },
693
- deserialize(e) {
694
- return e.start(), F(e);
695
- }
696
- }, We = {
697
- canHandle: (e) => X(e) && C in e,
698
- serialize({ value: e }) {
699
- let t;
700
- return e instanceof Error ? t = {
701
- isError: !0,
702
- value: {
703
- message: e.message,
704
- name: e.name,
705
- stack: e.stack
706
- }
707
- } : t = { isError: !1, value: e }, [t, []];
708
- },
709
- deserialize(e) {
710
- throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
711
- }
712
- }, k = /* @__PURE__ */ new Map([
713
- ["proxy", Ne],
714
- ["throw", We]
715
- ]);
716
- function Ie(e, t) {
717
- for (const r of e)
718
- if (t === r || r === "*" || r instanceof RegExp && r.test(t))
719
- return !0;
720
- return !1;
721
- }
722
- function M(e, t = globalThis, r = ["*"]) {
723
- t.addEventListener("message", function n(s) {
724
- if (!s || !s.data)
725
- return;
726
- if (!Ie(r, s.origin)) {
727
- console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
728
- return;
729
- }
730
- const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), u = (s.data.argumentList || []).map(g);
731
- let l;
732
- try {
733
- const c = a.slice(0, -1).reduce((f, P) => f[P], e), d = a.reduce((f, P) => f[P], e);
734
- switch (i) {
735
- case "GET":
736
- l = d;
737
- break;
738
- case "SET":
739
- c[a.slice(-1)[0]] = g(s.data.value), l = !0;
740
- break;
741
- case "APPLY":
742
- l = d.apply(c, u);
743
- break;
744
- case "CONSTRUCT":
745
- {
746
- const f = new d(...u);
747
- l = ne(f);
748
- }
749
- break;
750
- case "ENDPOINT":
751
- {
752
- const { port1: f, port2: P } = new MessageChannel();
753
- M(e, P), l = $e(f, [f]);
754
- }
755
- break;
756
- case "RELEASE":
757
- l = void 0;
758
- break;
759
- default:
760
- return;
761
- }
762
- } catch (c) {
763
- l = { value: c, [C]: 0 };
764
- }
765
- Promise.resolve(l).catch((c) => ({ value: c, [C]: 0 })).then((c) => {
766
- const [d, f] = A(c);
767
- t.postMessage(Object.assign(Object.assign({}, d), { id: o }), f), i === "RELEASE" && (t.removeEventListener("message", n), ee(t), L in e && typeof e[L] == "function" && e[L]());
768
- }).catch((c) => {
769
- const [d, f] = A({
770
- value: new TypeError("Unserializable return value"),
771
- [C]: 0
772
- });
773
- t.postMessage(Object.assign(Object.assign({}, d), { id: o }), f);
774
- });
775
- }), t.start && t.start();
776
- }
777
- function He(e) {
778
- return e.constructor.name === "MessagePort";
779
- }
780
- function ee(e) {
781
- He(e) && e.close();
782
- }
783
- function F(e, t) {
784
- return I(e, [], t);
785
- }
786
- function T(e) {
787
- if (e)
788
- throw new Error("Proxy has been released and is not useable");
789
- }
790
- function te(e) {
791
- return E(e, {
792
- type: "RELEASE"
793
- }).then(() => {
794
- ee(e);
795
- });
796
- }
797
- const S = /* @__PURE__ */ new WeakMap(), D = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
798
- const t = (S.get(e) || 0) - 1;
799
- S.set(e, t), t === 0 && te(e);
800
- });
801
- function Fe(e, t) {
802
- const r = (S.get(t) || 0) + 1;
803
- S.set(t, r), D && D.register(e, t, e);
804
- }
805
- function ze(e) {
806
- D && D.unregister(e);
807
- }
808
- function I(e, t = [], r = function() {
809
- }) {
810
- let n = !1;
811
- const s = new Proxy(r, {
812
- get(o, i) {
813
- if (T(n), i === Le)
814
- return () => {
815
- ze(s), te(e), n = !0;
816
- };
817
- if (i === "then") {
818
- if (t.length === 0)
819
- return { then: () => s };
820
- const a = E(e, {
821
- type: "GET",
822
- path: t.map((u) => u.toString())
823
- }).then(g);
824
- return a.then.bind(a);
825
- }
826
- return I(e, [...t, i]);
827
- },
828
- set(o, i, a) {
829
- T(n);
830
- const [u, l] = A(a);
831
- return E(e, {
832
- type: "SET",
833
- path: [...t, i].map((c) => c.toString()),
834
- value: u
835
- }, l).then(g);
836
- },
837
- apply(o, i, a) {
838
- T(n);
839
- const u = t[t.length - 1];
840
- if (u === Me)
841
- return E(e, {
842
- type: "ENDPOINT"
843
- }).then(g);
844
- if (u === "bind")
845
- return I(e, t.slice(0, -1));
846
- const [l, c] = q(a);
847
- return E(e, {
848
- type: "APPLY",
849
- path: t.map((d) => d.toString()),
850
- argumentList: l
851
- }, c).then(g);
852
- },
853
- construct(o, i) {
854
- T(n);
855
- const [a, u] = q(i);
856
- return E(e, {
857
- type: "CONSTRUCT",
858
- path: t.map((l) => l.toString()),
859
- argumentList: a
860
- }, u).then(g);
861
- }
862
- });
863
- return Fe(s, e), s;
864
- }
865
- function Be(e) {
866
- return Array.prototype.concat.apply([], e);
867
- }
868
- function q(e) {
869
- const t = e.map(A);
870
- return [t.map((r) => r[0]), Be(t.map((r) => r[1]))];
871
- }
872
- const re = /* @__PURE__ */ new WeakMap();
873
- function $e(e, t) {
874
- return re.set(e, t), e;
875
- }
876
- function ne(e) {
877
- return Object.assign(e, { [Q]: !0 });
878
- }
879
- function se(e, t = globalThis, r = "*") {
880
- return {
881
- postMessage: (n, s) => e.postMessage(n, r, s),
882
- addEventListener: t.addEventListener.bind(t),
883
- removeEventListener: t.removeEventListener.bind(t)
884
- };
885
- }
886
- function A(e) {
887
- for (const [t, r] of k)
888
- if (r.canHandle(e)) {
889
- const [n, s] = r.serialize(e);
890
- return [
891
- {
892
- type: "HANDLER",
893
- name: t,
894
- value: n
895
- },
896
- s
897
- ];
898
- }
899
- return [
900
- {
901
- type: "RAW",
902
- value: e
903
- },
904
- re.get(e) || []
905
- ];
906
- }
907
- function g(e) {
908
- switch (e.type) {
909
- case "HANDLER":
910
- return k.get(e.name).deserialize(e.value);
911
- case "RAW":
912
- return e.value;
913
- }
914
- }
915
- function E(e, t, r) {
916
- return new Promise((n) => {
917
- const s = je();
918
- e.addEventListener("message", function o(i) {
919
- !i.data || !i.data.id || i.data.id !== s || (e.removeEventListener("message", o), n(i.data));
920
- }), e.start && e.start(), e.postMessage(Object.assign({ id: s }, t), r);
921
- });
922
- }
923
- function je() {
924
- return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
925
- }
926
- function tt(e, t = void 0) {
927
- oe();
928
- const r = e instanceof Worker ? e : se(e, t), n = F(r), s = z(n);
929
- return new Proxy(s, {
930
- get: (o, i) => i === "isConnected" ? async () => {
1
+ import { PHPResponse as C, LatestSupportedPHPVersion as O, loadPHPRuntime as R, FSHelpers as w, __private__dont__use as y } from "@php-wasm/universal";
2
+ import * as d from "/home/runner/work/wordpress-playground/wordpress-playground/node_modules/comlink/dist/esm/comlink.mjs";
3
+ import { PhpWasmError as g, Semaphore as v, joinPaths as T } from "@php-wasm/util";
4
+ import { responseTo as L } from "@php-wasm/web-service-worker";
5
+ import { logger as p } from "@php-wasm/logger";
6
+ import { journalFSEvents as S } from "@php-wasm/fs-journal";
7
+ function B(r, t = void 0) {
8
+ W();
9
+ const e = r instanceof Worker ? r : d.windowEndpoint(r, t), a = d.wrap(e), n = h(a);
10
+ return new Proxy(n, {
11
+ get: (i, s) => s === "isConnected" ? async () => {
931
12
  for (; ; )
932
13
  try {
933
- await _e(n.isConnected(), 200);
14
+ await z(a.isConnected(), 200);
934
15
  break;
935
16
  } catch {
936
17
  }
937
- } : n[i]
18
+ } : a[s]
938
19
  });
939
20
  }
940
- async function _e(e, t) {
941
- return new Promise((r, n) => {
942
- setTimeout(n, t), e.then(r);
21
+ async function z(r, t) {
22
+ return new Promise((e, a) => {
23
+ setTimeout(a, t), r.then(e);
943
24
  });
944
25
  }
945
- function rt(e, t) {
946
- oe();
947
- const r = Promise.resolve();
948
- let n, s;
949
- const o = new Promise((u, l) => {
950
- n = u, s = l;
951
- }), i = z(e), a = new Proxy(i, {
952
- get: (u, l) => l === "isConnected" ? () => r : l === "isReady" ? () => o : l in u ? u[l] : t == null ? void 0 : t[l]
26
+ function Q(r, t) {
27
+ W();
28
+ const e = Promise.resolve();
29
+ let a, n;
30
+ const i = new Promise((o, u) => {
31
+ a = o, n = u;
32
+ }), s = h(r), c = new Proxy(s, {
33
+ get: (o, u) => u === "isConnected" ? () => e : u === "isReady" ? () => i : u in o ? o[u] : t == null ? void 0 : t[u]
953
34
  });
954
- return M(
955
- a,
956
- typeof window < "u" ? se(self.parent) : void 0
957
- ), [n, s, a];
958
- }
959
- let J = !1;
960
- function oe() {
961
- if (J)
35
+ return d.expose(
36
+ c,
37
+ typeof window < "u" ? d.windowEndpoint(self.parent) : void 0
38
+ ), [a, n, c];
39
+ }
40
+ let P = !1;
41
+ function W() {
42
+ if (P)
962
43
  return;
963
- J = !0, k.set("EVENT", {
964
- canHandle: (r) => r instanceof CustomEvent,
965
- serialize: (r) => [
44
+ P = !0, d.transferHandlers.set("EVENT", {
45
+ canHandle: (e) => e instanceof CustomEvent,
46
+ serialize: (e) => [
966
47
  {
967
- detail: r.detail
48
+ detail: e.detail
968
49
  },
969
50
  []
970
51
  ],
971
- deserialize: (r) => r
972
- }), k.set("FUNCTION", {
973
- canHandle: (r) => typeof r == "function",
974
- serialize(r) {
975
- const { port1: n, port2: s } = new MessageChannel();
976
- return M(r, n), [s, [s]];
52
+ deserialize: (e) => e
53
+ }), d.transferHandlers.set("FUNCTION", {
54
+ canHandle: (e) => typeof e == "function",
55
+ serialize(e) {
56
+ const { port1: a, port2: n } = new MessageChannel();
57
+ return d.expose(e, a), [n, [n]];
977
58
  },
978
- deserialize(r) {
979
- return r.start(), F(r);
59
+ deserialize(e) {
60
+ return e.start(), d.wrap(e);
980
61
  }
981
- }), k.set("PHPResponse", {
982
- canHandle: (r) => typeof r == "object" && r !== null && "headers" in r && "bytes" in r && "errors" in r && "exitCode" in r && "httpStatusCode" in r,
983
- serialize(r) {
984
- return [r.toRawData(), []];
62
+ }), d.transferHandlers.set("PHPResponse", {
63
+ canHandle: (e) => typeof e == "object" && e !== null && "headers" in e && "bytes" in e && "errors" in e && "exitCode" in e && "httpStatusCode" in e,
64
+ serialize(e) {
65
+ return [e.toRawData(), []];
985
66
  },
986
- deserialize(r) {
987
- return O.fromRawData(r);
67
+ deserialize(e) {
68
+ return C.fromRawData(e);
988
69
  }
989
70
  });
990
- const e = k.get("throw"), t = e == null ? void 0 : e.serialize;
991
- e.serialize = ({ value: r }) => {
992
- const n = t({ value: r });
993
- return r.response && (n[0].value.response = r.response), r.source && (n[0].value.source = r.source), n;
71
+ const r = d.transferHandlers.get("throw"), t = r == null ? void 0 : r.serialize;
72
+ r.serialize = ({ value: e }) => {
73
+ const a = t({ value: e });
74
+ return e.response && (a[0].value.response = e.response), e.source && (a[0].value.source = e.source), a;
994
75
  };
995
76
  }
996
- function z(e) {
997
- return new Proxy(e, {
998
- get(t, r) {
999
- switch (typeof t[r]) {
77
+ function h(r) {
78
+ return new Proxy(r, {
79
+ get(t, e) {
80
+ switch (typeof t[e]) {
1000
81
  case "function":
1001
- return (...n) => t[r](...n);
82
+ return (...a) => t[e](...a);
1002
83
  case "object":
1003
- return t[r] === null ? t[r] : z(t[r]);
84
+ return t[e] === null ? t[e] : h(t[e]);
1004
85
  case "undefined":
1005
86
  case "number":
1006
87
  case "string":
1007
- return t[r];
88
+ return t[e];
1008
89
  default:
1009
- return ne(t[r]);
90
+ return d.proxy(t[e]);
1010
91
  }
1011
92
  }
1012
93
  });
1013
94
  }
1014
- async function qe(e = Ae, t = "light") {
95
+ async function D(r = O, t = "light") {
1015
96
  if (t === "kitchen-sink")
1016
- switch (e) {
97
+ switch (r) {
1017
98
  case "8.3":
1018
99
  return await import("./kitchen-sink/php_8_3.js");
1019
100
  case "8.2":
@@ -1034,7 +115,7 @@ async function qe(e = Ae, t = "light") {
1034
115
  return await import("./kitchen-sink/php_7_0.js");
1035
116
  }
1036
117
  else
1037
- switch (e) {
118
+ switch (r) {
1038
119
  case "8.3":
1039
120
  return await import("./light/php_8_3.js");
1040
121
  case "8.2":
@@ -1054,11 +135,11 @@ async function qe(e = Ae, t = "light") {
1054
135
  case "7.0":
1055
136
  return await import("./light/php_7_0.js");
1056
137
  }
1057
- throw new Error(`Unsupported PHP version ${e}`);
138
+ throw new Error(`Unsupported PHP version ${r}`);
1058
139
  }
1059
- const Je = () => ({
140
+ const M = () => ({
1060
141
  websocket: {
1061
- decorator: (e) => class extends e {
142
+ decorator: (r) => class extends r {
1062
143
  constructor() {
1063
144
  try {
1064
145
  super();
@@ -1071,424 +152,286 @@ const Je = () => ({
1071
152
  }
1072
153
  }
1073
154
  });
1074
- async function st(e, t = {}) {
1075
- var s;
1076
- const r = t.loadAllExtensions ? "kitchen-sink" : "light", n = await qe(e, r);
1077
- return (s = t.onPhpLoaderModuleLoaded) == null || s.call(t, n), await xe(n, {
155
+ async function G(r, t = {}) {
156
+ var n;
157
+ const e = t.loadAllExtensions ? "kitchen-sink" : "light", a = await D(r, e);
158
+ return (n = t.onPhpLoaderModuleLoaded) == null || n.call(t, a), await R(a, {
1078
159
  ...t.emscriptenOptions || {},
1079
- ...Je()
160
+ ...M()
1080
161
  });
1081
162
  }
1082
- function Ve(e, t) {
1083
- return {
1084
- type: "response",
1085
- requestId: e,
1086
- response: t
1087
- };
1088
- }
1089
- async function ot(e, t, r) {
1090
- const n = navigator.serviceWorker;
1091
- if (!n)
1092
- throw window.isSecureContext ? new j(
163
+ async function K(r, t, e) {
164
+ const a = navigator.serviceWorker;
165
+ if (!a)
166
+ throw window.isSecureContext ? new g(
1093
167
  "Service workers are not supported in your browser."
1094
- ) : new j(
168
+ ) : new g(
1095
169
  "WordPress Playground uses service workers and may only work on HTTPS and http://localhost/ sites, but the current site is neither."
1096
170
  );
1097
- await (await n.register(r, {
171
+ await (await a.register(e, {
1098
172
  type: "module",
1099
173
  // Always bypass HTTP cache when fetching the new Service Worker script:
1100
174
  updateViaCache: "none"
1101
175
  })).update(), navigator.serviceWorker.addEventListener(
1102
176
  "message",
1103
- async function(i) {
1104
- if (t && i.data.scope !== t)
177
+ async function(s) {
178
+ if (t && s.data.scope !== t)
1105
179
  return;
1106
- const a = i.data.args || [], u = i.data.method, l = await e[u](...a);
1107
- i.source.postMessage(Ve(i.data.requestId, l));
180
+ const c = s.data.args || [], o = s.data.method, u = await r[o](...c);
181
+ s.source.postMessage(L(s.data.requestId, u));
1108
182
  }
1109
- ), n.startMessages();
1110
- }
1111
- function it(e, t) {
1112
- window.addEventListener("message", (r) => {
1113
- r.source === e.contentWindow && (t && r.origin !== t || typeof r.data != "object" || r.data.type !== "relay" || window.parent.postMessage(r.data, "*"));
1114
- }), window.addEventListener("message", (r) => {
1115
- var n;
1116
- r.source === window.parent && (typeof r.data != "object" || r.data.type !== "relay" || (n = e == null ? void 0 : e.contentWindow) == null || n.postMessage(r.data));
183
+ ), a.startMessages();
184
+ }
185
+ function X(r, t) {
186
+ window.addEventListener("message", (e) => {
187
+ e.source === r.contentWindow && (t && e.origin !== t || typeof e.data != "object" || e.data.type !== "relay" || window.parent.postMessage(e.data, "*"));
188
+ }), window.addEventListener("message", (e) => {
189
+ var a;
190
+ e.source === window.parent && (typeof e.data != "object" || e.data.type !== "relay" || (a = r == null ? void 0 : r.contentWindow) == null || a.postMessage(e.data));
1117
191
  });
1118
192
  }
1119
- async function at(e, t = {}) {
1120
- e = Ue(e, t);
1121
- const r = new Worker(e, { type: "module" });
1122
- return new Promise((n, s) => {
1123
- r.onerror = (i) => {
1124
- const a = new Error(
1125
- `WebWorker failed to load at ${e}. ${i.message ? `Original error: ${i.message}` : ""}`
193
+ async function Y(r, t = {}) {
194
+ r = A(r, t);
195
+ const e = new Worker(r, { type: "module" });
196
+ return new Promise((a, n) => {
197
+ e.onerror = (s) => {
198
+ const c = new Error(
199
+ `WebWorker failed to load at ${r}. ${s.message ? `Original error: ${s.message}` : ""}`
1126
200
  );
1127
- a.filename = i.filename, s(a);
201
+ c.filename = s.filename, n(c);
1128
202
  };
1129
- function o(i) {
1130
- i.data === "worker-script-started" && (n(r), r.removeEventListener("message", o));
203
+ function i(s) {
204
+ s.data === "worker-script-started" && (a(e), e.removeEventListener("message", i));
1131
205
  }
1132
- r.addEventListener("message", o);
206
+ e.addEventListener("message", i);
1133
207
  });
1134
208
  }
1135
- function Ue(e, t) {
209
+ function A(r, t) {
1136
210
  if (!Object.entries(t).length)
1137
- return e + "";
1138
- const r = new URL(e);
1139
- for (const [n, s] of Object.entries(t))
1140
- if (Array.isArray(s))
1141
- for (const o of s)
1142
- r.searchParams.append(n, o);
211
+ return r + "";
212
+ const e = new URL(r);
213
+ for (const [a, n] of Object.entries(t))
214
+ if (Array.isArray(n))
215
+ for (const i of n)
216
+ e.searchParams.append(a, i);
1143
217
  else
1144
- r.searchParams.set(n, s);
1145
- return r.toString();
1146
- }
1147
- function Ge(e, t, r = () => {
1148
- }) {
1149
- function n() {
1150
- t = Ye(t);
1151
- const o = e[w].FS, i = Ke(o, (c) => {
1152
- if (c.path.startsWith(t))
1153
- r(c);
1154
- else if (c.operation === "RENAME" && c.toPath.startsWith(t))
1155
- for (const d of ie(
1156
- e,
1157
- c.path,
1158
- c.toPath
1159
- ))
1160
- r(d);
1161
- }), a = {};
1162
- for (const [c] of Object.entries(i))
1163
- a[c] = o[c];
1164
- function u() {
1165
- for (const [c, d] of Object.entries(i))
1166
- o[c] = function(...f) {
1167
- return d(...f), a[c].apply(this, f);
1168
- };
1169
- }
1170
- function l() {
1171
- for (const [c, d] of Object.entries(a))
1172
- e[w].FS[c] = d;
1173
- }
1174
- e[w].journal = {
1175
- bind: u,
1176
- unbind: l
1177
- }, u();
1178
- }
1179
- e.addEventListener("runtime.initialized", n), e[w] && n();
1180
- function s() {
1181
- e[w].journal.unbind(), delete e[w].journal;
1182
- }
1183
- return e.addEventListener("runtime.beforedestroy", s), function() {
1184
- return e.removeEventListener("runtime.initialized", n), e.removeEventListener("runtime.beforedestroy", s), e[w].journal.unbind();
1185
- };
1186
- }
1187
- const Ke = (e, t = () => {
1188
- }) => ({
1189
- write(r) {
1190
- t({
1191
- operation: "WRITE",
1192
- path: r.path,
1193
- nodeType: "file"
1194
- });
1195
- },
1196
- truncate(r) {
1197
- let n;
1198
- typeof r == "string" ? n = e.lookupPath(r, {
1199
- follow: !0
1200
- }).node : n = r, t({
1201
- operation: "WRITE",
1202
- path: e.getPath(n),
1203
- nodeType: "file"
1204
- });
1205
- },
1206
- unlink(r) {
1207
- t({
1208
- operation: "DELETE",
1209
- path: r,
1210
- nodeType: "file"
1211
- });
1212
- },
1213
- mknod(r, n) {
1214
- e.isFile(n) && t({
1215
- operation: "CREATE",
1216
- path: r,
1217
- nodeType: "file"
1218
- });
1219
- },
1220
- mkdir(r) {
1221
- t({
1222
- operation: "CREATE",
1223
- path: r,
1224
- nodeType: "directory"
1225
- });
1226
- },
1227
- rmdir(r) {
1228
- t({
1229
- operation: "DELETE",
1230
- path: r,
1231
- nodeType: "directory"
1232
- });
1233
- },
1234
- rename(r, n) {
1235
- try {
1236
- const s = e.lookupPath(r, {
1237
- follow: !0
1238
- }), o = e.lookupPath(n, {
1239
- parent: !0
1240
- }).path;
1241
- t({
1242
- operation: "RENAME",
1243
- nodeType: e.isDir(s.node.mode) ? "directory" : "file",
1244
- path: s.path,
1245
- toPath: b(o, Ee(n))
1246
- });
1247
- } catch {
1248
- }
1249
- }
1250
- });
1251
- function* ie(e, t, r) {
1252
- if (e.isDir(t)) {
1253
- yield {
1254
- operation: "CREATE",
1255
- path: r,
1256
- nodeType: "directory"
1257
- };
1258
- for (const n of e.listFiles(t))
1259
- yield* ie(
1260
- e,
1261
- b(t, n),
1262
- b(r, n)
1263
- );
1264
- } else
1265
- yield {
1266
- operation: "CREATE",
1267
- path: r,
1268
- nodeType: "file"
1269
- }, yield {
1270
- operation: "WRITE",
1271
- nodeType: "file",
1272
- path: r
1273
- };
218
+ e.searchParams.set(a, n);
219
+ return e.toString();
1274
220
  }
1275
- function Ye(e) {
1276
- return e.replace(/\/$/, "").replace(/\/\/+/g, "/");
1277
- }
1278
- function ct(e, t = { initialSync: {} }) {
221
+ function Z(r, t = { initialSync: {} }) {
1279
222
  return t = {
1280
223
  ...t,
1281
224
  initialSync: {
1282
225
  ...t.initialSync,
1283
226
  direction: t.initialSync.direction ?? "opfs-to-memfs"
1284
227
  }
1285
- }, async function(r, n, s) {
1286
- return t.initialSync.direction === "opfs-to-memfs" ? (R.fileExists(n, s) && R.rmdir(n, s), R.mkdir(n, s), await Ze(n, e, s)) : await ae(
228
+ }, async function(e, a, n) {
229
+ return t.initialSync.direction === "opfs-to-memfs" ? (w.fileExists(a, n) && w.rmdir(a, n), w.mkdir(a, n), await I(a, r, n)) : await b(
230
+ a,
231
+ r,
1287
232
  n,
1288
- e,
1289
- s,
1290
233
  t.initialSync.onProgress
1291
- ), Xe(r, e, s);
234
+ ), $(e, r, n);
1292
235
  };
1293
236
  }
1294
- async function Ze(e, t, r) {
1295
- R.mkdir(e, r);
1296
- const n = new ge({
237
+ async function I(r, t, e) {
238
+ w.mkdir(r, e);
239
+ const a = new v({
1297
240
  concurrency: 40
1298
- }), s = [], o = [
1299
- [t, r]
241
+ }), n = [], i = [
242
+ [t, e]
1300
243
  ];
1301
- for (; o.length > 0; ) {
1302
- const [i, a] = o.pop();
1303
- for await (const u of i.values()) {
1304
- const l = n.run(async () => {
1305
- const c = b(
1306
- a,
1307
- u.name
244
+ for (; i.length > 0; ) {
245
+ const [s, c] = i.pop();
246
+ for await (const o of s.values()) {
247
+ const u = a.run(async () => {
248
+ const l = T(
249
+ c,
250
+ o.name
1308
251
  );
1309
- if (u.kind === "directory") {
252
+ if (o.kind === "directory") {
1310
253
  try {
1311
- e.mkdir(c);
1312
- } catch (d) {
1313
- if ((d == null ? void 0 : d.errno) !== 20)
1314
- throw v.error(d), d;
254
+ r.mkdir(l);
255
+ } catch (f) {
256
+ if ((f == null ? void 0 : f.errno) !== 20)
257
+ throw p.error(f), f;
1315
258
  }
1316
- o.push([u, c]);
1317
- } else if (u.kind === "file") {
1318
- const d = await u.getFile(), f = new Uint8Array(await d.arrayBuffer());
1319
- e.createDataFile(
1320
- a,
1321
- u.name,
1322
- f,
259
+ i.push([o, l]);
260
+ } else if (o.kind === "file") {
261
+ const f = await o.getFile(), m = new Uint8Array(await f.arrayBuffer());
262
+ r.createDataFile(
263
+ c,
264
+ o.name,
265
+ m,
1323
266
  !0,
1324
267
  !0,
1325
268
  !0
1326
269
  );
1327
270
  }
1328
- s.splice(s.indexOf(l), 1);
271
+ n.splice(n.indexOf(u), 1);
1329
272
  });
1330
- s.push(l);
273
+ n.push(u);
1331
274
  }
1332
- for (; o.length === 0 && s.length > 0; )
1333
- await Promise.any(s);
275
+ for (; i.length === 0 && n.length > 0; )
276
+ await Promise.any(n);
1334
277
  }
1335
278
  }
1336
- async function ae(e, t, r, n) {
1337
- e.mkdirTree(r);
1338
- const s = [];
1339
- async function o(u, l) {
279
+ async function b(r, t, e, a) {
280
+ r.mkdirTree(e);
281
+ const n = [];
282
+ async function i(o, u) {
1340
283
  await Promise.all(
1341
- e.readdir(u).filter(
1342
- (c) => c !== "." && c !== ".."
1343
- ).map(async (c) => {
1344
- const d = b(u, c);
1345
- if (!Qe(e, d)) {
1346
- s.push([l, d, c]);
284
+ r.readdir(o).filter(
285
+ (l) => l !== "." && l !== ".."
286
+ ).map(async (l) => {
287
+ const f = T(o, l);
288
+ if (!_(r, f)) {
289
+ n.push([u, f, l]);
1347
290
  return;
1348
291
  }
1349
- const f = await l.getDirectoryHandle(c, {
292
+ const m = await u.getDirectoryHandle(l, {
1350
293
  create: !0
1351
294
  });
1352
- return await o(d, f);
295
+ return await i(f, m);
1353
296
  })
1354
297
  );
1355
298
  }
1356
- await o(r, t);
1357
- let i = 0;
1358
- const a = s.map(
1359
- ([u, l, c]) => ce(u, c, e, l).then(() => {
1360
- n == null || n({ files: ++i, total: s.length });
299
+ await i(e, t);
300
+ let s = 0;
301
+ const c = n.map(
302
+ ([o, u, l]) => x(o, l, r, u).then(() => {
303
+ a == null || a({ files: ++s, total: n.length });
1361
304
  })
1362
305
  );
1363
- await Promise.all(a);
306
+ await Promise.all(c);
1364
307
  }
1365
- function Qe(e, t) {
1366
- return e.isDir(e.lookupPath(t, { follow: !0 }).node.mode);
308
+ function _(r, t) {
309
+ return r.isDir(r.lookupPath(t, { follow: !0 }).node.mode);
1367
310
  }
1368
- async function ce(e, t, r, n) {
1369
- let s;
311
+ async function x(r, t, e, a) {
312
+ let n;
1370
313
  try {
1371
- s = r.readFile(n, {
314
+ n = e.readFile(a, {
1372
315
  encoding: "binary"
1373
316
  });
1374
317
  } catch {
1375
318
  return;
1376
319
  }
1377
- const o = await e.getFileHandle(t, { create: !0 }), i = o.createWritable !== void 0 ? (
320
+ const i = await r.getFileHandle(t, { create: !0 }), s = i.createWritable !== void 0 ? (
1378
321
  // Google Chrome, Firefox, probably more browsers
1379
- await o.createWritable()
322
+ await i.createWritable()
1380
323
  ) : (
1381
324
  // Safari
1382
- await o.createSyncAccessHandle()
325
+ await i.createSyncAccessHandle()
1383
326
  );
1384
327
  try {
1385
- await i.truncate(0), await i.write(s);
328
+ await s.truncate(0), await s.write(n);
1386
329
  } finally {
1387
- await i.close();
330
+ await s.close();
1388
331
  }
1389
332
  }
1390
- function Xe(e, t, r) {
1391
- const n = [], s = Ge(e, r, (a) => {
1392
- n.push(a);
1393
- }), o = new et(e, t, r);
1394
- async function i() {
1395
- const a = await e.semaphore.acquire();
333
+ function $(r, t, e) {
334
+ const a = [], n = S(r, e, (c) => {
335
+ a.push(c);
336
+ }), i = new j(r, t, e);
337
+ async function s() {
338
+ const c = await r.semaphore.acquire();
1396
339
  try {
1397
- for (; n.length; )
1398
- await o.processEntry(n.shift());
340
+ for (; a.length; )
341
+ await i.processEntry(a.shift());
1399
342
  } finally {
1400
- a();
343
+ c();
1401
344
  }
1402
345
  }
1403
- return e.addEventListener("request.end", i), function() {
1404
- s(), e.removeEventListener("request.end", i);
346
+ return r.addEventListener("request.end", s), function() {
347
+ n(), r.removeEventListener("request.end", s);
1405
348
  };
1406
349
  }
1407
- class et {
1408
- constructor(t, r, n) {
1409
- this.php = t, this.opfs = r, this.memfsRoot = V(n);
350
+ class j {
351
+ constructor(t, e, a) {
352
+ this.php = t, this.opfs = e, this.memfsRoot = E(a);
1410
353
  }
1411
354
  toOpfsPath(t) {
1412
- return V(t.substring(this.memfsRoot.length));
355
+ return E(t.substring(this.memfsRoot.length));
1413
356
  }
1414
357
  async processEntry(t) {
1415
358
  if (!t.path.startsWith(this.memfsRoot) || t.path === this.memfsRoot)
1416
359
  return;
1417
- const r = this.toOpfsPath(t.path), n = await G(this.opfs, r), s = U(r);
1418
- if (s)
360
+ const e = this.toOpfsPath(t.path), a = await H(this.opfs, e), n = k(e);
361
+ if (n)
1419
362
  try {
1420
363
  if (t.operation === "DELETE")
1421
364
  try {
1422
- await n.removeEntry(s, {
365
+ await a.removeEntry(n, {
1423
366
  recursive: !0
1424
367
  });
1425
368
  } catch {
1426
369
  }
1427
370
  else if (t.operation === "CREATE")
1428
- t.nodeType === "directory" ? await n.getDirectoryHandle(s, {
371
+ t.nodeType === "directory" ? await a.getDirectoryHandle(n, {
1429
372
  create: !0
1430
- }) : await n.getFileHandle(s, {
373
+ }) : await a.getFileHandle(n, {
1431
374
  create: !0
1432
375
  });
1433
376
  else if (t.operation === "WRITE")
1434
- await ce(
377
+ await x(
378
+ a,
1435
379
  n,
1436
- s,
1437
- this.php[w].FS,
380
+ this.php[y].FS,
1438
381
  t.path
1439
382
  );
1440
383
  else if (t.operation === "RENAME" && t.toPath.startsWith(this.memfsRoot)) {
1441
- const o = this.toOpfsPath(t.toPath), i = await G(
384
+ const i = this.toOpfsPath(t.toPath), s = await H(
1442
385
  this.opfs,
1443
- o
1444
- ), a = U(o);
386
+ i
387
+ ), c = k(i);
1445
388
  if (t.nodeType === "directory") {
1446
- const u = await i.getDirectoryHandle(
1447
- s,
389
+ const o = await s.getDirectoryHandle(
390
+ n,
1448
391
  {
1449
392
  create: !0
1450
393
  }
1451
394
  );
1452
- await ae(
1453
- this.php[w].FS,
1454
- u,
395
+ await b(
396
+ this.php[y].FS,
397
+ o,
1455
398
  t.toPath
1456
- ), await n.removeEntry(s, {
399
+ ), await a.removeEntry(n, {
1457
400
  recursive: !0
1458
401
  });
1459
402
  } else
1460
- (await n.getFileHandle(s)).move(i, a);
403
+ (await a.getFileHandle(n)).move(s, c);
1461
404
  }
1462
- } catch (o) {
1463
- throw v.log({ entry: t, name: s }), v.error(o), o;
405
+ } catch (i) {
406
+ throw p.log({ entry: t, name: n }), p.error(i), i;
1464
407
  }
1465
408
  }
1466
409
  }
1467
- function V(e) {
1468
- return e.replace(/\/$/, "").replace(/\/\/+/g, "/");
410
+ function E(r) {
411
+ return r.replace(/\/$/, "").replace(/\/\/+/g, "/");
1469
412
  }
1470
- function U(e) {
1471
- return e.substring(e.lastIndexOf("/") + 1);
413
+ function k(r) {
414
+ return r.substring(r.lastIndexOf("/") + 1);
1472
415
  }
1473
- async function G(e, t) {
1474
- const r = t.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
1475
- if (!r)
1476
- return e;
1477
- const n = r.split("/");
1478
- let s = e;
1479
- for (let o = 0; o < n.length - 1; o++) {
1480
- const i = n[o];
1481
- s = await s.getDirectoryHandle(i, { create: !0 });
416
+ async function H(r, t) {
417
+ const e = t.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
418
+ if (!e)
419
+ return r;
420
+ const a = e.split("/");
421
+ let n = r;
422
+ for (let i = 0; i < a.length - 1; i++) {
423
+ const s = a[i];
424
+ n = await n.getDirectoryHandle(s, { create: !0 });
1482
425
  }
1483
- return s;
426
+ return n;
1484
427
  }
1485
428
  export {
1486
- tt as consumeAPI,
1487
- ct as createDirectoryHandleMountHandler,
1488
- rt as exposeAPI,
1489
- qe as getPHPLoaderModule,
1490
- st as loadWebRuntime,
1491
- ot as registerServiceWorker,
1492
- it as setupPostMessageRelay,
1493
- at as spawnPHPWorkerThread
429
+ B as consumeAPI,
430
+ Z as createDirectoryHandleMountHandler,
431
+ Q as exposeAPI,
432
+ D as getPHPLoaderModule,
433
+ G as loadWebRuntime,
434
+ K as registerServiceWorker,
435
+ X as setupPostMessageRelay,
436
+ Y as spawnPHPWorkerThread
1494
437
  };