@atkonoffice/sdk 1.4.0 → 1.6.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.
@@ -157,6 +157,8 @@ export interface AtkonofficeCompareDiff {
157
157
 
158
158
  export interface AtkonofficeSessionWord {
159
159
 
160
+ fillDataRegion(name: string, value: string): Promise<boolean>
161
+
160
162
  addDataRegion(name: string, caption?: string): Promise<boolean>
161
163
 
162
164
  deleteDataRegion(name: string): Promise<boolean>
@@ -166,6 +168,37 @@ export interface AtkonofficeSessionWord {
166
168
  listDataRegions(prefix?: string): Promise<string[]>
167
169
  }
168
170
 
171
+
172
+ export type AtkonofficeMessageBoxType = 'info' | 'confirm' | 'warning' | 'error'
173
+
174
+
175
+ export type AtkonofficeMessageBoxButtons = 'ok' | 'okCancel' | 'yesNo' | 'yesNoCancel'
176
+
177
+
178
+ export type AtkonofficeMessageBoxButton = 'ok' | 'cancel' | 'yes' | 'no'
179
+
180
+
181
+ export interface AtkonofficeMessageBoxOptions {
182
+
183
+ type?: AtkonofficeMessageBoxType
184
+
185
+ title?: string
186
+
187
+ text?: string
188
+
189
+ buttons?: AtkonofficeMessageBoxButtons
190
+ }
191
+
192
+
193
+ export interface AtkonofficeMessageBoxResult {
194
+
195
+ ok: boolean
196
+
197
+ button?: AtkonofficeMessageBoxButton
198
+
199
+ error?: string
200
+ }
201
+
169
202
  export interface AtkonofficeSession {
170
203
 
171
204
  on(
@@ -195,6 +228,8 @@ export interface AtkonofficeSession {
195
228
 
196
229
  setSavePath(path: string): boolean | void
197
230
 
231
+ showMessageBox(opts?: AtkonofficeMessageBoxOptions): Promise<AtkonofficeMessageBoxResult>
232
+
198
233
  word: AtkonofficeSessionWord
199
234
  }
200
235
 
@@ -1 +1 @@
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","shellClosed","error"],g={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave","shell.closed":"shellClosed"},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,backendBase:n.backendBase},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};
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,launchInFlight:!1,inFlightOpen:null};function x(){n.launchInFlight=!1,n.inFlightOpen=null}var C="atkonoffice.ws.session",V=12,Y=["documentSaved","documentOpened","documentBeforeSave","documentEmbedFailed","shellClosed","error"],T={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave","shell.closed":"shellClosed"},b="atkonoffice-launch=",B="\u2007",A="pair.ready",ae="launch.open",ce="doc.embedFailed",U="__atkonofficeTitle",X="atkonoffice-install-guide";function fe(e){return e&&e.endsWith("/")?e.slice(0,-1):e}function D(e,t,o){let r=e.indexOf("?")===-1?"?":"&";return e+r+t+"="+o}function N(e){return!!e&&Object.keys(e).length>0}function P(e){return e&&e.message?e.message:String(e)}function O(e,t,o){if(t==null)return;let r=String(t).trim();r&&(e[r]=o==null?"":String(o))}function le(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 E(){try{return typeof document<"u"&&typeof document.title=="string"?document.title:""}catch{return""}}function q(){if(typeof window>"u")return!1;try{return window.top!==window.self}catch{return!0}}function L(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 M(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 Qe(){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 F(e,t){let r=await Qe()(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 de(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,$(),tt()}function pe(){if(!(!n.pairing||typeof document>"u")){if(!n.pairingTitleSaved){let e=E();e.indexOf(b)<0&&(n.pairingPrevTitle=e,n.pairingTitleSaved=!0)}me(),et()}}function me(){k(H(n.wsUrl,n.pairId,n.launchTicket))}function H(e,t,o){let r=ue(JSON.stringify({wsUrl:e,pairId:t,launchTicket:o}));return B+b+r}function k(e){try{typeof document<"u"&&(document.title=e)}catch{}if(q())try{let t={};t[U]=e,window.top.postMessage(t,"*")}catch{}}function $(){n.titleRelayInstalled||typeof window>"u"||typeof window.addEventListener!="function"||q()||(n.titleRelayInstalled=!0,window.addEventListener("message",e=>{if(!Ze(e&&e.origin))return;let t=e&&e.data;if(t&&typeof t=="object"&&typeof t[U]=="string")try{document.title=t[U]}catch{}}))}function Ze(e){let t=n.trustedFrameOrigins;return!t||t.length===0?!0:typeof e=="string"&&t.indexOf(e)!==-1}function et(){n.pairingRecoverTimer||typeof setInterval>"u"||(n.pairingRecoverTimer=setInterval(()=>{n.pairing&&E().indexOf(b)<0&&me()},n.pairRecoverMs))}function tt(){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),x(),e&&nt(e)}function nt(e){let t={v:1,type:"event",op:ae,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 "+P(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&&(k(n.pairingPrevTitle),n.pairingTitleSaved=!1),e&&t&&(L(n.fallbackUrl),typeof n.onPairDowngrade=="function"&&n.onPairDowngrade())}var ot="documentEmbedFailed";function ye(e){l(ot,e||{})}function we(e,t){if(!(!e||typeof sessionStorage>"u"))try{sessionStorage.setItem(C,JSON.stringify({pairId:e,wsUrl:t}))}catch{}}function Te(){if(n.pairId)return{pairId:n.pairId,wsUrl:n.wsUrl};if(typeof sessionStorage>"u")return null;try{let e=sessionStorage.getItem(C);return e?JSON.parse(e):null}catch{return null}}function be(){if(n.pairId="",n.wsUrl="",!(typeof sessionStorage>"u"))try{sessionStorage.removeItem(C)}catch{}}function j(){if(n.ws||n.wsReconnectTimer||!n.backendBase)return;let e=Te();!e||!e.pairId||(n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,n.wsReconnectAttempt=0,xe(e.pairId,t=>W(t)))}function W(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}rt();let t=D(n.wsUrl,"ticket",encodeURIComponent(e)),o;try{o=new WebSocket(t)}catch(r){l("error",new Error("atkonoffice: WS connect failed \u2014 "+P(r))),_();return}n.ws=o,o.onopen=()=>{n.wsReconnectAttempt=0,n.wsGaveUp=!1,it(o),n.pairing&&pe()},o.onmessage=r=>{st(r&&r.data)},o.onerror=()=>{l("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){be();return}_()}}function rt(){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 it(e){if(!N(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 "+P(o)))}}function st(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}if(!t||t.type!=="event")return;if(t.op===A){he();return}if(t.op===ce){ye(t.payload||{});return}let o=T[t.op];o&&l(o,t.payload||{})}function _(){if(n.wsReconnectTimer||n.wsGaveUp)return;let e=Te();if(!e||!e.pairId){l("error",new Error("atkonoffice: document-event channel dropped and no pair to resume"));return}if(n.wsReconnectAttempt>=V){n.wsGaveUp=!0,be();let r=new Error("atkonoffice: document-event channel lost \u2014 gave up after "+V+" 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,xe(e.pairId,r=>{n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,W(r)})},o)}async function xe(e,t){let o=z();if(!o||!n.backendBase){l("error",new Error("atkonoffice: cannot refresh ws_ticket \u2014 backend not configured")),_();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)),_();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")),_();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 "+P(r))),_()}}function at(e){let t=n.eventHandlers[e];return!!t&&t.length>0}function ct(e){for(let t in T)if(T.hasOwnProperty(t)&&T[t]===e)return!0;return!1}function Ee(){for(let e in T)if(T.hasOwnProperty(e)&&at(T[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 ke(e,t){if(typeof e!="string"||Y.indexOf(e)===-1)throw new TypeError('atkonoffice.on: unknown event "'+e+'" (expected one of '+Y.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),ct(e)&&j(),y}function Re(){lt(n.pairTimeoutMs).then(e=>{x(),e.installed||dt(e.clientDownloadUrl)})}function ft(e){let t=e.indexOf(b);if(t<0)return null;let o=t;for(;o>0&&e.charAt(o-1)===B;)o-=1;return e.slice(0,o)}function lt(e){return new Promise(t=>{let o=!1,r=null,i=null,s=null,p=!1,c="",m="",h=()=>{if(i&&(clearTimeout(i),i=null),s&&(clearInterval(s),s=null),p)k(c),p=!1;else{let u=ft(E());u!==null&&k(u)}if(r){r.onopen=r.onmessage=r.onerror=r.onclose=null;try{r.close(1e3,"probe_done")}catch{}r=null}},d=u=>{o||(o=!0,h(),t({installed:u,clientDownloadUrl:m}))};i=setTimeout(()=>d(!1),e),ut().then(u=>{if(u&&typeof u.clientDownloadUrl=="string"&&(m=u.clientDownloadUrl),o||!M(u)){d(!1);return}let J=u.wsUrl,re=typeof u.pairId=="string"?u.pairId:"",ie=u.launchTicket;$();let R;try{R=new WebSocket(D(J,"ticket",encodeURIComponent(u.wsTicket)))}catch{d(!1);return}r=R,R.onopen=()=>{let S=E();S.indexOf(b)<0&&(c=S,p=!0),k(H(J,re,ie)),s=setInterval(()=>{!o&&E().indexOf(b)<0&&k(H(J,re,ie))},n.pairRecoverMs)},R.onmessage=S=>{let se=S&&S.data;if(typeof se!="string")return;let I;try{I=JSON.parse(se)}catch{return}I&&I.type==="event"&&I.op===A&&d(!0)},R.onerror=()=>{},R.onclose=()=>{}}).catch(()=>{d(!1)})})}async function ut(){return F({docId:"",pageUrl:"",user:""},"atkonoffice: launch-probe")}function dt(e){if(typeof document>"u"||!document.body||typeof document.createElement!="function")return null;Q();let t=document.createElement("div");t.setAttribute("data-atkonoffice-guide",X),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 s=document.createElement("div");s.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;",c="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 d=document.createElement("a");d.textContent="\u4E0B\u8F7D\u5BA2\u6237\u7AEF",d.href=e,d.target="_blank",d.rel="noopener noreferrer",d.style.cssText=c,s.appendChild(d)}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 h=document.createElement("button");return h.type="button",h.textContent="\u5173\u95ED",h.style.cssText=p,h.addEventListener("click",()=>Q()),s.appendChild(m),s.appendChild(h),o.appendChild(r),o.appendChild(i),o.appendChild(s),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="'+X+'"]');e&&typeof e.remove=="function"?e.remove():e&&e.parentNode&&typeof e.parentNode.removeChild=="function"&&e.parentNode.removeChild(e)}catch{}}function Se(e){if(!e||typeof e!="object")throw new TypeError("atkonoffice.config requires an options object");if(typeof e.backendBase=="string"&&(n.backendBase=fe(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,Ee()&&j(),y}function Z(e){if(n.launchInFlight)return n.inFlightOpen;n.launchInFlight=!0;let t=pt(e);return n.launchInFlight&&(n.inFlightOpen=t),t}async function pt(e){try{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 s={pageUrl:o,params:r,backendBase:n.backendBase},p=ht(t.options);p&&(s.options=p),typeof t.pageApi=="string"&&t.pageApi&&(s.pageApi=t.pageApi),t.storage&&typeof t.storage=="object"&&Object.keys(t.storage).length>0&&(s.storage=t.storage);let c=await F(s,"atkonoffice.open: launch");if(!c||typeof c.launchUrl!="string"||!c.launchUrl)throw new Error("atkonoffice.open: launch endpoint response missing launchUrl");let m=mt(t);n.headers=N(m)?m:null;let h=M(c);return n.replayOpen=()=>Z(e),n.onPairDowngrade=h?Re:null,typeof c.wsTicket=="string"&&c.wsTicket&&typeof c.wsUrl=="string"&&c.wsUrl&&(n.wsUrl=c.wsUrl,n.pairId=typeof c.pairId=="string"?c.pairId:"",we(n.pairId,n.wsUrl),n.wsReconnectAttempt=0,n.wsGaveUp=!1,h&&de(c),W(c.wsTicket)),h||(L(c.launchUrl),x()),{launchUrl:c.launchUrl,downloadUrl:typeof c.downloadUrl=="string"?c.downloadUrl:"",pairId:n.pairId,wsUrl:n.wsUrl}}catch(t){throw x(),t}}function mt(e){let t={},o=e.headers;if(Array.isArray(o)){for(let i of o)if(Array.isArray(i)&&i.length>=2)O(t,i[0],i[1]);else if(typeof i=="string"&&i.indexOf(":")!==-1){let s=i.indexOf(":");O(t,i.slice(0,s),i.slice(s+1).trim())}}else if(o&&typeof o=="object")for(let i of Object.keys(o))O(t,i,o[i]);let r=le(e.cookie);return r&&O(t,"Cookie",r),e.storage&&typeof e.storage=="object"&&O(t,"X-Atkonoffice-Storage",JSON.stringify(e.storage)),t}function ht(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 Pe="atkonoffice-doc-host",ee="__atkonofficeDocHostEvent",te=["documentSaved","documentOpened","documentBeforeSave","error","controlReady","compareDiff"],Oe={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave","compare.diff":"compareDiff"},_e="controlReady",ve="toolbarClick",Ie="readbackResult",Ce="messageBoxResult",a={eventHandlers:{},hintShown:!1,toolbarButtons:{},toolbarSeq:0,readbackPending:{},readbackSeq:0,messageBoxPending:{},messageBoxSeq:0};function Be(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;g();let r=typeof t=="number"&&isFinite(t)?Math.trunc(t):0,i="btn-"+ ++a.toolbarSeq;return a.toolbarButtons[i]=o,w("toolbarAdd",JSON.stringify({buttonId:i,caption:e,iconIndex:r}))?{remove:function(){delete a.toolbarButtons[i],w("toolbarRemove",JSON.stringify({buttonId:i}))}}:(delete a.toolbarButtons[i],Le(),null)}function Ae(e){if(typeof e!="boolean")throw new TypeError("atkonoffice embed.setCustomToolbarVisible: visible must be a boolean");return typeof window>"u"?f:(g(),w("toolbarSetVisible",JSON.stringify({visible:e})),f)}function Ue(e){let t=e&&e.buttonId;if(typeof t!="string"||!t)return;let o=a.toolbarButtons[t];if(typeof o=="function")try{o()}catch(r){Me("addCustomToolButton onClick threw: "+(r&&r.message?r.message:r))}}function K(){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)}),e}function De(e){let t=K();return t&&typeof t.save=="function"?t.save(e):!1}function Ne(e){let t=K();return t&&typeof t.setSavePath=="function"?t.setSavePath(e):!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 gt=15e3;function v(e,t){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});g();let o=++a.readbackSeq,r=JSON.stringify({rid:o,method:e,args:Array.isArray(t)?t:[]});return new Promise(i=>{let s=setTimeout(function(){ne(o,{ok:!1,error:"timeout"})},gt);s&&typeof s.unref=="function"&&s.unref(),a.readbackPending[o]={resolve:i,timer:s},w("readback",r)||ne(o,{ok:!1,error:"shell-absent"})})}function ne(e,t){let o=a.readbackPending[e];o&&(delete a.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})}var yt=6e5;function He(e){if(typeof window>"u")return Promise.resolve({ok:!1,error:"non-browser"});g();let t=e&&typeof e=="object"?e:{},o=++a.messageBoxSeq,r=JSON.stringify({rid:o,type:t.type,title:t.title,text:t.text,buttons:t.buttons});return new Promise(i=>{let s=setTimeout(function(){oe(o,{ok:!1,error:"timeout"})},yt);s&&typeof s.unref=="function"&&s.unref(),a.messageBoxPending[o]={resolve:i,timer:s},w("messageBox",r)||oe(o,{ok:!1,error:"shell-absent"})})}function oe(e,t){let o=a.messageBoxPending[e];o&&(delete a.messageBoxPending[e],clearTimeout(o.timer),o.resolve(t))}function je(e){let t=e&&e.rid;typeof t=="number"&&oe(t,{ok:!!(e&&e.ok),button:e?e.button:void 0,error:e?e.error:void 0})}function g(){wt(),K()}function Ke(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 g(),a.eventHandlers[e]||(a.eventHandlers[e]=[]),a.eventHandlers[e].push(t),f}function wt(){typeof window>"u"||typeof window[ee]=="function"||(window[ee]=function(e,t){if(e===_e){We("controlReady",t||{});return}if(e===ve){Ue(t||{});return}if(e===Ie){Fe(t||{});return}if(e===Ce){je(t||{});return}let o=Oe[e];o&&We(o,t||{})})}function We(e,t){let o=a.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 Le(){if(!a.hintShown){a.hintShown=!0;try{console.info("[atkonoffice embed] <"+Pe+"> \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 Ge(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeSave: fn must be a function");return g(),Ve("onBeforeSave",e),f}function Je(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeClose: fn must be a function");return g(),Ve("onBeforeClose",e),f}function Ve(e,t){if(typeof window>"u")return!1;let o=window.__atkonofficeDocHost;return o&&typeof o[e]=="function"?(o[e](t),!0):!1}var Tt="AO_";function G(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),r={};return r[e]=o,v("Word_FillDataRegion",[JSON.stringify(r)]).then(G)}function Xe(e,t){if(typeof e!="string"||!e)return Promise.resolve(!1);let o=typeof t=="string"?t:t==null?"":String(t);return v("Word_AddDataRegion",[e,o]).then(G)}function qe(e){return typeof e!="string"||!e?Promise.resolve(!1):v("Word_DeleteDataRegion",[e]).then(G)}function ze(e){return typeof e!="string"||!e?Promise.resolve(!1):v("Word_LocateDataRegion",[e]).then(G)}function $e(e){let t=typeof e=="string"?e:Tt;return v("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=Ke;f.addCustomToolButton=Be;f.setCustomToolbarVisible=Ae;f.save=De;f.setSavePath=Ne;f.showMessageBox=He;f.onBeforeSave=Ge;f.onBeforeClose=Je;f.word={fillDataRegion:Ye,addDataRegion:Xe,deleteDataRegion:qe,locateDataRegion:ze,listDataRegions:$e};y.config=Se;y.open=Z;y.on=ke;y.session=f;var bt=y,Wn=bt;export{bt as atkonoffice,Wn as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atkonoffice/sdk",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Browser-side SDK for the atkonoffice editor shell",
5
5
  "homepage": "https://atkon.yunhuichongming.cn",
6
6
  "type": "module",
@@ -30,4 +30,4 @@
30
30
  "devDependencies": {
31
31
  "esbuild": "0.28.1"
32
32
  }
33
- }
33
+ }