@wp-playground/client 0.1.45 → 0.1.49

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,4 +1,37 @@
1
- function x(t) {
1
+ const ke = async (t, { pluginPath: e }, r) => {
2
+ r?.tracker.setCaption(`Activating ${e}`);
3
+ const s = [
4
+ `${t.documentRoot}/wp-load.php`,
5
+ `${t.documentRoot}/wp-admin/includes/plugin.php`
6
+ ];
7
+ if (!s.every(
8
+ (i) => t.fileExists(i)
9
+ ))
10
+ throw new Error(
11
+ `Required WordPress files do not exist: ${s.join(", ")}`
12
+ );
13
+ await t.run({
14
+ code: `<?php
15
+ ${s.map((i) => `require_once( '${i}' );`).join(`
16
+ `)}
17
+ activate_plugin('${e}');
18
+ `
19
+ });
20
+ }, Oe = async (t, { themeFolderName: e }, r) => {
21
+ r?.tracker.setCaption(`Activating ${e}`);
22
+ const s = `${t.documentRoot}/wp-load.php`;
23
+ if (!t.fileExists(s))
24
+ throw new Error(
25
+ `Required WordPress file does not exist: ${s}`
26
+ );
27
+ await t.run({
28
+ code: `<?php
29
+ require_once( '${s}' );
30
+ switch_theme( '${e}' );
31
+ `
32
+ });
33
+ };
34
+ function F(t) {
2
35
  return new DOMParser().parseFromString(t.text, "text/html");
3
36
  }
4
37
  function L(t) {
@@ -9,30 +42,18 @@ async function P(t, e, r) {
9
42
  let s = "";
10
43
  await t.fileExists(e) && (s = await t.readFileAsText(e)), await t.writeFile(e, r(s));
11
44
  }
12
- async function ke(t) {
45
+ async function Ae(t) {
13
46
  return new Uint8Array(await t.arrayBuffer());
14
47
  }
15
- const G = "/vfs-blueprints", J = "/vfs-blueprints/wp-config-consts.php", Oe = async (t, { plugin: e }, r) => {
16
- r?.tracker.setCaption(`Activating ${e}`);
17
- const i = x(
18
- await t.request({
19
- url: "/wp-admin/plugins.php"
20
- })
21
- ).querySelector(
22
- `tr[data-slug="${e}"] a`
23
- ).attributes.getNamedItem("href").value;
24
- await t.request({
25
- url: "/wp-admin/" + i
26
- });
27
- }, Ae = async (t, e) => {
28
- const r = new Le(
48
+ const G = "/vfs-blueprints", J = "/vfs-blueprints/wp-config-consts.php", Le = async (t, e) => {
49
+ const r = new Ue(
29
50
  t,
30
51
  e.siteUrl,
31
52
  e.wordpressPath || "/wordpress"
32
53
  );
33
54
  e.patchSqlitePlugin !== !1 && await r.patchSqlitePlugin(), e.addPhpInfo !== !1 && await r.addPhpInfo(), e.patchSiteUrl !== !1 && await r.patchSiteUrl(), e.disableSiteHealth !== !1 && await r.disableSiteHealth(), e.disableWpNewBlogNotification !== !1 && await r.disableWpNewBlogNotification();
34
55
  };
35
- class Le {
56
+ class Ue {
36
57
  constructor(e, r, s) {
37
58
  this.php = e, this.scopedSiteUrl = r, this.wordpressPath = s;
38
59
  }
@@ -83,23 +104,23 @@ class Le {
83
104
  );
84
105
  }
85
106
  }
86
- const Ue = async (t, { code: e }) => await t.run({ code: e }), He = async (t, { options: e }) => await t.run(e), Ie = async (t, { key: e, value: r }) => {
107
+ const He = async (t, { code: e }) => await t.run({ code: e }), Ie = async (t, { options: e }) => await t.run(e), Ne = async (t, { key: e, value: r }) => {
87
108
  await t.setPhpIniEntry(e, r);
88
- }, Ne = async (t, { request: e }) => await t.request(e), Me = async (t, { fromPath: e, toPath: r }) => {
109
+ }, We = async (t, { request: e }) => await t.request(e), Me = async (t, { fromPath: e, toPath: r }) => {
89
110
  await t.writeFile(
90
111
  r,
91
112
  await t.readFileAsBuffer(e)
92
113
  );
93
- }, We = async (t, { fromPath: e, toPath: r }) => {
114
+ }, De = async (t, { fromPath: e, toPath: r }) => {
94
115
  await t.mv(e, r);
95
- }, De = async (t, { path: e }) => {
116
+ }, qe = async (t, { path: e }) => {
96
117
  await t.mkdir(e);
97
118
  }, ze = async (t, { path: e }) => {
98
119
  await t.unlink(e);
99
- }, qe = async (t, { path: e }) => {
120
+ }, je = async (t, { path: e }) => {
100
121
  await t.rmdir(e);
101
- }, je = async (t, { path: e, data: r }) => {
102
- r instanceof File && (r = await ke(r)), await t.writeFile(e, r);
122
+ }, Be = async (t, { path: e, data: r }) => {
123
+ r instanceof File && (r = await Ae(r)), await t.writeFile(e, r);
103
124
  }, pe = async (t, { consts: e }) => {
104
125
  const r = await t.documentRoot;
105
126
  await P(
@@ -121,7 +142,7 @@ const Ue = async (t, { code: e }) => await t.run({ code: e }), He = async (t, {
121
142
  }
122
143
  ?>${s}`
123
144
  );
124
- }, Be = async (t, { siteUrl: e }) => await pe(t, {
145
+ }, Ve = async (t, { siteUrl: e }) => await pe(t, {
125
146
  consts: {
126
147
  WP_HOME: e,
127
148
  WP_SITEURL: e
@@ -152,26 +173,26 @@ class fe {
152
173
  }
153
174
  }
154
175
  }
155
- const Ve = Symbol("literal");
156
- function v(t) {
176
+ const Ge = Symbol("literal");
177
+ function S(t) {
157
178
  if (typeof t == "string")
158
179
  return t.startsWith("$") ? t : JSON.stringify(t);
159
180
  if (typeof t == "number")
160
181
  return t.toString();
161
182
  if (Array.isArray(t))
162
- return `array(${t.map(v).join(", ")})`;
183
+ return `array(${t.map(S).join(", ")})`;
163
184
  if (t === null)
164
185
  return "null";
165
186
  if (typeof t == "object")
166
- return Ve in t ? t.toString() : `array(${Object.entries(t).map(([r, s]) => `${JSON.stringify(r)} => ${v(s)}`).join(", ")})`;
187
+ return Ge in t ? t.toString() : `array(${Object.entries(t).map(([r, s]) => `${JSON.stringify(r)} => ${S(s)}`).join(", ")})`;
167
188
  if (typeof t == "function")
168
189
  return t();
169
190
  throw new Error(`Unsupported value: ${t}`);
170
191
  }
171
- function W(t) {
192
+ function M(t) {
172
193
  const e = {};
173
194
  for (const r in t)
174
- e[r] = v(t[r]);
195
+ e[r] = S(t[r]);
175
196
  return e;
176
197
  }
177
198
  const Y = `<?php
@@ -237,19 +258,19 @@ function delTree($dir)
237
258
  return rmdir($dir);
238
259
  }
239
260
  `;
240
- async function Ge(t) {
241
- const e = "wordpress-playground.zip", r = `/${e}`, s = W({
261
+ async function Je(t) {
262
+ const e = "wordpress-playground.zip", r = `/${e}`, s = M({
242
263
  zipPath: r,
243
264
  documentRoot: await t.documentRoot
244
265
  });
245
- await ge(
266
+ await we(
246
267
  t,
247
268
  `zipDir(${s.documentRoot}, ${s.zipPath});`
248
269
  );
249
270
  const n = await t.readFileAsBuffer(r);
250
271
  return t.unlink(r), new File([n], e);
251
272
  }
252
- const Je = async (t, { fullSiteZip: e }) => {
273
+ const Ye = async (t, { fullSiteZip: e }) => {
253
274
  const r = "/import.zip";
254
275
  await t.writeFile(
255
276
  r,
@@ -257,8 +278,8 @@ const Je = async (t, { fullSiteZip: e }) => {
257
278
  );
258
279
  const s = await t.absoluteUrl, n = await t.documentRoot;
259
280
  await t.rmdir(n), await me(t, { zipPath: r, extractToPath: "/" });
260
- const i = W({ absoluteUrl: s });
261
- await Qe(
281
+ const i = M({ absoluteUrl: s });
282
+ await Xe(
262
283
  t,
263
284
  `${n}/wp-config.php`,
264
285
  (o) => `<?php
@@ -269,15 +290,15 @@ const Je = async (t, { fullSiteZip: e }) => {
269
290
  ?>${o}`
270
291
  );
271
292
  }, me = async (t, { zipPath: e, extractToPath: r }) => {
272
- const s = W({
293
+ const s = M({
273
294
  zipPath: e,
274
295
  extractToPath: r
275
296
  });
276
- await ge(
297
+ await we(
277
298
  t,
278
299
  `unzip(${s.zipPath}, ${s.extractToPath});`
279
300
  );
280
- }, Ye = async (t, { file: e }) => {
301
+ }, Ke = async (t, { file: e }) => {
281
302
  const r = await t.request({
282
303
  url: "/wp-admin/admin.php?import=wordpress"
283
304
  }), s = K(r).getElementById("import-upload-form")?.getAttribute("action"), n = await t.request({
@@ -291,12 +312,12 @@ const Je = async (t, { fullSiteZip: e }) => {
291
312
  throw console.log(n.text), new Error(
292
313
  "Could not find an importer form in response. See the response text above for details."
293
314
  );
294
- const o = Ke(i);
315
+ const o = Qe(i);
295
316
  o.fetch_attachments = "1";
296
317
  for (const a in o)
297
318
  if (a.startsWith("user_map[")) {
298
- const c = "user_new[" + a.slice(9, -1) + "]";
299
- o[c] = "1";
319
+ const l = "user_new[" + a.slice(9, -1) + "]";
320
+ o[l] = "1";
300
321
  }
301
322
  await t.request({
302
323
  url: i.action,
@@ -307,16 +328,16 @@ const Je = async (t, { fullSiteZip: e }) => {
307
328
  function K(t) {
308
329
  return new DOMParser().parseFromString(t.text, "text/html");
309
330
  }
310
- function Ke(t) {
331
+ function Qe(t) {
311
332
  return Object.fromEntries(new FormData(t).entries());
312
333
  }
313
- async function Qe(t, e, r) {
334
+ async function Xe(t, e, r) {
314
335
  await t.writeFile(
315
336
  e,
316
337
  r(await t.readFileAsText(e))
317
338
  );
318
339
  }
319
- async function ge(t, e) {
340
+ async function we(t, e) {
320
341
  const r = await t.run({
321
342
  code: Y + e
322
343
  });
@@ -324,25 +345,25 @@ async function ge(t, e) {
324
345
  throw console.log(Y + e), console.log(e + ""), console.log(r.errors), r.errors;
325
346
  return r;
326
347
  }
327
- const Xe = async (t, { pluginZipFile: e, options: r = {} }, s) => {
348
+ const Ze = async (t, { pluginZipFile: e, options: r = {} }, s) => {
328
349
  s?.tracker.setCaption(
329
350
  `Installing the ${L(e?.name)} plugin`
330
351
  );
331
352
  try {
332
353
  const n = "activate" in r ? r.activate : !0, i = await t.request({
333
354
  url: "/wp-admin/plugin-install.php?tab=upload"
334
- }), o = x(i), a = new FormData(
355
+ }), o = F(i), a = new FormData(
335
356
  o.querySelector(".wp-upload-form")
336
- ), { pluginzip: c, ...l } = Object.fromEntries(
357
+ ), { pluginzip: l, ...c } = Object.fromEntries(
337
358
  a.entries()
338
359
  ), u = await t.request({
339
360
  url: "/wp-admin/update.php?action=upload-plugin",
340
361
  method: "POST",
341
- formData: l,
362
+ formData: c,
342
363
  files: { pluginzip: e }
343
364
  });
344
365
  if (n) {
345
- const p = x(u).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, y = new URL(
366
+ const p = F(u).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, y = new URL(
346
367
  p,
347
368
  await t.pathToInternalUrl("/wp-admin/")
348
369
  ).toString();
@@ -379,25 +400,25 @@ async function Q(t, e, r) {
379
400
  r(await t.readFileAsText(e))
380
401
  );
381
402
  }
382
- const Ze = async (t, { themeZipFile: e, options: r = {} }, s) => {
403
+ const et = async (t, { themeZipFile: e, options: r = {} }, s) => {
383
404
  s?.tracker.setCaption(
384
405
  `Installing the ${L(e.name)} theme`
385
406
  );
386
407
  try {
387
408
  const n = "activate" in r ? r.activate : !0, i = await t.request({
388
409
  url: "/wp-admin/theme-install.php"
389
- }), o = x(i), a = new FormData(
410
+ }), o = F(i), a = new FormData(
390
411
  o.querySelector(".wp-upload-form")
391
- ), { themezip: c, ...l } = Object.fromEntries(
412
+ ), { themezip: l, ...c } = Object.fromEntries(
392
413
  a.entries()
393
414
  ), u = await t.request({
394
415
  url: "/wp-admin/update.php?action=upload-theme",
395
416
  method: "POST",
396
- formData: l,
417
+ formData: c,
397
418
  files: { themezip: e }
398
419
  });
399
420
  if (n) {
400
- const d = x(u), p = d.querySelector(
421
+ const d = F(u), p = d.querySelector(
401
422
  "#wpbody-content > .wrap"
402
423
  );
403
424
  if (p?.textContent?.includes(
@@ -426,7 +447,7 @@ const Ze = async (t, { themeZipFile: e, options: r = {} }, s) => {
426
447
  `Proceeding without the ${e.name} theme. Could not install it in wp-admin. The original error was: ${n}`
427
448
  ), console.error(n);
428
449
  }
429
- }, et = async (t, { username: e = "admin", password: r = "password" } = {}, s) => {
450
+ }, tt = async (t, { username: e = "admin", password: r = "password" } = {}, s) => {
430
451
  s?.tracker.setCaption(s?.initialCaption || "Logging in"), await t.request({
431
452
  url: "/wp-login.php"
432
453
  }), await t.request({
@@ -438,7 +459,7 @@ const Ze = async (t, { themeZipFile: e, options: r = {} }, s) => {
438
459
  rememberme: "forever"
439
460
  }
440
461
  });
441
- }, tt = async (t, { options: e }) => {
462
+ }, rt = async (t, { options: e }) => {
442
463
  await t.request({
443
464
  url: "/wp-admin/install.php?step=2",
444
465
  method: "POST",
@@ -455,10 +476,10 @@ const Ze = async (t, { themeZipFile: e, options: r = {} }, s) => {
455
476
  admin_email: "admin@localhost.com"
456
477
  }
457
478
  });
458
- }, rt = async (t, { options: e }) => {
479
+ }, st = async (t, { options: e }) => {
459
480
  const r = `<?php
460
481
  include 'wordpress/wp-load.php';
461
- $site_options = ${v(e)};
482
+ $site_options = ${S(e)};
462
483
  foreach($site_options as $name => $value) {
463
484
  update_option($name, $value);
464
485
  }
@@ -466,25 +487,25 @@ const Ze = async (t, { themeZipFile: e, options: r = {} }, s) => {
466
487
  `, s = await t.run({
467
488
  code: r
468
489
  });
469
- return we(s), { code: r, result: s };
470
- }, st = async (t, { meta: e, userId: r }) => {
490
+ return ge(s), { code: r, result: s };
491
+ }, nt = async (t, { meta: e, userId: r }) => {
471
492
  const s = `<?php
472
493
  include 'wordpress/wp-load.php';
473
- $meta = ${v(e)};
494
+ $meta = ${S(e)};
474
495
  foreach($meta as $name => $value) {
475
- update_user_meta(${v(r)}, $name, $value);
496
+ update_user_meta(${S(r)}, $name, $value);
476
497
  }
477
498
  echo "Success";
478
499
  `, n = await t.run({
479
500
  code: s
480
501
  });
481
- return we(n), { code: s, result: n };
502
+ return ge(n), { code: s, result: n };
482
503
  };
483
- async function we(t) {
504
+ async function ge(t) {
484
505
  if (t.text !== "Success")
485
506
  throw console.log(t), new Error(`Failed to run code: ${t.text} ${t.errors}`);
486
507
  }
487
- const nt = async (t, { consts: e }) => {
508
+ const it = async (t, { consts: e }) => {
488
509
  t.mkdir(G);
489
510
  const r = `${G}/playground-consts.json`;
490
511
  return await P(
@@ -502,36 +523,37 @@ const nt = async (t, { consts: e }) => {
502
523
  }
503
524
  }
504
525
  ?>${s}`), J;
505
- }, it = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
526
+ }, ot = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
506
527
  __proto__: null,
507
- activatePlugin: Oe,
508
- applyWordPressPatches: Ae,
528
+ activatePlugin: ke,
529
+ activateTheme: Oe,
530
+ applyWordPressPatches: Le,
509
531
  cp: Me,
510
- defineSiteUrl: Be,
511
- defineVirtualWpConfigConsts: nt,
532
+ defineSiteUrl: Ve,
533
+ defineVirtualWpConfigConsts: it,
512
534
  defineWpConfigConsts: pe,
513
- importFile: Ye,
514
- installPlugin: Xe,
515
- installTheme: Ze,
516
- login: et,
517
- mkdir: De,
518
- mv: We,
519
- replaceSite: Je,
520
- request: Ne,
535
+ importFile: Ke,
536
+ installPlugin: Ze,
537
+ installTheme: et,
538
+ login: tt,
539
+ mkdir: qe,
540
+ mv: De,
541
+ replaceSite: Ye,
542
+ request: We,
521
543
  rm: ze,
522
- rmdir: qe,
523
- runPHP: Ue,
524
- runPHPWithOptions: He,
525
- runWpInstallationWizard: tt,
526
- setPhpIniEntry: Ie,
527
- setSiteOptions: rt,
544
+ rmdir: je,
545
+ runPHP: He,
546
+ runPHPWithOptions: Ie,
547
+ runWpInstallationWizard: rt,
548
+ setPhpIniEntry: Ne,
549
+ setSiteOptions: st,
528
550
  unzip: me,
529
- updateUserMeta: st,
530
- writeFile: je,
531
- zipEntireSite: Ge
532
- }, Symbol.toStringTag, { value: "Module" })), ot = 5 * 1024 * 1024;
533
- function at(t, e) {
534
- const r = t.headers.get("content-length") || "", s = parseInt(r, 10) || ot;
551
+ updateUserMeta: nt,
552
+ writeFile: Be,
553
+ zipEntireSite: Je
554
+ }, Symbol.toStringTag, { value: "Module" })), at = 5 * 1024 * 1024;
555
+ function ct(t, e) {
556
+ const r = t.headers.get("content-length") || "", s = parseInt(r, 10) || at;
535
557
  function n(i, o) {
536
558
  e(
537
559
  new CustomEvent("progress", {
@@ -553,14 +575,14 @@ function at(t, e) {
553
575
  let a = 0;
554
576
  for (; ; )
555
577
  try {
556
- const { done: c, value: l } = await o.read();
557
- if (l && (a += l.byteLength), c) {
578
+ const { done: l, value: c } = await o.read();
579
+ if (c && (a += c.byteLength), l) {
558
580
  n(a, a), i.close();
559
581
  break;
560
582
  } else
561
- n(a, s), i.enqueue(l);
562
- } catch (c) {
563
- console.error({ e: c }), i.error(c);
583
+ n(a, s), i.enqueue(c);
584
+ } catch (l) {
585
+ console.error({ e: l }), i.error(l);
564
586
  break;
565
587
  }
566
588
  }
@@ -760,8 +782,8 @@ class D extends Event {
760
782
  }
761
783
  Object.defineProperty(D.prototype, "error", { enumerable: !0 });
762
784
  Object.defineProperty(D.prototype, "message", { enumerable: !0 });
763
- const ct = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : D;
764
- class lt extends EventTarget {
785
+ const lt = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : D;
786
+ class ut extends EventTarget {
765
787
  constructor() {
766
788
  super(...arguments), this.listenersCount = 0;
767
789
  }
@@ -775,11 +797,11 @@ class lt extends EventTarget {
775
797
  return this.listenersCount > 0;
776
798
  }
777
799
  }
778
- function ut(t) {
800
+ function ht(t) {
779
801
  t.asm = {
780
802
  ...t.asm
781
803
  };
782
- const e = new lt();
804
+ const e = new ut();
783
805
  for (const r in t.asm)
784
806
  if (typeof t.asm[r] == "function") {
785
807
  const s = t.asm[r];
@@ -791,14 +813,14 @@ function ut(t) {
791
813
  throw i;
792
814
  if ("exitCode" in i && i?.exitCode === 0)
793
815
  return;
794
- const o = dt(
816
+ const o = pt(
795
817
  i,
796
818
  t.lastAsyncifyStackSource?.stack
797
819
  );
798
820
  if (t.lastAsyncifyStackSource && (i.cause = t.lastAsyncifyStackSource), !e.hasListeners())
799
- throw mt(o), i;
821
+ throw wt(o), i;
800
822
  e.dispatchEvent(
801
- new ct("error", {
823
+ new lt("error", {
802
824
  error: i,
803
825
  message: o
804
826
  })
@@ -809,12 +831,12 @@ function ut(t) {
809
831
  return e;
810
832
  }
811
833
  let N = [];
812
- function ht() {
834
+ function dt() {
813
835
  return N;
814
836
  }
815
- function dt(t, e) {
837
+ function pt(t, e) {
816
838
  if (t.message === "unreachable") {
817
- let r = pt;
839
+ let r = ft;
818
840
  e || (r += `
819
841
 
820
842
  This stack trace is lacking. For a better one initialize
@@ -830,7 +852,7 @@ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
830
852
  }
831
853
  return t.message;
832
854
  }
833
- const pt = `
855
+ const ft = `
834
856
  "unreachable" WASM instruction executed.
835
857
 
836
858
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -854,13 +876,13 @@ the Dockerfile, you'll need to trigger this error again with long stack
854
876
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
855
877
  CLI option:
856
878
 
857
- `, ee = "\x1B[41m", ft = "\x1B[1m", te = "\x1B[0m", re = "\x1B[K";
879
+ `, ee = "\x1B[41m", mt = "\x1B[1m", te = "\x1B[0m", re = "\x1B[K";
858
880
  let se = !1;
859
- function mt(t) {
881
+ function wt(t) {
860
882
  if (!se) {
861
883
  se = !0, console.log(`${ee}
862
884
  ${re}
863
- ${ft} WASM ERROR${te}${ee}`);
885
+ ${mt} WASM ERROR${te}${ee}`);
864
886
  for (const e of t.split(`
865
887
  `))
866
888
  console.log(`${re} ${e} `);
@@ -884,12 +906,12 @@ function gt(t) {
884
906
  return [];
885
907
  }
886
908
  }
887
- class S {
909
+ class _ {
888
910
  constructor(e, r, s, n = "", i = 0) {
889
911
  this.httpStatusCode = e, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
890
912
  }
891
913
  static fromRawData(e) {
892
- return new S(
914
+ return new _(
893
915
  e.httpStatusCode,
894
916
  e.headers,
895
917
  e.bytes,
@@ -919,7 +941,7 @@ class S {
919
941
  return new TextDecoder().decode(this.bytes);
920
942
  }
921
943
  }
922
- const z = [
944
+ const q = [
923
945
  "8.2",
924
946
  "8.1",
925
947
  "8.0",
@@ -929,8 +951,8 @@ const z = [
929
951
  "7.1",
930
952
  "7.0",
931
953
  "5.6"
932
- ], wt = z[0], ir = z;
933
- class yt {
954
+ ], yt = q[0], or = q;
955
+ class Pt {
934
956
  #e;
935
957
  #t;
936
958
  /**
@@ -1016,17 +1038,17 @@ class yt {
1016
1038
  return e.join("; ");
1017
1039
  }
1018
1040
  }
1019
- const Pt = "http://example.com";
1041
+ const bt = "http://example.com";
1020
1042
  function ne(t) {
1021
1043
  return t.toString().substring(t.origin.length);
1022
1044
  }
1023
1045
  function ie(t, e) {
1024
1046
  return !e || !t.startsWith(e) ? t : t.substring(e.length);
1025
1047
  }
1026
- function bt(t, e) {
1048
+ function _t(t, e) {
1027
1049
  return !e || t.startsWith(e) ? t : e + t;
1028
1050
  }
1029
- class _t {
1051
+ class $t {
1030
1052
  #e;
1031
1053
  #t;
1032
1054
  #s;
@@ -1084,7 +1106,7 @@ class _t {
1084
1106
  async request(e) {
1085
1107
  const r = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL(
1086
1108
  e.url,
1087
- r ? void 0 : Pt
1109
+ r ? void 0 : bt
1088
1110
  ), n = ie(
1089
1111
  s.pathname,
1090
1112
  this.#n
@@ -1100,20 +1122,20 @@ class _t {
1100
1122
  #l(e) {
1101
1123
  const r = `${this.#e}${e}`;
1102
1124
  if (!this.php.fileExists(r))
1103
- return new S(
1125
+ return new _(
1104
1126
  404,
1105
1127
  {},
1106
1128
  new TextEncoder().encode("404 File not found")
1107
1129
  );
1108
1130
  const s = this.php.readFileAsBuffer(r);
1109
- return new S(
1131
+ return new _(
1110
1132
  200,
1111
1133
  {
1112
1134
  "content-length": [`${s.byteLength}`],
1113
1135
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
1114
1136
  // The code below won't return the correct mime-type if the extension
1115
1137
  // was tampered with.
1116
- "content-type": [Et(r)],
1138
+ "content-type": [vt(r)],
1117
1139
  "accept-ranges": ["bytes"],
1118
1140
  "cache-control": ["public, max-age=0"]
1119
1141
  },
@@ -1142,23 +1164,34 @@ class _t {
1142
1164
  if (e.files && Object.keys(e.files).length) {
1143
1165
  n = "POST";
1144
1166
  for (const c in e.files) {
1145
- const l = e.files[c];
1167
+ const u = e.files[c];
1146
1168
  o.push({
1147
1169
  key: c,
1148
- name: l.name,
1149
- type: l.type,
1150
- data: new Uint8Array(await l.arrayBuffer())
1170
+ name: u.name,
1171
+ type: u.type,
1172
+ data: new Uint8Array(await u.arrayBuffer())
1151
1173
  });
1152
1174
  }
1153
- i["content-type"]?.startsWith("multipart/form-data") && (e.formData = $t(
1175
+ i["content-type"]?.startsWith("multipart/form-data") && (e.formData = Et(
1154
1176
  e.body || ""
1155
1177
  ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
1156
1178
  }
1157
1179
  let a;
1158
- return e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
1180
+ e.formData !== void 0 ? (n = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
1159
1181
  e.formData
1160
- ).toString()) : a = e.body, await this.php.run({
1161
- relativeUri: bt(
1182
+ ).toString()) : a = e.body;
1183
+ let l;
1184
+ try {
1185
+ l = this.#h(r.pathname);
1186
+ } catch {
1187
+ return new _(
1188
+ 404,
1189
+ {},
1190
+ new TextEncoder().encode("404 File not found")
1191
+ );
1192
+ }
1193
+ return await this.php.run({
1194
+ relativeUri: _t(
1162
1195
  ne(r),
1163
1196
  this.#n
1164
1197
  ),
@@ -1166,7 +1199,7 @@ class _t {
1166
1199
  method: e.method || n,
1167
1200
  body: a,
1168
1201
  fileInfos: o,
1169
- scriptPath: this.#h(r.pathname),
1202
+ scriptPath: l,
1170
1203
  headers: i
1171
1204
  });
1172
1205
  } finally {
@@ -1179,16 +1212,21 @@ class _t {
1179
1212
  * Fall back to index.php as if there was a url rewriting rule in place.
1180
1213
  *
1181
1214
  * @param requestedPath - The requested pathname.
1215
+ * @throws {Error} If the requested path doesn't exist.
1182
1216
  * @returns The resolved filesystem path.
1183
1217
  */
1184
1218
  #h(e) {
1185
1219
  let r = ie(e, this.#n);
1186
1220
  r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
1187
1221
  const s = `${this.#e}${r}`;
1188
- return this.php.fileExists(s) ? s : `${this.#e}/index.php`;
1222
+ if (this.php.fileExists(s))
1223
+ return s;
1224
+ if (!this.php.fileExists(`${this.#e}/index.php`))
1225
+ throw new Error(`File not found: ${s}`);
1226
+ return `${this.#e}/index.php`;
1189
1227
  }
1190
1228
  }
1191
- function $t(t) {
1229
+ function Et(t) {
1192
1230
  const e = {}, r = t.match(/--(.*)\r\n/);
1193
1231
  if (!r)
1194
1232
  return e;
@@ -1196,14 +1234,14 @@ function $t(t) {
1196
1234
  return n.shift(), n.pop(), n.forEach((i) => {
1197
1235
  const o = i.indexOf(`\r
1198
1236
  \r
1199
- `), a = i.substring(0, o).trim(), c = i.substring(o + 4).trim(), l = a.match(/name="([^"]+)"/);
1200
- if (l) {
1201
- const u = l[1];
1202
- e[u] = c;
1237
+ `), a = i.substring(0, o).trim(), l = i.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
1238
+ if (c) {
1239
+ const u = c[1];
1240
+ e[u] = l;
1203
1241
  }
1204
1242
  }), e;
1205
1243
  }
1206
- function Et(t) {
1244
+ function vt(t) {
1207
1245
  switch (t.split(".").pop()) {
1208
1246
  case "css":
1209
1247
  return "text/css";
@@ -1329,10 +1367,10 @@ function m(t = "") {
1329
1367
  try {
1330
1368
  return i.apply(this, o);
1331
1369
  } catch (a) {
1332
- const c = typeof a == "object" ? a?.errno : null;
1333
- if (c in oe) {
1334
- const l = oe[c], u = typeof o[0] == "string" ? o[0] : null, d = u !== null ? t.replaceAll("{path}", u) : t;
1335
- throw new Error(`${d}: ${l}`, {
1370
+ const l = typeof a == "object" ? a?.errno : null;
1371
+ if (l in oe) {
1372
+ const c = oe[l], u = typeof o[0] == "string" ? o[0] : null, d = u !== null ? t.replaceAll("{path}", u) : t;
1373
+ throw new Error(`${d}: ${c}`, {
1336
1374
  cause: a
1337
1375
  });
1338
1376
  }
@@ -1341,20 +1379,20 @@ function m(t = "") {
1341
1379
  };
1342
1380
  };
1343
1381
  }
1344
- const vt = [];
1345
- function St(t) {
1346
- return vt[t];
1382
+ const St = [];
1383
+ function Rt(t) {
1384
+ return St[t];
1347
1385
  }
1348
1386
  (function() {
1349
1387
  return typeof process < "u" && process.release?.name === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
1350
1388
  })();
1351
- var Rt = Object.defineProperty, xt = Object.getOwnPropertyDescriptor, g = (t, e, r, s) => {
1352
- for (var n = s > 1 ? void 0 : s ? xt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1389
+ var xt = Object.defineProperty, Tt = Object.getOwnPropertyDescriptor, w = (t, e, r, s) => {
1390
+ for (var n = s > 1 ? void 0 : s ? Tt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1353
1391
  (o = t[i]) && (n = (s ? o(e, r, n) : o(n)) || n);
1354
- return s && n && Rt(e, r, n), n;
1392
+ return s && n && xt(e, r, n), n;
1355
1393
  };
1356
- const f = "string", $ = "number", h = Symbol("__private__dont__use");
1357
- class w {
1394
+ const f = "string", E = "number", h = Symbol("__private__dont__use");
1395
+ class g {
1358
1396
  /**
1359
1397
  * Initializes a PHP runtime.
1360
1398
  *
@@ -1363,8 +1401,8 @@ class w {
1363
1401
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
1364
1402
  */
1365
1403
  constructor(e, r) {
1366
- this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new yt(
1367
- new _t(this, r)
1404
+ this.#e = [], this.#t = !1, this.#s = null, this.#r = {}, e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new Pt(
1405
+ new $t(this, r)
1368
1406
  ));
1369
1407
  }
1370
1408
  #e;
@@ -1392,10 +1430,10 @@ class w {
1392
1430
  initializeRuntime(e) {
1393
1431
  if (this[h])
1394
1432
  throw new Error("PHP runtime already initialized.");
1395
- const r = St(e);
1433
+ const r = Rt(e);
1396
1434
  if (!r)
1397
1435
  throw new Error("Invalid PHP runtime id.");
1398
- this[h] = r, this.#s = ut(r);
1436
+ this[h] = r, this.#s = ht(r);
1399
1437
  }
1400
1438
  /** @inheritDoc */
1401
1439
  setPhpIniPath(e) {
@@ -1500,7 +1538,7 @@ class w {
1500
1538
  (!s || isNaN(s) || s === 80) && (s = r === "https" ? 443 : 80), this[h].ccall(
1501
1539
  "wasm_set_request_port",
1502
1540
  null,
1503
- [$],
1541
+ [E],
1504
1542
  [s]
1505
1543
  ), (r === "https" || !r && s === 443) && this.addServerGlobalEntry("HTTPS", "on");
1506
1544
  }
@@ -1526,7 +1564,7 @@ class w {
1526
1564
  ), e["content-length"] && this[h].ccall(
1527
1565
  "wasm_set_content_length",
1528
1566
  null,
1529
- [$],
1567
+ [E],
1530
1568
  [parseInt(e["content-length"], 10)]
1531
1569
  );
1532
1570
  for (const r in e)
@@ -1544,7 +1582,7 @@ class w {
1544
1582
  ), this[h].ccall(
1545
1583
  "wasm_set_content_length",
1546
1584
  null,
1547
- [$],
1585
+ [E],
1548
1586
  [new TextEncoder().encode(e).length]
1549
1587
  );
1550
1588
  }
@@ -1584,7 +1622,7 @@ class w {
1584
1622
  this[h].ccall(
1585
1623
  "wasm_add_uploaded_file",
1586
1624
  null,
1587
- [f, f, f, f, $, $],
1625
+ [f, f, f, f, E, E],
1588
1626
  [r, s, n, o, a, i.byteLength]
1589
1627
  );
1590
1628
  }
@@ -1599,48 +1637,37 @@ class w {
1599
1637
  async #m() {
1600
1638
  let e, r;
1601
1639
  try {
1602
- e = await new Promise(async (i, o) => {
1603
- r = (a) => {
1640
+ e = await new Promise((i, o) => {
1641
+ r = (l) => {
1604
1642
  const c = new Error("Rethrown");
1605
- c.cause = a.error, c.betterMessage = a.message, o(c);
1643
+ c.cause = l.error, c.betterMessage = l.message, o(c);
1606
1644
  }, this.#s?.addEventListener(
1607
1645
  "error",
1608
1646
  r
1609
1647
  );
1610
- try {
1611
- i(
1612
- /**
1613
- * This is awkward, but Asyncify makes wasm_sapi_handle_request return
1614
- * Promise<Promise<number>>.
1615
- *
1616
- * @TODO: Determine whether this is a bug in emscripten or in our code.
1617
- */
1618
- await await this[h].ccall(
1619
- "wasm_sapi_handle_request",
1620
- $,
1621
- [],
1622
- []
1623
- )
1624
- );
1625
- } catch (a) {
1626
- o(a);
1627
- }
1648
+ const a = this[h].ccall(
1649
+ "wasm_sapi_handle_request",
1650
+ E,
1651
+ [],
1652
+ []
1653
+ );
1654
+ return a instanceof Promise ? a.then(i, o) : i(a);
1628
1655
  });
1629
1656
  } catch (i) {
1630
- for (const l in this)
1631
- typeof this[l] == "function" && (this[l] = () => {
1657
+ for (const c in this)
1658
+ typeof this[c] == "function" && (this[c] = () => {
1632
1659
  throw new Error(
1633
1660
  "PHP runtime has crashed – see the earlier error for details."
1634
1661
  );
1635
1662
  });
1636
- this.functionsMaybeMissingFromAsyncify = ht();
1637
- const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, c = new Error(a);
1638
- throw c.cause = o, c;
1663
+ this.functionsMaybeMissingFromAsyncify = dt();
1664
+ const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
1665
+ throw l.cause = o, l;
1639
1666
  } finally {
1640
1667
  this.#s?.removeEventListener("error", r), this.#r = {};
1641
1668
  }
1642
1669
  const { headers: s, httpStatusCode: n } = this.#n();
1643
- return new S(
1670
+ return new _(
1644
1671
  n,
1645
1672
  s,
1646
1673
  this.readFileAsBuffer("/tmp/stdout"),
@@ -1699,56 +1726,56 @@ class w {
1699
1726
  }
1700
1727
  }
1701
1728
  }
1702
- g([
1729
+ w([
1703
1730
  m('Could not create directory "{path}"')
1704
- ], w.prototype, "mkdir", 1);
1705
- g([
1731
+ ], g.prototype, "mkdir", 1);
1732
+ w([
1706
1733
  m('Could not create directory "{path}"')
1707
- ], w.prototype, "mkdirTree", 1);
1708
- g([
1734
+ ], g.prototype, "mkdirTree", 1);
1735
+ w([
1709
1736
  m('Could not read "{path}"')
1710
- ], w.prototype, "readFileAsText", 1);
1711
- g([
1737
+ ], g.prototype, "readFileAsText", 1);
1738
+ w([
1712
1739
  m('Could not read "{path}"')
1713
- ], w.prototype, "readFileAsBuffer", 1);
1714
- g([
1740
+ ], g.prototype, "readFileAsBuffer", 1);
1741
+ w([
1715
1742
  m('Could not write to "{path}"')
1716
- ], w.prototype, "writeFile", 1);
1717
- g([
1743
+ ], g.prototype, "writeFile", 1);
1744
+ w([
1718
1745
  m('Could not unlink "{path}"')
1719
- ], w.prototype, "unlink", 1);
1720
- g([
1746
+ ], g.prototype, "unlink", 1);
1747
+ w([
1721
1748
  m('Could not move "{path}"')
1722
- ], w.prototype, "mv", 1);
1723
- g([
1749
+ ], g.prototype, "mv", 1);
1750
+ w([
1724
1751
  m('Could not remove directory "{path}"')
1725
- ], w.prototype, "rmdir", 1);
1726
- g([
1752
+ ], g.prototype, "rmdir", 1);
1753
+ w([
1727
1754
  m('Could not list files in "{path}"')
1728
- ], w.prototype, "listFiles", 1);
1729
- g([
1755
+ ], g.prototype, "listFiles", 1);
1756
+ w([
1730
1757
  m('Could not stat "{path}"')
1731
- ], w.prototype, "isDir", 1);
1732
- g([
1758
+ ], g.prototype, "isDir", 1);
1759
+ w([
1733
1760
  m('Could not stat "{path}"')
1734
- ], w.prototype, "fileExists", 1);
1761
+ ], g.prototype, "fileExists", 1);
1735
1762
  function ye(t) {
1736
1763
  const e = {};
1737
1764
  for (const r in t)
1738
1765
  e[r.toLowerCase()] = t[r];
1739
1766
  return e;
1740
1767
  }
1741
- const Tt = [
1768
+ const Ct = [
1742
1769
  "vfs",
1743
1770
  "literal",
1744
1771
  "wordpress.org/themes",
1745
1772
  "wordpress.org/plugins",
1746
1773
  "url"
1747
1774
  ];
1748
- function Ct(t) {
1749
- return t && typeof t == "object" && typeof t.resource == "string" && Tt.includes(t.resource);
1775
+ function Ft(t) {
1776
+ return t && typeof t == "object" && typeof t.resource == "string" && Ct.includes(t.resource);
1750
1777
  }
1751
- class _ {
1778
+ class $ {
1752
1779
  /**
1753
1780
  * Creates a new Resource based on the given file reference
1754
1781
  *
@@ -1760,24 +1787,24 @@ class _ {
1760
1787
  let n;
1761
1788
  switch (e.resource) {
1762
1789
  case "vfs":
1763
- n = new Ft(e, s);
1790
+ n = new kt(e, s);
1764
1791
  break;
1765
1792
  case "literal":
1766
- n = new kt(e, s);
1793
+ n = new Ot(e, s);
1767
1794
  break;
1768
1795
  case "wordpress.org/themes":
1769
- n = new Lt(e, s);
1796
+ n = new Ut(e, s);
1770
1797
  break;
1771
1798
  case "wordpress.org/plugins":
1772
- n = new Ut(e, s);
1799
+ n = new Ht(e, s);
1773
1800
  break;
1774
1801
  case "url":
1775
- n = new At(e, s);
1802
+ n = new Lt(e, s);
1776
1803
  break;
1777
1804
  default:
1778
1805
  throw new Error(`Invalid resource: ${e}`);
1779
1806
  }
1780
- return n = new Ht(n), r && (n = new It(n, r)), n;
1807
+ return n = new It(n), r && (n = new Nt(n, r)), n;
1781
1808
  }
1782
1809
  setPlayground(e) {
1783
1810
  this.playground = e;
@@ -1787,7 +1814,7 @@ class _ {
1787
1814
  return !1;
1788
1815
  }
1789
1816
  }
1790
- class Ft extends _ {
1817
+ class kt extends $ {
1791
1818
  /**
1792
1819
  * Creates a new instance of `VFSResource`.
1793
1820
  * @param playground The playground client.
@@ -1809,7 +1836,7 @@ class Ft extends _ {
1809
1836
  return this.resource.path;
1810
1837
  }
1811
1838
  }
1812
- class kt extends _ {
1839
+ class Ot extends $ {
1813
1840
  /**
1814
1841
  * Creates a new instance of `LiteralResource`.
1815
1842
  * @param resource The literal reference.
@@ -1827,7 +1854,7 @@ class kt extends _ {
1827
1854
  return this.resource.name;
1828
1855
  }
1829
1856
  }
1830
- class q extends _ {
1857
+ class z extends $ {
1831
1858
  /**
1832
1859
  * Creates a new instance of `FetchResource`.
1833
1860
  * @param progress The progress tracker.
@@ -1840,9 +1867,9 @@ class q extends _ {
1840
1867
  this.progress?.setCaption(this.caption);
1841
1868
  const e = this.getURL();
1842
1869
  let r = await fetch(e);
1843
- if (r = await at(
1870
+ if (r = await ct(
1844
1871
  r,
1845
- this.progress?.loadingListener ?? Ot
1872
+ this.progress?.loadingListener ?? At
1846
1873
  ), r.status !== 200)
1847
1874
  throw new Error(`Could not download "${e}"`);
1848
1875
  return new File([await r.blob()], this.name);
@@ -1867,9 +1894,9 @@ class q extends _ {
1867
1894
  return !0;
1868
1895
  }
1869
1896
  }
1870
- const Ot = () => {
1897
+ const At = () => {
1871
1898
  };
1872
- class At extends q {
1899
+ class Lt extends z {
1873
1900
  /**
1874
1901
  * Creates a new instance of `UrlResource`.
1875
1902
  * @param resource The URL reference.
@@ -1888,10 +1915,10 @@ class At extends q {
1888
1915
  }
1889
1916
  }
1890
1917
  let j = "https://playground.wordpress.net/plugin-proxy";
1891
- function or(t) {
1918
+ function ar(t) {
1892
1919
  j = t;
1893
1920
  }
1894
- class Lt extends q {
1921
+ class Ut extends z {
1895
1922
  constructor(e, r) {
1896
1923
  super(r), this.resource = e;
1897
1924
  }
@@ -1903,7 +1930,7 @@ class Lt extends q {
1903
1930
  return `${j}?theme=` + e;
1904
1931
  }
1905
1932
  }
1906
- class Ut extends q {
1933
+ class Ht extends z {
1907
1934
  constructor(e, r) {
1908
1935
  super(r), this.resource = e;
1909
1936
  }
@@ -1920,7 +1947,7 @@ class Ut extends q {
1920
1947
  function Pe(t) {
1921
1948
  return !t || t.endsWith(".zip") ? t : t + ".latest-stable.zip";
1922
1949
  }
1923
- class be extends _ {
1950
+ class be extends $ {
1924
1951
  constructor(e) {
1925
1952
  super(), this.resource = e;
1926
1953
  }
@@ -1949,13 +1976,13 @@ class be extends _ {
1949
1976
  return this.resource.isAsync;
1950
1977
  }
1951
1978
  }
1952
- class Ht extends be {
1979
+ class It extends be {
1953
1980
  /** @inheritDoc */
1954
1981
  async resolve() {
1955
1982
  return this.promise || (this.promise = super.resolve()), this.promise;
1956
1983
  }
1957
1984
  }
1958
- class It extends be {
1985
+ class Nt extends be {
1959
1986
  constructor(e, r) {
1960
1987
  super(e), this.semaphore = r;
1961
1988
  }
@@ -1964,18 +1991,18 @@ class It extends be {
1964
1991
  return this.isAsync ? this.semaphore.run(() => super.resolve()) : super.resolve();
1965
1992
  }
1966
1993
  }
1967
- const Nt = ["6.2", "6.1", "6.0", "5.9"];
1994
+ const Wt = ["6.2", "6.1", "6.0", "5.9"];
1968
1995
  function Mt(t, {
1969
1996
  progress: e = new U(),
1970
1997
  semaphore: r = new fe({ concurrency: 3 }),
1971
1998
  onStepCompleted: s = () => {
1972
1999
  }
1973
2000
  } = {}) {
1974
- const n = (t.steps || []).filter(Wt), i = n.reduce(
1975
- (a, c) => a + (c.progress?.weight || 1),
2001
+ const n = (t.steps || []).filter(Dt), i = n.reduce(
2002
+ (a, l) => a + (l.progress?.weight || 1),
1976
2003
  0
1977
2004
  ), o = n.map(
1978
- (a) => Dt(a, {
2005
+ (a) => qt(a, {
1979
2006
  semaphore: r,
1980
2007
  rootProgressTracker: e,
1981
2008
  totalProgressWeight: i
@@ -1985,23 +2012,23 @@ function Mt(t, {
1985
2012
  versions: {
1986
2013
  php: ae(
1987
2014
  t.preferredVersions?.php,
1988
- z,
1989
- wt
2015
+ q,
2016
+ yt
1990
2017
  ),
1991
2018
  wp: ae(
1992
2019
  t.preferredVersions?.wp,
1993
- Nt,
2020
+ Wt,
1994
2021
  "6.2"
1995
2022
  )
1996
2023
  },
1997
2024
  run: async (a) => {
1998
2025
  try {
1999
- for (const { resources: c } of o)
2000
- for (const l of c)
2001
- l.setPlayground(a), l.isAsync && l.resolve();
2002
- for (const { run: c, step: l } of o) {
2003
- const u = await c(a);
2004
- s(u, l);
2026
+ for (const { resources: l } of o)
2027
+ for (const c of l)
2028
+ c.setPlayground(a), c.isAsync && c.resolve();
2029
+ for (const { run: l, step: c } of o) {
2030
+ const u = await l(a);
2031
+ s(u, c);
2005
2032
  }
2006
2033
  try {
2007
2034
  await a.goTo(
@@ -2018,10 +2045,10 @@ function Mt(t, {
2018
2045
  function ae(t, e, r) {
2019
2046
  return t && e.includes(t) ? t : r;
2020
2047
  }
2021
- function Wt(t) {
2048
+ function Dt(t) {
2022
2049
  return !!(typeof t == "object" && t);
2023
2050
  }
2024
- function Dt(t, {
2051
+ function qt(t, {
2025
2052
  semaphore: e,
2026
2053
  rootProgressTracker: r,
2027
2054
  totalProgressWeight: s
@@ -2031,13 +2058,13 @@ function Dt(t, {
2031
2058
  ), i = {};
2032
2059
  for (const u of Object.keys(t)) {
2033
2060
  let d = t[u];
2034
- Ct(d) && (d = _.create(d, {
2061
+ Ft(d) && (d = $.create(d, {
2035
2062
  semaphore: e
2036
2063
  })), i[u] = d;
2037
2064
  }
2038
2065
  const o = async (u) => {
2039
2066
  try {
2040
- return n.fillSlowly(), await it[t.step](
2067
+ return n.fillSlowly(), await ot[t.step](
2041
2068
  u,
2042
2069
  await zt(i),
2043
2070
  {
@@ -2048,18 +2075,18 @@ function Dt(t, {
2048
2075
  } finally {
2049
2076
  n.finish();
2050
2077
  }
2051
- }, a = ce(i), c = ce(i).filter(
2078
+ }, a = ce(i), l = ce(i).filter(
2052
2079
  (u) => u.isAsync
2053
- ), l = 1 / (c.length + 1);
2054
- for (const u of c)
2055
- u.progress = n.stage(l);
2080
+ ), c = 1 / (l.length + 1);
2081
+ for (const u of l)
2082
+ u.progress = n.stage(c);
2056
2083
  return { run: o, step: t, resources: a };
2057
2084
  }
2058
2085
  function ce(t) {
2059
2086
  const e = [];
2060
2087
  for (const r in t) {
2061
2088
  const s = t[r];
2062
- s instanceof _ && e.push(s);
2089
+ s instanceof $ && e.push(s);
2063
2090
  }
2064
2091
  return e;
2065
2092
  }
@@ -2067,11 +2094,11 @@ async function zt(t) {
2067
2094
  const e = {};
2068
2095
  for (const r in t) {
2069
2096
  const s = t[r];
2070
- s instanceof _ ? e[r] = await s.resolve() : e[r] = s;
2097
+ s instanceof $ ? e[r] = await s.resolve() : e[r] = s;
2071
2098
  }
2072
2099
  return e;
2073
2100
  }
2074
- async function qt(t, e) {
2101
+ async function jt(t, e) {
2075
2102
  await t.run(e);
2076
2103
  }
2077
2104
  /**
@@ -2079,7 +2106,7 @@ async function qt(t, e) {
2079
2106
  * Copyright 2019 Google LLC
2080
2107
  * SPDX-License-Identifier: Apache-2.0
2081
2108
  */
2082
- const _e = Symbol("Comlink.proxy"), jt = Symbol("Comlink.endpoint"), Bt = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), C = Symbol("Comlink.thrown"), $e = (t) => typeof t == "object" && t !== null || typeof t == "function", Vt = {
2109
+ const _e = Symbol("Comlink.proxy"), Bt = Symbol("Comlink.endpoint"), Vt = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), T = Symbol("Comlink.thrown"), $e = (t) => typeof t == "object" && t !== null || typeof t == "function", Gt = {
2083
2110
  canHandle: (t) => $e(t) && t[_e],
2084
2111
  serialize(t) {
2085
2112
  const { port1: e, port2: r } = new MessageChannel();
@@ -2088,8 +2115,8 @@ const _e = Symbol("Comlink.proxy"), jt = Symbol("Comlink.endpoint"), Bt = Symbol
2088
2115
  deserialize(t) {
2089
2116
  return t.start(), V(t);
2090
2117
  }
2091
- }, Gt = {
2092
- canHandle: (t) => $e(t) && C in t,
2118
+ }, Jt = {
2119
+ canHandle: (t) => $e(t) && T in t,
2093
2120
  serialize({ value: t }) {
2094
2121
  let e;
2095
2122
  return t instanceof Error ? e = {
@@ -2105,10 +2132,10 @@ const _e = Symbol("Comlink.proxy"), jt = Symbol("Comlink.endpoint"), Bt = Symbol
2105
2132
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
2106
2133
  }
2107
2134
  }, R = /* @__PURE__ */ new Map([
2108
- ["proxy", Vt],
2109
- ["throw", Gt]
2135
+ ["proxy", Gt],
2136
+ ["throw", Jt]
2110
2137
  ]);
2111
- function Jt(t, e) {
2138
+ function Yt(t, e) {
2112
2139
  for (const r of t)
2113
2140
  if (e === r || r === "*" || r instanceof RegExp && r.test(e))
2114
2141
  return !0;
@@ -2118,72 +2145,72 @@ function B(t, e = globalThis, r = ["*"]) {
2118
2145
  e.addEventListener("message", function s(n) {
2119
2146
  if (!n || !n.data)
2120
2147
  return;
2121
- if (!Jt(r, n.origin)) {
2148
+ if (!Yt(r, n.origin)) {
2122
2149
  console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
2123
2150
  return;
2124
2151
  }
2125
- const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), c = (n.data.argumentList || []).map(b);
2126
- let l;
2152
+ const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(b);
2153
+ let c;
2127
2154
  try {
2128
2155
  const u = a.slice(0, -1).reduce((p, y) => p[y], t), d = a.reduce((p, y) => p[y], t);
2129
2156
  switch (o) {
2130
2157
  case "GET":
2131
- l = d;
2158
+ c = d;
2132
2159
  break;
2133
2160
  case "SET":
2134
- u[a.slice(-1)[0]] = b(n.data.value), l = !0;
2161
+ u[a.slice(-1)[0]] = b(n.data.value), c = !0;
2135
2162
  break;
2136
2163
  case "APPLY":
2137
- l = d.apply(u, c);
2164
+ c = d.apply(u, l);
2138
2165
  break;
2139
2166
  case "CONSTRUCT":
2140
2167
  {
2141
- const p = new d(...c);
2142
- l = Re(p);
2168
+ const p = new d(...l);
2169
+ c = Re(p);
2143
2170
  }
2144
2171
  break;
2145
2172
  case "ENDPOINT":
2146
2173
  {
2147
2174
  const { port1: p, port2: y } = new MessageChannel();
2148
- B(t, y), l = Zt(p, [p]);
2175
+ B(t, y), c = er(p, [p]);
2149
2176
  }
2150
2177
  break;
2151
2178
  case "RELEASE":
2152
- l = void 0;
2179
+ c = void 0;
2153
2180
  break;
2154
2181
  default:
2155
2182
  return;
2156
2183
  }
2157
2184
  } catch (u) {
2158
- l = { value: u, [C]: 0 };
2185
+ c = { value: u, [T]: 0 };
2159
2186
  }
2160
- Promise.resolve(l).catch((u) => ({ value: u, [C]: 0 })).then((u) => {
2187
+ Promise.resolve(c).catch((u) => ({ value: u, [T]: 0 })).then((u) => {
2161
2188
  const [d, p] = A(u);
2162
2189
  e.postMessage(Object.assign(Object.assign({}, d), { id: i }), p), o === "RELEASE" && (e.removeEventListener("message", s), Ee(e), I in t && typeof t[I] == "function" && t[I]());
2163
2190
  }).catch((u) => {
2164
2191
  const [d, p] = A({
2165
2192
  value: new TypeError("Unserializable return value"),
2166
- [C]: 0
2193
+ [T]: 0
2167
2194
  });
2168
2195
  e.postMessage(Object.assign(Object.assign({}, d), { id: i }), p);
2169
2196
  });
2170
2197
  }), e.start && e.start();
2171
2198
  }
2172
- function Yt(t) {
2199
+ function Kt(t) {
2173
2200
  return t.constructor.name === "MessagePort";
2174
2201
  }
2175
2202
  function Ee(t) {
2176
- Yt(t) && t.close();
2203
+ Kt(t) && t.close();
2177
2204
  }
2178
2205
  function V(t, e) {
2179
- return M(t, [], e);
2206
+ return W(t, [], e);
2180
2207
  }
2181
- function T(t) {
2208
+ function x(t) {
2182
2209
  if (t)
2183
2210
  throw new Error("Proxy has been released and is not useable");
2184
2211
  }
2185
2212
  function ve(t) {
2186
- return E(t, {
2213
+ return v(t, {
2187
2214
  type: "RELEASE"
2188
2215
  }).then(() => {
2189
2216
  Ee(t);
@@ -2193,85 +2220,85 @@ const k = /* @__PURE__ */ new WeakMap(), O = "FinalizationRegistry" in globalThi
2193
2220
  const e = (k.get(t) || 0) - 1;
2194
2221
  k.set(t, e), e === 0 && ve(t);
2195
2222
  });
2196
- function Kt(t, e) {
2223
+ function Qt(t, e) {
2197
2224
  const r = (k.get(e) || 0) + 1;
2198
2225
  k.set(e, r), O && O.register(t, e, t);
2199
2226
  }
2200
- function Qt(t) {
2227
+ function Xt(t) {
2201
2228
  O && O.unregister(t);
2202
2229
  }
2203
- function M(t, e = [], r = function() {
2230
+ function W(t, e = [], r = function() {
2204
2231
  }) {
2205
2232
  let s = !1;
2206
2233
  const n = new Proxy(r, {
2207
2234
  get(i, o) {
2208
- if (T(s), o === Bt)
2235
+ if (x(s), o === Vt)
2209
2236
  return () => {
2210
- Qt(n), ve(t), s = !0;
2237
+ Xt(n), ve(t), s = !0;
2211
2238
  };
2212
2239
  if (o === "then") {
2213
2240
  if (e.length === 0)
2214
2241
  return { then: () => n };
2215
- const a = E(t, {
2242
+ const a = v(t, {
2216
2243
  type: "GET",
2217
- path: e.map((c) => c.toString())
2244
+ path: e.map((l) => l.toString())
2218
2245
  }).then(b);
2219
2246
  return a.then.bind(a);
2220
2247
  }
2221
- return M(t, [...e, o]);
2248
+ return W(t, [...e, o]);
2222
2249
  },
2223
2250
  set(i, o, a) {
2224
- T(s);
2225
- const [c, l] = A(a);
2226
- return E(t, {
2251
+ x(s);
2252
+ const [l, c] = A(a);
2253
+ return v(t, {
2227
2254
  type: "SET",
2228
2255
  path: [...e, o].map((u) => u.toString()),
2229
- value: c
2230
- }, l).then(b);
2256
+ value: l
2257
+ }, c).then(b);
2231
2258
  },
2232
2259
  apply(i, o, a) {
2233
- T(s);
2234
- const c = e[e.length - 1];
2235
- if (c === jt)
2236
- return E(t, {
2260
+ x(s);
2261
+ const l = e[e.length - 1];
2262
+ if (l === Bt)
2263
+ return v(t, {
2237
2264
  type: "ENDPOINT"
2238
2265
  }).then(b);
2239
- if (c === "bind")
2240
- return M(t, e.slice(0, -1));
2241
- const [l, u] = le(a);
2242
- return E(t, {
2266
+ if (l === "bind")
2267
+ return W(t, e.slice(0, -1));
2268
+ const [c, u] = le(a);
2269
+ return v(t, {
2243
2270
  type: "APPLY",
2244
2271
  path: e.map((d) => d.toString()),
2245
- argumentList: l
2272
+ argumentList: c
2246
2273
  }, u).then(b);
2247
2274
  },
2248
2275
  construct(i, o) {
2249
- T(s);
2250
- const [a, c] = le(o);
2251
- return E(t, {
2276
+ x(s);
2277
+ const [a, l] = le(o);
2278
+ return v(t, {
2252
2279
  type: "CONSTRUCT",
2253
- path: e.map((l) => l.toString()),
2280
+ path: e.map((c) => c.toString()),
2254
2281
  argumentList: a
2255
- }, c).then(b);
2282
+ }, l).then(b);
2256
2283
  }
2257
2284
  });
2258
- return Kt(n, t), n;
2285
+ return Qt(n, t), n;
2259
2286
  }
2260
- function Xt(t) {
2287
+ function Zt(t) {
2261
2288
  return Array.prototype.concat.apply([], t);
2262
2289
  }
2263
2290
  function le(t) {
2264
2291
  const e = t.map(A);
2265
- return [e.map((r) => r[0]), Xt(e.map((r) => r[1]))];
2292
+ return [e.map((r) => r[0]), Zt(e.map((r) => r[1]))];
2266
2293
  }
2267
2294
  const Se = /* @__PURE__ */ new WeakMap();
2268
- function Zt(t, e) {
2295
+ function er(t, e) {
2269
2296
  return Se.set(t, e), t;
2270
2297
  }
2271
2298
  function Re(t) {
2272
2299
  return Object.assign(t, { [_e]: !0 });
2273
2300
  }
2274
- function er(t, e = globalThis, r = "*") {
2301
+ function tr(t, e = globalThis, r = "*") {
2275
2302
  return {
2276
2303
  postMessage: (s, n) => t.postMessage(s, r, n),
2277
2304
  addEventListener: e.addEventListener.bind(e),
@@ -2307,26 +2334,26 @@ function b(t) {
2307
2334
  return t.value;
2308
2335
  }
2309
2336
  }
2310
- function E(t, e, r) {
2337
+ function v(t, e, r) {
2311
2338
  return new Promise((s) => {
2312
- const n = tr();
2339
+ const n = rr();
2313
2340
  t.addEventListener("message", function i(o) {
2314
2341
  !o.data || !o.data.id || o.data.id !== n || (t.removeEventListener("message", i), s(o.data));
2315
2342
  }), t.start && t.start(), t.postMessage(Object.assign({ id: n }, e), r);
2316
2343
  });
2317
2344
  }
2318
- function tr() {
2345
+ function rr() {
2319
2346
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
2320
2347
  }
2321
2348
  function xe(t) {
2322
- rr();
2323
- const e = t instanceof Worker ? t : er(t), r = V(e), s = Te(r);
2349
+ sr();
2350
+ const e = t instanceof Worker ? t : tr(t), r = V(e), s = Te(r);
2324
2351
  return new Proxy(s, {
2325
2352
  get: (n, i) => i === "isConnected" ? () => r.isConnected() : r[i]
2326
2353
  });
2327
2354
  }
2328
2355
  let ue = !1;
2329
- function rr() {
2356
+ function sr() {
2330
2357
  ue || (ue = !0, R.set("EVENT", {
2331
2358
  canHandle: (t) => t instanceof CustomEvent,
2332
2359
  serialize: (t) => [
@@ -2352,7 +2379,7 @@ function rr() {
2352
2379
  return [t.toRawData(), []];
2353
2380
  },
2354
2381
  deserialize(t) {
2355
- return S.fromRawData(t);
2382
+ return _.fromRawData(t);
2356
2383
  }
2357
2384
  }));
2358
2385
  }
@@ -2377,7 +2404,7 @@ function Te(t) {
2377
2404
  (function() {
2378
2405
  return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
2379
2406
  })();
2380
- async function sr({
2407
+ async function nr({
2381
2408
  iframe: t,
2382
2409
  blueprint: e,
2383
2410
  remoteUrl: r,
@@ -2385,7 +2412,7 @@ async function sr({
2385
2412
  disableProgressBar: n,
2386
2413
  onBlueprintStepCompleted: i
2387
2414
  }) {
2388
- if (nr(r), r = de(r, {
2415
+ if (ir(r), r = de(r, {
2389
2416
  progressbar: !n
2390
2417
  }), s.setCaption("Preparing WordPress"), !e)
2391
2418
  return he(t, r, s);
@@ -2400,7 +2427,7 @@ async function sr({
2400
2427
  }),
2401
2428
  s
2402
2429
  );
2403
- return await qt(o, a), s.finish(), a;
2430
+ return await jt(o, a), s.finish(), a;
2404
2431
  }
2405
2432
  async function he(t, e, r) {
2406
2433
  await new Promise((i) => {
@@ -2413,25 +2440,25 @@ async function he(t, e, r) {
2413
2440
  const n = r.stage();
2414
2441
  return await s.onDownloadProgress(n.loadingListener), await s.isReady(), n.finish(), s;
2415
2442
  }
2416
- const F = "https://playground.wordpress.net";
2417
- function nr(t) {
2418
- const e = new URL(t, F);
2419
- if ((e.origin === F || e.hostname === "localhost") && e.pathname !== "/remote.html")
2443
+ const C = "https://playground.wordpress.net";
2444
+ function ir(t) {
2445
+ const e = new URL(t, C);
2446
+ if ((e.origin === C || e.hostname === "localhost") && e.pathname !== "/remote.html")
2420
2447
  throw new Error(
2421
- `Invalid remote URL: ${e}. Expected origin to be ${F}/remote.html.`
2448
+ `Invalid remote URL: ${e}. Expected origin to be ${C}/remote.html.`
2422
2449
  );
2423
2450
  }
2424
2451
  function de(t, e) {
2425
- const r = new URL(t, F), s = new URLSearchParams(r.search);
2452
+ const r = new URL(t, C), s = new URLSearchParams(r.search);
2426
2453
  for (const [n, i] of Object.entries(e))
2427
2454
  i != null && i !== !1 && s.set(n, i.toString());
2428
2455
  return r.search = s.toString(), r.toString();
2429
2456
  }
2430
- async function ar(t, e) {
2457
+ async function cr(t, e) {
2431
2458
  if (console.warn(
2432
2459
  "`connectPlayground` is deprecated and will be removed. Use `startPlayground` instead."
2433
2460
  ), e?.loadRemote)
2434
- return sr({
2461
+ return nr({
2435
2462
  iframe: t,
2436
2463
  remoteUrl: e.loadRemote
2437
2464
  });
@@ -2441,39 +2468,40 @@ async function ar(t, e) {
2441
2468
  return await r.isConnected(), r;
2442
2469
  }
2443
2470
  export {
2444
- wt as LatestSupportedPHPVersion,
2445
- z as SupportedPHPVersions,
2446
- ir as SupportedPHPVersionsList,
2447
- Oe as activatePlugin,
2448
- Ae as applyWordPressPatches,
2471
+ yt as LatestSupportedPHPVersion,
2472
+ q as SupportedPHPVersions,
2473
+ or as SupportedPHPVersionsList,
2474
+ ke as activatePlugin,
2475
+ Oe as activateTheme,
2476
+ Le as applyWordPressPatches,
2449
2477
  Mt as compileBlueprint,
2450
- ar as connectPlayground,
2478
+ cr as connectPlayground,
2451
2479
  Me as cp,
2452
- Be as defineSiteUrl,
2453
- nt as defineVirtualWpConfigConsts,
2480
+ Ve as defineSiteUrl,
2481
+ it as defineVirtualWpConfigConsts,
2454
2482
  pe as defineWpConfigConsts,
2455
- Ye as importFile,
2456
- Xe as installPlugin,
2457
- Ze as installTheme,
2458
- et as login,
2459
- De as mkdir,
2460
- We as mv,
2461
- v as phpVar,
2462
- W as phpVars,
2463
- Je as replaceSite,
2464
- Ne as request,
2483
+ Ke as importFile,
2484
+ Ze as installPlugin,
2485
+ et as installTheme,
2486
+ tt as login,
2487
+ qe as mkdir,
2488
+ De as mv,
2489
+ S as phpVar,
2490
+ M as phpVars,
2491
+ Ye as replaceSite,
2492
+ We as request,
2465
2493
  ze as rm,
2466
- qe as rmdir,
2467
- qt as runBlueprintSteps,
2468
- Ue as runPHP,
2469
- He as runPHPWithOptions,
2470
- tt as runWpInstallationWizard,
2471
- Ie as setPhpIniEntry,
2472
- or as setPluginProxyURL,
2473
- rt as setSiteOptions,
2474
- sr as startPlaygroundWeb,
2494
+ je as rmdir,
2495
+ jt as runBlueprintSteps,
2496
+ He as runPHP,
2497
+ Ie as runPHPWithOptions,
2498
+ rt as runWpInstallationWizard,
2499
+ Ne as setPhpIniEntry,
2500
+ ar as setPluginProxyURL,
2501
+ st as setSiteOptions,
2502
+ nr as startPlaygroundWeb,
2475
2503
  me as unzip,
2476
- st as updateUserMeta,
2477
- je as writeFile,
2478
- Ge as zipEntireSite
2504
+ nt as updateUserMeta,
2505
+ Be as writeFile,
2506
+ Je as zipEntireSite
2479
2507
  };