var e=function(){return(e=Object.assign||function(e){for(var n,t=1,r=arguments.length;t0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=0&&e.HANDLE_LIST.splice(t,1),window.removeEventListener("message",n,!1)},e.empty=function(){for(;e.HANDLE_LIST.length;)window.removeEventListener("message",e.HANDLE_LIST.shift(),!1)},e.parse=function(e){try{return"object"==typeof e?e:e?JSON.parse(e):e}catch(n){return console.log("Message.parse Error:",n),e}},e.HANDLE_LIST=[],e}();function i(e){return"[object Function]"==={}.toString.call(e)}var a,o,s,c,u={origin:""};function l(e,n){u[e]=n}function d(e){return u[e]}function f(e){var n=d("origin");return!!function(e,n){return e!==n&&(e.replace(/www\./i,"").toLowerCase()!==n.replace(/www\./i,"").toLowerCase()||(e.match("www.")?void 0:(l("origin",n),!1)))}(n,e.origin)&&(console.warn("postMessage 域名检查不通过",{safeOrigin:n,eventOrigin:e.origin}),!0)}!function(e){e.unknown="unknown",e.spreadsheet="s",e.writer="w",e.presentation="p",e.pdf="f"}(a||(a={})),function(e){e.wps="w",e.et="s",e.presentation="p",e.pdf="f"}(o||(o={})),function(e){e.nomal="nomal",e.simple="simple"}(s||(s={})),function(e){e[e.requestFullscreen=1]="requestFullscreen",e[e.exitFullscreen=0]="exitFullscreen"}(c||(c={}));var p,v,h,b=(p=0,function(){return p+=1}),m=function(e,n,t){void 0===t&&(t=!0);var r=n;if(!v){var i=function e(n){var t=n.clientHeight;var r=n.clientWidth;0!==t||0!==r||h?0===t&&0===r||!h||(h.disconnect(),h=null):window.ResizeObserver&&(h=new ResizeObserver(function(t){e(n)})).observe(n);v.style.cssText+="height: "+t+"px; width: "+r+"px"}.bind(null,r);(v=document.createElement("iframe")).classList.add("web-office-iframe");var a={id:"office-iframe",src:e,scrolling:"no",frameborder:"0",allowfullscreen:"allowfullscreen",webkitallowfullscreen:"true",mozallowfullscreen:"true",allow:"clipboard-read; clipboard-write"};for(var o in r?(a.style="width: "+r.clientWidth+"px; height: "+r.clientHeight+"px;",t&&window.addEventListener("resize",i)):((r=document.createElement("div")).classList.add("web-office-default-container"),function(e){var n=document.createElement("style");document.head.appendChild(n);var t=n.sheet;t.insertRule(e,t.cssRules.length)}(".web-office-default-container {position: absolute; padding: 0; margin: 0; width: 100%; height: 100%; left: 0; top: 0;}"),document.body.appendChild(r),a.style="position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;"),T&&window.visualViewport&&window.visualViewport.addEventListener("resize",w),a)v.setAttribute(o,a[o]);r.appendChild(v),v.destroy=function(){v.parentNode.removeChild(v),v=null,window.removeEventListener("resize",i),h&&(h.disconnect(),h=null)}}return v};function w(){var e=window.visualViewport,n=e.width,t=e.height,r=document.body.clientHeight-v.clientHeight;g({eventName:"visualViewportResize",data:{width:n,height:t-r}})}var g=function(e){m().contentWindow&&m().contentWindow.postMessage(JSON.stringify(e),d("origin"))};function y(e,n,t){return new Promise(function(i){var a=b(),o=function(e){if(!f(e)){var n=r.parse(e.data);n.eventName===t&&n.msgId===a&&(i(n.data),r.remove(o))}};r.add(o),g({data:e,msgId:a,eventName:n})})}var k=function(e){return y(e,"wps.jssdk.api","wps.api.reply")},j=function(e){return y(e,"api.basic","api.basic.reply")},O={idMap:{}};function I(e){return n(this,void 0,void 0,function(){var n,i,a,o,s,c,u,l,d,p;return t(this,function(t){switch(t.label){case 0:return f(e)?[2]:(n=r.parse(e.data),i=n.eventName,a=n.callbackId,o=n.data,a&&(s=O.idMap[a])?(c=s.split(":"),u=c[0],l=c[1],"api.callback"===i&&O[u]&&O[u][l]?[4,(p=O[u][l]).callback.apply(p,o.args)]:[3,2]):[3,2]);case 1:d=t.sent(),g({result:d,callbackId:a,eventName:"api.callback.reply"}),t.label=2;case 2:return[2]}})})}var E=function(e){return n(void 0,void 0,void 0,function(){function n(){return Object.keys(O.idMap).find(function(e){return O.idMap[e]===a+":"+i})}var i,a,o,s,c,u,l,d,f;return t(this,function(t){switch(t.label){case 0:return i=e.prop,a=e.parentObjId,[4,_([o=e.value])];case 1:return s=t.sent(),c=s[0],u=s[1],e.value=c[0],l=Object.keys(u)[0],d=O[a],null===o&&d&&d[i]&&((f=n())&&delete O.idMap[f],delete d[i],Object.keys(d).length||delete O[a],Object.keys(O.idMap).length||r.remove(I)),l&&(Object.keys(O.idMap).length||r.add(I),O[a]||(O[a]={}),O[a][i]={callbackId:l,callback:u[l]},(f=n())&&delete O.idMap[f],O.idMap[l]=a+":"+i),[2]}})})},x=function(i,a,o,s){return n(void 0,void 0,void 0,function(){var c,u,l,d,p,v,h,m;return t(this,function(w){switch(w.label){case 0:return c=b(),d=new Promise(function(e,n){u=e,l=n}),p={},a.args?[4,_(a.args)]:[3,2];case 1:v=w.sent(),h=v[0],m=v[1],a.args=h,p=m,w.label=2;case 2:return"api.setter"!==i?[3,4]:[4,E(a)];case 3:w.sent(),w.label=4;case 4:return function(n){var t=n[0],r=n[1];"function"==typeof(t=e({},t)).data&&(t.data=t.data());r(),g(t)}([{eventName:i,data:a,msgId:c},function(){var e=this,a=function(d){return n(e,void 0,void 0,function(){var e,n,v;return t(this,function(t){switch(t.label){case 0:return f(d)?[2]:"api.callback"===(e=r.parse(d.data)).eventName&&e.callbackId&&p[e.callbackId]?[4,p[e.callbackId].apply(p,e.data.args)]:[3,2];case 1:n=t.sent(),g({result:n,eventName:"api.callback.reply",callbackId:e.callbackId}),t.label=2;case 2:return e.eventName===i+".reply"&&e.msgId===c&&(e.error?((v=new Error("")).stack=e.error+"\n"+o,s&&s(),l(v)):u(e.result),r.remove(a)),[2]}})})};return r.add(a),d}]),[2,d]}})})};function _(e){return n(this,void 0,void 0,function(){var n,r,i,a,o,s,c,u,l,d,f;return t(this,function(t){switch(t.label){case 0:n={},r=[],i=e.slice(0),t.label=1;case 1:return i.length?(a=void 0,[4,i.shift()]):[3,13];case 2:return(o=t.sent())&&o.done?[4,o.done()]:[3,4];case 3:t.sent(),t.label=4;case 4:if(!function(e){if(!e)return!1;for(var n=e;null!==Object.getPrototypeOf(n);)n=Object.getPrototypeOf(n);return Object.getPrototypeOf(e)===n}(a))return[3,11];for(c in a={},s=[],o)s.push(c);u=0,t.label=5;case 5:return u=0?"&":"?")+y.join("&")),d&&(d.isParentFullscreen||d.isBrowserViewFullscreen)&&(document.addEventListener("fullscreenchange",F),document.addEventListener("webkitfullscreenchange",F),document.addEventListener("mozfullscreenchange",F)),r.wordOptions&&(r.wpsOptions=r.wordOptions),r.excelOptions&&(r.etOptions=r.excelOptions),r.pptOptions&&(r.wppOptions=r.pptOptions),"object"==typeof c.print){var k="wpsconfig_print";"function"==typeof c.print.subscribe&&(c[k]=c.print.subscribe,r.print={callback:k},void 0!==c.print.custom&&(r.print.custom=c.print.custom)),delete c.print}"function"==typeof c.exportPdf&&(c[k="wpsconfig_export_pdf"]=c.exportPdf,r.exportPdf={callback:k},delete c.exportPdf);return r.commandBars&&A(r.commandBars,!1),e(e({},r),{subscriptions:c})},C=function(e){void 0===e&&(e="");var n="";if(!n&&e){var t=e.toLowerCase();-1!==t.indexOf("/office/s/")&&(n=a.spreadsheet),-1!==t.indexOf("/office/w/")&&(n=a.writer),-1!==t.indexOf("/office/p/")&&(n=a.presentation),-1!==t.indexOf("/office/f/")&&(n=a.pdf)}if(!n){var r=e.match(/[\?&]type=([a-z]+)/)||[];n=o[r[1]]||""}return n};function A(e,n){void 0===n&&(n=!0);var t=e.map(function(e){var n=e.attributes;if(!Array.isArray(n)){var t=[];for(var r in n)if(n.hasOwnProperty(r)){var i={name:r,value:n[r]};t.push(i)}e.attributes=t}return e});return n&&g({data:t,eventName:"setCommandBars"}),t}var N=window.navigator.userAgent.toLowerCase(),L=/Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(N),T=/iPhone|iPod|iPad/i.test(N),P=function(){try{return-1!==window._parent.location.search.indexOf("from=wxminiprogram")}catch(e){return!1}}();function F(){var e={status:c.requestFullscreen},n=document,t=n.fullscreenElement||n.webkitFullscreenElement||n.mozFullScreenElement;e.status=t?c.requestFullscreen:c.exitFullscreen,g({data:e,eventName:"fullscreenchange"})}var D=function(){O.idMap={}};function V(){console.group("JSSDK 事件机制调整说明"),console.warn("jssdk.on、jssdk.off 和 jssdk.Application.Sub 将在后续版本中被弃用,建议使用改进后的 ApiEvent"),console.warn("具体请参考:https://wwo.wps.cn/docs/front-end/basic-usage/events/intro/"),console.groupEnd()}var R=0,B=new Set;function H(e){return R+=1,!e&&function(e){B.forEach(function(n){return n(e)})}(R),R}function M(){var e=new Error("");return(e.stack||e.message||"").split("\n").slice(2).join("\n")}function z(i,o){var s,c=this,u=o.Events,l=o.Enum,d=o.Props,p=d[0],v=d[1],h={objId:R};switch(function n(t,r,i){var a=r.slice(0);var o=function(){var r=a.shift();!r.alias&&~W.indexOf(r.prop)&&a.push(e(e({},r),{alias:r.prop+"Async"})),Object.defineProperty(t,r.alias||r.prop,{get:function(){var a=this,o=1===r.cache,s=o&&this["__"+r.prop+"CacheValue"];if(!s){var c=M(),u=H(o),l=function(){for(var n,a=[],o=0;o=0?(n.then=null,n.catch=null,s.then(function(){e(n)}).catch(function(e){return t(e)})):s.then(e,t)},n.catch=function(e){return s.catch(e)},n.Destroy=function(){return x("api.free",{objId:n.objId},"")}}var G={};var J=null,U={fileOpen:"fileOpen",tabSwitch:"tabSwitch",fileSaved:"fileSaved",fileStatus:"fileStatus",fullscreenChange:"fullscreenChange",error:"error",stage:"stage"},Z={getToken:"api.getToken",onToast:"event.toast",onHyperLinkOpen:"event.hyperLinkOpen",getClipboardData:"api.getClipboardData"};function Q(i,a,o,s,c,u,l){var d=this;void 0===o&&(o={});r.add(function(p){return n(d,void 0,void 0,function(){var n,d,v,h,b,m,w,y,k,j,O,I,E,x,_,S,C,A,N;return t(this,function(t){switch(t.label){case 0:return f(p)?[2]:(n=r.parse(p.data),d=n.eventName,v=void 0===d?"":d,h=n.data,b=void 0===h?null:h,m=n.url,w=void 0===m?null:m,-1!==["wps.jssdk.api"].indexOf(v)?[2]:"ready"!==v?[3,1]:(c.apiReadySended&&function(e){var n=[];Object.keys(G).forEach(function(t){G[t].forEach(function(r){var i=t;e.off(i,r),n.push({handle:r,eventName:i})}),delete G[t]}),n.forEach(function(e){var n=e.eventName,t=e.handle;null==J||J.ApiEvent.AddApiEventListener(n,t)})}(a),g({eventName:"setConfig",data:e(e({},o),{version:i.version})}),i.tokenData&&i.setToken(e(e({},i.tokenData),{hasRefreshTokenConfig:!!o.refreshToken})),i.iframeReady=!0,[3,15]));case 1:return"error"!==v?[3,2]:(a.emit(U.error,b),[3,15]);case 2:return"open.result"!==v?[3,3]:(void 0!==(null===(C=null==b?void 0:b.fileInfo)||void 0===C?void 0:C.officeVersion)&&(i.mainVersion=b.fileInfo.officeVersion,console.log("WebOfficeSDK Main Version: V"+i.mainVersion)),a.emit(U.fileOpen,b),[3,15]);case 3:return"api.scroll"!==v?[3,4]:(window.scrollTo(b.x,b.y),[3,15]);case 4:if(v!==Z.getToken)return[3,9];y={token:!1},t.label=5;case 5:return t.trys.push([5,7,,8]),[4,c.refreshToken()];case 6:return y=t.sent(),[3,8];case 7:return k=t.sent(),console.error("refreshToken: "+(k||"fail to get")),[3,8];case 8:return g({eventName:Z.getToken+".reply",data:y}),[3,15];case 9:if(v!==Z.getClipboardData)return[3,14];j={text:"",html:""},t.label=10;case 10:return t.trys.push([10,12,,13]),[4,c.getClipboardData()];case 11:return j=t.sent(),[3,13];case 12:return O=t.sent(),console.error("getClipboardData: "+(O||"fail to get")),[3,13];case 13:return g({eventName:Z.getClipboardData+".reply",data:j}),[3,15];case 14:v===Z.onToast?c.onToast(b):v===Z.onHyperLinkOpen?c.onHyperLinkOpen(b):"stage"===v?a.emit(U.stage,b):"event.callback"===v?(I=b.eventName,E=b.data,x=I,I===U.fullscreenChange&&(x="fullscreenchange"),"file.saved"===I&&(x=U.fileStatus),((null===(A=o.commonOptions)||void 0===A?void 0:A.isBrowserViewFullscreen)||(null===(N=o.commonOptions)||void 0===N?void 0:N.isParentFullscreen))&&"fullscreenchange"===x&&(_=E.status,S=E.isDispatchEvent,o.commonOptions.isBrowserViewFullscreen?function(e,n,t,r){0===e?n.style="position: static; width: "+t.width+"; height: "+t.height:1===e&&(n.style="position: absolute; width: 100%; height: 100%"),r&&function(e){["fullscreen","fullscreenElement"].forEach(function(n){Object.defineProperty(document,n,{get:function(){return!!e.status},configurable:!0})});var n=new CustomEvent("fullscreenchange");document.dispatchEvent(n)}({status:e})}(_,u,l,S):o.commonOptions.isParentFullscreen&&function(e,n,t){var r=document.querySelector(t),i=r&&1===r.nodeType?r:n;if(0===e){var a=document,o=a.exitFullscreen||a.mozCancelFullScreen||a.msExitFullscreen||a.webkitCancelFullScreen||a.webkitExitFullscreen;o.call(document)}else if(1===e){var s=i.requestFullscreen||i.mozRequestFullScreen||i.msRequestFullscreen||i.webkitRequestFullscreen;s.call(i)}}(_,u,o.commonOptions.isParentFullscreen)),a.emit(x,E)):"api.ready"===v&&z(i,b),t.label=15;case 15:return"function"==typeof s[v]&&s[v](i,w||b),[2]}})})})}function X(e){return new Promise(function(n){var t=function(i){f(i)||r.parse(i.data).eventName===e&&(n(),r.remove(t))};r.add(t)})}function Y(e){var a,o=this;void 0===e&&(e={}),J&&J.destroy();try{var s=S(e),c=s.subscriptions,u=void 0===c?{}:c,d=s.mount,f=void 0===d?null:d,p=s.url,v=s.refreshToken,h=s.onToast,b=s.onHyperLinkOpen,w=s.getClipboardData;l("origin",(p.match(/https*:\/\/[^\/]+/g)||[])[0]);var y=m(p,f),O=X("open.result"),I=X("api.ready"),E=f?{width:f.clientWidth+"px",height:f.clientHeight+"px"}:{width:"100vw",height:"100vh"};delete s.mount,p&&delete s.url,delete s.subscriptions;var x=(a=a||Object.create(null),{on:function(e,n){(a[e]||(a[e]=[])).push(n)},off:function(e,n){a[e]&&a[e].splice(a[e].indexOf(n)>>>0,1)},emit:function(e,n){(a[e]||[]).slice().map(function(e){e(n)}),(a["*"]||[]).slice().map(function(t){t(e,n)})}}),_={apiReadySended:!1,apiReadySendedOnce:!1},C=function(e,r,i){return n(o,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return function(e,n,t){if(G[e]){var r=!!G[e].find(function(e){return e===n});return r&&"off"===t?(x.off(e,n),G[e]=G[e].filter(function(e){return e!==n}),!!G[e].length||(G[e]=void 0,!1)):(r||"on"!==t||(G[e].push(n),x.on(e,n)),!0)}return"on"===t?(G[e]=[],G[e].push(n),!1):"off"===t||void 0}(e,r,i)?[3,2]:[4,N];case 1:n.sent(),function(e,n){var t=e.eventName,r=e.type,i=e.handle;"on"===n?x.on(t,i):x.off(t,i),"base.event"===r&&g({eventName:"basic.event",data:{eventName:t,action:n}}),V()}(function(e,n){var t=e,r="base.event";switch(t){case U.fileSaved:console.warn("fileSaved事件监听即将弃用, 推荐使用fileStatus进行文件状态的监听"),t="fileStatus";break;case U.fullscreenChange:t="fullscreenchange";break;case"error":case"fileOpen":r="callback.event"}return{eventName:t,type:r,handle:n}}(e,r),i),n.label=2;case 2:return[2]}})})};J={url:p,iframe:y,version:"1.1.18",iframeReady:!1,tokenData:null,commandBars:null,tabs:{getTabs:function(){return n(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return[4,N];case 1:return e.sent(),[2,j({api:"tab.getTabs"})]}})})},switchTab:function(e){return n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,N];case 1:return n.sent(),[2,j({api:"tab.switchTab",args:{tabKey:e}})]}})})}},setCooperUserColor:function(e){return n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,N];case 1:return n.sent(),[2,j({api:"setCooperUserColor",args:e})]}})})},setToken:function(e){return n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,N];case 1:return n.sent(),J.tokenData=e,g({eventName:"setToken",data:e}),[2]}})})},ready:function(){return n(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return _.apiReadySendedOnce?[3,2]:(_.apiReadySendedOnce=!0,[4,O]);case 1:e.sent(),_.apiReadySended=!0,g({eventName:"api.ready"}),e.label=2;case 2:return[4,I];case 3:return e.sent(),[2,new Promise(function(e){return setTimeout(function(){return e(null==J?void 0:J.Application)},0)})]}})})},destroy:function(){y.destroy(),r.empty(),J=null,B=new Set,R=0,document.removeEventListener("fullscreenchange",F),D()},save:function(){return n(this,void 0,void 0,function(){return t(this,function(e){switch(e.label){case 0:return[4,N];case 1:return e.sent(),[2,k({api:"save"})]}})})},setCommandBars:function(e){return n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,N];case 1:return n.sent(),A(e),[2]}})})},updateConfig:function(e){return void 0===e&&(e={}),n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,N];case 1:return n.sent(),e.commandBars?(console.warn("Deprecated: `updateConfig()` 方法即将废弃,请使用`setCommandBars()`代替`updateConfig()`更新`commandBars`配置。"),[4,A(e.commandBars)]):[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}})})},executeCommandBar:function(e){return n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,N];case 1:return n.sent(),A([{cmbId:e,attributes:[{name:"click",value:!0}]}]),[2]}})})},on:function(e,r){return n(this,void 0,void 0,function(){return t(this,function(n){return[2,this.ApiEvent.AddApiEventListener(e,r)]})})},off:function(e,r){return n(this,void 0,void 0,function(){return t(this,function(n){return[2,this.ApiEvent.RemoveApiEventListener(e,r)]})})},ApiEvent:{AddApiEventListener:function(e,r){return n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,C(e,r,"on")];case 1:return[2,n.sent()]}})})},RemoveApiEventListener:function(e,r){return n(this,void 0,void 0,function(){return t(this,function(n){switch(n.label){case 0:return[4,C(e,r,"off")];case 1:return[2,n.sent()]}})})}}},function(e,n,t,r,a,o){n&&i(n)&&(a.refreshToken=n,e.refreshToken={eventName:Z.getToken});o&&i(o)&&(a.getClipboardData=o,e.getClipboardData={eventName:Z.getClipboardData});t&&i(t)&&(a.onToast=t,e.onToast={eventName:Z.onToast});r&&i(r)&&(a.onHyperLinkOpen=r,e.onHyperLinkOpen={eventName:Z.onHyperLinkOpen})}(s,v,h,b,_,w),Q(J,x,s,u,_,y,E);var N=X("ready");return J}catch(e){console.error(e)}}console.log("WebOfficeSDK JS-SDK V1.1.18");var $=Object.freeze({__proto__:null,listener:Q,config:Y});window.WPS=$;var ee=Y;export default{config:Y};export{ee as config};