@atkonoffice/sdk 1.5.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>
@@ -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"],T={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave","shell.closed":"shellClosed"},P="atkonoffice-launch=",ie="\u2007",I="pair.ready",se="launch.open",ae="doc.embedFailed",C="__atkonofficeTitle",J="atkonoffice-install-guide";function ce(e){return e&&e.endsWith("/")?e.slice(0,-1):e}function B(e,t,o){let r=e.indexOf("?")===-1?"?":"&";return e+r+t+"="+o}function U(e){return!!e&&Object.keys(e).length>0}function x(e){return e&&e.message?e.message:String(e)}function E(e,t,o){if(t==null)return;let r=String(t).trim();r&&(e[r]=o==null?"":String(o))}function fe(e){return e?typeof e=="string"?e:typeof e=="object"?Object.keys(e).map(t=>t+"="+String(e[t])).join("; "):"":""}function le(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 A(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 ze(){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 ze()(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 ue(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,X(),Ze()}function de(){!n.pairing||typeof document>"u"||(n.pairingTitleSaved||(n.pairingPrevTitle=k(),n.pairingTitleSaved=!0),pe(),Qe())}function pe(){R(L(n.wsUrl,n.pairId,n.launchTicket))}function L(e,t,o){let r=le(JSON.stringify({wsUrl:e,pairId:t,launchTicket:o}));return ie+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 X(){n.titleRelayInstalled||typeof window>"u"||typeof window.addEventListener!="function"||Y()||(n.titleRelayInstalled=!0,window.addEventListener("message",e=>{if(!$e(e&&e.origin))return;let t=e&&e.data;if(t&&typeof t=="object"&&typeof t[C]=="string")try{document.title=t[C]}catch{}}))}function $e(e){let t=n.trustedFrameOrigins;return!t||t.length===0?!0:typeof e=="string"&&t.indexOf(e)!==-1}function Qe(){n.pairingRecoverTimer||typeof setInterval>"u"||(n.pairingRecoverTimer=setInterval(()=>{n.pairing&&k().indexOf(P)<0&&pe()},n.pairRecoverMs))}function Ze(){n.pairingTimeoutTimer||typeof setTimeout>"u"||(n.pairingTimeoutTimer=setTimeout(()=>{n.pairingTimeoutTimer=null,he(!0)},n.pairTimeoutMs))}function me(){if(!n.pairing)return;let e=n.ws;he(!1),e&&et(e)}function et(e){let t={v:1,type:"event",op:se,ts:Math.floor(Date.now()/1e3),payload:{pair_id:n.pairId,openParams:n.openParams||{}}};try{e.send(JSON.stringify(t))}catch(o){l("error",new Error("atkonoffice: failed to send launch.open frame \u2014 "+x(o)))}}function he(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&&(A(n.fallbackUrl),typeof n.onPairDowngrade=="function"&&n.onPairDowngrade())}var tt="documentEmbedFailed";function ge(e){l(tt,e||{})}function ye(e,t){if(!(!e||typeof sessionStorage>"u"))try{sessionStorage.setItem(O,JSON.stringify({pairId:e,wsUrl:t}))}catch{}}function we(){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 Te(){if(n.pairId="",n.wsUrl="",!(typeof sessionStorage>"u"))try{sessionStorage.removeItem(O)}catch{}}function M(){if(n.ws||n.wsReconnectTimer||!n.backendBase)return;let e=we();!e||!e.pairId||(n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,n.wsReconnectAttempt=0,be(e.pairId,t=>H(t)))}function H(e){if(typeof WebSocket>"u"){l("error",new Error("atkonoffice: WebSocket unavailable in this host \u2014 document events disabled"));return}if(!n.wsUrl){l("error",new Error("atkonoffice: no wsUrl \u2014 cannot open the document-event channel"));return}if(!e){l("error",new Error("atkonoffice: missing ws_ticket \u2014 cannot subscribe to document events"));return}nt();let t=B(n.wsUrl,"ticket",encodeURIComponent(e)),o;try{o=new WebSocket(t)}catch(r){l("error",new Error("atkonoffice: WS connect failed \u2014 "+x(r))),S();return}n.ws=o,o.onopen=()=>{n.wsReconnectAttempt=0,n.wsGaveUp=!1,ot(o),n.pairing&&de()},o.onmessage=r=>{rt(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){Te();return}S()}}function nt(){n.wsReconnectTimer&&(clearTimeout(n.wsReconnectTimer),n.wsReconnectTimer=null);let e=n.ws;if(n.ws=null,e){e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null;try{e.close(1e3,"client_close")}catch{}}}function ot(e){if(!U(n.headers))return;let t={v:1,type:"event",op:"client.headers",ts:Math.floor(Date.now()/1e3),payload:{headers:n.headers}};try{e.send(JSON.stringify(t))}catch(o){l("error",new Error("atkonoffice: failed to send headers frame \u2014 "+x(o)))}}function rt(e){if(typeof e!="string")return;let t;try{t=JSON.parse(e)}catch{return}if(!t||t.type!=="event")return;if(t.op===I){me();return}if(t.op===ae){ge(t.payload||{});return}let o=T[t.op];o&&l(o,t.payload||{})}function S(){if(n.wsReconnectTimer||n.wsGaveUp)return;let e=we();if(!e||!e.pairId){l("error",new Error("atkonoffice: document-event channel dropped and no pair to resume"));return}if(n.wsReconnectAttempt>=K){n.wsGaveUp=!0,Te();let r=new Error("atkonoffice: document-event channel lost \u2014 gave up after "+K+" consecutive reconnect attempts");r.terminal=!0,l("error",r);return}let t=n.wsReconnectAttempt+1;n.wsReconnectAttempt=t;let o=Math.min(3e4,500*Math.pow(2,t-1));n.wsReconnectTimer=setTimeout(()=>{n.wsReconnectTimer=null,be(e.pairId,r=>{n.pairId=e.pairId,n.wsUrl=e.wsUrl||n.wsUrl,H(r)})},o)}async function be(e,t){let o=G();if(!o||!n.backendBase){l("error",new Error("atkonoffice: cannot refresh ws_ticket \u2014 backend not configured")),S();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)),S();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")),S();return}typeof i.wsUrl=="string"&&i.wsUrl&&(n.wsUrl=i.wsUrl),t(i.wsTicket)}catch(r){l("error",new Error("atkonoffice: ws_ticket refresh failed \u2014 "+x(r))),S()}}function it(e){let t=n.eventHandlers[e];return!!t&&t.length>0}function st(e){for(let t in T)if(T.hasOwnProperty(t)&&T[t]===e)return!0;return!1}function xe(){for(let e in T)if(T.hasOwnProperty(e)&&it(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 Ee(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),st(e)&&M(),y}function ke(){at(n.pairTimeoutMs).then(e=>{e.installed||ft(e.clientDownloadUrl)})}function at(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&&(R(c),p=!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,h(),t({installed:d,clientDownloadUrl:m}))};i=setTimeout(()=>u(!1),e),ct().then(d=>{if(d&&typeof d.clientDownloadUrl=="string"&&(m=d.clientDownloadUrl),o||!N(d)){u(!1);return}let j=d.wsUrl,ne=typeof d.pairId=="string"?d.pairId:"",oe=d.launchTicket;X();let b;try{b=new WebSocket(B(j,"ticket",encodeURIComponent(d.wsTicket)))}catch{u(!1);return}r=b,b.onopen=()=>{c=k(),p=!0,R(L(j,ne,oe)),s=setInterval(()=>{!o&&k().indexOf(P)<0&&R(L(j,ne,oe))},n.pairRecoverMs)},b.onmessage=W=>{let re=W&&W.data;if(typeof re!="string")return;let _;try{_=JSON.parse(re)}catch{return}_&&_.type==="event"&&_.op===I&&u(!0)},b.onerror=()=>{},b.onclose=()=>{}}).catch(()=>{u(!1)})})}async function ct(){return D({docId:"",pageUrl:"",user:""},"atkonoffice: launch-probe")}function ft(e){if(typeof document>"u"||!document.body||typeof document.createElement!="function")return null;q();let t=document.createElement("div");t.setAttribute("data-atkonoffice-guide",J),t.style.cssText="position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.45);font:14px/1.6 system-ui,-apple-system,sans-serif;";let o=document.createElement("div");o.style.cssText="background:#fff;color:#222;max-width:420px;width:86%;border-radius:8px;padding:24px;box-shadow:0 8px 32px rgba(0,0,0,0.25);box-sizing:border-box;";let r=document.createElement("h2");r.textContent="\u9700\u8981\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF",r.style.cssText="margin:0 0 12px;font-size:18px;";let i=document.createElement("p");i.style.cssText="margin:0 0 20px;color:#444;",i.textContent=e?"\u672A\u68C0\u6D4B\u5230\u672C\u673A\u5DF2\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF\u3002\u8BF7\u5148\u4E0B\u8F7D\u5E76\u5B89\u88C5,\u5B89\u88C5\u5B8C\u6210\u540E\u70B9\u300C\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5\u300D\u3002":"\u672A\u68C0\u6D4B\u5230\u672C\u673A\u5DF2\u5B89\u88C5\u7F16\u8F91\u5668\u5BA2\u6237\u7AEF,\u4E14\u672A\u914D\u7F6E\u4E0B\u8F7D\u5730\u5740\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u83B7\u53D6\u5B89\u88C5\u5305,\u5B89\u88C5\u5B8C\u6210\u540E\u70B9\u300C\u6211\u5DF2\u5B89\u88C5,\u91CD\u8BD5\u300D\u3002";let 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 u=document.createElement("a");u.textContent="\u4E0B\u8F7D\u5BA2\u6237\u7AEF",u.href=e,u.target="_blank",u.rel="noopener noreferrer",u.style.cssText=c,s.appendChild(u)}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="'+J+'"]');e&&typeof e.remove=="function"?e.remove():e&&e.parentNode&&typeof e.parentNode.removeChild=="function"&&e.parentNode.removeChild(e)}catch{}}function Re(e){if(!e||typeof e!="object")throw new TypeError("atkonoffice.config requires an options object");if(typeof e.backendBase=="string"&&(n.backendBase=ce(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,xe()&&M(),y}async function z(e){let t=e||{};if(!n.backendBase)throw new Error("atkonoffice.open: backendBase not configured \u2014 call atkonoffice.config({ backendBase }) first");let o=t.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=ut(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 D(s,"atkonoffice.open: launch");if(!c||typeof c.launchUrl!="string"||!c.launchUrl)throw new Error("atkonoffice.open: launch endpoint response missing launchUrl");let m=lt(t);n.headers=U(m)?m:null;let h=N(c);return n.replayOpen=()=>z(e),n.onPairDowngrade=h?ke: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:"",ye(n.pairId,n.wsUrl),n.wsReconnectAttempt=0,n.wsGaveUp=!1,h&&ue(c),H(c.wsTicket)),h||A(c.launchUrl),{launchUrl:c.launchUrl,downloadUrl:typeof c.downloadUrl=="string"?c.downloadUrl:"",pairId:n.pairId,wsUrl:n.wsUrl}}function lt(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 s=i.indexOf(":");E(t,i.slice(0,s),i.slice(s+1).trim())}}else if(o&&typeof o=="object")for(let i of Object.keys(o))E(t,i,o[i]);let r=fe(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 ut(e){if(!e||typeof e!="object")return null;let t={};return typeof e.width=="number"&&(t.width=e.width),typeof e.height=="number"&&(t.height=e.height),typeof e.modal=="boolean"&&(t.modal=e.modal),Object.keys(t).length>0?t:null}var f={};var Se="atkonoffice-doc-host",$="__atkonofficeDocHostEvent",Q=["documentSaved","documentOpened","documentBeforeSave","error","controlReady","compareDiff"],Pe={"doc.saved":"documentSaved","doc.opened":"documentOpened","doc.beforeSave":"documentBeforeSave","compare.diff":"compareDiff"},ve="controlReady",_e="toolbarClick",Oe="readbackResult",Ie="messageBoxResult",a={eventHandlers:{},hintShown:!1,toolbarButtons:{},toolbarSeq:0,readbackPending:{},readbackSeq:0,messageBoxPending:{},messageBoxSeq:0};function Ce(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],De(),null)}function Be(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){Le("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):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 Ae(e){let t=F();return t&&typeof t.save=="function"?t.save(e):!1}function Ne(e){let t=F();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 dt=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(){Z(o,{ok:!1,error:"timeout"})},dt);s&&typeof s.unref=="function"&&s.unref(),a.readbackPending[o]={resolve:i,timer:s},w("readback",r)||Z(o,{ok:!1,error:"shell-absent"})})}function Z(e,t){let o=a.readbackPending[e];o&&(delete a.readbackPending[e],clearTimeout(o.timer),o.resolve(t))}function Me(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})}var pt=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(){ee(o,{ok:!1,error:"timeout"})},pt);s&&typeof s.unref=="function"&&s.unref(),a.messageBoxPending[o]={resolve:i,timer:s},w("messageBox",r)||ee(o,{ok:!1,error:"shell-absent"})})}function ee(e,t){let o=a.messageBoxPending[e];o&&(delete a.messageBoxPending[e],clearTimeout(o.timer),o.resolve(t))}function Fe(e){let t=e&&e.rid;typeof t=="number"&&ee(t,{ok:!!(e&&e.ok),button:e?e.button:void 0,error:e?e.error:void 0})}function g(){mt(),F()}function We(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 g(),a.eventHandlers[e]||(a.eventHandlers[e]=[]),a.eventHandlers[e].push(t),f}function mt(){typeof window>"u"||typeof window[$]=="function"||(window[$]=function(e,t){if(e===ve){je("controlReady",t||{});return}if(e===_e){Ue(t||{});return}if(e===Oe){Me(t||{});return}if(e===Ie){Fe(t||{});return}let o=Pe[e];o&&je(o,t||{})})}function je(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 De(){if(!a.hintShown){a.hintShown=!0;try{console.info("[atkonoffice embed] <"+Se+"> \u672A\u88AB\u5B9A\u4E49 \u2014\u2014 \u8BF7\u5728\u5DF2\u5B89\u88C5 atkonoffice \u5BA2\u6237\u7AEF\u7684\u58F3\u5185\u6253\u5F00\u672C\u7F16\u8F91\u9875;\u666E\u901A\u6D4F\u89C8\u5668\u91CC\u5B83\u662F\u7A7A\u76D2(\u4E0D\u5F71\u54CD\u9875\u9762\u5176\u4F59\u90E8\u5206)\u3002")}catch{}}}function Le(e){try{console.warn("[atkonoffice embed] "+e)}catch{}}function Ke(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeSave: fn must be a function");return g(),Je("onBeforeSave",e),f}function Ve(e){if(typeof e!="function")throw new TypeError("atkonoffice embed.onBeforeClose: fn must be a function");return g(),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 ht="AO_";function te(e){return!!(e&&e.ok&&Number(e.value)>0)}function Ye(e,t){if(typeof e!="string"||!e)return Promise.resolve(!1);let o=typeof t=="string"?t:t==null?"":String(t);return v("Word_AddDataRegion",[e,o]).then(te)}function Ge(e){return typeof e!="string"||!e?Promise.resolve(!1):v("Word_DeleteDataRegion",[e]).then(te)}function Xe(e){return typeof e!="string"||!e?Promise.resolve(!1):v("Word_LocateDataRegion",[e]).then(te)}function qe(e){let t=typeof e=="string"?e:ht;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=We;f.addCustomToolButton=Ce;f.setCustomToolbarVisible=Be;f.save=Ae;f.setSavePath=Ne;f.showMessageBox=He;f.onBeforeSave=Ke;f.onBeforeClose=Ve;f.word={addDataRegion:Ye,deleteDataRegion:Ge,locateDataRegion:Xe,listDataRegions:qe};y.config=Re;y.open=z;y.on=Ee;y.session=f;var gt=y,Mn=gt;export{gt as atkonoffice,Mn 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.5.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
+ }