@betteroffice/pptx 0.5.1 → 0.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.
Files changed (57) hide show
  1. package/LICENSES/MIT-ruzstd.txt +21 -0
  2. package/LICENSES/MIT-twox-hash.txt +21 -0
  3. package/LICENSES/MIT-wuff.txt +20 -0
  4. package/README.md +24 -5
  5. package/dist/chunk-2XA2UH2O.js +1 -0
  6. package/dist/chunk-4WP5ZWYV.js +1 -0
  7. package/dist/chunk-65A2TX24.js +1 -0
  8. package/dist/chunk-663FARNX.js +1 -0
  9. package/dist/chunk-AYLLA7XR.js +1 -0
  10. package/dist/chunk-AZDGFDN2.js +1 -0
  11. package/dist/chunk-CCVGR3MS.js +1 -0
  12. package/dist/chunk-COS6CTH7.js +2 -0
  13. package/dist/chunk-G54T5CXF.js +1 -0
  14. package/dist/chunk-GAM2OAAP.js +2 -0
  15. package/dist/chunk-GHET7GIK.js +1 -0
  16. package/dist/chunk-GR7EGQ2Z.js +1 -0
  17. package/dist/chunk-HZODDD5T.js +1 -0
  18. package/dist/chunk-J54GRQWZ.js +1 -0
  19. package/dist/chunk-JJV35WHH.js +2 -0
  20. package/dist/chunk-KGEED2XY.js +1 -0
  21. package/dist/chunk-OUNTNO7R.js +1 -0
  22. package/dist/chunk-QRAGGQDN.js +1 -0
  23. package/dist/chunk-QWRXUT7T.js +1 -0
  24. package/dist/chunk-RNJM2LKC.js +3 -0
  25. package/dist/chunk-S6HKAO2F.js +1 -0
  26. package/dist/chunk-S6UYP4BX.js +1 -0
  27. package/dist/chunk-T6VUFMNC.js +1 -0
  28. package/dist/chunk-TRT2B252.js +10 -0
  29. package/dist/collaboration.js +1 -1
  30. package/dist/{editorSession-Cl_EWgAi.d.ts → editorSession-qQaVvMVR.d.ts} +346 -6
  31. package/dist/generated/metafile_svg_wasm_bg.wasm +0 -0
  32. package/dist/generated/pptx_wasm_bg.wasm +0 -0
  33. package/dist/generated/pptx_wasm_lean_bg.wasm +0 -0
  34. package/dist/generated/preflight/pptx_preflight_bg.wasm +0 -0
  35. package/dist/index.d.ts +21 -18
  36. package/dist/index.js +1 -1
  37. package/dist/pptxSessionWorker.mjs +13 -9
  38. package/dist/pptxSessionWorker.node.mjs +1 -0
  39. package/dist/pptxWorkerStart.d.ts +5 -0
  40. package/dist/pptxWorkerStart.js +1 -0
  41. package/dist/sessionWorker.missing.d.ts +3 -0
  42. package/dist/sessionWorker.missing.js +1 -0
  43. package/dist/sessionWorker.node.d.ts +3 -0
  44. package/dist/sessionWorker.node.js +1 -0
  45. package/dist/transport-BcduBS8X.d.ts +16 -0
  46. package/dist/wasm-preflight.d.ts +26 -0
  47. package/dist/wasm-preflight.js +1 -0
  48. package/dist/worker.d.ts +122 -22
  49. package/dist/worker.js +1 -1
  50. package/package.json +18 -5
  51. package/dist/chunk-2CPM3HRW.js +0 -1
  52. package/dist/chunk-3TTZUGDD.js +0 -1
  53. package/dist/chunk-B6OFSXHM.js +0 -1
  54. package/dist/chunk-DDNX2Z7E.js +0 -1
  55. package/dist/chunk-JZOLK2OC.js +0 -1
  56. package/dist/chunk-NWXUJY6L.js +0 -3
  57. /package/dist/{pptxSessionWorker.d.ts → pptxSessionWorker.node.d.ts} +0 -0
