@wp-playground/client 0.1.6 → 0.1.7
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 +499 -214
- package/package.json +2 -6
package/index.js
CHANGED
|
@@ -1,15 +1,257 @@
|
|
|
1
|
-
import * as m from "comlink";
|
|
2
|
-
import { cloneResponseMonitorProgress as U } from "@php-wasm/progress";
|
|
3
1
|
(function() {
|
|
4
2
|
return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
5
3
|
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2019 Google LLC
|
|
7
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
*/
|
|
9
|
+
const M = Symbol("Comlink.proxy"), Z = Symbol("Comlink.endpoint"), G = Symbol("Comlink.releaseProxy"), C = Symbol("Comlink.finalizer"), T = Symbol("Comlink.thrown"), _ = (e) => typeof e == "object" && e !== null || typeof e == "function", K = {
|
|
10
|
+
canHandle: (e) => _(e) && e[M],
|
|
11
|
+
serialize(e) {
|
|
12
|
+
const { port1: t, port2: r } = new MessageChannel();
|
|
13
|
+
return z(e, t), [r, [r]];
|
|
14
|
+
},
|
|
15
|
+
deserialize(e) {
|
|
16
|
+
return e.start(), q(e);
|
|
17
|
+
}
|
|
18
|
+
}, X = {
|
|
19
|
+
canHandle: (e) => _(e) && T in e,
|
|
20
|
+
serialize({ value: e }) {
|
|
21
|
+
let t;
|
|
22
|
+
return e instanceof Error ? t = {
|
|
23
|
+
isError: !0,
|
|
24
|
+
value: {
|
|
25
|
+
message: e.message,
|
|
26
|
+
name: e.name,
|
|
27
|
+
stack: e.stack
|
|
28
|
+
}
|
|
29
|
+
} : t = { isError: !1, value: e }, [t, []];
|
|
30
|
+
},
|
|
31
|
+
deserialize(e) {
|
|
32
|
+
throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
|
|
33
|
+
}
|
|
34
|
+
}, F = /* @__PURE__ */ new Map([
|
|
35
|
+
["proxy", K],
|
|
36
|
+
["throw", X]
|
|
37
|
+
]);
|
|
38
|
+
function Y(e, t) {
|
|
39
|
+
for (const r of e)
|
|
40
|
+
if (t === r || r === "*" || r instanceof RegExp && r.test(t))
|
|
41
|
+
return !0;
|
|
42
|
+
return !1;
|
|
43
|
+
}
|
|
44
|
+
function z(e, t = globalThis, r = ["*"]) {
|
|
45
|
+
t.addEventListener("message", function l(s) {
|
|
46
|
+
if (!s || !s.data)
|
|
47
|
+
return;
|
|
48
|
+
if (!Y(r, s.origin)) {
|
|
49
|
+
console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const { id: u, type: i, path: p } = Object.assign({ path: [] }, s.data), c = (s.data.argumentList || []).map(w);
|
|
53
|
+
let n;
|
|
54
|
+
try {
|
|
55
|
+
const o = p.slice(0, -1).reduce((a, f) => a[f], e), d = p.reduce((a, f) => a[f], e);
|
|
56
|
+
switch (i) {
|
|
57
|
+
case "GET":
|
|
58
|
+
n = d;
|
|
59
|
+
break;
|
|
60
|
+
case "SET":
|
|
61
|
+
o[p.slice(-1)[0]] = w(s.data.value), n = !0;
|
|
62
|
+
break;
|
|
63
|
+
case "APPLY":
|
|
64
|
+
n = d.apply(o, c);
|
|
65
|
+
break;
|
|
66
|
+
case "CONSTRUCT":
|
|
67
|
+
{
|
|
68
|
+
const a = new d(...c);
|
|
69
|
+
n = re(a);
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case "ENDPOINT":
|
|
73
|
+
{
|
|
74
|
+
const { port1: a, port2: f } = new MessageChannel();
|
|
75
|
+
z(e, f), n = ne(a, [a]);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case "RELEASE":
|
|
79
|
+
n = void 0;
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
} catch (o) {
|
|
85
|
+
n = { value: o, [T]: 0 };
|
|
86
|
+
}
|
|
87
|
+
Promise.resolve(n).catch((o) => ({ value: o, [T]: 0 })).then((o) => {
|
|
88
|
+
const [d, a] = A(o);
|
|
89
|
+
t.postMessage(Object.assign(Object.assign({}, d), { id: u }), a), i === "RELEASE" && (t.removeEventListener("message", l), j(t), C in e && typeof e[C] == "function" && e[C]());
|
|
90
|
+
}).catch((o) => {
|
|
91
|
+
const [d, a] = A({
|
|
92
|
+
value: new TypeError("Unserializable return value"),
|
|
93
|
+
[T]: 0
|
|
94
|
+
});
|
|
95
|
+
t.postMessage(Object.assign(Object.assign({}, d), { id: u }), a);
|
|
96
|
+
});
|
|
97
|
+
}), t.start && t.start();
|
|
98
|
+
}
|
|
99
|
+
function Q(e) {
|
|
100
|
+
return e.constructor.name === "MessagePort";
|
|
101
|
+
}
|
|
102
|
+
function j(e) {
|
|
103
|
+
Q(e) && e.close();
|
|
104
|
+
}
|
|
105
|
+
function q(e, t) {
|
|
106
|
+
return O(e, [], t);
|
|
107
|
+
}
|
|
108
|
+
function P(e) {
|
|
109
|
+
if (e)
|
|
110
|
+
throw new Error("Proxy has been released and is not useable");
|
|
111
|
+
}
|
|
112
|
+
function H(e) {
|
|
113
|
+
return h(e, {
|
|
114
|
+
type: "RELEASE"
|
|
115
|
+
}).then(() => {
|
|
116
|
+
j(e);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const R = /* @__PURE__ */ new WeakMap(), S = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
|
|
120
|
+
const t = (R.get(e) || 0) - 1;
|
|
121
|
+
R.set(e, t), t === 0 && H(e);
|
|
122
|
+
});
|
|
123
|
+
function J(e, t) {
|
|
124
|
+
const r = (R.get(t) || 0) + 1;
|
|
125
|
+
R.set(t, r), S && S.register(e, t, e);
|
|
126
|
+
}
|
|
127
|
+
function ee(e) {
|
|
128
|
+
S && S.unregister(e);
|
|
129
|
+
}
|
|
130
|
+
function O(e, t = [], r = function() {
|
|
131
|
+
}) {
|
|
132
|
+
let l = !1;
|
|
133
|
+
const s = new Proxy(r, {
|
|
134
|
+
get(u, i) {
|
|
135
|
+
if (P(l), i === G)
|
|
136
|
+
return () => {
|
|
137
|
+
ee(s), H(e), l = !0;
|
|
138
|
+
};
|
|
139
|
+
if (i === "then") {
|
|
140
|
+
if (t.length === 0)
|
|
141
|
+
return { then: () => s };
|
|
142
|
+
const p = h(e, {
|
|
143
|
+
type: "GET",
|
|
144
|
+
path: t.map((c) => c.toString())
|
|
145
|
+
}).then(w);
|
|
146
|
+
return p.then.bind(p);
|
|
147
|
+
}
|
|
148
|
+
return O(e, [...t, i]);
|
|
149
|
+
},
|
|
150
|
+
set(u, i, p) {
|
|
151
|
+
P(l);
|
|
152
|
+
const [c, n] = A(p);
|
|
153
|
+
return h(e, {
|
|
154
|
+
type: "SET",
|
|
155
|
+
path: [...t, i].map((o) => o.toString()),
|
|
156
|
+
value: c
|
|
157
|
+
}, n).then(w);
|
|
158
|
+
},
|
|
159
|
+
apply(u, i, p) {
|
|
160
|
+
P(l);
|
|
161
|
+
const c = t[t.length - 1];
|
|
162
|
+
if (c === Z)
|
|
163
|
+
return h(e, {
|
|
164
|
+
type: "ENDPOINT"
|
|
165
|
+
}).then(w);
|
|
166
|
+
if (c === "bind")
|
|
167
|
+
return O(e, t.slice(0, -1));
|
|
168
|
+
const [n, o] = D(p);
|
|
169
|
+
return h(e, {
|
|
170
|
+
type: "APPLY",
|
|
171
|
+
path: t.map((d) => d.toString()),
|
|
172
|
+
argumentList: n
|
|
173
|
+
}, o).then(w);
|
|
174
|
+
},
|
|
175
|
+
construct(u, i) {
|
|
176
|
+
P(l);
|
|
177
|
+
const [p, c] = D(i);
|
|
178
|
+
return h(e, {
|
|
179
|
+
type: "CONSTRUCT",
|
|
180
|
+
path: t.map((n) => n.toString()),
|
|
181
|
+
argumentList: p
|
|
182
|
+
}, c).then(w);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return J(s, e), s;
|
|
186
|
+
}
|
|
187
|
+
function te(e) {
|
|
188
|
+
return Array.prototype.concat.apply([], e);
|
|
189
|
+
}
|
|
190
|
+
function D(e) {
|
|
191
|
+
const t = e.map(A);
|
|
192
|
+
return [t.map((r) => r[0]), te(t.map((r) => r[1]))];
|
|
193
|
+
}
|
|
194
|
+
const B = /* @__PURE__ */ new WeakMap();
|
|
195
|
+
function ne(e, t) {
|
|
196
|
+
return B.set(e, t), e;
|
|
197
|
+
}
|
|
198
|
+
function re(e) {
|
|
199
|
+
return Object.assign(e, { [M]: !0 });
|
|
200
|
+
}
|
|
201
|
+
function oe(e, t = globalThis, r = "*") {
|
|
202
|
+
return {
|
|
203
|
+
postMessage: (l, s) => e.postMessage(l, r, s),
|
|
204
|
+
addEventListener: t.addEventListener.bind(t),
|
|
205
|
+
removeEventListener: t.removeEventListener.bind(t)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function A(e) {
|
|
209
|
+
for (const [t, r] of F)
|
|
210
|
+
if (r.canHandle(e)) {
|
|
211
|
+
const [l, s] = r.serialize(e);
|
|
212
|
+
return [
|
|
213
|
+
{
|
|
214
|
+
type: "HANDLER",
|
|
215
|
+
name: t,
|
|
216
|
+
value: l
|
|
217
|
+
},
|
|
218
|
+
s
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
return [
|
|
222
|
+
{
|
|
223
|
+
type: "RAW",
|
|
224
|
+
value: e
|
|
225
|
+
},
|
|
226
|
+
B.get(e) || []
|
|
227
|
+
];
|
|
228
|
+
}
|
|
229
|
+
function w(e) {
|
|
230
|
+
switch (e.type) {
|
|
231
|
+
case "HANDLER":
|
|
232
|
+
return F.get(e.name).deserialize(e.value);
|
|
233
|
+
case "RAW":
|
|
234
|
+
return e.value;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function h(e, t, r) {
|
|
238
|
+
return new Promise((l) => {
|
|
239
|
+
const s = ie();
|
|
240
|
+
e.addEventListener("message", function u(i) {
|
|
241
|
+
!i.data || !i.data.id || i.data.id !== s || (e.removeEventListener("message", u), l(i.data));
|
|
242
|
+
}), e.start && e.start(), e.postMessage(Object.assign({ id: s }, t), r);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function ie() {
|
|
246
|
+
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
247
|
+
}
|
|
248
|
+
function ae(e) {
|
|
249
|
+
se();
|
|
250
|
+
const t = e instanceof Worker ? e : oe(e);
|
|
251
|
+
return q(t);
|
|
10
252
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
253
|
+
function se() {
|
|
254
|
+
F.set("EVENT", {
|
|
13
255
|
canHandle: (e) => e instanceof CustomEvent,
|
|
14
256
|
serialize: (e) => [
|
|
15
257
|
{
|
|
@@ -18,101 +260,101 @@ function A() {
|
|
|
18
260
|
[]
|
|
19
261
|
],
|
|
20
262
|
deserialize: (e) => e
|
|
21
|
-
}),
|
|
263
|
+
}), F.set("FUNCTION", {
|
|
22
264
|
canHandle: (e) => typeof e == "function",
|
|
23
265
|
serialize(e) {
|
|
24
266
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
25
|
-
const { port1:
|
|
26
|
-
return
|
|
267
|
+
const { port1: t, port2: r } = new MessageChannel();
|
|
268
|
+
return z(e, t), [r, [r]];
|
|
27
269
|
},
|
|
28
270
|
deserialize(e) {
|
|
29
|
-
return e.start(),
|
|
271
|
+
return e.start(), q(e);
|
|
30
272
|
}
|
|
31
273
|
});
|
|
32
274
|
}
|
|
33
275
|
(function() {
|
|
34
276
|
return navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
|
|
35
277
|
})();
|
|
36
|
-
var
|
|
278
|
+
var v = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, L = {}, le = {
|
|
37
279
|
get exports() {
|
|
38
|
-
return
|
|
280
|
+
return L;
|
|
39
281
|
},
|
|
40
282
|
set exports(e) {
|
|
41
|
-
|
|
283
|
+
L = e;
|
|
42
284
|
}
|
|
43
285
|
};
|
|
44
|
-
(function(e,
|
|
45
|
-
(function(
|
|
46
|
-
|
|
47
|
-
})(
|
|
48
|
-
function
|
|
49
|
-
return typeof
|
|
286
|
+
(function(e, t) {
|
|
287
|
+
(function(r, l) {
|
|
288
|
+
l();
|
|
289
|
+
})(v, function() {
|
|
290
|
+
function r(n, o) {
|
|
291
|
+
return typeof o > "u" ? o = { autoBom: !1 } : typeof o != "object" && (console.warn("Deprecated: Expected third argument to be a object"), o = { autoBom: !o }), o.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(n.type) ? new Blob(["\uFEFF", n], { type: n.type }) : n;
|
|
50
292
|
}
|
|
51
|
-
function
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
293
|
+
function l(n, o, d) {
|
|
294
|
+
var a = new XMLHttpRequest();
|
|
295
|
+
a.open("GET", n), a.responseType = "blob", a.onload = function() {
|
|
296
|
+
c(a.response, o, d);
|
|
297
|
+
}, a.onerror = function() {
|
|
56
298
|
console.error("could not download file");
|
|
57
|
-
},
|
|
299
|
+
}, a.send();
|
|
58
300
|
}
|
|
59
|
-
function
|
|
60
|
-
var
|
|
61
|
-
|
|
301
|
+
function s(n) {
|
|
302
|
+
var o = new XMLHttpRequest();
|
|
303
|
+
o.open("HEAD", n, !1);
|
|
62
304
|
try {
|
|
63
|
-
|
|
305
|
+
o.send();
|
|
64
306
|
} catch {
|
|
65
307
|
}
|
|
66
|
-
return 200 <=
|
|
308
|
+
return 200 <= o.status && 299 >= o.status;
|
|
67
309
|
}
|
|
68
|
-
function u(
|
|
310
|
+
function u(n) {
|
|
69
311
|
try {
|
|
70
|
-
|
|
312
|
+
n.dispatchEvent(new MouseEvent("click"));
|
|
71
313
|
} catch {
|
|
72
|
-
var
|
|
73
|
-
|
|
314
|
+
var o = document.createEvent("MouseEvents");
|
|
315
|
+
o.initMouseEvent("click", !0, !0, window, 0, 0, 0, 80, 20, !1, !1, !1, !1, 0, null), n.dispatchEvent(o);
|
|
74
316
|
}
|
|
75
317
|
}
|
|
76
|
-
var
|
|
77
|
-
} : "download" in HTMLAnchorElement.prototype && !
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
318
|
+
var i = typeof window == "object" && window.window === window ? window : typeof self == "object" && self.self === self ? self : typeof v == "object" && v.global === v ? v : void 0, p = i.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent), c = i.saveAs || (typeof window != "object" || window !== i ? function() {
|
|
319
|
+
} : "download" in HTMLAnchorElement.prototype && !p ? function(n, o, d) {
|
|
320
|
+
var a = i.URL || i.webkitURL, f = document.createElement("a");
|
|
321
|
+
o = o || n.name || "download", f.download = o, f.rel = "noopener", typeof n == "string" ? (f.href = n, f.origin === location.origin ? u(f) : s(f.href) ? l(n, o, d) : u(f, f.target = "_blank")) : (f.href = a.createObjectURL(n), setTimeout(function() {
|
|
322
|
+
a.revokeObjectURL(f.href);
|
|
81
323
|
}, 4e4), setTimeout(function() {
|
|
82
|
-
u(
|
|
324
|
+
u(f);
|
|
83
325
|
}, 0));
|
|
84
|
-
} : "msSaveOrOpenBlob" in navigator ? function(
|
|
85
|
-
if (
|
|
86
|
-
navigator.msSaveOrOpenBlob(
|
|
87
|
-
else if (
|
|
88
|
-
|
|
326
|
+
} : "msSaveOrOpenBlob" in navigator ? function(n, o, d) {
|
|
327
|
+
if (o = o || n.name || "download", typeof n != "string")
|
|
328
|
+
navigator.msSaveOrOpenBlob(r(n, d), o);
|
|
329
|
+
else if (s(n))
|
|
330
|
+
l(n, o, d);
|
|
89
331
|
else {
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
u(
|
|
332
|
+
var a = document.createElement("a");
|
|
333
|
+
a.href = n, a.target = "_blank", setTimeout(function() {
|
|
334
|
+
u(a);
|
|
93
335
|
});
|
|
94
336
|
}
|
|
95
|
-
} : function(
|
|
96
|
-
if (
|
|
97
|
-
return
|
|
98
|
-
var
|
|
99
|
-
if ((
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
},
|
|
337
|
+
} : function(n, o, d, a) {
|
|
338
|
+
if (a = a || open("", "_blank"), a && (a.document.title = a.document.body.innerText = "downloading..."), typeof n == "string")
|
|
339
|
+
return l(n, o, d);
|
|
340
|
+
var f = n.type === "application/octet-stream", g = /constructor/i.test(i.HTMLElement) || i.safari, E = /CriOS\/[\d]+/.test(navigator.userAgent);
|
|
341
|
+
if ((E || f && g || p) && typeof FileReader < "u") {
|
|
342
|
+
var y = new FileReader();
|
|
343
|
+
y.onloadend = function() {
|
|
344
|
+
var b = y.result;
|
|
345
|
+
b = E ? b : b.replace(/^data:[^;]*;/, "data:attachment/file;"), a ? a.location.href = b : location = b, a = null;
|
|
346
|
+
}, y.readAsDataURL(n);
|
|
105
347
|
} else {
|
|
106
|
-
var x =
|
|
107
|
-
|
|
108
|
-
x.revokeObjectURL(
|
|
348
|
+
var x = i.URL || i.webkitURL, m = x.createObjectURL(n);
|
|
349
|
+
a ? a.location = m : location.href = m, a = null, setTimeout(function() {
|
|
350
|
+
x.revokeObjectURL(m);
|
|
109
351
|
}, 4e4);
|
|
110
352
|
}
|
|
111
353
|
});
|
|
112
|
-
|
|
354
|
+
i.saveAs = c.saveAs = c, e.exports = c;
|
|
113
355
|
});
|
|
114
|
-
})(
|
|
115
|
-
const
|
|
356
|
+
})(le);
|
|
357
|
+
const U = `<?php
|
|
116
358
|
|
|
117
359
|
function generateZipFile($exportPath, $databasePath, $docRoot) {
|
|
118
360
|
$zip = new ZipArchive;
|
|
@@ -180,23 +422,23 @@ function importZipFile($pathToZip) {
|
|
|
180
422
|
$zip->close();
|
|
181
423
|
}
|
|
182
424
|
}
|
|
183
|
-
`,
|
|
184
|
-
async function
|
|
185
|
-
const
|
|
425
|
+
`, N = "databaseExport.xml", k = "/" + N;
|
|
426
|
+
async function fe(e) {
|
|
427
|
+
const t = await e.request({
|
|
186
428
|
relativeUrl: "/wp-admin/export.php?download=true&&content=all"
|
|
187
|
-
}),
|
|
188
|
-
|
|
429
|
+
}), r = new TextDecoder().decode(
|
|
430
|
+
t.body
|
|
189
431
|
);
|
|
190
|
-
await e.writeFile(
|
|
191
|
-
const
|
|
192
|
-
code:
|
|
432
|
+
await e.writeFile(k, r);
|
|
433
|
+
const l = await e.wordPressVersion, s = await e.phpVersion, u = await e.documentRoot, i = `wordpress-playground--wp${l}--php${s}.zip`, p = `/${i}`, c = await e.run({
|
|
434
|
+
code: U + ` generateZipFile('${p}', '${k}', '${u}');`
|
|
193
435
|
});
|
|
194
|
-
if (
|
|
195
|
-
throw
|
|
196
|
-
const
|
|
197
|
-
|
|
436
|
+
if (c.exitCode !== 0)
|
|
437
|
+
throw c.errors;
|
|
438
|
+
const n = await e.readFileAsBuffer(i), o = new File([n], i);
|
|
439
|
+
L.saveAs(o);
|
|
198
440
|
}
|
|
199
|
-
async function
|
|
441
|
+
async function we(e, t) {
|
|
200
442
|
if (
|
|
201
443
|
// eslint-disable-next-line no-alert
|
|
202
444
|
!confirm(
|
|
@@ -204,253 +446,296 @@ async function k(e, o) {
|
|
|
204
446
|
)
|
|
205
447
|
)
|
|
206
448
|
return !1;
|
|
207
|
-
const
|
|
208
|
-
await e.writeFile(
|
|
449
|
+
const r = await t.arrayBuffer(), l = new Uint8Array(r), s = "/import.zip";
|
|
450
|
+
await e.writeFile(s, l);
|
|
209
451
|
const u = await e.run({
|
|
210
|
-
code:
|
|
452
|
+
code: U + ` readFileFromZipArchive('${s}', '${k}');`
|
|
211
453
|
});
|
|
212
454
|
if (u.exitCode !== 0)
|
|
213
455
|
throw u.errors;
|
|
214
|
-
const
|
|
456
|
+
const i = new TextDecoder().decode(
|
|
215
457
|
u.body
|
|
216
|
-
),
|
|
217
|
-
[
|
|
218
|
-
|
|
219
|
-
),
|
|
458
|
+
), p = new File(
|
|
459
|
+
[i],
|
|
460
|
+
N
|
|
461
|
+
), c = await e.request({
|
|
220
462
|
relativeUrl: "/wp-admin/admin.php?import=wordpress"
|
|
221
|
-
}),
|
|
222
|
-
new TextDecoder().decode(
|
|
463
|
+
}), o = new DOMParser().parseFromString(
|
|
464
|
+
new TextDecoder().decode(c.body),
|
|
223
465
|
"text/html"
|
|
224
|
-
).getElementById("import-upload-form")?.getAttribute("action"),
|
|
225
|
-
relativeUrl: `/wp-admin/${
|
|
466
|
+
).getElementById("import-upload-form")?.getAttribute("action"), d = await e.request({
|
|
467
|
+
relativeUrl: `/wp-admin/${o}`,
|
|
226
468
|
method: "POST",
|
|
227
|
-
files: { import:
|
|
228
|
-
}),
|
|
229
|
-
new TextDecoder().decode(
|
|
469
|
+
files: { import: p }
|
|
470
|
+
}), f = new DOMParser().parseFromString(
|
|
471
|
+
new TextDecoder().decode(d.body),
|
|
230
472
|
"text/html"
|
|
231
473
|
).querySelector(
|
|
232
474
|
"#wpbody-content form"
|
|
233
|
-
),
|
|
475
|
+
), g = f?.getAttribute(
|
|
234
476
|
"action"
|
|
235
|
-
),
|
|
477
|
+
), E = (f?.querySelector(
|
|
236
478
|
"input[name='_wpnonce']"
|
|
237
|
-
)).value,
|
|
479
|
+
)).value, y = (f?.querySelector(
|
|
238
480
|
"input[name='_wp_http_referer']"
|
|
239
|
-
)).value, x = (
|
|
481
|
+
)).value, x = (f?.querySelector(
|
|
240
482
|
"input[name='import_id']"
|
|
241
483
|
)).value;
|
|
242
484
|
await e.request({
|
|
243
|
-
relativeUrl:
|
|
485
|
+
relativeUrl: g,
|
|
244
486
|
method: "POST",
|
|
245
487
|
formData: {
|
|
246
|
-
_wpnonce:
|
|
247
|
-
_wp_http_referer:
|
|
488
|
+
_wpnonce: E,
|
|
489
|
+
_wp_http_referer: y,
|
|
248
490
|
import_id: x
|
|
249
491
|
}
|
|
250
492
|
});
|
|
251
|
-
const
|
|
252
|
-
code:
|
|
493
|
+
const m = await e.run({
|
|
494
|
+
code: U + ` importZipFile('${s}');`
|
|
253
495
|
});
|
|
254
|
-
if (
|
|
255
|
-
throw
|
|
496
|
+
if (m.exitCode !== 0)
|
|
497
|
+
throw m.errors;
|
|
256
498
|
return !0;
|
|
257
499
|
}
|
|
258
|
-
async function
|
|
500
|
+
async function me(e, t = "admin", r = "password") {
|
|
259
501
|
await e.request({
|
|
260
502
|
relativeUrl: "/wp-login.php"
|
|
261
503
|
}), await e.request({
|
|
262
504
|
relativeUrl: "/wp-login.php",
|
|
263
505
|
method: "POST",
|
|
264
506
|
formData: {
|
|
265
|
-
log:
|
|
266
|
-
pwd:
|
|
507
|
+
log: t,
|
|
508
|
+
pwd: r,
|
|
267
509
|
rememberme: "forever"
|
|
268
510
|
}
|
|
269
511
|
});
|
|
270
512
|
}
|
|
271
|
-
function
|
|
272
|
-
return new DOMParser().parseFromString(
|
|
513
|
+
function $(e) {
|
|
514
|
+
return new DOMParser().parseFromString(ce(e), "text/html");
|
|
273
515
|
}
|
|
274
|
-
function
|
|
516
|
+
function ce(e) {
|
|
275
517
|
return new TextDecoder().decode(e.body);
|
|
276
518
|
}
|
|
277
|
-
function
|
|
278
|
-
const
|
|
279
|
-
return
|
|
519
|
+
function W(e) {
|
|
520
|
+
const t = e.split(".").shift().replace("-", " ");
|
|
521
|
+
return t.charAt(0).toUpperCase() + t.slice(1).toLowerCase();
|
|
280
522
|
}
|
|
281
|
-
async function
|
|
282
|
-
const
|
|
523
|
+
async function ue(e, t, r = {}) {
|
|
524
|
+
const l = "activate" in r ? r.activate : !0, s = await e.request({
|
|
283
525
|
relativeUrl: "/wp-admin/theme-install.php"
|
|
284
|
-
}), u =
|
|
526
|
+
}), u = $(s), i = new FormData(
|
|
285
527
|
u.querySelector(".wp-upload-form")
|
|
286
|
-
), { themezip:
|
|
287
|
-
|
|
288
|
-
),
|
|
528
|
+
), { themezip: p, ...c } = Object.fromEntries(
|
|
529
|
+
i.entries()
|
|
530
|
+
), n = await e.request({
|
|
289
531
|
relativeUrl: "/wp-admin/update.php?action=upload-theme",
|
|
290
532
|
method: "POST",
|
|
291
|
-
formData:
|
|
292
|
-
files: { themezip:
|
|
533
|
+
formData: c,
|
|
534
|
+
files: { themezip: t }
|
|
293
535
|
});
|
|
294
|
-
if (
|
|
295
|
-
const
|
|
536
|
+
if (l) {
|
|
537
|
+
const o = $(n), d = o.querySelector(
|
|
296
538
|
"#wpbody-content > .wrap"
|
|
297
539
|
);
|
|
298
|
-
if (
|
|
540
|
+
if (d?.textContent?.includes(
|
|
299
541
|
"Theme installation failed."
|
|
300
542
|
)) {
|
|
301
|
-
console.error(
|
|
543
|
+
console.error(d?.textContent);
|
|
302
544
|
return;
|
|
303
545
|
}
|
|
304
|
-
const
|
|
546
|
+
const a = o.querySelector(
|
|
305
547
|
"#wpbody-content .activatelink, .update-from-upload-actions .button.button-primary"
|
|
306
548
|
);
|
|
307
|
-
if (!
|
|
549
|
+
if (!a) {
|
|
308
550
|
console.error('The "activate" button was not found.');
|
|
309
551
|
return;
|
|
310
552
|
}
|
|
311
|
-
const
|
|
312
|
-
|
|
553
|
+
const f = a.attributes.getNamedItem("href").value, g = new URL(
|
|
554
|
+
f,
|
|
313
555
|
await e.pathToInternalUrl("/wp-admin/")
|
|
314
556
|
).toString();
|
|
315
557
|
await e.request({
|
|
316
|
-
absoluteUrl:
|
|
558
|
+
absoluteUrl: g
|
|
317
559
|
});
|
|
318
560
|
}
|
|
319
561
|
}
|
|
320
|
-
async function
|
|
321
|
-
const
|
|
562
|
+
async function de(e, t, r = {}) {
|
|
563
|
+
const l = "activate" in r ? r.activate : !0, s = await e.request({
|
|
322
564
|
relativeUrl: "/wp-admin/plugin-install.php?tab=upload"
|
|
323
|
-
}), u =
|
|
565
|
+
}), u = $(s), i = new FormData(
|
|
324
566
|
u.querySelector(".wp-upload-form")
|
|
325
|
-
), { pluginzip:
|
|
326
|
-
|
|
327
|
-
),
|
|
567
|
+
), { pluginzip: p, ...c } = Object.fromEntries(
|
|
568
|
+
i.entries()
|
|
569
|
+
), n = await e.request({
|
|
328
570
|
relativeUrl: "/wp-admin/update.php?action=upload-plugin",
|
|
329
571
|
method: "POST",
|
|
330
|
-
formData:
|
|
331
|
-
files: { pluginzip:
|
|
572
|
+
formData: c,
|
|
573
|
+
files: { pluginzip: t }
|
|
332
574
|
});
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
335
|
-
|
|
575
|
+
if (l) {
|
|
576
|
+
const a = $(n).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, f = new URL(
|
|
577
|
+
a,
|
|
336
578
|
await e.pathToInternalUrl("/wp-admin/")
|
|
337
579
|
).toString();
|
|
338
580
|
await e.request({
|
|
339
|
-
absoluteUrl:
|
|
581
|
+
absoluteUrl: f
|
|
340
582
|
});
|
|
341
583
|
}
|
|
342
|
-
async function
|
|
584
|
+
async function o(d, a) {
|
|
343
585
|
return await e.writeFile(
|
|
344
|
-
|
|
345
|
-
|
|
586
|
+
d,
|
|
587
|
+
a(await e.readFileAsText(d))
|
|
346
588
|
);
|
|
347
589
|
}
|
|
348
|
-
await e.isDir("/wordpress/wp-content/plugins/gutenberg") && !await e.fileExists("/wordpress/.gutenberg-patched") && (await e.writeFile("/wordpress/.gutenberg-patched", "1"), await
|
|
590
|
+
await e.isDir("/wordpress/wp-content/plugins/gutenberg") && !await e.fileExists("/wordpress/.gutenberg-patched") && (await e.writeFile("/wordpress/.gutenberg-patched", "1"), await o(
|
|
349
591
|
"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",
|
|
350
|
-
(
|
|
592
|
+
(d) => d.replace(
|
|
351
593
|
/srcDoc:("[^"]+"|[^,]+)/g,
|
|
352
594
|
'src:"/wp-includes/empty.html"'
|
|
353
595
|
)
|
|
354
|
-
), await
|
|
596
|
+
), await o(
|
|
355
597
|
"/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",
|
|
356
|
-
(
|
|
598
|
+
(d) => d.replace(
|
|
357
599
|
/srcDoc:("[^"]+"|[^,]+)/g,
|
|
358
600
|
'src:"/wp-includes/empty.html"'
|
|
359
601
|
)
|
|
360
602
|
));
|
|
361
603
|
}
|
|
362
|
-
async function
|
|
363
|
-
const
|
|
604
|
+
async function he(e, t) {
|
|
605
|
+
const s = $(
|
|
364
606
|
await e.request({
|
|
365
607
|
relativeUrl: "/wp-admin/plugins.php"
|
|
366
608
|
})
|
|
367
609
|
).querySelector(
|
|
368
|
-
`tr[data-slug="${
|
|
610
|
+
`tr[data-slug="${t}"] a`
|
|
369
611
|
).attributes.getNamedItem("href").value;
|
|
370
612
|
await e.request({
|
|
371
|
-
relativeUrl: "/wp-admin/" +
|
|
613
|
+
relativeUrl: "/wp-admin/" + s
|
|
372
614
|
});
|
|
373
615
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
616
|
+
const pe = 5 * 1024 * 1024;
|
|
617
|
+
function V(e, t) {
|
|
618
|
+
const r = e.headers.get("content-length") || "", l = parseInt(r, 10) || pe;
|
|
619
|
+
function s(u, i) {
|
|
620
|
+
t(
|
|
621
|
+
new CustomEvent("progress", {
|
|
622
|
+
detail: {
|
|
623
|
+
loaded: u,
|
|
624
|
+
total: i
|
|
625
|
+
}
|
|
626
|
+
})
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
return new Response(
|
|
630
|
+
new ReadableStream({
|
|
631
|
+
async start(u) {
|
|
632
|
+
if (!e.body) {
|
|
633
|
+
u.close();
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const i = e.body.getReader();
|
|
637
|
+
let p = 0;
|
|
638
|
+
for (; ; )
|
|
639
|
+
try {
|
|
640
|
+
const { done: c, value: n } = await i.read();
|
|
641
|
+
if (n && (p += n.byteLength), c) {
|
|
642
|
+
s(p, p), u.close();
|
|
643
|
+
break;
|
|
644
|
+
} else
|
|
645
|
+
s(p, l), u.enqueue(n);
|
|
646
|
+
} catch (c) {
|
|
647
|
+
console.error({ e: c }), u.error(c);
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}),
|
|
652
|
+
{
|
|
653
|
+
status: e.status,
|
|
654
|
+
statusText: e.statusText,
|
|
655
|
+
headers: e.headers
|
|
656
|
+
}
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
async function ge(e, t, r = 0, l) {
|
|
660
|
+
let s = await fetch("/plugin-proxy?theme=" + t);
|
|
661
|
+
if (l && (s = V(
|
|
662
|
+
s,
|
|
663
|
+
l.partialObserver(
|
|
664
|
+
r / 2,
|
|
665
|
+
`Installing ${W(t)} theme...`
|
|
381
666
|
)
|
|
382
|
-
),
|
|
383
|
-
const u = new File([await
|
|
667
|
+
), l.slowlyIncrementBy(r / 2)), s.status === 200) {
|
|
668
|
+
const u = new File([await s.blob()], t);
|
|
384
669
|
try {
|
|
385
|
-
await
|
|
386
|
-
} catch (
|
|
670
|
+
await ue(e, u);
|
|
671
|
+
} catch (i) {
|
|
387
672
|
console.error(
|
|
388
|
-
`Proceeding without the ${
|
|
389
|
-
), console.error(
|
|
673
|
+
`Proceeding without the ${t} theme. Could not install it in wp-admin. The original error was: ${i}`
|
|
674
|
+
), console.error(i);
|
|
390
675
|
}
|
|
391
676
|
} else
|
|
392
677
|
console.error(
|
|
393
|
-
`Proceeding without the ${
|
|
678
|
+
`Proceeding without the ${t} theme. Could not download the zip bundle from https://downloads.wordpress.org/themes/${t} – Is the file name correct?`
|
|
394
679
|
);
|
|
395
680
|
}
|
|
396
|
-
async function
|
|
397
|
-
const
|
|
398
|
-
await new Promise((
|
|
399
|
-
for (const
|
|
400
|
-
|
|
401
|
-
let
|
|
402
|
-
"/plugin-proxy?plugin=" +
|
|
681
|
+
async function ye(e, t, r = 0, l) {
|
|
682
|
+
const s = new I(), u = new I(), i = r / t.length;
|
|
683
|
+
await new Promise((p) => {
|
|
684
|
+
for (const c of t)
|
|
685
|
+
s.enqueue(async () => {
|
|
686
|
+
let n = await fetch(
|
|
687
|
+
"/plugin-proxy?plugin=" + c
|
|
403
688
|
);
|
|
404
|
-
return
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
`Installing ${
|
|
409
|
-
|
|
689
|
+
return l && (n = V(
|
|
690
|
+
n,
|
|
691
|
+
l.partialObserver(
|
|
692
|
+
i * 0.66,
|
|
693
|
+
`Installing ${W(
|
|
694
|
+
c
|
|
410
695
|
)} plugin...`
|
|
411
696
|
)
|
|
412
|
-
)),
|
|
413
|
-
`Proceeding without the ${
|
|
414
|
-
), null) : new File([await
|
|
697
|
+
)), n.status !== 200 ? (console.error(
|
|
698
|
+
`Proceeding without the ${c} plugin. Could not download the zip bundle from https://downloads.wordpress.org/plugin/${c} – Is the file name correct?`
|
|
699
|
+
), null) : new File([await n.blob()], c);
|
|
415
700
|
});
|
|
416
|
-
|
|
701
|
+
s.addEventListener("resolved", (c) => {
|
|
417
702
|
u.enqueue(async () => {
|
|
418
|
-
if (
|
|
419
|
-
|
|
703
|
+
if (c.detail) {
|
|
704
|
+
l?.slowlyIncrementBy(i * 0.33);
|
|
420
705
|
try {
|
|
421
|
-
await
|
|
422
|
-
} catch (
|
|
706
|
+
await de(e, c.detail);
|
|
707
|
+
} catch (n) {
|
|
423
708
|
console.error(
|
|
424
|
-
`Proceeding without the ${
|
|
425
|
-
), console.error(
|
|
709
|
+
`Proceeding without the ${c.detail.name} plugin. Could not install it in wp-admin. The original error was: ${n}`
|
|
710
|
+
), console.error(n);
|
|
426
711
|
}
|
|
427
712
|
}
|
|
428
713
|
});
|
|
429
714
|
}), u.addEventListener("empty", () => {
|
|
430
|
-
u.resolved ===
|
|
715
|
+
u.resolved === t.length && p(null);
|
|
431
716
|
});
|
|
432
717
|
});
|
|
433
718
|
}
|
|
434
|
-
class
|
|
719
|
+
class I extends EventTarget {
|
|
435
720
|
#e = [];
|
|
436
721
|
#t = !1;
|
|
437
722
|
#n = 0;
|
|
438
723
|
get resolved() {
|
|
439
724
|
return this.#n;
|
|
440
725
|
}
|
|
441
|
-
async enqueue(
|
|
442
|
-
this.#e.push(
|
|
726
|
+
async enqueue(t) {
|
|
727
|
+
this.#e.push(t), this.#r();
|
|
443
728
|
}
|
|
444
|
-
async #
|
|
729
|
+
async #r() {
|
|
445
730
|
if (!this.#t)
|
|
446
731
|
try {
|
|
447
732
|
for (this.#t = !0; this.#e.length; ) {
|
|
448
|
-
const
|
|
449
|
-
if (!
|
|
733
|
+
const t = this.#e.shift();
|
|
734
|
+
if (!t)
|
|
450
735
|
break;
|
|
451
|
-
const
|
|
736
|
+
const r = await t();
|
|
452
737
|
++this.#n, this.dispatchEvent(
|
|
453
|
-
new CustomEvent("resolved", { detail:
|
|
738
|
+
new CustomEvent("resolved", { detail: r })
|
|
454
739
|
);
|
|
455
740
|
}
|
|
456
741
|
} finally {
|
|
@@ -458,21 +743,21 @@ class E extends EventTarget {
|
|
|
458
743
|
}
|
|
459
744
|
}
|
|
460
745
|
}
|
|
461
|
-
async function
|
|
462
|
-
e.src =
|
|
463
|
-
e.addEventListener("load",
|
|
746
|
+
async function be(e, t) {
|
|
747
|
+
e.src = t, await new Promise((l) => {
|
|
748
|
+
e.addEventListener("load", l, !1);
|
|
464
749
|
});
|
|
465
|
-
const
|
|
466
|
-
return await
|
|
750
|
+
const r = ae(e.contentWindow);
|
|
751
|
+
return await r.absoluteUrl, r;
|
|
467
752
|
}
|
|
468
753
|
export {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
754
|
+
he as activatePlugin,
|
|
755
|
+
be as connectPlayground,
|
|
756
|
+
fe as exportFile,
|
|
757
|
+
we as importFile,
|
|
758
|
+
de as installPlugin,
|
|
759
|
+
ye as installPluginsFromDirectory,
|
|
760
|
+
ue as installTheme,
|
|
761
|
+
ge as installThemeFromDirectory,
|
|
762
|
+
me as login
|
|
478
763
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "WordPress Playground client",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,9 +29,5 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"types": "index.d.ts",
|
|
32
|
-
"
|
|
33
|
-
"@php-wasm/progress": "0.0.1",
|
|
34
|
-
"comlink": "4.4.1"
|
|
35
|
-
},
|
|
36
|
-
"gitHead": "87efbf6ada006edfb47fc16c081fafb05c555a93"
|
|
32
|
+
"gitHead": "629df0f3632cbd271f1fdbad2a1d0c0b22f40d4f"
|
|
37
33
|
}
|