@betteroffice/pptx 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/generated/pptx_wasm_bg.wasm +0 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +1 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -46,7 +46,9 @@ and registered with the Rust shaper through `openPresentation`.
|
|
|
46
46
|
Beyond rendering, `PresentationHandle` covers editing: text
|
|
47
47
|
(`insertText` / `deleteText` / `formatText`), slides
|
|
48
48
|
(`insertSlide` / `deleteSlide` / `moveSlide`), shapes
|
|
49
|
-
(`addTextBox` / `moveShape` / `resizeShape`), `hitTest`,
|
|
49
|
+
(`addTextBox` / `moveShape` / `resizeShape`), `hitTest`, undo/redo, and
|
|
50
|
+
`save()`, which serializes the deck back to `.pptx` bytes with edits applied —
|
|
51
|
+
untouched slides keep their exact source part bytes.
|
|
50
52
|
|
|
51
53
|
## Collaboration
|
|
52
54
|
|
|
@@ -71,7 +73,8 @@ provider.connect();
|
|
|
71
73
|
## Development
|
|
72
74
|
|
|
73
75
|
The generated `.wasm` binary is intentionally not committed. From the repository
|
|
74
|
-
root, install `wasm-pack` 0.15.0 and
|
|
76
|
+
root, install `wasm-pack` 0.15.0 and `binaryen`, then run
|
|
77
|
+
`bun scripts/build-pptx-wasm.ts`.
|
|
75
78
|
Package builds copy the binary into `dist/generated`.
|
|
76
79
|
|
|
77
80
|
Docs: https://betteroffice.dev · Apache-2.0.
|
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -292,7 +292,15 @@ interface PlaceholderPrimitive extends PrimitiveBase {
|
|
|
292
292
|
name: string;
|
|
293
293
|
label?: string;
|
|
294
294
|
}
|
|
295
|
-
|
|
295
|
+
/** A plotted chart. Its parts paint clipped to the chart rectangle, and
|
|
296
|
+
* `label` is the screen-reader summary of the whole chart. */
|
|
297
|
+
interface ChartPrimitive extends PrimitiveBase {
|
|
298
|
+
kind: 'chart';
|
|
299
|
+
name: string;
|
|
300
|
+
label: string;
|
|
301
|
+
primitives: SlidePrimitive[];
|
|
302
|
+
}
|
|
303
|
+
type SlidePrimitive = ShapePrimitive | ImagePrimitive | TextBoxPrimitive | PlaceholderPrimitive | ChartPrimitive;
|
|
296
304
|
interface SlideDisplayList {
|
|
297
305
|
contractVersion: number;
|
|
298
306
|
width: number;
|
|
@@ -488,6 +496,12 @@ type WasmInitInput = InitInput | Promise<InitInput>;
|
|
|
488
496
|
interface OpenPresentationOptions {
|
|
489
497
|
clientId?: number;
|
|
490
498
|
fonts?: ReadonlyArray<PptxFontFace>;
|
|
499
|
+
/**
|
|
500
|
+
* Opens from a collaboration update instead of parsing the file bytes.
|
|
501
|
+
* When the bytes are the file the update was seeded from, the session
|
|
502
|
+
* keeps them and `save()` works; any other bytes open without a source
|
|
503
|
+
* and `save()` throws.
|
|
504
|
+
*/
|
|
491
505
|
initialUpdate?: Uint8Array;
|
|
492
506
|
}
|
|
493
507
|
interface PresentationHandle extends CollaborationReplica {
|
|
@@ -498,6 +512,8 @@ interface PresentationHandle extends CollaborationReplica {
|
|
|
498
512
|
layoutSlide(slideIndex: number): SlideDisplayList;
|
|
499
513
|
hitTest(x: number, y: number): HitTestResult | null;
|
|
500
514
|
mediaBytes(partPath: string): Uint8Array;
|
|
515
|
+
/** serialize the presentation back to .pptx bytes, edits included. */
|
|
516
|
+
save(): Uint8Array;
|
|
501
517
|
insertText(storyId: string, index: number, text: string, style?: TextStyle): TextReceipt;
|
|
502
518
|
deleteText(storyId: string, start: number, end: number): TextReceipt;
|
|
503
519
|
formatText(storyId: string, start: number, end: number, patch: TextStylePatch): TextReceipt;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ze=Object.defineProperty;var We=(r,e,t)=>e in r?ze(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var u=(r,e,t)=>We(r,typeof e!="symbol"?e+"":e,t);function je(r,e,t,n=1){r.width=Math.round(e.width*n*t),r.height=Math.round(e.height*n*t),r.style.width=`${e.width*n}px`,r.style.height=`${e.height*n}px`;}async function $e(r,e,t=1,n=1,s={}){r.save();try{r.setTransform(t*n,0,0,t*n,0,0),r.clearRect(0,0,e.width,e.height),e.background&&(r.fillStyle=le(r,e.background,0,0,e.width,e.height),r.fillRect(0,0,e.width,e.height));for(let i of e.primitives)await qe(r,i,s);}finally{r.restore();}}async function qe(r,e,t){r.save();try{switch(Xe(r,e),e.kind){case "shape":Ge(r,e);break;case "image":await Ye(r,e,t.resolveImage);break;case "textBox":Ke(r,e);break;case "placeholder":et(r,e);break}}finally{r.restore();}}function Xe(r,e){let t=e.transform;if(!t)return;let n=e.x+e.w/2,s=e.y+e.h/2;r.translate(n,s),r.rotate((t.rotationDeg??0)*Math.PI/180),r.scale(t.flipH?-1:1,t.flipV?-1:1),r.translate(-n,-s);}function Ge(r,e){He(r,e.path,e.x,e.y,e.w,e.h),e.fill&&(r.fillStyle=le(r,e.fill,e.x,e.y,e.w,e.h),r.fill()),e.stroke&&ce(r,e.stroke);}function He(r,e,t,n,s,i){r.beginPath();for(let c of e)switch(c.type){case "move":r.moveTo(t+c.x*s,n+c.y*i);break;case "line":r.lineTo(t+c.x*s,n+c.y*i);break;case "quad":r.quadraticCurveTo(t+c.cpx*s,n+c.cpy*i,t+c.x*s,n+c.y*i);break;case "cubic":r.bezierCurveTo(t+c.cp1x*s,n+c.cp1y*i,t+c.cp2x*s,n+c.cp2y*i,t+c.x*s,n+c.y*i);break;case "close":r.closePath();break}}function ce(r,e){r.strokeStyle=e.color,r.lineWidth=e.width,r.setLineDash(e.dashed?[Math.max(3,e.width*2),Math.max(2,e.width)]:[]),r.stroke();}function le(r,e,t,n,s,i){if(e.kind==="solid")return e.color;let c=(e.angleDeg??0)*Math.PI/180,l=t+s/2,a=n+i/2,w=Math.hypot(s,i)/2,v=e.gradientType==="linear"?r.createLinearGradient(l-Math.cos(c)*w,a-Math.sin(c)*w,l+Math.cos(c)*w,a+Math.sin(c)*w):r.createRadialGradient(l,a,0,l,a,w);for(let I of e.stops)v.addColorStop(Math.max(0,Math.min(1,I.position)),I.color);return v}async function Ye(r,e,t){if(e.assetId&&t){let n=await t(e.assetId);n&&r.drawImage(n,e.x,e.y,e.w,e.h);}e.stroke&&(r.beginPath(),r.rect(e.x,e.y,e.w,e.h),ce(r,e.stroke));}function Ke(r,e){r.beginPath(),r.rect(e.x,e.y,e.w,e.h),r.clip(),r.textAlign="left",r.textBaseline="alphabetic";for(let t of e.lines)for(let n of t.runs)Qe(r,n,t.baseline);}function Qe(r,e,t){let n=e.italic?"italic ":"",s=e.bold?"bold ":"";r.font=`${n}${s}${e.fontSizePx}px ${Ze(e.fontFamily)}`,r.fillStyle=e.color,r.fillText(e.text,e.x,t),e.underline&&r.fillRect(e.x,t+e.fontSizePx*.08,e.width,Math.max(1,e.fontSizePx*.05));}function Ze(r){return r.includes(" ")?JSON.stringify(r):r}function et(r,e){r.strokeStyle="#8a94a6",r.lineWidth=1,r.setLineDash([5,4]),r.strokeRect(e.x,e.y,e.w,e.h),e.label&&(r.setLineDash([]),r.fillStyle="#5d6675",r.font="12px sans-serif",r.textAlign="center",r.textBaseline="middle",r.fillText(e.label,e.x+e.w/2,e.y+e.h/2,Math.max(0,e.w-12)));}var pe=3e3;var de=["#B3261E","#7B1FA2","#3949AB","#00796B","#2E7D32","#A84400","#C2185B","#00695C"],tt=/^#[0-9a-fA-F]+$/;function G(r){return de[Math.abs(r)%de.length]}function H(r,e){return typeof e=="string"&&(e.length===4||e.length===7)&&tt.test(e)?e:G(r)}function ue(r,e){if(e&&(typeof e.name!="string"||e.name.trim().length===0))throw new TypeError("Collaboration user name must be a non-empty string");if(e?.color!==void 0&&typeof e.color!="string")throw new TypeError("Collaboration user color must be a string");let t=e?.name.trim().slice(0,1024)||`Guest ${r.toString(36).toUpperCase()}`,n=H(r,e?.color);return {name:t,color:n}}function Y(r,e){return r?.slideId===e?.slideId&&r?.shapeId===e?.shapeId}var W=class{constructor(e,t={}){u(this,"localClientId",e);u(this,"states",new Map);u(this,"clocks",new Map);u(this,"maxTrackedIds");if(this.maxTrackedIds=t.maxTrackedIds??4096,!Number.isSafeInteger(this.maxTrackedIds)||this.maxTrackedIds<1)throw new RangeError("Presence tracked id limit must be a positive integer")}get peers(){return [...this.states.values()].sort((e,t)=>e.state.clientId-t.state.clientId).map(rt)}get trackedIdCount(){return this.clocks.size}get nextExpiryAt(){let e;for(let t of this.states.values()){let n=t.lastSeen+45e3;e=e===void 0?n:Math.min(e,n);}for(let t of this.clocks.values()){let n=t.updatedAt+3e5;e=e===void 0?n:Math.min(e,n);}return e}apply(e,t){let n=this.expire(t);for(let s of e){if(s.clientId===this.localClientId)continue;let i=this.clocks.get(s.clientId);if(i&&s.clock<=i.clock)continue;if(!i&&this.clocks.size>=this.maxTrackedIds&&(n=this.evictOldest()||n),this.clocks.delete(s.clientId),this.clocks.set(s.clientId,{clock:s.clock,updatedAt:t}),!s.state){n=this.states.delete(s.clientId)||n;continue}let c=this.states.get(s.clientId),l=c&&Y(c.state.cursor,s.state.cursor)?c.cursorMovedAt:t;this.states.set(s.clientId,{state:fe(s.state),lastSeen:t,cursorMovedAt:l}),n=true;}return n}expire(e,t=45e3){let n=false;for(let[s,i]of this.states)e-i.lastSeen<t||(this.states.delete(s),n=true);for(let[s,i]of this.clocks)e-i.updatedAt<3e5||(this.clocks.delete(s),n=this.states.delete(s)||n);return n}clear(){let e=this.states.size>0;return this.states.clear(),this.clocks.clear(),e}evictOldest(){let e=this.clocks.keys().next();return e.done?false:(this.clocks.delete(e.value),this.states.delete(e.value))}};function fe(r){return {clientId:r.clientId,clock:r.clock,user:{...r.user},cursor:r.cursor?{...r.cursor}:null}}function rt(r){return {state:fe(r.state),lastSeen:r.lastSeen,cursorMovedAt:r.cursorMovedAt}}var A=16777216,O=4096,_e=0,ye=1,st=2,be=3,me=0,ge=1,we=2,it=0,ot=Number.MAX_SAFE_INTEGER,f=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},j=class{constructor(e){u(this,"bytes",e);u(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,t=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new f("Truncated varUint");let s=this.bytes[this.offset++],i=s&127;if(i>Math.floor((ot-e)/t))throw new f("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=i*t,n+=1,(s&128)===0){if(n>1&&i===0)throw new f("Non-canonical varUint");return e}if(n>=8)throw new f("varUint exceeds Number.MAX_SAFE_INTEGER");t*=128;}}readVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new f("Truncated varUint8Array");let n=this.bytes.slice(this.offset,this.offset+e);return this.offset+=e,n}readVarString(){let e=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch(t){throw new f(`Invalid UTF-8 string${t instanceof Error?`: ${t.message}`:""}`)}}};function T(r){if(!Number.isSafeInteger(r)||r<0)throw new f("varUint value must be a non-negative safe integer");let e=[],t=r;for(;t>=128;)e.push(t%128|128),t=Math.floor(t/128);return e.push(t),Uint8Array.from(e)}function at(r){let e=new TextEncoder().encode(r);return D([T(e.byteLength),e],A)}function D(r,e){let t=0;for(let i of r)if(t+=i.byteLength,t>e)throw new f(`Frame exceeds ${e} bytes`);let n=new Uint8Array(t),s=0;for(let i of r)n.set(i,s),s+=i.byteLength;return n}function Z(r,e,t){return D([T(_e),T(r),T(e.byteLength),e],t)}function Se(r,e=A){return Z(me,r,e)}function xe(r,e=A){return Z(ge,r,e)}function Pe(r,e=A){return Z(we,r,e)}function ve(r,e=A){if(r.length>O)throw new f(`Awareness update exceeds ${O} entries`);let t=[T(r.length)];for(let s of r){Ue(s);let i=JSON.stringify(s.state);if(i===void 0)throw new f("Awareness state is not JSON serializable");t.push(T(s.clientId),T(s.clock),at(i));}let n=D(t,e);return D([T(ye),T(n.byteLength),n],e)}function Ce(r=A){return D([T(be)],r)}function Te(r,e=O){if(!(r instanceof Uint8Array))throw new f("Awareness update must be a Uint8Array");if(!Number.isSafeInteger(e)||e<1)throw new f("Awareness entry limit must be a positive integer");let t=new j(r),n=t.readVarUint();if(n>e)throw new f(`Awareness update exceeds ${e} entries`);let s=[];for(let i=0;i<n;i+=1){let c=t.readVarUint(),l=t.readVarUint(),a;try{a=JSON.parse(t.readVarString());}catch(v){throw v instanceof f?v:new f(`Invalid awareness JSON${v instanceof Error?`: ${v.message}`:""}`)}let w={clientId:c,clock:l,state:Ee(a,c,l)};Ue(w),s.push(w);}if(!t.done)throw new f("Awareness update has trailing bytes");return s}function Ae(r,e=A,t=O){if(!(r instanceof Uint8Array))throw new f("Frame must be a Uint8Array");if(r.byteLength===0)throw new f("Frame is empty");if(r.byteLength>e)throw new f(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(t)||t<1)throw new f("Message limit must be a positive integer");let n=new j(r),s=[];for(;!n.done;){if(s.length>=t)throw new f(`Frame exceeds ${t} messages`);let i=n.readVarUint();switch(i){case _e:{let c=n.readVarUint(),l=n.readVarUint8Array();if(c===me)s.push({type:"sync-step-1",stateVector:l});else if(c===ge)s.push({type:"sync-step-2",update:l});else if(c===we)s.push({type:"update",update:l});else throw new f(`Unknown sync message type ${c}`);break}case ye:s.push({type:"awareness",update:n.readVarUint8Array()});break;case st:{let c=n.readVarUint();if(c!==it)throw new f(`Unknown auth message type ${c}`);s.push({type:"auth",reason:n.readVarString()});break}case be:s.push({type:"query-awareness"});break;default:throw new f(`Unknown top-level message type ${i}`)}}return s}function Ee(r,e,t){if(r===null)return null;if(!Q(r))throw new f("Awareness state must be an object or null");if(r.clientId!==e||r.clock!==t)throw new f("Awareness state identity does not match its entry");if(!Q(r.user))throw new f("Awareness user must be an object");let n=K(r.user.name,"Awareness user name"),s=H(e,r.user.color);return {clientId:e,clock:t,user:{name:n,color:s},cursor:ct(r.cursor)}}function ct(r){if(r==null)return null;if(!Q(r))throw new f("Awareness cursor must be an object or null");let e=K(r.slideId,"Awareness slideId"),t=r.shapeId===void 0?void 0:K(r.shapeId,"Awareness shapeId");return t?{slideId:e,shapeId:t}:{slideId:e}}function Ue(r){he(r.clientId,"Awareness clientId"),he(r.clock,"Awareness clock"),r.state!==null&&Ee(r.state,r.clientId,r.clock);}function he(r,e){if(!Number.isSafeInteger(r)||r<0)throw new f(`${e} must be a non-negative safe integer`)}function K(r,e){if(typeof r!="string"||r.length===0||r.length>1024)throw new f(`${e} must be between 1 and ${1024} characters`);return r}function Q(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}var x=class extends Error{constructor(t,n,s){super(n);u(this,"code");u(this,"cause");this.name="CollaborationError",this.code=t,this.cause=s;}};var pt=16*1024*1024;function ee(r,e,t){if(!Number.isSafeInteger(e)||e<(t?0:1))throw new RangeError(`${r} must be ${t?"a non-negative":"a positive"} integer`);return e}function ut(r){return r instanceof Error&&r.message?r.message:typeof r=="string"&&r?r:"Unknown error"}function m(r,e,t){return t instanceof x?t:new x(r,`${e}: ${ut(t)}`,t)}function te(r,e){if(!(r instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return r.slice()}function re(r){typeof r=="object"&&r&&"unref"in r&&r.unref();}function ft(r){if(!Number.isSafeInteger(r)||r<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return r}function ht(r){if(r===null)return null;if(!r||typeof r.slideId!="string"||r.slideId.length===0)throw new TypeError("Presence cursor slideId must be a non-empty string");if(r.shapeId!==void 0&&(typeof r.shapeId!="string"||r.shapeId.length===0))throw new TypeError("Presence cursor shapeId must be a non-empty string");return r.shapeId?{slideId:r.slideId,shapeId:r.shapeId}:{slideId:r.slideId}}function _t(r){return r.slideId.length<=1024&&(r.shapeId===void 0||r.shapeId.length<=1024)}var $=class{constructor(e,t,n={}){u(this,"replica");u(this,"transport");u(this,"maxFrameBytes");u(this,"maxMessagesPerFrame");u(this,"maxPendingBytes");u(this,"localClientId");u(this,"localUser");u(this,"remotePresence");u(this,"statusListeners",new Map);u(this,"errorListeners",new Map);u(this,"presenceListeners",new Map);u(this,"pendingFrames",[]);u(this,"unsubscribeReplica");u(this,"unsubscribeTransport",()=>{});u(this,"hasTransportSubscription",false);u(this,"connectionStatus","disconnected");u(this,"isSynced",false);u(this,"wantsConnection",false);u(this,"isOpen",false);u(this,"isDestroyed",false);u(this,"epoch",0);u(this,"connectAttempt",0);u(this,"nextListenerId",0);u(this,"queuedBytes",0);u(this,"isFlushing",false);u(this,"localClock",0);u(this,"reportedClockExhaustion",false);u(this,"localCursor",null);u(this,"lastAwarenessSentAt",0);u(this,"cursorTimer",null);u(this,"heartbeatTimer",null);u(this,"expiryTimer",null);this.replica=e,this.transport=t,this.localClientId=ft(e.clientId),this.localUser=ue(this.localClientId,n.user),this.remotePresence=new W(this.localClientId),this.maxFrameBytes=ee("maxFrameBytes",n.maxFrameBytes??A,false),this.maxMessagesPerFrame=ee("maxMessagesPerFrame",n.maxMessagesPerFrame??O,false),this.maxPendingBytes=ee("maxPendingBytes",n.maxPendingBytes??pt,true);try{this.unsubscribeReplica=e.onUpdate((s,i)=>{i==="local"&&this.forwardLocalUpdate(s);});}catch(s){throw m("replica","Failed to observe replica updates",s)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}get peers(){return this.remotePresence.peers}setCursor(e){if(this.isDestroyed)return;let t=ht(e),n=!t||_t(t)?t:null;t&&!n&&this.report(new x("protocol",`Presence cursor identifiers exceed ${1024} characters; cursor dropped`)),!Y(this.localCursor,n)&&(this.localCursor=n,this.isOpen&&this.wantsConnection&&this.scheduleCursorBroadcast());}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 n;try{if(n=this.transport.onEvent(s=>this.handleTransportEvent(e,s)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(s){this.failConnection(e,m("transport","Failed to subscribe to transport events",s));return}if(!this.isCurrent(e)){try{n();}catch(s){this.isDestroyed||this.report(m("transport","Failed to unsubscribe from stale transport events",s));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(s=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,m("transport","Transport connect failed",s));});}catch(n){this.failConnection(e,m("transport","Transport connect failed",n));}}}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 n=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let s of n)this.report(s);}destroy(){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 n=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let s of n)this.report(s);try{this.unsubscribeReplica();}catch(s){this.report(m("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");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");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");let t=this.nextListenerId++;this.presenceListeners.set(t,e);try{e(this.peers);}catch{}return ()=>this.presenceListeners.delete(t)}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 n=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let s=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(t);for(let i of s)this.report(i);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let n=[];try{e();}catch(s){n.push(m("transport","Failed to unsubscribe from transport events",s));}if(!t)return n;try{let s=this.transport.disconnect();s&&s.catch(i=>{this.isDestroyed||this.report(m("transport","Transport disconnect failed",i));});}catch(s){n.push(m("transport","Transport disconnect failed",s));}return n}handleTransportEvent(e,t){if(this.isCurrent(e))switch(t.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(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,m("transport","Transport error",t.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new x("transport","Unknown transport event"));}}handleOpen(e){if(this.isOpen||(this.isOpen=true,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(e)||!this.isOpen))return;let t;try{t=te(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,m("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(Se(t,this.maxFrameBytes));}catch(n){this.failConnection(e,m("protocol","Failed to encode SyncStep1",n));return}if(!(!this.isCurrent(e)||!this.isOpen)&&(this.startPresenceTimers(),this.broadcastLocalPresence(false),!(!this.isCurrent(e)||!this.isOpen)))try{this.sendFrame(Ce(this.maxFrameBytes));}catch(n){this.report(m("protocol","Failed to encode awareness query",n));}}handleMessage(e,t){let n;try{n=Ae(t.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(s){this.failConnection(e,m("protocol","Invalid collaboration frame",s));return}for(let s of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(s.type){case "sync-step-1":this.respondToSyncStep1(e,s.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,s.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,s.update);break;case "awareness":{try{let i=Te(s.update,this.maxMessagesPerFrame);this.remotePresence.apply(i,Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();}catch(i){this.report(m("protocol","Invalid awareness update",i));}break}case "auth":this.failConnection(e,new x("protocol",s.reason?`Authentication denied: ${s.reason}`:"Authentication denied"));return;case "query-awareness":this.broadcastLocalPresence(false);break}}}respondToSyncStep1(e,t){let n;try{n=te(this.replica.encodeStateAsUpdate(t.slice()),"encodeStateAsUpdate");}catch(s){this.failConnection(e,m("replica","Failed to encode replica update",s));return}try{this.sendFrame(xe(n,this.maxFrameBytes));}catch(s){this.failConnection(e,m("protocol","Failed to encode SyncStep2",s));}}applyRemoteUpdate(e,t){try{return this.replica.applyUpdate(t.slice()),!0}catch(n){return this.failConnection(e,m("replica","Failed to apply remote update",n)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let t=this.epoch,n;try{n=te(e,"Replica update");}catch(s){this.failConnection(t,m("replica","Invalid replica update",s));return}try{this.sendFrame(Pe(n,this.maxFrameBytes));}catch(s){this.failConnection(t,m("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),re(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 x("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}this.localClock+=1;let t=this.localClock,n=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=ve([{clientId:this.localClientId,clock:t,state:n}],this.maxFrameBytes);e?this.sendLeaveFrameBestEffort(s):this.sendFrame(s);}catch(s){this.report(m("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),re(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())),re(this.expiryTimer));}clearRemotePresence(){this.remotePresence.clear()&&this.emitPresence();}emitPresence(){let e=this.peers;for(let[t,n]of [...this.presenceListeners])if(this.presenceListeners.get(t)===n)try{n(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 n;try{n=this.transport.send(e.slice());}catch(s){this.failConnection(t,m("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(t,new x("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(t)&&this.isOpen&&this.queueFrame(t,e);}queueFrame(e,t){if(t.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new x("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=t.slice();this.pendingFrames.push(n),this.queuedBytes+=n.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],n;try{n=this.transport.send(t.slice());}catch(s){this.failConnection(e,m("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(e,new x("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==t)return;this.pendingFrames.shift(),this.queuedBytes-=t.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){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 n={status:e,synced:t};for(let[s,i]of [...this.statusListeners])if(this.statusListeners.get(s)===i)try{i(n);}catch{}}report(e){for(let[t,n]of [...this.errorListeners])if(this.errorListeners.get(t)===n)try{n(e);}catch{}}};var U=class r{static __wrap(e){let t=Object.create(r.prototype);return t.__wbg_ptr=e,Re.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Re.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_pptxdocument_free(e,0);}addShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_addShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}addTextBoxJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_addTextBoxJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}applyUpdateJson(e){let t,n;try{let c=F(e,o.__wbindgen_malloc),l=_,a=o.pptxdocument_applyUpdateJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}canRedo(){return o.pptxdocument_canRedo(this.__wbg_ptr)!==0}canUndo(){return o.pptxdocument_canUndo(this.__wbg_ptr)!==0}clearUpdateObservation(){o.pptxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return o.pptxdocument_clientId(this.__wbg_ptr)}deleteSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_deleteSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}deleteTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_deleteTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}drainUpdateEvent(){let e=o.pptxdocument_drainUpdateEvent(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}encodeDiff(e){let t=F(e,o.__wbindgen_malloc),n=_,s=o.pptxdocument_encodeDiff(this.__wbg_ptr,t,n);if(s[3])throw h(s[2]);var i=E(s[0],s[1]).slice();return o.__wbindgen_free(s[0],s[1]*1,1),i}encodeStateAsUpdate(){let e=o.pptxdocument_encodeStateAsUpdate(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}encodeStateVector(){let e=o.pptxdocument_encodeStateVector(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}formatTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_formatTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertParagraphBreakJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertParagraphBreakJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}mediaBytes(e){let t=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),n=_,s=o.pptxdocument_mediaBytes(this.__wbg_ptr,t,n);if(s[3])throw h(s[2]);var i=E(s[0],s[1]).slice();return o.__wbindgen_free(s[0],s[1]*1,1),i}moveShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_moveShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}moveSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_moveSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}static openCollaborative(e,t){let n=F(e,o.__wbindgen_malloc),s=_,i=o.pptxdocument_openCollaborative(n,s,t);if(i[2])throw h(i[1]);return r.__wrap(i[0])}static openCollaborativeFromUpdate(e,t){let n=F(e,o.__wbindgen_malloc),s=_,i=o.pptxdocument_openCollaborativeFromUpdate(n,s,t);if(i[2])throw h(i[1]);return r.__wrap(i[0])}redoJson(){let e,t;try{let i=o.pptxdocument_redoJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}removeShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_removeShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}resizeShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_resizeShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeAdjustJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeAdjustJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeFillJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeFillJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeStrokeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeStrokeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}snapshotJson(){let e,t;try{let i=o.pptxdocument_snapshotJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}startUpdateObservation(){let e=o.pptxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw h(e[0])}storyJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_storyJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}undoJson(){let e,t;try{let i=o.pptxdocument_undoJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}static version(){let e,t;try{let n=o.pptxdocument_version();return e=n[0],t=n[1],y(n[0],n[1])}finally{o.__wbindgen_free(e,t,1);}}};Symbol.dispose&&(U.prototype[Symbol.dispose]=U.prototype.free);var M=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ie.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_pptxrenderer_free(e,0);}hitTestJson(e,t){let n,s;try{let l=o.pptxrenderer_hitTestJson(this.__wbg_ptr,e,t);var i=l[0],c=l[1];if(l[3])throw i=0,c=0,h(l[2]);return n=i,s=c,y(i,c)}finally{o.__wbindgen_free(n,s,1);}}layoutSlideJson(e,t){let n,s;try{mt(e,U);let l=o.pptxrenderer_layoutSlideJson(this.__wbg_ptr,e.__wbg_ptr,t);var i=l[0],c=l[1];if(l[3])throw i=0,c=0,h(l[2]);return n=i,s=c,y(i,c)}finally{o.__wbindgen_free(n,s,1);}}constructor(){let e=o.pptxrenderer_new();return this.__wbg_ptr=e,Ie.register(this,this.__wbg_ptr,this),this}registerFont(e,t,n,s){let i=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_,l=F(s,o.__wbindgen_malloc),a=_,w=o.pptxrenderer_registerFont(this.__wbg_ptr,i,c,t,n,l,a);if(w[2])throw h(w[1]);return w[0]>>>0}};Symbol.dispose&&(M.prototype[Symbol.dispose]=M.prototype.free);function Oe(r){let e,t;try{let i=F(r,o.__wbindgen_malloc),c=_,l=o.parsePptxJson(i,c);var n=l[0],s=l[1];if(l[3])throw n=0,s=0,h(l[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}function Fe(){let r,e;try{let t=o.rendererVersion();return r=t[0],e=t[1],y(t[0],t[1])}finally{o.__wbindgen_free(r,e,1);}}function yt(){return {__proto__:null,"./pptx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_string_get_b0ca35b86a603356:function(e,t){let n=t,s=typeof n=="string"?n:void 0;var i=gt(s)?0:S(s,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_;ke().setInt32(e+4,c,true),ke().setInt32(e+0,i,true);},__wbg___wbindgen_throw_344f42d3211c4765:function(e,t){throw new Error(y(e,t))},__wbg_getRandomValues_3f44b700395062e5:function(){return ne(function(e,t){globalThis.crypto.getRandomValues(E(e,t));},arguments)},__wbg_get_78f252d074a84d0b:function(){return ne(function(e,t){return Reflect.get(e,t)},arguments)},__wbg_get_unchecked_6e0ad6d2a41b06f6:function(e,t){return e[t>>>0]},__wbg_instanceof_Object_33f20e6f12439f3e:function(e){let t;try{t=e instanceof Object;}catch{t=false;}return t},__wbg_keys_58421f8f96795607:function(e){return Object.keys(e)},__wbg_length_1f0964f4a5e2c6d8:function(e){return e.length},__wbg_length_370319915dc99107:function(e){return e.length},__wbg_new_cd45aabdf6073e84:function(e){return new Uint8Array(e)},__wbg_new_da52cf8fe3429cb2:function(){return new Object},__wbg_new_from_slice_77cdfb7977362f3c:function(e,t){return new Uint8Array(E(e,t))},__wbg_prototypesetcall_4770620bbe4688a0:function(e,t,n){Uint8Array.prototype.set.call(E(e,t),n);},__wbg_set_8535240470bf2500:function(){return ne(function(e,t,n){return Reflect.set(e,t,n)},arguments)},__wbindgen_cast_0000000000000001:function(e,t){return y(e,t)},__wbindgen_init_externref_table:function(){let e=o.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,true),e.set(t+3,false);}}}}var Re=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxdocument_free(r,1)),Ie=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxrenderer_free(r,1));function bt(r){let e=o.__externref_table_alloc();return o.__wbindgen_externrefs.set(e,r),e}function mt(r,e){if(!(r instanceof e))throw new Error(`expected instance of ${e.name}`)}function E(r,e){return r=r>>>0,L().subarray(r/1,r/1+e)}var R=null;function ke(){return (R===null||R.buffer.detached===true||R.buffer.detached===void 0&&R.buffer!==o.memory.buffer)&&(R=new DataView(o.memory.buffer)),R}function y(r,e){return St(r>>>0,e)}var J=null;function L(){return (J===null||J.byteLength===0)&&(J=new Uint8Array(o.memory.buffer)),J}function ne(r,e){try{return r.apply(this,e)}catch(t){let n=bt(t);o.__wbindgen_exn_store(n);}}function gt(r){return r==null}function F(r,e){let t=e(r.length*1,1)>>>0;return L().set(r,t/1),_=r.length,t}function S(r,e,t){if(t===void 0){let l=B.encode(r),a=e(l.length,1)>>>0;return L().subarray(a,a+l.length).set(l),_=l.length,a}let n=r.length,s=e(n,1)>>>0,i=L(),c=0;for(;c<n;c++){let l=r.charCodeAt(c);if(l>127)break;i[s+c]=l;}if(c!==n){c!==0&&(r=r.slice(c)),s=t(s,n,n=c+r.length*3,1)>>>0;let l=L().subarray(s+c,s+n),a=B.encodeInto(r,l);c+=a.written,s=t(s,n,c,1)>>>0;}return _=c,s}function h(r){let e=o.__wbindgen_externrefs.get(r);return o.__externref_table_dealloc(r),e}var q=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});q.decode();var wt=2146435072,se=0;function St(r,e){return se+=e,se>=wt&&(q=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),q.decode(),se=e),q.decode(L().subarray(r,r+e))}var B=new TextEncoder;"encodeInto"in B||(B.encodeInto=function(r,e){let t=B.encode(r);return e.set(t),{read:r.length,written:t.length}});var _=0,o;function vt(r,e){return o=r.exports,R=null,J=null,o.__wbindgen_start(),o}async function Ct(r,e){if(typeof Response=="function"&&r instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(r,e)}catch(s){if(r.ok&&t(r.type)&&r.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",s);else throw s}let n=await r.arrayBuffer();return await WebAssembly.instantiate(n,e)}else {let n=await WebAssembly.instantiate(r,e);return n instanceof WebAssembly.Instance?{instance:n,module:r}:n}function t(n){switch(n){case "basic":case "cors":case "default":return true}return false}}async function Le(r){if(o!==void 0)return o;if(r!==void 0&&(Object.getPrototypeOf(r)===Object.prototype?{module_or_path:r}=r:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),r===void 0)throw new Error("pptx-wasm requires an explicit module or URL");let e=yt();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:t,module:n}=await Ct(await r,e);return vt(t)}var ie=false,V;function Tt(r=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return ie?Promise.resolve():V||(V=Le({module_or_path:r}).then(()=>{ie=true;},e=>{throw V=void 0,N(e)}),V)}function At(){return typeof WebAssembly=="object"}function Et(){return oe(),Fe()}function Ut(r){return oe(),Ot(()=>Oe(r))}function Rt(r,e={}){oe();let t=e.clientId??It(),n=Ne(()=>e.initialUpdate===void 0?U.openCollaborative(r,t):U.openCollaborativeFromUpdate(e.initialUpdate.slice(),t)),s=Ne(()=>new M);for(let d of e.fonts??[])Me(s,d);let i=new Map,c=[],l=0,a=false,w=false,v=0,I=false,ae=()=>{if(a)throw new Error("presentation handle is disposed")},De=()=>{if(!(a||I||v!==0)){I=true;try{for(;!a&&c.length>0;){let d=c.shift();if(!d)break;for(let[p,b]of [...i]){if(a)return;if(i.get(p)===b)try{b(d.update.slice(),d.origin);}catch{}}}}finally{I=false,a&&(c.length=0);}}},Je=()=>{if(!(!w||a))for(;;){let d=n.drainUpdateEvent();if(d.byteLength===0)return;let p=d[0];if(p!==0&&p!==1)throw new Error(`pptx wasm returned unknown update origin ${p}`);c.push({update:d.slice(1),origin:p===0?"local":"remote"});}},C=(d,p=false)=>{ae(),v+=1;try{let b,P,z=!1;try{b=d();}catch(X){P=X,z=!0;}if(p)try{Je();}catch(X){z||(P=X,z=!0);}if(z)throw N(P);return b}finally{v-=1,v===0&&De();}},g=(d,p=false)=>C(()=>JSON.parse(d()),p),Be=()=>{w||(C(()=>n.startUpdateObservation()),w=true);},Ve=()=>{!w||i.size>0||a||(c.length=0,C(()=>n.clearUpdateObservation()),w=false);};return {get clientId(){return C(()=>n.clientId)},snapshot(){return g(()=>n.snapshotJson())},story(d){return g(()=>n.storyJson(JSON.stringify({storyId:d})))},registerFont(d){return C(()=>Me(s,d))},layoutSlide(d){return g(()=>s.layoutSlideJson(n,d))},hitTest(d,p){return g(()=>s.hitTestJson(d,p))},mediaBytes(d){return C(()=>n.mediaBytes(d).slice())},insertText(d,p,b,P={}){return g(()=>n.insertTextJson(JSON.stringify({storyId:d,index:p,text:b,style:P})),true)},deleteText(d,p,b){return g(()=>n.deleteTextJson(JSON.stringify({storyId:d,start:p,end:b})),true)},formatText(d,p,b,P){return g(()=>n.formatTextJson(JSON.stringify({storyId:d,start:p,end:b,patch:P})),true)},insertParagraphBreak(d,p){return g(()=>n.insertParagraphBreakJson(JSON.stringify({storyId:d,index:p})),true)},insertSlide(d,p){return g(()=>n.insertSlideJson(JSON.stringify({index:d,layoutPartPath:p??null})),true)},deleteSlide(d){return g(()=>n.deleteSlideJson(JSON.stringify({slideId:d})),true)},moveSlide(d,p){return g(()=>n.moveSlideJson(JSON.stringify({slideId:d,toIndex:p})),true)},addTextBox(d,p){return g(()=>n.addTextBoxJson(JSON.stringify({slideId:d,draft:p})),true)},addShape(d,p){return g(()=>n.addShapeJson(JSON.stringify({slideId:d,draft:p})),true)},setShapeFill(d,p,b){return g(()=>n.setShapeFillJson(JSON.stringify({slideId:d,shapeId:p,color:b})),true)},setShapeStroke(d,p,b){return g(()=>n.setShapeStrokeJson(JSON.stringify({slideId:d,shapeId:p,stroke:b})),true)},setShapeAdjust(d,p,b){return g(()=>n.setShapeAdjustJson(JSON.stringify({slideId:d,shapeId:p,adjustments:b})),true)},removeShape(d,p){return g(()=>n.removeShapeJson(JSON.stringify({slideId:d,shapeId:p})),true)},moveShape(d,p,b,P){return g(()=>n.moveShapeJson(JSON.stringify({slideId:d,shapeId:p,x:b,y:P})),true)},resizeShape(d,p,b,P){return g(()=>n.resizeShapeJson(JSON.stringify({slideId:d,shapeId:p,width:b,height:P})),true)},canUndo(){return C(()=>n.canUndo())},canRedo(){return C(()=>n.canRedo())},undo(){return g(()=>n.undoJson(),true)},redo(){return g(()=>n.redoJson(),true)},encodeStateVector(){return C(()=>n.encodeStateVector().slice())},encodeStateAsUpdate(d){return C(()=>d===void 0?n.encodeStateAsUpdate().slice():n.encodeDiff(d.slice()).slice())},encodeDiff(d){return C(()=>n.encodeDiff(d.slice()).slice())},applyUpdate(d){return g(()=>n.applyUpdateJson(d.slice()),true)},onUpdate(d){if(ae(),typeof d!="function")throw new TypeError("update listener must be a function");let p=l++;i.set(p,d);try{Be();}catch(P){throw i.delete(p),P}let b=true;return ()=>{b&&(b=false,i.delete(p),Ve());}},dispose(){if(a)return;a=true,i.clear(),c.length=0;let d;if(w){try{n.clearUpdateObservation();}catch(p){d=p;}w=false;}try{s.free();}catch(p){d??(d=p);}try{n.free();}catch(p){d??(d=p);}if(d!==void 0)throw N(d)}}}function Me(r,e){try{return r.registerFont(e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(t){throw N(t)}}function oe(){if(!ie)throw new Error("pptx wasm is not initialized; call initWasm() first")}function It(){let r=globalThis.crypto;if(!r||typeof r.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let e=new Uint32Array(2),t;do r.getRandomValues(e),t=(e[0]&2097151)*4294967296+e[1];while(t===0);return t}function Ne(r){try{return r()}catch(e){throw N(e)}}function kt(r){try{return JSON.parse(r())}catch(e){throw N(e)}}function Ot(r){return kt(r)}function N(r){return r instanceof Error?r:new Error(typeof r=="string"?r:String(r))}export{x as CollaborationError,$ as CollaborationProvider,pe as PRESENCE_LABEL_DURATION_MS,Tt as initWasm,Ut as inspectPresentation,At as isWasmAvailable,Rt as openPresentation,$e as paintSlide,G as presenceColorForClientId,je as sizeCanvasForSlide,Et as wasmVersion};
|
|
1
|
+
var je=Object.defineProperty;var $e=(r,e,t)=>e in r?je(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var u=(r,e,t)=>$e(r,typeof e!="symbol"?e+"":e,t);function qe(r,e,t,n=1){r.width=Math.round(e.width*n*t),r.height=Math.round(e.height*n*t),r.style.width=`${e.width*n}px`,r.style.height=`${e.height*n}px`;}async function Xe(r,e,t=1,n=1,s={}){r.save();try{r.setTransform(t*n,0,0,t*n,0,0),r.clearRect(0,0,e.width,e.height),e.background&&(r.fillStyle=de(r,e.background,0,0,e.width,e.height),r.fillRect(0,0,e.width,e.height));for(let i of e.primitives)await ce(r,i,s);}finally{r.restore();}}async function ce(r,e,t){r.save();try{switch(He(r,e),e.kind){case "shape":Ye(r,e);break;case "image":await Qe(r,e,t.resolveImage);break;case "textBox":Ze(r,e);break;case "placeholder":rt(r,e);break;case "chart":await Ge(r,e,t);break}}finally{r.restore();}}async function Ge(r,e,t){r.beginPath(),r.rect(e.x,e.y,e.w,e.h),r.clip();for(let n of e.primitives)await ce(r,n,t);}function He(r,e){let t=e.transform;if(!t)return;let n=e.x+e.w/2,s=e.y+e.h/2;r.translate(n,s),r.rotate((t.rotationDeg??0)*Math.PI/180),r.scale(t.flipH?-1:1,t.flipV?-1:1),r.translate(-n,-s);}function Ye(r,e){Ke(r,e.path,e.x,e.y,e.w,e.h),e.fill&&(r.fillStyle=de(r,e.fill,e.x,e.y,e.w,e.h),r.fill()),e.stroke&&le(r,e.stroke);}function Ke(r,e,t,n,s,i){r.beginPath();for(let c of e)switch(c.type){case "move":r.moveTo(t+c.x*s,n+c.y*i);break;case "line":r.lineTo(t+c.x*s,n+c.y*i);break;case "quad":r.quadraticCurveTo(t+c.cpx*s,n+c.cpy*i,t+c.x*s,n+c.y*i);break;case "cubic":r.bezierCurveTo(t+c.cp1x*s,n+c.cp1y*i,t+c.cp2x*s,n+c.cp2y*i,t+c.x*s,n+c.y*i);break;case "close":r.closePath();break}}function le(r,e){r.strokeStyle=e.color,r.lineWidth=e.width,r.setLineDash(e.dashed?[Math.max(3,e.width*2),Math.max(2,e.width)]:[]),r.stroke();}function de(r,e,t,n,s,i){if(e.kind==="solid")return e.color;let c=(e.angleDeg??0)*Math.PI/180,l=t+s/2,a=n+i/2,w=Math.hypot(s,i)/2,v=e.gradientType==="linear"?r.createLinearGradient(l-Math.cos(c)*w,a-Math.sin(c)*w,l+Math.cos(c)*w,a+Math.sin(c)*w):r.createRadialGradient(l,a,0,l,a,w);for(let k of e.stops)v.addColorStop(Math.max(0,Math.min(1,k.position)),k.color);return v}async function Qe(r,e,t){if(e.assetId&&t){let n=await t(e.assetId);n&&r.drawImage(n,e.x,e.y,e.w,e.h);}e.stroke&&(r.beginPath(),r.rect(e.x,e.y,e.w,e.h),le(r,e.stroke));}function Ze(r,e){r.beginPath(),r.rect(e.x,e.y,e.w,e.h),r.clip(),r.textAlign="left",r.textBaseline="alphabetic";for(let t of e.lines)for(let n of t.runs)et(r,n,t.baseline);}function et(r,e,t){let n=e.italic?"italic ":"",s=e.bold?"bold ":"";r.font=`${n}${s}${e.fontSizePx}px ${tt(e.fontFamily)}`,r.fillStyle=e.color,r.fillText(e.text,e.x,t),e.underline&&r.fillRect(e.x,t+e.fontSizePx*.08,e.width,Math.max(1,e.fontSizePx*.05));}function tt(r){return r.includes(" ")?JSON.stringify(r):r}function rt(r,e){r.strokeStyle="#8a94a6",r.lineWidth=1,r.setLineDash([5,4]),r.strokeRect(e.x,e.y,e.w,e.h),e.label&&(r.setLineDash([]),r.fillStyle="#5d6675",r.font="12px sans-serif",r.textAlign="center",r.textBaseline="middle",r.fillText(e.label,e.x+e.w/2,e.y+e.h/2,Math.max(0,e.w-12)));}var ue=3e3;var pe=["#B3261E","#7B1FA2","#3949AB","#00796B","#2E7D32","#A84400","#C2185B","#00695C"],nt=/^#[0-9a-fA-F]+$/;function G(r){return pe[Math.abs(r)%pe.length]}function H(r,e){return typeof e=="string"&&(e.length===4||e.length===7)&&nt.test(e)?e:G(r)}function fe(r,e){if(e&&(typeof e.name!="string"||e.name.trim().length===0))throw new TypeError("Collaboration user name must be a non-empty string");if(e?.color!==void 0&&typeof e.color!="string")throw new TypeError("Collaboration user color must be a string");let t=e?.name.trim().slice(0,1024)||`Guest ${r.toString(36).toUpperCase()}`,n=H(r,e?.color);return {name:t,color:n}}function Y(r,e){return r?.slideId===e?.slideId&&r?.shapeId===e?.shapeId}var W=class{constructor(e,t={}){u(this,"localClientId",e);u(this,"states",new Map);u(this,"clocks",new Map);u(this,"maxTrackedIds");if(this.maxTrackedIds=t.maxTrackedIds??4096,!Number.isSafeInteger(this.maxTrackedIds)||this.maxTrackedIds<1)throw new RangeError("Presence tracked id limit must be a positive integer")}get peers(){return [...this.states.values()].sort((e,t)=>e.state.clientId-t.state.clientId).map(st)}get trackedIdCount(){return this.clocks.size}get nextExpiryAt(){let e;for(let t of this.states.values()){let n=t.lastSeen+45e3;e=e===void 0?n:Math.min(e,n);}for(let t of this.clocks.values()){let n=t.updatedAt+3e5;e=e===void 0?n:Math.min(e,n);}return e}apply(e,t){let n=this.expire(t);for(let s of e){if(s.clientId===this.localClientId)continue;let i=this.clocks.get(s.clientId);if(i&&s.clock<=i.clock)continue;if(!i&&this.clocks.size>=this.maxTrackedIds&&(n=this.evictOldest()||n),this.clocks.delete(s.clientId),this.clocks.set(s.clientId,{clock:s.clock,updatedAt:t}),!s.state){n=this.states.delete(s.clientId)||n;continue}let c=this.states.get(s.clientId),l=c&&Y(c.state.cursor,s.state.cursor)?c.cursorMovedAt:t;this.states.set(s.clientId,{state:he(s.state),lastSeen:t,cursorMovedAt:l}),n=true;}return n}expire(e,t=45e3){let n=false;for(let[s,i]of this.states)e-i.lastSeen<t||(this.states.delete(s),n=true);for(let[s,i]of this.clocks)e-i.updatedAt<3e5||(this.clocks.delete(s),n=this.states.delete(s)||n);return n}clear(){let e=this.states.size>0;return this.states.clear(),this.clocks.clear(),e}evictOldest(){let e=this.clocks.keys().next();return e.done?false:(this.clocks.delete(e.value),this.states.delete(e.value))}};function he(r){return {clientId:r.clientId,clock:r.clock,user:{...r.user},cursor:r.cursor?{...r.cursor}:null}}function st(r){return {state:he(r.state),lastSeen:r.lastSeen,cursorMovedAt:r.cursorMovedAt}}var A=16777216,F=4096,ye=0,be=1,ot=2,me=3,ge=0,we=1,Se=2,at=0,ct=Number.MAX_SAFE_INTEGER,f=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},j=class{constructor(e){u(this,"bytes",e);u(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,t=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new f("Truncated varUint");let s=this.bytes[this.offset++],i=s&127;if(i>Math.floor((ct-e)/t))throw new f("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=i*t,n+=1,(s&128)===0){if(n>1&&i===0)throw new f("Non-canonical varUint");return e}if(n>=8)throw new f("varUint exceeds Number.MAX_SAFE_INTEGER");t*=128;}}readVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new f("Truncated varUint8Array");let n=this.bytes.slice(this.offset,this.offset+e);return this.offset+=e,n}readVarString(){let e=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch(t){throw new f(`Invalid UTF-8 string${t instanceof Error?`: ${t.message}`:""}`)}}};function T(r){if(!Number.isSafeInteger(r)||r<0)throw new f("varUint value must be a non-negative safe integer");let e=[],t=r;for(;t>=128;)e.push(t%128|128),t=Math.floor(t/128);return e.push(t),Uint8Array.from(e)}function lt(r){let e=new TextEncoder().encode(r);return N([T(e.byteLength),e],A)}function N(r,e){let t=0;for(let i of r)if(t+=i.byteLength,t>e)throw new f(`Frame exceeds ${e} bytes`);let n=new Uint8Array(t),s=0;for(let i of r)n.set(i,s),s+=i.byteLength;return n}function Z(r,e,t){return N([T(ye),T(r),T(e.byteLength),e],t)}function xe(r,e=A){return Z(ge,r,e)}function Pe(r,e=A){return Z(we,r,e)}function ve(r,e=A){return Z(Se,r,e)}function Ce(r,e=A){if(r.length>F)throw new f(`Awareness update exceeds ${F} entries`);let t=[T(r.length)];for(let s of r){Re(s);let i=JSON.stringify(s.state);if(i===void 0)throw new f("Awareness state is not JSON serializable");t.push(T(s.clientId),T(s.clock),lt(i));}let n=N(t,e);return N([T(be),T(n.byteLength),n],e)}function Te(r=A){return N([T(me)],r)}function Ae(r,e=F){if(!(r instanceof Uint8Array))throw new f("Awareness update must be a Uint8Array");if(!Number.isSafeInteger(e)||e<1)throw new f("Awareness entry limit must be a positive integer");let t=new j(r),n=t.readVarUint();if(n>e)throw new f(`Awareness update exceeds ${e} entries`);let s=[];for(let i=0;i<n;i+=1){let c=t.readVarUint(),l=t.readVarUint(),a;try{a=JSON.parse(t.readVarString());}catch(v){throw v instanceof f?v:new f(`Invalid awareness JSON${v instanceof Error?`: ${v.message}`:""}`)}let w={clientId:c,clock:l,state:Ue(a,c,l)};Re(w),s.push(w);}if(!t.done)throw new f("Awareness update has trailing bytes");return s}function Ee(r,e=A,t=F){if(!(r instanceof Uint8Array))throw new f("Frame must be a Uint8Array");if(r.byteLength===0)throw new f("Frame is empty");if(r.byteLength>e)throw new f(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(t)||t<1)throw new f("Message limit must be a positive integer");let n=new j(r),s=[];for(;!n.done;){if(s.length>=t)throw new f(`Frame exceeds ${t} messages`);let i=n.readVarUint();switch(i){case ye:{let c=n.readVarUint(),l=n.readVarUint8Array();if(c===ge)s.push({type:"sync-step-1",stateVector:l});else if(c===we)s.push({type:"sync-step-2",update:l});else if(c===Se)s.push({type:"update",update:l});else throw new f(`Unknown sync message type ${c}`);break}case be:s.push({type:"awareness",update:n.readVarUint8Array()});break;case ot:{let c=n.readVarUint();if(c!==at)throw new f(`Unknown auth message type ${c}`);s.push({type:"auth",reason:n.readVarString()});break}case me:s.push({type:"query-awareness"});break;default:throw new f(`Unknown top-level message type ${i}`)}}return s}function Ue(r,e,t){if(r===null)return null;if(!Q(r))throw new f("Awareness state must be an object or null");if(r.clientId!==e||r.clock!==t)throw new f("Awareness state identity does not match its entry");if(!Q(r.user))throw new f("Awareness user must be an object");let n=K(r.user.name,"Awareness user name"),s=H(e,r.user.color);return {clientId:e,clock:t,user:{name:n,color:s},cursor:dt(r.cursor)}}function dt(r){if(r==null)return null;if(!Q(r))throw new f("Awareness cursor must be an object or null");let e=K(r.slideId,"Awareness slideId"),t=r.shapeId===void 0?void 0:K(r.shapeId,"Awareness shapeId");return t?{slideId:e,shapeId:t}:{slideId:e}}function Re(r){_e(r.clientId,"Awareness clientId"),_e(r.clock,"Awareness clock"),r.state!==null&&Ue(r.state,r.clientId,r.clock);}function _e(r,e){if(!Number.isSafeInteger(r)||r<0)throw new f(`${e} must be a non-negative safe integer`)}function K(r,e){if(typeof r!="string"||r.length===0||r.length>1024)throw new f(`${e} must be between 1 and ${1024} characters`);return r}function Q(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}var x=class extends Error{constructor(t,n,s){super(n);u(this,"code");u(this,"cause");this.name="CollaborationError",this.code=t,this.cause=s;}};var ft=16*1024*1024;function ee(r,e,t){if(!Number.isSafeInteger(e)||e<(t?0:1))throw new RangeError(`${r} must be ${t?"a non-negative":"a positive"} integer`);return e}function ht(r){return r instanceof Error&&r.message?r.message:typeof r=="string"&&r?r:"Unknown error"}function m(r,e,t){return t instanceof x?t:new x(r,`${e}: ${ht(t)}`,t)}function te(r,e){if(!(r instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return r.slice()}function re(r){typeof r=="object"&&r&&"unref"in r&&r.unref();}function _t(r){if(!Number.isSafeInteger(r)||r<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return r}function yt(r){if(r===null)return null;if(!r||typeof r.slideId!="string"||r.slideId.length===0)throw new TypeError("Presence cursor slideId must be a non-empty string");if(r.shapeId!==void 0&&(typeof r.shapeId!="string"||r.shapeId.length===0))throw new TypeError("Presence cursor shapeId must be a non-empty string");return r.shapeId?{slideId:r.slideId,shapeId:r.shapeId}:{slideId:r.slideId}}function bt(r){return r.slideId.length<=1024&&(r.shapeId===void 0||r.shapeId.length<=1024)}var $=class{constructor(e,t,n={}){u(this,"replica");u(this,"transport");u(this,"maxFrameBytes");u(this,"maxMessagesPerFrame");u(this,"maxPendingBytes");u(this,"localClientId");u(this,"localUser");u(this,"remotePresence");u(this,"statusListeners",new Map);u(this,"errorListeners",new Map);u(this,"presenceListeners",new Map);u(this,"pendingFrames",[]);u(this,"unsubscribeReplica");u(this,"unsubscribeTransport",()=>{});u(this,"hasTransportSubscription",false);u(this,"connectionStatus","disconnected");u(this,"isSynced",false);u(this,"wantsConnection",false);u(this,"isOpen",false);u(this,"isDestroyed",false);u(this,"epoch",0);u(this,"connectAttempt",0);u(this,"nextListenerId",0);u(this,"queuedBytes",0);u(this,"isFlushing",false);u(this,"localClock",0);u(this,"reportedClockExhaustion",false);u(this,"localCursor",null);u(this,"lastAwarenessSentAt",0);u(this,"cursorTimer",null);u(this,"heartbeatTimer",null);u(this,"expiryTimer",null);this.replica=e,this.transport=t,this.localClientId=_t(e.clientId),this.localUser=fe(this.localClientId,n.user),this.remotePresence=new W(this.localClientId),this.maxFrameBytes=ee("maxFrameBytes",n.maxFrameBytes??A,false),this.maxMessagesPerFrame=ee("maxMessagesPerFrame",n.maxMessagesPerFrame??F,false),this.maxPendingBytes=ee("maxPendingBytes",n.maxPendingBytes??ft,true);try{this.unsubscribeReplica=e.onUpdate((s,i)=>{i==="local"&&this.forwardLocalUpdate(s);});}catch(s){throw m("replica","Failed to observe replica updates",s)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}get peers(){return this.remotePresence.peers}setCursor(e){if(this.isDestroyed)return;let t=yt(e),n=!t||bt(t)?t:null;t&&!n&&this.report(new x("protocol",`Presence cursor identifiers exceed ${1024} characters; cursor dropped`)),!Y(this.localCursor,n)&&(this.localCursor=n,this.isOpen&&this.wantsConnection&&this.scheduleCursorBroadcast());}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 n;try{if(n=this.transport.onEvent(s=>this.handleTransportEvent(e,s)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(s){this.failConnection(e,m("transport","Failed to subscribe to transport events",s));return}if(!this.isCurrent(e)){try{n();}catch(s){this.isDestroyed||this.report(m("transport","Failed to unsubscribe from stale transport events",s));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(s=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,m("transport","Transport connect failed",s));});}catch(n){this.failConnection(e,m("transport","Transport connect failed",n));}}}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 n=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let s of n)this.report(s);}destroy(){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 n=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let s of n)this.report(s);try{this.unsubscribeReplica();}catch(s){this.report(m("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");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");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");let t=this.nextListenerId++;this.presenceListeners.set(t,e);try{e(this.peers);}catch{}return ()=>this.presenceListeners.delete(t)}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 n=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let s=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(t);for(let i of s)this.report(i);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let n=[];try{e();}catch(s){n.push(m("transport","Failed to unsubscribe from transport events",s));}if(!t)return n;try{let s=this.transport.disconnect();s&&s.catch(i=>{this.isDestroyed||this.report(m("transport","Transport disconnect failed",i));});}catch(s){n.push(m("transport","Transport disconnect failed",s));}return n}handleTransportEvent(e,t){if(this.isCurrent(e))switch(t.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(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,m("transport","Transport error",t.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new x("transport","Unknown transport event"));}}handleOpen(e){if(this.isOpen||(this.isOpen=true,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(e)||!this.isOpen))return;let t;try{t=te(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,m("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(xe(t,this.maxFrameBytes));}catch(n){this.failConnection(e,m("protocol","Failed to encode SyncStep1",n));return}if(!(!this.isCurrent(e)||!this.isOpen)&&(this.startPresenceTimers(),this.broadcastLocalPresence(false),!(!this.isCurrent(e)||!this.isOpen)))try{this.sendFrame(Te(this.maxFrameBytes));}catch(n){this.report(m("protocol","Failed to encode awareness query",n));}}handleMessage(e,t){let n;try{n=Ee(t.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(s){this.failConnection(e,m("protocol","Invalid collaboration frame",s));return}for(let s of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(s.type){case "sync-step-1":this.respondToSyncStep1(e,s.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,s.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,s.update);break;case "awareness":{try{let i=Ae(s.update,this.maxMessagesPerFrame);this.remotePresence.apply(i,Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();}catch(i){this.report(m("protocol","Invalid awareness update",i));}break}case "auth":this.failConnection(e,new x("protocol",s.reason?`Authentication denied: ${s.reason}`:"Authentication denied"));return;case "query-awareness":this.broadcastLocalPresence(false);break}}}respondToSyncStep1(e,t){let n;try{n=te(this.replica.encodeStateAsUpdate(t.slice()),"encodeStateAsUpdate");}catch(s){this.failConnection(e,m("replica","Failed to encode replica update",s));return}try{this.sendFrame(Pe(n,this.maxFrameBytes));}catch(s){this.failConnection(e,m("protocol","Failed to encode SyncStep2",s));}}applyRemoteUpdate(e,t){try{return this.replica.applyUpdate(t.slice()),!0}catch(n){return this.failConnection(e,m("replica","Failed to apply remote update",n)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let t=this.epoch,n;try{n=te(e,"Replica update");}catch(s){this.failConnection(t,m("replica","Invalid replica update",s));return}try{this.sendFrame(ve(n,this.maxFrameBytes));}catch(s){this.failConnection(t,m("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),re(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 x("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}this.localClock+=1;let t=this.localClock,n=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=Ce([{clientId:this.localClientId,clock:t,state:n}],this.maxFrameBytes);e?this.sendLeaveFrameBestEffort(s):this.sendFrame(s);}catch(s){this.report(m("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),re(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())),re(this.expiryTimer));}clearRemotePresence(){this.remotePresence.clear()&&this.emitPresence();}emitPresence(){let e=this.peers;for(let[t,n]of [...this.presenceListeners])if(this.presenceListeners.get(t)===n)try{n(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 n;try{n=this.transport.send(e.slice());}catch(s){this.failConnection(t,m("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(t,new x("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(t)&&this.isOpen&&this.queueFrame(t,e);}queueFrame(e,t){if(t.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new x("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=t.slice();this.pendingFrames.push(n),this.queuedBytes+=n.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],n;try{n=this.transport.send(t.slice());}catch(s){this.failConnection(e,m("transport","Transport send failed",s));return}if(typeof n!="boolean"){this.failConnection(e,new x("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==t)return;this.pendingFrames.shift(),this.queuedBytes-=t.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){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 n={status:e,synced:t};for(let[s,i]of [...this.statusListeners])if(this.statusListeners.get(s)===i)try{i(n);}catch{}}report(e){for(let[t,n]of [...this.errorListeners])if(this.errorListeners.get(t)===n)try{n(e);}catch{}}};var U=class r{static __wrap(e){let t=Object.create(r.prototype);return t.__wbg_ptr=e,Ie.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ie.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_pptxdocument_free(e,0);}addShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_addShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}addTextBoxJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_addTextBoxJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}applyUpdateJson(e){let t,n;try{let c=I(e,o.__wbindgen_malloc),l=_,a=o.pptxdocument_applyUpdateJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}canRedo(){return o.pptxdocument_canRedo(this.__wbg_ptr)!==0}canUndo(){return o.pptxdocument_canUndo(this.__wbg_ptr)!==0}clearUpdateObservation(){o.pptxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return o.pptxdocument_clientId(this.__wbg_ptr)}deleteSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_deleteSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}deleteTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_deleteTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}drainUpdateEvent(){let e=o.pptxdocument_drainUpdateEvent(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}encodeDiff(e){let t=I(e,o.__wbindgen_malloc),n=_,s=o.pptxdocument_encodeDiff(this.__wbg_ptr,t,n);if(s[3])throw h(s[2]);var i=E(s[0],s[1]).slice();return o.__wbindgen_free(s[0],s[1]*1,1),i}encodeStateAsUpdate(){let e=o.pptxdocument_encodeStateAsUpdate(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}encodeStateVector(){let e=o.pptxdocument_encodeStateVector(this.__wbg_ptr);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}formatTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_formatTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertParagraphBreakJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertParagraphBreakJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}insertTextJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_insertTextJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}mediaBytes(e){let t=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),n=_,s=o.pptxdocument_mediaBytes(this.__wbg_ptr,t,n);if(s[3])throw h(s[2]);var i=E(s[0],s[1]).slice();return o.__wbindgen_free(s[0],s[1]*1,1),i}moveShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_moveShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}moveSlideJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_moveSlideJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}static openCollaborative(e,t){let n=I(e,o.__wbindgen_malloc),s=_,i=o.pptxdocument_openCollaborative(n,s,t);if(i[2])throw h(i[1]);return r.__wrap(i[0])}static openCollaborativeFromUpdate(e,t,n){let s=I(e,o.__wbindgen_malloc),i=_;var c=Me(n)?0:I(n,o.__wbindgen_malloc),l=_;let a=o.pptxdocument_openCollaborativeFromUpdate(s,i,t,c,l);if(a[2])throw h(a[1]);return r.__wrap(a[0])}redoJson(){let e,t;try{let i=o.pptxdocument_redoJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}removeShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_removeShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}resizeShapeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_resizeShapeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}saveBytes(){let e=o.pptxdocument_saveBytes(this.__wbg_ptr);if(e[3])throw h(e[2]);var t=E(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*1,1),t}setShapeAdjustJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeAdjustJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeFillJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeFillJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}setShapeStrokeJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_setShapeStrokeJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}snapshotJson(){let e,t;try{let i=o.pptxdocument_snapshotJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}startUpdateObservation(){let e=o.pptxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw h(e[0])}storyJson(e){let t,n;try{let c=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=_,a=o.pptxdocument_storyJson(this.__wbg_ptr,c,l);var s=a[0],i=a[1];if(a[3])throw s=0,i=0,h(a[2]);return t=s,n=i,y(s,i)}finally{o.__wbindgen_free(t,n,1);}}undoJson(){let e,t;try{let i=o.pptxdocument_undoJson(this.__wbg_ptr);var n=i[0],s=i[1];if(i[3])throw n=0,s=0,h(i[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}static version(){let e,t;try{let n=o.pptxdocument_version();return e=n[0],t=n[1],y(n[0],n[1])}finally{o.__wbindgen_free(e,t,1);}}};Symbol.dispose&&(U.prototype[Symbol.dispose]=U.prototype.free);var M=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,ke.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_pptxrenderer_free(e,0);}hitTestJson(e,t){let n,s;try{let l=o.pptxrenderer_hitTestJson(this.__wbg_ptr,e,t);var i=l[0],c=l[1];if(l[3])throw i=0,c=0,h(l[2]);return n=i,s=c,y(i,c)}finally{o.__wbindgen_free(n,s,1);}}layoutSlideJson(e,t){let n,s;try{wt(e,U);let l=o.pptxrenderer_layoutSlideJson(this.__wbg_ptr,e.__wbg_ptr,t);var i=l[0],c=l[1];if(l[3])throw i=0,c=0,h(l[2]);return n=i,s=c,y(i,c)}finally{o.__wbindgen_free(n,s,1);}}constructor(){let e=o.pptxrenderer_new();return this.__wbg_ptr=e,ke.register(this,this.__wbg_ptr,this),this}registerFont(e,t,n,s){let i=S(e,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_,l=I(s,o.__wbindgen_malloc),a=_,w=o.pptxrenderer_registerFont(this.__wbg_ptr,i,c,t,n,l,a);if(w[2])throw h(w[1]);return w[0]>>>0}};Symbol.dispose&&(M.prototype[Symbol.dispose]=M.prototype.free);function Fe(r){let e,t;try{let i=I(r,o.__wbindgen_malloc),c=_,l=o.parsePptxJson(i,c);var n=l[0],s=l[1];if(l[3])throw n=0,s=0,h(l[2]);return e=n,t=s,y(n,s)}finally{o.__wbindgen_free(e,t,1);}}function Le(){let r,e;try{let t=o.rendererVersion();return r=t[0],e=t[1],y(t[0],t[1])}finally{o.__wbindgen_free(r,e,1);}}function mt(){return {__proto__:null,"./pptx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_string_get_b0ca35b86a603356:function(e,t){let n=t,s=typeof n=="string"?n:void 0;var i=Me(s)?0:S(s,o.__wbindgen_malloc,o.__wbindgen_realloc),c=_;Oe().setInt32(e+4,c,true),Oe().setInt32(e+0,i,true);},__wbg___wbindgen_throw_344f42d3211c4765:function(e,t){throw new Error(y(e,t))},__wbg_getRandomValues_3f44b700395062e5:function(){return ne(function(e,t){globalThis.crypto.getRandomValues(E(e,t));},arguments)},__wbg_get_78f252d074a84d0b:function(){return ne(function(e,t){return Reflect.get(e,t)},arguments)},__wbg_get_unchecked_6e0ad6d2a41b06f6:function(e,t){return e[t>>>0]},__wbg_instanceof_Object_33f20e6f12439f3e:function(e){let t;try{t=e instanceof Object;}catch{t=false;}return t},__wbg_keys_58421f8f96795607:function(e){return Object.keys(e)},__wbg_length_1f0964f4a5e2c6d8:function(e){return e.length},__wbg_length_370319915dc99107:function(e){return e.length},__wbg_new_cd45aabdf6073e84:function(e){return new Uint8Array(e)},__wbg_new_da52cf8fe3429cb2:function(){return new Object},__wbg_new_from_slice_77cdfb7977362f3c:function(e,t){return new Uint8Array(E(e,t))},__wbg_prototypesetcall_4770620bbe4688a0:function(e,t,n){Uint8Array.prototype.set.call(E(e,t),n);},__wbg_set_8535240470bf2500:function(){return ne(function(e,t,n){return Reflect.set(e,t,n)},arguments)},__wbindgen_cast_0000000000000001:function(e,t){return y(e,t)},__wbindgen_init_externref_table:function(){let e=o.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,true),e.set(t+3,false);}}}}var Ie=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxdocument_free(r,1)),ke=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>o.__wbg_pptxrenderer_free(r,1));function gt(r){let e=o.__externref_table_alloc();return o.__wbindgen_externrefs.set(e,r),e}function wt(r,e){if(!(r instanceof e))throw new Error(`expected instance of ${e.name}`)}function E(r,e){return r=r>>>0,L().subarray(r/1,r/1+e)}var R=null;function Oe(){return (R===null||R.buffer.detached===true||R.buffer.detached===void 0&&R.buffer!==o.memory.buffer)&&(R=new DataView(o.memory.buffer)),R}function y(r,e){return xt(r>>>0,e)}var J=null;function L(){return (J===null||J.byteLength===0)&&(J=new Uint8Array(o.memory.buffer)),J}function ne(r,e){try{return r.apply(this,e)}catch(t){let n=gt(t);o.__wbindgen_exn_store(n);}}function Me(r){return r==null}function I(r,e){let t=e(r.length*1,1)>>>0;return L().set(r,t/1),_=r.length,t}function S(r,e,t){if(t===void 0){let l=B.encode(r),a=e(l.length,1)>>>0;return L().subarray(a,a+l.length).set(l),_=l.length,a}let n=r.length,s=e(n,1)>>>0,i=L(),c=0;for(;c<n;c++){let l=r.charCodeAt(c);if(l>127)break;i[s+c]=l;}if(c!==n){c!==0&&(r=r.slice(c)),s=t(s,n,n=c+r.length*3,1)>>>0;let l=L().subarray(s+c,s+n),a=B.encodeInto(r,l);c+=a.written,s=t(s,n,c,1)>>>0;}return _=c,s}function h(r){let e=o.__wbindgen_externrefs.get(r);return o.__externref_table_dealloc(r),e}var q=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});q.decode();var St=2146435072,se=0;function xt(r,e){return se+=e,se>=St&&(q=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),q.decode(),se=e),q.decode(L().subarray(r,r+e))}var B=new TextEncoder;"encodeInto"in B||(B.encodeInto=function(r,e){let t=B.encode(r);return e.set(t),{read:r.length,written:t.length}});var _=0,o;function Ct(r,e){return o=r.exports,R=null,J=null,o.__wbindgen_start(),o}async function Tt(r,e){if(typeof Response=="function"&&r instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(r,e)}catch(s){if(r.ok&&t(r.type)&&r.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",s);else throw s}let n=await r.arrayBuffer();return await WebAssembly.instantiate(n,e)}else {let n=await WebAssembly.instantiate(r,e);return n instanceof WebAssembly.Instance?{instance:n,module:r}:n}function t(n){switch(n){case "basic":case "cors":case "default":return true}return false}}async function De(r){if(o!==void 0)return o;if(r!==void 0&&(Object.getPrototypeOf(r)===Object.prototype?{module_or_path:r}=r:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),r===void 0)throw new Error("pptx-wasm requires an explicit module or URL");let e=mt();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:t,module:n}=await Tt(await r,e);return Ct(t)}var ie=false,V;function At(r=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return ie?Promise.resolve():V||(V=De({module_or_path:r}).then(()=>{ie=true;},e=>{throw V=void 0,D(e)}),V)}function Et(){return typeof WebAssembly=="object"}function Ut(){return oe(),Le()}function Rt(r){return oe(),Ft(()=>Fe(r))}function It(r,e={}){oe();let t=e.clientId??kt(),n=Je(()=>e.initialUpdate===void 0?U.openCollaborative(r,t):U.openCollaborativeFromUpdate(e.initialUpdate.slice(),t,r.slice())),s=Je(()=>new M);for(let d of e.fonts??[])Ne(s,d);let i=new Map,c=[],l=0,a=false,w=false,v=0,k=false,ae=()=>{if(a)throw new Error("presentation handle is disposed")},Be=()=>{if(!(a||k||v!==0)){k=true;try{for(;!a&&c.length>0;){let d=c.shift();if(!d)break;for(let[p,b]of [...i]){if(a)return;if(i.get(p)===b)try{b(d.update.slice(),d.origin);}catch{}}}}finally{k=false,a&&(c.length=0);}}},Ve=()=>{if(!(!w||a))for(;;){let d=n.drainUpdateEvent();if(d.byteLength===0)return;let p=d[0];if(p!==0&&p!==1)throw new Error(`pptx wasm returned unknown update origin ${p}`);c.push({update:d.slice(1),origin:p===0?"local":"remote"});}},C=(d,p=false)=>{ae(),v+=1;try{let b,P,z=!1;try{b=d();}catch(X){P=X,z=!0;}if(p)try{Ve();}catch(X){z||(P=X,z=!0);}if(z)throw D(P);return b}finally{v-=1,v===0&&Be();}},g=(d,p=false)=>C(()=>JSON.parse(d()),p),ze=()=>{w||(C(()=>n.startUpdateObservation()),w=true);},We=()=>{!w||i.size>0||a||(c.length=0,C(()=>n.clearUpdateObservation()),w=false);};return {get clientId(){return C(()=>n.clientId)},snapshot(){return g(()=>n.snapshotJson())},story(d){return g(()=>n.storyJson(JSON.stringify({storyId:d})))},registerFont(d){return C(()=>Ne(s,d))},layoutSlide(d){return g(()=>s.layoutSlideJson(n,d))},hitTest(d,p){return g(()=>s.hitTestJson(d,p))},mediaBytes(d){return C(()=>n.mediaBytes(d).slice())},save(){return C(()=>n.saveBytes().slice())},insertText(d,p,b,P={}){return g(()=>n.insertTextJson(JSON.stringify({storyId:d,index:p,text:b,style:P})),true)},deleteText(d,p,b){return g(()=>n.deleteTextJson(JSON.stringify({storyId:d,start:p,end:b})),true)},formatText(d,p,b,P){return g(()=>n.formatTextJson(JSON.stringify({storyId:d,start:p,end:b,patch:P})),true)},insertParagraphBreak(d,p){return g(()=>n.insertParagraphBreakJson(JSON.stringify({storyId:d,index:p})),true)},insertSlide(d,p){return g(()=>n.insertSlideJson(JSON.stringify({index:d,layoutPartPath:p??null})),true)},deleteSlide(d){return g(()=>n.deleteSlideJson(JSON.stringify({slideId:d})),true)},moveSlide(d,p){return g(()=>n.moveSlideJson(JSON.stringify({slideId:d,toIndex:p})),true)},addTextBox(d,p){return g(()=>n.addTextBoxJson(JSON.stringify({slideId:d,draft:p})),true)},addShape(d,p){return g(()=>n.addShapeJson(JSON.stringify({slideId:d,draft:p})),true)},setShapeFill(d,p,b){return g(()=>n.setShapeFillJson(JSON.stringify({slideId:d,shapeId:p,color:b})),true)},setShapeStroke(d,p,b){return g(()=>n.setShapeStrokeJson(JSON.stringify({slideId:d,shapeId:p,stroke:b})),true)},setShapeAdjust(d,p,b){return g(()=>n.setShapeAdjustJson(JSON.stringify({slideId:d,shapeId:p,adjustments:b})),true)},removeShape(d,p){return g(()=>n.removeShapeJson(JSON.stringify({slideId:d,shapeId:p})),true)},moveShape(d,p,b,P){return g(()=>n.moveShapeJson(JSON.stringify({slideId:d,shapeId:p,x:b,y:P})),true)},resizeShape(d,p,b,P){return g(()=>n.resizeShapeJson(JSON.stringify({slideId:d,shapeId:p,width:b,height:P})),true)},canUndo(){return C(()=>n.canUndo())},canRedo(){return C(()=>n.canRedo())},undo(){return g(()=>n.undoJson(),true)},redo(){return g(()=>n.redoJson(),true)},encodeStateVector(){return C(()=>n.encodeStateVector().slice())},encodeStateAsUpdate(d){return C(()=>d===void 0?n.encodeStateAsUpdate().slice():n.encodeDiff(d.slice()).slice())},encodeDiff(d){return C(()=>n.encodeDiff(d.slice()).slice())},applyUpdate(d){return g(()=>n.applyUpdateJson(d.slice()),true)},onUpdate(d){if(ae(),typeof d!="function")throw new TypeError("update listener must be a function");let p=l++;i.set(p,d);try{ze();}catch(P){throw i.delete(p),P}let b=true;return ()=>{b&&(b=false,i.delete(p),We());}},dispose(){if(a)return;a=true,i.clear(),c.length=0;let d;if(w){try{n.clearUpdateObservation();}catch(p){d=p;}w=false;}try{s.free();}catch(p){d??(d=p);}try{n.free();}catch(p){d??(d=p);}if(d!==void 0)throw D(d)}}}function Ne(r,e){try{return r.registerFont(e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(t){throw D(t)}}function oe(){if(!ie)throw new Error("pptx wasm is not initialized; call initWasm() first")}function kt(){let r=globalThis.crypto;if(!r||typeof r.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let e=new Uint32Array(2),t;do r.getRandomValues(e),t=(e[0]&2097151)*4294967296+e[1];while(t===0);return t}function Je(r){try{return r()}catch(e){throw D(e)}}function Ot(r){try{return JSON.parse(r())}catch(e){throw D(e)}}function Ft(r){return Ot(r)}function D(r){return r instanceof Error?r:new Error(typeof r=="string"?r:String(r))}export{x as CollaborationError,$ as CollaborationProvider,ue as PRESENCE_LABEL_DURATION_MS,At as initWasm,Rt as inspectPresentation,Et as isWasmAvailable,It as openPresentation,Xe as paintSlide,G as presenceColorForClientId,qe as sizeCanvasForSlide,Ut as wasmVersion};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betteroffice/pptx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "PowerPoint-faithful PPTX editor and viewer core — full OOXML fidelity, real-time human + AI agent collaboration. Framework-free (Rust/Wasm).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pptx",
|
|
@@ -11,10 +11,18 @@
|
|
|
11
11
|
"office",
|
|
12
12
|
"editor",
|
|
13
13
|
"viewer",
|
|
14
|
+
"pptx-editor",
|
|
15
|
+
"pptx-viewer",
|
|
16
|
+
"pptx-parser",
|
|
17
|
+
"slides-editor",
|
|
14
18
|
"collaborative",
|
|
15
19
|
"real-time",
|
|
20
|
+
"crdt",
|
|
21
|
+
"yjs",
|
|
16
22
|
"ai-agent",
|
|
17
|
-
"
|
|
23
|
+
"headless",
|
|
24
|
+
"wasm",
|
|
25
|
+
"rust"
|
|
18
26
|
],
|
|
19
27
|
"type": "module",
|
|
20
28
|
"sideEffects": false,
|