/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/photopea@1.1.1/src/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
class Photopea{static async createEmbed(e,t){let n="";"object"==typeof t?n=JSON.stringify(t):"string"==typeof t&&(n=t);let a=document.createElement("iframe");a.style.border="0",a.style.width="100%",a.style.height="100%",a.src=t?`https://www.photopea.com/#${encodeURI(n)}`:"https://www.photopea.com/#",e.appendChild(a);let o=new Promise((function(e,t){let n=t=>{if(t.source==a.contentWindow&&"done"==t.data){let t=new Photopea(a.contentWindow);window.removeEventListener("message",n),e(t)}};window.addEventListener("message",n)}));return await o}contentWindow;constructor(e){this.contentWindow=e}async runScript(e){await this._pause();let t=new Promise(((t,n)=>{let a=[],o=e=>{e.source==this.contentWindow&&(a.push(e.data),"done"==e.data&&(window.removeEventListener("message",o),t(a)))};window.addEventListener("message",o),this.contentWindow.postMessage(e,"*")}));return await t}async loadAsset(e){await this._pause();let t=new Promise(((t,n)=>{let a=[],o=e=>{e.source==this.contentWindow&&(a.push(e.data),"done"==e.data&&(window.removeEventListener("message",o),t(a)))};window.addEventListener("message",o),this.contentWindow.postMessage(e,"*")}));return await t}async openFromURL(e,t=!0){await this._pause();let n="done";for(;"done"==n;)n=(await this.runScript(`app.echoToOE(${t?"app.activeDocument.layers.length":"app.documents.length"})`))[0];let a=n;for(await this.runScript(`app.open("${e}", null, ${t});`);a==n||"done"==a;)a=(await this.runScript(`app.echoToOE(${t?"app.activeDocument.layers.length":"app.documents.length"})`))[0];return["done"]}async exportImage(e="png"){await this._pause();let t="done";for(;"done"==t;){t=(await this.runScript(`app.activeDocument.saveToOE("${e}");`))[0]}return new Blob([t],{type:"image/"+e})}async _pause(e=10){return await new Promise(((t,n)=>{setTimeout((()=>{t()}),e)}))}}export default Photopea;
//# sourceMappingURL=/sm/cb4f35afe4dec5b9acf431df8af28d21a45f82ac9accaf0abde8f8aed081d74f.map