@koi-br/office-provider-sdk
Version:
Universal Office Provider SDK supporting WPS, OnlyOffice and more. Framework-agnostic library for React, Vue, Angular, and vanilla JavaScript / 通用 Office 提供商 SDK,支持 WPS、OnlyOffice 等多种办公套件。框架无关库,支持 React、Vue、Angular 和原生 JavaScript
5 lines • 65.1 kB
JavaScript
var ue=Object.defineProperty;var S=(s,e)=>()=>(s&&(e=s(s=0)),e);var U=(s,e)=>{for(var t in e)ue(s,t,{get:e[t],enumerable:true});};var H={};U(H,{DocumentType:()=>X,OfficeProviderType:()=>Q});var Q,X,A=S(()=>{Q=(t=>(t.WPS="wps",t.ONLYOFFICE="onlyoffice",t))(Q||{}),X=(r=>(r.WRITER="writer",r.SPREADSHEET="spreadsheet",r.PRESENTATION="presentation",r))(X||{});});function ee(s,e,t,r=1){s=Math.round(s),e=Math.round(e),t=Math.round(t);let n=Math.round(r*255),i=o=>o.toString(16).padStart(2,"0");return r<1?`#${i(s)}${i(e)}${i(t)}${i(n)}`:`#${i(s)}${i(e)}${i(t)}`}var te=S(()=>{});function $(s,e){function t(){this.constructor=s;}ne(s,e),s.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t);}function b(s,e,t,r){return new(t||(t=Promise))(function(n,i){function o(l){try{c(r.next(l));}catch(d){i(d);}}function a(l){try{c(r.throw(l));}catch(d){i(d);}}function c(l){var d;l.done?n(l.value):(d=l.value,d instanceof t?d:new t(function(f){f(d);})).then(o,a);}c((r=r.apply(s,[])).next());})}function w(s,e){var t,r,n,i,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function a(c){return function(l){return (function(d){if(t)throw new TypeError("Generator is already executing.");for(;o;)try{if(t=1,r&&(n=2&d[0]?r.return:d[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,d[1])).done)return n;switch(r=0,n&&(d=[2&d[0],n.value]),d[0]){case 0:case 1:n=d;break;case 4:return o.label++,{value:d[1],done:!1};case 5:o.label++,r=d[1],d=[0];continue;case 7:d=o.ops.pop(),o.trys.pop();continue;default:if(!(n=(n=o.trys).length>0&&n[n.length-1])&&(d[0]===6||d[0]===2)){o=0;continue}if(d[0]===3&&(!n||d[1]>n[0]&&d[1]<n[3])){o.label=d[1];break}if(d[0]===6&&o.label<n[1]){o.label=n[1],n=d;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(d);break}n[2]&&o.ops.pop(),o.trys.pop();continue}d=e.call(s,o);}catch(f){d=[6,f],r=0;}finally{t=n=0;}if(5&d[0])throw d[1];return {value:d[0]?d[1]:void 0,done:true}})([c,l])}}}function N(s){if(!s)return false;for(var e=s;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(s)===e}function be(s,e){var t=this;return e===void 0&&(e={}),new Proxy(s,g(g({},{get:function(r,n){if(Object.keys(re).includes(n)){var i=re[n];return i==="Tabs"?(function(o){var a=this;return {switchTab:function(c){return b(a,void 0,void 0,function(){return w(this,function(l){switch(l.label){case 0:return [4,o.commonApiReady()];case 1:return l.sent(),[4,o.CommonApi.Tabs.SwitchTab(c.tabKey)];case 2:return [2,l.sent()]}})})},getTabs:function(){return b(a,void 0,void 0,function(){return w(this,function(c){switch(c.label){case 0:return [4,o.commonApiReady()];case 1:return c.sent(),[4,o.CommonApi.Tabs.GetTabs()];case 2:return [2,c.sent()]}})})}}})(r):r.CommonApi?Reflect.get(r.CommonApi,i):function(){return b(t,void 0,void 0,function(){var o;return w(this,function(a){switch(a.label){case 0:return [4,r.commonApiReady()];case 1:return a.sent(),[4,r.commonApiPromise];case 2:return a.sent(),typeof r.CommonApi[i]!="function"?[3,4]:[4,r.CommonApi[i]()];case 3:return o=a.sent(),[3,5];case 4:o=r.CommonApi[i],a.label=5;case 5:return [2,o]}})})}}return Reflect.get(r,n)},set:function(r,n,i){return !!Reflect.has(r,n)&&Reflect.set(r,n,i)}}),e))}var ne,z,k,D,j,g,fe,pe,he,me,ie,ye,ve,ge,re,B,oe,v,se=S(()=>{ne=function(s,e){return (ne=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r;}||function(t,r){for(var n in r)r.hasOwnProperty(n)&&(t[n]=r[n]);})(s,e)};g=function(){return (g=Object.assign||function(s){for(var e,t=1,r=arguments.length;t<r;t++)for(var n in e=arguments[t])Object.prototype.hasOwnProperty.call(e,n)&&(s[n]=e[n]);return s}).apply(this,arguments)};((function(s){s.refreshToken="api.getToken";}))(z||(z={})),(function(s){s.unknown="unknown",s.spreadsheet="s",s.writer="w",s.presentation="p",s.pdf="f",s.otl="o",s.dbt="d",s.ksheet="k";})(k||(k={})),(function(s){s.nomal="nomal",s.simple="simple",s.embed="embed";})(D||(D={})),(function(s){s[s.requestFullscreen=1]="requestFullscreen",s[s.exitFullscreen=0]="exitFullscreen";})(j||(j={}));fe=window.navigator.userAgent.toLowerCase(),pe=/iPhone|iPod|iPad/i.test(fe);he=(function(){function s(e,t,r,n,i,o,a){var c=this;i===void 0&&(i=true),o===void 0&&(o=false),a===void 0&&(a={}),this.instance=e,this.instanceId=t,this.url=r,this.mount=n,this.isListenResize=i,this.addedStyles=o,this.customAttrs=a,this.handleResize=function(){var l=c.mount,d=c.mountResizeObserver,f=l.clientHeight,u=l.clientWidth;f!==0||u!==0||d?f===0&&u===0||!d||(d.disconnect(),d=null):window.ResizeObserver&&(d=new ResizeObserver(function(p){c.handleResize();})).observe(l),c.iframe.style.cssText+="height: "+l.clientHeight+"px; width: "+l.clientWidth+"px";},this.iframe=this.initIframe();}return s.prototype.initIframe=function(){var e=this,t=this.mount,r=document.createElement("iframe");r.classList.add("web-office-iframe");var n=this.mergeAttrs({id:"office-iframe-"+this.instanceId,src:this.url,scrolling:"no",frameborder:"0",allowfullscreen:"allowfullscreen",webkitallowfullscreen:"true",mozallowfullscreen:"true",allow:"clipboard-read; clipboard-write"});for(var i in t?(n.style="width: "+t.clientWidth+"px; height: "+t.clientHeight+"px;",this.isListenResize&&window.addEventListener("resize",this.handleResize)):((t=document.createElement("div")).classList.add("web-office-default-container"),this.addedStyles||this.addStylesheetRules(".web-office-default-container {position: absolute; padding: 0; margin: 0; width: 100vw; height: 100vh; left: 0; top: 0;}"),document.body.appendChild(t),n.style="width: 100vw; height: 100vh;"),pe&&window.visualViewport&&this.isListenResize&&window.visualViewport.addEventListener("resize",function(){var o=window.visualViewport,a=o.width,c=o.height,l=document.body.clientHeight-e.iframe.clientHeight;e.instance.sendMsgToWps({eventName:"visualViewportResize",data:{width:a,height:c-l}});}),n)r.setAttribute(i,n[i]);return t.appendChild(r),r.destroy=function(){window.removeEventListener("resize",e.handleResize),r.parentNode.removeChild(r),r=null,e.mountResizeObserver&&(e.mountResizeObserver.disconnect(),e.mountResizeObserver=null);},r},s.prototype.destroy=function(){this.iframe.parentNode.removeChild(this.iframe),window.removeEventListener("resize",this.handleResize);},s.prototype.addStylesheetRules=function(e){var t=document.createElement("style");document.head.appendChild(t);var r=t.sheet;r.insertRule(e,r.cssRules.length);},s.prototype.mergeAttrs=function(e){var t=this.customAttrs;if(t&&Object.keys(t).length&&t.allow){var r=t.allow instanceof Array?t.allow:t.allow.split(";");r.unshift("clipboard-write"),r.unshift("clipboard-read"),t.allow=r.join(";"),Object.assign(e,t);}return e},s})(),me=(function(){function s(){this.HANDLE_LIST=[];}return s.prototype.add=function(e){this.HANDLE_LIST.push(e),window.addEventListener("message",e,false);},s.prototype.remove=function(e){var t=this.HANDLE_LIST.indexOf(e);t>=0&&this.HANDLE_LIST.splice(t,1),window.removeEventListener("message",e,false);},s.prototype.empty=function(){for(;this.HANDLE_LIST.length;){var e=this.HANDLE_LIST.shift();window.removeEventListener("message",e,false);}},s.prototype.parse=function(e){try{return typeof e=="object"?e:e&&JSON.parse(e)}catch{return e}},s})(),ie=(function(){function s(e,t){var r=this;this.collectObjIdHandlers=new Set,this.polyfillApi=["ExportAsFixedFormat","GetOperatorsInfo","ImportDataIntoFields","ReplaceText","ReplaceBookmark","GetBookmarkText","GetComments"],this.getId=function(){return ""},this.setterCallbacks={idMap:{}},this.sendMsgToWps=function(){},this.objId=0,this.origin="",this.apiChannel=function(n,i,o,a){return b(r,void 0,void 0,function(){var c,l,d,f,u,p,h,m,y,I=this;return w(this,function(E){switch(E.label){case 0:return c=this.getId(),f=new Promise(function(R,P){l=R,d=P;}),u={},i.args?[4,this.reduceArgs(i.args)]:[3,2];case 1:p=E.sent(),h=p[0],m=p[1],i.args=h,u=m,E.label=2;case 2:return n!==this.prefix+"setter"?[3,4]:[4,this.handleApiSetter(i)];case 3:E.sent(),E.label=4;case 4:return y=function(){var R=function(P){return b(I,void 0,void 0,function(){var O,T,_;return w(this,function(q){switch(q.label){case 0:return this.instance.originWhiteList.includes(P.origin)||this.origin===P.origin?(O=this.message.parse(P.data)).eventName===this.prefix+"callback"&&O.callbackId&&u[O.callbackId]?[4,u[O.callbackId].apply(u,O.data.args)]:[3,2]:[2];case 1:T=q.sent(),this.sendMsgToWps({result:T,eventName:this.prefix+"callback.reply",callbackId:O.callbackId}),q.label=2;case 2:return O.eventName===n+".reply"&&O.msgId===c&&(O.error?((_=new Error("")).stack=O.error+`
`+o,a&&a(),d(_)):l(O.result),this.message.remove(R)),[2]}})})};return I.message.add(R),f},this.handleSendApiChannel([{eventName:n,data:i,msgId:c},y]),[2,f]}})})},this.handleApiSetter=function(n){return b(r,void 0,void 0,function(){var i,o,a,c,l,d,f,u,p,h,m=this;return w(this,function(y){switch(y.label){case 0:return i=function(){return Object.keys(m.setterCallbacks.idMap).find(function(I){return m.setterCallbacks.idMap[I]===a+":"+o})},o=n.prop,a=n.parentObjId,c=n.value,[4,this.reduceArgs([c])];case 1:return l=y.sent(),d=l[0],f=l[1],n.value=d[0],u=Object.keys(f)[0],p=this.setterCallbacks[a],c===null&&p&&p[o]&&((h=i())&&delete this.setterCallbacks.idMap[h],delete p[o],Object.keys(p).length||delete this.setterCallbacks[a],Object.keys(this.setterCallbacks.idMap).length||this.message.remove(this.setterCallbackSubscribe.bind(this))),u&&(Object.keys(this.setterCallbacks.idMap).length||this.message.add(this.setterCallbackSubscribe.bind(this)),this.setterCallbacks[a]||(this.setterCallbacks[a]={}),this.setterCallbacks[a][o]={callbackId:u,callback:f[u]},(h=i())&&delete this.setterCallbacks.idMap[h],this.setterCallbacks.idMap[u]=a+":"+o),[2]}})})},this.prefix=t,this.origin=e.origin,this.sendMsgToWps=e.sendMsgToWps.bind(e),this.getId=e.getId.bind(e),this.message=e.message,this.sdkInstanceId=e.instanceId,this.instance=e;}return s.prototype.destroyApplication=function(){this.collectObjIdHandlers=new Set,this.objId=0;},s.prototype.subEventHandle=function(e,t){var r=this,n={};this.message.add(function(a){return b(r,void 0,void 0,function(){var c,l,d,f,u,p;return w(this,function(h){switch(h.label){case 0:return this.instance.originWhiteList.includes(a.origin)||this.origin===a.origin?(c=this.message.parse(a.data),l=c.sdkInstanceId,c.eventName===this.prefix+"event"&&Number(l)===this.sdkInstanceId&&c.data?(d=c.data,f=d.eventName,u=d.data,(p=n[f])?[4,p(u)]:[3,2]):[3,2]):[2];case 1:h.sent(),h.label=2;case 2:return [2]}})})});var i=function(a){var c=t[a];Object.defineProperty(e,c,{set:function(l){n[c]=l,r.sendMsgToWps({eventName:r.prefix+"event.register",data:{eventName:c,register:!!l,objId:r.objId+=1},sdkInstanceId:r.sdkInstanceId});}});};for(var o in t)i(o);},s.prototype.mixinProto=function(e,t){Object.assign(e,t);},s.prototype.makeCollectObjIdHandle=function(e){var t=this;return function(){var r=[],n=function(i){r.push(i);};return t.collectObjIdHandlers.add(n),{End:function(){e(r),t.collectObjIdHandlers.delete(n);}}}},s.prototype.assign=function(e,t,r){for(var n=this,i=t.slice(0),o=function(){var c=i.shift();!c.alias&&~a.polyfillApi.indexOf(c.prop)&&i.push(g(g({},c),{alias:c.prop+"Async"})),Object.defineProperty(e,c.alias||c.prop,{get:function(){var l=c.cache===1,d=l&&e["__"+c.prop+"CacheValue"];if(!d){var f=n.getError(),u=n.createObjId(l),p=function(){for(var h,m=[],y=0;y<arguments.length;y++)m[y]=arguments[y];return c.caller!==void 0?(h={objId:n.createObjId()},n.assign(h,r[c.caller],r)):h={},n.wrapper(p,h,n.prefix+"caller",{obj:p,args:m,parentObjId:e.objId,objId:h.objId,prop:c.prop},f),h};return p.objId=-1,c.getter!==void 0&&(p.objId=u,n.assign(p,r[c.getter],r)),n.wrapper(e,p,n.prefix+"getter",{parentObjId:e.objId,objId:p.objId,prop:c.prop},f,function(){delete e["__"+c.prop+"CacheValue"];}),l&&(e["__"+c.prop+"CacheValue"]=p),p}return d},set:function(l){var d=n.getError();return n.wrapper(e,{},n.prefix+"setter",{value:l,parentObjId:e.objId,objId:-1,prop:c.prop},d)}});},a=this;i.length;)o();},s.prototype.wrapper=function(e,t,r,n,i,o){var a,c=this,l=(e.done?e.done():Promise.resolve()).then(function(){return a||(a=c.apiChannel(r,n,i,o)),a});t.done=function(){return l},t.then=function(d,f){return n.objId>=0?(t.then=null,t.catch=null,l.then(function(){d(t);}).catch(function(u){return f(u)})):l.then(d,f)},t.catch=function(d){return l.catch(d)},t.Destroy=function(){return this.apiChannel(this.prefix+"free",{objId:t.objId},"")};},s.prototype.handleSendApiChannel=function(e){var t=e[0],r=e[1];typeof(t=g({},t)).data=="function"&&(t.data=t.data()),r(),this.sendMsgToWps(t);},s.prototype.setterCallbackSubscribe=function(e){return b(this,void 0,void 0,function(){var t,r,n,i,o,a,c,l,d,f;return w(this,function(u){switch(u.label){case 0:return this.instance.originWhiteList.includes(e.origin)||this.origin===e.origin?(t=this.message.parse(e.data),r=t.eventName,n=t.callbackId,i=t.data,n&&(o=this.setterCallbacks.idMap[n])?(a=o.split(":"),c=a[0],l=a[1],r===this.prefix+"callback"&&this.setterCallbacks[c]&&this.setterCallbacks[c][l]?[4,(f=this.setterCallbacks[c][l]).callback.apply(f,i.args)]:[3,2]):[3,2]):[2];case 1:d=u.sent(),this.sendMsgToWps({result:d,callbackId:n,eventName:this.prefix+"callback.reply"}),u.label=2;case 2:return [2]}})})},s.prototype.reduceArgs=function(e){return b(this,void 0,void 0,function(){var t,r,n,i,o,a,c,l,d,f,u;return w(this,function(p){switch(p.label){case 0:t={},r=[],n=e.slice(0),p.label=1;case 1:return n.length?(i=void 0,[4,n.shift()]):[3,13];case 2:return (o=p.sent())&&o.done?[4,o.done()]:[3,4];case 3:p.sent(),p.label=4;case 4:if(!N(i))return [3,11];for(c in i={},a=[],o)a.push(c);l=0,p.label=5;case 5:return l<a.length?(d=a[l],f=o[d],/^[A-Z]/.test(d)?f&&f.done?[4,f.done()]:[3,7]:[3,8]):[3,10];case 6:p.sent(),p.label=7;case 7:f&&f.objId?f={objId:f.objId}:typeof f=="function"&&(u=this.getId(),t[u]=f,f={callbackId:u}),p.label=8;case 8:i[d]=f,p.label=9;case 9:return l++,[3,5];case 10:return [3,12];case 11:o&&o.objId?i={objId:o.objId}:typeof o=="function"&&o.objId===void 0?(u=this.getId(),t[u]=o,i={callbackId:u}):i=o,p.label=12;case 12:return r.push(i),[3,1];case 13:return [2,[r,t]]}})})},s.prototype.createObjId=function(e){return this.objId+=1,!e&&this.collectObjId(),this.objId},s.prototype.collectObjId=function(){var e=this;this.collectObjIdHandlers.forEach(function(t){return t(e.objId)});},s.prototype.getError=function(){var e=new Error("");return (e.stack||e.message||"").split(`
`).slice(2).join(`
`)},s})(),ye=(function(s){function e(t,r,n){var i=s.call(this,t,n)||this,o={},a=t.officeType,c=r.Events,l=r.Enum,d=r.Props,f=d[0],u=d[1],p={objId:i.objId};switch(i.assign(p,f,u),p.Events=c,p.Enum=l,p.Sub={},o.Enum=p.Enum,o.Events=p.Events,o.Props=d,a){case k.writer:o.WordApplication=t.WpsApplication=function(){return p};break;case k.spreadsheet:o.ExcelApplication=t.EtApplication=function(){return p};break;case k.presentation:o.PPTApplication=t.WppApplication=function(){return p};break;case k.pdf:o.PDFApplication=function(){return p};}return o.Application=p,o.Free=function(h){return i.apiChannel(i.prefix+"free",{objId:h},"")},o.Stack=p.Stack=i.makeCollectObjIdHandle(function(h){i.apiChannel(i.prefix+"free",{objId:h},"");}),o.destroyApplication=function(){i.destroyApplication();},i.subEventHandle(p.Sub,c),i.mixinProto(t,o),i}return $(e,s),e})(ie),ve=(function(s){function e(t,r,n){var i=s.call(this,t,n)||this,o={},a=r.Events,c=r.Enum,l=r.Props,d=l[0],f=l[1],u={objId:i.objId};return i.assign(u,d,f),u.Events=a,u.Enum=c,u.Sub={},o.CommonEnum=u.Enum,o.CommonEvents=u.Events,o.CommonProps=l,o.CommonApi=u,o.CommonFree=function(p){return i.apiChannel(i.prefix+"free",{objId:p},"")},o.CommonStack=u.Stack=i.makeCollectObjIdHandle(function(p){i.apiChannel(i.prefix+"free",{objId:p},"");}),o.destroyCommonApp=function(){i.destroyApplication();},i.subEventHandle(u.Sub,a),i.mixinProto(t,o),i}return $(e,s),e})(ie),ge=(function(){function s(e){var t,r=this;this.id=0,this.origin="",this.originWhiteList=[],this.realOrigin="",this.iframeWH=null,this.cbConfigsSub={},this.readyEventNames=[{event:"ready",callback:function(){r.handleBaseReady();},after:true},{event:"open.result"},{event:"api.ready",callback:function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var o=n[0];return new ye(r,o,"api."),r.Application}},{event:"commonApi.ready",callback:function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var o=n[0];return new ve(r,o,"commonApi."),r.CommonApi}}],this.cbConfigs=["refreshToken"],this.onEventNames={"open.result":"fileOpen","tab.switch":"tabSwitch","file.saved":"fileStatus",error:"error",stage:"stage"},this.polyfillConfigName=[["wpsOptions","wordOptions"],["etOptions","excelOptions"],["wppOptions","pptOptions"]],this.flag={advancedApiReadySended:false,advancedApiReadySendedJust:false,commonApiReadySended:false,commonApiReadySendedJust:false},this.baseReadyPromise=Promise.resolve(),this.fileOpenPromise=Promise.resolve(),this.advancedReadyPromise=Promise.resolve(),this.commonApiPromise=Promise.resolve(),this.iframeInstance=null,this.officeType="",this.url="",this.version="2.0.7",this.iframeReady=false,this.forceIframeResize=function(){r.iframeInstance&&r.iframeInstance.handleResize();},this.isOtherEvent=function(n){return n!==void 0&&n!==r.instanceId},this.handleBaseReady=function(){r.sendMsgToWps({eventName:"setConfig",data:g(g({},r.sdkConfig),{version:r.version})}),r.tokenData&&r.setToken(g(g({},r.tokenData),{hasRefreshTokenConfig:!!r.sdkConfig.refreshToken})),r.flag.advancedApiReadySended&&r.sendMsgToWps({eventName:"api.ready"}),r.flag.commonApiReadySended&&r.sendMsgToWps({eventName:"commonApi.ready"}),r.iframeReady=true;},this.handleFullscreenChange=function(){var n={status:j.requestFullscreen};document.fullscreenElement?n.status=j.requestFullscreen:n.status=j.exitFullscreen,r.sendMsgToWps({data:n,eventName:"fullscreenchange"});},this.instanceId=s.instanceId,s.instanceId+=1,this.message=new me,this.mittInstance=(t=t||Object.create(null),{on:function(n,i){(t[n]||(t[n]=[])).push(i);},off:function(n,i){t[n]&&t[n].splice(t[n].indexOf(i)>>>0,1);},emit:function(n,i){(t[n]||[]).slice().map(function(o){o(i);}),(t["*"]||[]).slice().map(function(o){o(n,i);});}}),this.handleConfig(e);}return s.config=function(e){return e===void 0&&(e={}),s.singleInstance||(s.singleInstance=new s(e)),s.singleInstance},s.prototype.setToken=function(e){return b(this,void 0,void 0,function(){return w(this,function(t){switch(t.label){case 0:return [4,this.basicReady()];case 1:return t.sent(),this.tokenData=e,this.sendMsgToWps({eventName:"setToken",data:e}),[2]}})})},s.prototype.advancedApiReady=function(){return b(this,void 0,void 0,function(){return w(this,function(e){switch(e.label){case 0:return this.flag.advancedApiReadySendedJust?[3,2]:(this.flag.advancedApiReadySendedJust=true,[4,this.fileOpenPromise]);case 1:e.sent(),this.flag.advancedApiReadySended||(this.flag.advancedApiReadySended=true,this.sendMsgToWps({eventName:"api.ready"})),e.label=2;case 2:return [4,this.advancedReadyPromise];case 3:return [2,e.sent()]}})})},s.prototype.commonApiReady=function(){return b(this,void 0,void 0,function(){return w(this,function(e){switch(e.label){case 0:return this.flag.commonApiReadySendedJust?[3,2]:(this.flag.commonApiReadySendedJust=true,[4,this.basicReady()]);case 1:e.sent(),this.flag.commonApiReadySended||(this.flag.commonApiReadySended=true,this.sendMsgToWps({eventName:"commonApi.ready"})),e.label=2;case 2:return [4,this.commonApiPromise];case 3:return [2,e.sent()]}})})},s.prototype.destroy=function(){this.iframeInstance.destroy(),this.message.empty(),this.destroyApplication&&this.destroyApplication(),this.destroyCommonApp&&this.destroyCommonApp(),this.removeFullscreenEventListener();},s.prototype.on=function(e,t){return b(this,void 0,void 0,function(){var r;return w(this,function(n){switch(n.label){case 0:return [4,this.basicReady()];case 1:return n.sent(),r=e,e==="fullscreenChange"&&(r="fullscreenchange"),this.handleBasicEvent(r,"on"),this.mittInstance.on(e,t),[2]}})})},s.prototype.off=function(e,t){return b(this,void 0,void 0,function(){return w(this,function(r){switch(r.label){case 0:return [4,this.basicReady()];case 1:return r.sent(),this.handleBasicEvent(e,"off"),this.mittInstance.off(e,t),[2]}})})},s.prototype.handleConfig=function(e){var t,r=this;e===void 0&&(e={});try{var n=this.userConfHandler(e),i=n.subscriptions,o=i===void 0?{}:i,a=n.mount,c=a===void 0?null:a,l=n.url,d=n.originWhiteList;this.origin=(l.match(/https*:\/\/[^\/]+/g)||[])[0],this.originWhiteList=d||[];var f=this.readyEventNames.map(function(y){return r.makeReady(y)}),u=f[0],p=f[1],h=f[2],m=f[3];this.baseReadyPromise=u,this.fileOpenPromise=p,this.advancedReadyPromise=h,this.commonApiPromise=m,this.iframeWH=c?{width:c.clientWidth+"px",height:c.clientHeight+"px"}:{width:"100vw",height:"100vh"},delete n.mount,l&&delete n.url,this.url=l,delete n.subscriptions,this.sdkConfig=n,this.iframeInstance=new he(this,this.instanceId,l,c,(t=n.isListenResize)===null||t===void 0||t,!1,{allow:n.attrAllow}),this.iframe=this.iframeInstance.iframe,this.listener(o);}catch{return null}},s.prototype.listener=function(e){var t=this;this.message.add(function(r){return b(t,void 0,void 0,function(){var n,i,o,a,c,l,d,f,u;return w(this,function(p){return n=this.message.parse(r.data),i=n.eventName,o=i===void 0?"":i,a=n.data,c=a===void 0?null:a,l=n.url,d=l===void 0?null:l,f=n.sdkInstanceId,this.isOtherEvent(f)?[2]:["wps.jssdk.api"].indexOf(o)!==-1?[2]:((u=this.handleListenEvent(o,c))?u():Object.keys(this.onEventNames).includes(o)&&(o==="open.result"&&(this.officeType=c.fileInfo.officeType),this.mittInstance.emit(this.onEventNames[o],c)),typeof e[o]=="function"&&e[o](this,d||c),[2])})})});},s.prototype.handleListenEvent=function(e,t){var r,n=this;return ((r={"api.scroll":function(){return window.scrollTo(t.x,t.y)},"event.callback":function(){return b(n,void 0,void 0,function(){var i,o,a,c,l,d,f;return w(this,function(u){return i=t.eventName,o=t.data,a=i,i==="fullScreenChange"&&(a="fullscreenChange"),(!((d=this.sdkConfig.commonOptions)===null||d===void 0)&&d.isBrowserViewFullscreen||!((f=this.sdkConfig.commonOptions)===null||f===void 0)&&f.isParentFullscreen)&&a==="fullscreenchange"&&(c=o.status,l=o.isDispatchEvent,this.sdkConfig.commonOptions.isBrowserViewFullscreen?this.iframeWH&&(function(p,h,m,y){p===0?h.style="position: static; width: "+m.width+"; height: "+m.height:p===1&&(h.style="position: absolute; width: 100%; height: 100%"),y&&(function(I){["fullscreen","fullscreenElement"].forEach(function(R){Object.defineProperty(document,R,{get:function(){return !!I.status},configurable:true});});var E=new CustomEvent("fullscreenchange");document.dispatchEvent(E);})({status:p});})(c,this.iframe,this.iframeWH,l):this.sdkConfig.commonOptions.isParentFullscreen&&(function(p,h){if(p===0){var m=document,y=m.exitFullscreen||m.mozCancelFullScreen||m.msExitFullscreen||m.webkitCancelFullScreen||m.webkitExitFullscreen;y.call(document);}else if(p===1){var I=h.requestFullscreen||h.mozRequestFullScreen||h.msRequestFullscreen||h.webkitRequestFullscreen;I.call(h);}})(c,this.iframe)),this.mittInstance.emit(a,o),[2]})})}})[z.refreshToken]=function(){return b(n,void 0,void 0,function(){var i;return w(this,function(a){switch(a.label){case 0:i={token:false},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.cbConfigsSub.refreshToken()];case 2:return i=a.sent(),[3,4];case 3:return a.sent(),[3,4];case 4:return this.sendMsgToWps({eventName:e+".reply",data:i}),[2]}})})},r)[e]},s.prototype.basicReady=function(){return this.baseReadyPromise},s.prototype.userConfHandler=function(e,t){var r=this;t===void 0&&(t=true);var n=g({},e),i=n.headers,o=i===void 0?{}:i,a=n.subscriptions,c=a===void 0?{}:a,l=n.commonOptions,d=n.url,f=d===void 0?"":d,u=n.wpsUrl,p=u===void 0?"":u,h=n.mode,m=h===void 0?D.nomal:h,y=n.debug,I=n.disablePlugins,E=n.hideGuide,R=n.readOnly;return Object.assign(n,this.handleHeadersAndSubscriptionsConfig(o,c,t)),n.url=this.handleUrlConfig(l,m,y,f,p,I,E,R),l&&(l.isParentFullscreen||l.isBrowserViewFullscreen)&&document.addEventListener("fullscreenchange",this.handleFullscreenChange),this.polyfillConfigName.map(function(P){var O=P[0],T=P[1];n[T]&&(n[O]=n[T]);}),this.cbConfigs.map(function(P){var O,T,_=n[P];_&&(O=_,T="Function",{}.toString.call(O)==="[object "+T+"]")&&(r.cbConfigsSub[P]=_,n[P]={eventName:z[P]});}),n.commandBars&&this.handleCommandBarsConfig(n.commandBars,false),g({},n)},s.prototype.handleBasicEvent=function(e,t){if(!["error","fileOpen"].includes(e)){var r={eventName:"basic.event",data:{eventName:e,action:t}};this.sendMsgToWps(r);}},s.prototype.removeFullscreenEventListener=function(){document.removeEventListener("fullscreenchange",this.handleFullscreenChange);},s.prototype.handleHeadersAndSubscriptionsConfig=function(e,t,r){var n=e.backBtn,i=n===void 0?{}:n,o=e.shareBtn,a=o===void 0?{}:o,c=e.otherMenuBtn,l=c===void 0?{}:c,d=[["wpsconfig_back_btn",i],["wpsconfig_share_btn",a],["wpsconfig_other_menu_btn",l]],f=[];return l.items&&Array.isArray(l.items)&&l.items.forEach(function(u,p){u===void 0&&(u={}),u.type==="custom"&&f.push(["wpsconfig_other_menu_btn_"+p,u]);}),d.concat(f).forEach(function(u){var p,h;p=u[1],h=u[0],p.subscribe&&typeof p.subscribe=="function"&&(p.callback=h,t[h]=p.subscribe,r&&delete p.subscribe);}),{}},s.prototype.handleUrlConfig=function(e,t,r,n,i,o,a,c){var l=[];l.push("sdkId="+this.instanceId),t===D.simple||e&&e.isShowTopArea===false?l.push("simple","hidecmb"):t===D.embed&&l.push("simple=1","hidecmb=1","embed=1"),o&&l.push("disablePlugins"),a&&l.push("hideguide"),c&&l.push("readonly"),r&&l.push("debugger");var d=n||i;return d&&l.length&&(d=d+(d.indexOf("?")>=0?"&":"?")+l.join("&")),d},s.prototype.handleCommandBarsConfig=function(e,t){t===void 0&&(t=true);var r=e.map(function(n){var i=n.attributes;if(!Array.isArray(i)){var o=[];for(var a in i)if(i.hasOwnProperty(a)){var c={name:a,value:i[a]};o.push(c);}n.attributes=o;}return n});return t&&this.sendMsgToWps({data:r,eventName:"setCommandBars"}),r},s.prototype.sendMsgToWps=function(e){var t,r,n=g(g({},e),{sdkInstanceId:this.instanceId});(r=(t=this.iframe)===null||t===void 0?void 0:t.contentWindow)===null||r===void 0||r.postMessage(JSON.stringify(n),this.realOrigin);},s.prototype.makeReady=function(e){var t=this,r=e.event,n=e.callback,i=e.after;return new Promise(function(o){var a=function(c){if(t.realOrigin=c.origin,t.originWhiteList.includes(c.origin)||t.origin===c.origin){var l=t.message.parse(c.data),d=l.eventName,f=l.data,u=l.sdkInstanceId;if(!t.isOtherEvent(u)&&d===r){var p=void 0;!i&&n&&(p=n(f)),o(p),i&&n&&n(f),r!=="ready"&&t.message.remove(a);}}};t.message.add(a);})},s.prototype.getId=function(){return this.id+=1,this.instanceId+"-"+this.id},s.instanceId=1,s})(),re={executeCommandBar:"ExecuteCommandBar",off:"Off",save:"Save",setCommandBars:"SetCommandBars",setCooperUserColor:"SetCooperUserColor",tabs:"Tabs",Stack:"Stack",WhenStacksEmpty:"WhenStacksEmpty"};(function(s){s.Spreadsheet="s",s.Writer="w",s.Presentation="p",s.Pdf="f",s.Otl="o",s.Dbt="d",s.KSheet="k";})(B||(B={}));oe=(function(s){function e(t){var r=s.call(this,t)||this;return t.token&&(N(t.token)?r.setToken(g({},t.token)):r.setToken({token:t.token})),r.ApiEvent={AddApiEventListener:function(n,i){r.on(n,i);},RemoveApiEventListener:function(n,i){r.off(n,i);}},r}return $(e,s),e.init=function(t){var r=g({},t);if(r.endpoint=r.endpoint||"https://o.wpsgo.com",typeof r.mount=="string"){var n=document.querySelector(r.mount);n?r.mount=n:delete r.mount;}if(r.url)throw Error("[WebOfficeSDK.init] \u4E0D\u652F\u6301\u4F20\u9012url\uFF0C\u8BF7\u4F7F\u7528appId\u3001fileId\u3001officeType\u3001token\u7B49\u53C2\u6570\u521D\u59CB\u5316\uFF01");if(!r.appId||!r.fileId||!r.officeType)throw Error("[WebOfficeSDK.init] appId\u3001fileId\u3001officeType\u4E3A\u5FC5\u9009\u9879\uFF01");if(typeof r.endpoint!="string")throw Error("[WebOfficeSDK.init] endpoint\u671F\u671B\u4E3A\u5B57\u7B26\u4E32");if(r.endpoint&&!r.endpoint.startsWith("http"))throw Error("[WebOfficeSDK.init] endpoint\u4EC5\u652F\u6301http\u3001https\u7684\u5730\u5740");var i=new e((function(o){var a=g({},o);a.token=a.token||a.fileToken;var c=a.appId,l=a.fileId,d=a.officeType,f=a.token,u=a.endpoint,p=a.customArgs,h=p===void 0?"":p;if(!Object.values(B).includes(d))throw Error("[WebOfficeSDK.init] officeType\u5C5E\u6027\u503C\u9519\u8BEF\uFF0C\u53EF\u9009\u503C\u53C2\u8003WebOfficeSDK.OfficeType: "+JSON.stringify(B));var m=f?1:0,y={token:""};if(typeof f=="string"?y.token=f:N(f)&&(y=g({tokenData:y},f)),m&&!y.token)return a;if(a.url=u+"/office/"+d+"/"+l+"?_w_appid="+c+"&_w_tokentype="+m,N(h)){var I=Object.entries(h).map(function(E){var R=E[0],P=E[1];return R+"="+encodeURIComponent(P)}).join("&");a.url=a.url+"&"+I;}return g({},a)})(r));return (function(o,a){b(this,void 0,void 0,function(){var c,l,d,f;return w(this,function(u){switch(u.label){case 0:return [4,o.commonApiReady()];case 1:for(l in u.sent(),c=[],a)c.push(l);d=0,u.label=2;case 2:if(!(d<c.length))return [3,11];switch(f=c[d]){case "onHyperLinkOpen":return [3,3];case "onToast":return [3,5];case "getClipboardData":return [3,7]}return [3,9];case 3:return [4,o.CommonApi.Hooks.Add("hyperLink")];case 4:return u.sent().OnAction=a[f],[3,10];case 5:return [4,o.CommonApi.Hooks.Add("toast")];case 6:return u.sent().OnAction=a[f],[3,10];case 7:return [4,o.CommonApi.Hooks.Add("getClipboardData")];case 8:return u.sent().OnAction=a[f],[3,10];case 9:return [3,10];case 10:return d++,[3,2];case 11:return [2]}})});})(i,t),be(i)},Object.defineProperty(e,"version",{get:function(){return "2.0.7"},enumerable:false,configurable:true}),e.prototype.ready=function(){return b(this,void 0,void 0,function(){return w(this,function(t){switch(t.label){case 0:return [4,this.advancedApiReady()];case 1:return [2,t.sent()]}})})},e.OfficeType=Object.freeze({Spreadsheet:"s",Writer:"w",Presentation:"p",Pdf:"f",Otl:"o",KSheet:"k",Dbt:"d"}),e})(ge);window.WPS=oe;v=oe;});var ae,we,W,V=S(()=>{te();se();ae=s=>new Promise(e=>{setTimeout(e,s);}),we=(s,e=true,t=true)=>{if(s<=0)return "";let r="";e&&(r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ"),t&&(r+="abcdefghijklmnopqrstuvwxyz"),r||(r="abcdefghijklmnopqrstuvwxyz");let n="";for(let i=0;i<s;i++){let o=Math.floor(Math.random()*r.length);n+=r.charAt(o);}return n},W=class{constructor(){this.type="wps";this.name="WPS Office";this._isReady=false;this._wpsInstance=null;this._appInstance=null;this._config=null;}get isReady(){return this._isReady}async initialize(e,t){if(this._isReady)throw new Error("WPS Provider \u5DF2\u7ECF\u521D\u59CB\u5316");let r=e;this._config=r;try{let n=await this.ensureContainer(r.containerSelector,"WPS Provider",1e4),i=l=>{if(!l)return v.OfficeType.Writer;let d={writer:v.OfficeType.Writer,w:v.OfficeType.Writer,spreadsheet:v.OfficeType.Spreadsheet,s:v.OfficeType.Spreadsheet,presentation:v.OfficeType.Presentation,p:v.OfficeType.Presentation,pdf:v.OfficeType.Pdf,f:v.OfficeType.Pdf,otl:v.OfficeType.Otl,o:v.OfficeType.Otl,dbt:v.OfficeType.Dbt,d:v.OfficeType.Dbt},f=l.toLowerCase();return d[f]||v.OfficeType.Writer},o={mode:r.simple?"simple":"normal",mount:n,officeType:i(r.officeType),appId:r.appId,fileId:r.fileId,token:r.token,refreshToken:r.refreshToken,...Object.fromEntries(Object.entries(r).filter(([l])=>!["fileId","appId","containerSelector","isReadOnly","token","simple","refreshToken","officeType","documentType"].includes(l)))};if(this._wpsInstance=v.init(o),!this._wpsInstance)throw new Error("WPS SDK \u521D\u59CB\u5316\u5931\u8D25");let a=3e4;await Promise.race([this._wpsInstance.ready(),new Promise((l,d)=>setTimeout(()=>d(new Error(`WPS ready() \u8D85\u65F6\uFF08${a}ms\uFF09`)),a))]),this._appInstance=await this._wpsInstance.Application,r.isReadOnly!==void 0&&await this.setReadOnly(r.isReadOnly);try{let l=await this._appInstance.ActiveDocument,d=0,f=30;for(;!l&&d<f;)await new Promise(u=>setTimeout(u,100)),l=await this._appInstance.ActiveDocument,d++;l&&(await l.TrackRevisions||this._wpsInstance.executeCommandBar("ReviewTrackChanges"));}catch{}if(this._isReady=!0,r.onReady)try{r.onReady(this._wpsInstance,this._appInstance);}catch{}t!=null&&t.onReady&&t.onReady(this);}catch(n){if(r.onError)try{r.onError(n);}catch{}if(t!=null&&t.onError){let i={type:"wps_error",message:n instanceof Error?n.message:"WPS\u64CD\u4F5C\u5931\u8D25",provider:"WPS",timestamp:new Date().toISOString(),originalError:n};t.onError(i);}throw n}}getWPSOfficeType(e){if(e.documentType)switch(e.documentType){case "w":case "writer":return v.OfficeType.Writer;case "s":case "spreadsheet":return v.OfficeType.Spreadsheet;case "p":case "presentation":return v.OfficeType.Presentation;case "pdf":return v.OfficeType.Pdf;default:return v.OfficeType.Writer}return v.OfficeType.Writer}async destroy(){this._wpsInstance&&(this._wpsInstance=null),this._appInstance=null,this._isReady=false;}async searchAndLocateText(e,t=false){var r,n;if(!this._appInstance||!e)return null;try{let i=(n=(r=e.split(`
`))==null?void 0:r[0])==null?void 0:n.trim(),o=await this._appInstance.ActiveDocument.Find.Execute(i,!1);if(!(o!=null&&o.length))return null;let{pos:a,len:c}=o[0],l=e.length>c?e.length:c;return t&&await this.highlightText(a,l),{pos:a,length:l,text:i,found:!0}}catch{return null}}async insertTextAtCursor(e){if(!this._wpsInstance)return false;try{let t=await this._appInstance.ActiveDocument.ActiveWindow.Selection;return t?(await t.InsertAfter(e),!0):!1}catch{return false}}async replaceText(e,t,r){if(!this._wpsInstance)return false;try{return (await this.replaceOriginalContent("",r,e,t)).success}catch{return false}}async highlightText(e,t){if(!this._appInstance)return false;try{return await this.clearHighlight(),await this.highlightByRange(e,t),!0}catch{return false}}async clearHighlight(){var e,t,r,n;this._appInstance&&(await((t=(e=this._appInstance.ActiveDocument)==null?void 0:e.Range(0,0))==null?void 0:t.SetRange(0,0)),(n=(r=this._appInstance.ActiveDocument)==null?void 0:r.Find)==null||n.ClearHitHighlight());}async setReadOnly(e){var t;this._appInstance&&await((t=this._appInstance.ActiveDocument)==null?void 0:t.SetReadOnly(e));}async saveDocument(){if(!this._wpsInstance)return false;try{return await this._appInstance.ActiveDocument.Save(),!0}catch{return false}}async getDocumentLength(){if(!this._appInstance)return 0;try{return await(await this._appInstance.ActiveDocument.GetDocumentRange()).End-1}catch{return 0}}async formatDocumentFont(e){if(!this._appInstance)return false;try{let t=await this.getDocumentLength(),r=this._appInstance.ActiveDocument.Range(0,t);e.name&&(r.Font.Name=e.name),e.size&&(r.Font.Size=e.size),e.bold!==void 0&&(r.Font.Bold=e.bold),e.italic!==void 0&&(r.Font.Italic=e.italic),e.color&&(r.Font.Color=e.color),await ae(300);let n=new Date().getTime(),i=await this.getLatestRevisionDate();if(n-new Date(i).getTime()<=2e3){let o=await this.getRevisions(i);await this.handleRevisions(o.map(a=>a.index),"accept");}return !0}catch{return false}}async getRevisions(e){if(!this._wpsInstance)return [];try{let t=await this._appInstance.ActiveDocument.Revisions,r=await t.Count,n=[];for(let i=1;i<=r;i++){let o=await t.Item(i),a=await o.Range,c=await a.Start,l=await a.End,d=await a.Text,f=await o.Date;n.push({index:i,text:d,date:f,start:c,end:l,author:"Unknown",type:"insert"});}return e?n.filter(i=>i.date===e).sort((i,o)=>o.index-i.index):n}catch{return []}}async handleRevisions(e,t){if(!this._wpsInstance)return false;try{let r=await this._appInstance.ActiveDocument.Revisions;for(let n of e)try{let i=await r.Item(n);t==="accept"?await i.Accept():await i.Reject(),await ae(300);}catch{}return !0}catch{return false}}getNativeInstance(){return {wpsInstance:this._wpsInstance,appInstance:this._appInstance}}async handleRevisionContent(e,t=false){var r;if(!(!this._wpsInstance||!e))try{let n=await this.getRevisions(e);if(t){let i=n.map(o=>o.index);await this.handleRevisions(i,"reject");}else {let i=(r=n.filter(o=>o.text.trim()))==null?void 0:r[0];if(!i)return;await this.highlightText(i.start,i.text.length);}}catch{}}getWPSApplication(){if(!this._appInstance)throw new Error("WPS\u5E94\u7528\u7A0B\u5E8F\u5B9E\u4F8B\u5C1A\u672A\u51C6\u5907\u5C31\u7EEA");return this._appInstance}getWPSInstance(){return this._wpsInstance}async highlightByRange(e,t){var r,n,i,o,a,c,l,d,f;if(!this._appInstance)return {pos:e,length:t};try{let u=(i=(n=(r=this._appInstance)==null?void 0:r.ActiveDocument)==null?void 0:n.Range)==null?void 0:i.SetRange(e,e+t);return await((c=(a=(o=this._appInstance)==null?void 0:o.ActiveDocument)==null?void 0:a.ActiveWindow)==null?void 0:c.ScrollIntoView(u)),(f=(d=(l=this._appInstance)==null?void 0:l.ActiveDocument)==null?void 0:d.Range)==null||f.SetRange(e,e+t),{pos:e,length:t}}catch{return {pos:e,length:t}}}async replaceOriginalContent(e="",t="",r,n){if(!this._wpsInstance)return {success:false,modifyDate:""};try{let i=await this._appInstance.ActiveDocument.Bookmarks,o=we(8);await i.Add({Name:o,Range:{Start:r,End:r+n}});let a=await i.ReplaceBookmark([{name:o,type:"text",value:t}]),c=await this.getLatestRevisionDate();return {success:a,modifyDate:c}}catch{return {success:false,modifyDate:""}}}async collectRevisionInfos(e,t){let r=[];for(let n=1;n<=t;n++)try{let i=await(e==null?void 0:e.Item(n)),o=await i.Range,a=await o.Start,c=await o.End,l=await o.Text,d=await i.Date;r.push({index:n,text:l,date:d,start:a,end:c,author:"Unknown",type:"insert"});}catch{}return r}checkWPSReady(){return !!(this._isReady&&this._wpsInstance&&this._appInstance)}generateRandomString(e){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",r="";for(let n=0;n<e;n++)r+=t.charAt(Math.floor(Math.random()*t.length));return r}async ensureContainer(e,t,r){return new Promise((n,i)=>{let o=Date.now(),a=()=>{let c=document.querySelector(e);if(c){n(c);return}if(Date.now()-o>=r){n(null);return}setTimeout(a,100);};a();})}async getLatestRevisionDate(){var e,t;try{let r=await((t=(e=this._appInstance)==null?void 0:e.ActiveDocument)==null?void 0:t.Revisions),n=await(r==null?void 0:r.Count);if(n>0){let i=null;for(let o=1;o<=n;o++){let c=await(await r.Item(o)).Date;(!i||c>i)&&(i=c);}return i||""}}catch{}return ""}async addContentControl(e){let r=await(await this._appInstance.ActiveDocument.ContentControls).Add();return r.Tag=e.fieldId,e.placeholderText&&r.SetPlaceholderText({Text:e.placeholderText}),true}async setContentControlValue(e,t){let r=await this._appInstance.ActiveDocument.ContentControls,n=await r.Count;for(let i=1;i<=n;i++){let o=await r.Item(i);if(await o.Tag===e){let c=await o.Range;return c.Text=t||"",true}}return false}async removeContentControl(e){return false}async setControlsHighlight(e){let t=await this._appInstance.ActiveDocument.ContentControls,r=await t.Count;for(let n=1;n<=r;n++){let a=await(await(await t.Item(n)).Range).Font,c=ee(e[0],e[1],e[2],e[3]);a.HighLight=c;}return true}async zoomFitToWidth(){return this._wpsInstance?(this._appInstance.ActiveDocument.ActiveWindow.View.Zoom.PageFit=2,true):false}async getCommentsList(){return this._wpsInstance?await this._appInstance.ActiveDocument.GetComments({Offset:0,Limit:1e3}):[]}async locateByText(e){return await this.searchAndLocateText(e.text,true)!==null}async searchAndReplace(e){if(!this._wpsInstance)return false;let t=await this.searchAndLocateText(e.old,false);return !t||typeof t=="boolean"?false:(await this.replaceText(t.pos,t.length,e.new),true)}async handleRevisionByText(e,t){if(!this._wpsInstance)return false;try{let r=await this.getRevisions();for(let n of r){let{index:i,start:o,end:a,text:c}=n;if(c===e){let l=await r.find(d=>(d.start>=o&&d.start<=a||d.end>=o&&d.end<=a)&&d.index!==i);return await this.handleRevisions([l==null?void 0:l.index,i].filter(Boolean),t),!0}}return !1}catch{return false}}async acceptReviewByText(e){return this.handleRevisionByText(e.new,"accept")}async rejectReviewByText(e){return this.handleRevisionByText(e.new,"reject")}async viewScrollToY(e){return this._wpsInstance?(await this._appInstance.ActiveDocument.ScrollTo({ScrollLeft:0,ScrollTop:e}),true):false}async jumpCommentDto(e,t){return false}};});var M,G=S(()=>{M=class{constructor(){this.type="onlyoffice";this.name="OnlyOffice";this._isReady=false;this._config=null;this._container=null;this._iframe=null;this._docEditor=null;this._vueComponent=null;this._integrationMode="auto";this._messageHandlers=new Map;this._pendingRequests=new Map;this._requestId=0;this._userOnError=null;this._userOnReady=null;this._editorReadyResolve=null;this._editorReadyReject=null;this._timeouts={editorInitTimeout:3e5,methodCallTimeout:3e5,containerTimeout:3e5};}get isReady(){return this._isReady}async initialize(e,t){if(this._isReady)throw new Error("OnlyOffice Provider \u5DF2\u7ECF\u521D\u59CB\u5316");let r=e;this._config=r,r.timeouts&&(this._timeouts={...this._timeouts,...r.timeouts}),this._userOnError=r.onError||null,this._userOnReady=r.onReady||null;try{if(this._integrationMode=this.determineIntegrationMode(r),this._integrationMode==="vue-component"?await this.initializeVueComponentMode(r,t):await this.initializeIframeMode(r,t),this._userOnReady)try{let n;this._integrationMode==="vue-component"&&r.vueComponentInstance?n=r.vueComponentInstance:this._integrationMode==="vue-component"&&r.editorInstance?n=r.editorInstance:n={documentServerUrl:r.documentServerUrl,documentKey:r.fileId,integrationMode:this._integrationMode,provider:this,iframe:this._iframe,docEditor:this._docEditor},this._userOnReady(n);}catch{}if(t!=null&&t.onReady)try{t.onReady(this);}catch{}}catch(n){if(this._userOnError)try{this._userOnError(n);}catch{}if(t!=null&&t.onError)try{t.onError(n);}catch{}throw n}}async destroy(){if(this._docEditor){try{this._docEditor.destroyEditor();}catch{}this._docEditor=null;}window.removeEventListener("message",this.handleMessage.bind(this)),window.removeEventListener("error",this.handleGlobalError.bind(this)),window.removeEventListener("unhandledrejection",this.handleUnhandledRejection.bind(this)),this._pendingRequests.forEach(({reject:e,timeout:t})=>{clearTimeout(t),e(new Error("Provider \u5DF2\u9500\u6BC1"));}),this._pendingRequests.clear(),this._messageHandlers.clear(),this._iframe=null,this._container=null,this._isReady=false;}setupMessageListener(){window.addEventListener("message",this.handleMessage.bind(this)),window.addEventListener("error",this.handleGlobalError.bind(this)),window.addEventListener("unhandledrejection",this.handleUnhandledRejection.bind(this));}handleGlobalError(e){var t,r,n;if((t=e.filename)!=null&&t.includes("api.js")||(r=e.message)!=null&&r.includes("OnlyOffice")||(n=e.message)!=null&&n.includes("DocEditor")){let i={message:e.message,filename:e.filename,lineno:e.lineno,colno:e.colno,type:"global_error",provider:"OnlyOffice",timestamp:new Date().toISOString()};if(this._userOnError)try{this._userOnError(i);}catch{}}}handleUnhandledRejection(e){var r,n,i;let t=e.reason;if((r=t==null?void 0:t.message)!=null&&r.includes("OnlyOffice")||(n=t==null?void 0:t.stack)!=null&&n.includes("api.js")||(i=t==null?void 0:t.stack)!=null&&i.includes("DocEditor")){let o={message:(t==null?void 0:t.message)||"\u672A\u5904\u7406\u7684 Promise \u62D2\u7EDD",stack:t==null?void 0:t.stack,type:"unhandled_rejection",provider:"OnlyOffice",timestamp:new Date().toISOString(),reason:t};if(this._userOnError)try{this._userOnError(o);}catch{}}}handleMessage(e){if(!this._iframe||e.source!==this._iframe.contentWindow)return;let t=e.data;if(t&&typeof t=="object"){if(t.type==="onMethodReturn"&&t.requestId){let r=this._pendingRequests.get(t.requestId);if(r)if(clearTimeout(r.timeout),this._pendingRequests.delete(t.requestId),t.error){let n={message:t.error,type:"method_call_error",requestId:t.requestId,timestamp:new Date().toISOString()};if(this._userOnError)try{this._userOnError(n);}catch{}r.reject(new Error(t.error));}else r.resolve(t.result);}if(t.type==="onEvent"){let r=this._messageHandlers.get(t.eventName);if(r&&r(t.data),t.eventName==="onError"&&this._userOnError)try{this._userOnError({...t.data,type:"iframe_error",provider:"OnlyOffice",timestamp:new Date().toISOString()});}catch{}}if(t.error||t.type==="error"){let r={message:t.error||t.message||"\u672A\u77E5\u9519\u8BEF",type:"iframe_message_error",data:t,timestamp:new Date().toISOString()};if(this._userOnError)try{this._userOnError(r);}catch{}}}}findEditorIframe(){if(!this._container)return;let e=document.getElementsByName("frameEditor")[0];if(e&&e.contentWindow)this._iframe=e;else {let t=this._container.querySelector("iframe");t&&t.contentWindow&&(this._iframe=t);}}sendMessage(e,t){return new Promise((r,n)=>{if(!this._iframe||!this._iframe.contentWindow){n(new Error("OnlyOffice iframe \u672A\u627E\u5230\u6216\u672A\u51C6\u5907\u5C31\u7EEA"));return}let i=`req_${++this._requestId}`,o;typeof e=="string"?o={type:"callMethod",methodName:e,params:t}:o={type:e.type||"callMethod",...e};let a=setTimeout(()=>{this._pendingRequests.delete(i),n(new Error(`\u8C03\u7528 ${o.methodName||o.type} \u8D85\u65F6 (${this._timeouts.methodCallTimeout/1e3}\u79D2)`));},this._timeouts.methodCallTimeout);this._pendingRequests.set(i,{resolve:r,reject:n,timeout:a}),this._iframe.contentWindow.postMessage({...o,requestId:i},"*"),window.addEventListener("message",function c(l){l.data.requestId===i&&(window.removeEventListener("message",c),r(l.data.result));});})}sendMessageNoResponse(e,t=[]){if(!this._iframe||!this._iframe.contentWindow)return;let r;typeof e=="string"?r={type:"callMethod",methodName:e,params:t}:r={type:e.type||"callMethod",...e},this._iframe.contentWindow.postMessage(r,"*");}async searchAndLocateText(e,t=false){return e?await this.locateByText({text:e}):null}async setReadOnly(e){try{await this.sendMessage("asc_SetReadOnly",[e]);}catch{}}async saveDocument(){try{return await this.sendMessage("saveDocument"),!0}catch{return false}}getNativeInstance(){return {docEditor:this._docEditor,iframe:this._iframe,container:this._container,sendMessage:this.sendMessage.bind(this),sendMessageNoResponse:this.sendMessageNoResponse.bind(this)}}async addContentControl(e){try{return await this.sendMessage("asc_AddContentControl",[2,{Tag:e.fieldId,PlaceHolderText:e.placeholderText||"\u8BF7\u8F93\u5165\u5185\u5BB9"}]),!0}catch{return false}}async setContentControlValue(e,t){try{return await this.sendMessage("custom_SetControlValueByTag",[e,t]),!0}catch{return false}}async setControlsHighlight(e){try{return await this.sendMessage("setControlsHighlight",e),!0}catch{return false}}async zoomFitToWidth(){try{return await this.sendMessage({type:"zoomFitToWidth"})||null}catch{return null}}async getCommentsList(e){try{return await this.sendMessage({type:"GetCommentsList",data:e})||null}catch{return null}}async jumpCommentDto(e,t){try{return await this.sendMessage({type:"JumpCommentDto",data:e,key:t}),!0}catch{return false}}async removeContentControl(e){try{return await this.sendMessage("asc_RemoveContentControl",[e]),!0}catch{return false}}async locateByText(e){try{return await this.sendMessage({type:"locateByText",params:{text:e.text}}),!0}catch{return false}}async searchAndReplace(e){try{return await this.sendMessage({type:"SearchAndReplace",params:{old:e.old,new:e.new}}),!0}catch{return false}}async rejectReviewByText(e){try{return await this.sendMessage({type:"rejectReviewByText",params:{old:e.old,new:e.new}}),!0}catch{return false}}async viewScrollToY(e){try{let t=await this.sendMessage({type:"ViewScrollToY",params:e});return !0}catch{return false}}async ensureContainer(e,t,r){return new Promise((n,i)=>{let o=Date.now(),a=()=>{let c=document.querySelector(e);if(c){n(c);return}if(Date.now()-o>=r){n(null);return}setTimeout(a,100);};a();})}determineIntegrationMode(e){if(e.integrationMode&&e.integrationMode!=="auto")return e.integrationMode;if(e.vueComponentInstance||e.editorInstance)return "vue-component";let t=document.querySelector(e.containerSelector);return t&&t.querySelector('iframe[name="frameEditor"]')?"vue-component":"iframe"}async initializeVueComponentMode(e,t){e.vueComponentInstance?this._vueComponent=e.vueComponentInstance:e.editorInstance?this._docEditor=e.editorInstance:await this.findExistingEditor(e),this.setupMessageListener(),this.findEditorIframe(),await this.waitForEditorReady(e,t),this._isReady=true;}async initializeIframeMode(e,t){if(this._container=await this.ensureContainer(e.containerSelector,"OnlyOffice iframe \u6A21\u5F0F",this._timeouts.containerTimeout),!this._container)throw new Error("\u5BB9\u5668\u5143\u7D20\u672A\u627E\u5230");this._container.id||(this._container.id="onlyoffice-editor-"+Date.now()),await this.loadOnlyOfficeScript(e.documentServerUrl);let r=this.buildEditorConfig(e);this.setupMessageListener(),this._docEditor=new window.DocsAPI.DocEditor(this._container.id,r),await this.waitForEditorReady(e,t),this._isReady=true;}async findExistingEditor(e){this._container=await this.ensureContainer(e.containerSelector,"OnlyOffice \u67E5\u627E\u73B0\u6709\u7F16\u8F91\u5668",this._timeouts.containerTimeout);let t=this._container;if(t.__vue__){let r=t.__vue__;this._vueComponent=r;}else if(t._vnode){let r=t._vnode;r&&r.component&&(this._vueComponent=r.component);}}waitForEditorReady(e,t){return new Promise((r,n)=>{let i=setTimeout(()=>{let c=`OnlyOffice \u521D\u59CB\u5316\u8D85\u65F6 (${this._timeouts.editorInitTimeout/1e3}\u79D2) - \u96C6\u6210\u6A21\u5F0F: ${this._integrationMode}`;this._editorReadyResolve=null,this._editorReadyReject=null,n(new Error(c));},this._timeouts.editorInitTimeout),o=()=>{clearTimeout(i),this.findEditorIframe(),this._iframe,this._editorReadyResolve=null,this._editorReadyReject=null,r();},a=c=>{if(clearTimeout(i),this._editorReadyResolve=null,this._editorReadyReject=null,this._userOnError)try{this._userOnError({...c,type:"editor_ready_error",provider:"OnlyOffice",timestamp:new Date().toISOString()});}catch{}n(c);};if(this._integrationMode==="vue-component"){let c=0,l=300,d=()=>{if(c++,!this._container){a(new Error("\u5BB9\u5668\u5143\u7D20\u672A\u627E\u