@atkonoffice/sdk 1.12.0 → 1.14.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.
@@ -83,6 +83,24 @@ export interface AtkonofficeDocOpened {
83
83
  }
84
84
 
85
85
 
86
+ export interface AtkonofficeDocReady {
87
+
88
+ doc_id?: string
89
+
90
+ ready_at?: number
91
+
92
+ pair_id?: string
93
+ }
94
+
95
+
96
+ export interface AtkonofficeDocEmbedFailed {
97
+
98
+ reason: string
99
+
100
+ pair_id?: string
101
+ }
102
+
103
+
86
104
  export interface AtkonofficeDocBeforeSave {
87
105
 
88
106
  doc_id?: string
@@ -212,6 +230,13 @@ export interface AtkonofficeCompareDiff {
212
230
  }
213
231
 
214
232
 
233
+ export interface AtkonofficeCompareFailedEvent {
234
+
235
+ reason: string
236
+ [key: string]: unknown
237
+ }
238
+
239
+
215
240
  export interface AtkonofficeSessionWord {
216
241
 
217
242
  fillDataRegion(name: string, value: string): Promise<boolean>
@@ -326,6 +351,8 @@ export interface AtkonofficeSession {
326
351
 
327
352
  on(event: 'compareDiff', handler: (diff: AtkonofficeCompareDiff) => void): AtkonofficeSession
328
353
 
354
+ on(event: 'compareFailed', handler: (payload: AtkonofficeCompareFailedEvent) => void): AtkonofficeSession
355
+
329
356
  on(event: 'error', handler: (err: Error) => void): AtkonofficeSession
330
357
 
331
358
  addCustomToolButton(
@@ -357,6 +384,10 @@ export interface Atkonoffice {
357
384
 
358
385
  on(event: 'documentOpened', handler: (payload: AtkonofficeDocOpened) => void): Atkonoffice
359
386
 
387
+ on(event: 'documentReady', handler: (payload: AtkonofficeDocReady) => void): Atkonoffice
388
+
389
+ on(event: 'documentEmbedFailed', handler: (payload: AtkonofficeDocEmbedFailed) => void): Atkonoffice
390
+
360
391
  on(event: 'documentBeforeSave', handler: (payload: AtkonofficeDocBeforeSave) => void): Atkonoffice
361
392
 
362
393
  on(event: 'shellClosed', handler: (payload: AtkonofficeShellClosed) => void): Atkonoffice
@@ -1 +1 @@
1
- var R={};var n={backendBase:"",launchPath:"/atkonoffice/rpc/launch",wsTicketPath:"/atkonoffice/rpc/ws-ticket",fetchImpl:null,initialized:!1,ws:null,wsUrl:"",pairId:"",nodeBase:"",headers:null,eventHandlers:{},wsReconnectAttempt:0,wsReconnectTimer:null,wsTicketInFlight:!1,wsStopped:!1,wsBackoffExhausted:!1,channelLostAnnounced:!1,channelRestoreConfirmTimer:null,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,launchInFlight:!1,inFlightOpen:null};function O(){n.launchInFlight=!1,n.inFlightOpen=null}var H="atkonoffice.ws.session",ee=12,te=3e5,Ae=1e3,B="channelLost",L="channelRestored",F=["documentSaved","documentOpened","documentBeforeSave","documentEmbedFailed","shellClosed",B,L,"error"],ne="shell.closed",v={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave",[ne]:"shellClosed"},k="atkonoffice-launch=",M="\u2007",V="pair.ready",De="launch.open",Be="doc.embedFailed",W="__atkonofficeTitle",oe="atkonoffice-install-guide";function re(e){return e&&e.endsWith("/")?e.slice(0,-1):e}function Le(e,t){if(!e||!t)return!1;try{return new URL(e).origin===new URL(t).origin}catch{return!1}}function j(e,t,o){let r=e.indexOf("?")===-1?"?":"&";return e+r+t+"="+o}function Y(e){return!!e&&Object.keys(e).length>0}function b(e){return e&&e.message?e.message:String(e)}function N(e,t,o){if(t==null)return;let r=String(t).trim();r&&(e[r]=o==null?"":String(o))}function Ue(e){return e?typeof e=="string"?e:typeof e=="object"?Object.keys(e).map(t=>t+"="+String(e[t])).join("; "):"":""}function He(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 S(){try{return typeof document<"u"&&typeof document.title=="string"?document.title:""}catch{return""}}function ie(){if(typeof window>"u")return!1;try{return window.top!==window.self}catch{return!0}}function G(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 J(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")}var l={CONFIG:"config",LAUNCH:"launch",CHANNEL:"channel"},ae={backend_base_missing:l.CONFIG,doc_id_missing:l.CONFIG,fetch_unavailable:l.CONFIG,ws_unsupported:l.CONFIG,ws_ticket_backend_missing:l.CONFIG,ws_ticket_node_mismatch:l.CONFIG,launch_request_failed:l.LAUNCH,launch_http_error:l.LAUNCH,launch_response_not_json:l.LAUNCH,launch_response_invalid:l.LAUNCH,launch_open_frame_send_failed:l.LAUNCH,ws_url_missing:l.CHANNEL,ws_ticket_missing:l.CHANNEL,ws_connect_failed:l.CHANNEL,ws_error:l.CHANNEL,headers_frame_send_failed:l.CHANNEL,ws_no_pair_to_resume:l.CHANNEL,ws_backoff_exhausted:l.CHANNEL,ws_gave_up:l.CHANNEL,ws_ticket_http_error:l.CHANNEL,ws_ticket_response_invalid:l.CHANNEL,ws_ticket_refresh_failed:l.CHANNEL};function c(e,t){let o=new Error(t);return o.code=e,o.category=ae[e],o}function se(){return typeof n.fetchImpl=="function"?n.fetchImpl:typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):null}function Bt(){let e=se();if(!e)throw c("fetch_unavailable","atkonoffice: no fetch available \u2014 pass fetchImpl via config in non-browser hosts");return e}async function K(e,t){let o;try{o=await Bt()(n.backendBase+n.launchPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(r){throw r&&ae[r.code]?r:c("launch_request_failed",t+" request failed \u2014 "+b(r))}if(!o.ok)throw c("launch_http_error",t+" endpoint returned HTTP "+o.status);try{return await o.json()}catch(r){throw c("launch_response_not_json",t+" response was not JSON \u2014 "+b(r))}}var T={PERM:"PERM",SLOW:"SLOW",RETRY:"RETRY"},ce=":",Lt=[[T.PERM+ce,T.PERM],[T.SLOW+ce,T.SLOW],[T.RETRY+ce,T.RETRY]];function Fe(e){if(typeof e!="string"||!e)return T.RETRY;for(let t of Lt)if(e.indexOf(t[0])===0)return t[1];return T.RETRY}function Me(e){n.launchTicket=e.launchTicket,n.openParams=e.openParams&&typeof e.openParams=="object"?e.openParams:{},n.fallbackUrl=e.launchUrl,n.pairing||(n.pairingTitleSaved=!1),n.pairing=!0,fe(),Ft()}function Ve(){if(!(!n.pairing||typeof document>"u")){if(!n.pairingTitleSaved){let e=S();e.indexOf(k)<0&&(n.pairingPrevTitle=e,n.pairingTitleSaved=!0)}We(),Ht()}}function We(){C(X(n.wsUrl,n.pairId,n.launchTicket))}function X(e,t,o){let r=He(JSON.stringify({wsUrl:e,pairId:t,launchTicket:o}));return M+k+r}function C(e){try{typeof document<"u"&&(document.title=e)}catch{}if(ie())try{let t={};t[W]=e,window.top.postMessage(t,"*")}catch{}}function fe(){n.titleRelayInstalled||typeof window>"u"||typeof window.addEventListener!="function"||ie()||(n.titleRelayInstalled=!0,window.addEventListener("message",e=>{if(!Ut(e&&e.origin))return;let t=e&&e.data;if(t&&typeof t=="object"&&typeof t[W]=="string")try{document.title=t[W]}catch{}}))}function Ut(e){let t=n.trustedFrameOrigins;return!t||t.length===0?!0:typeof e=="string"&&t.indexOf(e)!==-1}function Ht(){n.pairingRecoverTimer||typeof setInterval>"u"||(n.pairingRecoverTimer=setInterval(()=>{n.pairing&&S().indexOf(k)<0&&We()},n.pairRecoverMs))}function Ft(){n.pairingTimeoutTimer||typeof setTimeout>"u"||(n.pairingTimeoutTimer=setTimeout(()=>{n.pairingTimeoutTimer=null,Ye(!0)},n.pairTimeoutMs))}function je(){if(!n.pairing)return;let e=n.ws;Ye(!1),O(),e&&Mt(e)}function Mt(e){let t={v:1,type:"event",op:De,ts:Math.floor(Date.now()/1e3),payload:{pair_id:n.pairId,openParams:n.openParams||{}}};try{e.send(JSON.stringify(t))}catch(o){u("error",c("launch_open_frame_send_failed","atkonoffice: failed to send launch.open frame \u2014 "+b(o)))}}function Ye(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&&(C(n.pairingPrevTitle),n.pairingTitleSaved=!1),e&&t&&(G(n.fallbackUrl),typeof n.onPairDowngrade=="function"&&n.onPairDowngrade())}var Vt="documentEmbedFailed";function Ge(e){u(Vt,e||{})}function le(e,t,o){if(!(!e||typeof sessionStorage>"u"))try{sessionStorage.setItem(H,JSON.stringify({pairId:e,wsUrl:t,nodeBase:o||""}))}catch{}}function Je(){if(n.pairId)return{pairId:n.pairId,wsUrl:n.wsUrl,nodeBase:n.nodeBase};if(typeof sessionStorage>"u")return null;try{let e=sessionStorage.getItem(H);return e?JSON.parse(e):null}catch{return null}}function Wt(){n.pairId="",n.wsUrl="",n.nodeBase=""}function Ke(){if(!(typeof sessionStorage>"u"))try{sessionStorage.removeItem(H)}catch{}}function Xe(){Wt(),Ke()}function q(){if(n.ws||n.wsReconnectTimer||n.wsTicketInFlight||n.wsStopped||!n.backendBase)return;let e=Je();!e||!e.pairId||(n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,n.nodeBase=e.nodeBase||n.nodeBase,n.wsReconnectAttempt=0,ze(e.pairId,t=>z(t)))}function z(e){if(typeof WebSocket>"u"){u("error",c("ws_unsupported","atkonoffice: WebSocket unavailable in this host \u2014 document events disabled"));return}if(!n.wsUrl){u("error",c("ws_url_missing","atkonoffice: no wsUrl \u2014 cannot open the document-event channel"));return}if(!e){u("error",c("ws_ticket_missing","atkonoffice: missing ws_ticket \u2014 cannot subscribe to document events"));return}de();let t=j(n.wsUrl,"ticket",encodeURIComponent(e)),o;try{o=new WebSocket(t)}catch(r){u("error",c("ws_connect_failed","atkonoffice: WS connect failed \u2014 "+b(r))),A();return}n.ws=o,o.onopen=()=>{n.wsBackoffExhausted&&le(n.pairId,n.wsUrl,n.nodeBase),n.wsReconnectAttempt=0,n.wsStopped=!1,n.wsBackoffExhausted=!1,jt(o),Jt(o),n.pairing&&Ve()},o.onmessage=r=>{Kt(r&&r.data)},o.onerror=()=>{u("error",c("ws_error","atkonoffice: WS error on the document-event channel"))},o.onclose=r=>{if(n.ws===o&&(n.ws=null),ue(),Fe(r&&r.reason)===T.PERM){Yt("server closed it permanently; reopen the document from the page to start a new session");return}A()}}function qe(e){n.channelLostAnnounced||(n.channelLostAnnounced=!0,u(B,{reason:e}))}function jt(e){ue(),n.channelLostAnnounced&&(n.channelRestoreConfirmTimer=setTimeout(()=>{n.channelRestoreConfirmTimer=null,!(n.ws!==e||!n.channelLostAnnounced)&&(n.channelLostAnnounced=!1,u(L,{}))},Ae))}function ue(){n.channelRestoreConfirmTimer&&(clearTimeout(n.channelRestoreConfirmTimer),n.channelRestoreConfirmTimer=null)}function Yt(e){n.wsStopped=!0,n.wsBackoffExhausted=!1,de(),Xe();let t=c("ws_gave_up","atkonoffice: document-event channel lost \u2014 "+e);t.terminal=!0,u("error",t),qe("rejected")}function Gt(e){n.wsBackoffExhausted=!0,Ke();let t=c("ws_backoff_exhausted","atkonoffice: document-event channel still unreachable "+e+" \u2014 left fast reconnect, now probing every "+Math.round(te/1e3)+"s until it comes back");t.terminal=!1,u("error",t),qe("unreachable")}function de(){n.wsReconnectTimer&&(clearTimeout(n.wsReconnectTimer),n.wsReconnectTimer=null),ue();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 Jt(e){if(!Y(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){u("error",c("headers_frame_send_failed","atkonoffice: failed to send headers frame \u2014 "+b(o)))}}function Kt(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}if(!t||t.type!=="event")return;if(t.op===V){je();return}if(t.op===Be){Ge(t.payload||{});return}let o=v[t.op];o&&u(o,t.payload||{}),t.op===ne&&(n.wsBackoffExhausted=!1,Xe(),de())}function A(){if(n.wsReconnectTimer||n.wsStopped)return;let e=Je();if(!e||!e.pairId){u("error",c("ws_no_pair_to_resume","atkonoffice: document-event channel dropped and no pair to resume"));return}let t=n.wsReconnectAttempt>=ee,o;if(t)o=te;else{let r=n.wsReconnectAttempt+1;n.wsReconnectAttempt=r,o=Math.min(3e4,500*Math.pow(2,r-1))}n.wsReconnectTimer=setTimeout(()=>{n.wsReconnectTimer=null,n.nodeBase=e.nodeBase||n.nodeBase,ze(e.pairId,r=>{n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,z(r)})},o),t&&!n.wsBackoffExhausted&&Gt("after "+ee+" consecutive fast reconnect attempts")}async function ze(e,t){let o=se();if(!o||!n.backendBase){u("error",c("ws_ticket_backend_missing","atkonoffice: cannot refresh ws_ticket \u2014 backend not configured")),A();return}n.wsTicketInFlight=!0;let r=Le(n.nodeBase,n.backendBase)?n.nodeBase:n.backendBase;try{let i=await o(r+n.wsTicketPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pairId:e,backendBase:r})});if(!i.ok){u("error",c("ws_ticket_http_error","atkonoffice: ws_ticket refresh returned HTTP "+i.status)),A();return}let a=await i.json();if(!a||typeof a.wsTicket!="string"||!a.wsTicket){u("error",c("ws_ticket_response_invalid","atkonoffice: ws_ticket refresh response missing wsTicket")),A();return}typeof a.wsUrl=="string"&&a.wsUrl&&(n.nodeBase&&n.wsUrl&&a.wsUrl!==n.wsUrl?u("error",c("ws_ticket_node_mismatch","atkonoffice: ws_ticket refresh was served by a different backend instance than this session \u2014 expected "+n.wsUrl+", got "+a.wsUrl+" (multi-instance: check the load balancer routes this session node prefix to that instance)")):n.wsUrl=a.wsUrl),t(a.wsTicket)}catch(i){u("error",c("ws_ticket_refresh_failed","atkonoffice: ws_ticket refresh failed \u2014 "+b(i))),A()}finally{n.wsTicketInFlight=!1}}function Xt(e){let t=n.eventHandlers[e];return!!t&&t.length>0}function qt(e){for(let t in v)if(v.hasOwnProperty(t)&&v[t]===e)return!0;return!1}function $e(e){return qt(e)||e===B||e===L}function Qe(){return F.some(e=>$e(e)&&Xt(e))}function u(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 Ze(e,t){if(typeof e!="string"||F.indexOf(e)===-1)throw new TypeError('atkonoffice.on: unknown event "'+e+'" (expected one of '+F.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),$e(e)&&q(),R}function et(){$t(n.pairTimeoutMs).then(e=>{O(),e.installed||Zt(e.clientDownloadUrl)})}function zt(e){let t=e.indexOf(k);if(t<0)return null;let o=t;for(;o>0&&e.charAt(o-1)===M;)o-=1;return e.slice(0,o)}function $t(e){return new Promise(t=>{let o=!1,r=null,i=null,a=null,h=!1,f="",g="",y=()=>{if(i&&(clearTimeout(i),i=null),a&&(clearInterval(a),a=null),h)C(f),h=!1;else{let p=zt(S());p!==null&&C(p)}if(r){r.onopen=r.onmessage=r.onerror=r.onclose=null;try{r.close(1e3,"probe_done")}catch{}r=null}},m=p=>{o||(o=!0,y(),t({installed:p,clientDownloadUrl:g}))};i=setTimeout(()=>m(!1),e),Qt().then(p=>{if(p&&typeof p.clientDownloadUrl=="string"&&(g=p.clientDownloadUrl),o||!J(p)){m(!1);return}let Z=p.wsUrl,Ie=typeof p.pairId=="string"?p.pairId:"",ve=p.launchTicket;fe();let P;try{P=new WebSocket(j(Z,"ticket",encodeURIComponent(p.wsTicket)))}catch{m(!1);return}r=P,P.onopen=()=>{let I=S();I.indexOf(k)<0&&(f=I,h=!0),C(X(Z,Ie,ve)),a=setInterval(()=>{!o&&S().indexOf(k)<0&&C(X(Z,Ie,ve))},n.pairRecoverMs)},P.onmessage=I=>{let Ne=I&&I.data;if(typeof Ne!="string")return;let U;try{U=JSON.parse(Ne)}catch{return}U&&U.type==="event"&&U.op===V&&m(!0)},P.onerror=()=>{},P.onclose=()=>{}}).catch(()=>{m(!1)})})}async function Qt(){return K({docId:"",pageUrl:"",user:"",backendBase:n.backendBase},"atkonoffice: launch-probe")}function Zt(e){if(typeof document>"u"||!document.body||typeof document.createElement!="function")return null;pe();let t=document.createElement("div");t.setAttribute("data-atkonoffice-guide",oe),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;",f="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 m=document.createElement("a");m.textContent="\u4E0B\u8F7D\u5BA2\u6237\u7AEF",m.href=e,m.target="_blank",m.rel="noopener noreferrer",m.style.cssText=f,a.appendChild(m)}let g=document.createElement("button");g.type="button",g.textContent="\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5",g.style.cssText=h,g.addEventListener("click",()=>{pe();try{typeof n.replayOpen=="function"&&n.replayOpen()}catch{}});let y=document.createElement("button");return y.type="button",y.textContent="\u5173\u95ED",y.style.cssText=h,y.addEventListener("click",()=>pe()),a.appendChild(g),a.appendChild(y),o.appendChild(r),o.appendChild(i),o.appendChild(a),t.appendChild(o),document.body.appendChild(t),t}function pe(){if(!(typeof document>"u"||typeof document.querySelector!="function"))try{let e=document.querySelector('[data-atkonoffice-guide="'+oe+'"]');e&&typeof e.remove=="function"?e.remove():e&&e.parentNode&&typeof e.parentNode.removeChild=="function"&&e.parentNode.removeChild(e)}catch{}}function tt(e){if(!e||typeof e!="object")throw new TypeError("atkonoffice.config requires an options object");if(typeof e.backendBase=="string"&&(n.backendBase=re(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,Qe()&&q(),R}function me(e){if(n.launchInFlight)return n.inFlightOpen;n.launchInFlight=!0;let t=en(e);return n.launchInFlight&&(n.inFlightOpen=t),t}async function en(e){try{let t=e||{};if(!n.backendBase)throw c("backend_base_missing","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 c("doc_id_missing","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,backendBase:n.backendBase},h=on(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 f=await K(a,"atkonoffice.open: launch");if(!f||typeof f.launchUrl!="string"||!f.launchUrl)throw c("launch_response_invalid","atkonoffice.open: launch endpoint response missing launchUrl");let g=tn(t);n.headers=Y(g)?g:null;let y=J(f);return n.replayOpen=()=>me(e),n.onPairDowngrade=y?et:null,typeof f.wsTicket=="string"&&f.wsTicket&&typeof f.wsUrl=="string"&&f.wsUrl&&(n.wsUrl=f.wsUrl,n.pairId=typeof f.pairId=="string"?f.pairId:"",n.nodeBase=nn(f),le(n.pairId,n.wsUrl,n.nodeBase),n.wsReconnectAttempt=0,n.wsStopped=!1,n.wsBackoffExhausted=!1,n.wsTicketInFlight=!1,y&&Me(f),z(f.wsTicket)),y||(G(f.launchUrl),O()),{launchUrl:f.launchUrl,downloadUrl:typeof f.downloadUrl=="string"?f.downloadUrl:"",pairId:n.pairId,wsUrl:n.wsUrl}}catch(t){throw O(),t}}function tn(e){let t={},o=e.headers;if(Array.isArray(o)){for(let i of o)if(Array.isArray(i)&&i.length>=2)N(t,i[0],i[1]);else if(typeof i=="string"&&i.indexOf(":")!==-1){let a=i.indexOf(":");N(t,i.slice(0,a),i.slice(a+1).trim())}}else if(o&&typeof o=="object")for(let i of Object.keys(o))N(t,i,o[i]);let r=Ue(e.cookie);return r&&N(t,"Cookie",r),e.storage&&typeof e.storage=="object"&&N(t,"X-Atkonoffice-Storage",JSON.stringify(e.storage)),t}function nn(e){let t=e&&e.openParams?e.openParams.backend:null;return typeof t=="string"&&t?re(t):""}function on(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 d={};var nt="atkonoffice-doc-host",he="__atkonofficeDocHostEvent",ge=["documentSaved","documentOpened","documentBeforeSave","error","controlReady","compareDiff","documentReady","documentFailed"],ye="doc.ready",_e="doc.embedFailed",we="doc.opened",$={"doc.saved":"documentSaved",[we]:"documentOpened","doc.beforeSave":"documentBeforeSave","compare.diff":"compareDiff",[ye]:"documentReady",[_e]:"documentFailed"},ot="controlReady",rt="toolbarClick",it="readbackResult",at="messageBoxResult",s={eventHandlers:{},hintShown:!1,toolbarButtons:{},toolbarSeq:0,readbackPending:{},readbackSeq:0,messageBoxPending:{},messageBoxSeq:0,docTerminal:null};function st(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;_();let r=typeof t=="number"&&isFinite(t)?Math.trunc(t):0,i="btn-"+ ++s.toolbarSeq;return s.toolbarButtons[i]=o,E("toolbarAdd",JSON.stringify({buttonId:i,caption:e,iconIndex:r}))?{remove:function(){delete s.toolbarButtons[i],E("toolbarRemove",JSON.stringify({buttonId:i}))}}:(delete s.toolbarButtons[i],dt(),null)}function ct(e){if(typeof e!="boolean")throw new TypeError("atkonoffice embed.setCustomToolbarVisible: visible must be a boolean");return typeof window>"u"?d:(_(),E("toolbarSetVisible",JSON.stringify({visible:e})),d)}function ft(e){let t=e&&e.buttonId;if(typeof t!="string"||!t)return;let o=s.toolbarButtons[t];if(typeof o=="function")try{o()}catch(r){pt("addCustomToolButton onClick threw: "+(r&&r.message?r.message:r))}}function Q(){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):E("save",o)}),typeof e.exec!="function"&&(e.exec=function(t){return typeof t!="string"||!t?!1:E("executeJs",t)}),typeof e.setSavePath!="function"&&(e.setSavePath=function(t){return typeof t!="string"||!t?!1:E("setSavePath",t)}),e}function lt(e){let t=Q();return t&&typeof t.save=="function"?t.save(e):!1}function ut(e){let t=Q();return t&&typeof t.setSavePath=="function"?t.setSavePath(e):!1}function E(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 rn=15e3;function x(e,t){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});_();let o=++s.readbackSeq,r=JSON.stringify({rid:o,method:e,args:Array.isArray(t)?t:[]});return new Promise(i=>{let a=setTimeout(function(){Re(o,{ok:!1,error:"timeout"})},rn);a&&typeof a.unref=="function"&&a.unref(),s.readbackPending[o]={resolve:i,timer:a},E("readback",r)||Re(o,{ok:!1,error:"shell-absent"})})}function Re(e,t){let o=s.readbackPending[e];o&&(delete s.readbackPending[e],clearTimeout(o.timer),o.resolve(t))}function mt(e){let t=e&&e.rid;typeof t=="number"&&Re(t,e.ok?{ok:!0,value:e.value,error:void 0}:{ok:!1,value:void 0,error:e.error||"invoke failed"})}var an=6e5;function ht(e){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});_();let t=e&&typeof e=="object"?e:{},o=++s.messageBoxSeq,r=JSON.stringify({rid:o,type:t.type,title:t.title,text:t.text,buttons:t.buttons});return new Promise(i=>{let a=setTimeout(function(){Te(o,{ok:!1,error:"timeout"})},an);a&&typeof a.unref=="function"&&a.unref(),s.messageBoxPending[o]={resolve:i,timer:a},E("messageBox",r)||Te(o,{ok:!1,error:"shell-absent"})})}function Te(e,t){let o=s.messageBoxPending[e];o&&(delete s.messageBoxPending[e],clearTimeout(o.timer),o.resolve(t))}function gt(e){let t=e&&e.rid;typeof t=="number"&&Te(t,{ok:!!(e&&e.ok),button:e?e.button:void 0,error:e?e.error:void 0})}function yt(e,t){if(e===we){s.docTerminal=null;return}(e===ye||e===_e)&&(s.docTerminal={event:$[e],payload:t||{}})}function _t(e,t){!s.docTerminal||s.docTerminal.event!==e||typeof setTimeout=="function"&&setTimeout(function(){let o=s.docTerminal;if(!(!o||o.event!==e))try{t(o.payload)}catch{}},0)}function _(){sn(),Q()}function Rt(e,t){if(typeof e!="string"||ge.indexOf(e)===-1)throw new TypeError('atkonoffice embed.on: unknown event "'+e+'" (expected one of '+ge.join(", ")+")");if(typeof t!="function")throw new TypeError("atkonoffice embed.on: handler must be a function");return _(),s.eventHandlers[e]||(s.eventHandlers[e]=[]),s.eventHandlers[e].push(t),_t(e,t),d}function sn(){typeof window>"u"||typeof window[he]=="function"||(window[he]=function(e,t){if(e===ot){wt("controlReady",t||{});return}if(e===rt){ft(t||{});return}if(e===it){mt(t||{});return}if(e===at){gt(t||{});return}yt(e,t||{});let o=$[e];o&&wt(o,t||{})})}function wt(e,t){let o=s.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 dt(){if(!s.hintShown){s.hintShown=!0;try{console.info("[atkonoffice embed] <"+nt+"> \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 pt(e){try{console.warn("[atkonoffice embed] "+e)}catch{}}function Tt(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeSave: fn must be a function");return _(),bt("onBeforeSave",e),d}function Et(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeClose: fn must be a function");return _(),bt("onBeforeClose",e),d}function bt(e,t){if(typeof window>"u")return!1;let o=window.__atkonofficeDocHost;return o&&typeof o[e]=="function"?(o[e](t),!0):!1}var xt="AO_";function D(e){return!!(e&&e.ok&&Number(e.value)>0)}function w(){return Promise.resolve({ok:!1,error:"bad-args"})}function kt(e){return typeof e=="string"?e:e==null?"":String(e)}function Ot(e){if(!e||!e.ok)return{ok:!1,error:e&&e.error||"invoke failed"};let t;try{t=JSON.parse(e.value)}catch{t=null}return Array.isArray(t)?{ok:!0,value:t}:{ok:!1,error:"bad-value"}}function St(e,t){return Ee(e,t).then(D)}function Ee(e,t){if(typeof e!="string"||!e)return w();let o=typeof t=="string"?t:t==null?"":String(t),r={};return r[e]=o,x("Word_FillDataRegion",[JSON.stringify(r)])}function Ct(e,t){return be(e,t).then(D)}function be(e,t){if(typeof e!="string"||!e)return w();let o=kt(t);return o?x("Word_AddDataRegion",[e,o]):w()}function Pt(e){return xe(e).then(D)}function xe(e){return typeof e!="string"||!e?w():x("Word_DeleteDataRegion",[e])}function It(e){return ke(e).then(D)}function ke(e){return typeof e!="string"||!e?w():x("Word_LocateDataRegion",[e])}function vt(e){return Oe(e).then(function(t){return t.ok?t.value:[]})}function Oe(e){let t=typeof e=="string"?e:xt;return x("BookmarksAsJson",[]).then(function(o){let r=Ot(o);return r.ok?{ok:!0,value:r.value.filter(function(i){return typeof i=="string"&&(t===""||i.indexOf(t)===0)})}:r})}function Nt(e){return Se(e).then(function(t){return t.ok?t.value:[]})}function Se(e){let t=typeof e=="string"?e:xt;return x("Word_GetDataRegionValues",[]).then(function(o){let r=Ot(o);return r.ok?{ok:!0,value:r.value.filter(function(i){return!!i&&typeof i=="object"&&typeof i.name=="string"&&(t===""||i.name.indexOf(t)===0)})}:r})}function At(e,t){return Ce(e,t).then(D)}function Ce(e,t){if(typeof e!="string"||!e)return w();let o=kt(t);return o?x("Word_SetDataRegionPlaceholder",[e,o]):w()}function Dt(e,t){return Pe(e,t).then(D)}function Pe(e,t){if(typeof e!="string"||!e||!t||typeof t!="object"||Array.isArray(t))return w();let o={};for(let r of["contents","control"])if(t[r]!==void 0){if(typeof t[r]!="boolean")return w();o[r]=t[r]}return Object.keys(o).length?x("Word_SetDataRegionLock",[e,JSON.stringify(o)]):w()}d.on=Rt;d.addCustomToolButton=st;d.setCustomToolbarVisible=ct;d.save=lt;d.setSavePath=ut;d.showMessageBox=ht;d.onBeforeSave=Tt;d.onBeforeClose=Et;d.word={fillDataRegion:St,addDataRegion:Ct,deleteDataRegion:Pt,locateDataRegion:It,listDataRegions:vt,getDataRegionValues:Nt,setDataRegionPlaceholder:At,setDataRegionLock:Dt,receipt:{fillDataRegion:Ee,addDataRegion:be,deleteDataRegion:xe,locateDataRegion:ke,listDataRegions:Oe,getDataRegionValues:Se,setDataRegionPlaceholder:Ce,setDataRegionLock:Pe}};R.config=tt;R.open=me;R.on=Ze;R.session=d;var cn=R,Vo=cn;export{cn as atkonoffice,Vo as default};
1
+ var R={};var n={backendBase:"",launchPath:"/atkonoffice/rpc/launch",wsTicketPath:"/atkonoffice/rpc/ws-ticket",fetchImpl:null,initialized:!1,ws:null,wsUrl:"",pairId:"",nodeBase:"",headers:null,eventHandlers:{},wsReconnectAttempt:0,wsReconnectTimer:null,wsTicketInFlight:!1,wsStopped:!1,wsBackoffExhausted:!1,channelLostAnnounced:!1,channelRestoreConfirmTimer:null,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,launchInFlight:!1,inFlightOpen:null};function O(){n.launchInFlight=!1,n.inFlightOpen=null}var H="atkonoffice.ws.session",ee=12,te=3e5,Ae=1e3,B="channelLost",L="channelRestored",F=["documentSaved","documentOpened","documentReady","documentBeforeSave","documentEmbedFailed","shellClosed",B,L,"error"],ne="shell.closed",v={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.ready":"documentReady","doc.beforeSave":"documentBeforeSave",[ne]:"shellClosed"},k="atkonoffice-launch=",M="\u2007",V="pair.ready",De="launch.open",Be="doc.embedFailed",W="__atkonofficeTitle",oe="atkonoffice-install-guide";function re(e){return e&&e.endsWith("/")?e.slice(0,-1):e}function Le(e,t){if(!e||!t)return!1;try{return new URL(e).origin===new URL(t).origin}catch{return!1}}function j(e,t,o){let r=e.indexOf("?")===-1?"?":"&";return e+r+t+"="+o}function Y(e){return!!e&&Object.keys(e).length>0}function b(e){return e&&e.message?e.message:String(e)}function N(e,t,o){if(t==null)return;let r=String(t).trim();r&&(e[r]=o==null?"":String(o))}function Ue(e){return e?typeof e=="string"?e:typeof e=="object"?Object.keys(e).map(t=>t+"="+String(e[t])).join("; "):"":""}function He(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 S(){try{return typeof document<"u"&&typeof document.title=="string"?document.title:""}catch{return""}}function ie(){if(typeof window>"u")return!1;try{return window.top!==window.self}catch{return!0}}function G(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 J(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")}var l={CONFIG:"config",LAUNCH:"launch",CHANNEL:"channel"},ae={backend_base_missing:l.CONFIG,doc_id_missing:l.CONFIG,fetch_unavailable:l.CONFIG,ws_unsupported:l.CONFIG,ws_ticket_backend_missing:l.CONFIG,ws_ticket_node_mismatch:l.CONFIG,launch_request_failed:l.LAUNCH,launch_http_error:l.LAUNCH,launch_response_not_json:l.LAUNCH,launch_response_invalid:l.LAUNCH,launch_open_frame_send_failed:l.LAUNCH,ws_url_missing:l.CHANNEL,ws_ticket_missing:l.CHANNEL,ws_connect_failed:l.CHANNEL,ws_error:l.CHANNEL,headers_frame_send_failed:l.CHANNEL,ws_no_pair_to_resume:l.CHANNEL,ws_backoff_exhausted:l.CHANNEL,ws_gave_up:l.CHANNEL,ws_ticket_http_error:l.CHANNEL,ws_ticket_response_invalid:l.CHANNEL,ws_ticket_refresh_failed:l.CHANNEL};function c(e,t){let o=new Error(t);return o.code=e,o.category=ae[e],o}function se(){return typeof n.fetchImpl=="function"?n.fetchImpl:typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):null}function Bt(){let e=se();if(!e)throw c("fetch_unavailable","atkonoffice: no fetch available \u2014 pass fetchImpl via config in non-browser hosts");return e}async function K(e,t){let o;try{o=await Bt()(n.backendBase+n.launchPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(r){throw r&&ae[r.code]?r:c("launch_request_failed",t+" request failed \u2014 "+b(r))}if(!o.ok)throw c("launch_http_error",t+" endpoint returned HTTP "+o.status);try{return await o.json()}catch(r){throw c("launch_response_not_json",t+" response was not JSON \u2014 "+b(r))}}var T={PERM:"PERM",SLOW:"SLOW",RETRY:"RETRY"},ce=":",Lt=[[T.PERM+ce,T.PERM],[T.SLOW+ce,T.SLOW],[T.RETRY+ce,T.RETRY]];function Fe(e){if(typeof e!="string"||!e)return T.RETRY;for(let t of Lt)if(e.indexOf(t[0])===0)return t[1];return T.RETRY}function Me(e){n.launchTicket=e.launchTicket,n.openParams=e.openParams&&typeof e.openParams=="object"?e.openParams:{},n.fallbackUrl=e.launchUrl,n.pairing||(n.pairingTitleSaved=!1),n.pairing=!0,fe(),Ft()}function Ve(){if(!(!n.pairing||typeof document>"u")){if(!n.pairingTitleSaved){let e=S();e.indexOf(k)<0&&(n.pairingPrevTitle=e,n.pairingTitleSaved=!0)}We(),Ht()}}function We(){C(X(n.wsUrl,n.pairId,n.launchTicket))}function X(e,t,o){let r=He(JSON.stringify({wsUrl:e,pairId:t,launchTicket:o}));return M+k+r}function C(e){try{typeof document<"u"&&(document.title=e)}catch{}if(ie())try{let t={};t[W]=e,window.top.postMessage(t,"*")}catch{}}function fe(){n.titleRelayInstalled||typeof window>"u"||typeof window.addEventListener!="function"||ie()||(n.titleRelayInstalled=!0,window.addEventListener("message",e=>{if(!Ut(e&&e.origin))return;let t=e&&e.data;if(t&&typeof t=="object"&&typeof t[W]=="string")try{document.title=t[W]}catch{}}))}function Ut(e){let t=n.trustedFrameOrigins;return!t||t.length===0?!0:typeof e=="string"&&t.indexOf(e)!==-1}function Ht(){n.pairingRecoverTimer||typeof setInterval>"u"||(n.pairingRecoverTimer=setInterval(()=>{n.pairing&&S().indexOf(k)<0&&We()},n.pairRecoverMs))}function Ft(){n.pairingTimeoutTimer||typeof setTimeout>"u"||(n.pairingTimeoutTimer=setTimeout(()=>{n.pairingTimeoutTimer=null,Ye(!0)},n.pairTimeoutMs))}function je(){if(!n.pairing)return;let e=n.ws;Ye(!1),O(),e&&Mt(e)}function Mt(e){let t={v:1,type:"event",op:De,ts:Math.floor(Date.now()/1e3),payload:{pair_id:n.pairId,openParams:n.openParams||{}}};try{e.send(JSON.stringify(t))}catch(o){u("error",c("launch_open_frame_send_failed","atkonoffice: failed to send launch.open frame \u2014 "+b(o)))}}function Ye(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&&(C(n.pairingPrevTitle),n.pairingTitleSaved=!1),e&&t&&(G(n.fallbackUrl),typeof n.onPairDowngrade=="function"&&n.onPairDowngrade())}var Vt="documentEmbedFailed";function Ge(e){u(Vt,e||{})}function le(e,t,o){if(!(!e||typeof sessionStorage>"u"))try{sessionStorage.setItem(H,JSON.stringify({pairId:e,wsUrl:t,nodeBase:o||""}))}catch{}}function Je(){if(n.pairId)return{pairId:n.pairId,wsUrl:n.wsUrl,nodeBase:n.nodeBase};if(typeof sessionStorage>"u")return null;try{let e=sessionStorage.getItem(H);return e?JSON.parse(e):null}catch{return null}}function Wt(){n.pairId="",n.wsUrl="",n.nodeBase=""}function Ke(){if(!(typeof sessionStorage>"u"))try{sessionStorage.removeItem(H)}catch{}}function Xe(){Wt(),Ke()}function q(){if(n.ws||n.wsReconnectTimer||n.wsTicketInFlight||n.wsStopped||!n.backendBase)return;let e=Je();!e||!e.pairId||(n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,n.nodeBase=e.nodeBase||n.nodeBase,n.wsReconnectAttempt=0,ze(e.pairId,t=>z(t)))}function z(e){if(typeof WebSocket>"u"){u("error",c("ws_unsupported","atkonoffice: WebSocket unavailable in this host \u2014 document events disabled"));return}if(!n.wsUrl){u("error",c("ws_url_missing","atkonoffice: no wsUrl \u2014 cannot open the document-event channel"));return}if(!e){u("error",c("ws_ticket_missing","atkonoffice: missing ws_ticket \u2014 cannot subscribe to document events"));return}de();let t=j(n.wsUrl,"ticket",encodeURIComponent(e)),o;try{o=new WebSocket(t)}catch(r){u("error",c("ws_connect_failed","atkonoffice: WS connect failed \u2014 "+b(r))),A();return}n.ws=o,o.onopen=()=>{n.wsBackoffExhausted&&le(n.pairId,n.wsUrl,n.nodeBase),n.wsReconnectAttempt=0,n.wsStopped=!1,n.wsBackoffExhausted=!1,jt(o),Jt(o),n.pairing&&Ve()},o.onmessage=r=>{Kt(r&&r.data)},o.onerror=()=>{u("error",c("ws_error","atkonoffice: WS error on the document-event channel"))},o.onclose=r=>{if(n.ws===o&&(n.ws=null),ue(),Fe(r&&r.reason)===T.PERM){Yt("server closed it permanently; reopen the document from the page to start a new session");return}A()}}function qe(e){n.channelLostAnnounced||(n.channelLostAnnounced=!0,u(B,{reason:e}))}function jt(e){ue(),n.channelLostAnnounced&&(n.channelRestoreConfirmTimer=setTimeout(()=>{n.channelRestoreConfirmTimer=null,!(n.ws!==e||!n.channelLostAnnounced)&&(n.channelLostAnnounced=!1,u(L,{}))},Ae))}function ue(){n.channelRestoreConfirmTimer&&(clearTimeout(n.channelRestoreConfirmTimer),n.channelRestoreConfirmTimer=null)}function Yt(e){n.wsStopped=!0,n.wsBackoffExhausted=!1,de(),Xe();let t=c("ws_gave_up","atkonoffice: document-event channel lost \u2014 "+e);t.terminal=!0,u("error",t),qe("rejected")}function Gt(e){n.wsBackoffExhausted=!0,Ke();let t=c("ws_backoff_exhausted","atkonoffice: document-event channel still unreachable "+e+" \u2014 left fast reconnect, now probing every "+Math.round(te/1e3)+"s until it comes back");t.terminal=!1,u("error",t),qe("unreachable")}function de(){n.wsReconnectTimer&&(clearTimeout(n.wsReconnectTimer),n.wsReconnectTimer=null),ue();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 Jt(e){if(!Y(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){u("error",c("headers_frame_send_failed","atkonoffice: failed to send headers frame \u2014 "+b(o)))}}function Kt(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}if(!t||t.type!=="event")return;if(t.op===V){je();return}if(t.op===Be){Ge(t.payload||{});return}let o=v[t.op];o&&u(o,t.payload||{}),t.op===ne&&(n.wsBackoffExhausted=!1,Xe(),de())}function A(){if(n.wsReconnectTimer||n.wsStopped)return;let e=Je();if(!e||!e.pairId){u("error",c("ws_no_pair_to_resume","atkonoffice: document-event channel dropped and no pair to resume"));return}let t=n.wsReconnectAttempt>=ee,o;if(t)o=te;else{let r=n.wsReconnectAttempt+1;n.wsReconnectAttempt=r,o=Math.min(3e4,500*Math.pow(2,r-1))}n.wsReconnectTimer=setTimeout(()=>{n.wsReconnectTimer=null,n.nodeBase=e.nodeBase||n.nodeBase,ze(e.pairId,r=>{n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,z(r)})},o),t&&!n.wsBackoffExhausted&&Gt("after "+ee+" consecutive fast reconnect attempts")}async function ze(e,t){let o=se();if(!o||!n.backendBase){u("error",c("ws_ticket_backend_missing","atkonoffice: cannot refresh ws_ticket \u2014 backend not configured")),A();return}n.wsTicketInFlight=!0;let r=Le(n.nodeBase,n.backendBase)?n.nodeBase:n.backendBase;try{let i=await o(r+n.wsTicketPath,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pairId:e,backendBase:r})});if(!i.ok){u("error",c("ws_ticket_http_error","atkonoffice: ws_ticket refresh returned HTTP "+i.status)),A();return}let a=await i.json();if(!a||typeof a.wsTicket!="string"||!a.wsTicket){u("error",c("ws_ticket_response_invalid","atkonoffice: ws_ticket refresh response missing wsTicket")),A();return}typeof a.wsUrl=="string"&&a.wsUrl&&(n.nodeBase&&n.wsUrl&&a.wsUrl!==n.wsUrl?u("error",c("ws_ticket_node_mismatch","atkonoffice: ws_ticket refresh was served by a different backend instance than this session \u2014 expected "+n.wsUrl+", got "+a.wsUrl+" (multi-instance: check the load balancer routes this session node prefix to that instance)")):n.wsUrl=a.wsUrl),t(a.wsTicket)}catch(i){u("error",c("ws_ticket_refresh_failed","atkonoffice: ws_ticket refresh failed \u2014 "+b(i))),A()}finally{n.wsTicketInFlight=!1}}function Xt(e){let t=n.eventHandlers[e];return!!t&&t.length>0}function qt(e){for(let t in v)if(v.hasOwnProperty(t)&&v[t]===e)return!0;return!1}function $e(e){return qt(e)||e===B||e===L}function Qe(){return F.some(e=>$e(e)&&Xt(e))}function u(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 Ze(e,t){if(typeof e!="string"||F.indexOf(e)===-1)throw new TypeError('atkonoffice.on: unknown event "'+e+'" (expected one of '+F.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),$e(e)&&q(),R}function et(){$t(n.pairTimeoutMs).then(e=>{O(),e.installed||Zt(e.clientDownloadUrl)})}function zt(e){let t=e.indexOf(k);if(t<0)return null;let o=t;for(;o>0&&e.charAt(o-1)===M;)o-=1;return e.slice(0,o)}function $t(e){return new Promise(t=>{let o=!1,r=null,i=null,a=null,h=!1,f="",g="",y=()=>{if(i&&(clearTimeout(i),i=null),a&&(clearInterval(a),a=null),h)C(f),h=!1;else{let p=zt(S());p!==null&&C(p)}if(r){r.onopen=r.onmessage=r.onerror=r.onclose=null;try{r.close(1e3,"probe_done")}catch{}r=null}},m=p=>{o||(o=!0,y(),t({installed:p,clientDownloadUrl:g}))};i=setTimeout(()=>m(!1),e),Qt().then(p=>{if(p&&typeof p.clientDownloadUrl=="string"&&(g=p.clientDownloadUrl),o||!J(p)){m(!1);return}let Z=p.wsUrl,Ie=typeof p.pairId=="string"?p.pairId:"",ve=p.launchTicket;fe();let P;try{P=new WebSocket(j(Z,"ticket",encodeURIComponent(p.wsTicket)))}catch{m(!1);return}r=P,P.onopen=()=>{let I=S();I.indexOf(k)<0&&(f=I,h=!0),C(X(Z,Ie,ve)),a=setInterval(()=>{!o&&S().indexOf(k)<0&&C(X(Z,Ie,ve))},n.pairRecoverMs)},P.onmessage=I=>{let Ne=I&&I.data;if(typeof Ne!="string")return;let U;try{U=JSON.parse(Ne)}catch{return}U&&U.type==="event"&&U.op===V&&m(!0)},P.onerror=()=>{},P.onclose=()=>{}}).catch(()=>{m(!1)})})}async function Qt(){return K({docId:"",pageUrl:"",user:"",backendBase:n.backendBase},"atkonoffice: launch-probe")}function Zt(e){if(typeof document>"u"||!document.body||typeof document.createElement!="function")return null;pe();let t=document.createElement("div");t.setAttribute("data-atkonoffice-guide",oe),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;",f="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 m=document.createElement("a");m.textContent="\u4E0B\u8F7D\u5BA2\u6237\u7AEF",m.href=e,m.target="_blank",m.rel="noopener noreferrer",m.style.cssText=f,a.appendChild(m)}let g=document.createElement("button");g.type="button",g.textContent="\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5",g.style.cssText=h,g.addEventListener("click",()=>{pe();try{typeof n.replayOpen=="function"&&n.replayOpen()}catch{}});let y=document.createElement("button");return y.type="button",y.textContent="\u5173\u95ED",y.style.cssText=h,y.addEventListener("click",()=>pe()),a.appendChild(g),a.appendChild(y),o.appendChild(r),o.appendChild(i),o.appendChild(a),t.appendChild(o),document.body.appendChild(t),t}function pe(){if(!(typeof document>"u"||typeof document.querySelector!="function"))try{let e=document.querySelector('[data-atkonoffice-guide="'+oe+'"]');e&&typeof e.remove=="function"?e.remove():e&&e.parentNode&&typeof e.parentNode.removeChild=="function"&&e.parentNode.removeChild(e)}catch{}}function tt(e){if(!e||typeof e!="object")throw new TypeError("atkonoffice.config requires an options object");if(typeof e.backendBase=="string"&&(n.backendBase=re(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,Qe()&&q(),R}function me(e){if(n.launchInFlight)return n.inFlightOpen;n.launchInFlight=!0;let t=en(e);return n.launchInFlight&&(n.inFlightOpen=t),t}async function en(e){try{let t=e||{};if(!n.backendBase)throw c("backend_base_missing","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 c("doc_id_missing","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,backendBase:n.backendBase},h=on(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 f=await K(a,"atkonoffice.open: launch");if(!f||typeof f.launchUrl!="string"||!f.launchUrl)throw c("launch_response_invalid","atkonoffice.open: launch endpoint response missing launchUrl");let g=tn(t);n.headers=Y(g)?g:null;let y=J(f);return n.replayOpen=()=>me(e),n.onPairDowngrade=y?et:null,typeof f.wsTicket=="string"&&f.wsTicket&&typeof f.wsUrl=="string"&&f.wsUrl&&(n.wsUrl=f.wsUrl,n.pairId=typeof f.pairId=="string"?f.pairId:"",n.nodeBase=nn(f),le(n.pairId,n.wsUrl,n.nodeBase),n.wsReconnectAttempt=0,n.wsStopped=!1,n.wsBackoffExhausted=!1,n.wsTicketInFlight=!1,y&&Me(f),z(f.wsTicket)),y||(G(f.launchUrl),O()),{launchUrl:f.launchUrl,downloadUrl:typeof f.downloadUrl=="string"?f.downloadUrl:"",pairId:n.pairId,wsUrl:n.wsUrl}}catch(t){throw O(),t}}function tn(e){let t={},o=e.headers;if(Array.isArray(o)){for(let i of o)if(Array.isArray(i)&&i.length>=2)N(t,i[0],i[1]);else if(typeof i=="string"&&i.indexOf(":")!==-1){let a=i.indexOf(":");N(t,i.slice(0,a),i.slice(a+1).trim())}}else if(o&&typeof o=="object")for(let i of Object.keys(o))N(t,i,o[i]);let r=Ue(e.cookie);return r&&N(t,"Cookie",r),e.storage&&typeof e.storage=="object"&&N(t,"X-Atkonoffice-Storage",JSON.stringify(e.storage)),t}function nn(e){let t=e&&e.openParams?e.openParams.backend:null;return typeof t=="string"&&t?re(t):""}function on(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 d={};var nt="atkonoffice-doc-host",he="__atkonofficeDocHostEvent",ge=["documentSaved","documentOpened","documentBeforeSave","error","controlReady","compareDiff","compareFailed","documentReady","documentFailed"],ye="doc.ready",_e="doc.embedFailed",we="doc.opened",$={"doc.saved":"documentSaved",[we]:"documentOpened","doc.beforeSave":"documentBeforeSave","compare.diff":"compareDiff","compare.failed":"compareFailed",[ye]:"documentReady",[_e]:"documentFailed"},ot="controlReady",rt="toolbarClick",it="readbackResult",at="messageBoxResult",s={eventHandlers:{},hintShown:!1,toolbarButtons:{},toolbarSeq:0,readbackPending:{},readbackSeq:0,messageBoxPending:{},messageBoxSeq:0,docTerminal:null};function st(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;_();let r=typeof t=="number"&&isFinite(t)?Math.trunc(t):0,i="btn-"+ ++s.toolbarSeq;return s.toolbarButtons[i]=o,E("toolbarAdd",JSON.stringify({buttonId:i,caption:e,iconIndex:r}))?{remove:function(){delete s.toolbarButtons[i],E("toolbarRemove",JSON.stringify({buttonId:i}))}}:(delete s.toolbarButtons[i],dt(),null)}function ct(e){if(typeof e!="boolean")throw new TypeError("atkonoffice embed.setCustomToolbarVisible: visible must be a boolean");return typeof window>"u"?d:(_(),E("toolbarSetVisible",JSON.stringify({visible:e})),d)}function ft(e){let t=e&&e.buttonId;if(typeof t!="string"||!t)return;let o=s.toolbarButtons[t];if(typeof o=="function")try{o()}catch(r){pt("addCustomToolButton onClick threw: "+(r&&r.message?r.message:r))}}function Q(){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):E("save",o)}),typeof e.exec!="function"&&(e.exec=function(t){return typeof t!="string"||!t?!1:E("executeJs",t)}),typeof e.setSavePath!="function"&&(e.setSavePath=function(t){return typeof t!="string"||!t?!1:E("setSavePath",t)}),e}function lt(e){let t=Q();return t&&typeof t.save=="function"?t.save(e):!1}function ut(e){let t=Q();return t&&typeof t.setSavePath=="function"?t.setSavePath(e):!1}function E(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 rn=15e3;function x(e,t){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});_();let o=++s.readbackSeq,r=JSON.stringify({rid:o,method:e,args:Array.isArray(t)?t:[]});return new Promise(i=>{let a=setTimeout(function(){Re(o,{ok:!1,error:"timeout"})},rn);a&&typeof a.unref=="function"&&a.unref(),s.readbackPending[o]={resolve:i,timer:a},E("readback",r)||Re(o,{ok:!1,error:"shell-absent"})})}function Re(e,t){let o=s.readbackPending[e];o&&(delete s.readbackPending[e],clearTimeout(o.timer),o.resolve(t))}function mt(e){let t=e&&e.rid;typeof t=="number"&&Re(t,e.ok?{ok:!0,value:e.value,error:void 0}:{ok:!1,value:void 0,error:e.error||"invoke failed"})}var an=6e5;function ht(e){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});_();let t=e&&typeof e=="object"?e:{},o=++s.messageBoxSeq,r=JSON.stringify({rid:o,type:t.type,title:t.title,text:t.text,buttons:t.buttons});return new Promise(i=>{let a=setTimeout(function(){Te(o,{ok:!1,error:"timeout"})},an);a&&typeof a.unref=="function"&&a.unref(),s.messageBoxPending[o]={resolve:i,timer:a},E("messageBox",r)||Te(o,{ok:!1,error:"shell-absent"})})}function Te(e,t){let o=s.messageBoxPending[e];o&&(delete s.messageBoxPending[e],clearTimeout(o.timer),o.resolve(t))}function gt(e){let t=e&&e.rid;typeof t=="number"&&Te(t,{ok:!!(e&&e.ok),button:e?e.button:void 0,error:e?e.error:void 0})}function yt(e,t){if(e===we){s.docTerminal=null;return}(e===ye||e===_e)&&(s.docTerminal={event:$[e],payload:t||{}})}function _t(e,t){!s.docTerminal||s.docTerminal.event!==e||typeof setTimeout=="function"&&setTimeout(function(){let o=s.docTerminal;if(!(!o||o.event!==e))try{t(o.payload)}catch{}},0)}function _(){sn(),Q()}function Rt(e,t){if(typeof e!="string"||ge.indexOf(e)===-1)throw new TypeError('atkonoffice embed.on: unknown event "'+e+'" (expected one of '+ge.join(", ")+")");if(typeof t!="function")throw new TypeError("atkonoffice embed.on: handler must be a function");return _(),s.eventHandlers[e]||(s.eventHandlers[e]=[]),s.eventHandlers[e].push(t),_t(e,t),d}function sn(){typeof window>"u"||typeof window[he]=="function"||(window[he]=function(e,t){if(e===ot){wt("controlReady",t||{});return}if(e===rt){ft(t||{});return}if(e===it){mt(t||{});return}if(e===at){gt(t||{});return}yt(e,t||{});let o=$[e];o&&wt(o,t||{})})}function wt(e,t){let o=s.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 dt(){if(!s.hintShown){s.hintShown=!0;try{console.info("[atkonoffice embed] <"+nt+"> \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 pt(e){try{console.warn("[atkonoffice embed] "+e)}catch{}}function Tt(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeSave: fn must be a function");return _(),bt("onBeforeSave",e),d}function Et(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeClose: fn must be a function");return _(),bt("onBeforeClose",e),d}function bt(e,t){if(typeof window>"u")return!1;let o=window.__atkonofficeDocHost;return o&&typeof o[e]=="function"?(o[e](t),!0):!1}var xt="AO_";function D(e){return!!(e&&e.ok&&Number(e.value)>0)}function w(){return Promise.resolve({ok:!1,error:"bad-args"})}function kt(e){return typeof e=="string"?e:e==null?"":String(e)}function Ot(e){if(!e||!e.ok)return{ok:!1,error:e&&e.error||"invoke failed"};let t;try{t=JSON.parse(e.value)}catch{t=null}return Array.isArray(t)?{ok:!0,value:t}:{ok:!1,error:"bad-value"}}function St(e,t){return Ee(e,t).then(D)}function Ee(e,t){if(typeof e!="string"||!e)return w();let o=typeof t=="string"?t:t==null?"":String(t),r={};return r[e]=o,x("Word_FillDataRegion",[JSON.stringify(r)])}function Ct(e,t){return be(e,t).then(D)}function be(e,t){if(typeof e!="string"||!e)return w();let o=kt(t);return o?x("Word_AddDataRegion",[e,o]):w()}function Pt(e){return xe(e).then(D)}function xe(e){return typeof e!="string"||!e?w():x("Word_DeleteDataRegion",[e])}function It(e){return ke(e).then(D)}function ke(e){return typeof e!="string"||!e?w():x("Word_LocateDataRegion",[e])}function vt(e){return Oe(e).then(function(t){return t.ok?t.value:[]})}function Oe(e){let t=typeof e=="string"?e:xt;return x("BookmarksAsJson",[]).then(function(o){let r=Ot(o);return r.ok?{ok:!0,value:r.value.filter(function(i){return typeof i=="string"&&(t===""||i.indexOf(t)===0)})}:r})}function Nt(e){return Se(e).then(function(t){return t.ok?t.value:[]})}function Se(e){let t=typeof e=="string"?e:xt;return x("Word_GetDataRegionValues",[]).then(function(o){let r=Ot(o);return r.ok?{ok:!0,value:r.value.filter(function(i){return!!i&&typeof i=="object"&&typeof i.name=="string"&&(t===""||i.name.indexOf(t)===0)})}:r})}function At(e,t){return Ce(e,t).then(D)}function Ce(e,t){if(typeof e!="string"||!e)return w();let o=kt(t);return o?x("Word_SetDataRegionPlaceholder",[e,o]):w()}function Dt(e,t){return Pe(e,t).then(D)}function Pe(e,t){if(typeof e!="string"||!e||!t||typeof t!="object"||Array.isArray(t))return w();let o={};for(let r of["contents","control"])if(t[r]!==void 0){if(typeof t[r]!="boolean")return w();o[r]=t[r]}return Object.keys(o).length?x("Word_SetDataRegionLock",[e,JSON.stringify(o)]):w()}d.on=Rt;d.addCustomToolButton=st;d.setCustomToolbarVisible=ct;d.save=lt;d.setSavePath=ut;d.showMessageBox=ht;d.onBeforeSave=Tt;d.onBeforeClose=Et;d.word={fillDataRegion:St,addDataRegion:Ct,deleteDataRegion:Pt,locateDataRegion:It,listDataRegions:vt,getDataRegionValues:Nt,setDataRegionPlaceholder:At,setDataRegionLock:Dt,receipt:{fillDataRegion:Ee,addDataRegion:be,deleteDataRegion:xe,locateDataRegion:ke,listDataRegions:Oe,getDataRegionValues:Se,setDataRegionPlaceholder:Ce,setDataRegionLock:Pe}};R.config=tt;R.open=me;R.on=Ze;R.session=d;var cn=R,Vo=cn;export{cn as atkonoffice,Vo as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atkonoffice/sdk",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "Browser-side SDK for the atkonoffice editor shell",
5
5
  "homepage": "https://atkon.yunhuichongming.cn",
6
6
  "type": "module",