@wp-playground/client 0.1.22 → 0.1.25
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.cjs +78 -0
- package/index.js +159 -144
- package/package.json +11 -3
package/index.cjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class se{#e;#t;constructor(e,n={}){this.server=e,this.#e={},this.#t={handleRedirects:!1,maxRedirects:4,...n}}async request(e,n=0){const r=await this.server.request({...e,headers:{...e.headers,cookie:this.#r()}});if(r.headers["set-cookie"]&&this.#n(r.headers["set-cookie"]),this.#t.handleRedirects&&r.headers.location&&n<this.#t.maxRedirects){const o=new URL(r.headers.location[0],this.server.absoluteUrl);return this.request({url:o.toString(),method:"GET",headers:{}},n+1)}return r}#n(e){for(const n of e)try{if(!n.includes("="))continue;const r=n.indexOf("="),o=n.substring(0,r),a=n.substring(r+1).split(";")[0];this.#e[o]=a}catch(r){console.error(r)}}#r(){const e=[];for(const n in this.#e)e.push(`${n}=${this.#e[n]}`);return e.join("; ")}}const ae="http://example.com";function j(t){return t.toString().substring(t.origin.length)}function B(t,e){return!e||!t.startsWith(e)?t:t.substring(e.length)}function le(t,e){return!e||t.startsWith(e)?t:e+t}class ce{constructor({concurrency:e}){this._running=0,this.concurrency=e,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(e=>this.queue.push(e));else return this._running++,()=>{this._running--,this.queue.length>0&&this.queue.shift()()}}}class E{constructor(e,n,r,o="",a=0){this.httpStatusCode=e,this.headers=n,this.bytes=r,this.exitCode=a,this.errors=o}static fromRawData(e){return new E(e.httpStatusCode,e.headers,e.bytes,e.errors,e.exitCode)}toRawData(){return{headers:this.headers,bytes:this.bytes,errors:this.errors,exitCode:this.exitCode,httpStatusCode:this.httpStatusCode}}get json(){return JSON.parse(this.text)}get text(){return new TextDecoder().decode(this.bytes)}}class ue{#e;#t;#n;#r;#i;#o;#s;#a;#l;constructor(e,n={}){this.#a=new ce({concurrency:1});const{documentRoot:r="/www/",absoluteUrl:o=typeof location=="object"?location?.href:"",isStaticFilePath:a=()=>!1}=n;this.php=e,this.#e=r,this.#l=a;const i=new URL(o);this.#n=i.hostname,this.#r=i.port?Number(i.port):i.protocol==="https:"?443:80,this.#t=(i.protocol||"").replace(":","");const d=this.#r!==443&&this.#r!==80;this.#i=[this.#n,d?`:${this.#r}`:""].join(""),this.#o=i.pathname.replace(/\/+$/,""),this.#s=[`${this.#t}://`,this.#i,this.#o].join("")}pathToInternalUrl(e){return`${this.absoluteUrl}${e}`}internalUrlToPath(e){const n=new URL(e);return n.pathname.startsWith(this.#o)&&(n.pathname=n.pathname.slice(this.#o.length)),j(n)}get isRequestRunning(){return this.#a.running>0}get absoluteUrl(){return this.#s}get documentRoot(){return this.#e}async request(e){const n=e.url.startsWith("http://")||e.url.startsWith("https://"),r=new URL(e.url,n?void 0:ae),o=B(r.pathname,this.#o);return this.#l(o)?this.#c(o):await this.#u(e,r)}#c(e){const n=`${this.#e}${e}`;if(!this.php.fileExists(n))return new E(404,{},new TextEncoder().encode("404 File not found"));const r=this.php.readFileAsBuffer(n);return new E(200,{"content-length":[`${r.byteLength}`],"content-type":[he(n)],"accept-ranges":["bytes"],"cache-control":["public, max-age=0"]},r)}async#u(e,n){const r=await this.#a.acquire();try{this.php.addServerGlobalEntry("DOCUMENT_ROOT",this.#e),this.php.addServerGlobalEntry("HTTPS",this.#s.startsWith("https://")?"on":"");let o="GET";const a={host:this.#i,...K(e.headers||{})},i=[];if(e.files&&Object.keys(e.files).length){o="POST";for(const c in e.files){const s=e.files[c];i.push({key:c,name:s.name,type:s.type,data:new Uint8Array(await s.arrayBuffer())})}a["content-type"]?.startsWith("multipart/form-data")&&(e.formData=de(e.body||""),a["content-type"]="application/x-www-form-urlencoded",delete e.body)}let d;return e.formData!==void 0?(o="POST",a["content-type"]=a["content-type"]||"application/x-www-form-urlencoded",d=new URLSearchParams(e.formData).toString()):d=e.body,await this.php.run({relativeUri:le(j(n),this.#o),protocol:this.#t,method:e.method||o,body:d,fileInfos:i,scriptPath:this.#d(n.pathname),headers:a})}finally{r()}}#d(e){let n=B(e,this.#o);n.includes(".php")?n=n.split(".php")[0]+".php":(n.endsWith("/")||(n+="/"),n.endsWith("index.php")||(n+="index.php"));const r=`${this.#e}${n}`;return this.php.fileExists(r)?r:`${this.#e}/index.php`}}function de(t){const e={},n=t.match(/--(.*)\r\n/);if(!n)return e;const r=n[1],o=t.split(`--${r}`);return o.shift(),o.pop(),o.forEach(a=>{const i=a.indexOf(`\r
|
|
2
|
+
\r
|
|
3
|
+
`),d=a.substring(0,i).trim(),c=a.substring(i+4).trim(),s=d.match(/name="([^"]+)"/);if(s){const l=s[1];e[l]=c}}),e}function he(t){switch(t.split(".").pop()){case"css":return"text/css";case"js":return"application/javascript";case"png":return"image/png";case"jpg":case"jpeg":return"image/jpeg";case"gif":return"image/gif";case"svg":return"image/svg+xml";case"woff":return"font/woff";case"woff2":return"font/woff2";case"ttf":return"font/ttf";case"otf":return"font/otf";case"eot":return"font/eot";case"ico":return"image/x-icon";case"html":return"text/html";case"json":return"application/json";case"xml":return"application/xml";case"txt":case"md":return"text/plain";default:return"application-octet-stream"}}const W={0:"No error occurred. System call completed successfully.",1:"Argument list too long.",2:"Permission denied.",3:"Address in use.",4:"Address not available.",5:"Address family not supported.",6:"Resource unavailable, or operation would block.",7:"Connection already in progress.",8:"Bad file descriptor.",9:"Bad message.",10:"Device or resource busy.",11:"Operation canceled.",12:"No child processes.",13:"Connection aborted.",14:"Connection refused.",15:"Connection reset.",16:"Resource deadlock would occur.",17:"Destination address required.",18:"Mathematics argument out of domain of function.",19:"Reserved.",20:"File exists.",21:"Bad address.",22:"File too large.",23:"Host is unreachable.",24:"Identifier removed.",25:"Illegal byte sequence.",26:"Operation in progress.",27:"Interrupted function.",28:"Invalid argument.",29:"I/O error.",30:"Socket is connected.",31:"There is a directory under that path.",32:"Too many levels of symbolic links.",33:"File descriptor value too large.",34:"Too many links.",35:"Message too large.",36:"Reserved.",37:"Filename too long.",38:"Network is down.",39:"Connection aborted by network.",40:"Network unreachable.",41:"Too many files open in system.",42:"No buffer space available.",43:"No such device.",44:"There is no such file or directory OR the parent directory does not exist.",45:"Executable file format error.",46:"No locks available.",47:"Reserved.",48:"Not enough space.",49:"No message of the desired type.",50:"Protocol not available.",51:"No space left on device.",52:"Function not supported.",53:"The socket is not connected.",54:"Not a directory or a symbolic link to a directory.",55:"Directory not empty.",56:"State not recoverable.",57:"Not a socket.",58:"Not supported, or operation not supported on socket.",59:"Inappropriate I/O control operation.",60:"No such device or address.",61:"Value too large to be stored in data type.",62:"Previous owner died.",63:"Operation not permitted.",64:"Broken pipe.",65:"Protocol error.",66:"Protocol not supported.",67:"Protocol wrong type for socket.",68:"Result too large.",69:"Read-only file system.",70:"Invalid seek.",71:"No such process.",72:"Reserved.",73:"Connection timed out.",74:"Text file busy.",75:"Cross-device link.",76:"Extension: Capabilities insufficient."};function m(t=""){return function(n,r,o){const a=o.value;o.value=function(...i){try{return a.apply(this,i)}catch(d){const c=typeof d=="object"?d?.errno:null;if(c in W){const s=W[c],l=typeof i[0]=="string"?i[0]:null,h=l!==null?t.replaceAll("{path}",l):t;throw new Error(`${h}: ${s}`,{cause:d})}throw d}}}}var pe=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,w=(t,e,n,r)=>{for(var o=r>1?void 0:r?fe(e,n):e,a=t.length-1,i;a>=0;a--)(i=t[a])&&(o=(r?i(e,n,o):i(o))||o);return r&&o&&pe(e,n,o),o};const f="string",g="number",G=[];(function(){return typeof window<"u"&&!{}.TEST?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"})();class y{constructor(e,n){this.#t=[],this.#n=!1,e!==void 0&&this.initializeRuntime(e),n&&(this.requestHandler=new se(new ue(this,n)))}#e;#t;#n;initializeRuntime(e){if(this.#e)throw new Error("PHP runtime already initialized.");if(!G[e])throw new Error("Invalid PHP runtime id.");this.#e=G[e]}setPhpIniPath(e){if(this.#n)throw new Error("Cannot set PHP ini path after calling run().");this.#e.ccall("wasm_set_phpini_path",null,["string"],[e])}setPhpIniEntry(e,n){if(this.#n)throw new Error("Cannot set PHP ini entries after calling run().");this.#t.push([e,n])}chdir(e){this.#e.FS.chdir(e)}async request(e,n){if(!this.requestHandler)throw new Error("No request handler available.");return this.requestHandler.request(e,n)}async run(e={}){this.#n||(this.#r(),this.#n=!0),this.#u(e.scriptPath||""),this.#o(e.relativeUri||""),this.#a(e.method||"GET");const{host:n,...r}={host:"example.com:443",...K(e.headers||{})};if(this.#s(n,e.protocol||"http"),this.#l(r),e.body&&this.#c(e.body),e.fileInfos)for(const o of e.fileInfos)this.#d(o);return e.code&&this.#h(" ?>"+e.code),await this.#p()}#r(){if(this.#t.length>0){const e=this.#t.map(([n,r])=>`${n}=${r}`).join(`
|
|
4
|
+
`)+`
|
|
5
|
+
|
|
6
|
+
`;this.#e.ccall("wasm_set_phpini_entries",null,[f],[e])}this.#e.ccall("php_wasm_init",null,[],[])}cli(e){for(const n of e)this.#e.ccall("wasm_add_cli_arg",null,[f],[n]);return this.#e.ccall("run_cli",null,[],[],{async:!0})}#i(){const e="/tmp/headers.json";if(!this.fileExists(e))throw new Error("SAPI Error: Could not find response headers file.");const n=JSON.parse(this.readFileAsText(e)),r={};for(const o of n.headers){if(!o.includes(": "))continue;const a=o.indexOf(": "),i=o.substring(0,a).toLowerCase(),d=o.substring(a+2);i in r||(r[i]=[]),r[i].push(d)}return{headers:r,httpStatusCode:n.status}}#o(e){if(this.#e.ccall("wasm_set_request_uri",null,[f],[e]),e.includes("?")){const n=e.substring(e.indexOf("?")+1);this.#e.ccall("wasm_set_query_string",null,[f],[n])}}#s(e,n){this.#e.ccall("wasm_set_request_host",null,[f],[e]);let r;try{r=parseInt(new URL(e).port,10)}catch{}(!r||isNaN(r)||r===80)&&(r=n==="https"?443:80),this.#e.ccall("wasm_set_request_port",null,[g],[r]),(n==="https"||!n&&r===443)&&this.addServerGlobalEntry("HTTPS","on")}#a(e){this.#e.ccall("wasm_set_request_method",null,[f],[e])}setSkipShebang(e){this.#e.ccall("wasm_set_skip_shebang",null,[g],[e?1:0])}#l(e){e.cookie&&this.#e.ccall("wasm_set_cookies",null,[f],[e.cookie]),e["content-type"]&&this.#e.ccall("wasm_set_content_type",null,[f],[e["content-type"]]),e["content-length"]&&this.#e.ccall("wasm_set_content_length",null,[g],[parseInt(e["content-length"],10)]);for(const n in e)this.addServerGlobalEntry(`HTTP_${n.toUpperCase().replace(/-/g,"_")}`,e[n])}#c(e){this.#e.ccall("wasm_set_request_body",null,[f],[e]),this.#e.ccall("wasm_set_content_length",null,[g],[e.length])}#u(e){this.#e.ccall("wasm_set_path_translated",null,[f],[e])}addServerGlobalEntry(e,n){this.#e.ccall("wasm_add_SERVER_entry",null,[f,f],[e,n])}#d(e){const{key:n,name:r,type:o,data:a}=e,i=`/tmp/${Math.random().toFixed(20)}`;this.writeFile(i,a);const d=0;this.#e.ccall("wasm_add_uploaded_file",null,[f,f,f,f,g,g],[n,r,o,i,d,a.byteLength])}#h(e){this.#e.ccall("wasm_set_php_code",null,[f],[e])}async#p(){const e=await await this.#e.ccall("wasm_sapi_handle_request",g,[],[]),{headers:n,httpStatusCode:r}=this.#i();return new E(r,n,this.readFileAsBuffer("/tmp/stdout"),this.readFileAsText("/tmp/stderr"),e)}mkdir(e){this.#e.FS.mkdirTree(e)}mkdirTree(e){this.mkdir(e)}readFileAsText(e){return new TextDecoder().decode(this.readFileAsBuffer(e))}readFileAsBuffer(e){return this.#e.FS.readFile(e)}writeFile(e,n){this.#e.FS.writeFile(e,n)}unlink(e){this.#e.FS.unlink(e)}listFiles(e){if(!this.fileExists(e))return[];try{return this.#e.FS.readdir(e).filter(n=>n!=="."&&n!=="..")}catch(n){return console.error(n,{path:e}),[]}}isDir(e){return this.fileExists(e)?this.#e.FS.isDir(this.#e.FS.lookupPath(e).node.mode):!1}fileExists(e){try{return this.#e.FS.lookupPath(e),!0}catch{return!1}}mount(e,n){this.#e.FS.mount(this.#e.FS.filesystems.NODEFS,typeof e=="object"?e:{root:e},n)}}w([m('Could not create directory "{path}"')],y.prototype,"mkdir",1);w([m('Could not create directory "{path}"')],y.prototype,"mkdirTree",1);w([m('Could not read "{path}"')],y.prototype,"readFileAsText",1);w([m('Could not read "{path}"')],y.prototype,"readFileAsBuffer",1);w([m('Could not write to "{path}"')],y.prototype,"writeFile",1);w([m('Could not unlink "{path}"')],y.prototype,"unlink",1);w([m('Could not list files in "{path}"')],y.prototype,"listFiles",1);w([m('Could not stat "{path}"')],y.prototype,"isDir",1);w([m('Could not stat "{path}"')],y.prototype,"fileExists",1);w([m("Could not mount a directory")],y.prototype,"mount",1);function K(t){const e={};for(const n in t)e[n.toLowerCase()]=t[n];return e}/**
|
|
7
|
+
* @license
|
|
8
|
+
* Copyright 2019 Google LLC
|
|
9
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
*/const X=Symbol("Comlink.proxy"),me=Symbol("Comlink.endpoint"),we=Symbol("Comlink.releaseProxy"),D=Symbol("Comlink.finalizer"),O=Symbol("Comlink.thrown"),J=t=>typeof t=="object"&&t!==null||typeof t=="function",ye={canHandle:t=>J(t)&&t[X],serialize(t){const{port1:e,port2:n}=new MessageChannel;return H(t,e),[n,[n]]},deserialize(t){return t.start(),N(t)}},ge={canHandle:t=>J(t)&&O in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},S=new Map([["proxy",ye],["throw",ge]]);function be(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function H(t,e=globalThis,n=["*"]){e.addEventListener("message",function r(o){if(!o||!o.data)return;if(!be(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:a,type:i,path:d}=Object.assign({path:[]},o.data),c=(o.data.argumentList||[]).map(b);let s;try{const l=d.slice(0,-1).reduce((u,p)=>u[p],t),h=d.reduce((u,p)=>u[p],t);switch(i){case"GET":s=h;break;case"SET":l[d.slice(-1)[0]]=b(o.data.value),s=!0;break;case"APPLY":s=h.apply(l,c);break;case"CONSTRUCT":{const u=new h(...c);s=$e(u)}break;case"ENDPOINT":{const{port1:u,port2:p}=new MessageChannel;H(t,p),s=Fe(u,[u])}break;case"RELEASE":s=void 0;break;default:return}}catch(l){s={value:l,[O]:0}}Promise.resolve(s).catch(l=>({value:l,[O]:0})).then(l=>{const[h,u]=U(l);e.postMessage(Object.assign(Object.assign({},h),{id:a}),u),i==="RELEASE"&&(e.removeEventListener("message",r),Y(e),D in t&&typeof t[D]=="function"&&t[D]())}).catch(l=>{const[h,u]=U({value:new TypeError("Unserializable return value"),[O]:0});e.postMessage(Object.assign(Object.assign({},h),{id:a}),u)})}),e.start&&e.start()}function ve(t){return t.constructor.name==="MessagePort"}function Y(t){ve(t)&&t.close()}function N(t,e){return I(t,[],e)}function k(t){if(t)throw new Error("Proxy has been released and is not useable")}function Q(t){return P(t,{type:"RELEASE"}).then(()=>{Y(t)})}const A=new WeakMap,L="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(A.get(t)||0)-1;A.set(t,e),e===0&&Q(t)});function Pe(t,e){const n=(A.get(e)||0)+1;A.set(e,n),L&&L.register(t,e,t)}function Ee(t){L&&L.unregister(t)}function I(t,e=[],n=function(){}){let r=!1;const o=new Proxy(n,{get(a,i){if(k(r),i===we)return()=>{Ee(o),Q(t),r=!0};if(i==="then"){if(e.length===0)return{then:()=>o};const d=P(t,{type:"GET",path:e.map(c=>c.toString())}).then(b);return d.then.bind(d)}return I(t,[...e,i])},set(a,i,d){k(r);const[c,s]=U(d);return P(t,{type:"SET",path:[...e,i].map(l=>l.toString()),value:c},s).then(b)},apply(a,i,d){k(r);const c=e[e.length-1];if(c===me)return P(t,{type:"ENDPOINT"}).then(b);if(c==="bind")return I(t,e.slice(0,-1));const[s,l]=V(d);return P(t,{type:"APPLY",path:e.map(h=>h.toString()),argumentList:s},l).then(b)},construct(a,i){k(r);const[d,c]=V(i);return P(t,{type:"CONSTRUCT",path:e.map(s=>s.toString()),argumentList:d},c).then(b)}});return Pe(o,t),o}function xe(t){return Array.prototype.concat.apply([],t)}function V(t){const e=t.map(U);return[e.map(n=>n[0]),xe(e.map(n=>n[1]))]}const ee=new WeakMap;function Fe(t,e){return ee.set(t,e),t}function $e(t){return Object.assign(t,{[X]:!0})}function Te(t,e=globalThis,n="*"){return{postMessage:(r,o)=>t.postMessage(r,n,o),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function U(t){for(const[e,n]of S)if(n.canHandle(t)){const[r,o]=n.serialize(t);return[{type:"HANDLER",name:e,value:r},o]}return[{type:"RAW",value:t},ee.get(t)||[]]}function b(t){switch(t.type){case"HANDLER":return S.get(t.name).deserialize(t.value);case"RAW":return t.value}}function P(t,e,n){return new Promise(r=>{const o=Se();t.addEventListener("message",function a(i){!i.data||!i.data.id||i.data.id!==o||(t.removeEventListener("message",a),r(i.data))}),t.start&&t.start(),t.postMessage(Object.assign({id:o},e),n)})}function Se(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Re(t){_e();const e=t instanceof Worker?t:Te(t);return N(e)}function _e(){S.set("EVENT",{canHandle:t=>t instanceof CustomEvent,serialize:t=>[{detail:t.detail},[]],deserialize:t=>t}),S.set("FUNCTION",{canHandle:t=>typeof t=="function",serialize(t){console.debug("[Comlink][Performance] Proxying a function");const{port1:e,port2:n}=new MessageChannel;return H(t,e),[n,[n]]},deserialize(t){return t.start(),N(t)}}),S.set("PHPResponse",{canHandle:t=>typeof t=="object"&&t!==null&&"headers"in t&&"bytes"in t&&"errors"in t&&"exitCode"in t&&"httpStatusCode"in t,serialize(t){return[t.toRawData(),[]]},deserialize(t){return E.fromRawData(t)}})}(function(){return typeof navigator<"u"&&navigator?.userAgent?.toLowerCase().indexOf("firefox")>-1?"iframe":"webworker"})();var T=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},z={},Ce={get exports(){return z},set exports(t){z=t}};(function(t,e){(function(n,r){r()})(T,function(){function n(s,l){return typeof l>"u"?l={autoBom:!1}:typeof l!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),l={autoBom:!l}),l.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(s.type)?new Blob(["\uFEFF",s],{type:s.type}):s}function r(s,l,h){var u=new XMLHttpRequest;u.open("GET",s),u.responseType="blob",u.onload=function(){c(u.response,l,h)},u.onerror=function(){console.error("could not download file")},u.send()}function o(s){var l=new XMLHttpRequest;l.open("HEAD",s,!1);try{l.send()}catch{}return 200<=l.status&&299>=l.status}function a(s){try{s.dispatchEvent(new MouseEvent("click"))}catch{var l=document.createEvent("MouseEvents");l.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),s.dispatchEvent(l)}}var i=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof T=="object"&&T.global===T?T:void 0,d=i.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),c=i.saveAs||(typeof window!="object"||window!==i?function(){}:"download"in HTMLAnchorElement.prototype&&!d?function(s,l,h){var u=i.URL||i.webkitURL,p=document.createElement("a");l=l||s.name||"download",p.download=l,p.rel="noopener",typeof s=="string"?(p.href=s,p.origin===location.origin?a(p):o(p.href)?r(s,l,h):a(p,p.target="_blank")):(p.href=u.createObjectURL(s),setTimeout(function(){u.revokeObjectURL(p.href)},4e4),setTimeout(function(){a(p)},0))}:"msSaveOrOpenBlob"in navigator?function(s,l,h){if(l=l||s.name||"download",typeof s!="string")navigator.msSaveOrOpenBlob(n(s,h),l);else if(o(s))r(s,l,h);else{var u=document.createElement("a");u.href=s,u.target="_blank",setTimeout(function(){a(u)})}}:function(s,l,h,u){if(u=u||open("","_blank"),u&&(u.document.title=u.document.body.innerText="downloading..."),typeof s=="string")return r(s,l,h);var p=s.type==="application/octet-stream",x=/constructor/i.test(i.HTMLElement)||i.safari,_=/CriOS\/[\d]+/.test(navigator.userAgent);if((_||p&&x||d)&&typeof FileReader<"u"){var F=new FileReader;F.onloadend=function(){var $=F.result;$=_?$:$.replace(/^data:[^;]*;/,"data:attachment/file;"),u?u.location.href=$:location=$,u=null},F.readAsDataURL(s)}else{var C=i.URL||i.webkitURL,v=C.createObjectURL(s);u?u.location=v:location.href=v,u=null,setTimeout(function(){C.revokeObjectURL(v)},4e4)}});i.saveAs=c.saveAs=c,t.exports=c})})(Ce);const M=`<?php
|
|
11
|
+
|
|
12
|
+
function generateZipFile($exportPath, $databasePath, $docRoot) {
|
|
13
|
+
$zip = new ZipArchive;
|
|
14
|
+
$res = $zip->open($exportPath, ZipArchive::CREATE);
|
|
15
|
+
if ($res === TRUE) {
|
|
16
|
+
$zip->addFile($databasePath);
|
|
17
|
+
$directories = array();
|
|
18
|
+
$directories[] = $docRoot . '/';
|
|
19
|
+
|
|
20
|
+
while(sizeof($directories)) {
|
|
21
|
+
$dir = array_pop($directories);
|
|
22
|
+
|
|
23
|
+
if ($handle = opendir($dir)) {
|
|
24
|
+
while (false !== ($entry = readdir($handle))) {
|
|
25
|
+
if ($entry == '.' || $entry == '..') {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
$entry = $dir . $entry;
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
is_dir($entry) &&
|
|
33
|
+
strpos($entry, 'wp-content/database') == false &&
|
|
34
|
+
strpos($entry, 'wp-includes') == false
|
|
35
|
+
) {
|
|
36
|
+
$directory_path = $entry . '/';
|
|
37
|
+
array_push($directories, $directory_path);
|
|
38
|
+
} else if (is_file($entry)) {
|
|
39
|
+
$zip->addFile($entry);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
closedir($handle);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
$zip->close();
|
|
46
|
+
chmod($exportPath, 0777);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readFileFromZipArchive($pathToZip, $pathToFile) {
|
|
51
|
+
chmod($pathToZip, 0777);
|
|
52
|
+
$zip = new ZipArchive;
|
|
53
|
+
$res = $zip->open($pathToZip);
|
|
54
|
+
if ($res === TRUE) {
|
|
55
|
+
$file = $zip->getFromName($pathToFile);
|
|
56
|
+
echo $file;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function importZipFile($pathToZip) {
|
|
61
|
+
$zip = new ZipArchive;
|
|
62
|
+
$res = $zip->open($pathToZip);
|
|
63
|
+
if ($res === TRUE) {
|
|
64
|
+
$counter = 0;
|
|
65
|
+
while ($zip->statIndex($counter)) {
|
|
66
|
+
$file = $zip->statIndex($counter);
|
|
67
|
+
$filePath = $file['name'];
|
|
68
|
+
if (!file_exists(dirname($filePath))) {
|
|
69
|
+
mkdir(dirname($filePath), 0777, true);
|
|
70
|
+
}
|
|
71
|
+
$overwrite = fopen($filePath, 'w');
|
|
72
|
+
fwrite($overwrite, $zip->getFromIndex($counter));
|
|
73
|
+
$counter++;
|
|
74
|
+
}
|
|
75
|
+
$zip->close();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`,te="databaseExport.xml",q="/"+te;async function ke(t){const n=(await t.request({url:"/wp-admin/export.php?download=true&content=all"})).text;await t.writeFile(q,n);const r=await t.wordPressVersion,o=await t.phpVersion,a=await t.documentRoot,i=`wordpress-playground--wp${r}--php${o}.zip`,d=`/${i}`,c=await t.run({code:M+` generateZipFile('${d}', '${q}', '${a}');`});if(c.exitCode!==0)throw c.errors;const s=await t.readFileAsBuffer(i),l=new File([s],i);z.saveAs(l)}async function Oe(t,e){if(!confirm("Are you sure you want to import this file? Previous data will be lost."))return!1;const n=await e.arrayBuffer(),r=new Uint8Array(n),o="/import.zip";await t.writeFile(o,r);const a=await t.run({code:M+` readFileFromZipArchive('${o}', '${q}');`});if(a.exitCode!==0)throw a.errors;const i=new TextDecoder().decode(a.bytes),d=new File([i],te),c=await t.request({url:"/wp-admin/admin.php?import=wordpress"}),l=new DOMParser().parseFromString(c.text,"text/html").getElementById("import-upload-form")?.getAttribute("action"),h=await t.request({url:`/wp-admin/${l}`,method:"POST",files:{import:d}}),p=new DOMParser().parseFromString(h.text,"text/html").querySelector("#wpbody-content form"),x=p?.getAttribute("action"),_=(p?.querySelector("input[name='_wpnonce']")).value,F=(p?.querySelector("input[name='_wp_http_referer']")).value,C=(p?.querySelector("input[name='import_id']")).value;await t.request({url:x,method:"POST",formData:{_wpnonce:_,_wp_http_referer:F,import_id:C}});const v=await t.run({code:M+` importZipFile('${o}');`});if(v.exitCode!==0)throw v.errors;return!0}async function Ae(t,e="admin",n="password"){await t.request({url:"/wp-login.php"}),await t.request({url:"/wp-login.php",method:"POST",formData:{log:e,pwd:n,rememberme:"forever"}})}function R(t){return new DOMParser().parseFromString(t.text,"text/html")}function ne(t){const e=t.split(".").shift().replace("-"," ");return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}async function re(t,e,n={}){const r="activate"in n?n.activate:!0,o=await t.request({url:"/wp-admin/theme-install.php"}),a=R(o),i=new FormData(a.querySelector(".wp-upload-form")),{themezip:d,...c}=Object.fromEntries(i.entries()),s=await t.request({url:"/wp-admin/update.php?action=upload-theme",method:"POST",formData:c,files:{themezip:e}});if(r){const l=R(s),h=l.querySelector("#wpbody-content > .wrap");if(h?.textContent?.includes("Theme installation failed.")){console.error(h?.textContent);return}const u=l.querySelector("#wpbody-content .activatelink, .update-from-upload-actions .button.button-primary");if(!u){console.error('The "activate" button was not found.');return}const p=u.attributes.getNamedItem("href").value,x=new URL(p,await t.pathToInternalUrl("/wp-admin/")).toString();await t.request({url:x})}}async function oe(t,e,n={}){const r="activate"in n?n.activate:!0,o=await t.request({url:"/wp-admin/plugin-install.php?tab=upload"}),a=R(o),i=new FormData(a.querySelector(".wp-upload-form")),{pluginzip:d,...c}=Object.fromEntries(i.entries()),s=await t.request({url:"/wp-admin/update.php?action=upload-plugin",method:"POST",formData:c,files:{pluginzip:e}});if(r){const u=R(s).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value,p=new URL(u,await t.pathToInternalUrl("/wp-admin/")).toString();await t.request({url:p})}async function l(h,u){return await t.writeFile(h,u(await t.readFileAsText(h)))}await t.isDir("/wordpress/wp-content/plugins/gutenberg")&&!await t.fileExists("/wordpress/.gutenberg-patched")&&(await t.writeFile("/wordpress/.gutenberg-patched","1"),await l("/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.js",h=>h.replace(/srcDoc:("[^"]+"|[^,]+)/g,'src:"/wp-includes/empty.html"')),await l("/wordpress/wp-content/plugins/gutenberg/build/block-editor/index.min.js",h=>h.replace(/srcDoc:("[^"]+"|[^,]+)/g,'src:"/wp-includes/empty.html"')))}async function Le(t,e){const o=R(await t.request({url:"/wp-admin/plugins.php"})).querySelector(`tr[data-slug="${e}"] a`).attributes.getNamedItem("href").value;await t.request({url:"/wp-admin/"+o})}const Ue=5*1024*1024;function ie(t,e){const n=t.headers.get("content-length")||"",r=parseInt(n,10)||Ue;function o(a,i){e(new CustomEvent("progress",{detail:{loaded:a,total:i}}))}return new Response(new ReadableStream({async start(a){if(!t.body){a.close();return}const i=t.body.getReader();let d=0;for(;;)try{const{done:c,value:s}=await i.read();if(s&&(d+=s.byteLength),c){o(d,d),a.close();break}else o(d,r),a.enqueue(s)}catch(c){console.error({e:c}),a.error(c);break}}}),{status:t.status,statusText:t.statusText,headers:t.headers})}async function De(t,e,n=100,r){let o=await fetch("/plugin-proxy?theme="+e);if(r&&(o=ie(o,r.partialObserver(n/2,`Installing ${ne(e)} theme...`)),r.slowlyIncrementBy(n/2)),o.status===200){const a=new File([await o.blob()],e);try{await re(t,a)}catch(i){console.error(`Proceeding without the ${e} theme. Could not install it in wp-admin. The original error was: ${i}`),console.error(i)}}else console.error(`Proceeding without the ${e} theme. Could not download the zip bundle from https://downloads.wordpress.org/themes/${e} – Is the file name correct?`)}async function Ie(t,e,n=100,r){const o=new Z,a=new Z,i=n/e.length;await new Promise(d=>{for(const c of e)o.enqueue(async()=>{let s=await fetch("/plugin-proxy?plugin="+c);return r&&(s=ie(s,r.partialObserver(i*.66,`Installing ${ne(c)} plugin...`))),s.status!==200?(console.error(`Proceeding without the ${c} plugin. Could not download the zip bundle from https://downloads.wordpress.org/plugin/${c} – Is the file name correct?`),null):new File([await s.blob()],c)});o.addEventListener("resolved",c=>{a.enqueue(async()=>{if(c.detail){r?.slowlyIncrementBy(i*.33);try{await oe(t,c.detail)}catch(s){console.error(`Proceeding without the ${c.detail.name} plugin. Could not install it in wp-admin. The original error was: ${s}`),console.error(s)}}})}),a.addEventListener("empty",()=>{a.resolved===e.length&&d(null)})})}class Z extends EventTarget{#e=[];#t=!1;#n=0;get resolved(){return this.#n}async enqueue(e){this.#e.push(e),this.#r()}async#r(){if(!this.#t)try{for(this.#t=!0;this.#e.length;){const e=this.#e.shift();if(!e)break;const n=await e();++this.#n,this.dispatchEvent(new CustomEvent("resolved",{detail:n}))}}finally{this.#t=!1,this.dispatchEvent(new CustomEvent("empty"))}}}async function ze(t,e){e?.loadRemote&&(t.src=e?.loadRemote,await new Promise(r=>{t.addEventListener("load",r,!1)}));const n=Re(t.contentWindow);return await n.absoluteUrl,n}exports.activatePlugin=Le;exports.connectPlayground=ze;exports.exportFile=ke;exports.importFile=Oe;exports.installPlugin=oe;exports.installPluginsFromDirectory=Ie;exports.installTheme=re;exports.installThemeFromDirectory=De;exports.login=Ae;
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class oe {
|
|
2
2
|
#e;
|
|
3
3
|
#t;
|
|
4
4
|
/**
|
|
@@ -68,17 +68,17 @@ class re {
|
|
|
68
68
|
return e.join("; ");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
const
|
|
71
|
+
const ie = "http://example.com";
|
|
72
72
|
function j(t) {
|
|
73
73
|
return t.toString().substring(t.origin.length);
|
|
74
74
|
}
|
|
75
75
|
function B(t, e) {
|
|
76
76
|
return !e || !t.startsWith(e) ? t : t.substring(e.length);
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function se(t, e) {
|
|
79
79
|
return !e || t.startsWith(e) ? t : e + t;
|
|
80
80
|
}
|
|
81
|
-
class
|
|
81
|
+
class ae {
|
|
82
82
|
constructor({ concurrency: e }) {
|
|
83
83
|
this._running = 0, this.concurrency = e, this.queue = [];
|
|
84
84
|
}
|
|
@@ -130,7 +130,7 @@ class E {
|
|
|
130
130
|
return new TextDecoder().decode(this.bytes);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
class
|
|
133
|
+
class le {
|
|
134
134
|
#e;
|
|
135
135
|
#t;
|
|
136
136
|
#n;
|
|
@@ -145,7 +145,7 @@ class ae {
|
|
|
145
145
|
* @param config - Request Handler configuration.
|
|
146
146
|
*/
|
|
147
147
|
constructor(e, n = {}) {
|
|
148
|
-
this.#a = new
|
|
148
|
+
this.#a = new ae({ concurrency: 1 });
|
|
149
149
|
const {
|
|
150
150
|
documentRoot: r = "/www/",
|
|
151
151
|
absoluteUrl: o = typeof location == "object" ? location?.href : "",
|
|
@@ -210,7 +210,7 @@ class ae {
|
|
|
210
210
|
async request(e) {
|
|
211
211
|
const n = e.url.startsWith("http://") || e.url.startsWith("https://"), r = new URL(
|
|
212
212
|
e.url,
|
|
213
|
-
n ? void 0 :
|
|
213
|
+
n ? void 0 : ie
|
|
214
214
|
), o = B(
|
|
215
215
|
r.pathname,
|
|
216
216
|
this.#o
|
|
@@ -239,7 +239,7 @@ class ae {
|
|
|
239
239
|
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
240
240
|
// The code below won't return the correct mime-type if the extension
|
|
241
241
|
// was tampered with.
|
|
242
|
-
"content-type": [
|
|
242
|
+
"content-type": [ue(n)],
|
|
243
243
|
"accept-ranges": ["bytes"],
|
|
244
244
|
"cache-control": ["public, max-age=0"]
|
|
245
245
|
},
|
|
@@ -261,39 +261,39 @@ class ae {
|
|
|
261
261
|
this.#s.startsWith("https://") ? "on" : ""
|
|
262
262
|
);
|
|
263
263
|
let o = "GET";
|
|
264
|
-
const a =
|
|
265
|
-
|
|
264
|
+
const a = {
|
|
265
|
+
host: this.#i,
|
|
266
|
+
...K(e.headers || {})
|
|
267
|
+
}, i = [];
|
|
268
|
+
if (e.files && Object.keys(e.files).length) {
|
|
266
269
|
o = "POST";
|
|
267
270
|
for (const c in e.files) {
|
|
268
271
|
const s = e.files[c];
|
|
269
|
-
|
|
272
|
+
i.push({
|
|
270
273
|
key: c,
|
|
271
274
|
name: s.name,
|
|
272
275
|
type: s.type,
|
|
273
276
|
data: new Uint8Array(await s.arrayBuffer())
|
|
274
277
|
});
|
|
275
278
|
}
|
|
279
|
+
a["content-type"]?.startsWith("multipart/form-data") && (e.formData = ce(
|
|
280
|
+
e.body || ""
|
|
281
|
+
), a["content-type"] = "application/x-www-form-urlencoded", delete e.body);
|
|
276
282
|
}
|
|
277
|
-
const i = {
|
|
278
|
-
host: this.#i
|
|
279
|
-
};
|
|
280
283
|
let d;
|
|
281
|
-
return e.formData !== void 0 ? (o = "POST",
|
|
284
|
+
return e.formData !== void 0 ? (o = "POST", a["content-type"] = a["content-type"] || "application/x-www-form-urlencoded", d = new URLSearchParams(
|
|
282
285
|
e.formData
|
|
283
286
|
).toString()) : d = e.body, await this.php.run({
|
|
284
|
-
relativeUri:
|
|
287
|
+
relativeUri: se(
|
|
285
288
|
j(n),
|
|
286
289
|
this.#o
|
|
287
290
|
),
|
|
288
291
|
protocol: this.#t,
|
|
289
292
|
method: e.method || o,
|
|
290
293
|
body: d,
|
|
291
|
-
fileInfos:
|
|
294
|
+
fileInfos: i,
|
|
292
295
|
scriptPath: this.#d(n.pathname),
|
|
293
|
-
headers:
|
|
294
|
-
...i,
|
|
295
|
-
...e.headers || {}
|
|
296
|
-
}
|
|
296
|
+
headers: a
|
|
297
297
|
});
|
|
298
298
|
} finally {
|
|
299
299
|
r();
|
|
@@ -314,7 +314,22 @@ class ae {
|
|
|
314
314
|
return this.php.fileExists(r) ? r : `${this.#e}/index.php`;
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
-
function
|
|
317
|
+
function ce(t) {
|
|
318
|
+
const e = {}, n = t.match(/--(.*)\r\n/);
|
|
319
|
+
if (!n)
|
|
320
|
+
return e;
|
|
321
|
+
const r = n[1], o = t.split(`--${r}`);
|
|
322
|
+
return o.shift(), o.pop(), o.forEach((a) => {
|
|
323
|
+
const i = a.indexOf(`\r
|
|
324
|
+
\r
|
|
325
|
+
`), d = a.substring(0, i).trim(), c = a.substring(i + 4).trim(), s = d.match(/name="([^"]+)"/);
|
|
326
|
+
if (s) {
|
|
327
|
+
const l = s[1];
|
|
328
|
+
e[l] = c;
|
|
329
|
+
}
|
|
330
|
+
}), e;
|
|
331
|
+
}
|
|
332
|
+
function ue(t) {
|
|
318
333
|
switch (t.split(".").pop()) {
|
|
319
334
|
case "css":
|
|
320
335
|
return "text/css";
|
|
@@ -452,16 +467,16 @@ function m(t = "") {
|
|
|
452
467
|
};
|
|
453
468
|
};
|
|
454
469
|
}
|
|
455
|
-
var
|
|
456
|
-
for (var o = r > 1 ? void 0 : r ?
|
|
470
|
+
var de = Object.defineProperty, he = Object.getOwnPropertyDescriptor, w = (t, e, n, r) => {
|
|
471
|
+
for (var o = r > 1 ? void 0 : r ? he(e, n) : e, a = t.length - 1, i; a >= 0; a--)
|
|
457
472
|
(i = t[a]) && (o = (r ? i(e, n, o) : i(o)) || o);
|
|
458
|
-
return r && o &&
|
|
473
|
+
return r && o && de(e, n, o), o;
|
|
459
474
|
};
|
|
460
|
-
const f = "string",
|
|
475
|
+
const f = "string", g = "number", G = [];
|
|
461
476
|
(function() {
|
|
462
477
|
return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
463
478
|
})();
|
|
464
|
-
class
|
|
479
|
+
class y {
|
|
465
480
|
/**
|
|
466
481
|
* Initializes a PHP runtime.
|
|
467
482
|
*
|
|
@@ -470,8 +485,8 @@ class g {
|
|
|
470
485
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
471
486
|
*/
|
|
472
487
|
constructor(e, n) {
|
|
473
|
-
this.#t = [], this.#n = !1, e !== void 0 && this.initializeRuntime(e), n && (this.requestHandler = new
|
|
474
|
-
new
|
|
488
|
+
this.#t = [], this.#n = !1, e !== void 0 && this.initializeRuntime(e), n && (this.requestHandler = new oe(
|
|
489
|
+
new le(this, n)
|
|
475
490
|
));
|
|
476
491
|
}
|
|
477
492
|
#e;
|
|
@@ -511,7 +526,7 @@ class g {
|
|
|
511
526
|
this.#n || (this.#r(), this.#n = !0), this.#u(e.scriptPath || ""), this.#o(e.relativeUri || ""), this.#a(e.method || "GET");
|
|
512
527
|
const { host: n, ...r } = {
|
|
513
528
|
host: "example.com:443",
|
|
514
|
-
...
|
|
529
|
+
...K(e.headers || {})
|
|
515
530
|
};
|
|
516
531
|
if (this.#s(n, e.protocol || "http"), this.#l(r), e.body && this.#c(e.body), e.fileInfos)
|
|
517
532
|
for (const o of e.fileInfos)
|
|
@@ -574,7 +589,7 @@ class g {
|
|
|
574
589
|
r = parseInt(new URL(e).port, 10);
|
|
575
590
|
} catch {
|
|
576
591
|
}
|
|
577
|
-
(!r || isNaN(r) || r === 80) && (r = n === "https" ? 443 : 80), this.#e.ccall("wasm_set_request_port", null, [
|
|
592
|
+
(!r || isNaN(r) || r === 80) && (r = n === "https" ? 443 : 80), this.#e.ccall("wasm_set_request_port", null, [g], [r]), (n === "https" || !n && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
578
593
|
}
|
|
579
594
|
#a(e) {
|
|
580
595
|
this.#e.ccall("wasm_set_request_method", null, [f], [e]);
|
|
@@ -583,7 +598,7 @@ class g {
|
|
|
583
598
|
this.#e.ccall(
|
|
584
599
|
"wasm_set_skip_shebang",
|
|
585
600
|
null,
|
|
586
|
-
[
|
|
601
|
+
[g],
|
|
587
602
|
[e ? 1 : 0]
|
|
588
603
|
);
|
|
589
604
|
}
|
|
@@ -601,7 +616,7 @@ class g {
|
|
|
601
616
|
), e["content-length"] && this.#e.ccall(
|
|
602
617
|
"wasm_set_content_length",
|
|
603
618
|
null,
|
|
604
|
-
[
|
|
619
|
+
[g],
|
|
605
620
|
[parseInt(e["content-length"], 10)]
|
|
606
621
|
);
|
|
607
622
|
for (const n in e)
|
|
@@ -614,7 +629,7 @@ class g {
|
|
|
614
629
|
this.#e.ccall("wasm_set_request_body", null, [f], [e]), this.#e.ccall(
|
|
615
630
|
"wasm_set_content_length",
|
|
616
631
|
null,
|
|
617
|
-
[
|
|
632
|
+
[g],
|
|
618
633
|
[e.length]
|
|
619
634
|
);
|
|
620
635
|
}
|
|
@@ -645,7 +660,7 @@ class g {
|
|
|
645
660
|
this.#e.ccall(
|
|
646
661
|
"wasm_add_uploaded_file",
|
|
647
662
|
null,
|
|
648
|
-
[f, f, f, f,
|
|
663
|
+
[f, f, f, f, g, g],
|
|
649
664
|
[n, r, o, i, d, a.byteLength]
|
|
650
665
|
);
|
|
651
666
|
}
|
|
@@ -655,7 +670,7 @@ class g {
|
|
|
655
670
|
async #p() {
|
|
656
671
|
const e = await await this.#e.ccall(
|
|
657
672
|
"wasm_sapi_handle_request",
|
|
658
|
-
|
|
673
|
+
g,
|
|
659
674
|
[],
|
|
660
675
|
[]
|
|
661
676
|
), { headers: n, httpStatusCode: r } = this.#i();
|
|
@@ -718,35 +733,35 @@ class g {
|
|
|
718
733
|
}
|
|
719
734
|
w([
|
|
720
735
|
m('Could not create directory "{path}"')
|
|
721
|
-
],
|
|
736
|
+
], y.prototype, "mkdir", 1);
|
|
722
737
|
w([
|
|
723
738
|
m('Could not create directory "{path}"')
|
|
724
|
-
],
|
|
739
|
+
], y.prototype, "mkdirTree", 1);
|
|
725
740
|
w([
|
|
726
741
|
m('Could not read "{path}"')
|
|
727
|
-
],
|
|
742
|
+
], y.prototype, "readFileAsText", 1);
|
|
728
743
|
w([
|
|
729
744
|
m('Could not read "{path}"')
|
|
730
|
-
],
|
|
745
|
+
], y.prototype, "readFileAsBuffer", 1);
|
|
731
746
|
w([
|
|
732
747
|
m('Could not write to "{path}"')
|
|
733
|
-
],
|
|
748
|
+
], y.prototype, "writeFile", 1);
|
|
734
749
|
w([
|
|
735
750
|
m('Could not unlink "{path}"')
|
|
736
|
-
],
|
|
751
|
+
], y.prototype, "unlink", 1);
|
|
737
752
|
w([
|
|
738
753
|
m('Could not list files in "{path}"')
|
|
739
|
-
],
|
|
754
|
+
], y.prototype, "listFiles", 1);
|
|
740
755
|
w([
|
|
741
756
|
m('Could not stat "{path}"')
|
|
742
|
-
],
|
|
757
|
+
], y.prototype, "isDir", 1);
|
|
743
758
|
w([
|
|
744
759
|
m('Could not stat "{path}"')
|
|
745
|
-
],
|
|
760
|
+
], y.prototype, "fileExists", 1);
|
|
746
761
|
w([
|
|
747
762
|
m("Could not mount a directory")
|
|
748
|
-
],
|
|
749
|
-
function
|
|
763
|
+
], y.prototype, "mount", 1);
|
|
764
|
+
function K(t) {
|
|
750
765
|
const e = {};
|
|
751
766
|
for (const n in t)
|
|
752
767
|
e[n.toLowerCase()] = t[n];
|
|
@@ -757,17 +772,17 @@ function de(t) {
|
|
|
757
772
|
* Copyright 2019 Google LLC
|
|
758
773
|
* SPDX-License-Identifier: Apache-2.0
|
|
759
774
|
*/
|
|
760
|
-
const
|
|
761
|
-
canHandle: (t) =>
|
|
775
|
+
const X = Symbol("Comlink.proxy"), pe = Symbol("Comlink.endpoint"), fe = Symbol("Comlink.releaseProxy"), D = Symbol("Comlink.finalizer"), O = Symbol("Comlink.thrown"), J = (t) => typeof t == "object" && t !== null || typeof t == "function", me = {
|
|
776
|
+
canHandle: (t) => J(t) && t[X],
|
|
762
777
|
serialize(t) {
|
|
763
778
|
const { port1: e, port2: n } = new MessageChannel();
|
|
764
|
-
return
|
|
779
|
+
return M(t, e), [n, [n]];
|
|
765
780
|
},
|
|
766
781
|
deserialize(t) {
|
|
767
|
-
return t.start(),
|
|
782
|
+
return t.start(), N(t);
|
|
768
783
|
}
|
|
769
|
-
},
|
|
770
|
-
canHandle: (t) =>
|
|
784
|
+
}, we = {
|
|
785
|
+
canHandle: (t) => J(t) && O in t,
|
|
771
786
|
serialize({ value: t }) {
|
|
772
787
|
let e;
|
|
773
788
|
return t instanceof Error ? e = {
|
|
@@ -782,21 +797,21 @@ const K = Symbol("Comlink.proxy"), he = Symbol("Comlink.endpoint"), pe = Symbol(
|
|
|
782
797
|
deserialize(t) {
|
|
783
798
|
throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
|
|
784
799
|
}
|
|
785
|
-
},
|
|
786
|
-
["proxy",
|
|
787
|
-
["throw",
|
|
800
|
+
}, T = /* @__PURE__ */ new Map([
|
|
801
|
+
["proxy", me],
|
|
802
|
+
["throw", we]
|
|
788
803
|
]);
|
|
789
|
-
function
|
|
804
|
+
function ye(t, e) {
|
|
790
805
|
for (const n of t)
|
|
791
806
|
if (e === n || n === "*" || n instanceof RegExp && n.test(e))
|
|
792
807
|
return !0;
|
|
793
808
|
return !1;
|
|
794
809
|
}
|
|
795
|
-
function
|
|
810
|
+
function M(t, e = globalThis, n = ["*"]) {
|
|
796
811
|
e.addEventListener("message", function r(o) {
|
|
797
812
|
if (!o || !o.data)
|
|
798
813
|
return;
|
|
799
|
-
if (!
|
|
814
|
+
if (!ye(n, o.origin)) {
|
|
800
815
|
console.warn(`Invalid origin '${o.origin}' for comlink proxy`);
|
|
801
816
|
return;
|
|
802
817
|
}
|
|
@@ -817,13 +832,13 @@ function N(t, e = globalThis, n = ["*"]) {
|
|
|
817
832
|
case "CONSTRUCT":
|
|
818
833
|
{
|
|
819
834
|
const u = new h(...c);
|
|
820
|
-
s =
|
|
835
|
+
s = xe(u);
|
|
821
836
|
}
|
|
822
837
|
break;
|
|
823
838
|
case "ENDPOINT":
|
|
824
839
|
{
|
|
825
840
|
const { port1: u, port2: p } = new MessageChannel();
|
|
826
|
-
|
|
841
|
+
M(t, p), s = Ee(u, [u]);
|
|
827
842
|
}
|
|
828
843
|
break;
|
|
829
844
|
case "RELEASE":
|
|
@@ -837,7 +852,7 @@ function N(t, e = globalThis, n = ["*"]) {
|
|
|
837
852
|
}
|
|
838
853
|
Promise.resolve(s).catch((l) => ({ value: l, [O]: 0 })).then((l) => {
|
|
839
854
|
const [h, u] = U(l);
|
|
840
|
-
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u), i === "RELEASE" && (e.removeEventListener("message", r),
|
|
855
|
+
e.postMessage(Object.assign(Object.assign({}, h), { id: a }), u), i === "RELEASE" && (e.removeEventListener("message", r), Y(e), D in t && typeof t[D] == "function" && t[D]());
|
|
841
856
|
}).catch((l) => {
|
|
842
857
|
const [h, u] = U({
|
|
843
858
|
value: new TypeError("Unserializable return value"),
|
|
@@ -850,42 +865,42 @@ function N(t, e = globalThis, n = ["*"]) {
|
|
|
850
865
|
function ge(t) {
|
|
851
866
|
return t.constructor.name === "MessagePort";
|
|
852
867
|
}
|
|
853
|
-
function
|
|
868
|
+
function Y(t) {
|
|
854
869
|
ge(t) && t.close();
|
|
855
870
|
}
|
|
856
|
-
function
|
|
857
|
-
return
|
|
871
|
+
function N(t, e) {
|
|
872
|
+
return I(t, [], e);
|
|
858
873
|
}
|
|
859
874
|
function k(t) {
|
|
860
875
|
if (t)
|
|
861
876
|
throw new Error("Proxy has been released and is not useable");
|
|
862
877
|
}
|
|
863
|
-
function
|
|
878
|
+
function Q(t) {
|
|
864
879
|
return P(t, {
|
|
865
880
|
type: "RELEASE"
|
|
866
881
|
}).then(() => {
|
|
867
|
-
|
|
882
|
+
Y(t);
|
|
868
883
|
});
|
|
869
884
|
}
|
|
870
885
|
const A = /* @__PURE__ */ new WeakMap(), L = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
|
|
871
886
|
const e = (A.get(t) || 0) - 1;
|
|
872
|
-
A.set(t, e), e === 0 &&
|
|
887
|
+
A.set(t, e), e === 0 && Q(t);
|
|
873
888
|
});
|
|
874
|
-
function
|
|
889
|
+
function be(t, e) {
|
|
875
890
|
const n = (A.get(e) || 0) + 1;
|
|
876
891
|
A.set(e, n), L && L.register(t, e, t);
|
|
877
892
|
}
|
|
878
|
-
function
|
|
893
|
+
function ve(t) {
|
|
879
894
|
L && L.unregister(t);
|
|
880
895
|
}
|
|
881
|
-
function
|
|
896
|
+
function I(t, e = [], n = function() {
|
|
882
897
|
}) {
|
|
883
898
|
let r = !1;
|
|
884
899
|
const o = new Proxy(n, {
|
|
885
900
|
get(a, i) {
|
|
886
|
-
if (k(r), i ===
|
|
901
|
+
if (k(r), i === fe)
|
|
887
902
|
return () => {
|
|
888
|
-
|
|
903
|
+
ve(o), Q(t), r = !0;
|
|
889
904
|
};
|
|
890
905
|
if (i === "then") {
|
|
891
906
|
if (e.length === 0)
|
|
@@ -896,7 +911,7 @@ function D(t, e = [], n = function() {
|
|
|
896
911
|
}).then(b);
|
|
897
912
|
return d.then.bind(d);
|
|
898
913
|
}
|
|
899
|
-
return
|
|
914
|
+
return I(t, [...e, i]);
|
|
900
915
|
},
|
|
901
916
|
set(a, i, d) {
|
|
902
917
|
k(r);
|
|
@@ -910,12 +925,12 @@ function D(t, e = [], n = function() {
|
|
|
910
925
|
apply(a, i, d) {
|
|
911
926
|
k(r);
|
|
912
927
|
const c = e[e.length - 1];
|
|
913
|
-
if (c ===
|
|
928
|
+
if (c === pe)
|
|
914
929
|
return P(t, {
|
|
915
930
|
type: "ENDPOINT"
|
|
916
931
|
}).then(b);
|
|
917
932
|
if (c === "bind")
|
|
918
|
-
return
|
|
933
|
+
return I(t, e.slice(0, -1));
|
|
919
934
|
const [s, l] = V(d);
|
|
920
935
|
return P(t, {
|
|
921
936
|
type: "APPLY",
|
|
@@ -933,23 +948,23 @@ function D(t, e = [], n = function() {
|
|
|
933
948
|
}, c).then(b);
|
|
934
949
|
}
|
|
935
950
|
});
|
|
936
|
-
return
|
|
951
|
+
return be(o, t), o;
|
|
937
952
|
}
|
|
938
|
-
function
|
|
953
|
+
function Pe(t) {
|
|
939
954
|
return Array.prototype.concat.apply([], t);
|
|
940
955
|
}
|
|
941
956
|
function V(t) {
|
|
942
957
|
const e = t.map(U);
|
|
943
|
-
return [e.map((n) => n[0]),
|
|
958
|
+
return [e.map((n) => n[0]), Pe(e.map((n) => n[1]))];
|
|
944
959
|
}
|
|
945
|
-
const
|
|
946
|
-
function
|
|
947
|
-
return
|
|
960
|
+
const ee = /* @__PURE__ */ new WeakMap();
|
|
961
|
+
function Ee(t, e) {
|
|
962
|
+
return ee.set(t, e), t;
|
|
948
963
|
}
|
|
949
|
-
function
|
|
950
|
-
return Object.assign(t, { [
|
|
964
|
+
function xe(t) {
|
|
965
|
+
return Object.assign(t, { [X]: !0 });
|
|
951
966
|
}
|
|
952
|
-
function
|
|
967
|
+
function $e(t, e = globalThis, n = "*") {
|
|
953
968
|
return {
|
|
954
969
|
postMessage: (r, o) => t.postMessage(r, n, o),
|
|
955
970
|
addEventListener: e.addEventListener.bind(e),
|
|
@@ -957,7 +972,7 @@ function xe(t, e = globalThis, n = "*") {
|
|
|
957
972
|
};
|
|
958
973
|
}
|
|
959
974
|
function U(t) {
|
|
960
|
-
for (const [e, n] of
|
|
975
|
+
for (const [e, n] of T)
|
|
961
976
|
if (n.canHandle(t)) {
|
|
962
977
|
const [r, o] = n.serialize(t);
|
|
963
978
|
return [
|
|
@@ -974,35 +989,35 @@ function U(t) {
|
|
|
974
989
|
type: "RAW",
|
|
975
990
|
value: t
|
|
976
991
|
},
|
|
977
|
-
|
|
992
|
+
ee.get(t) || []
|
|
978
993
|
];
|
|
979
994
|
}
|
|
980
995
|
function b(t) {
|
|
981
996
|
switch (t.type) {
|
|
982
997
|
case "HANDLER":
|
|
983
|
-
return
|
|
998
|
+
return T.get(t.name).deserialize(t.value);
|
|
984
999
|
case "RAW":
|
|
985
1000
|
return t.value;
|
|
986
1001
|
}
|
|
987
1002
|
}
|
|
988
1003
|
function P(t, e, n) {
|
|
989
1004
|
return new Promise((r) => {
|
|
990
|
-
const o =
|
|
1005
|
+
const o = Fe();
|
|
991
1006
|
t.addEventListener("message", function a(i) {
|
|
992
1007
|
!i.data || !i.data.id || i.data.id !== o || (t.removeEventListener("message", a), r(i.data));
|
|
993
1008
|
}), t.start && t.start(), t.postMessage(Object.assign({ id: o }, e), n);
|
|
994
1009
|
});
|
|
995
1010
|
}
|
|
996
|
-
function
|
|
1011
|
+
function Fe() {
|
|
997
1012
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
998
1013
|
}
|
|
999
|
-
function
|
|
1014
|
+
function Se(t) {
|
|
1000
1015
|
Te();
|
|
1001
|
-
const e = t instanceof Worker ? t :
|
|
1002
|
-
return
|
|
1016
|
+
const e = t instanceof Worker ? t : $e(t);
|
|
1017
|
+
return N(e);
|
|
1003
1018
|
}
|
|
1004
1019
|
function Te() {
|
|
1005
|
-
|
|
1020
|
+
T.set("EVENT", {
|
|
1006
1021
|
canHandle: (t) => t instanceof CustomEvent,
|
|
1007
1022
|
serialize: (t) => [
|
|
1008
1023
|
{
|
|
@@ -1011,17 +1026,17 @@ function Te() {
|
|
|
1011
1026
|
[]
|
|
1012
1027
|
],
|
|
1013
1028
|
deserialize: (t) => t
|
|
1014
|
-
}),
|
|
1029
|
+
}), T.set("FUNCTION", {
|
|
1015
1030
|
canHandle: (t) => typeof t == "function",
|
|
1016
1031
|
serialize(t) {
|
|
1017
1032
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
1018
1033
|
const { port1: e, port2: n } = new MessageChannel();
|
|
1019
|
-
return
|
|
1034
|
+
return M(t, e), [n, [n]];
|
|
1020
1035
|
},
|
|
1021
1036
|
deserialize(t) {
|
|
1022
|
-
return t.start(),
|
|
1037
|
+
return t.start(), N(t);
|
|
1023
1038
|
}
|
|
1024
|
-
}),
|
|
1039
|
+
}), T.set("PHPResponse", {
|
|
1025
1040
|
canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
|
|
1026
1041
|
serialize(t) {
|
|
1027
1042
|
return [t.toRawData(), []];
|
|
@@ -1032,20 +1047,20 @@ function Te() {
|
|
|
1032
1047
|
});
|
|
1033
1048
|
}
|
|
1034
1049
|
(function() {
|
|
1035
|
-
return navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
|
|
1050
|
+
return typeof navigator < "u" && navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
|
|
1036
1051
|
})();
|
|
1037
|
-
var
|
|
1052
|
+
var S = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, z = {}, Re = {
|
|
1038
1053
|
get exports() {
|
|
1039
|
-
return
|
|
1054
|
+
return z;
|
|
1040
1055
|
},
|
|
1041
1056
|
set exports(t) {
|
|
1042
|
-
|
|
1057
|
+
z = t;
|
|
1043
1058
|
}
|
|
1044
1059
|
};
|
|
1045
1060
|
(function(t, e) {
|
|
1046
1061
|
(function(n, r) {
|
|
1047
1062
|
r();
|
|
1048
|
-
})(
|
|
1063
|
+
})(S, function() {
|
|
1049
1064
|
function n(s, l) {
|
|
1050
1065
|
return typeof l > "u" ? l = { autoBom: !1 } : typeof l != "object" && (console.warn("Deprecated: Expected third argument to be a object"), l = { autoBom: !l }), l.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(s.type) ? new Blob(["\uFEFF", s], { type: s.type }) : s;
|
|
1051
1066
|
}
|
|
@@ -1074,7 +1089,7 @@ var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1074
1089
|
l.initMouseEvent("click", !0, !0, window, 0, 0, 0, 80, 20, !1, !1, !1, !1, 0, null), s.dispatchEvent(l);
|
|
1075
1090
|
}
|
|
1076
1091
|
}
|
|
1077
|
-
var i = typeof window == "object" && window.window === window ? window : typeof self == "object" && self.self === self ? self : typeof
|
|
1092
|
+
var i = typeof window == "object" && window.window === window ? window : typeof self == "object" && self.self === self ? self : typeof S == "object" && S.global === S ? S : void 0, d = i.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent), c = i.saveAs || (typeof window != "object" || window !== i ? function() {
|
|
1078
1093
|
} : "download" in HTMLAnchorElement.prototype && !d ? function(s, l, h) {
|
|
1079
1094
|
var u = i.URL || i.webkitURL, p = document.createElement("a");
|
|
1080
1095
|
l = l || s.name || "download", p.download = l, p.rel = "noopener", typeof s == "string" ? (p.href = s, p.origin === location.origin ? a(p) : o(p.href) ? r(s, l, h) : a(p, p.target = "_blank")) : (p.href = u.createObjectURL(s), setTimeout(function() {
|
|
@@ -1113,7 +1128,7 @@ var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : ty
|
|
|
1113
1128
|
i.saveAs = c.saveAs = c, t.exports = c;
|
|
1114
1129
|
});
|
|
1115
1130
|
})(Re);
|
|
1116
|
-
const
|
|
1131
|
+
const q = `<?php
|
|
1117
1132
|
|
|
1118
1133
|
function generateZipFile($exportPath, $databasePath, $docRoot) {
|
|
1119
1134
|
$zip = new ZipArchive;
|
|
@@ -1181,21 +1196,21 @@ function importZipFile($pathToZip) {
|
|
|
1181
1196
|
$zip->close();
|
|
1182
1197
|
}
|
|
1183
1198
|
}
|
|
1184
|
-
`,
|
|
1185
|
-
async function
|
|
1199
|
+
`, te = "databaseExport.xml", H = "/" + te;
|
|
1200
|
+
async function Oe(t) {
|
|
1186
1201
|
const n = (await t.request({
|
|
1187
1202
|
url: "/wp-admin/export.php?download=true&content=all"
|
|
1188
1203
|
})).text;
|
|
1189
1204
|
await t.writeFile(H, n);
|
|
1190
1205
|
const r = await t.wordPressVersion, o = await t.phpVersion, a = await t.documentRoot, i = `wordpress-playground--wp${r}--php${o}.zip`, d = `/${i}`, c = await t.run({
|
|
1191
|
-
code:
|
|
1206
|
+
code: q + ` generateZipFile('${d}', '${H}', '${a}');`
|
|
1192
1207
|
});
|
|
1193
1208
|
if (c.exitCode !== 0)
|
|
1194
1209
|
throw c.errors;
|
|
1195
1210
|
const s = await t.readFileAsBuffer(i), l = new File([s], i);
|
|
1196
|
-
|
|
1211
|
+
z.saveAs(l);
|
|
1197
1212
|
}
|
|
1198
|
-
async function
|
|
1213
|
+
async function Ae(t, e) {
|
|
1199
1214
|
if (
|
|
1200
1215
|
// eslint-disable-next-line no-alert
|
|
1201
1216
|
!confirm(
|
|
@@ -1206,7 +1221,7 @@ async function Oe(t, e) {
|
|
|
1206
1221
|
const n = await e.arrayBuffer(), r = new Uint8Array(n), o = "/import.zip";
|
|
1207
1222
|
await t.writeFile(o, r);
|
|
1208
1223
|
const a = await t.run({
|
|
1209
|
-
code:
|
|
1224
|
+
code: q + ` readFileFromZipArchive('${o}', '${H}');`
|
|
1210
1225
|
});
|
|
1211
1226
|
if (a.exitCode !== 0)
|
|
1212
1227
|
throw a.errors;
|
|
@@ -1214,7 +1229,7 @@ async function Oe(t, e) {
|
|
|
1214
1229
|
a.bytes
|
|
1215
1230
|
), d = new File(
|
|
1216
1231
|
[i],
|
|
1217
|
-
|
|
1232
|
+
te
|
|
1218
1233
|
), c = await t.request({
|
|
1219
1234
|
url: "/wp-admin/admin.php?import=wordpress"
|
|
1220
1235
|
}), l = new DOMParser().parseFromString(
|
|
@@ -1248,13 +1263,13 @@ async function Oe(t, e) {
|
|
|
1248
1263
|
}
|
|
1249
1264
|
});
|
|
1250
1265
|
const v = await t.run({
|
|
1251
|
-
code:
|
|
1266
|
+
code: q + ` importZipFile('${o}');`
|
|
1252
1267
|
});
|
|
1253
1268
|
if (v.exitCode !== 0)
|
|
1254
1269
|
throw v.errors;
|
|
1255
1270
|
return !0;
|
|
1256
1271
|
}
|
|
1257
|
-
async function
|
|
1272
|
+
async function Le(t, e = "admin", n = "password") {
|
|
1258
1273
|
await t.request({
|
|
1259
1274
|
url: "/wp-login.php"
|
|
1260
1275
|
}), await t.request({
|
|
@@ -1267,17 +1282,17 @@ async function Ae(t, e = "admin", n = "password") {
|
|
|
1267
1282
|
}
|
|
1268
1283
|
});
|
|
1269
1284
|
}
|
|
1270
|
-
function
|
|
1285
|
+
function R(t) {
|
|
1271
1286
|
return new DOMParser().parseFromString(t.text, "text/html");
|
|
1272
1287
|
}
|
|
1273
|
-
function
|
|
1288
|
+
function ne(t) {
|
|
1274
1289
|
const e = t.split(".").shift().replace("-", " ");
|
|
1275
1290
|
return e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
|
|
1276
1291
|
}
|
|
1277
|
-
async function
|
|
1292
|
+
async function _e(t, e, n = {}) {
|
|
1278
1293
|
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1279
1294
|
url: "/wp-admin/theme-install.php"
|
|
1280
|
-
}), a =
|
|
1295
|
+
}), a = R(o), i = new FormData(
|
|
1281
1296
|
a.querySelector(".wp-upload-form")
|
|
1282
1297
|
), { themezip: d, ...c } = Object.fromEntries(
|
|
1283
1298
|
i.entries()
|
|
@@ -1288,7 +1303,7 @@ async function Se(t, e, n = {}) {
|
|
|
1288
1303
|
files: { themezip: e }
|
|
1289
1304
|
});
|
|
1290
1305
|
if (r) {
|
|
1291
|
-
const l =
|
|
1306
|
+
const l = R(s), h = l.querySelector(
|
|
1292
1307
|
"#wpbody-content > .wrap"
|
|
1293
1308
|
);
|
|
1294
1309
|
if (h?.textContent?.includes(
|
|
@@ -1313,10 +1328,10 @@ async function Se(t, e, n = {}) {
|
|
|
1313
1328
|
});
|
|
1314
1329
|
}
|
|
1315
1330
|
}
|
|
1316
|
-
async function
|
|
1331
|
+
async function Ce(t, e, n = {}) {
|
|
1317
1332
|
const r = "activate" in n ? n.activate : !0, o = await t.request({
|
|
1318
1333
|
url: "/wp-admin/plugin-install.php?tab=upload"
|
|
1319
|
-
}), a =
|
|
1334
|
+
}), a = R(o), i = new FormData(
|
|
1320
1335
|
a.querySelector(".wp-upload-form")
|
|
1321
1336
|
), { pluginzip: d, ...c } = Object.fromEntries(
|
|
1322
1337
|
i.entries()
|
|
@@ -1327,7 +1342,7 @@ async function _e(t, e, n = {}) {
|
|
|
1327
1342
|
files: { pluginzip: e }
|
|
1328
1343
|
});
|
|
1329
1344
|
if (r) {
|
|
1330
|
-
const u =
|
|
1345
|
+
const u = R(s).querySelector("#wpbody-content .button.button-primary").attributes.getNamedItem("href").value, p = new URL(
|
|
1331
1346
|
u,
|
|
1332
1347
|
await t.pathToInternalUrl("/wp-admin/")
|
|
1333
1348
|
).toString();
|
|
@@ -1355,8 +1370,8 @@ async function _e(t, e, n = {}) {
|
|
|
1355
1370
|
)
|
|
1356
1371
|
));
|
|
1357
1372
|
}
|
|
1358
|
-
async function
|
|
1359
|
-
const o =
|
|
1373
|
+
async function Ue(t, e) {
|
|
1374
|
+
const o = R(
|
|
1360
1375
|
await t.request({
|
|
1361
1376
|
url: "/wp-admin/plugins.php"
|
|
1362
1377
|
})
|
|
@@ -1367,9 +1382,9 @@ async function Le(t, e) {
|
|
|
1367
1382
|
url: "/wp-admin/" + o
|
|
1368
1383
|
});
|
|
1369
1384
|
}
|
|
1370
|
-
const
|
|
1371
|
-
function
|
|
1372
|
-
const n = t.headers.get("content-length") || "", r = parseInt(n, 10) ||
|
|
1385
|
+
const ke = 5 * 1024 * 1024;
|
|
1386
|
+
function re(t, e) {
|
|
1387
|
+
const n = t.headers.get("content-length") || "", r = parseInt(n, 10) || ke;
|
|
1373
1388
|
function o(a, i) {
|
|
1374
1389
|
e(
|
|
1375
1390
|
new CustomEvent("progress", {
|
|
@@ -1410,18 +1425,18 @@ function ne(t, e) {
|
|
|
1410
1425
|
}
|
|
1411
1426
|
);
|
|
1412
1427
|
}
|
|
1413
|
-
async function
|
|
1428
|
+
async function De(t, e, n = 100, r) {
|
|
1414
1429
|
let o = await fetch("/plugin-proxy?theme=" + e);
|
|
1415
|
-
if (r && (o =
|
|
1430
|
+
if (r && (o = re(
|
|
1416
1431
|
o,
|
|
1417
1432
|
r.partialObserver(
|
|
1418
1433
|
n / 2,
|
|
1419
|
-
`Installing ${
|
|
1434
|
+
`Installing ${ne(e)} theme...`
|
|
1420
1435
|
)
|
|
1421
1436
|
), r.slowlyIncrementBy(n / 2)), o.status === 200) {
|
|
1422
1437
|
const a = new File([await o.blob()], e);
|
|
1423
1438
|
try {
|
|
1424
|
-
await
|
|
1439
|
+
await _e(t, a);
|
|
1425
1440
|
} catch (i) {
|
|
1426
1441
|
console.error(
|
|
1427
1442
|
`Proceeding without the ${e} theme. Could not install it in wp-admin. The original error was: ${i}`
|
|
@@ -1440,11 +1455,11 @@ async function Ie(t, e, n = 100, r) {
|
|
|
1440
1455
|
let s = await fetch(
|
|
1441
1456
|
"/plugin-proxy?plugin=" + c
|
|
1442
1457
|
);
|
|
1443
|
-
return r && (s =
|
|
1458
|
+
return r && (s = re(
|
|
1444
1459
|
s,
|
|
1445
1460
|
r.partialObserver(
|
|
1446
1461
|
i * 0.66,
|
|
1447
|
-
`Installing ${
|
|
1462
|
+
`Installing ${ne(
|
|
1448
1463
|
c
|
|
1449
1464
|
)} plugin...`
|
|
1450
1465
|
)
|
|
@@ -1457,7 +1472,7 @@ async function Ie(t, e, n = 100, r) {
|
|
|
1457
1472
|
if (c.detail) {
|
|
1458
1473
|
r?.slowlyIncrementBy(i * 0.33);
|
|
1459
1474
|
try {
|
|
1460
|
-
await
|
|
1475
|
+
await Ce(t, c.detail);
|
|
1461
1476
|
} catch (s) {
|
|
1462
1477
|
console.error(
|
|
1463
1478
|
`Proceeding without the ${c.detail.name} plugin. Could not install it in wp-admin. The original error was: ${s}`
|
|
@@ -1497,21 +1512,21 @@ class Z extends EventTarget {
|
|
|
1497
1512
|
}
|
|
1498
1513
|
}
|
|
1499
1514
|
}
|
|
1500
|
-
async function
|
|
1515
|
+
async function ze(t, e) {
|
|
1501
1516
|
e?.loadRemote && (t.src = e?.loadRemote, await new Promise((r) => {
|
|
1502
1517
|
t.addEventListener("load", r, !1);
|
|
1503
1518
|
}));
|
|
1504
|
-
const n =
|
|
1519
|
+
const n = Se(t.contentWindow);
|
|
1505
1520
|
return await n.absoluteUrl, n;
|
|
1506
1521
|
}
|
|
1507
1522
|
export {
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1523
|
+
Ue as activatePlugin,
|
|
1524
|
+
ze as connectPlayground,
|
|
1525
|
+
Oe as exportFile,
|
|
1526
|
+
Ae as importFile,
|
|
1527
|
+
Ce as installPlugin,
|
|
1513
1528
|
Ie as installPluginsFromDirectory,
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1529
|
+
_e as installTheme,
|
|
1530
|
+
De as installThemeFromDirectory,
|
|
1531
|
+
Le as login
|
|
1517
1532
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "WordPress Playground client",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,6 +15,13 @@
|
|
|
15
15
|
"url": "https://github.com/adamziel"
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./index.js",
|
|
21
|
+
"require": "./index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
18
25
|
"typedoc": {
|
|
19
26
|
"entryPoint": "./src/index.ts",
|
|
20
27
|
"readmeFile": "./README.md",
|
|
@@ -27,7 +34,8 @@
|
|
|
27
34
|
},
|
|
28
35
|
"license": "(GPL-2.0-or-later OR MPL-2.0)",
|
|
29
36
|
"type": "module",
|
|
30
|
-
"main": "index.
|
|
37
|
+
"main": "./index.cjs",
|
|
38
|
+
"module": "./index.js",
|
|
31
39
|
"types": "index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "111d5c8d2ce3279d028a09449f9af6299818ad66"
|
|
33
41
|
}
|