@atkonoffice/sdk 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atkonoffice.d.ts +6 -16
- package/dist/atkonoffice.js +1 -1
- package/package.json +1 -1
package/dist/atkonoffice.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface AtkonofficeDocSaved {
|
|
|
29
29
|
|
|
30
30
|
pair_id?: string
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
saveTypes?: string[]
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
|
|
@@ -62,9 +62,11 @@ export interface AtkonofficeWindowOptions {
|
|
|
62
62
|
|
|
63
63
|
export interface AtkonofficeOpenRequest {
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
pageUrl?: string
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
pageApi?: string
|
|
68
|
+
|
|
69
|
+
params?: Record<string, string>
|
|
68
70
|
|
|
69
71
|
headers?: Record<string, string> | Array<[string, string] | string>
|
|
70
72
|
|
|
@@ -73,16 +75,6 @@ export interface AtkonofficeOpenRequest {
|
|
|
73
75
|
storage?: Record<string, string>
|
|
74
76
|
|
|
75
77
|
options?: AtkonofficeWindowOptions
|
|
76
|
-
|
|
77
|
-
compareWith?: string
|
|
78
|
-
|
|
79
|
-
compareMode?: string
|
|
80
|
-
|
|
81
|
-
hostPagePath?: string
|
|
82
|
-
|
|
83
|
-
compareHost?: 'pageB' | string
|
|
84
|
-
|
|
85
|
-
create?: 'word' | 'excel' | 'ppt' | string
|
|
86
78
|
}
|
|
87
79
|
|
|
88
80
|
export interface AtkonofficeOpenResult {
|
|
@@ -193,12 +185,10 @@ export interface AtkonofficeSession {
|
|
|
193
185
|
|
|
194
186
|
onBeforeClose(fn: () => boolean | Promise<boolean> | void): AtkonofficeSession
|
|
195
187
|
|
|
196
|
-
save(opts?: { savePath?: string } & Record<string, unknown>): boolean | void
|
|
188
|
+
save(opts?: { savePath?: string; formats?: string[] } & Record<string, unknown>): boolean | void
|
|
197
189
|
|
|
198
190
|
setSavePath(path: string): boolean | void
|
|
199
191
|
|
|
200
|
-
saveAsPdf(): boolean | void
|
|
201
|
-
|
|
202
192
|
word: AtkonofficeSessionWord
|
|
203
193
|
}
|
|
204
194
|
|
package/dist/atkonoffice.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var h={};var n={backendBase:"",launchPath:"/atkonoffice-rpc/launch",wsTicketPath:"/atkonoffice-rpc/ws-ticket",fetchImpl:null,initialized:!1,ws:null,wsUrl:"",pairId:"",headers:null,eventHandlers:{},wsReconnectAttempt:0,wsReconnectTimer:null,wsGaveUp:!1,pairing:!1,launchTicket:"",openParams:null,fallbackUrl:"",pairingPrevTitle:"",pairingTitleSaved:!1,pairingRecoverTimer:null,pairingTimeoutTimer:null,pairTimeoutMs:5e3,pairRecoverMs:1e3,titleRelayInstalled:!1,trustedFrameOrigins:null,onPairDowngrade:null,replayOpen:null},j="atkonoffice.ws.session",K=12,V=["documentSaved","documentOpened","documentBeforeSave","documentEmbedFailed","error"],g={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave"},R="atkonoffice-launch=",se="\u2007",I="pair.ready",ce="launch.open",fe="doc.embedFailed",C="__atkonofficeTitle",J="atkonoffice-install-guide",Y="atkonoffice-embed-failure-guide";function le(e){return e&&e.endsWith("/")?e.slice(0,-1):e}function A(e,t,o){let r=e.indexOf("?")===-1?"?":"&";return e+r+t+"="+o}function U(e){return!!e&&Object.keys(e).length>0}function x(e){return e&&e.message?e.message:String(e)}function E(e,t,o){if(t==null)return;let r=String(t).trim();r&&(e[r]=o==null?"":String(o))}function de(e){return e?typeof e=="string"?e:typeof e=="object"?Object.keys(e).map(t=>t+"="+String(e[t])).join("; "):"":""}function ue(e){let t;if(typeof TextEncoder<"u"){let o=new TextEncoder().encode(e),r="";for(let i=0;i<o.length;i++)r+=String.fromCharCode(o[i]);t=r}else t=unescape(encodeURIComponent(e));return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function k(){try{return typeof document<"u"&&typeof document.title=="string"?document.title:""}catch{return""}}function G(){if(typeof window>"u")return!1;try{return window.top!==window.self}catch{return!0}}function N(e){try{let t=document.createElement("iframe");t.style.display="none",t.src=e,document.body.appendChild(t),setTimeout(()=>{try{document.body.removeChild(t)}catch{}},1e3)}catch{window.location.href=e}}function B(e){return!!(typeof e.launchTicket=="string"&&e.launchTicket&&typeof e.wsUrl=="string"&&e.wsUrl&&typeof e.wsTicket=="string"&&e.wsTicket&&typeof document<"u"&&typeof WebSocket<"u")}function z(){return typeof n.fetchImpl=="function"?n.fetchImpl:typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):null}function Xe(){let e=z();if(!e)throw new Error("atkonoffice: no fetch available \u2014 pass fetchImpl via config in non-browser hosts");return e}async function D(e,t){let r=await Xe()(n.backendBase+n.launchPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok)throw new Error(t+" endpoint returned HTTP "+r.status);return r.json()}function pe(e){n.launchTicket=e.launchTicket,n.openParams=e.openParams&&typeof e.openParams=="object"?e.openParams:{},n.fallbackUrl=e.launchUrl,n.pairing=!0,n.pairingTitleSaved=!1,q(),Ze()}function me(){!n.pairing||typeof document>"u"||(n.pairingTitleSaved||(n.pairingPrevTitle=k(),n.pairingTitleSaved=!0),ye(),Qe())}function ye(){v(L(n.wsUrl,n.pairId,n.launchTicket))}function L(e,t,o){let r=ue(JSON.stringify({wsUrl:e,pairId:t,launchTicket:o}));return se+R+r}function v(e){try{typeof document<"u"&&(document.title=e)}catch{}if(G())try{let t={};t[C]=e,window.top.postMessage(t,"*")}catch{}}function q(){n.titleRelayInstalled||typeof window>"u"||typeof window.addEventListener!="function"||G()||(n.titleRelayInstalled=!0,window.addEventListener("message",e=>{if(!$e(e&&e.origin))return;let t=e&&e.data;if(t&&typeof t=="object"&&typeof t[C]=="string")try{document.title=t[C]}catch{}}))}function $e(e){let t=n.trustedFrameOrigins;return!t||t.length===0?!0:typeof e=="string"&&t.indexOf(e)!==-1}function Qe(){n.pairingRecoverTimer||typeof setInterval>"u"||(n.pairingRecoverTimer=setInterval(()=>{n.pairing&&k().indexOf(R)<0&&ye()},n.pairRecoverMs))}function Ze(){n.pairingTimeoutTimer||typeof setTimeout>"u"||(n.pairingTimeoutTimer=setTimeout(()=>{n.pairingTimeoutTimer=null,ge(!0)},n.pairTimeoutMs))}function he(){if(!n.pairing)return;let e=n.ws;ge(!1),e&&et(e)}function et(e){let t={v:1,type:"event",op:ce,ts:Math.floor(Date.now()/1e3),payload:{pair_id:n.pairId,openParams:n.openParams||{}}};try{e.send(JSON.stringify(t))}catch(o){l("error",new Error("atkonoffice: failed to send launch.open frame \u2014 "+x(o)))}}function ge(e){n.pairingRecoverTimer&&(clearInterval(n.pairingRecoverTimer),n.pairingRecoverTimer=null),n.pairingTimeoutTimer&&(clearTimeout(n.pairingTimeoutTimer),n.pairingTimeoutTimer=null);let t=n.pairing;n.pairing=!1,n.pairingTitleSaved&&(v(n.pairingPrevTitle),n.pairingTitleSaved=!1),e&&t&&(N(n.fallbackUrl),typeof n.onPairDowngrade=="function"&&n.onPairDowngrade())}var we="documentEmbedFailed";function Te(e){let t=e||{};l(we,t),$(we)||tt(typeof t.reason=="string"?t.reason:"")}function tt(e){if(typeof document>"u"||!document.body||typeof document.createElement!="function")return null;X();let t=document.createElement("div");t.setAttribute("data-atkonoffice-guide",Y),t.style.cssText="position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.45);font:14px/1.6 system-ui,-apple-system,sans-serif;";let o=document.createElement("div");o.style.cssText="background:#fff;color:#222;max-width:420px;width:86%;border-radius:8px;padding:24px;box-shadow:0 8px 32px rgba(0,0,0,0.25);box-sizing:border-box;";let r,i;e==="wps_not_installed"?(r="\u672A\u68C0\u6D4B\u5230 WPS",i="\u672A\u68C0\u6D4B\u5230\u672C\u673A\u5DF2\u5B89\u88C5 WPS Office,\u65E0\u6CD5\u5728\u7F16\u8F91\u5668\u4E2D\u6253\u5F00\u6587\u6863\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u5B89\u88C5 WPS \u540E\u91CD\u8BD5;\u82E5\u786E\u5DF2\u5B89\u88C5\u4ECD\u63D0\u793A,\u8BF7\u5C1D\u8BD5\u4EE5\u666E\u901A\u6743\u9650(\u975E\u7BA1\u7406\u5458)\u91CD\u65B0\u6253\u5F00\u3002"):e==="doc_fetch_failed"?(r="\u65E0\u6CD5\u83B7\u53D6\u6587\u6863",i="\u6587\u6863\u4E0B\u8F7D\u6216\u53C2\u6570\u6821\u9A8C\u5931\u8D25(\u53EF\u80FD\u662F\u7F51\u7EDC\u5F02\u5E38\u3001\u767B\u5F55\u6001\u8FC7\u671F\u6216\u65E0\u8BBF\u95EE\u6743\u9650),\u7F16\u8F91\u5668\u672A\u5F00\u59CB\u52A0\u8F7D\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u4E0E\u767B\u5F55\u72B6\u6001\u540E\u70B9\u300C\u91CD\u8BD5\u300D,\u6216\u8054\u7CFB\u7BA1\u7406\u5458\u6392\u67E5\u3002"):(r="\u7F16\u8F91\u5668\u5D4C\u5165\u5931\u8D25",i="\u7F16\u8F91\u5668\u672A\u80FD\u52A0\u8F7D\u6587\u6863(\u5D4C\u5165\u5931\u8D25)\u3002\u8BF7\u70B9\u300C\u91CD\u8BD5\u300D,\u6216\u8054\u7CFB\u7BA1\u7406\u5458\u6392\u67E5\u3002");let a=document.createElement("h2");a.textContent=r,a.style.cssText="margin:0 0 12px;font-size:18px;";let p=document.createElement("p");p.style.cssText="margin:0 0 20px;color:#444;",p.textContent=i;let s=document.createElement("div");s.style.cssText="display:flex;gap:10px;justify-content:flex-end;flex-wrap:wrap;";let m="font:inherit;padding:8px 16px;border-radius:6px;cursor:pointer;border:1px solid #ccc;background:#f6f6f6;color:#222;",u=document.createElement("button");u.type="button",u.textContent="\u91CD\u8BD5",u.style.cssText=m,u.addEventListener("click",()=>{X();try{typeof n.replayOpen=="function"&&n.replayOpen()}catch{}});let c=document.createElement("button");return c.type="button",c.textContent="\u5173\u95ED",c.style.cssText=m,c.addEventListener("click",()=>X()),s.appendChild(u),s.appendChild(c),o.appendChild(a),o.appendChild(p),o.appendChild(s),t.appendChild(o),document.body.appendChild(t),t}function X(){if(!(typeof document>"u"||typeof document.querySelector!="function"))try{let e=document.querySelector('[data-atkonoffice-guide="'+Y+'"]');e&&typeof e.remove=="function"?e.remove():e&&e.parentNode&&typeof e.parentNode.removeChild=="function"&&e.parentNode.removeChild(e)}catch{}}function be(e,t){if(!(!e||typeof sessionStorage>"u"))try{sessionStorage.setItem(j,JSON.stringify({pairId:e,wsUrl:t}))}catch{}}function xe(){if(n.pairId)return{pairId:n.pairId,wsUrl:n.wsUrl};if(typeof sessionStorage>"u")return null;try{let e=sessionStorage.getItem(j);return e?JSON.parse(e):null}catch{return null}}function H(){if(n.ws||n.wsReconnectTimer||!n.backendBase)return;let e=xe();!e||!e.pairId||(n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,n.wsReconnectAttempt=0,Ee(e.pairId,t=>M(t)))}function M(e){if(typeof WebSocket>"u"){l("error",new Error("atkonoffice: WebSocket unavailable in this host \u2014 document events disabled"));return}if(!n.wsUrl){l("error",new Error("atkonoffice: no wsUrl \u2014 cannot open the document-event channel"));return}if(!e){l("error",new Error("atkonoffice: missing ws_ticket \u2014 cannot subscribe to document events"));return}nt();let t=A(n.wsUrl,"ticket",encodeURIComponent(e)),o;try{o=new WebSocket(t)}catch(r){l("error",new Error("atkonoffice: WS connect failed \u2014 "+x(r))),P();return}n.ws=o,o.onopen=()=>{n.wsReconnectAttempt=0,n.wsGaveUp=!1,ot(o),n.pairing&&me()},o.onmessage=r=>{rt(r&&r.data)},o.onerror=()=>{l("error",new Error("atkonoffice: WS error on the document-event channel"))},o.onclose=r=>{n.ws===o&&(n.ws=null),!(r&&r.code===1e3)&&P()}}function nt(){n.wsReconnectTimer&&(clearTimeout(n.wsReconnectTimer),n.wsReconnectTimer=null);let e=n.ws;if(n.ws=null,e){e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null;try{e.close(1e3,"client_close")}catch{}}}function ot(e){if(!U(n.headers))return;let t={v:1,type:"event",op:"client.headers",ts:Math.floor(Date.now()/1e3),payload:{headers:n.headers}};try{e.send(JSON.stringify(t))}catch(o){l("error",new Error("atkonoffice: failed to send headers frame \u2014 "+x(o)))}}function rt(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}if(!t||t.type!=="event")return;if(t.op===I){he();return}if(t.op===fe){Te(t.payload||{});return}let o=g[t.op];o&&l(o,t.payload||{})}function P(){if(n.wsReconnectTimer||n.wsGaveUp)return;let e=xe();if(!e||!e.pairId){l("error",new Error("atkonoffice: document-event channel dropped and no pair to resume"));return}if(n.wsReconnectAttempt>=K){n.wsGaveUp=!0;let r=new Error("atkonoffice: document-event channel lost \u2014 gave up after "+K+" consecutive reconnect attempts");r.terminal=!0,l("error",r);return}let t=n.wsReconnectAttempt+1;n.wsReconnectAttempt=t;let o=Math.min(3e4,500*Math.pow(2,t-1));n.wsReconnectTimer=setTimeout(()=>{n.wsReconnectTimer=null,Ee(e.pairId,r=>{n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,M(r)})},o)}async function Ee(e,t){let o=z();if(!o||!n.backendBase){l("error",new Error("atkonoffice: cannot refresh ws_ticket \u2014 backend not configured")),P();return}try{let r=await o(n.backendBase+n.wsTicketPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pairId:e})});if(!r.ok){l("error",new Error("atkonoffice: ws_ticket refresh returned HTTP "+r.status)),P();return}let i=await r.json();if(!i||typeof i.wsTicket!="string"||!i.wsTicket){l("error",new Error("atkonoffice: ws_ticket refresh response missing wsTicket")),P();return}typeof i.wsUrl=="string"&&i.wsUrl&&(n.wsUrl=i.wsUrl),t(i.wsTicket)}catch(r){l("error",new Error("atkonoffice: ws_ticket refresh failed \u2014 "+x(r))),P()}}function $(e){let t=n.eventHandlers[e];return!!t&&t.length>0}function it(e){for(let t in g)if(g.hasOwnProperty(t)&&g[t]===e)return!0;return!1}function ke(){for(let e in g)if(g.hasOwnProperty(e)&&$(g[e]))return!0;return!1}function l(e,t){let o=n.eventHandlers[e];if(!o||o.length===0){if(e==="error")try{console.error("[atkonoffice] "+(t&&t.message?t.message:t))}catch{}return}for(let r of o.slice())try{r(t)}catch{}}function ve(e,t){if(typeof e!="string"||V.indexOf(e)===-1)throw new TypeError('atkonoffice.on: unknown event "'+e+'" (expected one of '+V.join(", ")+")");if(typeof t!="function")throw new TypeError("atkonoffice.on: handler must be a function");return n.eventHandlers[e]||(n.eventHandlers[e]=[]),n.eventHandlers[e].push(t),it(e)&&H(),h}function Pe(){at(n.pairTimeoutMs).then(e=>{e.installed||ct(e.clientDownloadUrl)})}function at(e){return new Promise(t=>{let o=!1,r=null,i=null,a=null,p=!1,s="",m="",u=()=>{if(i&&(clearTimeout(i),i=null),a&&(clearInterval(a),a=null),p&&(v(s),p=!1),r){r.onopen=r.onmessage=r.onerror=r.onclose=null;try{r.close(1e3,"probe_done")}catch{}r=null}},c=y=>{o||(o=!0,u(),t({installed:y,clientDownloadUrl:m}))};i=setTimeout(()=>c(!1),e),st().then(y=>{if(y&&typeof y.clientDownloadUrl=="string"&&(m=y.clientDownloadUrl),o||!B(y)){c(!1);return}let F=y.wsUrl,re=typeof y.pairId=="string"?y.pairId:"",ie=y.launchTicket;q();let b;try{b=new WebSocket(A(F,"ticket",encodeURIComponent(y.wsTicket)))}catch{c(!1);return}r=b,b.onopen=()=>{s=k(),p=!0,v(L(F,re,ie)),a=setInterval(()=>{!o&&k().indexOf(R)<0&&v(L(F,re,ie))},n.pairRecoverMs)},b.onmessage=W=>{let ae=W&&W.data;if(typeof ae!="string")return;let O;try{O=JSON.parse(ae)}catch{return}O&&O.type==="event"&&O.op===I&&c(!0)},b.onerror=()=>{},b.onclose=()=>{}}).catch(()=>{c(!1)})})}async function st(){return D({docId:"",page:"",openType:"",user:""},"atkonoffice: launch-probe")}function ct(e){if(typeof document>"u"||!document.body||typeof document.createElement!="function")return null;Q();let t=document.createElement("div");t.setAttribute("data-atkonoffice-guide",J),t.style.cssText="position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.45);font:14px/1.6 system-ui,-apple-system,sans-serif;";let o=document.createElement("div");o.style.cssText="background:#fff;color:#222;max-width:420px;width:86%;border-radius:8px;padding:24px;box-shadow:0 8px 32px rgba(0,0,0,0.25);box-sizing:border-box;";let r=document.createElement("h2");r.textContent="\u9700\u8981\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF",r.style.cssText="margin:0 0 12px;font-size:18px;";let i=document.createElement("p");i.style.cssText="margin:0 0 20px;color:#444;",i.textContent=e?"\u672A\u68C0\u6D4B\u5230\u672C\u673A\u5DF2\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF\u3002\u8BF7\u5148\u4E0B\u8F7D\u5E76\u5B89\u88C5,\u5B89\u88C5\u5B8C\u6210\u540E\u70B9\u300C\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5\u300D\u3002":"\u672A\u68C0\u6D4B\u5230\u672C\u673A\u5DF2\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF,\u4E14\u672A\u914D\u7F6E\u4E0B\u8F7D\u5730\u5740\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u83B7\u53D6\u5B89\u88C5\u5305,\u5B89\u88C5\u5B8C\u6210\u540E\u70B9\u300C\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5\u300D\u3002";let a=document.createElement("div");a.style.cssText="display:flex;gap:10px;justify-content:flex-end;flex-wrap:wrap;";let p="font:inherit;padding:8px 16px;border-radius:6px;cursor:pointer;border:1px solid #ccc;background:#f6f6f6;color:#222;",s="font:inherit;padding:8px 16px;border-radius:6px;cursor:pointer;border:1px solid #1a6dd6;background:#1a6dd6;color:#fff;text-decoration:none;display:inline-block;";if(e){let c=document.createElement("a");c.textContent="\u4E0B\u8F7D\u5BA2\u6237\u7AEF",c.href=e,c.target="_blank",c.rel="noopener noreferrer",c.style.cssText=s,a.appendChild(c)}let m=document.createElement("button");m.type="button",m.textContent="\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5",m.style.cssText=p,m.addEventListener("click",()=>{Q();try{typeof n.replayOpen=="function"&&n.replayOpen()}catch{}});let u=document.createElement("button");return u.type="button",u.textContent="\u5173\u95ED",u.style.cssText=p,u.addEventListener("click",()=>Q()),a.appendChild(m),a.appendChild(u),o.appendChild(r),o.appendChild(i),o.appendChild(a),t.appendChild(o),document.body.appendChild(t),t}function Q(){if(!(typeof document>"u"||typeof document.querySelector!="function"))try{let e=document.querySelector('[data-atkonoffice-guide="'+J+'"]');e&&typeof e.remove=="function"?e.remove():e&&e.parentNode&&typeof e.parentNode.removeChild=="function"&&e.parentNode.removeChild(e)}catch{}}function Re(e){if(!e||typeof e!="object")throw new TypeError("atkonoffice.config requires an options object");if(typeof e.backendBase=="string"&&(n.backendBase=le(e.backendBase)),typeof e.launchPath=="string"&&e.launchPath&&(n.launchPath=e.launchPath),typeof e.wsTicketPath=="string"&&e.wsTicketPath&&(n.wsTicketPath=e.wsTicketPath),typeof e.fetchImpl=="function"&&(n.fetchImpl=e.fetchImpl),Array.isArray(e.trustedFrameOrigins)){let t=e.trustedFrameOrigins.filter(o=>typeof o=="string"&&o);n.trustedFrameOrigins=t.length>0?t:null}return n.initialized=!0,ke()&&H(),h}async function Z(e){let t=e||{};if(!n.backendBase)throw new Error("atkonoffice.open: backendBase not configured \u2014 call atkonoffice.config({ backendBase }) first");let o=t.page!=null?String(t.page):"",r=t.params||{},i=r.docId!=null?String(r.docId):"";if(!o&&!i)throw new Error("atkonoffice.open: docId is required \u2014 call open({ params: { docId, \u2026 } }) (page-less \u6A21\u5F0F\u4E0B\u65E0\u4E1A\u52A1\u9875\u53EF\u951A docId\uFF0C\u4E0B\u8F7D/\u4FDD\u5B58\u5747 docId \u7ED1\u5B9A)");let a={docId:i,page:o,openType:r.openType!=null?String(r.openType):"",user:r.user!=null?String(r.user):""},p=lt(t.options);p&&(a.options=p),typeof t.compareWith=="string"&&t.compareWith&&(a.compareWith=t.compareWith),typeof t.compareMode=="string"&&t.compareMode&&(a.compareMode=t.compareMode),typeof t.hostPagePath=="string"&&t.hostPagePath&&(a.hostPagePath=t.hostPagePath),typeof t.compareHost=="string"&&t.compareHost&&(a.compareHost=t.compareHost),typeof t.create=="string"&&t.create&&(a.create=t.create),t.storage&&typeof t.storage=="object"&&Object.keys(t.storage).length>0&&(a.storage=t.storage);let s=await D(a,"atkonoffice.open: launch");if(!s||typeof s.launchUrl!="string"||!s.launchUrl)throw new Error("atkonoffice.open: launch endpoint response missing launchUrl");let m=ft(t);n.headers=U(m)?m:null;let u=B(s);return n.replayOpen=()=>Z(e),n.onPairDowngrade=u?Pe:null,typeof s.wsTicket=="string"&&s.wsTicket&&typeof s.wsUrl=="string"&&s.wsUrl&&(n.wsUrl=s.wsUrl,n.pairId=typeof s.pairId=="string"?s.pairId:"",be(n.pairId,n.wsUrl),n.wsReconnectAttempt=0,n.wsGaveUp=!1,u&&pe(s),M(s.wsTicket)),u||N(s.launchUrl),{launchUrl:s.launchUrl,downloadUrl:typeof s.downloadUrl=="string"?s.downloadUrl:"",pairId:n.pairId,wsUrl:n.wsUrl}}function ft(e){let t={},o=e.headers;if(Array.isArray(o)){for(let i of o)if(Array.isArray(i)&&i.length>=2)E(t,i[0],i[1]);else if(typeof i=="string"&&i.indexOf(":")!==-1){let a=i.indexOf(":");E(t,i.slice(0,a),i.slice(a+1).trim())}}else if(o&&typeof o=="object")for(let i of Object.keys(o))E(t,i,o[i]);let r=de(e.cookie);return r&&E(t,"Cookie",r),e.storage&&typeof e.storage=="object"&&E(t,"X-Atkonoffice-Storage",JSON.stringify(e.storage)),t}function lt(e){if(!e||typeof e!="object")return null;let t={};return typeof e.width=="number"&&(t.width=e.width),typeof e.height=="number"&&(t.height=e.height),typeof e.modal=="boolean"&&(t.modal=e.modal),Object.keys(t).length>0?t:null}var f={};var Se="atkonoffice-doc-host",ee="__atkonofficeDocHostEvent",te=["documentSaved","documentOpened","documentBeforeSave","error","controlReady","compareDiff"],_e={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave","compare.diff":"compareDiff"},Oe="controlReady",Ie="toolbarClick",Ce="readbackResult",d={eventHandlers:{},hintShown:!1,toolbarButtons:{},toolbarSeq:0,readbackPending:{},readbackSeq:0};function Ae(e,t,o){if(typeof e!="string")throw new TypeError("atkonoffice embed.addCustomToolButton: caption must be a string");if(typeof o!="function")throw new TypeError("atkonoffice embed.addCustomToolButton: onClick must be a function");if(typeof window>"u")return null;T();let r=typeof t=="number"&&isFinite(t)?Math.trunc(t):0,i="btn-"+ ++d.toolbarSeq;return d.toolbarButtons[i]=o,w("toolbarAdd",JSON.stringify({buttonId:i,caption:e,iconIndex:r}))?{remove:function(){delete d.toolbarButtons[i],w("toolbarRemove",JSON.stringify({buttonId:i}))}}:(delete d.toolbarButtons[i],He(),null)}function Ue(e){if(typeof e!="boolean")throw new TypeError("atkonoffice embed.setCustomToolbarVisible: visible must be a boolean");return typeof window>"u"?f:(T(),w("toolbarSetVisible",JSON.stringify({visible:e})),f)}function Ne(e){let t=e&&e.buttonId;if(typeof t!="string"||!t)return;let o=d.toolbarButtons[t];if(typeof o=="function")try{o()}catch(r){Me("addCustomToolButton onClick threw: "+(r&&r.message?r.message:r))}}function S(){if(typeof window>"u")return null;let e=window.atkonofficeCtrl=window.atkonofficeCtrl||{};return typeof e.save!="function"&&(e.save=function(t){let o=t&&typeof t=="object"?JSON.stringify(t):void 0;return typeof e._WebSave=="function"?e._WebSave(o):w("save",o)}),typeof e.exec!="function"&&(e.exec=function(t){return typeof t!="string"||!t?!1:w("executeJs",t)}),typeof e.setSavePath!="function"&&(e.setSavePath=function(t){return typeof t!="string"||!t?!1:w("setSavePath",t)}),typeof e.saveAsPdf!="function"&&(e.saveAsPdf=function(){return w("saveAsPdf")}),e}function Be(e){let t=S();return t&&typeof t.save=="function"?t.save(e):!1}function De(e){let t=S();return t&&typeof t.setSavePath=="function"?t.setSavePath(e):!1}function Le(){let e=S();return e&&typeof e.saveAsPdf=="function"?e.saveAsPdf():!1}function w(e,t){if(typeof window>"u")return!1;let o=window.__atkonofficeDocHost;return o&&typeof o.sendCommand=="function"?(t!=null?o.sendCommand(e,t):o.sendCommand(e),!0):!1}var dt=15e3;function _(e,t){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});T();let o=++d.readbackSeq,r=JSON.stringify({rid:o,method:e,args:Array.isArray(t)?t:[]});return new Promise(i=>{let a=setTimeout(function(){ne(o,{ok:!1,error:"timeout"})},dt);a&&typeof a.unref=="function"&&a.unref(),d.readbackPending[o]={resolve:i,timer:a},w("readback",r)||ne(o,{ok:!1,error:"shell-absent"})})}function ne(e,t){let o=d.readbackPending[e];o&&(delete d.readbackPending[e],clearTimeout(o.timer),o.resolve(t))}function Fe(e){let t=e&&e.rid;typeof t=="number"&&ne(t,{ok:!!(e&&e.ok),value:e?e.value:void 0,error:e?e.error:void 0})}function T(){ut(),S()}function je(e,t){if(typeof e!="string"||te.indexOf(e)===-1)throw new TypeError('atkonoffice embed.on: unknown event "'+e+'" (expected one of '+te.join(", ")+")");if(typeof t!="function")throw new TypeError("atkonoffice embed.on: handler must be a function");return T(),d.eventHandlers[e]||(d.eventHandlers[e]=[]),d.eventHandlers[e].push(t),f}function ut(){typeof window>"u"||typeof window[ee]=="function"||(window[ee]=function(e,t){if(e===Oe){We("controlReady",t||{});return}if(e===Ie){Ne(t||{});return}if(e===Ce){Fe(t||{});return}let o=_e[e];o&&We(o,t||{})})}function We(e,t){let o=d.eventHandlers[e];if(!o||o.length===0){if(e==="error")try{console.error("[atkonoffice embed] "+(t&&t.message?t.message:t))}catch{}return}for(let r of o.slice())try{r(t)}catch{}}function He(){if(!d.hintShown){d.hintShown=!0;try{console.info("[atkonoffice embed] <"+Se+"> \u672A\u88AB\u5B9A\u4E49 \u2014\u2014 \u8BF7\u5728\u5DF2\u5B89\u88C5 atkonoffice \u5BA2\u6237\u7AEF\u7684\u58F3\u5185\u6253\u5F00\u672C\u7F16\u8F91\u9875;\u666E\u901A\u6D4F\u89C8\u5668\u91CC\u5B83\u662F\u7A7A\u76D2(\u4E0D\u5F71\u54CD\u9875\u9762\u5176\u4F59\u90E8\u5206)\u3002")}catch{}}}function Me(e){try{console.warn("[atkonoffice embed] "+e)}catch{}}function Ke(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeSave: fn must be a function");return T(),Je("onBeforeSave",e),f}function Ve(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeClose: fn must be a function");return T(),Je("onBeforeClose",e),f}function Je(e,t){if(typeof window>"u")return!1;let o=window.__atkonofficeDocHost;return o&&typeof o[e]=="function"?(o[e](t),!0):!1}var pt="AO_";function oe(e){return!!(e&&e.ok&&Number(e.value)>0)}function Ye(e,t){if(typeof e!="string"||!e)return Promise.resolve(!1);let o=typeof t=="string"?t:t==null?"":String(t);return _("Word_AddDataRegion",[e,o]).then(oe)}function Ge(e){return typeof e!="string"||!e?Promise.resolve(!1):_("Word_DeleteDataRegion",[e]).then(oe)}function ze(e){return typeof e!="string"||!e?Promise.resolve(!1):_("Word_LocateDataRegion",[e]).then(oe)}function qe(e){let t=typeof e=="string"?e:pt;return _("BookmarksAsJson",[]).then(function(o){if(!o||!o.ok)return[];let r;try{r=JSON.parse(o.value)}catch{return[]}return Array.isArray(r)?r.filter(function(i){return typeof i=="string"&&(t===""||i.indexOf(t)===0)}):[]})}f.on=je;f.addCustomToolButton=Ae;f.setCustomToolbarVisible=Ue;f.save=Be;f.setSavePath=De;f.saveAsPdf=Le;f.onBeforeSave=Ke;f.onBeforeClose=Ve;f.word={addDataRegion:Ye,deleteDataRegion:Ge,locateDataRegion:ze,listDataRegions:qe};h.config=Re;h.open=Z;h.on=ve;h.session=f;var mt=h,In=mt;export{mt as atkonoffice,In as default};
|
|
1
|
+
var y={};var n={backendBase:"",launchPath:"/atkonoffice-rpc/launch",wsTicketPath:"/atkonoffice-rpc/ws-ticket",fetchImpl:null,initialized:!1,ws:null,wsUrl:"",pairId:"",headers:null,eventHandlers:{},wsReconnectAttempt:0,wsReconnectTimer:null,wsGaveUp:!1,pairing:!1,launchTicket:"",openParams:null,fallbackUrl:"",pairingPrevTitle:"",pairingTitleSaved:!1,pairingRecoverTimer:null,pairingTimeoutTimer:null,pairTimeoutMs:5e3,pairRecoverMs:1e3,titleRelayInstalled:!1,trustedFrameOrigins:null,onPairDowngrade:null,replayOpen:null},O="atkonoffice.ws.session",K=12,V=["documentSaved","documentOpened","documentBeforeSave","documentEmbedFailed","error"],g={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave"},P="atkonoffice-launch=",re="\u2007",I="pair.ready",ie="launch.open",ae="doc.embedFailed",C="__atkonofficeTitle",J="atkonoffice-install-guide";function se(e){return e&&e.endsWith("/")?e.slice(0,-1):e}function U(e,t,o){let r=e.indexOf("?")===-1?"?":"&";return e+r+t+"="+o}function A(e){return!!e&&Object.keys(e).length>0}function x(e){return e&&e.message?e.message:String(e)}function E(e,t,o){if(t==null)return;let r=String(t).trim();r&&(e[r]=o==null?"":String(o))}function ce(e){return e?typeof e=="string"?e:typeof e=="object"?Object.keys(e).map(t=>t+"="+String(e[t])).join("; "):"":""}function fe(e){let t;if(typeof TextEncoder<"u"){let o=new TextEncoder().encode(e),r="";for(let i=0;i<o.length;i++)r+=String.fromCharCode(o[i]);t=r}else t=unescape(encodeURIComponent(e));return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function k(){try{return typeof document<"u"&&typeof document.title=="string"?document.title:""}catch{return""}}function Y(){if(typeof window>"u")return!1;try{return window.top!==window.self}catch{return!0}}function B(e){try{let t=document.createElement("iframe");t.style.display="none",t.src=e,document.body.appendChild(t),setTimeout(()=>{try{document.body.removeChild(t)}catch{}},1e3)}catch{window.location.href=e}}function N(e){return!!(typeof e.launchTicket=="string"&&e.launchTicket&&typeof e.wsUrl=="string"&&e.wsUrl&&typeof e.wsTicket=="string"&&e.wsTicket&&typeof document<"u"&&typeof WebSocket<"u")}function G(){return typeof n.fetchImpl=="function"?n.fetchImpl:typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):null}function Ye(){let e=G();if(!e)throw new Error("atkonoffice: no fetch available \u2014 pass fetchImpl via config in non-browser hosts");return e}async function D(e,t){let r=await Ye()(n.backendBase+n.launchPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok)throw new Error(t+" endpoint returned HTTP "+r.status);return r.json()}function le(e){n.launchTicket=e.launchTicket,n.openParams=e.openParams&&typeof e.openParams=="object"?e.openParams:{},n.fallbackUrl=e.launchUrl,n.pairing=!0,n.pairingTitleSaved=!1,z(),Xe()}function ue(){!n.pairing||typeof document>"u"||(n.pairingTitleSaved||(n.pairingPrevTitle=k(),n.pairingTitleSaved=!0),de(),ze())}function de(){R(L(n.wsUrl,n.pairId,n.launchTicket))}function L(e,t,o){let r=fe(JSON.stringify({wsUrl:e,pairId:t,launchTicket:o}));return re+P+r}function R(e){try{typeof document<"u"&&(document.title=e)}catch{}if(Y())try{let t={};t[C]=e,window.top.postMessage(t,"*")}catch{}}function z(){n.titleRelayInstalled||typeof window>"u"||typeof window.addEventListener!="function"||Y()||(n.titleRelayInstalled=!0,window.addEventListener("message",e=>{if(!Ge(e&&e.origin))return;let t=e&&e.data;if(t&&typeof t=="object"&&typeof t[C]=="string")try{document.title=t[C]}catch{}}))}function Ge(e){let t=n.trustedFrameOrigins;return!t||t.length===0?!0:typeof e=="string"&&t.indexOf(e)!==-1}function ze(){n.pairingRecoverTimer||typeof setInterval>"u"||(n.pairingRecoverTimer=setInterval(()=>{n.pairing&&k().indexOf(P)<0&&de()},n.pairRecoverMs))}function Xe(){n.pairingTimeoutTimer||typeof setTimeout>"u"||(n.pairingTimeoutTimer=setTimeout(()=>{n.pairingTimeoutTimer=null,me(!0)},n.pairTimeoutMs))}function pe(){if(!n.pairing)return;let e=n.ws;me(!1),e&&qe(e)}function qe(e){let t={v:1,type:"event",op:ie,ts:Math.floor(Date.now()/1e3),payload:{pair_id:n.pairId,openParams:n.openParams||{}}};try{e.send(JSON.stringify(t))}catch(o){c("error",new Error("atkonoffice: failed to send launch.open frame \u2014 "+x(o)))}}function me(e){n.pairingRecoverTimer&&(clearInterval(n.pairingRecoverTimer),n.pairingRecoverTimer=null),n.pairingTimeoutTimer&&(clearTimeout(n.pairingTimeoutTimer),n.pairingTimeoutTimer=null);let t=n.pairing;n.pairing=!1,n.pairingTitleSaved&&(R(n.pairingPrevTitle),n.pairingTitleSaved=!1),e&&t&&(B(n.fallbackUrl),typeof n.onPairDowngrade=="function"&&n.onPairDowngrade())}var $e="documentEmbedFailed";function he(e){c($e,e||{})}function ye(e,t){if(!(!e||typeof sessionStorage>"u"))try{sessionStorage.setItem(O,JSON.stringify({pairId:e,wsUrl:t}))}catch{}}function ge(){if(n.pairId)return{pairId:n.pairId,wsUrl:n.wsUrl};if(typeof sessionStorage>"u")return null;try{let e=sessionStorage.getItem(O);return e?JSON.parse(e):null}catch{return null}}function we(){if(n.pairId="",n.wsUrl="",!(typeof sessionStorage>"u"))try{sessionStorage.removeItem(O)}catch{}}function H(){if(n.ws||n.wsReconnectTimer||!n.backendBase)return;let e=ge();!e||!e.pairId||(n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,n.wsReconnectAttempt=0,Te(e.pairId,t=>M(t)))}function M(e){if(typeof WebSocket>"u"){c("error",new Error("atkonoffice: WebSocket unavailable in this host \u2014 document events disabled"));return}if(!n.wsUrl){c("error",new Error("atkonoffice: no wsUrl \u2014 cannot open the document-event channel"));return}if(!e){c("error",new Error("atkonoffice: missing ws_ticket \u2014 cannot subscribe to document events"));return}Qe();let t=U(n.wsUrl,"ticket",encodeURIComponent(e)),o;try{o=new WebSocket(t)}catch(r){c("error",new Error("atkonoffice: WS connect failed \u2014 "+x(r))),v();return}n.ws=o,o.onopen=()=>{n.wsReconnectAttempt=0,n.wsGaveUp=!1,Ze(o),n.pairing&&ue()},o.onmessage=r=>{et(r&&r.data)},o.onerror=()=>{c("error",new Error("atkonoffice: WS error on the document-event channel"))},o.onclose=r=>{if(n.ws===o&&(n.ws=null),r&&r.code===1e3){we();return}v()}}function Qe(){n.wsReconnectTimer&&(clearTimeout(n.wsReconnectTimer),n.wsReconnectTimer=null);let e=n.ws;if(n.ws=null,e){e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null;try{e.close(1e3,"client_close")}catch{}}}function Ze(e){if(!A(n.headers))return;let t={v:1,type:"event",op:"client.headers",ts:Math.floor(Date.now()/1e3),payload:{headers:n.headers}};try{e.send(JSON.stringify(t))}catch(o){c("error",new Error("atkonoffice: failed to send headers frame \u2014 "+x(o)))}}function et(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}if(!t||t.type!=="event")return;if(t.op===I){pe();return}if(t.op===ae){he(t.payload||{});return}let o=g[t.op];o&&c(o,t.payload||{})}function v(){if(n.wsReconnectTimer||n.wsGaveUp)return;let e=ge();if(!e||!e.pairId){c("error",new Error("atkonoffice: document-event channel dropped and no pair to resume"));return}if(n.wsReconnectAttempt>=K){n.wsGaveUp=!0,we();let r=new Error("atkonoffice: document-event channel lost \u2014 gave up after "+K+" consecutive reconnect attempts");r.terminal=!0,c("error",r);return}let t=n.wsReconnectAttempt+1;n.wsReconnectAttempt=t;let o=Math.min(3e4,500*Math.pow(2,t-1));n.wsReconnectTimer=setTimeout(()=>{n.wsReconnectTimer=null,Te(e.pairId,r=>{n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,M(r)})},o)}async function Te(e,t){let o=G();if(!o||!n.backendBase){c("error",new Error("atkonoffice: cannot refresh ws_ticket \u2014 backend not configured")),v();return}try{let r=await o(n.backendBase+n.wsTicketPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pairId:e})});if(!r.ok){c("error",new Error("atkonoffice: ws_ticket refresh returned HTTP "+r.status)),v();return}let i=await r.json();if(!i||typeof i.wsTicket!="string"||!i.wsTicket){c("error",new Error("atkonoffice: ws_ticket refresh response missing wsTicket")),v();return}typeof i.wsUrl=="string"&&i.wsUrl&&(n.wsUrl=i.wsUrl),t(i.wsTicket)}catch(r){c("error",new Error("atkonoffice: ws_ticket refresh failed \u2014 "+x(r))),v()}}function tt(e){let t=n.eventHandlers[e];return!!t&&t.length>0}function nt(e){for(let t in g)if(g.hasOwnProperty(t)&&g[t]===e)return!0;return!1}function be(){for(let e in g)if(g.hasOwnProperty(e)&&tt(g[e]))return!0;return!1}function c(e,t){let o=n.eventHandlers[e];if(!o||o.length===0){if(e==="error")try{console.error("[atkonoffice] "+(t&&t.message?t.message:t))}catch{}return}for(let r of o.slice())try{r(t)}catch{}}function xe(e,t){if(typeof e!="string"||V.indexOf(e)===-1)throw new TypeError('atkonoffice.on: unknown event "'+e+'" (expected one of '+V.join(", ")+")");if(typeof t!="function")throw new TypeError("atkonoffice.on: handler must be a function");return n.eventHandlers[e]||(n.eventHandlers[e]=[]),n.eventHandlers[e].push(t),nt(e)&&H(),y}function Ee(){ot(n.pairTimeoutMs).then(e=>{e.installed||it(e.clientDownloadUrl)})}function ot(e){return new Promise(t=>{let o=!1,r=null,i=null,a=null,h=!1,s="",p="",m=()=>{if(i&&(clearTimeout(i),i=null),a&&(clearInterval(a),a=null),h&&(R(s),h=!1),r){r.onopen=r.onmessage=r.onerror=r.onclose=null;try{r.close(1e3,"probe_done")}catch{}r=null}},u=d=>{o||(o=!0,m(),t({installed:d,clientDownloadUrl:p}))};i=setTimeout(()=>u(!1),e),rt().then(d=>{if(d&&typeof d.clientDownloadUrl=="string"&&(p=d.clientDownloadUrl),o||!N(d)){u(!1);return}let j=d.wsUrl,te=typeof d.pairId=="string"?d.pairId:"",ne=d.launchTicket;z();let b;try{b=new WebSocket(U(j,"ticket",encodeURIComponent(d.wsTicket)))}catch{u(!1);return}r=b,b.onopen=()=>{s=k(),h=!0,R(L(j,te,ne)),a=setInterval(()=>{!o&&k().indexOf(P)<0&&R(L(j,te,ne))},n.pairRecoverMs)},b.onmessage=W=>{let oe=W&&W.data;if(typeof oe!="string")return;let _;try{_=JSON.parse(oe)}catch{return}_&&_.type==="event"&&_.op===I&&u(!0)},b.onerror=()=>{},b.onclose=()=>{}}).catch(()=>{u(!1)})})}async function rt(){return D({docId:"",pageUrl:"",user:""},"atkonoffice: launch-probe")}function it(e){if(typeof document>"u"||!document.body||typeof document.createElement!="function")return null;X();let t=document.createElement("div");t.setAttribute("data-atkonoffice-guide",J),t.style.cssText="position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.45);font:14px/1.6 system-ui,-apple-system,sans-serif;";let o=document.createElement("div");o.style.cssText="background:#fff;color:#222;max-width:420px;width:86%;border-radius:8px;padding:24px;box-shadow:0 8px 32px rgba(0,0,0,0.25);box-sizing:border-box;";let r=document.createElement("h2");r.textContent="\u9700\u8981\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF",r.style.cssText="margin:0 0 12px;font-size:18px;";let i=document.createElement("p");i.style.cssText="margin:0 0 20px;color:#444;",i.textContent=e?"\u672A\u68C0\u6D4B\u5230\u672C\u673A\u5DF2\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF\u3002\u8BF7\u5148\u4E0B\u8F7D\u5E76\u5B89\u88C5,\u5B89\u88C5\u5B8C\u6210\u540E\u70B9\u300C\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5\u300D\u3002":"\u672A\u68C0\u6D4B\u5230\u672C\u673A\u5DF2\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF,\u4E14\u672A\u914D\u7F6E\u4E0B\u8F7D\u5730\u5740\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u83B7\u53D6\u5B89\u88C5\u5305,\u5B89\u88C5\u5B8C\u6210\u540E\u70B9\u300C\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5\u300D\u3002";let a=document.createElement("div");a.style.cssText="display:flex;gap:10px;justify-content:flex-end;flex-wrap:wrap;";let h="font:inherit;padding:8px 16px;border-radius:6px;cursor:pointer;border:1px solid #ccc;background:#f6f6f6;color:#222;",s="font:inherit;padding:8px 16px;border-radius:6px;cursor:pointer;border:1px solid #1a6dd6;background:#1a6dd6;color:#fff;text-decoration:none;display:inline-block;";if(e){let u=document.createElement("a");u.textContent="\u4E0B\u8F7D\u5BA2\u6237\u7AEF",u.href=e,u.target="_blank",u.rel="noopener noreferrer",u.style.cssText=s,a.appendChild(u)}let p=document.createElement("button");p.type="button",p.textContent="\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5",p.style.cssText=h,p.addEventListener("click",()=>{X();try{typeof n.replayOpen=="function"&&n.replayOpen()}catch{}});let m=document.createElement("button");return m.type="button",m.textContent="\u5173\u95ED",m.style.cssText=h,m.addEventListener("click",()=>X()),a.appendChild(p),a.appendChild(m),o.appendChild(r),o.appendChild(i),o.appendChild(a),t.appendChild(o),document.body.appendChild(t),t}function X(){if(!(typeof document>"u"||typeof document.querySelector!="function"))try{let e=document.querySelector('[data-atkonoffice-guide="'+J+'"]');e&&typeof e.remove=="function"?e.remove():e&&e.parentNode&&typeof e.parentNode.removeChild=="function"&&e.parentNode.removeChild(e)}catch{}}function ke(e){if(!e||typeof e!="object")throw new TypeError("atkonoffice.config requires an options object");if(typeof e.backendBase=="string"&&(n.backendBase=se(e.backendBase)),typeof e.launchPath=="string"&&e.launchPath&&(n.launchPath=e.launchPath),typeof e.wsTicketPath=="string"&&e.wsTicketPath&&(n.wsTicketPath=e.wsTicketPath),typeof e.fetchImpl=="function"&&(n.fetchImpl=e.fetchImpl),Array.isArray(e.trustedFrameOrigins)){let t=e.trustedFrameOrigins.filter(o=>typeof o=="string"&&o);n.trustedFrameOrigins=t.length>0?t:null}return n.initialized=!0,be()&&H(),y}async function q(e){let t=e||{};if(!n.backendBase)throw new Error("atkonoffice.open: backendBase not configured \u2014 call atkonoffice.config({ backendBase }) first");let o=t.pageUrl!=null?String(t.pageUrl):"",r=t.params||{},i=r.docId!=null?String(r.docId):"";if(!o&&!i)throw new Error("atkonoffice.open: docId is required \u2014 call open({ params: { docId, \u2026 } }) (page-less \u6A21\u5F0F\u4E0B\u65E0\u4E1A\u52A1\u9875\u53EF\u951A docId\uFF0C\u4E0B\u8F7D/\u4FDD\u5B58\u5747 docId \u7ED1\u5B9A)");let a={pageUrl:o,params:r},h=st(t.options);h&&(a.options=h),typeof t.pageApi=="string"&&t.pageApi&&(a.pageApi=t.pageApi),t.storage&&typeof t.storage=="object"&&Object.keys(t.storage).length>0&&(a.storage=t.storage);let s=await D(a,"atkonoffice.open: launch");if(!s||typeof s.launchUrl!="string"||!s.launchUrl)throw new Error("atkonoffice.open: launch endpoint response missing launchUrl");let p=at(t);n.headers=A(p)?p:null;let m=N(s);return n.replayOpen=()=>q(e),n.onPairDowngrade=m?Ee:null,typeof s.wsTicket=="string"&&s.wsTicket&&typeof s.wsUrl=="string"&&s.wsUrl&&(n.wsUrl=s.wsUrl,n.pairId=typeof s.pairId=="string"?s.pairId:"",ye(n.pairId,n.wsUrl),n.wsReconnectAttempt=0,n.wsGaveUp=!1,m&&le(s),M(s.wsTicket)),m||B(s.launchUrl),{launchUrl:s.launchUrl,downloadUrl:typeof s.downloadUrl=="string"?s.downloadUrl:"",pairId:n.pairId,wsUrl:n.wsUrl}}function at(e){let t={},o=e.headers;if(Array.isArray(o)){for(let i of o)if(Array.isArray(i)&&i.length>=2)E(t,i[0],i[1]);else if(typeof i=="string"&&i.indexOf(":")!==-1){let a=i.indexOf(":");E(t,i.slice(0,a),i.slice(a+1).trim())}}else if(o&&typeof o=="object")for(let i of Object.keys(o))E(t,i,o[i]);let r=ce(e.cookie);return r&&E(t,"Cookie",r),e.storage&&typeof e.storage=="object"&&E(t,"X-Atkonoffice-Storage",JSON.stringify(e.storage)),t}function st(e){if(!e||typeof e!="object")return null;let t={};return typeof e.width=="number"&&(t.width=e.width),typeof e.height=="number"&&(t.height=e.height),typeof e.modal=="boolean"&&(t.modal=e.modal),Object.keys(t).length>0?t:null}var f={};var Re="atkonoffice-doc-host",$="__atkonofficeDocHostEvent",Q=["documentSaved","documentOpened","documentBeforeSave","error","controlReady","compareDiff"],ve={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave","compare.diff":"compareDiff"},Pe="controlReady",Se="toolbarClick",_e="readbackResult",l={eventHandlers:{},hintShown:!1,toolbarButtons:{},toolbarSeq:0,readbackPending:{},readbackSeq:0};function Oe(e,t,o){if(typeof e!="string")throw new TypeError("atkonoffice embed.addCustomToolButton: caption must be a string");if(typeof o!="function")throw new TypeError("atkonoffice embed.addCustomToolButton: onClick must be a function");if(typeof window>"u")return null;w();let r=typeof t=="number"&&isFinite(t)?Math.trunc(t):0,i="btn-"+ ++l.toolbarSeq;return l.toolbarButtons[i]=o,T("toolbarAdd",JSON.stringify({buttonId:i,caption:e,iconIndex:r}))?{remove:function(){delete l.toolbarButtons[i],T("toolbarRemove",JSON.stringify({buttonId:i}))}}:(delete l.toolbarButtons[i],Be(),null)}function Ie(e){if(typeof e!="boolean")throw new TypeError("atkonoffice embed.setCustomToolbarVisible: visible must be a boolean");return typeof window>"u"?f:(w(),T("toolbarSetVisible",JSON.stringify({visible:e})),f)}function Ce(e){let t=e&&e.buttonId;if(typeof t!="string"||!t)return;let o=l.toolbarButtons[t];if(typeof o=="function")try{o()}catch(r){Ne("addCustomToolButton onClick threw: "+(r&&r.message?r.message:r))}}function F(){if(typeof window>"u")return null;let e=window.atkonofficeCtrl=window.atkonofficeCtrl||{};return typeof e.save!="function"&&(e.save=function(t){let o=t&&typeof t=="object"?JSON.stringify(t):void 0;return typeof e._WebSave=="function"?e._WebSave(o):T("save",o)}),typeof e.exec!="function"&&(e.exec=function(t){return typeof t!="string"||!t?!1:T("executeJs",t)}),typeof e.setSavePath!="function"&&(e.setSavePath=function(t){return typeof t!="string"||!t?!1:T("setSavePath",t)}),e}function Ue(e){let t=F();return t&&typeof t.save=="function"?t.save(e):!1}function Ae(e){let t=F();return t&&typeof t.setSavePath=="function"?t.setSavePath(e):!1}function T(e,t){if(typeof window>"u")return!1;let o=window.__atkonofficeDocHost;return o&&typeof o.sendCommand=="function"?(t!=null?o.sendCommand(e,t):o.sendCommand(e),!0):!1}var ct=15e3;function S(e,t){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});w();let o=++l.readbackSeq,r=JSON.stringify({rid:o,method:e,args:Array.isArray(t)?t:[]});return new Promise(i=>{let a=setTimeout(function(){Z(o,{ok:!1,error:"timeout"})},ct);a&&typeof a.unref=="function"&&a.unref(),l.readbackPending[o]={resolve:i,timer:a},T("readback",r)||Z(o,{ok:!1,error:"shell-absent"})})}function Z(e,t){let o=l.readbackPending[e];o&&(delete l.readbackPending[e],clearTimeout(o.timer),o.resolve(t))}function De(e){let t=e&&e.rid;typeof t=="number"&&Z(t,{ok:!!(e&&e.ok),value:e?e.value:void 0,error:e?e.error:void 0})}function w(){ft(),F()}function He(e,t){if(typeof e!="string"||Q.indexOf(e)===-1)throw new TypeError('atkonoffice embed.on: unknown event "'+e+'" (expected one of '+Q.join(", ")+")");if(typeof t!="function")throw new TypeError("atkonoffice embed.on: handler must be a function");return w(),l.eventHandlers[e]||(l.eventHandlers[e]=[]),l.eventHandlers[e].push(t),f}function ft(){typeof window>"u"||typeof window[$]=="function"||(window[$]=function(e,t){if(e===Pe){Le("controlReady",t||{});return}if(e===Se){Ce(t||{});return}if(e===_e){De(t||{});return}let o=ve[e];o&&Le(o,t||{})})}function Le(e,t){let o=l.eventHandlers[e];if(!o||o.length===0){if(e==="error")try{console.error("[atkonoffice embed] "+(t&&t.message?t.message:t))}catch{}return}for(let r of o.slice())try{r(t)}catch{}}function Be(){if(!l.hintShown){l.hintShown=!0;try{console.info("[atkonoffice embed] <"+Re+"> \u672A\u88AB\u5B9A\u4E49 \u2014\u2014 \u8BF7\u5728\u5DF2\u5B89\u88C5 atkonoffice \u5BA2\u6237\u7AEF\u7684\u58F3\u5185\u6253\u5F00\u672C\u7F16\u8F91\u9875;\u666E\u901A\u6D4F\u89C8\u5668\u91CC\u5B83\u662F\u7A7A\u76D2(\u4E0D\u5F71\u54CD\u9875\u9762\u5176\u4F59\u90E8\u5206)\u3002")}catch{}}}function Ne(e){try{console.warn("[atkonoffice embed] "+e)}catch{}}function Me(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeSave: fn must be a function");return w(),je("onBeforeSave",e),f}function Fe(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeClose: fn must be a function");return w(),je("onBeforeClose",e),f}function je(e,t){if(typeof window>"u")return!1;let o=window.__atkonofficeDocHost;return o&&typeof o[e]=="function"?(o[e](t),!0):!1}var lt="AO_";function ee(e){return!!(e&&e.ok&&Number(e.value)>0)}function We(e,t){if(typeof e!="string"||!e)return Promise.resolve(!1);let o=typeof t=="string"?t:t==null?"":String(t);return S("Word_AddDataRegion",[e,o]).then(ee)}function Ke(e){return typeof e!="string"||!e?Promise.resolve(!1):S("Word_DeleteDataRegion",[e]).then(ee)}function Ve(e){return typeof e!="string"||!e?Promise.resolve(!1):S("Word_LocateDataRegion",[e]).then(ee)}function Je(e){let t=typeof e=="string"?e:lt;return S("BookmarksAsJson",[]).then(function(o){if(!o||!o.ok)return[];let r;try{r=JSON.parse(o.value)}catch{return[]}return Array.isArray(r)?r.filter(function(i){return typeof i=="string"&&(t===""||i.indexOf(t)===0)}):[]})}f.on=He;f.addCustomToolButton=Oe;f.setCustomToolbarVisible=Ie;f.save=Ue;f.setSavePath=Ae;f.onBeforeSave=Me;f.onBeforeClose=Fe;f.word={addDataRegion:We,deleteDataRegion:Ke,locateDataRegion:Ve,listDataRegions:Je};y.config=ke;y.open=q;y.on=xe;y.session=f;var ut=y,Pn=ut;export{ut as atkonoffice,Pn as default};
|