UNPKG

@gaoding/editor-sdk

Version:

稿定编辑器对外 SDK

44 lines (43 loc) 40.5 kB
(function(T,b){typeof exports=="object"&&typeof module!="undefined"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(T=typeof globalThis!="undefined"?globalThis:T||self,b(T.gaoding={}))})(this,function(T){"use strict";var b;(function(t){t.Call="call",t.Reply="reply",t.Syn="syn",t.SynAck="synAck",t.Ack="ack"})(b||(b={}));var N;(function(t){t.Fulfilled="fulfilled",t.Rejected="rejected"})(N||(N={}));var M;(function(t){t.ConnectionDestroyed="ConnectionDestroyed",t.ConnectionTimeout="ConnectionTimeout",t.NotInIframe="NotInIframe",t.NoIframeSrc="NoIframeSrc"})(M||(M={}));var X;(function(t){t.DataCloneError="DataCloneError"})(X||(X={}));var A;(function(t){t.Message="message"})(A||(A={}));var He=()=>{const t=[];let e=!1;return{destroy(r){e=!0,t.forEach(n=>{n(r)})},onDestroy(r){e?r():t.push(r)}}},Ve=t=>(...e)=>{t&&console.log("[Penpal]",...e)};const Je={"http:":"80","https:":"443"},Ge=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,We=["file:","data:"];var Xe=t=>{if(t&&We.find(u=>t.startsWith(u)))return"null";const e=document.location,r=Ge.exec(t);let n,a,o;r?(n=r[1]?r[1]:e.protocol,a=r[2],o=r[4]):(n=e.protocol,a=e.hostname,o=e.port);const s=o&&o!==Je[n]?`:${o}`:"";return`${n}//${a}${s}`};const pe=({name:t,message:e,stack:r})=>({name:t,message:e,stack:r}),Ye=t=>{const e=new Error;return Object.keys(t).forEach(r=>e[r]=t[r]),e};var Ze=(t,e,r)=>{const{localName:n,local:a,remote:o,originForSending:s,originForReceiving:u}=t;let i=!1;const f=y=>{if(y.source!==o||y.data.penpal!==b.Call)return;if(y.origin!==u){r(`${n} received message from origin ${y.origin} which did not match expected origin ${u}`);return}const p=y.data,{methodName:l,args:d,id:h}=p;r(`${n}: Received ${l}() call`);const m=c=>v=>{if(r(`${n}: Sending ${l}() reply`),i){r(`${n}: Unable to send ${l}() reply due to destroyed connection`);return}const g={penpal:b.Reply,id:h,resolution:c,returnValue:v};c===N.Rejected&&v instanceof Error&&(g.returnValue=pe(v),g.returnValueIsError=!0);try{o.postMessage(g,s)}catch(k){if(k.name===X.DataCloneError){const $={penpal:b.Reply,id:h,resolution:N.Rejected,returnValue:pe(k),returnValueIsError:!0};o.postMessage($,s)}throw k}};new Promise(c=>c(e[l].apply(e,d))).then(m(N.Fulfilled),m(N.Rejected))};return a.addEventListener(A.Message,f),()=>{i=!0,a.removeEventListener(A.Message,f)}};let Qe=0;var et=()=>++Qe,tt=(t,e,r,n,a)=>{const{localName:o,local:s,remote:u,originForSending:i,originForReceiving:f}=e;let y=!1;a(`${o}: Connecting call sender`);const p=l=>(...d)=>{a(`${o}: Sending ${l}() call`);let h;try{u.closed&&(h=!0)}catch{h=!0}if(h&&n(),y){const m=new Error(`Unable to send ${l}() call due to destroyed connection`);throw m.code=M.ConnectionDestroyed,m}return new Promise((m,c)=>{const v=et(),g=$=>{if($.source!==u||$.data.penpal!==b.Reply||$.data.id!==v)return;if($.origin!==f){a(`${o} received message from origin ${$.origin} which did not match expected origin ${f}`);return}const de=$.data;a(`${o}: Received ${l}() reply`),s.removeEventListener(A.Message,g);let fe=de.returnValue;de.returnValueIsError&&(fe=Ye(fe)),(de.resolution===N.Fulfilled?m:c)(fe)};s.addEventListener(A.Message,g);const k={penpal:b.Call,id:v,methodName:l,args:d};u.postMessage(k,i)})};return r.reduce((l,d)=>(l[d]=p(d),l),t),()=>{y=!0}},rt=(t,e,r,n,a)=>{const{destroy:o,onDestroy:s}=n;let u,i;const f={};return y=>{if(y.origin!==e){a(`Parent: Handshake - Received ACK message from origin ${y.origin} which did not match expected origin ${e}`);return}a("Parent: Handshake - Received ACK");const p={localName:"Parent",local:window,remote:y.source,originForSending:r,originForReceiving:e};u&&u(),u=Ze(p,t,a),s(u),i&&i.forEach(d=>{delete f[d]}),i=y.data.methodNames;const l=tt(f,p,i,o,a);return s(l),f}},nt=(t,e,r,n)=>a=>{if(a.origin!==r){t(`Parent: Handshake - Received SYN message from origin ${a.origin} which did not match expected origin ${r}`);return}t("Parent: Handshake - Received SYN, responding with SYN-ACK");const o={penpal:b.SynAck,methodNames:Object.keys(e)};a.source.postMessage(o,n)};const at=6e4;var it=(t,e)=>{const{destroy:r,onDestroy:n}=e,a=setInterval(()=>{t.isConnected||(clearInterval(a),r())},at);n(()=>{clearInterval(a)})},ot=(t,e)=>{let r;return t!==void 0&&(r=window.setTimeout(()=>{const n=new Error(`Connection timed out after ${t}ms`);n.code=M.ConnectionTimeout,e(n)},t)),()=>{clearTimeout(r)}},st=t=>{if(!t.src&&!t.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=M.NoIframeSrc,e}},ut=t=>{let{iframe:e,methods:r={},childOrigin:n,timeout:a,debug:o=!1}=t;const s=Ve(o),u=He(),{onDestroy:i,destroy:f}=u;n||(st(e),n=Xe(e.src));const y=n==="null"?"*":n,p=nt(s,r,n,y),l=rt(r,n,y,u,s);return{promise:new Promise((h,m)=>{const c=ot(a,f),v=g=>{if(!(g.source!==e.contentWindow||!g.data)){if(g.data.penpal===b.Syn){p(g);return}if(g.data.penpal===b.Ack){const k=l(g);k&&(c(),h(k));return}}};window.addEventListener(A.Message,v),s("Parent: Awaiting handshake"),it(e,u),i(g=>{window.removeEventListener(A.Message,v),g||(g=new Error("Connection destroyed"),g.code=M.ConnectionDestroyed),m(g)})}),destroy(){f()}}};const lt="2.2.6",E={TEMPLATE_EDITOR_URL:"https://open.gaoding.com/design",MOBILE_TEMPLATE_EDITOR_URL:"https://open.gaoding.com/h5/design",KOUTU_EDITOR_URL:"https://open.gaoding.com/clip",IMAGE_EDITOR_URL:"https://open.gaoding.com/design/image",OPEN_PLATFORM_ORIGIN:"https://open.gaoding.com",get VERSION(){return lt}};var Y=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});function he(t,e){const r=document.createElement("div");r.style.cssText=` position: relative; width: calc(100vw - 100px); min-width: 1280px; height: calc(100vh - 80px); min-height: 604px; margin: 50px auto; background: rgb(255, 255, 255); display: block; `;const n=document.createElement("div");n.style.cssText=` font-size: 13px; width: 42px; height: 42px; text-align: right; position: absolute; right: -42px; top: 0px; background: no-repeat rgb(0, 0, 0); cursor: pointer; display: flex; align-items: center; justify-content: center; `;const a=document.createElement("img");a.src="https://st-gdx.dancf.com/gaodingx/34555636/design/20190509-142237-249d.png",a.style.cssText="display: block; width: 24px;",n.appendChild(a);const o=document.createElement("div");o.style.cssText=` position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 1000; `,o.className="gaoding-editor-iframe-dialog",r.appendChild(n),r.appendChild(t),o.appendChild(r),r.appendChild(t);const s=document.createElement("div");s.style.cssText=` position: fixed; inset: 0px; z-index: 999; background-color: rgb(0, 0, 0); opacity: 0.5; `;let u=!1,i="";function f(){!document.querySelector(".gaoding-editor-iframe-dialog")||(u?(i=document.documentElement.style.overflow,document.documentElement.style.overflow="hidden"):document.documentElement.style.overflow=i)}function y(){return Y(this,null,function*(){var l,d;e&&(yield e())===!1||(u=!1,f(),(l=s.parentElement)==null||l.removeChild(s),(d=o.parentElement)==null||d.removeChild(o))})}function p(){u||(u=!0,document.body.appendChild(s),document.body.appendChild(o),f())}return n.addEventListener("click",y),{open:p,close:y}}function B(t){const e=document.createElement("iframe");e.style.cssText=` display: block; width: 100%; height: 100%; ${t.css} `,e.referrerPolicy="strict-origin-when-cross-origin",e.className="gaoding-iframe",e.setAttribute("frameborder","0");let r=null;function n(i,f){return Y(this,null,function*(){const y=Object.assign({},f,{app_id:t.appId,v:E.VERSION}),p=`${i}?${Object.entries(y).filter(([l,d])=>d!==void 0).map(([l,d])=>`${l}=${d}`).join("&")}`;if(!f){e.src=i;return}e.src=p,r&&r.destroy(),r=ut({iframe:e,methods:t.methods})})}let a=null;t.container||(a=he(e,t.onClose));function o(){if(a)return a.open();const i=typeof t.container=="string"?document.body.querySelector(t.container):t.container;if(!i)throw new Error(`\u65E0\u6548\u7684 container ${t.container}`);i.appendChild(e)}function s(){if(a==null?void 0:a.close)return a.close();e.parentElement&&e.parentElement.removeChild(e)}function u(i){a=he(e,t.onClose),t.container=i}return{remove:s,insert:o,update:n,iframe:e,restetContainer:u,getService(){return Y(this,null,function*(){return r.promise})}}}var ct=Object.defineProperty,dt=(t,e,r)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ft=(t,e,r)=>(dt(t,typeof e!="symbol"?e+"":e,r),r),me=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});class j{constructor(){ft(this,"events"),this.events={}}add(e,r){if(!r)return()=>{};const n=this.get(e);return n.push(r),this.events[e]=n,()=>this.off(e,r)}on(e,r){return this.add(e,r)}once(e,r){const n=this.add(e,(...a)=>{n(),r(...a)});return n}off(e,r){const n=this.get(e);if(n){const a=n.findIndex(o=>o===r);a!==-1&&n.splice(a,1)}}get(e){return this.events[e]||[]}invoke(e,...r){const n=[...this.get(e)];for(const a of n)a(...r)}emit(e,...r){this.invoke(e,...r)}asyncInvoke(e,...r){return me(this,null,function*(){const n=[...this.get(e)];for(const a of n)yield a(...r)})}asyncInvokeAll(e,...r){return me(this,null,function*(){yield Promise.all(this.get(e).map(n=>n(...r)))})}}var pt=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});function ve(t){return pt(this,null,function*(){const e=t instanceof File?t.name:`${t.type}`;return new File([yield t.arrayBuffer()],e,{type:t.type})})}function S(t,e){if(!t)throw new Error(e)}var R=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});function ht(t){const e=new j;let r=null,n=!1;const a=[];function o(){a.forEach(c=>c()),a.length=0}const s=B({appId:t.appId,container:t.container,onClose(){return R(this,null,function*(){if(t.onCloseModal&&(yield t.onCloseModal())===!1)return!1;e.emit("close")})},methods:{emit(c,...v){return R(this,null,function*(){e.emit(c,...v)})},onload(){return R(this,null,function*(){e.emit("load")})},onSelectTemplate(c){return R(this,null,function*(){return e.emit("select.template",c),!1})},onTemplateLoad(){return R(this,null,function*(){r=yield u(),e.emit("template.load")})},getUseRightToken(c){return R(this,null,function*(){if(!t.getUseRightCert)return!1;const v=yield t.getUseRightCert(c);return v instanceof Error?{message:v.message}:v})},getUserCode(){return R(this,null,function*(){if(!t.authorize)return!1;try{return yield t.authorize()}catch{p()}})}}});function u(){return R(this,null,function*(){const c=yield s.getService();return{addImage(v,g){return R(this,null,function*(){c.addImage(v,g)})}}})}function i(c={}){c.categoryId&&S(["number","string"].includes(typeof c.categoryId),"categoryId \u53C2\u6570\u7C7B\u578B\u6709\u8BEF"),o(),n=!1;const v={version:t.authorize?"TE002":"TE001",buttonText:c.okText||"\u4FDD\u5B58"};return c.templateId?v.id=c.templateId:(v.mode="create",c.size&&(v.width=c.size.width,v.height=c.size.height)),c.categoryId&&(v.filterId=c.categoryId),s.update(E.TEMPLATE_EDITOR_URL,v),e.once("load",()=>R(this,null,function*(){n=!0,yield(yield s.getService()).init({appId:t.appId,version:t.authorize?"TE002":"TE001",fileTypes:c.fileTypes,disableModules:c.disableModules,v:E.VERSION,filterPaidMaterial:c.filterPaidMaterial,categoryId:c.categoryId}),e.emit("editor.load")})),s.insert(),new Promise(g=>{a.push(e.once("save",k=>g(k))),a.push(e.once("close",()=>g(!1)))})}function f(c){return c.categories&&(S(Array.isArray(c.categories),"categories \u53C2\u6570\u5FC5\u987B\u662F number \u6570\u7EC4\u7C7B\u578B"),S(c.categories.map(v=>+v).filter(Boolean).length===c.categories.length,"categories \u53C2\u6570\u5FC5\u987B\u662F number \u6570\u7EC4\u7C7B\u578B")),o(),n=!1,s.update(E.TEMPLATE_EDITOR_URL,{id:c.id,buttonText:c.okText||"\u4FDD\u5B58",mode:"user",version:t.authorize?"TE002":"TE001"}),e.once("load",()=>R(this,null,function*(){var v;n=!0,yield(yield s.getService()).init({appId:t.appId,version:t.authorize?"TE002":"TE001",disableModules:c.disableModules,categoryId:(v=c.categories)==null?void 0:v.join(","),v:E.VERSION,filterPaidMaterial:c.filterPaidMaterial,fileTypes:c.fileTypes}),e.emit("editor.load")})),s.insert(),new Promise(v=>{a.push(e.once("save",g=>v(g))),a.push(e.once("close",()=>v(!1)))})}function y(c){return c.categories&&(S(Array.isArray(c.categories),"categories \u53C2\u6570\u5FC5\u987B\u662F number \u6570\u7EC4\u7C7B\u578B"),S(c.categories.map(v=>+v).filter(Boolean).length===c.categories.length,"categories \u53C2\u6570\u5FC5\u987B\u662F number \u6570\u7EC4\u7C7B\u578B")),n=!1,o(),s.update(E.OPEN_PLATFORM_ORIGIN+"/template/search",{app_id:t.appId,version:t.authorize?"TE002":"TE001"}),e.once("load",()=>R(this,null,function*(){n=!0,(yield s.getService()).init({appId:t.appId,v:E.VERSION,version:t.authorize?"TE002":"TE001",categories:c.categories})})),c.onSelectTemplate&&a.push(e.add("select.template",c.onSelectTemplate)),s.insert(),new Promise(v=>{a.push(e.once("select.template",g=>v(g))),a.push(e.once("close",()=>v(!1)))})}function p(){e.emit("close"),s.remove()}function l(c){e.add("save",c)}function d(c){e.add("close",c)}function h(c){e.add("editor.load",c)}function m(c){e.add("template.load",c)}return{get canva(){return r},get isLoad(){return n},openTemplateList:y,close:p,onSave:l,onTemplateLoad:m,onClose:d,onLoad:h,editDesign:f,createDesign:i}}var O=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});function mt(t){S(!!t,"createTemplateEditor \u9700\u8981\u4F20\u5165\u53C2\u6570\u624D\u80FD\u4F7F\u7528"),S(typeof t.authorize=="function","authorize \u5FC5\u73B0\u662F\u4E2A function"),S(typeof t.container=="string","\u7F3A\u5C11\u5FC5\u586B\u53C2\u6570 container"),S(typeof t.getUseRightCert=="function","\u7F3A\u5C11\u5FC5\u586B\u53C2\u6570 getUseRightCert");const e=new j;let r=!1;const n=[];function a(){n.forEach(h=>h()),n.length=0}const o=B({appId:t.appId,container:t.container,css:"min-height: 100vh;",methods:{emit(h,...m){return O(this,null,function*(){e.emit(h,...m)})},onload(){return O(this,null,function*(){e.emit("load")})},onSelectTemplate(h){return O(this,null,function*(){return e.emit("select.template",h),!1})},onTemplateLoad(){return O(this,null,function*(){e.emit("template.load")})},getUseRightCert(h){return O(this,null,function*(){if(!t.getUseRightCert)return!1;const m=yield t.getUseRightCert(h);return m instanceof Error?{message:m.message}:m})},getUserCode(){return O(this,null,function*(){if(!t.authorize)return!1;try{return yield t.authorize()}catch{f()}})}}});function s(h){return O(this,null,function*(){a(),r=!1;const m=yield t.authorize(),c={version:"TE002",user_code:m};return h.templateId&&(c.id=h.templateId),o.update(E.MOBILE_TEMPLATE_EDITOR_URL,c),e.once("load",()=>O(this,null,function*(){r=!0,yield(yield o.getService()).init({appId:t.appId,version:"TE002"}),e.emit("editor.load")})),o.insert(),new Promise(v=>{n.push(e.once("save",g=>v(g))),n.push(e.once("close",()=>v(!1)))})})}function u(h){return O(this,null,function*(){a(),r=!1;const m=yield t.authorize();return o.update(E.MOBILE_TEMPLATE_EDITOR_URL,{id:h.id,mode:"user",user_code:m,version:"TE002"}),e.once("load",()=>O(this,null,function*(){r=!0,yield(yield o.getService()).init({appId:t.appId,version:"TE002",v:E.VERSION}),e.emit("editor.load")})),o.insert(),new Promise(c=>{n.push(e.once("save",v=>c(v))),n.push(e.once("close",()=>c(!1)))})})}function i(h){return r=!1,a(),o.update(E.OPEN_PLATFORM_ORIGIN+"/mt/templates",{app_id:t.appId,version:"TE002"}),e.once("load",()=>O(this,null,function*(){r=!0,(yield o.getService()).init({appId:t.appId,v:E.VERSION,version:"TE002"})})),h.onSelectTemplate&&n.push(e.add("select.template",h.onSelectTemplate)),o.insert(),new Promise(m=>{n.push(e.once("select.template",c=>m(c))),n.push(e.once("close",()=>m(!1)))})}function f(){e.emit("close"),o.remove()}function y(h){e.add("save",h)}function p(h){e.add("close",h)}function l(h){e.add("editor.load",h)}function d(h){e.add("template.load",h)}return{get isLoad(){return r},openTemplateList:i,close:f,onSave:y,onTemplateLoad:d,onClose:p,onLoad:l,editDesign:u,createDesign:s}}var Z={exports:{}},ye=function(e,r){return function(){for(var a=new Array(arguments.length),o=0;o<a.length;o++)a[o]=arguments[o];return e.apply(r,a)}},vt=ye,U=Object.prototype.toString;function Q(t){return U.call(t)==="[object Array]"}function ee(t){return typeof t=="undefined"}function yt(t){return t!==null&&!ee(t)&&t.constructor!==null&&!ee(t.constructor)&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}function gt(t){return U.call(t)==="[object ArrayBuffer]"}function Et(t){return typeof FormData!="undefined"&&t instanceof FormData}function wt(t){var e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&t.buffer instanceof ArrayBuffer,e}function Ct(t){return typeof t=="string"}function bt(t){return typeof t=="number"}function ge(t){return t!==null&&typeof t=="object"}function z(t){if(U.call(t)!=="[object Object]")return!1;var e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}function It(t){return U.call(t)==="[object Date]"}function Rt(t){return U.call(t)==="[object File]"}function Tt(t){return U.call(t)==="[object Blob]"}function Ee(t){return U.call(t)==="[object Function]"}function St(t){return ge(t)&&Ee(t.pipe)}function Ot(t){return typeof URLSearchParams!="undefined"&&t instanceof URLSearchParams}function Pt(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function xt(){return typeof navigator!="undefined"&&(navigator.product==="ReactNative"||navigator.product==="NativeScript"||navigator.product==="NS")?!1:typeof window!="undefined"&&typeof document!="undefined"}function te(t,e){if(!(t===null||typeof t=="undefined"))if(typeof t!="object"&&(t=[t]),Q(t))for(var r=0,n=t.length;r<n;r++)e.call(null,t[r],r,t);else for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&e.call(null,t[a],a,t)}function re(){var t={};function e(a,o){z(t[o])&&z(a)?t[o]=re(t[o],a):z(a)?t[o]=re({},a):Q(a)?t[o]=a.slice():t[o]=a}for(var r=0,n=arguments.length;r<n;r++)te(arguments[r],e);return t}function _t(t,e,r){return te(e,function(a,o){r&&typeof a=="function"?t[o]=vt(a,r):t[o]=a}),t}function kt(t){return t.charCodeAt(0)===65279&&(t=t.slice(1)),t}var I={isArray:Q,isArrayBuffer:gt,isBuffer:yt,isFormData:Et,isArrayBufferView:wt,isString:Ct,isNumber:bt,isObject:ge,isPlainObject:z,isUndefined:ee,isDate:It,isFile:Rt,isBlob:Tt,isFunction:Ee,isStream:St,isURLSearchParams:Ot,isStandardBrowserEnv:xt,forEach:te,merge:re,extend:_t,trim:Pt,stripBOM:kt},L=I;function we(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var Ce=function(e,r,n){if(!r)return e;var a;if(n)a=n(r);else if(L.isURLSearchParams(r))a=r.toString();else{var o=[];L.forEach(r,function(i,f){i===null||typeof i=="undefined"||(L.isArray(i)?f=f+"[]":i=[i],L.forEach(i,function(p){L.isDate(p)?p=p.toISOString():L.isObject(p)&&(p=JSON.stringify(p)),o.push(we(f)+"="+we(p))}))}),a=o.join("&")}if(a){var s=e.indexOf("#");s!==-1&&(e=e.slice(0,s)),e+=(e.indexOf("?")===-1?"?":"&")+a}return e},At=I;function q(){this.handlers=[]}q.prototype.use=function(e,r,n){return this.handlers.push({fulfilled:e,rejected:r,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1},q.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},q.prototype.forEach=function(e){At.forEach(this.handlers,function(n){n!==null&&e(n)})};var $t=q,Nt=I,Ut=function(e,r){Nt.forEach(e,function(a,o){o!==r&&o.toUpperCase()===r.toUpperCase()&&(e[r]=a,delete e[o])})},be=function(e,r,n,a,o){return e.config=r,n&&(e.code=n),e.request=a,e.response=o,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e},Mt=be,Ie=function(e,r,n,a,o){var s=new Error(e);return Mt(s,r,n,a,o)},Lt=Ie,Dt=function(e,r,n){var a=n.config.validateStatus;!n.status||!a||a(n.status)?e(n):r(Lt("Request failed with status code "+n.status,n.config,null,n.request,n))},K=I,Ft=K.isStandardBrowserEnv()?function(){return{write:function(r,n,a,o,s,u){var i=[];i.push(r+"="+encodeURIComponent(n)),K.isNumber(a)&&i.push("expires="+new Date(a).toGMTString()),K.isString(o)&&i.push("path="+o),K.isString(s)&&i.push("domain="+s),u===!0&&i.push("secure"),document.cookie=i.join("; ")},read:function(r){var n=document.cookie.match(new RegExp("(^|;\\s*)("+r+")=([^;]*)"));return n?decodeURIComponent(n[3]):null},remove:function(r){this.write(r,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}(),Bt=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)},jt=function(e,r){return r?e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""):e},zt=Bt,qt=jt,Kt=function(e,r){return e&&!zt(r)?qt(e,r):r},ne=I,Ht=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"],Vt=function(e){var r={},n,a,o;return e&&ne.forEach(e.split(` `),function(u){if(o=u.indexOf(":"),n=ne.trim(u.substr(0,o)).toLowerCase(),a=ne.trim(u.substr(o+1)),n){if(r[n]&&Ht.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([a]):r[n]=r[n]?r[n]+", "+a:a}}),r},Re=I,Jt=Re.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function a(o){var s=o;return e&&(r.setAttribute("href",s),s=r.href),r.setAttribute("href",s),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:r.pathname.charAt(0)==="/"?r.pathname:"/"+r.pathname}}return n=a(window.location.href),function(s){var u=Re.isString(s)?a(s):s;return u.protocol===n.protocol&&u.host===n.host}}():function(){return function(){return!0}}(),H=I,Gt=Dt,Wt=Ft,Xt=Ce,Yt=Kt,Zt=Vt,Qt=Jt,ae=Ie,Te=function(e){return new Promise(function(n,a){var o=e.data,s=e.headers,u=e.responseType;H.isFormData(o)&&delete s["Content-Type"];var i=new XMLHttpRequest;if(e.auth){var f=e.auth.username||"",y=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";s.Authorization="Basic "+btoa(f+":"+y)}var p=Yt(e.baseURL,e.url);i.open(e.method.toUpperCase(),Xt(p,e.params,e.paramsSerializer),!0),i.timeout=e.timeout;function l(){if(!!i){var h="getAllResponseHeaders"in i?Zt(i.getAllResponseHeaders()):null,m=!u||u==="text"||u==="json"?i.responseText:i.response,c={data:m,status:i.status,statusText:i.statusText,headers:h,config:e,request:i};Gt(n,a,c),i=null}}if("onloadend"in i?i.onloadend=l:i.onreadystatechange=function(){!i||i.readyState!==4||i.status===0&&!(i.responseURL&&i.responseURL.indexOf("file:")===0)||setTimeout(l)},i.onabort=function(){!i||(a(ae("Request aborted",e,"ECONNABORTED",i)),i=null)},i.onerror=function(){a(ae("Network Error",e,null,i)),i=null},i.ontimeout=function(){var m="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(m=e.timeoutErrorMessage),a(ae(m,e,e.transitional&&e.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED",i)),i=null},H.isStandardBrowserEnv()){var d=(e.withCredentials||Qt(p))&&e.xsrfCookieName?Wt.read(e.xsrfCookieName):void 0;d&&(s[e.xsrfHeaderName]=d)}"setRequestHeader"in i&&H.forEach(s,function(m,c){typeof o=="undefined"&&c.toLowerCase()==="content-type"?delete s[c]:i.setRequestHeader(c,m)}),H.isUndefined(e.withCredentials)||(i.withCredentials=!!e.withCredentials),u&&u!=="json"&&(i.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&i.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&i.upload&&i.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then(function(m){!i||(i.abort(),a(m),i=null)}),o||(o=null),i.send(o)})},w=I,Se=Ut,er=be,tr={"Content-Type":"application/x-www-form-urlencoded"};function Oe(t,e){!w.isUndefined(t)&&w.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function rr(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Te),t}function nr(t,e,r){if(w.isString(t))try{return(e||JSON.parse)(t),w.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var V={transitional:{silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},adapter:rr(),transformRequest:[function(e,r){return Se(r,"Accept"),Se(r,"Content-Type"),w.isFormData(e)||w.isArrayBuffer(e)||w.isBuffer(e)||w.isStream(e)||w.isFile(e)||w.isBlob(e)?e:w.isArrayBufferView(e)?e.buffer:w.isURLSearchParams(e)?(Oe(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):w.isObject(e)||r&&r["Content-Type"]==="application/json"?(Oe(r,"application/json"),nr(e)):e}],transformResponse:[function(e){var r=this.transitional,n=r&&r.silentJSONParsing,a=r&&r.forcedJSONParsing,o=!n&&this.responseType==="json";if(o||a&&w.isString(e)&&e.length)try{return JSON.parse(e)}catch(s){if(o)throw s.name==="SyntaxError"?er(s,this,"E_JSON_PARSE"):s}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};V.headers={common:{Accept:"application/json, text/plain, */*"}},w.forEach(["delete","get","head"],function(e){V.headers[e]={}}),w.forEach(["post","put","patch"],function(e){V.headers[e]=w.merge(tr)});var ie=V,ar=I,ir=ie,or=function(e,r,n){var a=this||ir;return ar.forEach(n,function(s){e=s.call(a,e,r)}),e},Pe=function(e){return!!(e&&e.__CANCEL__)},xe=I,oe=or,sr=Pe,ur=ie;function se(t){t.cancelToken&&t.cancelToken.throwIfRequested()}var lr=function(e){se(e),e.headers=e.headers||{},e.data=oe.call(e,e.data,e.headers,e.transformRequest),e.headers=xe.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),xe.forEach(["delete","get","head","post","put","patch","common"],function(a){delete e.headers[a]});var r=e.adapter||ur.adapter;return r(e).then(function(a){return se(e),a.data=oe.call(e,a.data,a.headers,e.transformResponse),a},function(a){return sr(a)||(se(e),a&&a.response&&(a.response.data=oe.call(e,a.response.data,a.response.headers,e.transformResponse))),Promise.reject(a)})},C=I,_e=function(e,r){r=r||{};var n={},a=["url","method","data"],o=["headers","auth","proxy","params"],s=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],u=["validateStatus"];function i(l,d){return C.isPlainObject(l)&&C.isPlainObject(d)?C.merge(l,d):C.isPlainObject(d)?C.merge({},d):C.isArray(d)?d.slice():d}function f(l){C.isUndefined(r[l])?C.isUndefined(e[l])||(n[l]=i(void 0,e[l])):n[l]=i(e[l],r[l])}C.forEach(a,function(d){C.isUndefined(r[d])||(n[d]=i(void 0,r[d]))}),C.forEach(o,f),C.forEach(s,function(d){C.isUndefined(r[d])?C.isUndefined(e[d])||(n[d]=i(void 0,e[d])):n[d]=i(void 0,r[d])}),C.forEach(u,function(d){d in r?n[d]=i(e[d],r[d]):d in e&&(n[d]=i(void 0,e[d]))});var y=a.concat(o).concat(s).concat(u),p=Object.keys(e).concat(Object.keys(r)).filter(function(d){return y.indexOf(d)===-1});return C.forEach(p,f),n},cr={name:"axios",version:"0.21.4",description:"Promise based HTTP client for the browser and node.js",main:"index.js",scripts:{test:"grunt test",start:"node ./sandbox/server.js",build:"NODE_ENV=production grunt build",preversion:"npm test",version:"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",postversion:"git push && git push --tags",examples:"node ./examples/server.js",coveralls:"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",fix:"eslint --fix lib/**/*.js"},repository:{type:"git",url:"https://github.com/axios/axios.git"},keywords:["xhr","http","ajax","promise","node"],author:"Matt Zabriskie",license:"MIT",bugs:{url:"https://github.com/axios/axios/issues"},homepage:"https://axios-http.com",devDependencies:{coveralls:"^3.0.0","es6-promise":"^4.2.4",grunt:"^1.3.0","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^23.0.0","grunt-karma":"^4.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^4.0.2","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1",karma:"^6.3.2","karma-chrome-launcher":"^3.1.0","karma-firefox-launcher":"^2.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^4.3.6","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.8","karma-webpack":"^4.0.2","load-grunt-tasks":"^3.5.2",minimist:"^1.2.0",mocha:"^8.2.1",sinon:"^4.5.0","terser-webpack-plugin":"^4.2.3",typescript:"^4.0.5","url-search-params":"^0.10.0",webpack:"^4.44.2","webpack-dev-server":"^3.11.0"},browser:{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},jsdelivr:"dist/axios.min.js",unpkg:"dist/axios.min.js",typings:"./index.d.ts",dependencies:{"follow-redirects":"^1.14.0"},bundlesize:[{path:"./dist/axios.min.js",threshold:"5kB"}]},ke=cr,ue={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){ue[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var Ae={},dr=ke.version.split(".");function $e(t,e){for(var r=e?e.split("."):dr,n=t.split("."),a=0;a<3;a++){if(r[a]>n[a])return!0;if(r[a]<n[a])return!1}return!1}ue.transitional=function(e,r,n){var a=r&&$e(r);function o(s,u){return"[Axios v"+ke.version+"] Transitional option '"+s+"'"+u+(n?". "+n:"")}return function(s,u,i){if(e===!1)throw new Error(o(u," has been removed in "+r));return a&&!Ae[u]&&(Ae[u]=!0,console.warn(o(u," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,u,i):!0}};function fr(t,e,r){if(typeof t!="object")throw new TypeError("options must be an object");for(var n=Object.keys(t),a=n.length;a-- >0;){var o=n[a],s=e[o];if(s){var u=t[o],i=u===void 0||s(u,o,t);if(i!==!0)throw new TypeError("option "+o+" must be "+i);continue}if(r!==!0)throw Error("Unknown option "+o)}}var pr={isOlderVersion:$e,assertOptions:fr,validators:ue},Ne=I,hr=Ce,Ue=$t,Me=lr,J=_e,Le=pr,D=Le.validators;function F(t){this.defaults=t,this.interceptors={request:new Ue,response:new Ue}}F.prototype.request=function(e){typeof e=="string"?(e=arguments[1]||{},e.url=arguments[0]):e=e||{},e=J(this.defaults,e),e.method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var r=e.transitional;r!==void 0&&Le.assertOptions(r,{silentJSONParsing:D.transitional(D.boolean,"1.0.0"),forcedJSONParsing:D.transitional(D.boolean,"1.0.0"),clarifyTimeoutError:D.transitional(D.boolean,"1.0.0")},!1);var n=[],a=!0;this.interceptors.request.forEach(function(l){typeof l.runWhen=="function"&&l.runWhen(e)===!1||(a=a&&l.synchronous,n.unshift(l.fulfilled,l.rejected))});var o=[];this.interceptors.response.forEach(function(l){o.push(l.fulfilled,l.rejected)});var s;if(!a){var u=[Me,void 0];for(Array.prototype.unshift.apply(u,n),u=u.concat(o),s=Promise.resolve(e);u.length;)s=s.then(u.shift(),u.shift());return s}for(var i=e;n.length;){var f=n.shift(),y=n.shift();try{i=f(i)}catch(p){y(p);break}}try{s=Me(i)}catch(p){return Promise.reject(p)}for(;o.length;)s=s.then(o.shift(),o.shift());return s},F.prototype.getUri=function(e){return e=J(this.defaults,e),hr(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},Ne.forEach(["delete","get","head","options"],function(e){F.prototype[e]=function(r,n){return this.request(J(n||{},{method:e,url:r,data:(n||{}).data}))}}),Ne.forEach(["post","put","patch"],function(e){F.prototype[e]=function(r,n,a){return this.request(J(a||{},{method:e,url:r,data:n}))}});var mr=F;function le(t){this.message=t}le.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},le.prototype.__CANCEL__=!0;var De=le,vr=De;function G(t){if(typeof t!="function")throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(a){e=a});var r=this;t(function(a){r.reason||(r.reason=new vr(a),e(r.reason))})}G.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},G.source=function(){var e,r=new G(function(a){e=a});return{token:r,cancel:e}};var yr=G,gr=function(e){return function(n){return e.apply(null,n)}},Er=function(e){return typeof e=="object"&&e.isAxiosError===!0},Fe=I,wr=ye,W=mr,Cr=_e,br=ie;function Be(t){var e=new W(t),r=wr(W.prototype.request,e);return Fe.extend(r,W.prototype,e),Fe.extend(r,e),r}var P=Be(br);P.Axios=W,P.create=function(e){return Be(Cr(P.defaults,e))},P.Cancel=De,P.CancelToken=yr,P.isCancel=Pe,P.all=function(e){return Promise.all(e)},P.spread=gr,P.isAxiosError=Er,Z.exports=P,Z.exports.default=P;var Ir=Z.exports,Rr=Object.defineProperty,Tr=(t,e,r)=>e in t?Rr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Sr=(t,e,r)=>(Tr(t,typeof e!="symbol"?e+"":e,r),r),ce=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});class Or{constructor(){Sr(this,"axios"),this.axios=Ir.create({baseURL:E.OPEN_PLATFORM_ORIGIN})}createKoutuRecord(e){return ce(this,null,function*(){const r=e.url,n=yield this.axios.get(r,{responseType:"arraybuffer"}).then(u=>u.data),{width:a,height:o}=yield new Promise(u=>{const i=document.createElement("img");i.src=r,i.onload=()=>{u({width:i.width,height:i.height})}});return(yield this.axios.post("/sdk/api/koutu-records",{url:r,size:n.byteLength,width:a,height:o},{headers:{authorization:`Bearer ${e.token}`}})).data.work_id})}koutu(e){return ce(this,null,function*(){return(yield this.axios.post("/sdk/api/koutus",{app_id:e.appId,url:e.url,ability_code:e.abilityCode,work_id:e.workId,use_cert:e.useCert},{headers:{authorization:`Bearer ${e.token}`}})).data.result})}createAuth(e){return ce(this,null,function*(){return(yield this.axios.post("/sdk/api/auths",{code:e})).data.access_token})}}var Pr=Object.defineProperty,xr=Object.defineProperties,_r=Object.getOwnPropertyDescriptors,je=Object.getOwnPropertySymbols,kr=Object.prototype.hasOwnProperty,Ar=Object.prototype.propertyIsEnumerable,ze=(t,e,r)=>e in t?Pr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qe=(t,e)=>{for(var r in e||(e={}))kr.call(e,r)&&ze(t,r,e[r]);if(je)for(var r of je(e))Ar.call(e,r)&&ze(t,r,e[r]);return t},Ke=(t,e)=>xr(t,_r(e)),x=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});function $r(t){const e=new j,r=B({appId:t.appId,container:t.container,onClose(){return x(this,null,function*(){if(t.onCloseModal&&(yield t.onCloseModal())===!1)return!1;e.emit("close")})},methods:{emit(p,...l){return x(this,null,function*(){e.emit(p,...l)})},onload(){e.emit("load")},getUseRightToken(p){return x(this,null,function*(){if(!t.getUseRightCert)return!1;const l=yield t.getUseRightCert(p);return l instanceof Error?{message:l.message}:l})},getUserCode(){return x(this,null,function*(){if(!t.authorize)return!1;try{return yield t.authorize()}catch{y()}})},download(p){return x(this,null,function*(){e.emit("save",p)})}}}),n=[];function a(){n.forEach(p=>p()),n.length=0}function o(p,l){return x(this,null,function*(){return a(),r.update(E.KOUTU_EDITOR_URL,Ke(qe({},l),{version:t.authorize?"KE002":"KE001"})),r.insert(),e.once("load",()=>x(this,null,function*(){(yield r.getService()).init({appId:t.appId,v:E.VERSION,version:t.authorize?"KE002":"KE001"});const h=typeof p=="string"?p:yield ve(p);(yield r.getService()).importFile(h)})),new Promise(d=>{n.push(e.once("save",h=>d(h))),n.push(e.once("close",()=>d(!1)))})})}function s(p,l){return x(this,null,function*(){return S(Number.isInteger(+p),`\u65E0\u6548\u7684ID ${p}`),a(),r.update(E.KOUTU_EDITOR_URL,Ke(qe({},l),{id:p,mode:"user",version:t.authorize?"KE002":"KE001"})),r.insert(),e.once("load",()=>x(this,null,function*(){const d=yield r.getService();d.init({appId:t.appId,v:E.VERSION,version:t.authorize?"KE002":"KE001"}),d.openWork(p)})),new Promise(d=>{n.push(e.once("save",h=>d(h))),n.push(e.once("close",()=>d(!1)))})})}function u(p){return x(this,null,function*(){if(S(typeof p=="string","url \u5FC5\u987B\u662F url \u683C\u5F0F"),!t.authorize||!t.getUseRightCert)throw new Error("\u7F3A\u5C11 authorize \u6216\u8005 getUseRightCert \u53C2\u6570");const l=new Or,d=yield t.authorize(),h=yield l.createAuth(d),m=yield l.createKoutuRecord({token:h,url:p}),c=yield t.getUseRightCert({abilityCode:"KE002",appId:t.appId,workId:m});if(c){if(c instanceof Error)throw c}else throw new Error("\u6CA1\u6709\u6743\u9650");return{result:yield l.koutu({url:p,appId:t.appId,workId:m,abilityCode:"KE002",useCert:c,token:h}),workId:m}})}function i(p){e.add("save",p)}function f(p){e.add("close",p)}function y(){e.emit("close"),r.remove()}return{onSave:i,onClose:f,close:y,koutu:u,editKoutu:s,importImage:o}}var _=(t,e,r)=>new Promise((n,a)=>{var o=i=>{try{u(r.next(i))}catch(f){a(f)}},s=i=>{try{u(r.throw(i))}catch(f){a(f)}},u=i=>i.done?n(i.value):Promise.resolve(i.value).then(o,s);u((r=r.apply(t,e)).next())});function Nr(t){const e=new j,r=[];function n(){r.forEach(l=>l()),r.length=0}const a=B({container:t.container,appId:t.appId,onClose(){return _(this,null,function*(){if(t.onCloseModal&&(yield t.onCloseModal())===!1)return!1;e.emit("close")})},methods:{emit(l,...d){return _(this,null,function*(){e.emit(l,...d)})},onload(){e.emit("load")},getUseRightToken(l){return _(this,null,function*(){if(!t.getUseRightCert)return!1;const d=yield t.getUseRightCert(l);return d instanceof Error?{message:d.message}:d})},getUserCode(){return _(this,null,function*(){if(!t.authorize)return!1;try{return yield t.authorize()}catch{f()}})},download(l){return _(this,null,function*(){e.emit("save",l)})}}});function o(l,d){e.on(l,d)}function s(l,d){e.off(l,d)}function u(l){return _(this,arguments,function*(d,h={}){return n(),a.update(E.IMAGE_EDITOR_URL,{version:t.authorize?"IE002":"IE001"}),a.insert(),e.once("load",()=>_(this,null,function*(){(yield a.getService()).init({appId:t.appId,v:E.VERSION,version:t.authorize?"IE002":"IE001",fileTypes:h.fileTypes,disableModules:h.disableModules});const c=yield a.getService(),v=yield Promise.all((Array.isArray(d)?d:[d]).map(g=>_(this,null,function*(){return typeof g=="string"?g:yield ve(g)})));c.importFile(v)})),new Promise(m=>{r.push(e.once("save",c=>m(c))),r.push(e.once("close",()=>m(!1)))})})}function i(l){return _(this,arguments,function*(d,h={}){return n(),a.update(E.IMAGE_EDITOR_URL,{id:d,mode:"user",version:t.authorize?"IE002":"IE001"}),a.insert(),e.once("load",()=>_(this,null,function*(){(yield a.getService()).init({appId:t.appId,v:E.VERSION,version:t.authorize?"IE002":"IE001",fileTypes:h.fileTypes,disableModules:h.disableModules})})),new Promise(m=>{r.push(e.once("save",c=>m(c))),r.push(e.once("close",()=>m(!1)))})})}function f(){e.emit("close"),a.remove()}function y(l){e.add("save",l)}function p(l){e.add("close",l)}return{editImage:i,close:f,onSave:y,onClose:p,importImage:u,on:o,off:s}}T.createImageEditor=Nr,T.createKoutuEditor=$r,T.createMobileTemplateEditor=mt,T.createTemplateEditor=ht,T.env=E,Object.defineProperty(T,"__esModule",{value:!0}),T[Symbol.toStringTag]="Module"}); //# sourceMappingURL=editor-sdk.umd.js.map