@officesdk/web
Version:
Web JS SDK for the Office SDK
2 lines (1 loc) • 48.9 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@officesdk/web"]={})}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},t.apply(this,arguments)};function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}s((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return u.next=c(0),u.throw=c(1),u.return=c(2),"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;u&&(u=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}"function"==typeof SuppressedError&&SuppressedError;var o=class extends Error{code;constructor(e,t){super(t),this.name="PenpalError",this.code=e}},i=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof o?e.code:void 0}),u=Symbol("Reply"),c=class{value;transferables;#e=u;constructor(e,t){this.value=e,this.transferables=t?.transferables}},s="penpal",a=e=>"object"==typeof e&&null!==e,l=e=>"function"==typeof e,f=e=>"SYN"===e.type,d=e=>"ACK1"===e.type,h=e=>"ACK2"===e.type,v=e=>"CALL"===e.type,p=e=>"REPLY"===e.type,g=(e,t=[])=>{const n=[];for(const r of Object.keys(e)){const o=e[r];l(o)?n.push([...t,r]):a(o)&&n.push(...g(o,[...t,r]))}return n},m=e=>e.join("."),y=(e,t,n)=>({namespace:s,channel:e,type:"REPLY",callId:t,isError:!0,...n instanceof Error?{value:i(n),isSerializedErrorInstance:!0}:{value:n}}),w=(e,t,n,r)=>{let i=!1;const u=async u=>{if(i)return;if(!v(u))return;r?.(`Received ${m(u.methodPath)}() call`,u);const{methodPath:f,args:d,id:h}=u;let p,g;try{const e=((e,t)=>{const n=e.reduce(((e,t)=>a(e)?e[t]:void 0),t);return l(n)?n:void 0})(f,t);if(!e)throw new o("METHOD_NOT_FOUND",`Method \`${m(f)}\` is not found.`);let r=await e(...d);r instanceof c&&(g=r.transferables,r=await r.value),p={namespace:s,channel:n,type:"REPLY",callId:h,value:r}}catch(e){p=y(n,h,e)}if(!i)try{r?.(`Sending ${m(f)}() reply`,p),e.sendMessage(p,g)}catch(t){throw"DataCloneError"===t.name&&(p=y(n,h,t),r?.(`Sending ${m(f)}() reply`,p),e.sendMessage(p)),t}};return e.addMessageHandler(u),()=>{i=!0,e.removeMessageHandler(u)}},b=crypto.randomUUID?.bind(crypto)??(()=>new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-")),S=Symbol("CallOptions"),E=class{transferables;timeout;#e=S;constructor(e){this.transferables=e?.transferables,this.timeout=e?.timeout}},P=new Set(["apply","call","bind"]),C=(e,t,n=[])=>new Proxy(n.length?()=>{}:Object.create(null),{get(r,o){if("then"!==o)return n.length&&P.has(o)?Reflect.get(r,o):C(e,t,[...n,o])},apply:(t,r,o)=>e(n,o)}),T=e=>new o("CONNECTION_DESTROYED",`Method call ${m(e)}() failed due to destroyed connection`),k=(e,t,n)=>{let r=!1;const i=new Map,u=e=>{if(!p(e))return;const{callId:t,value:r,isError:u,isSerializedErrorInstance:c}=e,s=i.get(t);s&&(i.delete(t),n?.(`Received ${m(s.methodPath)}() call`,e),u?s.reject(c?(({name:e,message:t,stack:n,penpalCode:r})=>{const i=r?new o(r,t):new Error(t);return i.name=e,i.stack=n,i})(r):r):s.resolve(r))};e.addMessageHandler(u);return{remoteProxy:C(((u,c)=>{if(r)throw T(u);const a=b(),l=c[c.length-1],f=l instanceof E,{timeout:d,transferables:h}=f?l:{},v=f?c.slice(0,-1):c;return new Promise(((r,c)=>{const l=void 0!==d?window.setTimeout((()=>{i.delete(a),c(new o("METHOD_CALL_TIMEOUT",`Method call ${m(u)}() timed out after ${d}ms`))}),d):void 0;i.set(a,{methodPath:u,resolve:r,reject:c,timeoutId:l});try{const r={namespace:s,channel:t,type:"CALL",id:a,methodPath:u,args:v};n?.(`Sending ${m(u)}() call`,r),e.sendMessage(r,h)}catch(e){c(new o("TRANSMISSION_FAILED",e.message))}}))}),n),destroy:()=>{r=!0,e.removeMessageHandler(u);for(const{methodPath:e,reject:t,timeoutId:n}of i.values())clearTimeout(n),t(T(e));i.clear()}}},O=()=>{let e,t;return{promise:new Promise(((n,r)=>{e=n,t=r})),resolve:e,reject:t}},R=class extends Error{constructor(e){super(`You've hit a bug in Penpal. Please file an issue with the following information: ${e}`)}},M="deprecated-penpal",I=e=>e.join("."),A=e=>new R(`Unexpected message to translate: ${JSON.stringify(e)}`),x=({messenger:e,methods:t,timeout:n,channel:r,log:i})=>{const u=b();let c;const a=[];let l=!1;const v=g(t),{promise:p,resolve:m,reject:y}=O(),S=void 0!==n?setTimeout((()=>{y(new o("CONNECTION_TIMEOUT",`Connection timed out after ${n}ms`))}),n):void 0,E=()=>{for(const e of a)e()},P=()=>{if(l)return;a.push(w(e,t,r,i));const{remoteProxy:n,destroy:o}=k(e,r,i);a.push(o),clearTimeout(S),l=!0,m({remoteProxy:n,destroy:E})},C=()=>{const t={namespace:s,type:"SYN",channel:r,participantId:u};i?.("Sending handshake SYN",t);try{e.sendMessage(t)}catch(e){y(new o("TRANSMISSION_FAILED",e.message))}},T=t=>{f(t)&&(t=>{if(i?.("Received handshake SYN",t),t.participantId===c&&c!==M)return;if(c=t.participantId,C(),!(u>c||c===M))return;const n={namespace:s,channel:r,type:"ACK1",methodPaths:v};i?.("Sending handshake ACK1",n);try{e.sendMessage(n)}catch(e){return void y(new o("TRANSMISSION_FAILED",e.message))}})(t),d(t)&&(t=>{i?.("Received handshake ACK1",t);const n={namespace:s,channel:r,type:"ACK2"};i?.("Sending handshake ACK2",n);try{e.sendMessage(n)}catch(e){return void y(new o("TRANSMISSION_FAILED",e.message))}P()})(t),h(t)&&(e=>{i?.("Received handshake ACK2",e),P()})(t)};return e.addMessageHandler(T),a.push((()=>e.removeMessageHandler(T))),C(),p},D=e=>{let t,n=!1;return(...r)=>(n||(n=!0,t=e(...r)),t)},F=new WeakSet,L=({messenger:e,methods:t={},timeout:n,channel:r,log:i})=>{if(!e)throw new o("INVALID_ARGUMENT","messenger must be defined");if(F.has(e))throw new o("INVALID_ARGUMENT","A messenger can only be used for a single connection");F.add(e);const u=[e.destroy],c=D((t=>{if(t){const t={namespace:s,channel:r,type:"DESTROY"};try{e.sendMessage(t)}catch(e){}}for(const e of u)e();i?.("Connection destroyed")})),l=e=>(e=>a(e)&&e.namespace===s)(e)&&e.channel===r;return{promise:(async()=>{try{e.initialize({log:i,validateReceivedMessage:l}),e.addMessageHandler((e=>{(e=>"DESTROY"===e.type)(e)&&c(!1)}));const{remoteProxy:o,destroy:s}=await x({messenger:e,methods:t,timeout:n,channel:r,log:i});return u.push(s),o}catch(e){throw c(!0),e}})(),destroy:()=>{c(!0)}}},j=class{#t;#n;#r;#o;#i;#u=new Set;#c;#s=!1;constructor({remoteWindow:e,allowedOrigins:t}){if(!e)throw new o("INVALID_ARGUMENT","remoteWindow must be defined");this.#t=e,this.#n=t?.length?t:[window.origin]}initialize=({log:e,validateReceivedMessage:t})=>{this.#r=e,this.#o=t,window.addEventListener("message",this.#a)};sendMessage=(e,t)=>{if(f(e)){const n=this.#l(e);this.#t.postMessage(e,{targetOrigin:n,transfer:t})}else if(d(e)||this.#s){const n=this.#s?(e=>{if(d(e))return{penpal:"synAck",methodNames:e.methodPaths.map(I)};if(v(e))return{penpal:"call",id:e.id,methodName:I(e.methodPath),args:e.args};if(p(e))return e.isError?{penpal:"reply",id:e.callId,resolution:"rejected",...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:"reply",id:e.callId,resolution:"fulfilled",returnValue:e.value};throw A(e)})(e):e,r=this.#l(e);this.#t.postMessage(n,{targetOrigin:r,transfer:t})}else if(h(e)){const{port1:n,port2:r}=new MessageChannel;this.#c=n,n.addEventListener("message",this.#f),n.start();const o=[r,...t||[]],i=this.#l(e);this.#t.postMessage(e,{targetOrigin:i,transfer:o})}else{if(!this.#c)throw new R("Port is undefined");this.#c.postMessage(e,{transfer:t})}};addMessageHandler=e=>{this.#u.add(e)};removeMessageHandler=e=>{this.#u.delete(e)};destroy=()=>{window.removeEventListener("message",this.#a),this.#d(),this.#u.clear()};#h=e=>this.#n.some((t=>t instanceof RegExp?t.test(e):t===e||"*"===t));#l=e=>{if(f(e))return"*";if(!this.#i)throw new R("Concrete remote origin not set");return"null"===this.#i&&this.#n.includes("*")?"*":this.#i};#d=()=>{this.#c?.removeEventListener("message",this.#f),this.#c?.close(),this.#c=void 0};#a=({source:e,origin:t,ports:n,data:r})=>{if(e===this.#t&&((e=>a(e)&&"penpal"in e)(r)&&(this.#r?.("Please upgrade the child window to the latest version of Penpal."),this.#s=!0,r=(e=>{if("syn"===e.penpal)return{namespace:s,channel:void 0,type:"SYN",participantId:M};if("ack"===e.penpal)return{namespace:s,channel:void 0,type:"ACK2"};if("call"===e.penpal)return{namespace:s,channel:void 0,type:"CALL",id:e.id,methodPath:(t=e.methodName,t.split(".")),args:e.args};var t;if("reply"===e.penpal)return"fulfilled"===e.resolution?{namespace:s,channel:void 0,type:"REPLY",callId:e.id,value:e.returnValue}:{namespace:s,channel:void 0,type:"REPLY",callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw A(e)})(r)),this.#o?.(r)))if(this.#h(t)){if(f(r)&&(this.#d(),this.#i=t),h(r)&&!this.#s){if(this.#c=n[0],!this.#c)throw new R("No port received on ACK2");this.#c.addEventListener("message",this.#f),this.#c.start()}for(const e of this.#u)e(r)}else this.#r?.(`Received a message from origin \`${t}\` which did not match allowed origins \`[${this.#n.join(", ")}]\``)};#f=({data:e})=>{if(this.#o?.(e))for(const t of this.#u)t(e)}};var N,W,U=null!==(N=Object.fromEntries)&&void 0!==N?N:function(e){for(var t={},n=0,r=Array.from(e);n<r.length;n++){var o=r[n],i=o[0],u=o[1];t[i]=u}return t},_=null!==(W=Object.entries)&&void 0!==W?W:function(e){for(var t=[],n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],u=o[1];t.push([i,u])}return t};function B(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}function z(e){return Array.isArray(e)}function V(e){if(!function(e){return null!==e&&"object"==typeof e}(e)||"[object Object]"!=B(e))return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&Function.prototype.toString.call(n)===Function.prototype.toString.call(Object)}function Y(e){return null===e||function(e){return"[object Number]"===B(e)}(e)||function(e){return"[object String]"===B(e)}(e)||function(e){return"[object Boolean]"===B(e)}(e)||function(e){return"[object Undefined]"===B(e)}(e)}var $=Math.ceil(Date.now()*Math.random()),H=0;var K=function(){return K=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},K.apply(this,arguments)},G=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}s((r=r.apply(e,t||[])).next())}))},Q=function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}};function Z(e){return e.slice(1)}var J=Symbol("TokenStructured");function X(e){var t;return K(((t={})[J]=!0,t),e)}function q(e){var t;return"object"==typeof e&&1==(null===(t=Object.getOwnPropertyDescriptor(e,J))||void 0===t?void 0:t.value)}var ee=Symbol("TokenData");function te(e){var t;return"object"==typeof e&&null!==e&&1==(null===(t=Object.getOwnPropertyDescriptor(e,ee))||void 0===t?void 0:t.value)}var ne=function(){function e(e,t){this.value=e,this.options={},t&&(this.options=t)}return e.prototype.getSchemaEntity=function(e){return G(this,void 0,void 0,(function(){var t,n;return Q(this,(function(r){return t=this.value,n=this.sortRules(),[2,this.toSchemaEntity(t,n,e)]}))}))},e.prototype.sortRules=function(){var e=this.options,t=e.callbacks,n=e.refs,r=e.arrays,o=e.maps,i=[];return(null==t?void 0:t.length)&&i.push({type:"callback",paths:t}),(null==n?void 0:n.length)&&i.push({type:"ref",paths:n}),(null==o?void 0:o.length)&&i.push({type:"map",paths:o}),(null==r?void 0:r.length)&&i.push({type:"array",paths:r}),i},e.prototype.toSchemaEntity=function(e,t,n){return G(this,void 0,void 0,(function(){var r=this;return Q(this,(function(o){return(null==t?void 0:t.length)?[2,this.iterateRules(e,t,n)]:"function"==typeof e?[2,this.toSchemaCallback(e,n)]:e instanceof Promise?[2,e.then((function(e){return r.toSchemaEntity(e,t,n)}))]:Y(e)?[2,this.toSchemaData(e)]:V(e)||z(e)?[2,this.iterateValue(e,n)]:[2,this.toSchemaRef(e,n)]}))}))},e.prototype.iterateValue=function(e,t){return G(this,void 0,void 0,(function(){var n,r,o,i,u,c,s,a,l,f,d;return Q(this,(function(h){switch(h.label){case 0:if(this.isStructuredCloneable(e))return[2,this.toSchemaData(e)];if(!Array.isArray(e))return[3,5];i={type:"array",value:[]},n=0,h.label=1;case 1:return n<e.length?(l=e[n],o=(r=i.value).push,[4,this.toSchemaEntity(l,null,t)]):[3,4];case 2:o.apply(r,[h.sent()]),h.label=3;case 3:return n++,[3,1];case 4:return[2,X(i)];case 5:i={type:"map",value:{}},u=0,c=_(e),h.label=6;case 6:return u<c.length?(s=c[u],a=s[0],l=s[1],f=i.value,d=a,[4,this.toSchemaEntity(l,null,t)]):[3,9];case 7:f[d]=h.sent(),h.label=8;case 8:return u++,[3,6];case 9:return[2,X(i)]}}))}))},e.prototype.isStructuredCloneable=function(e){var t=this;return!!Y(e)||!("function"==typeof e||e instanceof Promise)&&(!(!V(e)&&!z(e))&&(z(e)?e.every((function(e){return t.isStructuredCloneable(e)})):!!V(e)&&Object.values(e).every((function(e){return t.isStructuredCloneable(e)}))))},e.prototype.iterateRules=function(e,t,n){for(var r=this,o=this.toStructured(e),i=0,u=t[i],c=function(){for(var e=u.type,c=0,s=u.paths;c<s.length;c++){var a=Z(s[c]);re(o,a,(function(t,o,i){if(!i){if(q(t)){var u=r.toStructured(t.value[o]);return t.value[o]=u,u}u=r.toStructured(t[o]);return t[o]=u,u}var c=t.value,s=c[o],a=te(s)?s.value:s;c[o]=r.parseRule(a,e,n)}))}u=t[++i]};u;)c();return o},e.prototype.parseRule=function(e,t,n){switch(t){case"callback":return this.toSchemaCallback(e,n);case"ref":return this.toSchemaRef(e,n);case"map":return this.toStructured(e,"map");case"array":return this.toStructured(e,"array")}return this.toSchemaData(e)},e.prototype.toStructured=function(e,t){var n=this;return q(e)?e:te(e)?this.toStructured(e.value):Array.isArray(e)||"array"===t?X({type:"array",value:e.map((function(e){return n.toSchemaData(e)}))}):X({type:"map",value:U(_(e).map((function(e){var t=e[0],r=e[1];return[t,n.toSchemaData(r)]})))})},e.prototype.toSchemaCallback=function(e,t){return{type:"callback",source:t.name,ref:t.createRefId({type:"callback",value:e})}},e.prototype.toSchemaRef=function(e,t){return{type:"ref",source:t.name,ref:t.createRefId({type:"ref",value:e})}},e.prototype.toSchemaData=function(e){return te(e)?e:function(e){var t;return K(((t={})[ee]=!0,t),e)}({type:"data",value:e})},e}();function re(e,t,n){var r=e;if(t)for(var o=t.split("."),i=0;i<o.length;i++){r=n(r,o[i],i===o.length-1)}}var oe=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}s((r=r.apply(e,t||[])).next())}))},ie=function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}},ue=function(){function e(e){var t=this;this.refsMap=new Map,this.valuesMap=new WeakMap,this.counter=0,this.createRefId=function(e){var n=t.valuesMap.get(e);if(n)return n;var r=t.generateRefId();return t.refsMap.set(r,e),t.valuesMap.set(e,r),r},this.name=e.name,this.callback=e.callback}return e.prototype.createSchemaEntity=function(e){return(e instanceof ne?e:new ne(e)).getSchemaEntity({name:this.name,createRefId:this.createRefId})},e.prototype.parseSchemaEntity=function(e){var t=this;switch(e.type){case"data":return e.value;case"callback":return this.parseSchemaCallback(e);case"ref":return this.parseSchemaRef(e);case"array":return e.value.map((function(e){return t.parseSchemaEntity(e)}));case"map":return U(_(e.value).map((function(e){var n=e[0],r=e[1];return[n,t.parseSchemaEntity(r)]})));default:throw new Error("Unknown schema type: ".concat(e.type))}},e.prototype.resolveSchemaCallback=function(e){var t=this,n=this.parseSchemaCallback(e);return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var o=e.map((function(e){return t.parseSchemaEntity(e)})),i=n.apply(void 0,o);return t.createSchemaEntity(i)}},e.prototype.parseSchemaCallback=function(e){var t=this;if(e.source!==this.name)return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return oe(t,void 0,void 0,(function(){var t;return ie(this,(function(r){switch(r.label){case 0:return[4,this.callback(e,n)];case 1:return(t=r.sent())?[2,this.parseSchemaEntity(t)]:[2,t]}}))}))};var n=this.refsMap.get(e.ref);if(!n)throw new Error("Invalid reference: ".concat(e.ref));return n.value},e.prototype.parseSchemaRef=function(e){if(e.source!==this.name)return new Proxy({},{get:function(e,t){throw new Error("Unexpected remote property access")},set:function(){throw new Error("Unexpected remote property assignment")}});var t=this.refsMap.get(e.ref);if(!t)throw new Error("Invalid reference: ".concat(e.ref));return t.value},e.prototype.generateRefId=function(){return"#office-sdk-rpc@".concat(this.counter++)},e}(),ce=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}s((r=r.apply(e,t||[])).next())}))},se=function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}},ae=new WeakMap;function le(e){return ce(this,void 0,void 0,(function(){var t,n,r,o,i,u,c,s,a,l,f,d,h,v,p,g,m,y,w,b,S=this;return se(this,(function(E){switch(E.label){case 0:return t=e.remoteWindow,n=e.allowedOrigins,r=void 0===n?["*"]:n,o=e.timeout,i=e.settings,u=ae.get(t),c=function(e){void 0===e&&(e=7);var t=$%Math.pow(36,e);return t<Math.pow(36,e-1)&&(t=Math.pow(36,e-1)-t),(t+ ++H).toString(36)}(),u?[4,fe(u.connection,c)]:[3,2];case 1:return E.sent(),[2,{id:c,methods:u.methods}];case 2:return s=new j({remoteWindow:t,allowedOrigins:r}),a=new Set([]),l=function(){if(!w)throw new Error("Unexpected invoke before server connected");return w},f=function(e,t){return ce(S,void 0,void 0,(function(){var n,r;return se(this,(function(o){switch(o.label){case 0:return n=l(),[4,Promise.all(t.map((function(e){return d.createSchemaEntity(e)})))];case 1:return r=o.sent(),[2,n.callback(e,r)]}}))}))},d=new ue({name:c,callback:f}),h=L({channel:"#office-sdk-rpc",messenger:s,methods:(P={getClients:function(){return a},resolveCallback:function(e){return e.source!==c?function(){throw new Error("Invalid callback source: ".concat(e.source,", can not resolve callback from other client."))}:d.resolveSchemaCallback(e)}},{open:function(){return Array.from(P.getClients())},close:function(e){},callback:function(e,t){return P.resolveCallback(e).apply(void 0,t)}}),timeout:o}),i?[4,d.createSchemaEntity(i)]:[3,4];case 3:return p=E.sent(),[3,5];case 4:p=void 0,E.label=5;case 5:return v=p,a.add({clientId:c,settings:v}),g=fe(h,c,v),m=e.proxy,y=m({invoke:function(e,t){return ce(S,void 0,void 0,(function(){var n,r;return se(this,(function(o){switch(o.label){case 0:return n=l(),[4,Promise.all(t.map((function(e){return d.createSchemaEntity(e)})))];case 1:return r=o.sent(),[2,n.invoke(c,e,r).then((function(e){if(e)return d.parseSchemaEntity(e)}))]}}))}))}}),[4,g];case 6:return w=E.sent(),b={connection:h,clients:a,methods:y},ae.set(t,b),[2,{id:c,methods:y}]}var P}))}))}function fe(e,t,n){return ce(this,void 0,void 0,(function(){var r;return se(this,(function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,e.promise];case 1:return[4,(r=o.sent()).open(t,n)];case 2:return o.sent(),[2,r];case 3:throw o.sent();case 4:return[2]}}))}))}var de,he,ve,pe,ge,me=(de=function(e,t){return de=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},de(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}de(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});function ye(t){var n;return((n={})[e.FileType.Document]="docx",n[e.FileType.Spreadsheet]="sheet",n[e.FileType.Pdf]="pdf",n[e.FileType.Presentation]="presentation",n[e.FileType.DBTable]="table",n[e.FileType.LiteDoc]="unsupported",n)[t]}function we(){var e=this;return function(t){var o=t.invoke;return{ready:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("ready",[])]}))}))},getSelection:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getSelection",[])]}))}))},getContent:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getContent",[])]}))}))},getZoom:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getZoom",[])]}))}))},getTOCs:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getTOCs",[])]}))}))},getOutline:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getOutline",[])]}))}))},getWindow:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getWindow",[])]}))}))}}}}function be(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getContent()]}))}))};return{save:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[4,e.sent().save()];case 2:return e.sent(),[2]}}))}))},addContentListener:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[4,t.sent().addContentListener(e)];case 2:return[2,t.sent()]}}))}))}}}function Se(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getOutline()]}))}))};return{getContent:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getContent()]}}))}))},addChangedListener:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().addChangedListener(e)]}}))}))},goto:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().goto(e)]}}))}))}}}function Ee(e){var t=e.methods,o=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getSelection()]}))}))};return{getRange:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().getRange(e)]}}))}))},setRange:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().setRange(e)]}}))}))},addRangeListener:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().addRangeListener(e)]}}))}))},getWholeRange:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getWholeRange()]}}))}))}}}(t),i=be(t),u=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getZoom()]}))}))};return{getPercentage:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getPercentage()]}}))}))},setPercentage:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[4,t.sent().setPercentage(e)];case 2:return t.sent(),[2]}}))}))},zoomIn:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[4,e.sent().zoomIn()];case 2:return e.sent(),[2]}}))}))},zoomOut:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[4,e.sent().zoomOut()];case 2:return e.sent(),[2]}}))}))},setFitMode:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[4,t.sent().setFitMode(e)];case 2:return t.sent(),[2]}}))}))},getFitMode:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getFitMode()]}}))}))}}}(t),c=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getTOCs()]}))}))};return{getAll:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getAll()]}}))}))},getOne:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().getOne(e)]}}))}))},deleteAll:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().deleteAll()]}}))}))},deleteOne:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().deleteOne(e)]}}))}))},add:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().add(e)]}}))}))}}}(t),s=Se(t),a=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getWindow()]}))}))};return{getScrollPosition:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getScrollPosition()]}}))}))},scrollTo:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().scrollTo(e)]}}))}))},scrollToPage:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().scrollToPage(e)]}}))}))},scrollIntoView:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().scrollIntoView(e)]}}))}))},addScrollListener:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().addScrollListener(e)]}}))}))}}}(t);return{get selection(){return o},get content(){return i},get zoom(){return u},get TOCs(){return c},get outline(){return s},get window(){return a}}}function Pe(){var e=this;return function(t){var o=t.invoke;return{getActiveDBSheet:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getActiveDBSheet",[])]}))}))},getDBTableSelection:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getDBTableSelection",[])]}))}))},getContent:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getContent",[])]}))}))}}}}function Ce(e){var t=e.methods,o=be(t),i=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return o?[2,o]:[4,e.getDBTableSelection()];case 1:return t=n.sent(),[2,o=t]}}))}))};return{getSelection:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getSelection()]}}))}))},getSelectionType:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getSelectionType()]}}))}))},selectRange:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().selectRange(e)]}}))}))},selectRow:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().selectRow(e)]}}))}))},selectColumn:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().selectColumn(e)]}}))}))},selectCell:function(e,o){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().selectCell(e,o)]}}))}))},selectMultipleRows:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().selectMultipleRows(e)]}}))}))},selectMultipleColumns:function(e,o){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().selectMultipleColumns(e,o)]}}))}))}}}(t);return{get activeDBSheet(){return t.getActiveDBSheet()},get selection(){return i},get content(){return o}}}function Te(){var e=this;return function(t){var o=t.invoke;return{ready:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("ready",[])]}))}))},getSelection:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getSelection",[])]}))}))},getContent:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getContent",[])]}))}))},getZoom:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getZoom",[])]}))}))},getSlides:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getSlides",[])]}))}))}}}}function ke(e){var t=e.methods,o=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getSelection()]}))}))};return{getTextRange:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getTextRange()]}}))}))},setTextRange:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().setTextRange(e)]}}))}))},getSelectedShapes:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getSelectedShapes()]}}))}))},setSelectedShapes:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().setSelectedShapes(e)]}}))}))},addRangeListener:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().addRangeListener(e)]}}))}))}}}(t),i=be(t),u=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getZoom()]}))}))};return{getPercentage:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getPercentage()]}}))}))},setPercentage:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[4,t.sent().setPercentage(e)];case 2:return t.sent(),[2]}}))}))},zoomIn:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[4,e.sent().zoomIn()];case 2:return e.sent(),[2]}}))}))},zoomOut:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[4,e.sent().zoomOut()];case 2:return e.sent(),[2]}}))}))},setFitMode:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[4,t.sent().setFitMode(e)];case 2:return t.sent(),[2]}}))}))},getFitMode:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getFitMode()]}}))}))}}}(t),c=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getSlides()]}))}))};return{getCurrentSlide:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getCurrentSlide()]}}))}))},setCurrentSlideIndex:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[4,t.sent().setCurrentSlideIndex(e)];case 2:return t.sent(),[2]}}))}))},getSlideIndex:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().getSlideIndex(e)]}}))}))},getSlidesCount:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getSlidesCount()]}}))}))},getSlides:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getSlides()]}}))}))},getSlideById:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().getSlideById(e)]}}))}))},getSelectedSlides:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getSelectedSlides()]}}))}))},setSelectedSlides:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[4,t.sent().setSelectedSlides(e)];case 2:return t.sent(),[2]}}))}))}}}(t);return{get selection(){return o},get content(){return i},get zoom(){return u},get slides(){return c}}}function Oe(){var e=this;return function(t){var o=t.invoke;return{ready:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("ready",[])]}))}))},getWorkbook:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getWorkbook",[])]}))}))},getActiveSheet:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getActiveSheet",[])]}))}))},getActiveCell:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getActiveCell",[])]}))}))},getSelections:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getSelections",[])]}))}))},getContent:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getContent",[])]}))}))}}}}function Re(e){var t=e.methods,o=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getWorkbook()]}))}))};return{getWorksheets:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getWorksheets()]}}))}))},getWorksheetById:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().getWorksheetById(e)]}}))}))},getActiveWorksheet:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getActiveWorksheet()]}}))}))},setActiveWorksheet:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().setActiveWorksheet(e)]}}))}))}}}(t),i=be(t);return{get workbook(){return o},get activeCell(){return t.getActiveCell()},get selections(){return t.getSelections()},get activeSheet(){return t.getActiveSheet()},get content(){return i}}}function Me(){var e=this;return function(t){var o=t.invoke;return{getPages:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getPages",[])]}))}))},getSelection:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getSelection",[])]}))}))},getOutline:function(){return n(e,void 0,void 0,(function(){return r(this,(function(e){return[2,o("getOutline",[])]}))}))}}}}function Ie(e){var t=e.methods,o=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getPages()]}))}))};return{getCurrentPageNumber:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getCurrentPageNumber()]}}))}))},setCurrentPage:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().setCurrentPage(e)]}}))}))},getPagesCount:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getPagesCount()]}}))}))},getPage:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().getPage(e)]}}))}))}}}(t),i=function(e){var t=this,o=null,i=function(){return n(t,void 0,void 0,(function(){return r(this,(function(t){return o?[2,o]:[2,o=e.getSelection()]}))}))};return{getRange:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().getRange(e)]}}))}))},setRange:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().setRange(e)]}}))}))},addRangeListener:function(e){return n(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,i()];case 1:return[2,t.sent().addRangeListener(e)]}}))}))},getWholeRange:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,i()];case 1:return[2,e.sent().getWholeRange()]}}))}))}}}(t),u=Se(t);return{get pages(){return o},get selection(){return i},get outline(){return u}}}function Ae(e){var t=e.iframe,n=e.root;return t.style.border="none",t.style.overflow="hidden",t.style.width="100%",t.style.height="100%",t.frameBorder="0",t.allow="fullscreen *; clipboard-read *; clipboard-write *;",t.allowFullscreen=!0,null==n||n.appendChild(t),t}function xe(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return(t=e.contentWindow)?[2,t]:[3,1];case 1:return[4,new Promise((function(t,n){var r=function(){e.removeEventListener("load",r),e.removeEventListener("error",o);var i=e.contentWindow;i?t(i):n(new Error("Failed to load iframe"))},o=function(){e.removeEventListener("load",r),e.removeEventListener("error",o),n(new Error("Failed to load iframe"))};e.addEventListener("load",r),e.addEventListener("error",o)}))];case 2:return[2,n.sent()]}}))}))}function De(t){var n,r,o=t.fileType,i=t.endpoint,u=t.token,c=t.fileId,s=t.path,a=t.root,l=t.mode,f=t.role,d=t.lang,h=t.iframe,v=t.userQuery;return h?(n=new URL(h.src),r=Ae({iframe:h,root:a})):(n=function(t){var n,r=e.EditorModeType.Standard,o=e.EditorStandardRole.Viewer,i=t.endpoint,u=t.token,c=t.fileId,s=t.fileType,a=t.userQuery,l=t.path,f=void 0===l?"/v1/api/file/page":l,d=t.mode,h=void 0===d?r:d,v=t.role,p=void 0===v?o:v;try{if("https:"!==(n=new URL(i)).protocol&&"http:"!==n.protocol)throw new Error("Invalid URL");n.pathname=f,n.searchParams.set(ge.FileId,c),n.searchParams.set(ge.Token,u),n.searchParams.set(ge.FileType,s),n.searchParams.set(ge.ModeType,h),n.searchParams.set(ge.ModeRole,p);var g=function(e){return e&&["en-US","zh-CN"].includes(e)?e:null}(t.lang);g&&n.searchParams.set(ge.Language,g),a&&n.searchParams.set(ge.UserQuery,encodeURIComponent(JSON.stringify(a)))}catch(e){throw e}return n}({endpoint:i,token:u,fileId:c,path:s,mode:l,role:f,lang:d,userQuery:v,fileType:ye(o)}),r=function(e){var t=e.source,n=e.root,r=document.createElement("iframe");return r.src=t,Ae({iframe:r,root:n})}({source:n.toString(),root:a})),{url:n.toString(),container:r}}!function(e){function t(n){var r=e.call(this,n)||this;return r.message=n,r.name=t.errorName,r}me(t,e),t.errorName="ServerClientNotAccessible"}(Error),e.FileType=void 0,(he=e.FileType||(e.FileType={}))[he.Document=0]="Document",he[he.Spreadsheet=1]="Spreadsheet",he[he.Presentation=2]="Presentation",he[he.LiteDoc=3]="LiteDoc",he[he.DBTable=4]="DBTable",he[he.Pdf=5]="Pdf",e.EditorModeType=void 0,(ve=e.EditorModeType||(e.EditorModeType={})).Standard="standard",ve.Preview="preview",e.EditorStandardRole=void 0,(pe=e.EditorStandardRole||(e.EditorStandardRole={})).Editor="editor",pe.Viewer="viewer",pe.Reviewer="reviewer",function(e){e.FileId="fileID",e.Token="token",e.Language="lang",e.ModeType="modeType",e.ModeRole="modeRole",e.FileType="fileType",e.UserQuery="userQuery"}(ge||(ge={})),e.createSDK=function(o){var i=o.fileType,u=o.settings,c=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(o,["fileType","settings"]);if(function(t){if("number"!=typeof t||isNaN(t))throw new Error("Unsupported file type: ".concat(t));if(![e.FileType.Document,e.FileType.Spreadsheet,e.FileType.Presentation,e.FileType.LiteDoc,e.FileType.DBTable,e.FileType.Pdf].includes(t))throw new Error("Unsupported file type: ".concat(t))}(i),i===e.FileType.Document)return function(e){var t=this,o=e.settings,i=function(e){var t,n;return(null===(n=null===(t=null==e?void 0:e.menu)||void 0===t?void 0:t.custom)||void 0===n?void 0:n.length)?{menu:e.menu}:null}(o),u=De(e),c=u.url,s=u.container;return{url:c,iframe:s,destroy:function(){s.remove()},connect:function(){return n(t,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,xe(s)];case 1:return[4,le({remoteWindow:t.sent(),proxy:we(),settings:i})];case 2:return[4,(e=t.sent()).methods.ready()];case 3:return t.sent(),[2,Ee(e)]}}))}))}}}(t({fileType:i,settings:u},c));if(i===e.FileType.Spreadsheet)return function(e){var t=this,o=e.settings,i=function(e){return{menu:null==e?void 0:e.menu,toolbar:null==e?void 0:e.toolbar}}(o),u=De(e),c=u.url,s=u.container;return{url:c.toString(),iframe:s,destroy:function(){s.remove()},connect:function(){return n(t,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,xe(s)];case 1:return[4,le({remoteWindow:t.sent(),proxy:Oe(),settings:i})];case 2:return[4,(e=t.sent()).methods.ready()];case 3:return t.sent(),[2,Re(e)]}}))}))}}}(t({fileType:i,settings:u},c));if(i===e.FileType.Presentation)return function(e){var t=this,o=e.settings,i=function(e){return{menu:null==e?void 0:e.menu,toolbar:null==e?void 0:e.toolbar}}(o),u=De(e),c=u.url,s=u.container;return{url:c.toString(),iframe:s,destroy:function(){s.remove()},connect:function(){return n(t,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,xe(s)];case 1:return[4,le({remoteWindow:t.sent(),proxy:Te(),settings:i})];case 2:return[4,(e=t.sent()).methods.ready()];case 3:return t.sent(),[2,ke(e)]}}))}))}}}(t({fileType:i,settings:u},c));if(i===e.FileType.Pdf)return function(e){var t=this,o=De(e),i=o.url,u=o.container;return{url:i.toString(),iframe:u,destroy:function(){u.remove()},connect:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,xe(u)];case 1:return[4,le({remoteWindow:e.sent(),proxy:Me()})];case 2:return[2,Ie(e.sent())]}}))}))}}}(t({fileType:i},c));if(i===e.FileType.LiteDoc)return function(e){var t=this,o=De(e),i=o.url,u=o.container;return{url:i.toString(),iframe:u,destroy:function(){u.remove()},connect:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,xe(u)];case 1:return[4,le({remoteWindow:e.sent(),proxy:function(e){return{}}})];case 2:return e.sent(),[2,{}]}}))}))}}}(t({fileType:i},c));if(i===e.FileType.DBTable)return function(e){var t=this,o=De(e),i=o.url,u=o.container;return{url:i.toString(),iframe:u,destroy:function(){u.remove()},connect:function(){return n(t,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,xe(u)];case 1:return[4,le({remoteWindow:e.sent(),proxy:Pe()})];case 2:return[2,Ce(e.sent())]}}))}))}}}(t({fileType:i},c));throw new Error("Unsupported file type: ".concat(i))}}));