@@ -1 +0,0 @@
1
- import {c,g as g$1,h,i,d as d$1,f,m,r,j as j$1,n,l as l$1,t,s,p as p$1,k,o,u,x}from'./chunk-2CPM3HRW.js';import {a}from'./chunk-O2XFH626.js';var O=new WeakMap;function ee(n,e){O.set(n,e);}function D(n){return O.get(n)}var l=class extends Error{constructor(t,r,s){super(r);a(this,"code");a(this,"cause");this.name="CollaborationError",this.code=t,this.cause=s;}};function G(n){return n instanceof Error&&n.message?n.message:typeof n=="string"&&n?n:"Unknown error"}var $=["backpressure","protocol","replica","transport"],g=64,Q=250;function X(n){if(n[0]!==0||n[1]!==2)return false;let e=0;for(let t=2,r=0;t<Math.min(n.byteLength,7);t++,r+=7)if(e+=(n[t]&127)*2**r,n[t]<128)return t+1+e===n.byteLength;return false}var y=class{constructor(e,t,r){a(this,"transport",t);a(this,"options",r);a(this,"endpoint");a(this,"statusListeners",new Map);a(this,"errorListeners",new Map);a(this,"peerListeners",new Map);a(this,"nextListenerId",0);a(this,"connectionStatus","disconnected");a(this,"isSynced",false);a(this,"peerList",[]);a(this,"seq",0);a(this,"floor",0);a(this,"sendFloor",0);a(this,"inboundBytes",0);a(this,"flushingFrames",false);a(this,"queue",[]);a(this,"posting",false);a(this,"flushQueued",false);a(this,"heldTimer",null);a(this,"urgent",false);a(this,"unsubscribeTransport",null);a(this,"subscription",0);a(this,"wantsConnection",false);a(this,"connectAttempt",0);a(this,"leaveFrame",null);a(this,"pendingFrames",[]);a(this,"queuedBytes",0);a(this,"isDestroyed",false);a(this,"closed",false);this.endpoint=e.open(s=>this.receive(s),s=>this.lose(s)),this.enqueue({op:"create",seq:++this.seq,options:r.worker});}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}get peers(){return this.peerList}setCursor(e,t){this.isDestroyed||this.enqueue({op:"cursor",seq:++this.seq,cursor:e,broadcast:t});}onPeers(e){if(this.isDestroyed)return ()=>{};let t=this.nextListenerId++;return this.peerListeners.set(t,e),e(this.peers),()=>this.peerListeners.delete(t)}onStatus(e){if(this.isDestroyed)return ()=>{};let t=this.nextListenerId++;return this.statusListeners.set(t,e),()=>this.statusListeners.delete(t)}onError(e){if(this.isDestroyed)return ()=>{};let t=this.nextListenerId++;return this.errorListeners.set(t,e),()=>this.errorListeners.delete(t)}connect(){if(this.isDestroyed||this.connectionStatus==="connected"||this.connectionStatus==="connecting")return;if(this.closed){this.report(this.options.makeError("replica","Collaboration replica is retired"));return}this.wantsConnection=true,this.floor=++this.seq,this.enqueue({op:"connect",seq:this.floor});let e=++this.connectAttempt;if(this.setStatus("connecting",false),!(!this.wantsConnection||this.isDestroyed||e!==this.connectAttempt)){if(!this.unsubscribeTransport){let t=++this.subscription,r;try{if(r=this.transport.onEvent(s=>this.forward(t,s)),typeof r!="function")throw new TypeError("Transport event subscription must return a function")}catch(s){this.subscription+=1,this.fail(this.transportError("Failed to subscribe to transport events",s));return}if(!this.wantsConnection||this.isDestroyed||e!==this.connectAttempt||t!==this.subscription){try{r();}catch(s){this.isDestroyed||this.report(this.transportError("Failed to unsubscribe from stale transport events",s));}return}this.unsubscribeTransport=r;}try{let t=this.transport.connect();t&&t.catch(r=>{!this.isDestroyed&&this.wantsConnection&&this.connectAttempt===e&&this.fail(this.transportError("Transport connect failed",r));});}catch(t){this.fail(this.transportError("Transport connect failed",t));}}}disconnect(){if(this.isDestroyed)return;if(this.closed){this.setStatus("disconnected",false);return}if(!(this.wantsConnection||this.unsubscribeTransport!==null||this.connectionStatus!=="disconnected"))return;this.sendLeave(),this.floor=++this.seq,this.enqueue({op:"disconnect",seq:this.floor});let t=this.release(true);this.setStatus("disconnected",false);for(let r of t)this.report(r);}destroy(){if(this.isDestroyed)return;let e=!this.closed&&(this.wantsConnection||this.unsubscribeTransport!==null||this.connectionStatus==="connecting"||this.connectionStatus==="connected");e&&this.sendLeave(),this.floor=++this.seq,this.enqueue({op:"destroy",seq:this.floor});let t=this.closed?[]:this.release(e);this.isDestroyed=true,this.setStatus("destroyed",false);for(let r of t)this.report(r);this.statusListeners.clear(),this.errorListeners.clear(),this.peerListeners.clear();}transportError(e,t){return this.options.normalize("transport",e,t)}release(e){this.wantsConnection=false,this.connectAttempt+=1,this.leaveFrame=null,this.clearQueue(),this.clearPeers();let t=[],r=this.unsubscribeTransport;if(this.unsubscribeTransport=null,this.subscription+=1,r)try{r();}catch(s){t.push(this.transportError("Failed to unsubscribe from transport events",s));}if(!e)return t;try{let s=this.transport.disconnect();s&&s.catch(o=>{this.isDestroyed||this.report(this.transportError("Transport disconnect failed",o));});}catch(s){t.push(this.transportError("Transport disconnect failed",s));}return t}fail(e){if(this.isDestroyed||!this.wantsConnection)return;let t=e.code;this.floor=++this.seq,this.enqueue({op:"fail",seq:this.floor,error:{code:typeof t=="string"&&$.includes(t)?t:"transport",message:e.message}});let r=this.release(true);this.setStatus("disconnected",false),this.report(e);for(let s of r)this.report(s);}sendLeave(){let e=this.leaveFrame;if(this.leaveFrame=null,!(!e||!this.options.hasUser||!this.unsubscribeTransport||this.connectionStatus!=="connected"))try{this.transport.send(e);}catch(t){this.report(this.transportError("Failed to send awareness leave",t));}}enqueue(e,t=false){this.closed||(this.queue.push(e),this.schedule(t));}schedule(e){if(e||(this.urgent=true),!(this.posting||this.flushQueued)){if(e){this.heldTimer??(this.heldTimer=setTimeout(()=>{this.heldTimer=null,this.flush();},Q));return}this.flushQueued=true,queueMicrotask(()=>{this.flushQueued=false,this.flush();});}}flush(){if(this.posting||this.closed||this.queue.length===0)return;this.heldTimer!==null&&(clearTimeout(this.heldTimer),this.heldTimer=null);let e=this.queue;this.queue=[],this.urgent=false,this.posting=true;let t=e.some(o=>o.op==="destroy"),r=e.reduce((o,a)=>a.op==="event"&&a.event.type==="message"?o+a.event.data.byteLength+g:o,0),s;try{s=this.endpoint.post(e,u(e));}catch(o){s=Promise.reject(o);}s.then(()=>{this.posting=false,this.inboundBytes-=r,t?this.close():this.urgent?this.flush():this.queue.length>0&&this.schedule(true);},o=>{this.posting=false,this.inboundBytes-=r,this.lose(G(o));});}forward(e,t){if(!(this.closed||this.isDestroyed||e!==this.subscription))switch(t.type){case "message":if(this.inboundBytes===0?t.data.byteLength>this.options.maxPendingBytes:t.data.byteLength+g>this.options.maxPendingBytes-this.inboundBytes){this.fail(this.options.makeError("backpressure","Pending replica data exceeds the byte limit"));return}this.inboundBytes+=t.data.byteLength+g,this.enqueue({op:"event",seq:++this.seq,event:{type:"message",data:t.data.slice().buffer}},!this.isSynced&&X(t.data)&&this.inboundBytes<=this.options.maxPendingBytes/2);return;case "open":case "close":this.clearQueue(),t.type==="close"&&(this.connectAttempt+=1,this.leaveFrame=null),this.sendFloor=++this.seq,this.enqueue({op:"event",seq:this.sendFloor,event:t.type==="open"?{type:"open"}:{type:"close",...t.reason!==void 0&&{reason:t.reason}}}),t.type==="close"&&(this.clearPeers(),this.setStatus("disconnected",false));return;case "drain":this.flushPending();return;case "error":this.fail(this.transportError("Transport error",t.error));return;default:this.fail(this.options.makeError("transport","Unknown transport event"));}}receive(e){for(let t of e){if(this.closed||this.isDestroyed)return;if(t.do==="lost"){this.lose("Collaboration replica is retired");return}if(!(t.through<this.floor))switch(t.do){case "unsubscribe":{let r=this.release(false);for(let s of r)this.report(s);break}case "disconnect":{this.wantsConnection=false;let r=this.release(true);for(let s of r)this.report(s);break}case "send":t.through>=this.sendFloor&&this.send(new Uint8Array(t.data));break;case "leave":t.through>=this.sendFloor&&(this.leaveFrame=t.data?new Uint8Array(t.data):null);break;case "status":t.through>=this.sendFloor&&this.setStatus(t.status,t.synced);break;case "peers":{if(t.through<this.sendFloor||t.peers.length===0&&this.peerList.length===0)break;let r=this.options.rebasePeer,s=t.timeOrigin-x();this.peerList=r?t.peers.map(o=>r(o,s)):t.peers,this.emitPeers();break}case "error":this.report(this.options.makeError(t.error.code,t.error.message));break}}}send(e){if(!this.unsubscribeTransport)return;if(this.pendingFrames.length>0){this.queueFrame(e);return}let t=this.sendFloor,r;try{r=this.transport.send(e.slice());}catch(s){this.fail(this.transportError("Transport send failed",s));return}if(typeof r!="boolean"){this.fail(this.options.makeError("transport","Transport send must return a boolean"));return}!r&&this.unsubscribeTransport!==null&&t===this.sendFloor&&this.queueFrame(e);}queueFrame(e){if(e.byteLength>this.options.maxPendingBytes-this.queuedBytes){this.fail(this.options.makeError("backpressure",`Pending collaboration data exceeds ${this.options.maxPendingBytes} bytes`));return}this.pendingFrames.push(e),this.queuedBytes+=e.byteLength;}flushPending(){if(!this.flushingFrames){this.flushingFrames=true;try{for(;this.unsubscribeTransport&&this.pendingFrames.length>0;){let e=this.pendingFrames[0],t;try{t=this.transport.send(e.slice());}catch(r){this.fail(this.transportError("Transport send failed",r));return}if(typeof t!="boolean"){this.fail(this.options.makeError("transport","Transport send must return a boolean"));return}if(!t||this.pendingFrames[0]!==e)return;this.pendingFrames.shift(),this.queuedBytes-=e.byteLength;}}finally{this.flushingFrames=false;}}}clearQueue(){this.pendingFrames.length=0,this.queuedBytes=0;}lose(e){if(this.closed||(this.close(),this.isDestroyed))return;this.sendLeave();let t=this.release(this.wantsConnection||this.connectionStatus!=="disconnected");setTimeout(()=>{if(!this.isDestroyed){this.setStatus("disconnected",false),this.report(this.options.makeError("replica",e));for(let r of t)this.report(r);}},0);}close(){this.closed||(this.closed=true,this.queue=[],this.heldTimer!==null&&(clearTimeout(this.heldTimer),this.heldTimer=null),this.endpoint.close());}clearPeers(){this.peerList.length!==0&&(this.peerList=[],this.emitPeers());}setStatus(e,t){if(!(this.connectionStatus===e&&this.isSynced===t)){this.connectionStatus=e,t&&!this.isSynced&&this.queue.length>0&&this.schedule(false),this.isSynced=t;for(let[r,s]of [...this.statusListeners])if(this.statusListeners.get(r)===s)try{s({status:e,synced:t});}catch{}}}emitPeers(){let e=this.peers;for(let[t,r]of [...this.peerListeners])if(this.peerListeners.get(t)===r)try{r(e);}catch{}}report(e){for(let[t,r]of [...this.errorListeners])if(this.errorListeners.get(t)===r)try{r(e);}catch{}}};var j=16*1024*1024,Y=16*1024*1024;function C(n,e,t){if(!Number.isSafeInteger(e)||e<(t?0:1))throw new RangeError(`${n} must be ${t?"a non-negative":"a positive"} integer`);return e}function J(n){return n instanceof Error&&n.message?n.message:typeof n=="string"&&n?n:"Unknown error"}function p(n,e,t){return t instanceof l?t:new l(n,`${e}: ${J(t)}`,t)}function d(n,e){if(!(n instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return n.slice()}function T(n){typeof n=="object"&&n&&"unref"in n&&n.unref();}function K(n){if(!Number.isSafeInteger(n)||n<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return n}function Z(n){if(n===null)return null;if(!n||typeof n.slideId!="string"||n.slideId.length===0)throw new TypeError("Presence cursor slideId must be a non-empty string");if(n.shapeId!==void 0&&(typeof n.shapeId!="string"||n.shapeId.length===0))throw new TypeError("Presence cursor shapeId must be a non-empty string");return n.shapeId?{slideId:n.slideId,shapeId:n.shapeId}:{slideId:n.slideId}}var _=new WeakMap,N=new WeakMap;function ue(n){return _.get(n)()}function de(n){return N.get(n)()}var M=class{constructor(e,t,r={}){a(this,"piped");a(this,"openEpoch",0);a(this,"replica");a(this,"transport");a(this,"maxFrameBytes");a(this,"maxMessagesPerFrame");a(this,"maxPendingBytes");a(this,"localClientId");a(this,"localUser");a(this,"remotePresence");a(this,"statusListeners",new Map);a(this,"errorListeners",new Map);a(this,"presenceListeners",new Map);a(this,"pendingFrames",[]);a(this,"unsubscribeReplica");a(this,"unsubscribeTransport",()=>{});a(this,"hasTransportSubscription",false);a(this,"connectionStatus","disconnected");a(this,"isSynced",false);a(this,"wantsConnection",false);a(this,"isOpen",false);a(this,"isDestroyed",false);a(this,"epoch",0);a(this,"connectAttempt",0);a(this,"nextListenerId",0);a(this,"queuedBytes",0);a(this,"incoming",[]);a(this,"incomingBytes",0);a(this,"incomingBusy",false);a(this,"asyncReplica",false);a(this,"incomingGeneration",0);a(this,"isFlushing",false);a(this,"localClock",0);a(this,"reportedClockExhaustion",false);a(this,"localCursor",null);a(this,"applyingArrival");a(this,"lastAwarenessSentAt",0);a(this,"cursorTimer",null);a(this,"heartbeatTimer",null);a(this,"expiryTimer",null);this.replica=e,"setCollaborative"in e&&e.setCollaborative?.(),this.transport=t,this.localClientId=K(e.clientId),this.localUser=c(this.localClientId,r.user),this.remotePresence=new g$1(this.localClientId),this.maxFrameBytes=C("maxFrameBytes",r.maxFrameBytes??h,false),this.maxMessagesPerFrame=C("maxMessagesPerFrame",r.maxMessagesPerFrame??i,false),this.maxPendingBytes=C("maxPendingBytes",r.maxPendingBytes??j,true),_.set(this,()=>this.beginArrival()),N.set(this,()=>this.leaveFrame());let s=D(e);if(s){this.unsubscribeReplica=()=>{},this.piped=new y(s,t,{worker:{maxFrameBytes:this.maxFrameBytes,maxMessagesPerFrame:this.maxMessagesPerFrame,user:{...this.localUser}},maxPendingBytes:this.maxPendingBytes,hasUser:true,makeError:(o,a,c)=>new l(o,a,c),normalize:p});return}try{this.unsubscribeReplica=e.onUpdate((o,a)=>{a==="local"&&this.forwardLocalUpdate(o);});}catch(o){throw p("replica","Failed to observe replica updates",o)}}get status(){return this.piped?this.piped.status:this.connectionStatus}get synced(){return this.piped?this.piped.synced:this.isSynced}get pendingBytes(){return this.piped?this.piped.pendingBytes:this.queuedBytes}get peers(){return this.piped?this.piped.peers:this.remotePresence.peers}setCursor(e){if(this.isDestroyed||this.piped?.status==="destroyed")return;let t=Z(e),r=!t||d$1(t)?t:null;if(t&&!r){let s=new l("protocol",`Presence cursor identifiers exceed ${1024} characters; cursor dropped`);this.report(s);}if(!f(this.localCursor,r)){if(this.localCursor=r,this.piped)return this.piped.setCursor(r,true);this.isOpen&&this.wantsConnection&&this.scheduleCursorBroadcast();}}connect(){if(this.piped)return this.piped.connect();if(this.isDestroyed||this.isOpen||this.connectionStatus==="connecting")return;this.wantsConnection=true;let e=this.hasTransportSubscription?this.epoch:++this.epoch,t=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let r;try{if(r=this.transport.onEvent(s=>this.handleTransportEvent(e,s)),typeof r!="function")throw new TypeError("Transport event subscription must return a function")}catch(s){this.failConnection(e,p("transport","Failed to subscribe to transport events",s));return}if(!this.isCurrent(e)){try{r();}catch(s){this.isDestroyed||this.report(p("transport","Failed to unsubscribe from stale transport events",s));}return}this.unsubscribeTransport=r,this.hasTransportSubscription=true;}try{let r=this.transport.connect();r&&r.catch(s=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,p("transport","Transport connect failed",s));});}catch(r){this.failConnection(e,p("transport","Transport connect failed",r));}}}disconnect(){if(this.piped)return this.piped.disconnect();if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;if(this.isOpen&&this.wantsConnection){let s=this.epoch;if(this.broadcastLocalPresence(true),!this.isCurrent(s))return}this.stopPresenceTimers(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let r=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let s of r)this.report(s);}destroy(){if(this.piped){this.piped.destroy(),this.isDestroyed=true,this.errorListeners.clear();return}if(this.isDestroyed||(this.isOpen&&this.wantsConnection&&this.broadcastLocalPresence(true),this.isDestroyed))return;let e=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.stopPresenceTimers(),this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let r=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let s of r)this.report(s);try{this.unsubscribeReplica();}catch(s){this.report(p("replica","Failed to unsubscribe from replica updates",s));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear(),this.presenceListeners.clear();}onStatus(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("status listener must be a function");if(this.piped)return this.piped.onStatus(e);let t=this.nextListenerId++;return this.statusListeners.set(t,e),()=>this.statusListeners.delete(t)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");if(this.piped){let r=this.piped.onError(e),s=this.nextListenerId++;return this.errorListeners.set(s,e),()=>{r(),this.errorListeners.delete(s);}}let t=this.nextListenerId++;return this.errorListeners.set(t,e),()=>this.errorListeners.delete(t)}onPresence(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("presence listener must be a function");if(this.piped)return this.piped.onPeers(r=>{try{e(r);}catch{}});let t=this.nextListenerId++;this.presenceListeners.set(t,e);try{e(this.peers);}catch{}return ()=>this.presenceListeners.delete(t)}beginArrival(){let e=this.epoch,t=this.openEpoch,r=this.applyingArrival;r&&(r.deferred=true);let s=false,o=a=>{s||(s=true,this.isCurrent(e)&&this.isOpen&&this.openEpoch===t&&a());};return {settle:()=>o(()=>{r?.synced&&this.setStatus("connected",true);}),fail:a=>o(()=>this.failConnection(e,p("replica","Failed to apply remote update",a)))}}leaveFrame(){if(!this.isOpen||this.isDestroyed||!this.wantsConnection||this.localClock>=Number.MAX_SAFE_INTEGER)return null;try{let e=this.localClock+1;return {clock:e,frame:m([{clientId:this.localClientId,clock:e,state:null}],this.maxFrameBytes)}}catch{return null}}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,t){if(!this.isCurrent(e))return;this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1,this.stopPresenceTimers();let r=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let s=this.cleanupTransport(r,true);this.setStatus("disconnected",false),this.report(t);for(let o of s)this.report(o);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let r=[];try{e();}catch(s){r.push(p("transport","Failed to unsubscribe from transport events",s));}if(!t)return r;try{let s=this.transport.disconnect();s&&s.catch(o=>{this.isDestroyed||this.report(p("transport","Transport disconnect failed",o));});}catch(s){r.push(p("transport","Transport disconnect failed",s));}return r}handleTransportEvent(e,t){if(this.isCurrent(e))switch(t.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.enqueueMessage(e,t.data);break;case "close":this.isOpen=false,this.connectAttempt+=1,this.stopPresenceTimers(),this.clearPending(),this.clearRemotePresence(),this.setStatus("disconnected",false);break;case "error":this.failConnection(e,p("transport","Transport error",t.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new l("transport","Unknown transport event"));}}handleOpen(e){if(this.isOpen||(this.isOpen=true,this.openEpoch+=1,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(e)||!this.isOpen))return;let t=this.connectAttempt;this.replicaResult(e,t,()=>this.replica.encodeStateVector(),r$1=>{try{let s=d(r$1,"encodeStateVector"),o=r(s);if(this.sendFrame(j$1(o??s,this.maxFrameBytes)),!this.isCurrent(e)||!this.isOpen||(o||this.sendFullUpdate(e,t),!this.isCurrent(e)||!this.isOpen)||(this.startPresenceTimers(),this.broadcastLocalPresence(!1),!this.isCurrent(e)||!this.isOpen))return;this.sendFrame(n(this.maxFrameBytes));}catch(s){this.failConnection(e,p("protocol","Failed to encode handshake",s));}});}sendFullUpdate(e,t){this.replicaResult(e,t,()=>this.replica.encodeStateAsUpdate(),r=>{try{this.sendFrame(l$1(d(r,"encodeStateAsUpdate"),this.maxFrameBytes));}catch(s){this.failConnection(e,p("protocol","Failed to encode handshake",s));}});}replicaResult(e,t,r,s){let o=c=>{this.isCurrent(e)&&this.isOpen&&this.connectAttempt===t&&s(c);},a=c=>{this.isCurrent(e)&&this.isOpen&&this.connectAttempt===t&&this.failConnection(e,p("replica","Collaboration replica operation failed",c));};try{let c=r();if(c instanceof Promise)return this.asyncReplica=!0,c.then(o,a).catch(a);o(c);}catch(c){a(c);}}handleMessage(e,t$1){let r;try{r=t(t$1.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(a){this.failConnection(e,p("protocol","Invalid collaboration frame",a));return}let s=this.connectAttempt,o$1=a=>{for(;a<r.length;a++){if(!this.isCurrent(e)||!this.isOpen||this.connectAttempt!==s)return;let c=r[a],h;switch(c.type){case "sync-step-1":h=this.answerSyncStep1(e,s,c.stateVector);break;case "sync-step-2":case "update":{let u={deferred:false,synced:c.type==="sync-step-2"};h=this.replicaResult(e,s,()=>{let V=this.applyingArrival;this.applyingArrival=u;try{return this.replica.applyUpdate(p$1(c.update).slice())}finally{this.applyingArrival=V;}},()=>{u.synced&&!u.deferred&&this.setStatus("connected",true);});break}case "awareness":try{let u=o(c.update,this.maxMessagesPerFrame);this.remotePresence.apply(u,Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();}catch(u){this.report(p("protocol","Invalid awareness update",u));}break;case "auth":this.failConnection(e,new l("protocol",c.reason?`Authentication denied: ${c.reason}`:"Authentication denied"));return;case "query-awareness":this.broadcastLocalPresence(false);break}if(h instanceof Promise)return h.then(()=>o$1(a+1))}};return o$1(0)}answerSyncStep1(e,t,r){let s$1=s(r),o=this.replicaResult(e,t,()=>this.replica.encodeStateAsUpdate(p$1(s$1.stateVector).slice()),c=>{try{this.sendFrame(k(d(c,"encodeStateAsUpdate"),this.maxFrameBytes));}catch(h){this.failConnection(e,p("protocol","Failed to encode SyncStep2",h));}});if(!s$1.open)return o;let a=()=>{if(!(!this.isCurrent(e)||!this.isOpen||this.connectAttempt!==t))return this.replicaResult(e,t,()=>this.replica.encodeStateVector(),c=>{try{this.sendFrame(j$1(d(c,"encodeStateVector"),this.maxFrameBytes));}catch(h){this.failConnection(e,p("protocol","Failed to encode handshake",h));}})};return o instanceof Promise?o.then(a):a()}enqueueMessage(e,t){if(this.asyncReplica&&this.incomingBytes+t.byteLength>this.maxPendingBytes){this.failConnection(e,new l("backpressure","Incoming collaboration queue is full"));return}this.incoming.push({token:e,data:t.slice()}),this.incomingBytes+=t.byteLength,this.drainIncoming();}drainIncoming(){if(this.incomingBusy)return;let e=this.incomingGeneration;for(;this.incoming.length;){let t=this.takeUpdateBatch(),r=t?.items??[this.incoming.shift()],s=r.reduce((a,c)=>a+c.data.byteLength,0);this.incomingBusy=true;let o=t?this.applyUpdateBatch(r[0].token,t.updates):this.handleMessage(r[0].token,r[0].data);if(e!==this.incomingGeneration)return;if(o instanceof Promise){o.finally(()=>{e===this.incomingGeneration&&(this.incomingBusy=false,this.incomingBytes-=s,this.drainIncoming());}).catch(()=>{});return}this.incomingBusy=false,this.incomingBytes-=s;}}takeUpdateBatch(){if(!this.asyncReplica||typeof this.replica.applyUpdateChunks!="function")return null;let e=[],t=[],r=Math.min(this.maxFrameBytes,Y),s=0;for(let o of this.incoming){if(o.token!==this.incoming[0].token)break;let a=this.remoteUpdates(o.data),c=a?.reduce((h,u)=>h+u.byteLength,0)??0;if(!a?.length||e.length&&s+c>r)break;e.push(o),t.push(...a),s+=c;}return e.length<2?null:(this.incoming.splice(0,e.length),{items:e,updates:t})}remoteUpdates(e){try{let t$1=t(e.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);return t$1.every(r=>r.type==="update")?t$1.map(r=>p$1(r.update).slice()):null}catch{return null}}applyUpdateBatch(e,t){if(!this.isCurrent(e)||!this.isOpen)return;let r=this.replica;return this.replicaResult(e,this.connectAttempt,()=>r.applyUpdateChunks(t),()=>{})}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let t=this.epoch,r;try{r=d(e,"Replica update");}catch(s){this.failConnection(t,p("replica","Invalid replica update",s));return}try{this.sendFrame(l$1(r,this.maxFrameBytes));}catch(s){this.failConnection(t,p("protocol","Failed to encode update",s));}}scheduleCursorBroadcast(){if(this.cursorTimer)return;let e=Math.max(0,80-(Date.now()-this.lastAwarenessSentAt));if(e===0){this.broadcastLocalPresence(false);return}this.cursorTimer=setTimeout(()=>{this.cursorTimer=null,this.broadcastLocalPresence(false);},e),T(this.cursorTimer);}broadcastLocalPresence(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;if(this.localClock>=Number.MAX_SAFE_INTEGER){this.reportedClockExhaustion||(this.reportedClockExhaustion=true,this.report(new l("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}this.localClock+=1;let t=this.localClock,r=e?null:{clientId:this.localClientId,clock:t,user:{...this.localUser},cursor:this.localCursor?{...this.localCursor}:null};this.cursorTimer&&clearTimeout(this.cursorTimer),this.cursorTimer=null,this.lastAwarenessSentAt=Date.now();try{let s=m([{clientId:this.localClientId,clock:t,state:r}],this.maxFrameBytes);e?this.sendLeaveFrameBestEffort(s):this.sendFrame(s);}catch(s){this.report(p("protocol","Failed to encode awareness update",s));}}sendLeaveFrameBestEffort(e){try{this.transport.send(e.slice());}catch{}}startPresenceTimers(){this.stopPresenceTimers(),this.heartbeatTimer=setInterval(()=>{this.broadcastLocalPresence(false);},2e4),T(this.heartbeatTimer),this.schedulePresenceExpiry();}stopPresenceTimers(){this.cursorTimer&&clearTimeout(this.cursorTimer),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.expiryTimer&&clearTimeout(this.expiryTimer),this.cursorTimer=null,this.heartbeatTimer=null,this.expiryTimer=null;}schedulePresenceExpiry(){if(this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null,!this.isOpen||this.isDestroyed)return;let e=this.remotePresence.nextExpiryAt;e!==void 0&&(this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.remotePresence.expire(Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();},Math.max(0,e-Date.now())),T(this.expiryTimer));}clearRemotePresence(){this.remotePresence.clear()&&this.emitPresence();}emitPresence(){let e=this.peers;for(let[t,r]of [...this.presenceListeners])if(this.presenceListeners.get(t)===r)try{r(e);}catch{}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let t=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(t,e);return}let r;try{r=this.transport.send(e.slice());}catch(s){this.failConnection(t,p("transport","Transport send failed",s));return}if(typeof r!="boolean"){this.failConnection(t,new l("transport","Transport send must return a boolean"));return}!r&&this.isCurrent(t)&&this.isOpen&&this.queueFrame(t,e);}queueFrame(e,t){if(t.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new l("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let r=t.slice();this.pendingFrames.push(r),this.queuedBytes+=r.byteLength;}flushPending(){if(!this.isFlushing){this.isFlushing=true;try{for(;this.isOpen&&!this.isDestroyed&&this.pendingFrames.length>0;){let e=this.epoch,t=this.pendingFrames[0],r;try{r=this.transport.send(t.slice());}catch(s){this.failConnection(e,p("transport","Transport send failed",s));return}if(typeof r!="boolean"){this.failConnection(e,new l("transport","Transport send must return a boolean"));return}if(!r||!this.isOpen||this.pendingFrames[0]!==t)return;this.pendingFrames.shift(),this.queuedBytes-=t.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.incoming.length=0,this.incomingBytes=0,this.incomingBusy=false,this.incomingGeneration+=1,this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,t){if(this.connectionStatus===e&&this.isSynced===t)return;this.connectionStatus=e,this.isSynced=t;let r={status:e,synced:t};for(let[s,o]of [...this.statusListeners])if(this.statusListeners.get(s)===o)try{o(r);}catch{}}report(e){for(let[t,r]of [...this.errorListeners])if(this.errorListeners.get(t)===r)try{r(e);}catch{}}};export{ee as a,D as b,l as c,ue as d,de as e,M as f};
@@ -1,3 +0,0 @@
1
- import {J as J$1}from'./chunk-DDNX2Z7E.js';import {a}from'./chunk-O2XFH626.js';var W={bold:false,italic:false,underline:"none",fontSizePt:24,color:"#111827",fontFamily:"Arial"};function D(e,n,r,o){let i=Z(e,n,r,o),a=S(i,"underline");return {bold:S(i,"bold"),italic:S(i,"italic"),underline:a===void 0?void 0:a!=="none",fontSize:S(i,"fontSizePt"),textColor:S(i,"color"),fontFamily:S(i,"fontFamily")}}function de(e,n){return D(e,0,e.length,n)}function J(e,n,r,o){let i=D(e,n,r,o);return {bold:i.bold??o.bold,italic:i.italic??o.italic,underline:i.underline===void 0?o.underline:i.underline?"sng":"none",fontSizePt:i.fontSize??o.fontSizePt,color:i.textColor??o.color,fontFamily:i.fontFamily??o.fontFamily}}function Y(e,n,r,o){return {...J(e,n,r,W),...o}}function me(e,n,r,o){if(n!==r)return null;let i={...Y(e,n,r,o),caps:null},a=s=>[...new Set([...Object.keys(s),...Object.keys(i)])].every(m=>(s[m]??null)===(i[m]??null)),t=0;for(let s of e.paragraphs){let d;for(let m of s.runs){let l=t;if(t+=m.text.length,t!==l){if(n>=l&&n<t)return !a(m.style)||n===l&&d&&!a(d.style)?null:{neighbour:"after",start:l,end:t,paragraphId:s.id};d={style:m.style,start:l,end:t};}}if(n===t&&d&&a(d.style))return {neighbour:"before",start:d.start,end:d.end,paragraphId:s.id};t+=1;}return null}function Z(e,n,r,o){let i=$(e,o);if(i.length===0)return [o];let a=Math.min(n,r),t=Math.max(n,r);if(a===t){let m=i.find(p=>a>=p.start&&a<p.end);return m?[m.style]:[[...i].reverse().find(p=>p.end<=a)?.style??i[0].style]}let s=i.filter(m=>m.end>a&&m.start<t).map(m=>m.style);return s.length>0?s:[[...i].reverse().find(m=>m.end<=a)?.style??i[0].style]}function $(e,n){let r=[],o=0;return e.paragraphs.forEach((i,a)=>{for(let t of i.runs){let s=o;o+=t.text.length,o>s&&r.push({start:s,end:o,style:ee(t.style,n)});}a<e.paragraphs.length-1&&(o+=1);}),r}function ee(e,n){return {bold:e.bold??n.bold,italic:e.italic??n.italic,underline:e.underline??n.underline,fontSizePt:e.fontSizePt??n.fontSizePt,color:e.color??n.color,fontFamily:e.fontFamily??n.fontFamily}}function S(e,n){let r=e[0]?.[n];return e.every(o=>o[n]===r)?r:void 0}var le=["insertTableRow","deleteTableRow","insertTableColumn","deleteTableColumn","setShapeFill","setShapeStroke","setShapeAdjust","removeShape","bringShapeToFront","sendShapeToBack","bringShapeForward","sendShapeBackward","insertSlide","deleteSlide","moveSlide","setSlideNotes","addComment","replyToComment","setCommentStatus","setCommentPosition","removeComment","setCommentFlavor","propose","acceptProposal","rejectProposal"],ue=Object.freeze({setChangeObserver:"mode",invoke:"local-write",applyRemoteUpdate:"remote-update",collabPipe:"remote-update",applyEdits:"local-write",registerFont:"local-write",insertTextBox:"local-write",insertShape:"local-write",insertPicture:"local-write",moveShape:"local-write",setShapeRect:"local-write",undo:"local-write",redo:"local-write",insertText:"local-write",replaceText:"local-write",formatText:"local-write",setParagraphAlignment:"local-write",deleteBackward:"local-write",deleteForward:"local-write",paragraphBreak:"local-write",compositionStart:"local-write",compositionCommit:"local-write",activateSlide:"view",selectObject:"view",moveSelection:"view",selectAtPoint:"view",setSelection:"view",compositionEnd:"view",setReadOnly:"mode"}),N=class extends Error{constructor(r,o){super(o);a(this,"seq",r);a(this,"refusal");this.name="CommandOutcomeUnknown",this.refusal={seq:r,reason:"unknown-outcome"};}},ce={openCommandEditor:true,command:true,thumbnailFrame:true,flushCommandEditor:true,saveCommandEditor:true,readEditor:true,prepareCommandPicture:true,accessCommandEditor:true,checkpointCommandEditor:true};function g(e,n){return (e[n]?.columnOffset??0)-(e[0]?.columnOffset??0)}var I,G;function Pe(e,n,r){return r==="word"?ne(e,n):te(e,n)}function ne(e,n){let r=M(e,n);I??(I=new Intl.Segmenter(void 0,{granularity:"word"}));let o=[...I.segment(e)],i=o.find(a=>r>=a.index&&r<a.index+a.segment.length)??o[o.length-1];return i?{start:i.index,end:i.index+i.segment.length}:{start:r,end:r}}function te(e,n){let r=M(e,n),o=e.lastIndexOf(`
2
- `,Math.max(0,r-1))+1,i=e.indexOf(`
3
- `,r);return {start:o,end:i===-1?e.length:i}}function Se(e,n){return n.start<e.start?{anchor:e.end,focus:n.start}:n.end>e.end?{anchor:e.start,focus:n.end}:{anchor:e.start,focus:e.end}}function M(e,n){return Number.isFinite(n)?Math.max(0,Math.min(e.length,Math.trunc(n))):0}function oe(e,n){let o=e[A(e,n)]?.caretStops.find(i=>i.position===n.position)?.x;return o===void 0?void 0:o-g(e,A(e,n))}function H(e,n,r,o){if(e.length===0)return {position:n.position,lineIndex:0};let i=A(e,n),a=i+(r==="up"?-1:1),t=e[a];if(!t)return {position:n.position,lineIndex:i};let s=o??oe(e,n),d=s===void 0?void 0:s+g(e,a);return d===void 0?{position:t.start,lineIndex:a}:{position:t.caretStops.reduce((l,p)=>l===null||Math.abs(p.x-d)<Math.abs(l.x-d)?p:l,null)?.position??t.start,lineIndex:a}}function z(e,n,r){let o=M(e,n);I??(I=new Intl.Segmenter(void 0,{granularity:"word"}));let i=[...I.segment(e)].filter(t=>t.isWordLike).flatMap(t=>[t.index,t.index+t.segment.length]),a=r<0?i.filter(t=>t<o):i.filter(t=>t>o);return a.length===0?r<0?0:e.length:r<0?Math.max(...a):Math.min(...a)}function A(e,n){let r=n.lineIndex;if(r!==void 0&&r>=0&&r<e.length&&n.position>=e[r].start&&n.position<=e[r].end)return r;let o=-1;for(let i=0;i<e.length;i+=1){let a=e[i];n.position>=a.start&&n.position<=a.end&&(o=i);}return o===-1?Math.max(0,e.length-1):o}function K(e){return G??(G=new Intl.Segmenter(void 0,{granularity:"grapheme"})),new Set([...[...G.segment(e)].map(n=>n.index),e.length])}var j=new WeakMap;function ge(e){let n=j.get(e);return n||(n=JSON.parse(new TextDecoder().decode(e.displayList)),j.set(e,n)),n}function E(e,n){return JSON.stringify([e,n])}function V(e){return e.paragraphs.reduce((n,r)=>n+r.runs.reduce((o,i)=>o+i.text.length,0),Math.max(0,e.paragraphs.length-1))}function Ee(e){let n={hits:[],lines:new Map};function r(o,i,a){for(let t of o){let s=[...i,t];if(t.shapeId&&n.hits.push({primitive:t,transforms:s,clips:a,...t.kind==="textBox"?{textLength:V(t)}:{}}),t.kind==="textBox"&&t.shapeId&&t.storyId){let d=E(t.shapeId,t.storyId),m=n.lines.get(d)??[];for(let l of t.lines)m.push({box:t,line:l,transforms:s});n.lines.set(d,m);}else (t.kind==="chart"||t.kind==="table")&&r(t.primitives,s,[...a,t]);}}return r(e.primitives,[],[]),n}function ke(e){let n={hits:[],lines:new Map,size:{width:e.width,height:e.height}};function r(o,i,a){for(let t of o){let s={kind:t.kind,shapeId:t.shapeId,x:t.x,y:t.y,w:t.w,h:t.h,...t.transform?{transform:{...t.transform}}:{}},d=[...i,s];if(t.shapeId&&n.hits.push({primitive:s,transforms:d,clips:a,...t.kind==="textBox"?{textLength:V(t)}:{}}),t.kind==="textBox"&&t.shapeId&&t.storyId){s.storyId=t.storyId,s.lines=t.lines.map(p=>({columnOffset:p.columnOffset,x:p.x,y:p.y,height:p.height,start:p.start,end:p.end,caretStops:p.caretStops.map(u=>({position:u.position,x:u.x}))}));let m=E(t.shapeId,t.storyId),l=n.lines.get(m)??[];for(let p of s.lines)l.push({line:p});n.lines.set(m,l);}else (t.kind==="chart"||t.kind==="table")&&r(t.primitives,d,[...a,s]);}}return r(e.primitives,[],[]),n}function q(e,n){if(!n||n.kind==="object")return null;let r=e.lines.get(E(n.shapeId,n.storyId))??[];return r.find(({line:o})=>n.focus>=o.start&&(n.focus<o.end||n.focus===o.end&&n.affinity==="upstream"))??r.find(({line:o})=>n.focus>=o.start&&n.focus<=o.end)??r[r.length-1]??null}function _(e,n,r=false){let o=e.x+e.w/2,i=e.y+e.h/2,a=(e.transform?.rotationDeg??0)*Math.PI/180,t=Math.cos(a),s=Math.sin(a),d=n.x-o,m=n.y-i;if(r){let l=d*t+m*s;m=m*t-d*s,d=l;}return e.transform?.flipH&&(d=-d),e.transform?.flipV&&(m=-m),r?{x:o+d,y:i+m}:{x:o+d*t-m*s,y:i+d*s+m*t}}function U(e,n){let r=[{x:n.x,y:n.y},{x:n.x+n.width,y:n.y},{x:n.x,y:n.y+n.height},{x:n.x+n.width,y:n.y+n.height}];for(let a=e.length-1;a>=0;a-=1)for(let t=0;t<r.length;t+=1)r[t]=_(e[a],r[t]);let o=Math.min(...r.map(a=>a.x)),i=Math.min(...r.map(a=>a.y));return {x:o,y:i,width:Math.max(...r.map(a=>a.x))-o,height:Math.max(...r.map(a=>a.y))-i}}function v(e,n){let r=e.caretStops[0];return r?e.caretStops.reduce((o,i)=>Math.abs(i.position-n)<Math.abs(o.position-n)?i:o,r).x:e.x}function Ie(e,n){let r=q(e,n);if(!r||!n)return {caret:null,selectionRects:[]};let o=U(r.transforms,{x:v(r.line,n.focus),y:r.line.y,width:1,height:r.line.height}),i=[],a=Math.min(n.anchor,n.focus),t=Math.max(n.anchor,n.focus);for(let s of e.lines.get(E(n.shapeId,n.storyId))??[]){if(t<=s.line.start||a>=s.line.end)continue;let d=v(s.line,Math.max(a,s.line.start)),m=v(s.line,Math.min(t,s.line.end));i.push(U(s.transforms,{x:Math.min(d,m),y:s.line.y,width:Math.abs(m-d),height:s.line.height}));}return {caret:o,selectionRects:i}}function ve(e,n,r,o){for(let i=e.hits.length-1;i>=0;i-=1){let a=e.hits[i],t=n,s=false;for(let m of a.transforms)if(t=_(m,t,true),a.clips.includes(m)&&!Q(m,t)&&(s=true,!r))break;let d=a.primitive;if(!(r&&(d.shapeId!==r.shapeId||d.storyId!==r.storyId))&&!(!r&&(s||!Q(d,t))||!d.shapeId)){if(!r&&o!==void 0){let m=Math.min(6/o,d.w/3,d.h/3);if(t.x-d.x<=m||d.x+d.w-t.x<=m||t.y-d.y<=m||d.y+d.h-t.y<=m)return {kind:"shape",shapeId:d.shapeId}}if(d.kind==="textBox"&&d.storyId){let m=r||a.clips.some(c=>"kind"in c&&c.kind==="table"),l=d.lines?.some((c,f,C)=>f>0&&(c.columnOffset??0)!==(C[f-1].columnOffset??0)),p=Number.POSITIVE_INFINITY,u=d.lines?.reduce((c,f)=>{if(!m&&(t.y<f.y||t.y>f.y+f.height))return c;let X=(P=>{let T=P.x,R=P.x;for(let L of P.caretStops)T=Math.min(T,L.x),R=Math.max(R,L.x);let B=Math.max(T-t.x,t.x-R,0),F=Math.max(P.y-t.y,t.y-P.y-P.height,0);return l?B*B+F*F:F})(f);return !c||X<p?(p=X,f):c},void 0),y=u?.caretStops[0];if(u&&y){let c=u.caretStops.reduce((f,C)=>Math.abs(C.x-t.x)<Math.abs(f.x-t.x)?C:f,y);return {kind:"text",shapeId:d.shapeId,storyId:d.storyId,position:c.position,affinity:c.position===u.end?"upstream":"downstream"}}}return {kind:"shape",shapeId:d.shapeId}}}return null}function Q(e,n){return n.x>=e.x&&n.x<=e.x+e.w&&n.y>=e.y&&n.y<=e.y+e.h}function re(e,n,r){if(!n||n.kind==="object")return null;let o=s=>"kind"in s&&s.kind==="table",i=e.find(({primitive:s})=>s.kind==="textBox"&&s.shapeId===n.shapeId&&s.storyId===n.storyId)?.clips.filter(o).pop();if(!i)return null;let a=[];for(let{primitive:s,clips:d,textLength:m}of e){let l=s.storyId;s.kind!=="textBox"||!l||s.shapeId!==n.shapeId||d.filter(o).pop()!==i||a.some(p=>p.storyId===l)||a.push({storyId:l,end:m??0});}let t=a[a.findIndex(s=>s.storyId===n.storyId)+(r?-1:1)];return t?{slideId:n.slideId,shapeId:n.shapeId,storyId:t.storyId,anchor:0,focus:t.end,affinity:t.end>0?"upstream":"downstream"}:{...n}}function Te(e,n,r,o,i){if(r==="nextCell"||r==="previousCell")return e.hits?re(e.hits,n,r==="previousCell"):null;let a=q(e,n);if(!a||!n||n.kind==="object")return null;let t=e.lines.get(E(n.shapeId,n.storyId))??[],s=n.focus,d=a,m;if(!o&&n.anchor!==n.focus&&(r==="left"||r==="right"))s=r==="left"?Math.min(n.anchor,n.focus):Math.max(n.anchor,n.focus);else if(r==="wordLeft"||r==="wordRight"){if(i===void 0)return null;s=z(i,s,r==="wordLeft"?-1:1);}else if(r==="storyStart")d=t[0],s=0;else if(r==="storyEnd")d=t[t.length-1],s=i?.length??d.line.end;else if(r==="lineStart"||r==="lineEnd"){let p=a.line.caretStops;if(!p.length)return null;s=r==="lineStart"?p[0].position:p[p.length-1].position;}else if(r==="left"||r==="right"){let u=(i===void 0?t.flatMap(({line:y})=>y.caretStops.map(c=>c.position)):[...K(i)]).filter(y=>r==="left"?y<s:y>s);u.length&&(s=r==="left"?Math.max(...u):Math.min(...u));}else if(r==="up"||r==="down"){let p=t.map(({line:y})=>y);m=n.goalX??v(a.line,s)-g(p,t.indexOf(a));let u=H(p,{position:s,lineIndex:t.indexOf(a)},r,m);d=t[u.lineIndex],s=u.position;}(r==="left"||r==="right"||r==="wordLeft"||r==="wordRight")&&(d=q(e,{...n,focus:s,affinity:r==="left"||r==="wordLeft"?"upstream":"downstream"})??a);let l={...n,anchor:o?n.anchor:s,focus:s,affinity:s===d.line.end?"upstream":"downstream"};return m===void 0?delete l.goalX:l.goalX=m,l}function Fe(){let e=0,n=new Map;function r(o){for(let[i,a]of n)if(a===o)return {version:o,clock:i}}return {get version(){return e},initialize(o){n.set(e,o);},commit(o){n.set(++e,o);},retain(o){let i=new Set(o);for(let[a,t]of n)a!==e&&!i.has(t)&&n.delete(a);},envelope(o,i){let a=n.get(o.basis.version);if(a===void 0)for(a="unretained";r(a);)a+="\0";return {...i,seq:o.seq,basis:{epoch:o.basis.epoch,version:a},...o.afterSeq===void 0?{}:{afterSeq:o.afterSeq},kind:o.kind,payload:o.payload}},ack(o,i){let a=o.frame?{coversThroughSeq:o.frame.coversThroughSeq,revision:o.frame.epoch,payload:o.frame}:void 0;return {session:o.session,incarnation:0,epoch:o.epoch,throughSeq:o.throughSeq,version:e,selection:o.selection,editState:o.editState,outcomes:o.outcomes.map(({committed:t,...s})=>t?s:{...s,committed:false}),...a?{frame:a}:{},pptx:{incarnation:o.incarnation,version:o.version,outcomes:o.outcomes,dirtySlideIds:o.dirtySlideIds,activeSlideId:o.activeSlideId,historyThroughSeq:o.historyThroughSeq,...o.creation?{creation:o.creation}:{},...o.change?{change:o.change}:{},..."mutationResult"in o?{mutationResult:o.mutationResult}:{},...o.updates?{updates:o.updates}:{},...o.editResult?{editResult:o.editResult}:{},...o.fontId!==void 0?{fontId:o.fontId}:{},...o.slides?{slides:o.slides,size:o.size}:{},...i===void 0?{}:{retainedBasis:r(i)}}}},dispose(){n.clear();}}}function we(e){let n=new Map,r=new Set,o=new Map,i=-1;function a(t){if(t.throughSeq<i)return;for(i=t.throughSeq,n.set(t.pptx.version,t.version),r.add(t.pptx.version);r.size>256;)r.delete(r.values().next().value);for(t.frame&&o.set(t.frame.revision,t.pptx.version);o.size>257;)o.delete(o.keys().next().value);let s=new Set([...r,...o.values(),t.pptx.version]);t.pptx.retainedBasis&&(s.add(t.pptx.retainedBasis.version),n.set(t.pptx.retainedBasis.version,t.pptx.retainedBasis.clock));for(let d of n.keys())s.has(d)||n.delete(d);}return a(e),{envelope(t){return {session:t.session,incarnation:e.incarnation,seq:t.seq,basis:{epoch:t.basis.epoch,version:n.get(t.basis.version)??-1},...t.afterSeq===void 0?{}:{afterSeq:t.afterSeq},kind:t.kind,payload:t.payload}},ack(t){return a(t),{session:t.session,incarnation:t.pptx.incarnation,epoch:t.epoch,throughSeq:t.throughSeq,version:t.pptx.version,selection:t.selection,editState:t.editState,outcomes:t.pptx.outcomes,dirtySlideIds:t.pptx.dirtySlideIds,activeSlideId:t.pptx.activeSlideId,historyThroughSeq:t.pptx.historyThroughSeq,...t.pptx.creation?{creation:t.pptx.creation}:{},...t.pptx.change?{change:t.pptx.change}:{},..."mutationResult"in t.pptx?{mutationResult:t.pptx.mutationResult}:{},...t.pptx.updates?{updates:t.pptx.updates}:{},...t.pptx.editResult?{editResult:t.pptx.editResult}:{},...t.pptx.fontId!==void 0?{fontId:t.pptx.fontId}:{},...t.pptx.slides?{slides:t.pptx.slides,size:t.pptx.size}:{},...t.frame?{frame:t.frame.payload}:t.pptx.activeSlideId===null?{frame:null}:{}}}}}var ie="CommandOutcomeUnknown";function Me(e){return x(e)&&typeof e.session=="string"&&h(e.incarnation)&&k(e.seq)&&x(e.basis)&&h(e.basis.epoch)&&b(e.basis.version)&&(e.afterSeq===void 0||k(e.afterSeq))&&(e.expectVersion===void 0||typeof e.expectVersion=="boolean")&&typeof e.kind=="string"&&J$1(e,"payload")&&(e.inputTime===void 0||b(e.inputTime))&&(e.lastInputTime===void 0||b(e.lastInputTime))&&(e.group===void 0||typeof e.group=="string")&&(e.replay===void 0||e.replay===true)}function qe(e){return x(e)&&typeof e.session=="string"&&h(e.incarnation)&&h(e.epoch)&&h(e.throughSeq)&&b(e.version)&&Array.isArray(e.outcomes)&&e.outcomes.every(ae)&&(e.frame===void 0||se(e.frame))&&(e.revisions===void 0||x(e.revisions)&&h(e.revisions.selection)&&h(e.revisions.layout))}function Xe(e){return e instanceof Error&&e.name===ie&&x(e)&&x(e.refusal)&&k(e.refusal.seq)}function x(e){return e!==null&&typeof e=="object"}function b(e){return typeof e=="number"&&Number.isFinite(e)}function h(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0}function k(e){return h(e)&&e>0}function ae(e){return x(e)&&k(e.seq)&&(e.status==="applied"||e.status==="noop"||e.status==="refused"||e.status==="cancelled"||e.status==="duplicate")&&(e.reason===void 0||typeof e.reason=="string")&&(e.committed===void 0||e.committed===false)&&(e.affectedSeqs===void 0||Array.isArray(e.affectedSeqs)&&e.affectedSeqs.every(k))}function se(e){return x(e)&&h(e.coversThroughSeq)&&b(e.revision)&&(e.baseRevision===void 0||b(e.baseRevision))&&J$1(e,"payload")}export{W as a,D as b,de as c,J as d,me as e,Me as f,qe as g,Xe as h,Fe as i,we as j,le as k,ue as l,N as m,ce as n,Pe as o,Se as p,K as q,ge as r,Ee as s,ke as t,q as u,U as v,Ie as w,ve as x,Te as y};