"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var extendStatics=function(e,t){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function __extends(e,t){function n(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var __assign=function(){return(__assign=Object.assign||function(e){for(var t,n=1,r=arguments.length;n=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,n,i):a(t,n))||i);return o>3&&i&&Object.defineProperty(t,n,i),i}function __param(e,t){return function(n,r){t(n,r,e)}}function __metadata(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function __awaiter(e,t,n,r){return new(n||(n=Promise))(function(a,o){function i(e){try{c(r.next(e))}catch(e){o(e)}}function s(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){e.done?a(e.value):new n(function(t){t(e.value)}).then(i,s)}c((r=r.apply(e,t||[])).next())})}function __generator(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=(a=i.trys).length>0&&a[a.length-1])&&(6===o[0]||2===o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function __read(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i}function __spread(){for(var e=[],t=0;t1||s(e,t)})})}function s(e,t){try{(n=a[e](t)).value instanceof __await?Promise.resolve(n.value.v).then(c,u):f(o[0][2],n)}catch(e){f(o[0][3],e)}var n}function c(e){s("next",e)}function u(e){s("throw",e)}function f(e,t){e(t),o.shift(),o.length&&s(o[0][0],o[0][1])}}function __asyncDelegator(e){var t,n;return t={},r("next"),r("throw",function(e){throw e}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,a){t[r]=e[r]?function(t){return(n=!n)?{value:__await(e[r](t)),done:"return"===r}:a?a(t):t}:a}}function __asyncValues(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise(function(r,a){(function(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)})(r,a,(t=e[n](t)).done,t.value)})}}}function __makeTemplateObject(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function __importStar(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function __importDefault(e){return e&&e.__esModule?e:{default:e}}var tslib_1=Object.freeze({__extends:__extends,get __assign(){return __assign},__rest:__rest,__decorate:__decorate,__param:__param,__metadata:__metadata,__awaiter:__awaiter,__generator:__generator,__exportStar:__exportStar,__values:__values,__read:__read,__spread:__spread,__await:__await,__asyncGenerator:__asyncGenerator,__asyncDelegator:__asyncDelegator,__asyncValues:__asyncValues,__makeTemplateObject:__makeTemplateObject,__importStar:__importStar,__importDefault:__importDefault}),Message=function(){function e(){}return e.add=function(t){e._handleList.push(t),window.addEventListener("message",t,!1)},e.remove=function(t){var n=e._handleList.indexOf(t);n>=0&&e._handleList.splice(n,1),window.removeEventListener("message",t,!1)},e.empty=function(){for(;e._handleList.length;)window.removeEventListener("message",e._handleList.shift(),!1)},e.parse=function(e){return"object"==typeof e?e:JSON.parse(e)},e._handleList=[],e}();function isPlainObject(e){if(!e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function addStylesheetRules(e){var t=document.createElement("style");document.head.appendChild(t);var n=t.sheet;n.insertRule(e,n.cssRules.length)}var officeTypes,officeNameTypes,modeTypes,_this=this;!function(e){e.unknown="unknown",e.spreadsheet="s",e.writer="w",e.presentation="p",e.pdf="f"}(officeTypes||(officeTypes={})),function(e){e.wps="w",e.et="s",e.presentation="p",e.pdf="f"}(officeNameTypes||(officeNameTypes={})),function(e){e.nomal="nomal",e.simple="simple"}(modeTypes||(modeTypes={}));var iframe,getId=function(e){return function(){return++e}}(0),getIframe=function(e,t){if(!iframe){(iframe=document.createElement("iframe")).classList.add("web-office-iframe");var n={id:"office-iframe",src:e,scrolling:"no",frameborder:"0",allowfullscreen:"allowfullscreen",webkitallowfullscreen:"true",mozallowfullscreen:"true",style:"width: 100%; height: 100%;"};for(var r in t||((t=document.createElement("div")).classList.add("web-office-default-container"),addStylesheetRules(".web-office-default-container {position: absolute; padding: 0; margin: 0; width: 100vw; height: 100vh; left: 0; top: 0;}"),document.body.appendChild(t)),n)iframe.setAttribute(r,n[r]);t.appendChild(iframe),iframe.destroy=function(){iframe.parentNode.removeChild(iframe),iframe=null}}return iframe},sendMsgToWps=function(e){getIframe().contentWindow.postMessage(JSON.stringify(e),"*")},apiChannelOld=function(e){return new Promise(function(t){var n=getId(),r=function(e){var a=Message.parse(e.data);"wps.api.reply"===a.eventName&&a.msgId===n&&(t(a.data),Message.remove(r))};Message.add(r),sendMsgToWps({eventName:"wps.jssdk.api",data:e,msgId:n})})},apiChannel=function(e,t,n,r){return __awaiter(_this,void 0,void 0,function(){var a,o,i,s,c,u,f,l;return __generator(this,function(p){switch(p.label){case 0:return a=getId(),s=new Promise(function(e,t){o=e,i=t}),c={},t.args?[4,reduceArgs(t.args)]:[3,2];case 1:u=p.sent(),f=u[0],l=u[1],t.args=f,c=l,p.label=2;case 2:return handleSendApiChannel([{eventName:e,data:t,msgId:a},function(){var t=this,u=function(s){return __awaiter(t,void 0,void 0,function(){var t,f,l;return __generator(this,function(p){switch(p.label){case 0:return"api.callback"===(t=Message.parse(s.data)).eventName&&t.callbackId&&c[t.callbackId]?[4,c[t.callbackId].apply(c,t.data.args)]:[3,2];case 1:f=p.sent(),sendMsgToWps({eventName:"api.callback.reply",result:f,callbackId:t.callbackId}),p.label=2;case 2:return t.eventName===e+".reply"&&t.msgId===a&&(t.error?((l=new Error("")).stack=t.error+"\n"+n,r&&r(),i(l)):o(t.result),Message.remove(u)),[2]}})})};return Message.add(u),s}]),[2,s]}})})};function reduceArgs(e){return __awaiter(this,void 0,void 0,function(){var t,n,r,a,o,i,s;return __generator(this,function(c){switch(c.label){case 0:t={},n=[],e=e.slice(0),c.label=1;case 1:return e.length?(r=void 0,[4,e.shift()]):[3,3];case 2:if(a=c.sent(),isPlainObject(r))for(o in r={},a)"function"==typeof(i=a[o])&&(s=getId(),t[s]=i,i={callbackId:s}),r[o]=i;else"function"==typeof a?(s=getId(),t[s]=a,r={callbackId:s}):r=a;return n.push(r),[3,1];case 3:return[2,[n,t]]}})})}function handleSendApiChannel(e){var t=e[0],n=e[1];"function"==typeof(t=__assign({},t)).data&&(t.data=t.data()),n(),sendMsgToWps(t)}var userConfHandler=function(e,t){void 0===t&&(t=!0);var n=__assign({},e),r=n.headers,a=void 0===r?{}:r,o=n.subscriptions,i=void 0===o?{}:o,s=n.mode,c=void 0===s?modeTypes.nomal:s,u=a.backBtn,f=void 0===u?{}:u,l=a.shareBtn,p=void 0===l?{}:l,d=a.otherMenuBtn,_=void 0===d?{}:d,m=function(e,n){e.subscribe&&"function"==typeof e.subscribe&&(e.callback=n,i[n]=e.subscribe,t&&delete e.subscribe)};if(m(f,"wpsconfig_back_btn"),m(p,"wpsconfig_share_btn"),m(_,"wpsconfig_other_menu_btn"),_.items&&Array.isArray(_.items)){var v=[];_.items.forEach(function(e,t){switch(void 0===e&&(e={}),e.type){case"export_img":e.type=1,e.callback="export_img";break;case"export_pdf":e.type=1,e.callback="export_pdf";break;case"save_version":e.type=1,e.callback="save_version";break;case"about_wps":e.type=1,e.callback="about_wps";break;case"split_line":e.type=2;break;case"custom":e.type=3,m(e,"wpsconfig_other_menu_btn_"+t),v.push(e)}}),v.length&&(isMobile||isInMiniProgram)&&(_.items=v)}if(n.url=n.url||n.wpsUrl,(c===modeTypes.simple||n.commonOptions&&!1===n.commonOptions.isShowTopArea)&&n.url&&(n.url+="&simple&hidecmb"),n.debug&&n.url&&(n.url+="&debugger"),n.wordOptions&&(n.wpsOptions=n.wordOptions),n.excelOptions&&(n.etOptions=n.excelOptions),n.pptOptions&&(n.wppOptions=n.pptOptions),"object"==typeof i.print){var b="wpsconfig_print";"function"==typeof i.print.subscribe&&(i[b]=i.print.subscribe,n.print={callback:b},void 0!==i.print.custom&&(n.print.custom=i.print.custom)),delete i.print}"function"==typeof i.exportPdf&&(i[b="wpsconfig_export_pdf"]=i.exportPdf,n.exportPdf={callback:b},delete i.exportPdf);return __assign({},n,{subscriptions:i})},getOfficeType=function(e){void 0===e&&(e="");var t="";if(!t&&e){var n=e.toLowerCase();-1!==n.indexOf("/office/s/")&&(t=officeTypes.spreadsheet),-1!==n.indexOf("/office/w/")&&(t=officeTypes.writer),-1!==n.indexOf("/office/p/")&&(t=officeTypes.presentation),-1!==n.indexOf("/office/f/")&&(t=officeTypes.pdf)}if(!t){var r=e.match(/[\?&]type=([a-z]+)/)||[];t=officeNameTypes[r[1]]||""}return t};function setCommandBars(e,t){void 0===t&&(t=!0);var n=e.map(function(e){var t=e.attributes;if(!Array.isArray(t)){var n=[];for(var r in t)if(t.hasOwnProperty(r)){var a={name:r,value:t[r]};n.push(a)}e.attributes=n}return e});return t&&sendMsgToWps({eventName:"setCommandBars",data:n}),n}var MsoTriState,agent=window.navigator.userAgent.toLowerCase(),isMobile=/Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(agent),isInMiniProgram=function(){try{return-1!==window._parent.location.search.indexOf("from=wxminiprogram")}catch(e){return!1}}();function mitt(e){return e=e||Object.create(null),{on:function(t,n){(e[t]||(e[t]=[])).push(n)},off:function(t,n){e[t]&&e[t].splice(e[t].indexOf(n)>>>0,1)},emit:function(t,n){(e[t]||[]).slice().map(function(e){e(n)}),(e["*"]||[]).slice().map(function(e){e(t,n)})}}}!function(e){e[e.msoFalse=0]="msoFalse",e[e.msoTrue=-1]="msoTrue"}(MsoTriState||(MsoTriState={}));var objId=0,collectObjIdHandlers=new Set;function createObjId(e){return++objId,!e&&collectObjId(objId),objId}function collectObjId(e){collectObjIdHandlers.forEach(function(t){return t(e)})}function makeCollectObjIdHandle(e){return function(){var t=[],n=function(e){t.push(e)};return collectObjIdHandlers.add(n),{End:function(){e(t),collectObjIdHandlers.delete(n)}}}}function destroyApplication(){collectObjIdHandlers=new Set,objId=0}function initApplication(e,t){var n=this,r=t.Events,a=t.Enum,o=t.Props,i=o[0],s=o[1],c={objId:objId};switch(assign(c,i,s),c.Events=r,c.Enum=a,e.Enum=c.Enum,e.Events=c.Events,getOfficeType(e.url)){case officeTypes.writer:e.WordApplication=e.WpsApplication=function(){return c};break;case officeTypes.spreadsheet:e.ExcelApplication=e.EtApplication=function(){return c};break;case officeTypes.presentation:e.PPTApplication=e.WppApplication=function(){return c};break;case officeTypes.pdf:e.PDFApplication=function(){return c}}e.Application=c,e.Free=function(e){return apiChannel("api.free",{objId:e},"")},e.Stack=c.Stack=makeCollectObjIdHandle(function(t){return e.Free(t)});var u={};Message.add(function(e){return __awaiter(n,void 0,void 0,function(){var t,n,r,a,o;return __generator(this,function(i){switch(i.label){case 0:return"api.event"===(t=Message.parse(e.data)).eventName&&t.data?(n=t.data,r=n.eventName,a=n.data,n.objIds,(o=u[r])?[4,o(a)]:[3,2]):[3,2];case 1:i.sent(),i.label=2;case 2:return[2]}})})}),c.Sub={},Object.values(r).forEach(function(e){Object.defineProperty(c.Sub,e,{set:function(t){u[e]=t,sendMsgToWps({eventName:"api.event.register",data:{eventName:e,register:!!t,objId:++objId}})}})})}var wps,polyfillApi=["ExportAsFixedFormat","GetOperatorsInfo","ImportDataIntoFields","ReplaceText","ReplaceBookmark","GetBookmarkText","GetComments"];function assign(e,t,n){t=t.slice(0);for(var r=function(){var r=t.shift();!r.alias&&~polyfillApi.indexOf(r.prop)&&t.push(__assign({},r,{alias:r.prop+"Async"})),Object.defineProperty(e,r.alias||r.prop,{get:function(){var t=this,a=1===r.cache,o=a&&this["__"+r.prop+"CacheValue"];if(o)return o;var i=new Error("").stack.split("\n").slice(2).join("\n"),s=createObjId(a),c=function(){for(var t,a=[],o=0;o