@php-wasm/web 0.0.1

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.
@@ -0,0 +1,1054 @@
1
+ const u = "string", m = "number", b = [];
2
+ async function le(t, e = {}, n = []) {
3
+ let r, s;
4
+ const l = new Promise((o) => {
5
+ s = o;
6
+ }), i = new Promise((o) => {
7
+ r = o;
8
+ }), a = t.default(D, {
9
+ onAbort(o) {
10
+ console.error("WASM aborted: "), console.error(o);
11
+ },
12
+ ENV: {},
13
+ // Emscripten sometimes prepends a '/' to the path, which
14
+ // breaks vite dev mode. An identity `locateFile` function
15
+ // fixes it.
16
+ locateFile: (o) => o,
17
+ ...e,
18
+ noInitialRun: !0,
19
+ onRuntimeInitialized() {
20
+ e.onRuntimeInitialized && e.onRuntimeInitialized(), r();
21
+ },
22
+ monitorRunDependencies(o) {
23
+ o === 0 && (delete a.monitorRunDependencies, s());
24
+ }
25
+ });
26
+ for (const { default: o } of n)
27
+ o(a);
28
+ return n.length || s(), await l, await i, b.push(a), b.length - 1;
29
+ }
30
+ const D = function() {
31
+ return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
32
+ }();
33
+ class ce {
34
+ #e;
35
+ #t = [];
36
+ #n = !1;
37
+ /**
38
+ * Initializes a PHP runtime.
39
+ *
40
+ * @internal
41
+ * @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
42
+ */
43
+ constructor(e) {
44
+ e !== void 0 && this.initializeRuntime(e);
45
+ }
46
+ initializeRuntime(e) {
47
+ if (this.#e)
48
+ throw new Error("PHP runtime already initialized.");
49
+ if (!b[e])
50
+ throw new Error("Invalid PHP runtime id.");
51
+ this.#e = b[e];
52
+ }
53
+ /** @inheritDoc */
54
+ setPhpIniPath(e) {
55
+ if (this.#n)
56
+ throw new Error("Cannot set PHP ini path after calling run().");
57
+ this.#e.ccall("wasm_set_phpini_path", null, ["string"], [e]);
58
+ }
59
+ /** @inheritDoc */
60
+ setPhpIniEntry(e, n) {
61
+ if (this.#n)
62
+ throw new Error("Cannot set PHP ini entries after calling run().");
63
+ this.#t.push([e, n]);
64
+ }
65
+ /** @inheritDoc */
66
+ run(e = {}) {
67
+ this.#n || (this.#s(), this.#n = !0), this.#u(e.scriptPath || ""), this.#r(e.relativeUri || ""), this.#o(e.method || "GET");
68
+ const { host: n, ...r } = {
69
+ host: "example.com:443",
70
+ ...j(e.headers || {})
71
+ };
72
+ if (this.#a(n, e.protocol || "http"), this.#l(r), e.body && this.#c(e.body), e.fileInfos)
73
+ for (const s of e.fileInfos)
74
+ this.#h(s);
75
+ return e.code && this.#f(" ?>" + e.code), this.#d();
76
+ }
77
+ #s() {
78
+ if (this.#t.length > 0) {
79
+ const e = this.#t.map(([n, r]) => `${n}=${r}`).join(`
80
+ `);
81
+ this.#e.ccall(
82
+ "wasm_set_phpini_entries",
83
+ null,
84
+ [u],
85
+ [e]
86
+ );
87
+ }
88
+ this.#e.ccall("php_wasm_init", null, [], []);
89
+ }
90
+ cli(e) {
91
+ for (const n of e)
92
+ this.#e.ccall("wasm_add_cli_arg", null, [u], [n]);
93
+ return this.#e.ccall("run_cli", null, [], [], { async: !0 });
94
+ }
95
+ #i() {
96
+ const e = "/tmp/headers.json";
97
+ if (!this.fileExists(e))
98
+ throw new Error(
99
+ "SAPI Error: Could not find response headers file."
100
+ );
101
+ const n = JSON.parse(this.readFileAsText(e)), r = {};
102
+ for (const s of n.headers) {
103
+ if (!s.includes(": "))
104
+ continue;
105
+ const l = s.indexOf(": "), i = s.substring(0, l).toLowerCase(), a = s.substring(l + 2);
106
+ i in r || (r[i] = []), r[i].push(a);
107
+ }
108
+ return {
109
+ headers: r,
110
+ httpStatusCode: n.status
111
+ };
112
+ }
113
+ #r(e) {
114
+ if (this.#e.ccall("wasm_set_request_uri", null, [u], [e]), e.includes("?")) {
115
+ const n = e.substring(e.indexOf("?") + 1);
116
+ this.#e.ccall(
117
+ "wasm_set_query_string",
118
+ null,
119
+ [u],
120
+ [n]
121
+ );
122
+ }
123
+ }
124
+ #a(e, n) {
125
+ this.#e.ccall("wasm_set_request_host", null, [u], [e]);
126
+ let r;
127
+ try {
128
+ r = parseInt(new URL(e).port, 10);
129
+ } catch {
130
+ }
131
+ (!r || isNaN(r) || r === 80) && (r = n === "https" ? 443 : 80), this.#e.ccall("wasm_set_request_port", null, [m], [r]), (n === "https" || !n && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
132
+ }
133
+ #o(e) {
134
+ this.#e.ccall("wasm_set_request_method", null, [u], [e]);
135
+ }
136
+ setSkipShebang(e) {
137
+ this.#e.ccall(
138
+ "wasm_set_skip_shebang",
139
+ null,
140
+ [m],
141
+ [e ? 1 : 0]
142
+ );
143
+ }
144
+ #l(e) {
145
+ e.cookie && this.#e.ccall(
146
+ "wasm_set_cookies",
147
+ null,
148
+ [u],
149
+ [e.cookie]
150
+ ), e["content-type"] && this.#e.ccall(
151
+ "wasm_set_content_type",
152
+ null,
153
+ [u],
154
+ [e["content-type"]]
155
+ ), e["content-length"] && this.#e.ccall(
156
+ "wasm_set_content_length",
157
+ null,
158
+ [m],
159
+ [parseInt(e["content-length"], 10)]
160
+ );
161
+ for (const n in e)
162
+ this.addServerGlobalEntry(
163
+ `HTTP_${n.toUpperCase().replace(/-/g, "_")}`,
164
+ e[n]
165
+ );
166
+ }
167
+ #c(e) {
168
+ this.#e.ccall("wasm_set_request_body", null, [u], [e]), this.#e.ccall(
169
+ "wasm_set_content_length",
170
+ null,
171
+ [m],
172
+ [e.length]
173
+ );
174
+ }
175
+ #u(e) {
176
+ this.#e.ccall("wasm_set_path_translated", null, [u], [e]);
177
+ }
178
+ addServerGlobalEntry(e, n) {
179
+ this.#e.ccall(
180
+ "wasm_add_SERVER_entry",
181
+ null,
182
+ [u, u],
183
+ [e, n]
184
+ );
185
+ }
186
+ /**
187
+ * Adds file information to $_FILES superglobal in PHP.
188
+ *
189
+ * In particular:
190
+ * * Creates the file data in the filesystem
191
+ * * Registers the file details in PHP
192
+ *
193
+ * @param fileInfo - File details
194
+ */
195
+ #h(e) {
196
+ const { key: n, name: r, type: s, data: l } = e, i = `/tmp/${Math.random().toFixed(20)}`;
197
+ this.writeFile(i, l);
198
+ const a = 0;
199
+ this.#e.ccall(
200
+ "wasm_add_uploaded_file",
201
+ null,
202
+ [u, u, u, u, m, m],
203
+ [n, r, s, i, a, l.byteLength]
204
+ );
205
+ }
206
+ #f(e) {
207
+ this.#e.ccall("wasm_set_php_code", null, [u], [e]);
208
+ }
209
+ #d() {
210
+ return {
211
+ exitCode: this.#e.ccall(
212
+ "wasm_sapi_handle_request",
213
+ m,
214
+ [],
215
+ []
216
+ ),
217
+ body: this.readFileAsBuffer("/tmp/stdout"),
218
+ errors: this.readFileAsText("/tmp/stderr"),
219
+ ...this.#i()
220
+ };
221
+ }
222
+ mkdirTree(e) {
223
+ this.#e.FS.mkdirTree(e);
224
+ }
225
+ readFileAsText(e) {
226
+ return new TextDecoder().decode(this.readFileAsBuffer(e));
227
+ }
228
+ /** @inheritDoc */
229
+ readFileAsBuffer(e) {
230
+ return this.#e.FS.readFile(e);
231
+ }
232
+ /** @inheritDoc */
233
+ writeFile(e, n) {
234
+ this.#e.FS.writeFile(e, n);
235
+ }
236
+ /** @inheritDoc */
237
+ unlink(e) {
238
+ this.#e.FS.unlink(e);
239
+ }
240
+ /** @inheritDoc */
241
+ listFiles(e) {
242
+ if (!this.fileExists(e))
243
+ return [];
244
+ try {
245
+ return this.#e.FS.readdir(e).filter(
246
+ (n) => n !== "." && n !== ".."
247
+ );
248
+ } catch (n) {
249
+ return console.error(n, { path: e }), [];
250
+ }
251
+ }
252
+ isDir(e) {
253
+ return this.fileExists(e) ? this.#e.FS.isDir(
254
+ this.#e.FS.lookupPath(e).node.mode
255
+ ) : !1;
256
+ }
257
+ fileExists(e) {
258
+ try {
259
+ return this.#e.FS.lookupPath(e), !0;
260
+ } catch {
261
+ return !1;
262
+ }
263
+ }
264
+ mount(e, n) {
265
+ this.#e.FS.mount(
266
+ this.#e.FS.filesystems.NODEFS,
267
+ e,
268
+ n
269
+ );
270
+ }
271
+ }
272
+ function j(t) {
273
+ const e = {};
274
+ for (const n in t)
275
+ e[n.toLowerCase()] = t[n];
276
+ return e;
277
+ }
278
+ const B = "http://example.com";
279
+ function U(t) {
280
+ return t.toString().substring(t.origin.length);
281
+ }
282
+ function O(t, e) {
283
+ return !e || !t.startsWith(e) ? t : t.substring(e.length);
284
+ }
285
+ function G(t, e) {
286
+ return !e || t.startsWith(e) ? t : e + t;
287
+ }
288
+ class ue {
289
+ #e;
290
+ #t;
291
+ #n;
292
+ #s;
293
+ #i;
294
+ #r;
295
+ #a;
296
+ #o;
297
+ /**
298
+ * @param php - The PHP instance.
299
+ * @param config - Server configuration.
300
+ */
301
+ constructor(e, n = {}) {
302
+ const {
303
+ documentRoot: r = "/www/",
304
+ absoluteUrl: s = location.origin,
305
+ isStaticFilePath: l = () => !1
306
+ } = n;
307
+ this.php = e, this.#e = r, this.#o = l;
308
+ const i = new URL(s);
309
+ this.#n = i.hostname, this.#s = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
310
+ const a = this.#s !== 443 && this.#s !== 80;
311
+ this.#i = [
312
+ this.#n,
313
+ a ? `:${this.#s}` : ""
314
+ ].join(""), this.#r = i.pathname.replace(/\/+$/, ""), this.#a = [
315
+ `${this.#t}://`,
316
+ this.#i,
317
+ this.#r
318
+ ].join("");
319
+ }
320
+ /**
321
+ * Converts a path to an absolute URL based at the PHPServer
322
+ * root.
323
+ *
324
+ * @param path The server path to convert to an absolute URL.
325
+ * @returns The absolute URL.
326
+ */
327
+ pathToInternalUrl(e) {
328
+ return `${this.absoluteUrl}${e}`;
329
+ }
330
+ /**
331
+ * Converts an absolute URL based at the PHPServer to a relative path
332
+ * without the server pathname and scope.
333
+ *
334
+ * @param internalUrl An absolute URL based at the PHPServer root.
335
+ * @returns The relative path.
336
+ */
337
+ internalUrlToPath(e) {
338
+ const n = new URL(e);
339
+ return n.pathname.startsWith(this.#r) && (n.pathname = n.pathname.slice(this.#r.length)), U(n);
340
+ }
341
+ /**
342
+ * The absolute URL of this PHPServer instance.
343
+ */
344
+ get absoluteUrl() {
345
+ return this.#a;
346
+ }
347
+ /**
348
+ * The absolute URL of this PHPServer instance.
349
+ */
350
+ get documentRoot() {
351
+ return this.#e;
352
+ }
353
+ /**
354
+ * Serves the request – either by serving a static file, or by
355
+ * dispatching it to the PHP runtime.
356
+ *
357
+ * @param request - The request.
358
+ * @returns The response.
359
+ */
360
+ async request(e) {
361
+ let n;
362
+ e.relativeUrl !== void 0 ? n = new URL(e.relativeUrl, B) : n = new URL(e.absoluteUrl);
363
+ const r = O(
364
+ n.pathname,
365
+ this.#r
366
+ );
367
+ return this.#o(r) ? this.#l(r) : await this.#c(e, n);
368
+ }
369
+ /**
370
+ * Serves a static file from the PHP filesystem.
371
+ *
372
+ * @param path - The requested static file path.
373
+ * @returns The response.
374
+ */
375
+ #l(e) {
376
+ const n = `${this.#e}${e}`;
377
+ if (!this.php.fileExists(n))
378
+ return {
379
+ body: new TextEncoder().encode("404 File not found"),
380
+ headers: {},
381
+ httpStatusCode: 404,
382
+ exitCode: 0,
383
+ errors: ""
384
+ };
385
+ const r = this.php.readFileAsBuffer(n);
386
+ return {
387
+ body: r,
388
+ headers: {
389
+ "content-length": [`${r.byteLength}`],
390
+ // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
391
+ // The code below won't return the correct mime-type if the extension
392
+ // was tampered with.
393
+ "content-type": [V(n)],
394
+ "accept-ranges": ["bytes"],
395
+ "cache-control": ["public, max-age=0"]
396
+ },
397
+ httpStatusCode: 200,
398
+ exitCode: 0,
399
+ errors: ""
400
+ };
401
+ }
402
+ /**
403
+ * Runs the requested PHP file with all the request and $_SERVER
404
+ * superglobals populated.
405
+ *
406
+ * @param request - The request.
407
+ * @returns The response.
408
+ */
409
+ async #c(e, n) {
410
+ this.php.addServerGlobalEntry("DOCUMENT_ROOT", this.#e), this.php.addServerGlobalEntry(
411
+ "HTTPS",
412
+ this.#a.startsWith("https://") ? "on" : ""
413
+ );
414
+ let r = "GET";
415
+ const s = [];
416
+ if (e.files) {
417
+ r = "POST";
418
+ for (const a in e.files) {
419
+ const o = e.files[a];
420
+ s.push({
421
+ key: a,
422
+ name: o.name,
423
+ type: o.type,
424
+ data: new Uint8Array(await o.arrayBuffer())
425
+ });
426
+ }
427
+ }
428
+ const l = {
429
+ host: this.#i
430
+ };
431
+ let i;
432
+ return e.formData !== void 0 ? (r = "POST", l["content-type"] = "application/x-www-form-urlencoded", i = new URLSearchParams(
433
+ e.formData
434
+ ).toString()) : i = e.body, this.php.run({
435
+ relativeUri: G(
436
+ U(n),
437
+ this.#r
438
+ ),
439
+ protocol: this.#t,
440
+ method: e.method || r,
441
+ body: i,
442
+ fileInfos: s,
443
+ scriptPath: this.#u(n.pathname),
444
+ headers: {
445
+ ...l,
446
+ ...e.headers || {}
447
+ }
448
+ });
449
+ }
450
+ /**
451
+ * Resolve the requested path to the filesystem path of the requested PHP file.
452
+ *
453
+ * Fall back to index.php as if there was a url rewriting rule in place.
454
+ *
455
+ * @param requestedPath - The requested pathname.
456
+ * @returns The resolved filesystem path.
457
+ */
458
+ #u(e) {
459
+ let n = O(e, this.#r);
460
+ n.includes(".php") ? n = n.split(".php")[0] + ".php" : (n.endsWith("/") || (n += "/"), n.endsWith("index.php") || (n += "index.php"));
461
+ const r = `${this.#e}${n}`;
462
+ return this.php.fileExists(r) ? r : `${this.#e}/index.php`;
463
+ }
464
+ }
465
+ function V(t) {
466
+ switch (t.split(".").pop()) {
467
+ case "css":
468
+ return "text/css";
469
+ case "js":
470
+ return "application/javascript";
471
+ case "png":
472
+ return "image/png";
473
+ case "jpg":
474
+ case "jpeg":
475
+ return "image/jpeg";
476
+ case "gif":
477
+ return "image/gif";
478
+ case "svg":
479
+ return "image/svg+xml";
480
+ case "woff":
481
+ return "font/woff";
482
+ case "woff2":
483
+ return "font/woff2";
484
+ case "ttf":
485
+ return "font/ttf";
486
+ case "otf":
487
+ return "font/otf";
488
+ case "eot":
489
+ return "font/eot";
490
+ case "ico":
491
+ return "image/x-icon";
492
+ case "html":
493
+ return "text/html";
494
+ case "json":
495
+ return "application/json";
496
+ case "xml":
497
+ return "application/xml";
498
+ case "txt":
499
+ case "md":
500
+ return "text/plain";
501
+ default:
502
+ return "application-octet-stream";
503
+ }
504
+ }
505
+ class he {
506
+ #e;
507
+ #t;
508
+ /**
509
+ * @param server - The PHP server to browse.
510
+ * @param config - The browser configuration.
511
+ */
512
+ constructor(e, n = {}) {
513
+ this.server = e, this.#e = {}, this.#t = {
514
+ handleRedirects: !1,
515
+ maxRedirects: 4,
516
+ ...n
517
+ };
518
+ }
519
+ async request(e, n = 0) {
520
+ const r = await this.server.request({
521
+ ...e,
522
+ headers: {
523
+ ...e.headers,
524
+ cookie: this.#s()
525
+ }
526
+ });
527
+ if (r.headers["set-cookie"] && this.#n(r.headers["set-cookie"]), this.#t.handleRedirects && r.headers.location && n < this.#t.maxRedirects) {
528
+ const s = new URL(
529
+ r.headers.location[0],
530
+ this.server.absoluteUrl
531
+ );
532
+ return this.request(
533
+ {
534
+ absoluteUrl: s.toString(),
535
+ method: "GET",
536
+ headers: {}
537
+ },
538
+ n + 1
539
+ );
540
+ }
541
+ return r;
542
+ }
543
+ #n(e) {
544
+ for (const n of e)
545
+ try {
546
+ if (!n.includes("="))
547
+ continue;
548
+ const r = n.indexOf("="), s = n.substring(0, r), l = n.substring(r + 1).split(";")[0];
549
+ this.#e[s] = l;
550
+ } catch (r) {
551
+ console.error(r);
552
+ }
553
+ }
554
+ #s() {
555
+ const e = [];
556
+ for (const n in this.#e)
557
+ e.push(`${n}=${this.#e[n]}`);
558
+ return e.join("; ");
559
+ }
560
+ }
561
+ /**
562
+ * @license
563
+ * Copyright 2019 Google LLC
564
+ * SPDX-License-Identifier: Apache-2.0
565
+ */
566
+ const A = Symbol("Comlink.proxy"), q = Symbol("Comlink.endpoint"), J = Symbol("Comlink.releaseProxy"), k = Symbol("Comlink.finalizer"), E = Symbol("Comlink.thrown"), L = (t) => typeof t == "object" && t !== null || typeof t == "function", Y = {
567
+ canHandle: (t) => L(t) && t[A],
568
+ serialize(t) {
569
+ const { port1: e, port2: n } = new MessageChannel();
570
+ return T(t, e), [n, [n]];
571
+ },
572
+ deserialize(t) {
573
+ return t.start(), F(t);
574
+ }
575
+ }, K = {
576
+ canHandle: (t) => L(t) && E in t,
577
+ serialize({ value: t }) {
578
+ let e;
579
+ return t instanceof Error ? e = {
580
+ isError: !0,
581
+ value: {
582
+ message: t.message,
583
+ name: t.name,
584
+ stack: t.stack
585
+ }
586
+ } : e = { isError: !1, value: t }, [e, []];
587
+ },
588
+ deserialize(t) {
589
+ throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
590
+ }
591
+ }, S = /* @__PURE__ */ new Map([
592
+ ["proxy", Y],
593
+ ["throw", K]
594
+ ]);
595
+ function Q(t, e) {
596
+ for (const n of t)
597
+ if (e === n || n === "*" || n instanceof RegExp && n.test(e))
598
+ return !0;
599
+ return !1;
600
+ }
601
+ function T(t, e = globalThis, n = ["*"]) {
602
+ e.addEventListener("message", function r(s) {
603
+ if (!s || !s.data)
604
+ return;
605
+ if (!Q(n, s.origin)) {
606
+ console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
607
+ return;
608
+ }
609
+ const { id: l, type: i, path: a } = Object.assign({ path: [] }, s.data), o = (s.data.argumentList || []).map(g);
610
+ let c;
611
+ try {
612
+ const h = a.slice(0, -1).reduce((d, y) => d[y], t), p = a.reduce((d, y) => d[y], t);
613
+ switch (i) {
614
+ case "GET":
615
+ c = p;
616
+ break;
617
+ case "SET":
618
+ h[a.slice(-1)[0]] = g(s.data.value), c = !0;
619
+ break;
620
+ case "APPLY":
621
+ c = p.apply(h, o);
622
+ break;
623
+ case "CONSTRUCT":
624
+ {
625
+ const d = new p(...o);
626
+ c = M(d);
627
+ }
628
+ break;
629
+ case "ENDPOINT":
630
+ {
631
+ const { port1: d, port2: y } = new MessageChannel();
632
+ T(t, y), c = ne(d, [d]);
633
+ }
634
+ break;
635
+ case "RELEASE":
636
+ c = void 0;
637
+ break;
638
+ default:
639
+ return;
640
+ }
641
+ } catch (h) {
642
+ c = { value: h, [E]: 0 };
643
+ }
644
+ Promise.resolve(c).catch((h) => ({ value: h, [E]: 0 })).then((h) => {
645
+ const [p, d] = x(h);
646
+ e.postMessage(Object.assign(Object.assign({}, p), { id: l }), d), i === "RELEASE" && (e.removeEventListener("message", r), H(e), k in t && typeof t[k] == "function" && t[k]());
647
+ }).catch((h) => {
648
+ const [p, d] = x({
649
+ value: new TypeError("Unserializable return value"),
650
+ [E]: 0
651
+ });
652
+ e.postMessage(Object.assign(Object.assign({}, p), { id: l }), d);
653
+ });
654
+ }), e.start && e.start();
655
+ }
656
+ function X(t) {
657
+ return t.constructor.name === "MessagePort";
658
+ }
659
+ function H(t) {
660
+ X(t) && t.close();
661
+ }
662
+ function F(t, e) {
663
+ return v(t, [], e);
664
+ }
665
+ function P(t) {
666
+ if (t)
667
+ throw new Error("Proxy has been released and is not useable");
668
+ }
669
+ function I(t) {
670
+ return w(t, {
671
+ type: "RELEASE"
672
+ }).then(() => {
673
+ H(t);
674
+ });
675
+ }
676
+ const R = /* @__PURE__ */ new WeakMap(), _ = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
677
+ const e = (R.get(t) || 0) - 1;
678
+ R.set(t, e), e === 0 && I(t);
679
+ });
680
+ function Z(t, e) {
681
+ const n = (R.get(e) || 0) + 1;
682
+ R.set(e, n), _ && _.register(t, e, t);
683
+ }
684
+ function ee(t) {
685
+ _ && _.unregister(t);
686
+ }
687
+ function v(t, e = [], n = function() {
688
+ }) {
689
+ let r = !1;
690
+ const s = new Proxy(n, {
691
+ get(l, i) {
692
+ if (P(r), i === J)
693
+ return () => {
694
+ ee(s), I(t), r = !0;
695
+ };
696
+ if (i === "then") {
697
+ if (e.length === 0)
698
+ return { then: () => s };
699
+ const a = w(t, {
700
+ type: "GET",
701
+ path: e.map((o) => o.toString())
702
+ }).then(g);
703
+ return a.then.bind(a);
704
+ }
705
+ return v(t, [...e, i]);
706
+ },
707
+ set(l, i, a) {
708
+ P(r);
709
+ const [o, c] = x(a);
710
+ return w(t, {
711
+ type: "SET",
712
+ path: [...e, i].map((h) => h.toString()),
713
+ value: o
714
+ }, c).then(g);
715
+ },
716
+ apply(l, i, a) {
717
+ P(r);
718
+ const o = e[e.length - 1];
719
+ if (o === q)
720
+ return w(t, {
721
+ type: "ENDPOINT"
722
+ }).then(g);
723
+ if (o === "bind")
724
+ return v(t, e.slice(0, -1));
725
+ const [c, h] = C(a);
726
+ return w(t, {
727
+ type: "APPLY",
728
+ path: e.map((p) => p.toString()),
729
+ argumentList: c
730
+ }, h).then(g);
731
+ },
732
+ construct(l, i) {
733
+ P(r);
734
+ const [a, o] = C(i);
735
+ return w(t, {
736
+ type: "CONSTRUCT",
737
+ path: e.map((c) => c.toString()),
738
+ argumentList: a
739
+ }, o).then(g);
740
+ }
741
+ });
742
+ return Z(s, t), s;
743
+ }
744
+ function te(t) {
745
+ return Array.prototype.concat.apply([], t);
746
+ }
747
+ function C(t) {
748
+ const e = t.map(x);
749
+ return [e.map((n) => n[0]), te(e.map((n) => n[1]))];
750
+ }
751
+ const W = /* @__PURE__ */ new WeakMap();
752
+ function ne(t, e) {
753
+ return W.set(t, e), t;
754
+ }
755
+ function M(t) {
756
+ return Object.assign(t, { [A]: !0 });
757
+ }
758
+ function N(t, e = globalThis, n = "*") {
759
+ return {
760
+ postMessage: (r, s) => t.postMessage(r, n, s),
761
+ addEventListener: e.addEventListener.bind(e),
762
+ removeEventListener: e.removeEventListener.bind(e)
763
+ };
764
+ }
765
+ function x(t) {
766
+ for (const [e, n] of S)
767
+ if (n.canHandle(t)) {
768
+ const [r, s] = n.serialize(t);
769
+ return [
770
+ {
771
+ type: "HANDLER",
772
+ name: e,
773
+ value: r
774
+ },
775
+ s
776
+ ];
777
+ }
778
+ return [
779
+ {
780
+ type: "RAW",
781
+ value: t
782
+ },
783
+ W.get(t) || []
784
+ ];
785
+ }
786
+ function g(t) {
787
+ switch (t.type) {
788
+ case "HANDLER":
789
+ return S.get(t.name).deserialize(t.value);
790
+ case "RAW":
791
+ return t.value;
792
+ }
793
+ }
794
+ function w(t, e, n) {
795
+ return new Promise((r) => {
796
+ const s = re();
797
+ t.addEventListener("message", function l(i) {
798
+ !i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", l), r(i.data));
799
+ }), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), n);
800
+ });
801
+ }
802
+ function re() {
803
+ return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
804
+ }
805
+ function fe(t) {
806
+ z();
807
+ const e = t instanceof Worker ? t : N(t);
808
+ return F(e);
809
+ }
810
+ function de(t, e) {
811
+ z();
812
+ let n;
813
+ const r = new Promise((i) => {
814
+ n = i;
815
+ }), s = $(t), l = new Proxy(s, {
816
+ get: (i, a) => a === "isReady" ? () => r : a in i ? i[a] : e?.[a]
817
+ });
818
+ return T(
819
+ l,
820
+ typeof window < "u" ? N(self.parent) : void 0
821
+ ), [n, l];
822
+ }
823
+ function z() {
824
+ S.set("EVENT", {
825
+ canHandle: (t) => t instanceof CustomEvent,
826
+ serialize: (t) => [
827
+ {
828
+ detail: t.detail
829
+ },
830
+ []
831
+ ],
832
+ deserialize: (t) => t
833
+ }), S.set("FUNCTION", {
834
+ canHandle: (t) => typeof t == "function",
835
+ serialize(t) {
836
+ console.debug("[Comlink][Performance] Proxying a function");
837
+ const { port1: e, port2: n } = new MessageChannel();
838
+ return T(t, e), [n, [n]];
839
+ },
840
+ deserialize(t) {
841
+ return t.start(), F(t);
842
+ }
843
+ });
844
+ }
845
+ function $(t) {
846
+ return new Proxy(t, {
847
+ get(e, n) {
848
+ switch (typeof e[n]) {
849
+ case "function":
850
+ return (...r) => e[n](...r);
851
+ case "object":
852
+ return e[n] === null ? e[n] : $(e[n]);
853
+ case "undefined":
854
+ case "number":
855
+ case "string":
856
+ return e[n];
857
+ default:
858
+ return M(e[n]);
859
+ }
860
+ }
861
+ });
862
+ }
863
+ const f = /* @__PURE__ */ new WeakMap();
864
+ class pe {
865
+ /** @inheritDoc */
866
+ constructor(e, n) {
867
+ f.set(this, {
868
+ php: e.server.php,
869
+ phpServer: e.server,
870
+ phpBrowser: e,
871
+ monitor: n
872
+ }), this.absoluteUrl = Promise.resolve(e.server.absoluteUrl), this.documentRoot = Promise.resolve(e.server.documentRoot);
873
+ }
874
+ /** @inheritDoc @php-wasm/web!PHPServer.pathToInternalUrl */
875
+ async pathToInternalUrl(e) {
876
+ return f.get(this).phpServer.pathToInternalUrl(e);
877
+ }
878
+ /** @inheritDoc @php-wasm/web!PHPServer.internalUrlToPath */
879
+ async internalUrlToPath(e) {
880
+ return f.get(this).phpServer.internalUrlToPath(e);
881
+ }
882
+ async onDownloadProgress(e) {
883
+ f.get(this).monitor?.addEventListener("progress", e);
884
+ }
885
+ /** @inheritDoc @php-wasm/web!PHPServer.request */
886
+ request(e, n) {
887
+ return f.get(this).phpBrowser.request(e, n);
888
+ }
889
+ /** @inheritDoc @php-wasm/web!PHP.run */
890
+ async run(e) {
891
+ return f.get(this).php.run(e);
892
+ }
893
+ /** @inheritDoc @php-wasm/web!PHP.setPhpIniPath */
894
+ setPhpIniPath(e) {
895
+ return f.get(this).php.setPhpIniPath(e);
896
+ }
897
+ /** @inheritDoc @php-wasm/web!PHP.setPhpIniEntry */
898
+ setPhpIniEntry(e, n) {
899
+ f.get(this).php.setPhpIniEntry(e, n);
900
+ }
901
+ /** @inheritDoc @php-wasm/web!PHP.mkdirTree */
902
+ mkdirTree(e) {
903
+ f.get(this).php.mkdirTree(e);
904
+ }
905
+ /** @inheritDoc @php-wasm/web!PHP.readFileAsText */
906
+ async readFileAsText(e) {
907
+ return f.get(this).php.readFileAsText(e);
908
+ }
909
+ /** @inheritDoc @php-wasm/web!PHP.readFileAsBuffer */
910
+ async readFileAsBuffer(e) {
911
+ return f.get(this).php.readFileAsBuffer(e);
912
+ }
913
+ /** @inheritDoc @php-wasm/web!PHP.writeFile */
914
+ writeFile(e, n) {
915
+ f.get(this).php.writeFile(e, n);
916
+ }
917
+ /** @inheritDoc @php-wasm/web!PHP.unlink */
918
+ unlink(e) {
919
+ f.get(this).php.unlink(e);
920
+ }
921
+ /** @inheritDoc @php-wasm/web!PHP.listFiles */
922
+ async listFiles(e) {
923
+ return f.get(this).php.listFiles(e);
924
+ }
925
+ /** @inheritDoc @php-wasm/web!PHP.isDir */
926
+ async isDir(e) {
927
+ return f.get(this).php.isDir(e);
928
+ }
929
+ /** @inheritDoc @php-wasm/web!PHP.fileExists */
930
+ async fileExists(e) {
931
+ return f.get(this).php.fileExists(e);
932
+ }
933
+ }
934
+ const me = {};
935
+ async function ge(t = "8.2") {
936
+ switch (t) {
937
+ case "8.2":
938
+ return await import("php_8_2.js");
939
+ case "8.1":
940
+ return await import("php_8_1.js");
941
+ case "8.0":
942
+ return await import("php_8_0.js");
943
+ case "7.4":
944
+ return await import("php_7_4.js");
945
+ case "7.3":
946
+ return await import("php_7_3.js");
947
+ case "7.2":
948
+ return await import("php_7_2.js");
949
+ case "7.1":
950
+ return await import("php_7_1.js");
951
+ case "7.0":
952
+ return await import("php_7_0.js");
953
+ case "5.6":
954
+ return await import("php_5_6.js");
955
+ }
956
+ throw new Error(`Unsupported PHP version ${t}`);
957
+ }
958
+ function we() {
959
+ const t = {};
960
+ return typeof self?.location?.href < "u" && new URL(self.location.href).searchParams.forEach((n, r) => {
961
+ t[r] = n;
962
+ }), t;
963
+ }
964
+ const ye = function() {
965
+ return navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
966
+ }();
967
+ async function Pe(t, e = "webworker", n = {}) {
968
+ if (t = se(t, n), e === "webworker")
969
+ return new Worker(t, { type: "module" });
970
+ if (e === "iframe")
971
+ return (await ie(t)).contentWindow;
972
+ throw new Error(`Unknown backendName: ${e}`);
973
+ }
974
+ function se(t, e) {
975
+ if (!Object.entries(e).length)
976
+ return t + "";
977
+ const n = new URL(t);
978
+ for (const [r, s] of Object.entries(e))
979
+ n.searchParams.set(r, s);
980
+ return n.toString();
981
+ }
982
+ async function ie(t) {
983
+ const e = document.createElement("iframe"), n = "/" + t.split("/").slice(-1)[0];
984
+ return e.src = n, e.style.display = "none", document.body.appendChild(e), await new Promise((r) => {
985
+ e.addEventListener("load", r);
986
+ }), e;
987
+ }
988
+ function ae(t, e) {
989
+ return {
990
+ type: "response",
991
+ requestId: t,
992
+ response: e
993
+ };
994
+ }
995
+ async function Ee(t, e, n, r) {
996
+ const s = navigator.serviceWorker;
997
+ if (!s)
998
+ throw new Error("Service workers are not supported in this browser.");
999
+ const l = await s.getRegistrations();
1000
+ if (l.length > 0) {
1001
+ const i = await oe();
1002
+ if (r !== i) {
1003
+ console.debug(
1004
+ `[window] Reloading the currently registered Service Worker (expected version: ${r}, registered version: ${i})`
1005
+ );
1006
+ for (const a of l) {
1007
+ let o = !1;
1008
+ try {
1009
+ await a.update();
1010
+ } catch {
1011
+ o = !0;
1012
+ }
1013
+ const c = a.waiting || a.installing;
1014
+ c && !o && (i !== null ? c.postMessage("skip-waiting") : o = !0), o && (await a.unregister(), window.location.reload());
1015
+ }
1016
+ }
1017
+ } else
1018
+ console.debug(
1019
+ `[window] Creating a Service Worker registration (version: ${r})`
1020
+ ), await s.register(n, {
1021
+ type: "module"
1022
+ });
1023
+ navigator.serviceWorker.addEventListener(
1024
+ "message",
1025
+ async function(a) {
1026
+ if (console.debug("Message from ServiceWorker", a), e && a.data.scope !== e)
1027
+ return;
1028
+ const o = a.data.args || [], c = a.data.method, h = await t[c](...o);
1029
+ a.source.postMessage(ae(a.data.requestId, h));
1030
+ }
1031
+ ), s.startMessages();
1032
+ }
1033
+ async function oe() {
1034
+ try {
1035
+ return (await (await fetch("/version")).json()).version;
1036
+ } catch {
1037
+ return null;
1038
+ }
1039
+ }
1040
+ export {
1041
+ ce as PHP,
1042
+ he as PHPBrowser,
1043
+ pe as PHPClient,
1044
+ ue as PHPServer,
1045
+ fe as consumeAPI,
1046
+ de as exposeAPI,
1047
+ ge as getPHPLoaderModule,
1048
+ me as isAssignableToRemoteClient,
1049
+ le as loadPHPRuntime,
1050
+ we as parseWorkerStartupOptions,
1051
+ ye as recommendedWorkerBackend,
1052
+ Ee as registerServiceWorker,
1053
+ Pe as spawnPHPWorkerThread
1054
+ };