1 |
- var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))(function(a,o){function i(e){try{s(r.next(e))}catch(e){o(e)}}function c(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){e.done?a(e.value):new n(function(t){t(e.value)}).then(i,c)}s((r=r.apply(e,t||[])).next())})}function n(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:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){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]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var r=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}();var a,o,i,c=this;!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"}(i||(i={}));var s,u,p=(s=0,function(){return++s}),l=function(e,t){if(!u){(u=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"),function(e){var t=document.createElement("style");document.head.appendChild(t);var n=t.sheet;n.insertRule(e,n.cssRules.length)}(".web-office-default-container {position: absolute; padding: 0; margin: 0; width: 100vw; height: 100vh; left: 0; top: 0;}"),document.body.appendChild(t)),n)u.setAttribute(r,n[r]);t.appendChild(u),u.destroy=function(){u.parentNode.removeChild(u),u=null}}return u},f=function(e){l().contentWindow.postMessage(JSON.stringify(e),"*")},d=function(e){return new Promise(function(t){var n=p(),a=function(e){var o=r.parse(e.data);"wps.api.reply"===o.eventName&&o.msgId===n&&(t(o.data),r.remove(a))};r.add(a),f({eventName:"wps.jssdk.api",data:e,msgId:n})})},v=function(a,o,i,s){return t(c,void 0,void 0,function(){var c,u,l,d,v,m,h,w;return n(this,function(y){switch(y.label){case 0:return c=p(),d=new Promise(function(e,t){u=e,l=t}),v={},o.args?[4,b(o.args)]:[3,2];case 1:m=y.sent(),h=m[0],w=m[1],o.args=h,v=w,y.label=2;case 2:return function(t){var n=t[0],r=t[1];"function"==typeof(n=e({},n)).data&&(n.data=n.data());r(),f(n)}([{eventName:a,data:o,msgId:c},function(){var e=this,o=function(p){return t(e,void 0,void 0,function(){var e,t,d;return n(this,function(n){switch(n.label){case 0:return"api.callback"===(e=r.parse(p.data)).eventName&&e.callbackId&&v[e.callbackId]?[4,v[e.callbackId].apply(v,e.data.args)]:[3,2];case 1:t=n.sent(),f({eventName:"api.callback.reply",result:t,callbackId:e.callbackId}),n.label=2;case 2:return e.eventName===a+".reply"&&e.msgId===c&&(e.error?((d=new Error("")).stack=e.error+"\n"+i,s&&s(),l(d)):u(e.result),r.remove(o)),[2]}})})};return r.add(o),d}]),[2,d]}})})};function b(e){return t(this,void 0,void 0,function(){var t,r,a,o,i,c,s;return n(this,function(n){switch(n.label){case 0:t={},r=[],e=e.slice(0),n.label=1;case 1:return e.length?(a=void 0,[4,e.shift()]):[3,3];case 2:if(o=n.sent(),function(e){if(!e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}(a))for(i in a={},o)"function"==typeof(c=o[i])&&(s=p(),t[s]=c,c={callbackId:s}),a[i]=c;else"function"==typeof o?(s=p(),t[s]=o,a={callbackId:s}):a=o;return r.push(a),[3,1];case 3:return[2,[r,t]]}})})}var m=function(t,n){void 0===n&&(n=!0);var r=e({},t),a=r.headers,o=void 0===a?{}:a,c=r.subscriptions,s=void 0===c?{}:c,u=r.mode,p=void 0===u?i.nomal:u,l=o.backBtn,f=void 0===l?{}:l,d=o.shareBtn,v=void 0===d?{}:d,b=o.otherMenuBtn,m=void 0===b?{}:b,h=function(e,t){e.subscribe&&"function"==typeof e.subscribe&&(e.callback=t,s[t]=e.subscribe,n&&delete e.subscribe)};if(h(f,"wpsconfig_back_btn"),h(v,"wpsconfig_share_btn"),h(m,"wpsconfig_other_menu_btn"),m.items&&Array.isArray(m.items)){var w=[];m.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,h(e,"wpsconfig_other_menu_btn_"+t),w.push(e)}}),w.length&&(j||I)&&(m.items=w)}if(r.url=r.url||r.wpsUrl,(p===i.simple||r.commonOptions&&!1===r.commonOptions.isShowTopArea)&&r.url&&(r.url+="&simple&hidecmb"),r.debug&&r.url&&(r.url+="&debugger"),r.wordOptions&&(r.wpsOptions=r.wordOptions),r.excelOptions&&(r.etOptions=r.excelOptions),r.pptOptions&&(r.wppOptions=r.pptOptions),"object"==typeof s.print){var y="wpsconfig_print";"function"==typeof s.print.subscribe&&(s[y]=s.print.subscribe,r.print={callback:y},void 0!==s.print.custom&&(r.print.custom=s.print.custom)),delete s.print}"function"==typeof s.exportPdf&&(s[y="wpsconfig_export_pdf"]=s.exportPdf,r.exportPdf={callback:y},delete s.exportPdf);return e({},r,{subscriptions:s})},h=function(e){void 0===e&&(e="");var t="";if(!t&&e){var n=e.toLowerCase();-1!==n.indexOf("/office/s/")&&(t=a.spreadsheet),-1!==n.indexOf("/office/w/")&&(t=a.writer),-1!==n.indexOf("/office/p/")&&(t=a.presentation),-1!==n.indexOf("/office/f/")&&(t=a.pdf)}if(!t){var r=e.match(/[\?&]type=([a-z]+)/)||[];t=o[r[1]]||""}return t};function w(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&&f({eventName:"setCommandBars",data:n}),n}var y,g=window.navigator.userAgent.toLowerCase(),j=/Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(g),I=function(){try{return-1!==window._parent.location.search.indexOf("from=wxminiprogram")}catch(e){return!1}}();function k(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"}(y||(y={}));var O=0,_=new Set;function x(e){return++O,!e&&function(e){_.forEach(function(t){return t(e)})}(O),O}function E(o,i){var c,s=this,u=i.Events,p=i.Enum,l=i.Props,d=l[0],b=l[1],m={objId:O};switch(function t(n,r,a){r=r.slice(0);var o=function(){var o=r.shift();!o.alias&&~C.indexOf(o.prop)&&r.push(e({},o,{alias:o.prop+"Async"})),Object.defineProperty(n,o.alias||o.prop,{get:function(){var r=this,i=1===o.cache,c=i&&this["__"+o.prop+"CacheValue"];if(c)return c;var s=new Error(""),u=s.stack.split("\n").slice(2).join("\n"),p=x(i),l=function(){for(var t,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];void 0!==o.caller?function t(n,r,a){r=r.slice(0);var o=function(){var o=r.shift();!o.alias&&~C.indexOf(o.prop)&&r.push(e({},o,{alias:o.prop+"Async"})),Object.defineProperty(n,o.alias||o.prop,{get:function(){var e=this,r=1===o.cache,i=r&&this["__"+o.prop+"CacheValue"];if(i)return i;var c=new Error(""),s=c.stack.split("\n").slice(2).join("\n"),u=x(r),p=function(){for(var e,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];void 0!==o.caller?t(e={objId:x()},a[o.caller],a):e={};return N(p,e,"api.caller",{obj:p,parentObjId:n.objId,objId:e.objId,args:r,prop:o.prop},s),e};return p.objId=-1,void 0!==o.getter&&(p.objId=u,t(p,a[o.getter],a)),N(n,p,"api.getter",{parentObjId:n.objId,objId:p.objId,prop:o.prop},s,function(){delete e["__"+o.prop+"CacheValue"]}),r&&(this["__"+o.prop+"CacheValue"]=p),p},set:function(e){var t=new Error(""),r=t.stack.split("\n").slice(2).join("\n");return N(n,{},"api.setter",{parentObjId:n.objId,objId:-1,prop:o.prop,value:e},r)}})};for(;r.length;)o()}(t={objId:x()},a[o.caller],a):t={};return N(l,t,"api.caller",{obj:l,parentObjId:n.objId,objId:t.objId,args:r,prop:o.prop},u),t};return l.objId=-1,void 0!==o.getter&&(l.objId=p,t(l,a[o.getter],a)),N(n,l,"api.getter",{parentObjId:n.objId,objId:l.objId,prop:o.prop},u,function(){delete r["__"+o.prop+"CacheValue"]}),i&&(this["__"+o.prop+"CacheValue"]=l),l},set:function(e){var t=new Error(""),r=t.stack.split("\n").slice(2).join("\n");return N(n,{},"api.setter",{parentObjId:n.objId,objId:-1,prop:o.prop,value:e},r)}})};for(;r.length;)o()}(m,d,b),m.Events=u,m.Enum=p,o.Enum=m.Enum,o.Events=m.Events,h(o.url)){case a.writer:o.WordApplication=o.WpsApplication=function(){return m};break;case a.spreadsheet:o.ExcelApplication=o.EtApplication=function(){return m};break;case a.presentation:o.PPTApplication=o.WppApplication=function(){return m};break;case a.pdf:o.PDFApplication=function(){return m}}o.Application=m,o.Free=function(e){return v("api.free",{objId:e},"")},o.Stack=m.Stack=(c=function(e){return o.Free(e)},function(){var e=[],t=function(t){e.push(t)};return _.add(t),{End:function(){c(e),_.delete(t)}}});var w={};r.add(function(e){return t(s,void 0,void 0,function(){var t,a,o,i,c;return n(this,function(n){switch(n.label){case 0:return"api.event"===(t=r.parse(e.data)).eventName&&t.data?(a=t.data,o=a.eventName,i=a.data,a.objIds,(c=w[o])?[4,c(i)]:[3,2]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})}),m.Sub={},Object.values(u).forEach(function(e){Object.defineProperty(m.Sub,e,{set:function(t){w[e]=t,f({eventName:"api.event.register",data:{eventName:e,register:!!t,objId:++O}})}})})}var P,C=["ExportAsFixedFormat","GetOperatorsInfo","ImportDataIntoFields","ReplaceText","ReplaceBookmark","GetBookmarkText","GetComments"];function A(t,n,r){n=n.slice(0);var a=function(){var a=n.shift();if(!a.alias&&~C.indexOf(a.prop)){n.push(e({},a,{alias:a.prop+"Async"}))}Object.defineProperty(t,a.alias||a.prop,{get:function(){var e=this;var n=a.cache===1;var o=n&&this["__"+a.prop+"CacheValue"];if(!o){var i=new Error("");var c=i.stack.split("\n").slice(2).join("\n");var s=x(n);var u=function(){for(var e=[],n=0,o;n<arguments.length;n++){e[n]=arguments[n]}if(a.caller!==undefined){o={objId:x()};A(o,r[a.caller],r)}else{o={}}return N(p,o,"api.caller",{obj:p,parentObjId:t.objId,objId:o.objId,args:e,prop:a.prop},c),o};var p=u;p.objId=-1;if(a.getter!==undefined){p.objId=s;A(p,r[a.getter],r)}N(t,p,"api.getter",{parentObjId:t.objId,objId:p.objId,prop:a.prop},c,function(){delete e["__"+a.prop+"CacheValue"]});if(n){this["__"+a.prop+"CacheValue"]=p}return p}else{return o}},set:function(e){var n=new Error("");var r=n.stack.split("\n").slice(2).join("\n");return N(t,{},"api.setter",{parentObjId:t.objId,objId:-1,prop:a.prop,value:e},r)}})};while(n.length){a()}}function N(e,t,n,r,a,o){var i=Promise.resolve(e).catch(function(){}).then(function(){return v(n,r,a,o)});t.then=function(e,t){return i.then(e,t)},t.catch=function(e){return i.catch(e)},t.Destroy=function(){return v("api.free",{objId:t.objId},"")}}var B="fileOpen",S=function(e){return"api.ready"===e},L=function(e,t){void 0===e&&(e={});r.add(function(n){var a=r.parse(n.data),o=a.eventName,i=void 0===o?"":o,c=a.data,s=void 0===c?null:c,u=a.url,p=void 0===u?null:u;-1===["wps.jssdk.api"].indexOf(i)&&("ready"===i?(f({eventName:"setConfig",data:e}),P.tokenData&&f({eventName:"setToken",data:P.tokenData}),P.commandBars&&w(P.commandBars),P.iframeReady=!0):"open.result"===i?P.emit(B,s):"api.ready"===i&&E(P,s),"function"==typeof t[i]&&t[i](P,p||s))})};function D(t){void 0===t&&(t={}),P&&P.destroy();try{var n,a=m(t),o=a.subscriptions,i=void 0===o?{}:o,c=a.mount,s=void 0===c?null:c,u=a.url,p=l(u,s);return delete a.mount,u&&delete a.url,delete a.subscriptions,P={url:u,version:"1.1.1",iframe:p,Enum:e({},y),iframeReady:!1,tokenData:null,commandBars:null,setToken:function(e){P.tokenData=e,P.iframeReady&&f({eventName:"setToken",data:e})},ready:function(){return n||(n=new Promise(function(e){var t=function(n){var a=r.parse(n.data).eventName;S(a)&&(e(),r.remove(t))};r.add(t)}))},destroy:function(){p.destroy(),r.empty(),P=null,_=new Set,O=0},save:function(){return d({api:"save"})},setCommandBars:function(e){P.commandBars=w(e,P.iframeReady)},updateConfig:function(e){if(void 0===e&&(e={}),e.commandBars)return console.warn("Deprecated: `updateConfig()` 方法即将废弃,请使用`setCommandBars()`代替`updateConfig()`更新`commandBars`配置。"),w(e.commandBars)}},P=e({},P,new k.prototype.constructor),L(a,i),P.ready(),P}catch(e){console.error(e)}}console.log("WebOfficeSDK JS-SDK V1.1.1");var T=Object.freeze({Listener:L,config:D});window.WPS=T;var V=D;export default{config:D};export{V as config};
|