@betteroffice/pptx 0.1.1 → 0.2.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.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var _t=Object.defineProperty;var gt=(t,e,r)=>e in t?_t(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var m=(t,e,r)=>gt(t,typeof e!="symbol"?e+"":e,r);function pe(t,e,r,n=1){t.width=Math.round(e.width*n*r),t.height=Math.round(e.height*n*r),t.style.width=`${e.width*n}px`,t.style.height=`${e.height*n}px`;}async function ue(t,e,r=1,n=1,o={}){let i={remaining:o.maxShadowPixels??134217728};if(!Number.isSafeInteger(i.remaining)||i.remaining<0)throw new Error("invalid shadow pixel budget");t.save();try{t.setTransform(r*n,0,0,r*n,0,0),t.clearRect(0,0,e.width,e.height),e.background&&(t.fillStyle=te(t,e.background,0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height));for(let a of e.primitives)await Je(t,a,o,r*n,i);}finally{t.restore();}}async function Je(t,e,r,n,o){t.save();try{switch(yt(t,e),e.kind){case "shape":Le(t,e,n,o);break;case "image":await Et(t,e,r.resolveImage,n,o);break;case "textBox":Nt(t,e,r.textChanges);break;case "placeholder":Xt(t,e);break;case "chart":case "table":await bt(t,e,r,n,o);break}}finally{t.restore();}}async function bt(t,e,r,n,o){t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip();for(let i of e.primitives)await Je(t,i,r,n,o);}function yt(t,e){let r=e.transform;if(!r)return;let n=e.x+e.w/2,o=e.y+e.h/2;t.translate(n,o),t.rotate((r.rotationDeg??0)*Math.PI/180),t.scale(r.flipH?-1:1,r.flipV?-1:1),t.translate(-n,-o);}function Le(t,e,r,n){e.clip&&(ce(t,e.clip,e.x,e.y,e.w,e.h),t.clip()),e.shadow&&(e.fill||e.stroke)&&wt(t,e,r,n),ce(t,e.path,e.x,e.y,e.w,e.h),e.fill&&(t.fillStyle=te(t,e.fill,e.x,e.y,e.w,e.h),t.fill(e.evenOdd?"evenodd":"nonzero")),e.stroke&&(Ne(t,e.stroke,e.x,e.y,e.w,e.h),Pt(t,e));}function wt(t,e,r,n){Fe(t,e.shadow,fe(e.path,e),e.stroke?.width??0,r,n,o=>Le(o,{...e,shadow:void 0},r,n));}function Fe(t,e,r,n,o,i,a){let c=e.scaleX??1,s=e.scaleY??1,u=t.getTransform(),f={a:u.a*c,b:u.b*s,c:u.c*c,d:u.d*s,e:u.e*c,f:u.f*s};if(!r.length)return;let v=1/0,C=1/0,T=-1/0,L=-1/0;for(let[$,Ie]of r){let Re=f.a*$+f.c*Ie+f.e,Ue=f.b*$+f.d*Ie+f.f;v=Math.min(v,Re),C=Math.min(C,Ue),T=Math.max(T,Re),L=Math.max(L,Ue);}let A=Math.min(Math.max(e.blur??0,0)*o/2,128),_=A*3+1,N=n*o*Math.max(Math.abs(c),Math.abs(s))*2,B=(e.dx??0)*o,z=(e.dy??0)*o,d=Math.floor(Math.max(v-N,-_-B)),p=Math.floor(Math.max(C-N,-_-z)),y=Math.ceil(Math.min(T+N,t.canvas.width+_-B)),x=Math.ceil(Math.min(L+N,t.canvas.height+_-z));if(y<=d||x<=p)return;let M=(y-d)*(x-p);if(!Number.isSafeInteger(M)||M>i.remaining)throw new Error("shadows exceed the pixel budget on one slide");i.remaining-=M;let U=typeof OffscreenCanvas<"u"?new OffscreenCanvas(y-d,x-p):Object.assign(document.createElement("canvas"),{width:y-d,height:x-p}),F=U.getContext("2d");if(F){F.setTransform(f.a,f.b,f.c,f.d,f.e-d,f.f-p),a(F),t.save();try{if(t.setTransform(1,0,0,1,0,0),typeof t.filter=="string")F.setTransform(1,0,0,1,0,0),F.globalCompositeOperation="source-in",F.fillStyle=e.color,F.fillRect(0,0,U.width,U.height),t.filter=`blur(${A}px)`,t.drawImage(U,d+B,p+z);else {let $=t.canvas.width+1;t.shadowColor=e.color,t.shadowBlur=A*2,t.shadowOffsetX=d+B-$,t.shadowOffsetY=z,t.drawImage(U,$,p);}}finally{t.restore();}}}function fe(t,e){let r=[];for(let n of t)n.type!=="close"&&(n.type==="quad"?r.push([e.x+n.cpx*e.w,e.y+n.cpy*e.h]):n.type==="cubic"&&(r.push([e.x+n.cp1x*e.w,e.y+n.cp1y*e.h]),r.push([e.x+n.cp2x*e.w,e.y+n.cp2y*e.h])),r.push([e.x+n.x*e.w,e.y+n.y*e.h]));return r.filter((n,o)=>o===0||n[0]!==r[o-1][0]||n[1]!==r[o-1][1])}function St(t){return t.path?fe(t.path,t):[[t.x,t.y],[t.x+t.w,t.y],[t.x+t.w,t.y+t.h],[t.x,t.y+t.h]]}var vt=new Set(["triangle","stealth","arrow","diamond","oval"]);function Pt(t,e){let r=e.stroke;if(!r||!r.headEnd&&!r.tailEnd)return;let n=fe(e.path,e);if(n.length<2)return;let o=[[r.headEnd,n[1],n[0]],[r.tailEnd,n[n.length-2],n[n.length-1]]];t.save(),t.setLineDash([]);let i=r.paint?te(t,r.paint,e.x,e.y,e.w,e.h):r.color;t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r.width,t.lineJoin="miter";for(let[a,c,s]of o){if(!a||!vt.has(a.kind))continue;let[u,f]=[s[0]-c[0],s[1]-c[1]],v=Math.hypot(u,f);v<1e-6||xt(t,a,s,u/v,f/v);}t.restore();}function xt(t,e,[r,n],o,i){let a=e.width/2,[c,s]=[-i*a,o*a],[u,f]=[r-o*e.length,n-i*e.length];switch(t.beginPath(),e.kind){case "triangle":t.moveTo(r,n),t.lineTo(u+c,f+s),t.lineTo(u-c,f-s),t.closePath(),t.fill();break;case "stealth":t.moveTo(r,n),t.lineTo(u+c,f+s),t.lineTo(r-o*e.length*.6,n-i*e.length*.6),t.lineTo(u-c,f-s),t.closePath(),t.fill();break;case "arrow":t.moveTo(u+c,f+s),t.lineTo(r,n),t.lineTo(u-c,f-s),t.stroke();break;case "diamond":{let[v,C]=[o*e.length/2,i*e.length/2];t.moveTo(r+v,n+C),t.lineTo(r+c,n+s),t.lineTo(r-v,n-C),t.lineTo(r-c,n-s),t.closePath(),t.fill();break}case "oval":t.ellipse(r,n,e.length/2,a,Math.atan2(i,o),0,Math.PI*2),t.fill();break}}function Ct(t,e,r){let n=r.crop,o=Z(n?.left),i=Z(n?.top),a=1-o-Z(n?.right),c=1-i-Z(n?.bottom),s=r.path!==void 0||a!==1||c!==1;if(a<=0||c<=0)return;s&&(t.save(),De(t,r),t.clip());let u=Tt(e),f=At(e);u>0&&f>0?t.drawImage(e,o*u,i*f,a*u,c*f,r.x,r.y,r.w,r.h):t.drawImage(e,r.x,r.y,r.w,r.h),s&&t.restore();}function De(t,e){e.path?ce(t,e.path,e.x,e.y,e.w,e.h):(t.beginPath(),t.rect(e.x,e.y,e.w,e.h));}function Z(t){return t===void 0||!Number.isFinite(t)?0:Math.min(Math.max(t,0),1)}function Tt(t){return "naturalWidth"in t&&typeof t.naturalWidth=="number"?t.naturalWidth:"width"in t&&typeof t.width=="number"?t.width:0}function At(t){return "naturalHeight"in t&&typeof t.naturalHeight=="number"?t.naturalHeight:"height"in t&&typeof t.height=="number"?t.height:0}function ce(t,e,r,n,o,i){t.beginPath();for(let a of e)switch(a.type){case "move":t.moveTo(r+a.x*o,n+a.y*i);break;case "line":t.lineTo(r+a.x*o,n+a.y*i);break;case "quad":t.quadraticCurveTo(r+a.cpx*o,n+a.cpy*i,r+a.x*o,n+a.y*i);break;case "cubic":t.bezierCurveTo(r+a.cp1x*o,n+a.cp1y*i,r+a.cp2x*o,n+a.cp2y*i,r+a.x*o,n+a.y*i);break;case "close":t.closePath();break}}function Ne(t,e,r,n,o,i){t.strokeStyle=e.paint?te(t,e.paint,r,n,o,i):e.color,t.lineWidth=e.width,t.setLineDash(e.dashed?[Math.max(3,e.width*2),Math.max(2,e.width)]:[]),t.stroke();}function te(t,e,r,n,o,i){if(e.kind==="solid")return e.color;let a=(e.angleDeg??0)*Math.PI/180,c=r+o/2,s=n+i/2,u=Math.hypot(o,i)/2,f=e.gradientType==="linear"?t.createLinearGradient(c-Math.cos(a)*u,s-Math.sin(a)*u,c+Math.cos(a)*u,s+Math.sin(a)*u):t.createRadialGradient(c,s,0,c,s,u);for(let v of e.stops)f.addColorStop(Math.max(0,Math.min(1,v.position)),v.color);return f}async function Et(t,e,r,n,o){let i;if(e.assetId&&r){let a=await r(e.assetId);a&&(i=e.effects?.length?Lt(a,e.effects):a);}e.shadow&&(i||e.stroke)&&Fe(t,e.shadow,St(e),e.stroke?.width??0,n,o,a=>ke(a,e,i)),ke(t,e,i);}function ke(t,e,r){r&&Ct(t,r,e),e.stroke&&(De(t,e),Ne(t,e.stroke,e.x,e.y,e.w,e.h));}var Me=33554432,It=67108864;function Rt(t){let e=t,r=e.naturalWidth??e.videoWidth??e.displayWidth??(typeof e.width=="number"?e.width:0),n=e.naturalHeight??e.videoHeight??e.displayHeight??(typeof e.height=="number"?e.height:0);return r>0&&n>0?{width:r,height:n}:null}function Ut(t){let e=t.width*t.height;if(e<=Me)return t;let r=Math.sqrt(Me/e);return {width:Math.max(1,Math.floor(t.width*r)),height:Math.max(1,Math.floor(t.height*r))}}var de=new WeakMap,W=[],ae=0;function kt(t){let e=t;return "videoWidth"in e||"displayWidth"in e||typeof e.getContext=="function"}function Mt(t,e){let r=de.get(t),n=r?.get(e);if(!r||!n)return;let o=W.findIndex(i=>i.entries===r&&i.key===e);return o>=0&&W.push(...W.splice(o,1)),n}function Ot(t,e,r,n){let o=de.get(t);for(o||(o=new Map,de.set(t,o)),o.set(e,r),W.push({entries:o,key:e,pixels:n}),ae+=n;ae>It&&W.length>1;){let i=W.shift();if(!i)break;i.entries.delete(i.key),ae-=i.pixels;}}function Jt(t,e){if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(t,e);if(typeof document>"u")return null;let r=document.createElement("canvas");return r.width=t,r.height=e,r}function Lt(t,e){let r=Rt(t);if(!r)return t;let n=JSON.stringify(e),o=!kt(t);if(o){let a=Mt(t,n);if(a)return a}let i=Ut(r);try{let a=Jt(i.width,i.height),c=a?.getContext("2d");if(!a||!c)return t;c.drawImage(t,0,0,i.width,i.height);let s=c.getImageData(0,0,i.width,i.height);Dt(s.data,e),c.putImageData(s,0,0);let u=a;return o&&Ot(t,n,u,i.width*i.height),u}catch{return t}}function le(t,e){return .299*t[e]+.587*t[e+1]+.114*t[e+2]}function Ft(t,e){let r=Math.min(Math.max(e,-1),1),n=r>=0?128/(128-127*r):(128+127*r)/128,o=128-128*n+255*Math.min(Math.max(t,-1),1)*(1+n)/2,i=new Uint8ClampedArray(256);for(let a=0;a<256;a+=1)i[a]=Math.round(n*a+o);return i}function ee(t){let e=t.startsWith("#")?t.slice(1):t,r=e.length===3||e.length===4?[...e].map(i=>i+i).join(""):e;if(r.length!==6&&r.length!==8)return null;let n=i=>Number.parseInt(r.slice(i,i+2),16),o=[n(0),n(2),n(4),r.length===8?n(6):255];return o.some(Number.isNaN)?null:o}function Dt(t,e){for(let r of e)switch(r.kind){case "biLevel":{let n=Math.min(Math.max(r.threshold,0),1)*255;for(let o=0;o<t.length;o+=4){let i=le(t,o)<n?0:255;t[o]=i,t[o+1]=i,t[o+2]=i;}break}case "grayscale":{for(let n=0;n<t.length;n+=4){let o=Math.round(le(t,n));t[n]=o,t[n+1]=o,t[n+2]=o;}break}case "luminance":{let n=Ft(r.brightness,r.contrast);for(let o=0;o<t.length;o+=4)t[o]=n[t[o]],t[o+1]=n[t[o+1]],t[o+2]=n[t[o+2]];break}case "duotone":{let n=ee(r.shadow),o=ee(r.highlight);if(!n||!o)break;for(let i=0;i<t.length;i+=4){let a=le(t,i)/255;for(let s=0;s<3;s+=1)t[i+s]=Math.round(n[s]*(1-a)+o[s]*a);let c=n[3]*(1-a)+o[3]*a;t[i+3]=Math.round(t[i+3]*c/255);}break}case "colorChange":{let n=ee(r.from),o=ee(r.to);if(!n||!o)break;for(let i=0;i<t.length;i+=4)t[i]!==n[0]||t[i+1]!==n[1]||t[i+2]!==n[2]||r.useAlpha!==false&&t[i+3]!==n[3]||(t[i]=o[0],t[i+1]=o[1],t[i+2]=o[2],r.useAlpha!==false&&(t[i+3]=o[3]));break}}}function Nt(t,e,r=[]){e.overflow||(t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip()),t.textAlign="left",t.textBaseline="alphabetic";let n=r.filter(o=>o.storyId===e.storyId);Oe(t,e,n,false);for(let o of e.lines)for(let i of o.runs)Bt(t,i,o.baseline);Oe(t,e,n,true);}function Oe(t,e,r,n){if(r.length!==0)for(let o of e.lines)for(let i of o.runs)for(let a of r){let c=Math.max(i.start,a.start),s=Math.min(i.end,a.end);if(c>=s)continue;let u=o.caretStops.filter(T=>T.position>=c&&T.position<=s),f=u.length>1?Math.max(i.x,Math.min(...u.map(T=>T.x))):i.x,v=u.length>1?Math.min(i.x+i.width,Math.max(...u.map(T=>T.x))):i.x+i.width;if(v<=f)continue;let C=a.kind==="insertion";if(n){t.fillStyle=C?"#166534":"#b91c1c";let L=o.baseline-(i.baselineOffsetPx??0)+i.fontSizePx*(C?.08:-0.3);t.fillRect(f,L,v-f,Math.max(1,i.fontSizePx*.05));}else t.fillStyle=C?"#dcfce7cc":"#fee2e2cc",t.fillRect(f,o.y,v-f,o.height);}}function Bt(t,e,r){let n=e.italic?"italic ":"",o=e.bold?"bold ":"";t.font=`${n}${o}${e.fontSizePx}px ${Vt(e.fontFamily)}`,t.fillStyle=e.color;let i=e.letterSpacingPx??0;t.letterSpacing=i===0?"0px":`${i}px`;let a=r-(e.baselineOffsetPx??0);for(let c of Wt(e))t.fillText(c.text,c.x,a);t.letterSpacing="0px",e.underline&&t.fillRect(e.x,a+e.fontSizePx*.08,e.width,Math.max(1,e.fontSizePx*.05));}function Wt(t){if(t.glyphs.length<2)return [{text:t.text,x:t.x}];let e=[],r=0,n=t.x,o=t.glyphs[0].x;for(let i of t.glyphs){let a=i.cluster-t.start;a>r&&a<t.text.length&&Math.abs(i.x-o)>1e-4&&(e.push({text:t.text.slice(r,a),x:n}),r=a,n=i.x),o=Math.fround(Math.fround(i.x)+Math.fround(i.advance));}return e.push({text:t.text.slice(r),x:n}),e}function Vt(t){return t.includes(" ")?JSON.stringify(t):t}function Xt(t,e){t.strokeStyle="#8a94a6",t.lineWidth=1,t.setLineDash([5,4]),t.strokeRect(e.x,e.y,e.w,e.h),e.label&&(t.setLineDash([]),t.fillStyle="#5d6675",t.font="12px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(e.label,e.x+e.w/2,e.y+e.h/2,Math.max(0,e.w-12)));}function Be(t){return t.length>=4&&(t[0]===73&&t[1]===73&&t[2]===42&&t[3]===0||t[0]===77&&t[1]===77&&t[2]===0&&t[3]===42)}var I=class t{static __wrap(e){let r=Object.create(t.prototype);return r.__wbg_ptr=e,We.register(r,r.__wbg_ptr,r),r}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,We.unregister(this),e}free(){let e=this.__destroy_into_raw();l.__wbg_pptxdocument_free(e,0);}acceptProposalJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_acceptProposalJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}addCommentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_addCommentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}addShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_addShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}addTextBoxJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_addTextBoxJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}applyUpdateJson(e){let r,n;try{let a=J(e,l.__wbindgen_malloc),c=b,s=l.pptxdocument_applyUpdateJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}canRedo(){return l.pptxdocument_canRedo(this.__wbg_ptr)!==0}canUndo(){return l.pptxdocument_canUndo(this.__wbg_ptr)!==0}clearUpdateObservation(){l.pptxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return l.pptxdocument_clientId(this.__wbg_ptr)}commentsJson(){let e,r;try{let i=l.pptxdocument_commentsJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}deleteSlideJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_deleteSlideJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}deleteTextJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_deleteTextJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}drainUpdateEvent(){let e=l.pptxdocument_drainUpdateEvent(this.__wbg_ptr);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}encodeDiff(e){let r=J(e,l.__wbindgen_malloc),n=b,o=l.pptxdocument_encodeDiff(this.__wbg_ptr,r,n);if(o[3])throw h(o[2]);var i=O(o[0],o[1]).slice();return l.__wbindgen_free(o[0],o[1]*1,1),i}encodeStateAsUpdate(){let e=l.pptxdocument_encodeStateAsUpdate(this.__wbg_ptr);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}encodeStateVector(){let e=l.pptxdocument_encodeStateVector(this.__wbg_ptr);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}formatTextJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_formatTextJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}insertParagraphBreakJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_insertParagraphBreakJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}insertSlideJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_insertSlideJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}insertTextJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_insertTextJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}listProposalsJson(){let e,r;try{let i=l.pptxdocument_listProposalsJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}mediaBytes(e){let r=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),n=b,o=l.pptxdocument_mediaBytes(this.__wbg_ptr,r,n);if(o[3])throw h(o[2]);var i=O(o[0],o[1]).slice();return l.__wbindgen_free(o[0],o[1]*1,1),i}moveShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_moveShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}moveSlideJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_moveSlideJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}static openCollaborative(e,r){let n=J(e,l.__wbindgen_malloc),o=b,i=l.pptxdocument_openCollaborative(n,o,r);if(i[2])throw h(i[1]);return t.__wrap(i[0])}static openCollaborativeFromUpdate(e,r,n){let o=J(e,l.__wbindgen_malloc),i=b;var a=$t(n)?0:J(n,l.__wbindgen_malloc),c=b;let s=l.pptxdocument_openCollaborativeFromUpdate(o,i,r,a,c);if(s[2])throw h(s[1]);return t.__wrap(s[0])}previewProposalJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_previewProposalJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}proposeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_proposeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}redoJson(){let e,r;try{let i=l.pptxdocument_redoJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}rejectProposalJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_rejectProposalJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}removeCommentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_removeCommentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}removeShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_removeShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}replyToCommentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_replyToCommentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}resizeShapeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_resizeShapeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}saveBytes(){let e=l.pptxdocument_saveBytes(this.__wbg_ptr);if(e[3])throw h(e[2]);var r=O(e[0],e[1]).slice();return l.__wbindgen_free(e[0],e[1]*1,1),r}setCommentFlavorJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setCommentFlavorJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setCommentStatusJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setCommentStatusJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setParagraphAlignmentJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setParagraphAlignmentJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeAdjustJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeAdjustJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeFillJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeFillJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeRectJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeRectJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setShapeStrokeJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setShapeStrokeJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}setSlideNotesJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_setSlideNotesJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}snapshotJson(){let e,r;try{let i=l.pptxdocument_snapshotJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}startUpdateObservation(){let e=l.pptxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw h(e[0])}storyJson(e){let r,n;try{let a=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),c=b,s=l.pptxdocument_storyJson(this.__wbg_ptr,a,c);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{l.__wbindgen_free(r,n,1);}}undoJson(){let e,r;try{let i=l.pptxdocument_undoJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}static version(){let e,r;try{let n=l.pptxdocument_version();return e=n[0],r=n[1],g(n[0],n[1])}finally{l.__wbindgen_free(e,r,1);}}};Symbol.dispose&&(I.prototype[Symbol.dispose]=I.prototype.free);var D=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ve.unregister(this),e}free(){let e=this.__destroy_into_raw();l.__wbg_pptxrenderer_free(e,0);}hitTestJson(e,r){let n,o;try{let c=l.pptxrenderer_hitTestJson(this.__wbg_ptr,e,r);var i=c[0],a=c[1];if(c[3])throw i=0,a=0,h(c[2]);return n=i,o=a,g(i,a)}finally{l.__wbindgen_free(n,o,1);}}layoutProposalDiffSlideJson(e,r,n){let o,i;try{he(e,I);let s=w(r,l.__wbindgen_malloc,l.__wbindgen_realloc),u=b,f=l.pptxrenderer_layoutProposalDiffSlideJson(this.__wbg_ptr,e.__wbg_ptr,s,u,n);var a=f[0],c=f[1];if(f[3])throw a=0,c=0,h(f[2]);return o=a,i=c,g(a,c)}finally{l.__wbindgen_free(o,i,1);}}layoutProposalSlideJson(e,r,n){let o,i;try{he(e,I);let s=w(r,l.__wbindgen_malloc,l.__wbindgen_realloc),u=b,f=l.pptxrenderer_layoutProposalSlideJson(this.__wbg_ptr,e.__wbg_ptr,s,u,n);var a=f[0],c=f[1];if(f[3])throw a=0,c=0,h(f[2]);return o=a,i=c,g(a,c)}finally{l.__wbindgen_free(o,i,1);}}layoutSlideJson(e,r){let n,o;try{he(e,I);let c=l.pptxrenderer_layoutSlideJson(this.__wbg_ptr,e.__wbg_ptr,r);var i=c[0],a=c[1];if(c[3])throw i=0,a=0,h(c[2]);return n=i,o=a,g(i,a)}finally{l.__wbindgen_free(n,o,1);}}constructor(){let e=l.pptxrenderer_new();return this.__wbg_ptr=e,Ve.register(this,this.__wbg_ptr,this),this}registerFont(e,r,n,o){let i=w(e,l.__wbindgen_malloc,l.__wbindgen_realloc),a=b,c=J(o,l.__wbindgen_malloc),s=b,u=l.pptxrenderer_registerFont(this.__wbg_ptr,i,a,r,n,c,s);if(u[2])throw h(u[1]);return u[0]>>>0}};Symbol.dispose&&(D.prototype[Symbol.dispose]=D.prototype.free);function Xe(t){let e=J(t,l.__wbindgen_malloc),r=b,n=l.decodeTiffPng(e,r);if(n[3])throw h(n[2]);var o=O(n[0],n[1]).slice();return l.__wbindgen_free(n[0],n[1]*1,1),o}function je(t){let e,r;try{let i=J(t,l.__wbindgen_malloc),a=b,c=l.parsePptxJson(i,a);var n=c[0],o=c[1];if(c[3])throw n=0,o=0,h(c[2]);return e=n,r=o,g(n,o)}finally{l.__wbindgen_free(e,r,1);}}function He(){let t,e;try{let r=l.rendererVersion();return t=r[0],e=r[1],g(r[0],r[1])}finally{l.__wbindgen_free(t,e,1);}}function jt(){return {__proto__:null,"./pptx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_throw_344f42d3211c4765:function(e,r){throw new Error(g(e,r))},__wbg_getRandomValues_3f44b700395062e5:function(){return zt(function(e,r){globalThis.crypto.getRandomValues(O(e,r));},arguments)},__wbindgen_cast_0000000000000001:function(e,r){return g(e,r)},__wbindgen_init_externref_table:function(){let e=l.__wbindgen_externrefs,r=e.grow(4);e.set(0,void 0),e.set(r+0,void 0),e.set(r+1,null),e.set(r+2,true),e.set(r+3,false);}}}}var We=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>l.__wbg_pptxdocument_free(t,1)),Ve=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>l.__wbg_pptxrenderer_free(t,1));function Ht(t){let e=l.__externref_table_alloc();return l.__wbindgen_externrefs.set(e,t),e}function he(t,e){if(!(t instanceof e))throw new Error(`expected instance of ${e.name}`)}function O(t,e){return t=t>>>0,V().subarray(t/1,t/1+e)}function g(t,e){return Gt(t>>>0,e)}var q=null;function V(){return (q===null||q.byteLength===0)&&(q=new Uint8Array(l.memory.buffer)),q}function zt(t,e){try{return t.apply(this,e)}catch(r){let n=Ht(r);l.__wbindgen_exn_store(n);}}function $t(t){return t==null}function J(t,e){let r=e(t.length*1,1)>>>0;return V().set(t,r/1),b=t.length,r}function w(t,e,r){if(r===void 0){let c=G.encode(t),s=e(c.length,1)>>>0;return V().subarray(s,s+c.length).set(c),b=c.length,s}let n=t.length,o=e(n,1)>>>0,i=V(),a=0;for(;a<n;a++){let c=t.charCodeAt(a);if(c>127)break;i[o+a]=c;}if(a!==n){a!==0&&(t=t.slice(a)),o=r(o,n,n=a+t.length*3,1)>>>0;let c=V().subarray(o+a,o+n),s=G.encodeInto(t,c);a+=s.written,o=r(o,n,a,1)>>>0;}return b=a,o}function h(t){let e=l.__wbindgen_externrefs.get(t);return l.__externref_table_dealloc(t),e}var ne=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});ne.decode();var qt=2146435072,me=0;function Gt(t,e){return me+=e,me>=qt&&(ne=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),ne.decode(),me=e),ne.decode(V().subarray(t,t+e))}var G=new TextEncoder;"encodeInto"in G||(G.encodeInto=function(t,e){let r=G.encode(t);return e.set(r),{read:t.length,written:r.length}});var b=0,l;function Qt(t,e){return l=t.exports,q=null,l.__wbindgen_start(),l}async function Zt(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(o){if(t.ok&&r(t.type)&&t.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",o);else throw o}let n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}else {let n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}function r(n){switch(n){case "basic":case "cors":case "default":return true}return false}}async function ze(t){if(l!==void 0)return l;if(t!==void 0&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),t===void 0)throw new Error("pptx-wasm requires an explicit module or URL");let e=jt();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await Zt(await t,e);return Qt(r)}var Y=class extends Error{constructor(r){super(`Proposal targets changed: ${r.join(", ")}`);m(this,"targets");this.name="StaleProposalError",this.targets=r;}};var _e=false;function ge(){return typeof I.prototype.proposeJson=="function"&&typeof D.prototype.layoutProposalSlideJson=="function"}var K;function en(t=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return _e?Promise.resolve():K||(K=ze({module_or_path:t}).then(()=>{_e=true;},e=>{throw K=void 0,X(e)}),K)}function tn(){return typeof WebAssembly=="object"}function nn(){return re(),He()}function rn(t){return re(),ln(()=>je(t))}function qe(t){return re(),be(()=>Xe(t))}function on(t,e={}){re();let r=e.clientId??sn(),n=be(()=>e.initialUpdate===void 0?I.openCollaborative(t,r):I.openCollaborativeFromUpdate(e.initialUpdate.slice(),r,t.slice())),o=be(()=>new D);for(let d of e.fonts??[])$e(o,d);let i=new Map,a=[],c=0,s=false,u=false,f=0,v=false,C=()=>{if(s)throw new Error("presentation handle is disposed")},T=()=>{if(!(s||v||f!==0)){v=true;try{for(;!s&&a.length>0;){let d=a.shift();if(!d)break;for(let[p,y]of [...i]){if(s)return;if(i.get(p)===y)try{y(d.update.slice(),d.origin);}catch{}}}}finally{v=false,s&&(a.length=0);}}},L=()=>{if(!(!u||s))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}`);a.push({update:d.subarray(1),origin:p===0?"local":"remote"});}},A=(d,p=false)=>{C(),f+=1;try{let y,x,M=!1;try{y=d();}catch(U){x=U,M=!0;}if(p)try{L();}catch(U){M||(x=U,M=!0);}if(M)throw X(x);return y}finally{f-=1,f===0&&T();}},_=(d,p=false)=>A(()=>JSON.parse(d()),p),N=()=>{u||(A(()=>n.startUpdateObservation()),u=true);},B=()=>{!u||i.size>0||s||(a.length=0,A(()=>n.clearUpdateObservation()),u=false);};return {isProposalsAvailable:ge,propose(d,p,y){return _(()=>n.proposeJson(JSON.stringify({agentId:d,note:p,edits:y})))},listProposals(){return ge()?_(()=>n.listProposalsJson()):[]},previewProposal(d){return _(()=>n.previewProposalJson(JSON.stringify({id:d})))},layoutProposalDiffSlide(d,p){return _(()=>o.layoutProposalDiffSlideJson(n,d,p))},layoutProposalSlide(d,p){return _(()=>o.layoutProposalSlideJson(n,d,p))},acceptProposal(d,p){return _(()=>n.acceptProposalJson(JSON.stringify({id:d,force:p?.force??false})),true)},rejectProposal(d){return _(()=>n.rejectProposalJson(JSON.stringify({id:d})))},get clientId(){return A(()=>n.clientId)},snapshot(){return _(()=>n.snapshotJson())},story(d){return _(()=>n.storyJson(JSON.stringify({storyId:d})))},registerFont(d){return A(()=>$e(o,d))},layoutSlide(d){return _(()=>o.layoutSlideJson(n,d))},hitTest(d,p){return _(()=>o.hitTestJson(d,p))},mediaBytes(d){return A(()=>n.mediaBytes(d))},save(){return A(()=>n.saveBytes())},insertText(d,p,y,x={}){return _(()=>n.insertTextJson(JSON.stringify({storyId:d,index:p,text:y,style:x})),true)},deleteText(d,p,y){return _(()=>n.deleteTextJson(JSON.stringify({storyId:d,start:p,end:y})),true)},formatText(d,p,y,x){return _(()=>n.formatTextJson(JSON.stringify({storyId:d,start:p,end:y,patch:x})),true)},insertParagraphBreak(d,p){return _(()=>n.insertParagraphBreakJson(JSON.stringify({storyId:d,index:p})),true)},setParagraphAlignment(d,p,y,x){return _(()=>n.setParagraphAlignmentJson(JSON.stringify({storyId:d,start:p,end:y,alignment:x})),true)},insertSlide(d,p){return _(()=>n.insertSlideJson(JSON.stringify({index:d,layoutPartPath:p??null})),true)},deleteSlide(d){return _(()=>n.deleteSlideJson(JSON.stringify({slideId:d})),true)},moveSlide(d,p){return _(()=>n.moveSlideJson(JSON.stringify({slideId:d,toIndex:p})),true)},setSlideNotes(d,p){_(()=>n.setSlideNotesJson(JSON.stringify({slideId:d,text:p})),true);},addComment(d,p){return _(()=>n.addCommentJson(JSON.stringify({slideId:d,author:p.author,initials:p.initials??"",text:p.text,created:p.created,xEmu:p.xEmu??0,yEmu:p.yEmu??0})),true)},replyToComment(d,p){return _(()=>n.replyToCommentJson(JSON.stringify({commentId:d,author:p.author,initials:p.initials??"",text:p.text,created:p.created})),true)},setCommentStatus(d,p){return _(()=>n.setCommentStatusJson(JSON.stringify({commentId:d,resolved:p})),true)},removeComment(d){return _(()=>n.removeCommentJson(JSON.stringify({commentId:d})),true)},setCommentFlavor(d){return _(()=>n.setCommentFlavorJson(JSON.stringify({flavor:d})),true)},comments(){return _(()=>n.commentsJson())},addTextBox(d,p){return _(()=>n.addTextBoxJson(JSON.stringify({slideId:d,draft:p})),true)},addShape(d,p){return _(()=>n.addShapeJson(JSON.stringify({slideId:d,draft:p})),true)},setShapeFill(d,p,y){return _(()=>n.setShapeFillJson(JSON.stringify({slideId:d,shapeId:p,color:y})),true)},setShapeStroke(d,p,y){return _(()=>n.setShapeStrokeJson(JSON.stringify({slideId:d,shapeId:p,stroke:y})),true)},setShapeAdjust(d,p,y){return _(()=>n.setShapeAdjustJson(JSON.stringify({slideId:d,shapeId:p,adjustments:y})),true)},removeShape(d,p){return _(()=>n.removeShapeJson(JSON.stringify({slideId:d,shapeId:p})),true)},moveShape(d,p,y,x){return _(()=>n.moveShapeJson(JSON.stringify({slideId:d,shapeId:p,x:y,y:x})),true)},resizeShape(d,p,y,x){return _(()=>n.resizeShapeJson(JSON.stringify({slideId:d,shapeId:p,width:y,height:x})),true)},setShapeRect(d,p,y){return _(()=>n.setShapeRectJson(JSON.stringify({slideId:d,shapeId:p,rect:y})),true)},canUndo(){return A(()=>n.canUndo())},canRedo(){return A(()=>n.canRedo())},undo(){return _(()=>n.undoJson(),true)},redo(){return _(()=>n.redoJson(),true)},encodeStateVector(){return A(()=>n.encodeStateVector())},encodeStateAsUpdate(d){return A(()=>d===void 0?n.encodeStateAsUpdate():n.encodeDiff(d))},encodeDiff(d){return A(()=>n.encodeDiff(d))},applyUpdate(d){return _(()=>n.applyUpdateJson(d),true)},onUpdate(d){if(C(),typeof d!="function")throw new TypeError("update listener must be a function");let p=c++;i.set(p,d);try{N();}catch(x){throw i.delete(p),x}let y=true;return ()=>{y&&(y=false,i.delete(p),B());}},dispose(){if(s)return;s=true,i.clear(),a.length=0;let d;if(u){try{n.clearUpdateObservation();}catch(p){d=p;}u=false;}try{o.free();}catch(p){d??(d=p);}try{n.free();}catch(p){d??(d=p);}if(d!==void 0)throw X(d)}}}function $e(t,e){try{return t.registerFont(e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(r){throw X(r)}}function re(){if(!_e)throw new Error("pptx wasm is not initialized; call initWasm() first")}function sn(){let t=globalThis.crypto;if(!t||typeof t.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let e=new Uint32Array(2),r;do t.getRandomValues(e),r=(e[0]&2097151)*4294967296+e[1];while(r===0);return r}function be(t){try{return t()}catch(e){throw X(e)}}function an(t){try{return JSON.parse(t())}catch(e){throw X(e)}}function ln(t){return an(t)}function X(t){if(t instanceof Error)return t;if(typeof t=="string")try{let e=JSON.parse(t);if(e.code==="staleProposal"&&Array.isArray(e.targets)&&e.targets.every(r=>typeof r=="string"))return new Y(e.targets)}catch{}return new Error(typeof t=="string"?t:String(t))}var dn=33554432;function pn(t){if(Be(t)){if(t.byteLength>33554432)throw new Error("TIFF image exceeds the browser transfer budget");return new Blob([qe(t).slice()],{type:"image/png"})}let e=un(t);return e?new Blob([e],{type:"image/bmp"}):new Blob([t.slice()])}function un(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(e.byteLength<18)return;let r=e.getUint32(0,true)===2596720087?22:0;if(e.byteLength<r+18||![1,2].includes(e.getUint16(r,true))||e.getUint16(r+2,true)!==9||e.getUint16(r+4,true)!==768||e.getUint32(r+6,true)*2!==e.byteLength-r)return;let n=0,o=0,i=0,a=0,c=false,s;for(let u=r+18;u+6<=e.byteLength;){let f=e.getUint32(u,true)*2,v=e.getUint16(u+4,true);if(f<6||f>e.byteLength-u)return;if(v===0)return f===6&&u+f===e.byteLength?s:void 0;if(s)return;if(v===259){if(f<8||e.getUint16(u+6,true)!==8)return;c=true;}else if(v===263){if(f<8||![1,2,3,4].includes(e.getUint16(u+6,true)))return}else if(v===523||v===524){if(f!==10)return;let C=e.getInt16(u+6,true),T=e.getInt16(u+8,true);if(v===523)n=T,o=C;else {if(!c)return;i=T,a=C;}}else if(v===2881){if(f<66||e.getUint32(u+6,true)!==13369376||e.getInt16(u+14,true)!==0||e.getInt16(u+16,true)!==0||e.getInt16(u+18,true)!==a||e.getInt16(u+20,true)!==i||e.getInt16(u+22,true)!==o||e.getInt16(u+24,true)!==n||!i||!a||(s=fn(t.subarray(u+26,u+f),e.getInt16(u+12,true),e.getInt16(u+10,true)),!s))return}else return;u+=f;}}function fn(t,e,r){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),o=n.getInt32(4,true),i=n.getInt32(8,true),a=n.getUint16(14,true);if(n.getUint32(0,true)!==40||o<1||!i||o*Math.abs(i)>dn||e!==o||r!==Math.abs(i)||n.getUint16(12,true)!==1||![24,32].includes(a)||n.getUint32(16,true)!==0||n.getUint32(32,true)!==0)return;let c=Math.ceil(o*a/32)*4*Math.abs(i),s=n.getUint32(20,true);if(40+c!==t.length||s!==0&&s!==c)return;let u=new Uint8Array(14+t.length),f=new DataView(u.buffer);return f.setUint16(0,19778,true),f.setUint32(2,u.length,true),f.setUint32(10,54,true),u.set(t,14),u}async function hn(t,e={}){let{scale:r=1,resolveImage:n}=e;if(!Number.isFinite(r)||r<=0)throw new Error("scale must be finite and positive");let o=mn(t,r),i=o.getContext("2d");if(!i)throw new Error("2d canvas context unavailable");return await ue(i,t,1,r,{resolveImage:n}),_n(o)}function mn(t,e){let r=Math.round(t.width*e),n=Math.round(t.height*e);if(typeof OffscreenCanvas=="function")return new OffscreenCanvas(r,n);if(typeof document>"u")throw new Error("no canvas backend in this environment");let o=document.createElement("canvas");return pe(o,t,1,e),o}function _n(t){return "convertToBlob"in t?t.convertToBlob({type:"image/png"}):new Promise((e,r)=>{t.toBlob(n=>{n?e(n):r(new Error("canvas produced no png"));},"image/png");})}var Ye=3e3;var Ge=["#B3261E","#7B1FA2","#3949AB","#00796B","#2E7D32","#A84400","#C2185B","#00695C"],gn=/^#[0-9a-fA-F]+$/;function ye(t){return Ge[Math.abs(t)%Ge.length]}function we(t,e){return typeof e=="string"&&(e.length===4||e.length===7)&&gn.test(e)?e:ye(t)}function Ke(t,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 r=e?.name.trim().slice(0,1024)||`Guest ${t.toString(36).toUpperCase()}`,n=we(t,e?.color);return {name:r,color:n}}function Se(t,e){return t?.slideId===e?.slideId&&t?.shapeId===e?.shapeId}var oe=class{constructor(e,r={}){m(this,"localClientId",e);m(this,"states",new Map);m(this,"clocks",new Map);m(this,"maxTrackedIds");if(this.maxTrackedIds=r.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,r)=>e.state.clientId-r.state.clientId).map(bn)}get trackedIdCount(){return this.clocks.size}get nextExpiryAt(){let e;for(let r of this.states.values()){let n=r.lastSeen+45e3;e=e===void 0?n:Math.min(e,n);}for(let r of this.clocks.values()){let n=r.updatedAt+3e5;e=e===void 0?n:Math.min(e,n);}return e}apply(e,r){let n=this.expire(r);for(let o of e){if(o.clientId===this.localClientId)continue;let i=this.clocks.get(o.clientId);if(i&&o.clock<=i.clock)continue;if(!i&&this.clocks.size>=this.maxTrackedIds&&(n=this.evictOldest()||n),this.clocks.delete(o.clientId),this.clocks.set(o.clientId,{clock:o.clock,updatedAt:r}),!o.state){n=this.states.delete(o.clientId)||n;continue}let a=this.states.get(o.clientId),c=a&&Se(a.state.cursor,o.state.cursor)?a.cursorMovedAt:r;this.states.set(o.clientId,{state:Qe(o.state),lastSeen:r,cursorMovedAt:c}),n=true;}return n}expire(e,r=45e3){let n=false;for(let[o,i]of this.states)e-i.lastSeen<r||(this.states.delete(o),n=true);for(let[o,i]of this.clocks)e-i.updatedAt<3e5||(this.clocks.delete(o),n=this.states.delete(o)||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 Qe(t){return {clientId:t.clientId,clock:t.clock,user:{...t.user},cursor:t.cursor?{...t.cursor}:null}}function bn(t){return {state:Qe(t.state),lastSeen:t.lastSeen,cursorMovedAt:t.cursorMovedAt}}var k=16777216,H=4096,et=0,tt=1,wn=2,nt=3,rt=0,ot=1,it=2,Sn=0,vn=Number.MAX_SAFE_INTEGER,S=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},ie=class{constructor(e){m(this,"bytes",e);m(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,r=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new S("Truncated varUint");let o=this.bytes[this.offset++],i=o&127;if(i>Math.floor((vn-e)/r))throw new S("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=i*r,n+=1,(o&128)===0){if(n>1&&i===0)throw new S("Non-canonical varUint");return e}if(n>=8)throw new S("varUint exceeds Number.MAX_SAFE_INTEGER");r*=128;}}readVarUint8Array(){let e=this.readVarUint(),r=this.bytes.byteLength-this.offset;if(e>r)throw new S("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(r){throw new S(`Invalid UTF-8 string${r instanceof Error?`: ${r.message}`:""}`)}}};function R(t){if(!Number.isSafeInteger(t)||t<0)throw new S("varUint value must be a non-negative safe integer");let e=[],r=t;for(;r>=128;)e.push(r%128|128),r=Math.floor(r/128);return e.push(r),Uint8Array.from(e)}function Pn(t){let e=new TextEncoder().encode(t);return Q([R(e.byteLength),e],k)}function Q(t,e){let r=0;for(let i of t)if(r+=i.byteLength,r>e)throw new S(`Frame exceeds ${e} bytes`);let n=new Uint8Array(r),o=0;for(let i of t)n.set(i,o),o+=i.byteLength;return n}function xe(t,e,r){return Q([R(et),R(t),R(e.byteLength),e],r)}function st(t,e=k){return xe(rt,t,e)}function at(t,e=k){return xe(ot,t,e)}function lt(t,e=k){return xe(it,t,e)}function ct(t,e=k){if(t.length>H)throw new S(`Awareness update exceeds ${H} entries`);let r=[R(t.length)];for(let o of t){ht(o);let i=JSON.stringify(o.state);if(i===void 0)throw new S("Awareness state is not JSON serializable");r.push(R(o.clientId),R(o.clock),Pn(i));}let n=Q(r,e);return Q([R(tt),R(n.byteLength),n],e)}function dt(t=k){return Q([R(nt)],t)}function pt(t,e=H){if(!(t instanceof Uint8Array))throw new S("Awareness update must be a Uint8Array");if(!Number.isSafeInteger(e)||e<1)throw new S("Awareness entry limit must be a positive integer");let r=new ie(t),n=r.readVarUint();if(n>e)throw new S(`Awareness update exceeds ${e} entries`);let o=[];for(let i=0;i<n;i+=1){let a=r.readVarUint(),c=r.readVarUint(),s;try{s=JSON.parse(r.readVarString());}catch(f){throw f instanceof S?f:new S(`Invalid awareness JSON${f instanceof Error?`: ${f.message}`:""}`)}let u={clientId:a,clock:c,state:ft(s,a,c)};ht(u),o.push(u);}if(!r.done)throw new S("Awareness update has trailing bytes");return o}function ut(t,e=k,r=H){if(!(t instanceof Uint8Array))throw new S("Frame must be a Uint8Array");if(t.byteLength===0)throw new S("Frame is empty");if(t.byteLength>e)throw new S(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(r)||r<1)throw new S("Message limit must be a positive integer");let n=new ie(t),o=[];for(;!n.done;){if(o.length>=r)throw new S(`Frame exceeds ${r} messages`);let i=n.readVarUint();switch(i){case et:{let a=n.readVarUint(),c=n.readVarUint8Array();if(a===rt)o.push({type:"sync-step-1",stateVector:c});else if(a===ot)o.push({type:"sync-step-2",update:c});else if(a===it)o.push({type:"update",update:c});else throw new S(`Unknown sync message type ${a}`);break}case tt:o.push({type:"awareness",update:n.readVarUint8Array()});break;case wn:{let a=n.readVarUint();if(a!==Sn)throw new S(`Unknown auth message type ${a}`);o.push({type:"auth",reason:n.readVarString()});break}case nt:o.push({type:"query-awareness"});break;default:throw new S(`Unknown top-level message type ${i}`)}}return o}function ft(t,e,r){if(t===null)return null;if(!Pe(t))throw new S("Awareness state must be an object or null");if(t.clientId!==e||t.clock!==r)throw new S("Awareness state identity does not match its entry");if(!Pe(t.user))throw new S("Awareness user must be an object");let n=ve(t.user.name,"Awareness user name"),o=we(e,t.user.color);return {clientId:e,clock:r,user:{name:n,color:o},cursor:xn(t.cursor)}}function xn(t){if(t==null)return null;if(!Pe(t))throw new S("Awareness cursor must be an object or null");let e=ve(t.slideId,"Awareness slideId"),r=t.shapeId===void 0?void 0:ve(t.shapeId,"Awareness shapeId");return r?{slideId:e,shapeId:r}:{slideId:e}}function ht(t){Ze(t.clientId,"Awareness clientId"),Ze(t.clock,"Awareness clock"),t.state!==null&&ft(t.state,t.clientId,t.clock);}function Ze(t,e){if(!Number.isSafeInteger(t)||t<0)throw new S(`${e} must be a non-negative safe integer`)}function ve(t,e){if(typeof t!="string"||t.length===0||t.length>1024)throw new S(`${e} must be between 1 and ${1024} characters`);return t}function Pe(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}var E=class extends Error{constructor(r,n,o){super(n);m(this,"code");m(this,"cause");this.name="CollaborationError",this.code=r,this.cause=o;}};var An=16*1024*1024,Ce=new TextEncoder().encode("\0betteroffice-document-fingerprint-v1\0");function Te(t,e,r){if(!Number.isSafeInteger(e)||e<(r?0:1))throw new RangeError(`${t} must be ${r?"a non-negative":"a positive"} integer`);return e}function En(t){return t instanceof Error&&t.message?t.message:typeof t=="string"&&t?t:"Unknown error"}function P(t,e,r){return r instanceof E?r:new E(t,`${e}: ${En(r)}`,r)}function Ae(t,e){if(!(t instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return t.slice()}function mt(t){let e=Ce.byteLength+32,r=t.byteLength-e;if(r<0)return t;for(let n=0;n<Ce.byteLength;n+=1)if(t[r+n]!==Ce[n])return t;return t.subarray(0,r)}function Ee(t){typeof t=="object"&&t&&"unref"in t&&t.unref();}function In(t){if(!Number.isSafeInteger(t)||t<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return t}function Rn(t){if(t===null)return null;if(!t||typeof t.slideId!="string"||t.slideId.length===0)throw new TypeError("Presence cursor slideId must be a non-empty string");if(t.shapeId!==void 0&&(typeof t.shapeId!="string"||t.shapeId.length===0))throw new TypeError("Presence cursor shapeId must be a non-empty string");return t.shapeId?{slideId:t.slideId,shapeId:t.shapeId}:{slideId:t.slideId}}function Un(t){return t.slideId.length<=1024&&(t.shapeId===void 0||t.shapeId.length<=1024)}var se=class{constructor(e,r,n={}){m(this,"replica");m(this,"transport");m(this,"maxFrameBytes");m(this,"maxMessagesPerFrame");m(this,"maxPendingBytes");m(this,"localClientId");m(this,"localUser");m(this,"remotePresence");m(this,"statusListeners",new Map);m(this,"errorListeners",new Map);m(this,"presenceListeners",new Map);m(this,"pendingFrames",[]);m(this,"unsubscribeReplica");m(this,"unsubscribeTransport",()=>{});m(this,"hasTransportSubscription",false);m(this,"connectionStatus","disconnected");m(this,"isSynced",false);m(this,"wantsConnection",false);m(this,"isOpen",false);m(this,"isDestroyed",false);m(this,"epoch",0);m(this,"connectAttempt",0);m(this,"nextListenerId",0);m(this,"queuedBytes",0);m(this,"isFlushing",false);m(this,"localClock",0);m(this,"reportedClockExhaustion",false);m(this,"localCursor",null);m(this,"lastAwarenessSentAt",0);m(this,"cursorTimer",null);m(this,"heartbeatTimer",null);m(this,"expiryTimer",null);this.replica=e,this.transport=r,this.localClientId=In(e.clientId),this.localUser=Ke(this.localClientId,n.user),this.remotePresence=new oe(this.localClientId),this.maxFrameBytes=Te("maxFrameBytes",n.maxFrameBytes??k,false),this.maxMessagesPerFrame=Te("maxMessagesPerFrame",n.maxMessagesPerFrame??H,false),this.maxPendingBytes=Te("maxPendingBytes",n.maxPendingBytes??An,true);try{this.unsubscribeReplica=e.onUpdate((o,i)=>{i==="local"&&this.forwardLocalUpdate(o);});}catch(o){throw P("replica","Failed to observe replica updates",o)}}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 r=Rn(e),n=!r||Un(r)?r:null;r&&!n&&this.report(new E("protocol",`Presence cursor identifiers exceed ${1024} characters; cursor dropped`)),!Se(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,r=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let n;try{if(n=this.transport.onEvent(o=>this.handleTransportEvent(e,o)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(o){this.failConnection(e,P("transport","Failed to subscribe to transport events",o));return}if(!this.isCurrent(e)){try{n();}catch(o){this.isDestroyed||this.report(P("transport","Failed to unsubscribe from stale transport events",o));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(o=>{this.isCurrent(e)&&this.connectAttempt===r&&this.failConnection(e,P("transport","Transport connect failed",o));});}catch(n){this.failConnection(e,P("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 o=this.epoch;if(this.broadcastLocalPresence(true),!this.isCurrent(o))return}this.stopPresenceTimers(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let r=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(r,true);this.setStatus("disconnected",false);for(let o of n)this.report(o);}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 r=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(r,e);this.setStatus("destroyed",false);for(let o of n)this.report(o);try{this.unsubscribeReplica();}catch(o){this.report(P("replica","Failed to unsubscribe from replica updates",o));}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 r=this.nextListenerId++;return this.statusListeners.set(r,e),()=>this.statusListeners.delete(r)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");let r=this.nextListenerId++;return this.errorListeners.set(r,e),()=>this.errorListeners.delete(r)}onPresence(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("presence listener must be a function");let r=this.nextListenerId++;this.presenceListeners.set(r,e);try{e(this.peers);}catch{}return ()=>this.presenceListeners.delete(r)}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,r){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 o=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(r);for(let i of o)this.report(i);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,r){let n=[];try{e();}catch(o){n.push(P("transport","Failed to unsubscribe from transport events",o));}if(!r)return n;try{let o=this.transport.disconnect();o&&o.catch(i=>{this.isDestroyed||this.report(P("transport","Transport disconnect failed",i));});}catch(o){n.push(P("transport","Transport disconnect failed",o));}return n}handleTransportEvent(e,r){if(this.isCurrent(e))switch(r.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(e,r.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",r.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new E("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 r;try{r=Ae(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,P("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(st(r,this.maxFrameBytes));}catch(n){this.failConnection(e,P("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(dt(this.maxFrameBytes));}catch(n){this.report(P("protocol","Failed to encode awareness query",n));}}handleMessage(e,r){let n;try{n=ut(r.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(o){this.failConnection(e,P("protocol","Invalid collaboration frame",o));return}for(let o of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(o.type){case "sync-step-1":this.respondToSyncStep1(e,o.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,o.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,o.update);break;case "awareness":{try{let i=pt(o.update,this.maxMessagesPerFrame);this.remotePresence.apply(i,Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();}catch(i){this.report(P("protocol","Invalid awareness update",i));}break}case "auth":this.failConnection(e,new E("protocol",o.reason?`Authentication denied: ${o.reason}`:"Authentication denied"));return;case "query-awareness":this.broadcastLocalPresence(false);break}}}respondToSyncStep1(e,r){let n;try{n=Ae(this.replica.encodeStateAsUpdate(mt(r).slice()),"encodeStateAsUpdate");}catch(o){this.failConnection(e,P("replica","Failed to encode replica update",o));return}try{this.sendFrame(at(n,this.maxFrameBytes));}catch(o){this.failConnection(e,P("protocol","Failed to encode SyncStep2",o));}}applyRemoteUpdate(e,r){try{return this.replica.applyUpdate(mt(r).slice()),!0}catch(n){return this.failConnection(e,P("replica","Failed to apply remote update",n)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let r=this.epoch,n;try{n=Ae(e,"Replica update");}catch(o){this.failConnection(r,P("replica","Invalid replica update",o));return}try{this.sendFrame(lt(n,this.maxFrameBytes));}catch(o){this.failConnection(r,P("protocol","Failed to encode update",o));}}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),Ee(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 E("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}this.localClock+=1;let r=this.localClock,n=e?null:{clientId:this.localClientId,clock:r,user:{...this.localUser},cursor:this.localCursor?{...this.localCursor}:null};this.cursorTimer&&clearTimeout(this.cursorTimer),this.cursorTimer=null,this.lastAwarenessSentAt=Date.now();try{let o=ct([{clientId:this.localClientId,clock:r,state:n}],this.maxFrameBytes);e?this.sendLeaveFrameBestEffort(o):this.sendFrame(o);}catch(o){this.report(P("protocol","Failed to encode awareness update",o));}}sendLeaveFrameBestEffort(e){try{this.transport.send(e.slice());}catch{}}startPresenceTimers(){this.stopPresenceTimers(),this.heartbeatTimer=setInterval(()=>{this.broadcastLocalPresence(false);},2e4),Ee(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())),Ee(this.expiryTimer));}clearRemotePresence(){this.remotePresence.clear()&&this.emitPresence();}emitPresence(){let e=this.peers;for(let[r,n]of [...this.presenceListeners])if(this.presenceListeners.get(r)===n)try{n(e);}catch{}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let r=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(r,e);return}let n;try{n=this.transport.send(e.slice());}catch(o){this.failConnection(r,P("transport","Transport send failed",o));return}if(typeof n!="boolean"){this.failConnection(r,new E("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(r)&&this.isOpen&&this.queueFrame(r,e);}queueFrame(e,r){if(r.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new E("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=r.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,r=this.pendingFrames[0],n;try{n=this.transport.send(r.slice());}catch(o){this.failConnection(e,P("transport","Transport send failed",o));return}if(typeof n!="boolean"){this.failConnection(e,new E("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==r)return;this.pendingFrames.shift(),this.queuedBytes-=r.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,r){if(this.connectionStatus===e&&this.isSynced===r)return;this.connectionStatus=e,this.isSynced=r;let n={status:e,synced:r};for(let[o,i]of [...this.statusListeners])if(this.statusListeners.get(o)===i)try{i(n);}catch{}}report(e){for(let[r,n]of [...this.errorListeners])if(this.errorListeners.get(r)===n)try{n(e);}catch{}}};export{E as CollaborationError,se as CollaborationProvider,Ye as PRESENCE_LABEL_DURATION_MS,Y as StaleProposalError,en as initWasm,rn as inspectPresentation,ge as isProposalsAvailable,tn as isWasmAvailable,on as openPresentation,ue as paintSlide,ye as presenceColorForClientId,pn as presentationImageBlob,pe as sizeCanvasForSlide,hn as slideToPng,nn as wasmVersion};
1
+ var Mt=Object.defineProperty;var Ot=(t,e,r)=>e in t?Mt(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var y=(t,e,r)=>Ot(t,typeof e!="symbol"?e+"":e,r);function me(t,e,r=1){return {width:Math.ceil(t.width*r*e),height:Math.ceil(t.height*r*e)}}function be(t,e,r,n=1){let o=me(e,r,n);t.width=o.width,t.height=o.height,t.style.width=`${e.width*n}px`,t.style.height=`${e.height*n}px`;}async function ye(t,e,r=1,n=1,o={}){let i={remaining:o.maxShadowPixels??134217728};if(!Number.isSafeInteger(i.remaining)||i.remaining<0)throw new Error("invalid shadow pixel budget");t.save();try{t.setTransform(r*n,0,0,r*n,0,0),t.clearRect(0,0,e.width,e.height),e.background&&(t.fillStyle=oe(t,e.background,0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height));for(let l of e.primitives)await We(t,l,o,r*n,i);}finally{t.restore();}}async function We(t,e,r,n,o){t.save();try{switch(Lt(t,e),e.kind){case "shape":Xe(t,e,n,o);break;case "image":await qt(t,e,r.resolveImage,n,o);break;case "textBox":nr(t,e,r.textChanges);break;case "placeholder":ar(t,e);break;case "chart":case "table":await Ft(t,e,r,n,o);break}}finally{t.restore();}}async function Ft(t,e,r,n,o){t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip();for(let i of e.primitives)await We(t,i,r,n,o);}function Lt(t,e){let r=e.transform;if(!r)return;let n=e.x+e.w/2,o=e.y+e.h/2;t.translate(n,o),t.rotate((r.rotationDeg??0)*Math.PI/180),t.scale(r.flipH?-1:1,r.flipV?-1:1),t.translate(-n,-o);}function Xe(t,e,r,n){e.clip&&(_e(t,e.clip,e.x,e.y,e.w,e.h),t.clip()),e.shadow&&(e.fill||e.stroke||e.shadow.paths?.some(o=>o.stroke))&&Nt(t,e,r,n),_e(t,e.path,e.x,e.y,e.w,e.h),e.fill&&(t.fillStyle=oe(t,e.fill,e.x,e.y,e.w,e.h),t.fill(e.evenOdd?"evenodd":"nonzero")),e.stroke&&(ze(t,e.stroke,e.x,e.y,e.w,e.h),Vt(t,e));}function Nt(t,e,r,n){let o=e.shadow?.paths?.length?e.shadow.paths.map(i=>({...e,path:i.path,fill:i.fill?e.fill:void 0,stroke:i.stroke,shadow:void 0})):[{...e,shadow:void 0}];He(t,e.shadow,o.flatMap(i=>we(i.path,i)),o.reduce((i,l)=>Math.max(i,l.stroke?.width??0),0),r,n,i=>{for(let l of o)Xe(i,l,r,n);});}function He(t,e,r,n,o,i,l){let d=e.scaleX??1,s=e.scaleY??1,u=t.getTransform(),f={a:u.a*d,b:u.b*s,c:u.c*d,d:u.d*s,e:u.e*d,f:u.f*s};if(!r.length)return;let x=1/0,E=1/0,T=-1/0,N=-1/0;for(let[G,Le]of r){let Ne=f.a*G+f.c*Le+f.e,De=f.b*G+f.d*Le+f.f;x=Math.min(x,Ne),E=Math.min(E,De),T=Math.max(T,Ne),N=Math.max(N,De);}let C=Math.min(Math.max(e.blur??0,0)*o/2,128),m=C*3+1,V=n*o*Math.max(Math.abs(d),Math.abs(s))*2,j=(e.dx??0)*o,z=(e.dy??0)*o,c=Math.floor(Math.max(x-V,-m-j)),p=Math.floor(Math.max(E-V,-m-z)),w=Math.ceil(Math.min(T+V,t.canvas.width+m-j)),S=Math.ceil(Math.min(N+V,t.canvas.height+m-z));if(w<=c||S<=p)return;let O=(w-c)*(S-p);if(!Number.isSafeInteger(O)||O>i.remaining)throw new Error("shadows exceed the pixel budget on one slide");i.remaining-=O;let k=typeof OffscreenCanvas<"u"?new OffscreenCanvas(w-c,S-p):Object.assign(document.createElement("canvas"),{width:w-c,height:S-p}),D=k.getContext("2d");if(D){D.setTransform(f.a,f.b,f.c,f.d,f.e-c,f.f-p),l(D),t.save();try{if(t.setTransform(1,0,0,1,0,0),typeof t.filter=="string")D.setTransform(1,0,0,1,0,0),D.globalCompositeOperation="source-in",D.fillStyle=e.color,D.fillRect(0,0,k.width,k.height),t.filter=`blur(${C}px)`,t.drawImage(k,c+j,p+z);else {let G=t.canvas.width+1;t.shadowColor=e.color,t.shadowBlur=C*2,t.shadowOffsetX=c+j-G,t.shadowOffsetY=z,t.drawImage(k,G,p);}}finally{t.restore();}}}function we(t,e){let r=[];for(let n of t)n.type!=="close"&&(n.type==="quad"?r.push([e.x+n.cpx*e.w,e.y+n.cpy*e.h]):n.type==="cubic"&&(r.push([e.x+n.cp1x*e.w,e.y+n.cp1y*e.h]),r.push([e.x+n.cp2x*e.w,e.y+n.cp2y*e.h])),r.push([e.x+n.x*e.w,e.y+n.y*e.h]));return r.filter((n,o)=>o===0||n[0]!==r[o-1][0]||n[1]!==r[o-1][1])}function Dt(t){return t.path?we(t.path,t):[[t.x,t.y],[t.x+t.w,t.y],[t.x+t.w,t.y+t.h],[t.x,t.y+t.h]]}var Bt=new Set(["triangle","stealth","arrow","diamond","oval"]);function Vt(t,e){let r=e.stroke;if(!r||!r.headEnd&&!r.tailEnd)return;let n=we(e.path,e);if(n.length<2)return;let o=[[r.headEnd,n[1],n[0]],[r.tailEnd,n[n.length-2],n[n.length-1]]];t.save(),t.setLineDash([]);let i=r.paint?oe(t,r.paint,e.x,e.y,e.w,e.h):r.color;t.fillStyle=i,t.strokeStyle=i,t.lineWidth=r.width,t.lineJoin="miter";for(let[l,d,s]of o){if(!l||!Bt.has(l.kind))continue;let[u,f]=[s[0]-d[0],s[1]-d[1]],x=Math.hypot(u,f);x<1e-6||jt(t,l,s,u/x,f/x);}t.restore();}function jt(t,e,[r,n],o,i){let l=e.width/2,[d,s]=[-i*l,o*l],[u,f]=[r-o*e.length,n-i*e.length];switch(t.beginPath(),e.kind){case "triangle":t.moveTo(r,n),t.lineTo(u+d,f+s),t.lineTo(u-d,f-s),t.closePath(),t.fill();break;case "stealth":t.moveTo(r,n),t.lineTo(u+d,f+s),t.lineTo(r-o*e.length*.6,n-i*e.length*.6),t.lineTo(u-d,f-s),t.closePath(),t.fill();break;case "arrow":t.moveTo(u+d,f+s),t.lineTo(r,n),t.lineTo(u-d,f-s),t.stroke();break;case "diamond":{let[x,E]=[o*e.length/2,i*e.length/2];t.moveTo(r+x,n+E),t.lineTo(r+d,n+s),t.lineTo(r-x,n-E),t.lineTo(r-d,n-s),t.closePath(),t.fill();break}case "oval":t.ellipse(r,n,e.length/2,l,Math.atan2(i,o),0,Math.PI*2),t.fill();break}}function Wt(t,e,r){if(r.tile){Xt(t,e,r,r.tile);return}let n=r.crop,o=F(n?.left),i=F(n?.top),l=1-o-F(n?.right),d=1-i-F(n?.bottom),s=r.path!==void 0||l!==1||d!==1;if(l<=0||d<=0)return;s&&(t.save(),xe(t,r),t.clip());let u=qe(e),f=$e(e);u>0&&f>0?t.drawImage(e,o*u,i*f,l*u,d*f,r.x,r.y,r.w,r.h):t.drawImage(e,r.x,r.y,r.w,r.h),s&&t.restore();}function Xt(t,e,r,n){let o=qe(e),i=$e(e);if(o<=0||i<=0)return;let l=Math.round(F(r.crop?.left)*o),d=Math.round(F(r.crop?.top)*i),s=o-Math.round(F(r.crop?.right)*o),u=i-Math.round(F(r.crop?.bottom)*i);if(s<=l||u<=d)return;let f=l>0||d>0||s<o||u<i,x=t.createPattern(f?Ht(e,l,d,s-l,u-d):e,"repeat");x&&(t.save(),xe(t,r),t.clip(),x.setTransform(new DOMMatrix().translateSelf(r.x,r.y).scaleSelf(n.scaleX,n.scaleY)),t.fillStyle=x,t.fillRect(r.x,r.y,r.w,r.h),t.restore());}function Ht(t,e,r,n,o){try{let i=Ge(n,o),l=i?.getContext("2d");return !i||!l?t:(l.drawImage(t,e,r,n,o,0,0,n,o),i)}catch{return t}}function xe(t,e){e.path?_e(t,e.path,e.x,e.y,e.w,e.h):(t.beginPath(),t.rect(e.x,e.y,e.w,e.h));}function F(t){return t===void 0||!Number.isFinite(t)?0:Math.min(Math.max(t,0),1)}function qe(t){return "naturalWidth"in t&&typeof t.naturalWidth=="number"?t.naturalWidth:"width"in t&&typeof t.width=="number"?t.width:0}function $e(t){return "naturalHeight"in t&&typeof t.naturalHeight=="number"?t.naturalHeight:"height"in t&&typeof t.height=="number"?t.height:0}function _e(t,e,r,n,o,i){t.beginPath();for(let l of e)switch(l.type){case "move":t.moveTo(r+l.x*o,n+l.y*i);break;case "line":t.lineTo(r+l.x*o,n+l.y*i);break;case "quad":t.quadraticCurveTo(r+l.cpx*o,n+l.cpy*i,r+l.x*o,n+l.y*i);break;case "cubic":t.bezierCurveTo(r+l.cp1x*o,n+l.cp1y*i,r+l.cp2x*o,n+l.cp2y*i,r+l.x*o,n+l.y*i);break;case "close":t.closePath();break}}function ze(t,e,r,n,o,i){t.strokeStyle=e.paint?oe(t,e.paint,r,n,o,i):e.color,t.lineWidth=e.width,t.setLineDash(e.dashed?[Math.max(3,e.width*2),Math.max(2,e.width)]:[]),t.lineJoin=e.join??"miter",t.stroke();}function oe(t,e,r,n,o,i){if(e.kind==="solid")return e.color;let l=(e.angleDeg??0)*Math.PI/180,d=r+o/2,s=n+i/2,u=Math.hypot(o,i)/2,f=e.gradientType==="linear"?t.createLinearGradient(d-Math.cos(l)*u,s-Math.sin(l)*u,d+Math.cos(l)*u,s+Math.sin(l)*u):t.createRadialGradient(d,s,0,d,s,u);for(let x of e.stops)f.addColorStop(Math.max(0,Math.min(1,x.position)),x.color);return f}async function qt(t,e,r,n,o){let i;if(e.assetId&&r){let l=await $t(r,e.assetId);l&&(i=e.effects?.length?er(l,e.effects):l);}if(e.shadow&&(i||e.stroke||e.shadow.paths?.some(l=>l.stroke))){let l=e.shadow.paths?.length?e.shadow.paths.map(d=>({image:{...e,path:d.path,stroke:d.stroke},source:d.fill?i:void 0})):[{image:e,source:i}];He(t,e.shadow,l.flatMap(d=>Dt(d.image)),l.reduce((d,s)=>Math.max(d,s.image.stroke?.width??0),0),n,o,d=>{for(let s of l)Be(d,s.image,s.source);});}Be(t,e,i);}async function $t(t,e){try{return await t(e)}catch{return null}}function Be(t,e,r){r&&Wt(t,r,e),e.stroke&&(xe(t,e),ze(t,e.stroke,e.x,e.y,e.w,e.h));}var Ve=33554432,zt=67108864;function Gt(t){let e=t,r=e.naturalWidth??e.videoWidth??e.displayWidth??(typeof e.width=="number"?e.width:0),n=e.naturalHeight??e.videoHeight??e.displayHeight??(typeof e.height=="number"?e.height:0);return r>0&&n>0?{width:r,height:n}:null}function Yt(t){let e=t.width*t.height;if(e<=Ve)return t;let r=Math.sqrt(Ve/e);return {width:Math.max(1,Math.floor(t.width*r)),height:Math.max(1,Math.floor(t.height*r))}}var ge=new WeakMap,W=[],fe=0;function Kt(t){let e=t;return "videoWidth"in e||"displayWidth"in e||typeof e.getContext=="function"}function Zt(t,e){let r=ge.get(t),n=r?.get(e);if(!r||!n)return;let o=W.findIndex(i=>i.entries===r&&i.key===e);return o>=0&&W.push(...W.splice(o,1)),n}function Qt(t,e,r,n){let o=ge.get(t);for(o||(o=new Map,ge.set(t,o)),o.set(e,r),W.push({entries:o,key:e,pixels:n}),fe+=n;fe>zt&&W.length>1;){let i=W.shift();if(!i)break;i.entries.delete(i.key),fe-=i.pixels;}}function Ge(t,e){if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(t,e);if(typeof document>"u")return null;let r=document.createElement("canvas");return r.width=t,r.height=e,r}function er(t,e){let r=Gt(t);if(!r)return t;let n=JSON.stringify(e),o=!Kt(t);if(o){let l=Zt(t,n);if(l)return l}let i=Yt(r);try{let l=Ge(i.width,i.height),d=l?.getContext("2d");if(!l||!d)return t;d.drawImage(t,0,0,i.width,i.height);let s=d.getImageData(0,0,i.width,i.height);rr(s.data,e),d.putImageData(s,0,0);let u=l;return o&&Qt(t,n,u,i.width*i.height),u}catch{return t}}function he(t,e){return .299*t[e]+.587*t[e+1]+.114*t[e+2]}function tr(t,e){let r=Math.min(Math.max(e,-1),1),n=r>=0?128/(128-127*r):(128+127*r)/128,o=128-128*n+255*Math.min(Math.max(t,-1),1)*(1+n)/2,i=new Uint8ClampedArray(256);for(let l=0;l<256;l+=1)i[l]=Math.round(n*l+o);return i}function ne(t){let e=t.startsWith("#")?t.slice(1):t,r=e.length===3||e.length===4?[...e].map(i=>i+i).join(""):e;if(r.length!==6&&r.length!==8)return null;let n=i=>Number.parseInt(r.slice(i,i+2),16),o=[n(0),n(2),n(4),r.length===8?n(6):255];return o.some(Number.isNaN)?null:o}function rr(t,e){for(let r of e)switch(r.kind){case "biLevel":{let n=Math.min(Math.max(r.threshold,0),1)*255;for(let o=0;o<t.length;o+=4){let i=he(t,o)<n?0:255;t[o]=i,t[o+1]=i,t[o+2]=i;}break}case "alpha":{let n=Math.min(Math.max(r.amount,0),1);for(let o=3;o<t.length;o+=4)t[o]=Math.round(t[o]*n);break}case "grayscale":{for(let n=0;n<t.length;n+=4){let o=Math.round(he(t,n));t[n]=o,t[n+1]=o,t[n+2]=o;}break}case "luminance":{let n=tr(r.brightness,r.contrast);for(let o=0;o<t.length;o+=4)t[o]=n[t[o]],t[o+1]=n[t[o+1]],t[o+2]=n[t[o+2]];break}case "duotone":{let n=ne(r.shadow),o=ne(r.highlight);if(!n||!o)break;for(let i=0;i<t.length;i+=4){let l=he(t,i)/255;for(let s=0;s<3;s+=1)t[i+s]=Math.round(n[s]*(1-l)+o[s]*l);let d=n[3]*(1-l)+o[3]*l;t[i+3]=Math.round(t[i+3]*d/255);}break}case "colorChange":{let n=ne(r.from),o=ne(r.to);if(!n||!o)break;for(let i=0;i<t.length;i+=4)t[i]!==n[0]||t[i+1]!==n[1]||t[i+2]!==n[2]||r.useAlpha!==false&&t[i+3]!==n[3]||(t[i]=o[0],t[i+1]=o[1],t[i+2]=o[2],r.useAlpha!==false&&(t[i+3]=o[3]));break}}}function nr(t,e,r=[]){e.overflow||(t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip()),t.textAlign="left",t.textBaseline="alphabetic";let n=r.filter(i=>i.storyId===e.storyId);je(t,e,n,false);let o=e.textShadow;o&&(t.save(),t.shadowColor=o.color,t.shadowBlur=Math.max(o.blur??0,0),t.shadowOffsetX=o.dx??0,t.shadowOffsetY=o.dy??0);for(let i of e.lines)for(let l of i.runs)or(t,l,i.baseline);o&&t.restore(),je(t,e,n,true);}function je(t,e,r,n){if(r.length!==0)for(let o of e.lines)for(let i of o.runs)for(let l of r){let d=Math.max(i.start,l.start),s=Math.min(i.end,l.end);if(d>=s)continue;let u=o.caretStops.filter(T=>T.position>=d&&T.position<=s),f=u.length>1?Math.max(i.x,Math.min(...u.map(T=>T.x))):i.x,x=u.length>1?Math.min(i.x+i.width,Math.max(...u.map(T=>T.x))):i.x+i.width;if(x<=f)continue;let E=l.kind==="insertion";if(n){t.fillStyle=E?"#166534":"#b91c1c";let N=o.baseline-(i.baselineOffsetPx??0)+i.fontSizePx*(E?.08:-0.3);t.fillRect(f,N,x-f,Math.max(1,i.fontSizePx*.05));}else t.fillStyle=E?"#dcfce7cc":"#fee2e2cc",t.fillRect(f,o.y,x-f,o.height);}}function or(t,e,r){let n=e.italic?"italic ":"",o=e.bold?"bold ":"";t.font=`${n}${o}${e.fontSizePx}px ${sr(e.fontFamily)}`,t.fillStyle=e.color;let i=e.letterSpacingPx??0;t.letterSpacing=i===0?"0px":`${i}px`;let l=r-(e.baselineOffsetPx??0);for(let d of ir(e))t.fillText(d.text,d.x,l);t.letterSpacing="0px",e.underline&&t.fillRect(e.x,l+e.fontSizePx*.08,e.width,Math.max(1,e.fontSizePx*.05));}function ir(t){if(t.glyphs.length===0)return [{text:t.text,x:t.x}];if(t.glyphs.length>1&&t.glyphs[1].x<t.glyphs[0].x){let i=t.text.split(" "),l=[],d=-1;for(let u of i)d+=u.length+1,l.push(d);let s=i.map(()=>1/0);for(let u of t.glyphs){let f=u.cluster-t.start,x=0,E=l.length-1;for(;x<E;){let T=x+E>>1;l[T]<f?x=T+1:E=T;}f>=0&&f<l[x]&&(s[x]=Math.min(s[x],u.x));}return i.flatMap((u,f)=>u.length>0&&s[f]<1/0?[{text:u,x:s[f]}]:[])}let e=[],r=0,n=t.x,o=t.x;for(let i of t.glyphs){let l=i.cluster-t.start;l>r&&l<t.text.length&&Math.abs(i.x-o)>1e-4&&(e.push({text:t.text.slice(r,l),x:n}),r=l,n=i.x),o=Math.fround(Math.fround(i.x)+Math.fround(i.advance));}return e.push({text:t.text.slice(r),x:n}),e}function sr(t){return t.includes(" ")?JSON.stringify(t):t}function ar(t,e){t.strokeStyle="#8a94a6",t.lineWidth=1,t.setLineDash([5,4]),t.strokeRect(e.x,e.y,e.w,e.h),e.label&&(t.setLineDash([]),t.fillStyle="#5d6675",t.font="12px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(e.label,e.x+e.w/2,e.y+e.h/2,Math.max(0,e.w-12)));}function Ye(t){return t.length>=4&&(t[0]===73&&t[1]===73&&t[2]===42&&t[3]===0||t[0]===77&&t[1]===77&&t[2]===0&&t[3]===42)}var A=class t{static __wrap(e){let r=Object.create(t.prototype);return r.__wbg_ptr=e,Ke.register(r,r.__wbg_ptr,r),r}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ke.unregister(this),e}free(){let e=this.__destroy_into_raw();a.__wbg_pptxdocument_free(e,0);}acceptProposalJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_acceptProposalJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}addCommentJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_addCommentJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}addPictureJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_addPictureJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}addShapeJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_addShapeJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}addTextBoxJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_addTextBoxJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}addTextBoxProfiledJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_addTextBoxProfiledJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}addUndoBoundary(){a.pptxdocument_addUndoBoundary(this.__wbg_ptr);}anchorCaretJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_anchorCaretJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}applyEditsJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_applyEditsJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}applyUpdateJson(e){let r,n;try{let l=R(e,a.__wbindgen_malloc),d=_,s=a.pptxdocument_applyUpdateJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}bringShapeForwardJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_bringShapeForwardJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}bringShapeToFrontJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_bringShapeToFrontJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}canRedo(){return a.pptxdocument_canRedo(this.__wbg_ptr)!==0}canUndo(){return a.pptxdocument_canUndo(this.__wbg_ptr)!==0}clearUpdateObservation(){a.pptxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return a.pptxdocument_clientId(this.__wbg_ptr)}commentsJson(){let e,r;try{let i=a.pptxdocument_commentsJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{a.__wbindgen_free(e,r,1);}}deleteSlideJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_deleteSlideJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}deleteTextJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_deleteTextJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}deleteTextProfiledJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_deleteTextProfiledJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}documentVersion(){let e,r;try{let n=a.pptxdocument_documentVersion(this.__wbg_ptr);return e=n[0],r=n[1],g(n[0],n[1])}finally{a.__wbindgen_free(e,r,1);}}drainUpdateEvent(){let e=a.pptxdocument_drainUpdateEvent(this.__wbg_ptr);var r=L(e[0],e[1]).slice();return a.__wbindgen_free(e[0],e[1]*1,1),r}encodeDiff(e){let r=R(e,a.__wbindgen_malloc),n=_,o=a.pptxdocument_encodeDiff(this.__wbg_ptr,r,n);if(o[3])throw h(o[2]);var i=L(o[0],o[1]).slice();return a.__wbindgen_free(o[0],o[1]*1,1),i}encodeStateAsUpdate(){let e=a.pptxdocument_encodeStateAsUpdate(this.__wbg_ptr);var r=L(e[0],e[1]).slice();return a.__wbindgen_free(e[0],e[1]*1,1),r}encodeStateVector(){let e=a.pptxdocument_encodeStateVector(this.__wbg_ptr);var r=L(e[0],e[1]).slice();return a.__wbindgen_free(e[0],e[1]*1,1),r}exportMarkdownJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_exportMarkdownJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}exportStructuredJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_exportStructuredJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}findTextJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_findTextJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}formatTextJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_formatTextJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}insertParagraphBreakJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_insertParagraphBreakJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}insertSlideJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_insertSlideJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}insertSlideProfiledJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_insertSlideProfiledJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}insertTextJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_insertTextJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}insertTextProfiledJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_insertTextProfiledJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}listProposalsJson(){let e,r;try{let i=a.pptxdocument_listProposalsJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{a.__wbindgen_free(e,r,1);}}mediaBytes(e){let r=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),n=_,o=a.pptxdocument_mediaBytes(this.__wbg_ptr,r,n);if(o[3])throw h(o[2]);var i=L(o[0],o[1]).slice();return a.__wbindgen_free(o[0],o[1]*1,1),i}moveShapeJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_moveShapeJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}moveShapeProfiledJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_moveShapeProfiledJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}moveSlideJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_moveSlideJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}static openCollaborative(e,r){let n=R(e,a.__wbindgen_malloc),o=_,i=a.pptxdocument_openCollaborative(n,o,r);if(i[2])throw h(i[1]);return t.__wrap(i[0])}static openCollaborativeFromUpdate(e,r,n){let o=R(e,a.__wbindgen_malloc),i=_;var l=pr(n)?0:R(n,a.__wbindgen_malloc),d=_;let s=a.pptxdocument_openCollaborativeFromUpdate(o,i,r,l,d);if(s[2])throw h(s[1]);return t.__wrap(s[0])}previewProposalJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_previewProposalJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}proposeJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_proposeJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}readContentJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_readContentJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}redoJson(){let e,r;try{let i=a.pptxdocument_redoJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{a.__wbindgen_free(e,r,1);}}rejectProposalJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_rejectProposalJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}removeCommentJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_removeCommentJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}removeShapeJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_removeShapeJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}replyToCommentJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_replyToCommentJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}resizeShapeJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_resizeShapeJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}resolveCaretAnchorJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_resolveCaretAnchorJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}saveBytes(){let e=a.pptxdocument_saveBytes(this.__wbg_ptr);if(e[3])throw h(e[2]);var r=L(e[0],e[1]).slice();return a.__wbindgen_free(e[0],e[1]*1,1),r}searchTextJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_searchTextJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}sendShapeBackwardJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_sendShapeBackwardJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}sendShapeToBackJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_sendShapeToBackJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setCommentFlavorJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setCommentFlavorJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setCommentPositionJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setCommentPositionJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setCommentStatusJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setCommentStatusJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setParagraphAlignmentJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setParagraphAlignmentJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setShapeAdjustJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setShapeAdjustJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setShapeFillJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setShapeFillJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setShapeRectJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setShapeRectJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setShapeStrokeJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setShapeStrokeJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setSlideNotesJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_setSlideNotesJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}setUndoCaptureMode(e){let r=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),n=_,o=a.pptxdocument_setUndoCaptureMode(this.__wbg_ptr,r,n);if(o[1])throw h(o[0])}snapshotJson(){let e,r;try{let i=a.pptxdocument_snapshotJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{a.__wbindgen_free(e,r,1);}}startUpdateObservation(){let e=a.pptxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw h(e[0])}storyJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_storyJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}undoCaptureMode(){let e,r;try{let n=a.pptxdocument_undoCaptureMode(this.__wbg_ptr);return e=n[0],r=n[1],g(n[0],n[1])}finally{a.__wbindgen_free(e,r,1);}}undoJson(){let e,r;try{let i=a.pptxdocument_undoJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{a.__wbindgen_free(e,r,1);}}undoProfiledJson(){let e,r;try{let i=a.pptxdocument_undoProfiledJson(this.__wbg_ptr);var n=i[0],o=i[1];if(i[3])throw n=0,o=0,h(i[2]);return e=n,r=o,g(n,o)}finally{a.__wbindgen_free(e,r,1);}}validateEditsJson(e){let r,n;try{let l=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=a.pptxdocument_validateEditsJson(this.__wbg_ptr,l,d);var o=s[0],i=s[1];if(s[3])throw o=0,i=0,h(s[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}static version(){let e,r;try{let n=a.pptxdocument_version();return e=n[0],r=n[1],g(n[0],n[1])}finally{a.__wbindgen_free(e,r,1);}}};Symbol.dispose&&(A.prototype[Symbol.dispose]=A.prototype.free);var B=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,Ze.unregister(this),e}free(){let e=this.__destroy_into_raw();a.__wbg_pptxrenderer_free(e,0);}hitTestJson(e,r){let n,o;try{let d=a.pptxrenderer_hitTestJson(this.__wbg_ptr,e,r);var i=d[0],l=d[1];if(d[3])throw i=0,l=0,h(d[2]);return n=i,o=l,g(i,l)}finally{a.__wbindgen_free(n,o,1);}}layoutProposalDiffSlideJson(e,r,n){let o,i;try{ie(e,A);let s=b(r,a.__wbindgen_malloc,a.__wbindgen_realloc),u=_,f=a.pptxrenderer_layoutProposalDiffSlideJson(this.__wbg_ptr,e.__wbg_ptr,s,u,n);var l=f[0],d=f[1];if(f[3])throw l=0,d=0,h(f[2]);return o=l,i=d,g(l,d)}finally{a.__wbindgen_free(o,i,1);}}layoutProposalSlideJson(e,r,n){let o,i;try{ie(e,A);let s=b(r,a.__wbindgen_malloc,a.__wbindgen_realloc),u=_,f=a.pptxrenderer_layoutProposalSlideJson(this.__wbg_ptr,e.__wbg_ptr,s,u,n);var l=f[0],d=f[1];if(f[3])throw l=0,d=0,h(f[2]);return o=l,i=d,g(l,d)}finally{a.__wbindgen_free(o,i,1);}}layoutSlideJson(e,r){let n,o;try{ie(e,A);let d=a.pptxrenderer_layoutSlideJson(this.__wbg_ptr,e.__wbg_ptr,r);var i=d[0],l=d[1];if(d[3])throw i=0,l=0,h(d[2]);return n=i,o=l,g(i,l)}finally{a.__wbindgen_free(n,o,1);}}layoutSlideProfiledJson(e,r){let n,o;try{ie(e,A);let d=a.pptxrenderer_layoutSlideProfiledJson(this.__wbg_ptr,e.__wbg_ptr,r);var i=d[0],l=d[1];if(d[3])throw i=0,l=0,h(d[2]);return n=i,o=l,g(i,l)}finally{a.__wbindgen_free(n,o,1);}}constructor(){let e=a.pptxrenderer_new();return this.__wbg_ptr=e,Ze.register(this,this.__wbg_ptr,this),this}registerFallbackFont(e,r,n,o){let i=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),l=_,d=R(o,a.__wbindgen_malloc),s=_,u=a.pptxrenderer_registerFallbackFont(this.__wbg_ptr,i,l,r,n,d,s);if(u[2])throw h(u[1]);return u[0]>>>0}registerFont(e,r,n,o){let i=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),l=_,d=R(o,a.__wbindgen_malloc),s=_,u=a.pptxrenderer_registerFont(this.__wbg_ptr,i,l,r,n,d,s);if(u[2])throw h(u[1]);return u[0]>>>0}};Symbol.dispose&&(B.prototype[Symbol.dispose]=B.prototype.free);function Qe(t){let e=R(t,a.__wbindgen_malloc),r=_,n=a.decodeTiffPng(e,r);if(n[3])throw h(n[2]);var o=L(n[0],n[1]).slice();return a.__wbindgen_free(n[0],n[1]*1,1),o}function et(t,e){let r,n;try{let l=R(t,a.__wbindgen_malloc),d=_,s=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),u=_,f=a.exportPptxMarkdownJson(l,d,s,u);var o=f[0],i=f[1];if(f[3])throw o=0,i=0,h(f[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}function tt(t,e){let r,n;try{let l=R(t,a.__wbindgen_malloc),d=_,s=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),u=_,f=a.exportPptxStructuredJson(l,d,s,u);var o=f[0],i=f[1];if(f[3])throw o=0,i=0,h(f[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}function rt(t){let e,r;try{let i=R(t,a.__wbindgen_malloc),l=_,d=a.parsePptxJson(i,l);var n=d[0],o=d[1];if(d[3])throw n=0,o=0,h(d[2]);return e=n,r=o,g(n,o)}finally{a.__wbindgen_free(e,r,1);}}function nt(t,e){let r,n;try{let l=b(t,a.__wbindgen_malloc,a.__wbindgen_realloc),d=_,s=b(e,a.__wbindgen_malloc,a.__wbindgen_realloc),u=_,f=a.renderPptxMarkdownJson(l,d,s,u);var o=f[0],i=f[1];if(f[3])throw o=0,i=0,h(f[2]);return r=o,n=i,g(o,i)}finally{a.__wbindgen_free(r,n,1);}}function ot(){let t,e;try{let r=a.rendererVersion();return t=r[0],e=r[1],g(r[0],r[1])}finally{a.__wbindgen_free(t,e,1);}}function lr(){return {__proto__:null,"./pptx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_throw_344f42d3211c4765:function(e,r){throw new Error(g(e,r))},__wbg_getRandomValues_3f44b700395062e5:function(){return cr(function(e,r){globalThis.crypto.getRandomValues(L(e,r));},arguments)},__wbg_now_546eb6b39d572d7e:function(){return performance.now()},__wbg_now_86c0d4ba3fa605b8:function(){return Date.now()},__wbg_now_f1489d8a2945407f:function(){return performance.now()},__wbg_random_039a7d5d06e0d333:function(){return Math.random()},__wbindgen_cast_0000000000000001:function(e,r){return g(e,r)},__wbindgen_init_externref_table:function(){let e=a.__wbindgen_externrefs,r=e.grow(4);e.set(0,void 0),e.set(r+0,void 0),e.set(r+1,null),e.set(r+2,true),e.set(r+3,false);}}}}var Ke=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>a.__wbg_pptxdocument_free(t,1)),Ze=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>a.__wbg_pptxrenderer_free(t,1));function dr(t){let e=a.__externref_table_alloc();return a.__wbindgen_externrefs.set(e,t),e}function ie(t,e){if(!(t instanceof e))throw new Error(`expected instance of ${e.name}`)}function L(t,e){return t=t>>>0,X().subarray(t/1,t/1+e)}function g(t,e){return fr(t>>>0,e)}var Y=null;function X(){return (Y===null||Y.byteLength===0)&&(Y=new Uint8Array(a.memory.buffer)),Y}function cr(t,e){try{return t.apply(this,e)}catch(r){let n=dr(r);a.__wbindgen_exn_store(n);}}function pr(t){return t==null}function R(t,e){let r=e(t.length*1,1)>>>0;return X().set(t,r/1),_=t.length,r}function b(t,e,r){if(r===void 0){let d=K.encode(t),s=e(d.length,1)>>>0;return X().subarray(s,s+d.length).set(d),_=d.length,s}let n=t.length,o=e(n,1)>>>0,i=X(),l=0;for(;l<n;l++){let d=t.charCodeAt(l);if(d>127)break;i[o+l]=d;}if(l!==n){l!==0&&(t=t.slice(l)),o=r(o,n,n=l+t.length*3,1)>>>0;let d=X().subarray(o+l,o+n),s=K.encodeInto(t,d);l+=s.written,o=r(o,n,l,1)>>>0;}return _=l,o}function h(t){let e=a.__wbindgen_externrefs.get(t);return a.__externref_table_dealloc(t),e}var se=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});se.decode();var ur=2146435072,Pe=0;function fr(t,e){return Pe+=e,Pe>=ur&&(se=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),se.decode(),Pe=e),se.decode(X().subarray(t,t+e))}var K=new TextEncoder;"encodeInto"in K||(K.encodeInto=function(t,e){let r=K.encode(t);return e.set(r),{read:t.length,written:r.length}});var _=0,a;function gr(t,e){return a=t.exports,Y=null,a.__wbindgen_start(),a}async function mr(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(o){if(t.ok&&r(t.type)&&t.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",o);else throw o}let n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}else {let n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}function r(n){switch(n){case "basic":case "cors":case "default":return true}return false}}async function it(t){if(a!==void 0)return a;if(t!==void 0&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),t===void 0)throw new Error("pptx-wasm requires an explicit module or URL");let e=lr();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await mr(await t,e);return gr(r)}var Z=class extends Error{constructor(r){super(`Proposal targets changed: ${r.join(", ")}`);y(this,"targets");this.name="StaleProposalError",this.targets=r;}};var Q=class extends Error{constructor(r){super(r.message);y(this,"failure");this.name="PptxExportError",this.failure=r;}};var Se=false;function ve(){return typeof A.prototype.proposeJson=="function"&&typeof B.prototype.layoutProposalSlideJson=="function"}var ee;function le(t=new URL("./generated/pptx_wasm_bg.wasm",import.meta.url)){return Se?Promise.resolve():ee||(ee=it({module_or_path:t}).then(()=>{Se=true;},e=>{throw ee=void 0,H(e)}),ee)}function br(){return typeof WebAssembly=="object"}function yr(){return de(),ot()}function wr(t){return de(),Er(()=>rt(t))}function Ee(t){let e=at(t);if(!e.ok)throw new Q(e.failure);return e.content}async function xr(t,e={}){await le();let r=J(e);return Ee(()=>tt(t,r))}async function Pr(t,e={}){await le();let r=J(e);return Ee(()=>et(t,r))}async function Sr(t,e={}){await le();let r=J(e);return Ee(()=>nt(JSON.stringify(t),r))}function st(t){return de(),Ce(()=>Qe(t))}function vr(t,e={}){de();let r=e.clientId??Cr(),n=Ce(()=>e.initialUpdate===void 0?A.openCollaborative(t,r):A.openCollaborativeFromUpdate(e.initialUpdate.slice(),r,t.slice())),o=Ce(()=>new B);for(let c of e.fonts??[])ae(o,c);for(let c of e.fallbackFonts??[])ae(o,c,true);let i=new Map,l=[],d=0,s=false,u=false,f=0,x=false,E=()=>{if(s)throw new Error("presentation handle is disposed")},T=()=>{if(!(s||x||f!==0)){x=true;try{for(;!s&&l.length>0;){let c=l.shift();if(!c)break;for(let[p,w]of [...i]){if(s)return;if(i.get(p)===w)try{w(c.update.slice(),c.origin);}catch{}}}}finally{x=false,s&&(l.length=0);}}},N=()=>{if(!(!u||s))for(;;){let c=n.drainUpdateEvent();if(c.byteLength===0)return;let p=c[0];if(p!==0&&p!==1)throw new Error(`pptx wasm returned unknown update origin ${p}`);l.push({update:c.subarray(1),origin:p===0?"local":"remote"});}},C=(c,p=false)=>{E(),f+=1;try{let w,S,O=!1;try{w=c();}catch(k){S=k,O=!0;}if(p)try{N();}catch(k){O||(S=k,O=!0);}if(O)throw H(S);return w}finally{f-=1,f===0&&T();}},m=(c,p=false)=>C(()=>JSON.parse(c()),p),V=()=>{u||(C(()=>n.startUpdateObservation()),u=true);},j=()=>{!u||i.size>0||s||(l.length=0,C(()=>n.clearUpdateObservation()),u=false);};return {isProposalsAvailable:ve,propose(c,p,w){return m(()=>n.proposeJson(JSON.stringify({agentId:c,note:p,edits:w})))},listProposals(){return ve()?m(()=>n.listProposalsJson()):[]},previewProposal(c){return m(()=>n.previewProposalJson(JSON.stringify({id:c})))},layoutProposalDiffSlide(c,p){return m(()=>o.layoutProposalDiffSlideJson(n,c,p))},layoutProposalSlide(c,p){return m(()=>o.layoutProposalSlideJson(n,c,p))},acceptProposal(c,p){return m(()=>n.acceptProposalJson(JSON.stringify({id:c,force:p?.force??false})),true)},rejectProposal(c){return m(()=>n.rejectProposalJson(JSON.stringify({id:c})))},get clientId(){return C(()=>n.clientId)},snapshot(){return m(()=>n.snapshotJson())},story(c){return m(()=>n.storyJson(JSON.stringify({storyId:c})))},anchorCaret(c,p){return m(()=>n.anchorCaretJson(JSON.stringify({storyId:c,index:p})))},resolveCaretAnchor(c){return m(()=>n.resolveCaretAnchorJson(JSON.stringify({storyId:c.storyId,position:c.position})))},version(){return C(()=>n.documentVersion())},readContent(c={}){let p=J(c);return m(()=>n.readContentJson(p))},findText(c){let p=J(c);return m(()=>n.findTextJson(p))},exportStructured(c={}){let p=J(c);return m(()=>n.exportStructuredJson(p))},exportMarkdown(c={}){let p=J(c);return m(()=>n.exportMarkdownJson(p))},validateEdits(c){let p=J(c);return m(()=>n.validateEditsJson(p))},applyEdits(c){let p=J(c);return m(()=>n.applyEditsJson(p),true)},searchText(c,p={}){if(!c)return [];let w=p.limit??Number.POSITIVE_INFINITY;if(!Number.isSafeInteger(w)&&w!==Number.POSITIVE_INFINITY||w<0)throw new RangeError("search limit must be a non-negative safe integer");return m(()=>n.searchTextJson(JSON.stringify({query:c,caseSensitive:p.caseSensitive??false,limit:Number.isFinite(w)?Math.min(w,4294967295):void 0})))},registerFont(c){return C(()=>ae(o,c))},registerFallbackFont(c){return C(()=>ae(o,c,!0))},layoutSlide(c){return m(()=>o.layoutSlideJson(n,c))},layoutSlideProfiled(c){return m(()=>o.layoutSlideProfiledJson(n,c))},hitTest(c,p){return m(()=>o.hitTestJson(c,p))},mediaBytes(c){return C(()=>n.mediaBytes(c))},save(){return C(()=>n.saveBytes())},insertText(c,p,w,S={}){return m(()=>n.insertTextJson(JSON.stringify({storyId:c,index:p,text:w,style:S})),true)},insertTextProfiled(c,p,w,S={}){return m(()=>n.insertTextProfiledJson(JSON.stringify({storyId:c,index:p,text:w,style:S})),true)},deleteText(c,p,w){return m(()=>n.deleteTextJson(JSON.stringify({storyId:c,start:p,end:w})),true)},deleteTextProfiled(c,p,w){return m(()=>n.deleteTextProfiledJson(JSON.stringify({storyId:c,start:p,end:w})),true)},formatText(c,p,w,S){return m(()=>n.formatTextJson(JSON.stringify({storyId:c,start:p,end:w,patch:S})),true)},insertParagraphBreak(c,p){return m(()=>n.insertParagraphBreakJson(JSON.stringify({storyId:c,index:p})),true)},setParagraphAlignment(c,p,w,S){return m(()=>n.setParagraphAlignmentJson(JSON.stringify({storyId:c,start:p,end:w,alignment:S})),true)},insertSlide(c,p){return m(()=>n.insertSlideJson(JSON.stringify({index:c,layoutPartPath:p??null})),true)},insertSlideProfiled(c,p){return m(()=>n.insertSlideProfiledJson(JSON.stringify({index:c,layoutPartPath:p??null})),true)},deleteSlide(c){return m(()=>n.deleteSlideJson(JSON.stringify({slideId:c})),true)},moveSlide(c,p){return m(()=>n.moveSlideJson(JSON.stringify({slideId:c,toIndex:p})),true)},setSlideNotes(c,p){m(()=>n.setSlideNotesJson(JSON.stringify({slideId:c,text:p})),true);},addComment(c,p){return m(()=>n.addCommentJson(JSON.stringify({slideId:c,author:p.author,initials:p.initials??"",text:p.text,created:p.created,xEmu:p.xEmu??0,yEmu:p.yEmu??0})),true)},replyToComment(c,p){return m(()=>n.replyToCommentJson(JSON.stringify({commentId:c,author:p.author,initials:p.initials??"",text:p.text,created:p.created})),true)},setCommentPosition(c,p){if(!Number.isSafeInteger(p.xEmu)||!Number.isSafeInteger(p.yEmu))throw new Error("Comment coordinates must be safe integer EMU");return m(()=>n.setCommentPositionJson(JSON.stringify({commentId:c,...p})),true)},setCommentStatus(c,p){return m(()=>n.setCommentStatusJson(JSON.stringify({commentId:c,resolved:p})),true)},removeComment(c){return m(()=>n.removeCommentJson(JSON.stringify({commentId:c})),true)},setCommentFlavor(c){return m(()=>n.setCommentFlavorJson(JSON.stringify({flavor:c})),true)},comments(){return m(()=>n.commentsJson())},addTextBox(c,p){return m(()=>n.addTextBoxJson(JSON.stringify({slideId:c,draft:p})),true)},addTextBoxProfiled(c,p){return m(()=>n.addTextBoxProfiledJson(JSON.stringify({slideId:c,draft:p})),true)},addShape(c,p){return m(()=>n.addShapeJson(JSON.stringify({slideId:c,draft:p})),true)},addPicture(c,p){return m(()=>n.addPictureJson(JSON.stringify({slideId:c,...p})),true)},setShapeFill(c,p,w){return m(()=>n.setShapeFillJson(JSON.stringify({slideId:c,shapeId:p,color:w})),true)},setShapeStroke(c,p,w){return m(()=>n.setShapeStrokeJson(JSON.stringify({slideId:c,shapeId:p,stroke:w})),true)},setShapeAdjust(c,p,w){return m(()=>n.setShapeAdjustJson(JSON.stringify({slideId:c,shapeId:p,adjustments:w})),true)},removeShape(c,p){return m(()=>n.removeShapeJson(JSON.stringify({slideId:c,shapeId:p})),true)},bringShapeToFront(c,p){return m(()=>n.bringShapeToFrontJson(JSON.stringify({slideId:c,shapeId:p})),true)},sendShapeToBack(c,p){return m(()=>n.sendShapeToBackJson(JSON.stringify({slideId:c,shapeId:p})),true)},bringShapeForward(c,p){return m(()=>n.bringShapeForwardJson(JSON.stringify({slideId:c,shapeId:p})),true)},sendShapeBackward(c,p){return m(()=>n.sendShapeBackwardJson(JSON.stringify({slideId:c,shapeId:p})),true)},moveShape(c,p,w,S){return m(()=>n.moveShapeJson(JSON.stringify({slideId:c,shapeId:p,x:w,y:S})),true)},moveShapeProfiled(c,p,w,S){return m(()=>n.moveShapeProfiledJson(JSON.stringify({slideId:c,shapeId:p,x:w,y:S})),true)},resizeShape(c,p,w,S){return m(()=>n.resizeShapeJson(JSON.stringify({slideId:c,shapeId:p,width:w,height:S})),true)},setShapeRect(c,p,w){return m(()=>n.setShapeRectJson(JSON.stringify({slideId:c,shapeId:p,rect:w})),true)},canUndo(){return C(()=>n.canUndo())},canRedo(){return C(()=>n.canRedo())},undoCaptureMode(){return C(()=>n.undoCaptureMode())},setUndoCaptureMode(c){C(()=>n.setUndoCaptureMode(c));},addUndoBoundary(){C(()=>n.addUndoBoundary());},undo(){return m(()=>n.undoJson(),true)},undoProfiled(){return m(()=>n.undoProfiledJson(),true)},redo(){return m(()=>n.redoJson(),true)},encodeStateVector(){return C(()=>n.encodeStateVector())},encodeStateAsUpdate(c){return C(()=>c===void 0?n.encodeStateAsUpdate():n.encodeDiff(c))},encodeDiff(c){return C(()=>n.encodeDiff(c))},applyUpdate(c){return m(()=>n.applyUpdateJson(c),true)},onUpdate(c){if(E(),typeof c!="function")throw new TypeError("update listener must be a function");let p=d++;i.set(p,c);try{V();}catch(S){throw i.delete(p),S}let w=true;return ()=>{w&&(w=false,i.delete(p),j());}},dispose(){if(s)return;s=true,i.clear(),l.length=0;let c;if(u){try{n.clearUpdateObservation();}catch(p){c=p;}u=false;}try{o.free();}catch(p){c??(c=p);}try{n.free();}catch(p){c??(c=p);}if(c!==void 0)throw H(c)}}}function J(t){return JSON.stringify(t,(e,r)=>{if(typeof r=="number"&&!Number.isFinite(r))throw new RangeError("host requests must not contain NaN or infinite numbers");return r})}function ae(t,e,r=false){try{return (r?t.registerFallbackFont:t.registerFont).call(t,e.family,e.bold??!1,e.italic??!1,e.bytes)}catch(n){throw H(n)}}function de(){if(!Se)throw new Error("pptx wasm is not initialized; call initWasm() first")}function Cr(){let t=globalThis.crypto;if(!t||typeof t.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let e=new Uint32Array(2),r;do t.getRandomValues(e),r=(e[0]&2097151)*4294967296+e[1];while(r===0);return r}function Ce(t){try{return t()}catch(e){throw H(e)}}function at(t){try{return JSON.parse(t())}catch(e){throw H(e)}}function Er(t){return at(t)}function H(t){if(t instanceof Error)return t;if(typeof t=="string")try{let e=JSON.parse(t);if(e.code==="staleProposal"&&Array.isArray(e.targets)&&e.targets.every(r=>typeof r=="string"))return new Z(e.targets)}catch{}return new Error(typeof t=="string"?t:String(t))}var Ir=33554432,dt="image/svg+xml",Ar=4194304;function ct(t){if(Ye(t)){if(t.byteLength>33554432)throw new Error("TIFF image exceeds the browser transfer budget");return new Blob([st(t).slice()],{type:"image/png"})}let e=Or(t)??Mr(t);return e?new Blob([e],{type:"image/bmp"}):Ur(t)??new Blob([t.slice()])}function pt(t){return t.type===dt}async function Rr(t,e){let r=ct(t);if(typeof createImageBitmap=="function"&&!pt(r))return createImageBitmap(r);let n=URL.createObjectURL(r);try{return await new Promise((o,i)=>{let l=new Image;l.onload=()=>o(l),l.onerror=()=>i(new Error(e)),l.src=n;})}finally{URL.revokeObjectURL(n);}}function Ur(t){if(t.byteLength>Ar)return;let e;try{e=new TextDecoder("utf-8",{fatal:!0}).decode(t).replace(/^\ufeff/,"");}catch{return}if(!(!/^\s*</.test(e)||!e.slice(0,1024).includes("<svg")))return new Blob([kr(e)],{type:dt})}function kr(t){let e=Jr(t);if(!e||/\s(?:width|height)\s*=/.test(t.slice(e.start,e.end)))return t;let r=t.slice(e.start,e.end).match(/\sviewBox\s*=\s*(["'])\s*[-+.\deE]+[\s,]+[-+.\deE]+[\s,]+([-+.\deE]+)[\s,]+([-+.\deE]+)\s*\1/),[n,o]=[Number(r?.[2]),Number(r?.[3])];if(!(n>0)||!(o>0))return t;let i=e.start+4;return `${t.slice(0,i)} width="${n}" height="${o}"${t.slice(i)}`}function Jr(t){let e=0;for(;e<t.length;){if(/\s/.test(t[e]))e+=1;else if(t.startsWith("<!--",e))e=te(t.indexOf("-->",e+4),3);else if(t.startsWith("<?",e))e=te(t.indexOf("?>",e+2),2);else if(t.startsWith("<!",e))e=te(lt(t,e+2),1);else break;if(e<0)return}if(!/^<svg[\s/>]/.test(t.slice(e,e+5)))return;let r=lt(t,e+4);return r<0?void 0:{start:e,end:r}}function te(t,e){return t<0?-1:t+e}function lt(t,e){let r="",n=false;for(let o=e;o<t.length;o+=1){let i=t[o];if(r)i===r&&(r="");else if(n&&t.startsWith("<!--",o)){if(o=te(t.indexOf("-->",o+4),2),o<0)return -1}else if(n&&t.startsWith("<?",o)){if(o=te(t.indexOf("?>",o+2),1),o<0)return -1}else if(i==='"'||i==="'")r=i;else if(i==="[")n=true;else if(i==="]")n=false;else if(i===">"&&!n)return o}return -1}function Mr(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(e.byteLength<108||e.getUint32(0,true)!==1||e.getUint32(40,true)!==1179469088)return;let r=e.getUint32(4,true);if(r<88||r%4||r>e.byteLength-8)return;let n=e.getInt32(16,true)-e.getInt32(8,true)+1,o=e.getInt32(20,true)-e.getInt32(12,true)+1,i=e.getUint32(r+4,true);if(e.getUint32(r,true)!==81||i<80||i>e.byteLength-r-8)return;let l=x=>e.getInt32(r+x,true),d=e.getUint32(r+48,true),s=e.getUint32(r+56,true),u=e.getUint32(r+60,true);if(l(24)!==e.getInt32(8,true)||l(28)!==e.getInt32(12,true)||l(72)!==n||l(76)!==o||l(32)!==0||l(36)!==0||l(40)!==n||l(44)!==o||e.getUint32(r+64,true)!==0||e.getUint32(r+68,true)!==13369376||d<80||d+e.getUint32(r+52,true)!==s||s+u!==i)return;let f=r+i;if(!(e.getUint32(f,true)!==14||e.getUint32(f+4,true)!==e.byteLength-f))return ut(t.subarray(r+d,f),n,o)}function Or(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(e.byteLength<18)return;let r=e.getUint32(0,true)===2596720087?22:0;if(e.byteLength<r+18||![1,2].includes(e.getUint16(r,true))||e.getUint16(r+2,true)!==9||e.getUint16(r+4,true)!==768||e.getUint32(r+6,true)*2!==e.byteLength-r)return;let n=0,o=0,i=0,l=0,d=false,s;for(let u=r+18;u+6<=e.byteLength;){let f=e.getUint32(u,true)*2,x=e.getUint16(u+4,true);if(f<6||f>e.byteLength-u)return;if(x===0)return f===6&&u+f===e.byteLength?s:void 0;if(s)return;if(x===259){if(f<8||e.getUint16(u+6,true)!==8)return;d=true;}else if(x===263){if(f<8||![1,2,3,4].includes(e.getUint16(u+6,true)))return}else if(x===523||x===524){if(f!==10)return;let E=e.getInt16(u+6,true),T=e.getInt16(u+8,true);if(x===523)n=T,o=E;else {if(!d)return;i=T,l=E;}}else if(x===2881){if(f<66||e.getUint32(u+6,true)!==13369376||e.getInt16(u+14,true)!==0||e.getInt16(u+16,true)!==0||e.getInt16(u+18,true)!==l||e.getInt16(u+20,true)!==i||e.getInt16(u+22,true)!==o||e.getInt16(u+24,true)!==n||!i||!l||(s=ut(t.subarray(u+26,u+f),e.getInt16(u+12,true),e.getInt16(u+10,true)),!s))return}else return;u+=f;}}function ut(t,e,r){if(t.length<40)return;let n=new DataView(t.buffer,t.byteOffset,t.byteLength),o=n.getInt32(4,true),i=n.getInt32(8,true),l=n.getUint16(14,true);if(n.getUint32(0,true)!==40||o<1||!i||o*Math.abs(i)>Ir||e!==o||r!==Math.abs(i)||n.getUint16(12,true)!==1||![24,32].includes(l)||n.getUint32(16,true)!==0||n.getUint32(32,true)!==0)return;let d=Math.ceil(o*l/32)*4*Math.abs(i),s=n.getUint32(20,true);if(40+d!==t.length||s!==0&&s!==d)return;let u=new Uint8Array(14+t.length),f=new DataView(u.buffer);return f.setUint16(0,19778,true),f.setUint32(2,u.length,true),f.setUint32(10,54,true),u.set(t,14),u}async function Fr(t,e={}){let{scale:r=1,resolveImage:n}=e;if(!Number.isFinite(r)||r<=0)throw new Error("scale must be finite and positive");let o=Lr(t,r),i=o.getContext("2d");if(!i)throw new Error("2d canvas context unavailable");return await ye(i,t,1,r,{resolveImage:n}),Nr(o)}function Lr(t,e){if(typeof OffscreenCanvas=="function"){let{width:n,height:o}=me(t,1,e);return new OffscreenCanvas(n,o)}if(typeof document>"u")throw new Error("no canvas backend in this environment");let r=document.createElement("canvas");return be(r,t,1,e),r}function Nr(t){return "convertToBlob"in t?t.convertToBlob({type:"image/png"}):new Promise((e,r)=>{t.toBlob(n=>{n?e(n):r(new Error("canvas produced no png"));},"image/png");})}var ht=3e3;var ft=["#B3261E","#7B1FA2","#3949AB","#00796B","#2E7D32","#A84400","#C2185B","#00695C"],Dr=/^#[0-9a-fA-F]+$/;function Te(t){return ft[Math.abs(t)%ft.length]}function Ie(t,e){return typeof e=="string"&&(e.length===4||e.length===7)&&Dr.test(e)?e:Te(t)}function _t(t,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 r=e?.name.trim().slice(0,1024)||`Guest ${t.toString(36).toUpperCase()}`,n=Ie(t,e?.color);return {name:r,color:n}}function Ae(t,e){return t?.slideId===e?.slideId&&t?.shapeId===e?.shapeId}var ce=class{constructor(e,r={}){y(this,"localClientId",e);y(this,"states",new Map);y(this,"clocks",new Map);y(this,"maxTrackedIds");if(this.maxTrackedIds=r.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,r)=>e.state.clientId-r.state.clientId).map(Br)}get trackedIdCount(){return this.clocks.size}get nextExpiryAt(){let e;for(let r of this.states.values()){let n=r.lastSeen+45e3;e=e===void 0?n:Math.min(e,n);}for(let r of this.clocks.values()){let n=r.updatedAt+3e5;e=e===void 0?n:Math.min(e,n);}return e}apply(e,r){let n=this.expire(r);for(let o of e){if(o.clientId===this.localClientId)continue;let i=this.clocks.get(o.clientId);if(i&&o.clock<=i.clock)continue;if(!i&&this.clocks.size>=this.maxTrackedIds&&(n=this.evictOldest()||n),this.clocks.delete(o.clientId),this.clocks.set(o.clientId,{clock:o.clock,updatedAt:r}),!o.state){n=this.states.delete(o.clientId)||n;continue}let l=this.states.get(o.clientId),d=l&&Ae(l.state.cursor,o.state.cursor)?l.cursorMovedAt:r;this.states.set(o.clientId,{state:gt(o.state),lastSeen:r,cursorMovedAt:d}),n=true;}return n}expire(e,r=45e3){let n=false;for(let[o,i]of this.states)e-i.lastSeen<r||(this.states.delete(o),n=true);for(let[o,i]of this.clocks)e-i.updatedAt<3e5||(this.clocks.delete(o),n=this.states.delete(o)||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 gt(t){return {clientId:t.clientId,clock:t.clock,user:{...t.user},cursor:t.cursor?{...t.cursor}:null}}function Br(t){return {state:gt(t.state),lastSeen:t.lastSeen,cursorMovedAt:t.cursorMovedAt}}var M=16777216,$=4096,bt=0,yt=1,jr=2,wt=3,xt=0,Pt=1,St=2,Wr=0,Xr=Number.MAX_SAFE_INTEGER,P=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},pe=class{constructor(e){y(this,"bytes",e);y(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,r=1,n=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new P("Truncated varUint");let o=this.bytes[this.offset++],i=o&127;if(i>Math.floor((Xr-e)/r))throw new P("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=i*r,n+=1,(o&128)===0){if(n>1&&i===0)throw new P("Non-canonical varUint");return e}if(n>=8)throw new P("varUint exceeds Number.MAX_SAFE_INTEGER");r*=128;}}readVarUint8Array(){let e=this.readVarUint(),r=this.bytes.byteLength-this.offset;if(e>r)throw new P("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(r){throw new P(`Invalid UTF-8 string${r instanceof Error?`: ${r.message}`:""}`)}}};function U(t){if(!Number.isSafeInteger(t)||t<0)throw new P("varUint value must be a non-negative safe integer");let e=[],r=t;for(;r>=128;)e.push(r%128|128),r=Math.floor(r/128);return e.push(r),Uint8Array.from(e)}function Hr(t){let e=new TextEncoder().encode(t);return re([U(e.byteLength),e],M)}function re(t,e){let r=0;for(let i of t)if(r+=i.byteLength,r>e)throw new P(`Frame exceeds ${e} bytes`);let n=new Uint8Array(r),o=0;for(let i of t)n.set(i,o),o+=i.byteLength;return n}function ke(t,e,r){return re([U(bt),U(t),U(e.byteLength),e],r)}function vt(t,e=M){return ke(xt,t,e)}function Ct(t,e=M){return ke(Pt,t,e)}function Et(t,e=M){return ke(St,t,e)}function Tt(t,e=M){if(t.length>$)throw new P(`Awareness update exceeds ${$} entries`);let r=[U(t.length)];for(let o of t){kt(o);let i=JSON.stringify(o.state);if(i===void 0)throw new P("Awareness state is not JSON serializable");r.push(U(o.clientId),U(o.clock),Hr(i));}let n=re(r,e);return re([U(yt),U(n.byteLength),n],e)}function It(t=M){return re([U(wt)],t)}function At(t,e=$){if(!(t instanceof Uint8Array))throw new P("Awareness update must be a Uint8Array");if(!Number.isSafeInteger(e)||e<1)throw new P("Awareness entry limit must be a positive integer");let r=new pe(t),n=r.readVarUint();if(n>e)throw new P(`Awareness update exceeds ${e} entries`);let o=[];for(let i=0;i<n;i+=1){let l=r.readVarUint(),d=r.readVarUint(),s;try{s=JSON.parse(r.readVarString());}catch(f){throw f instanceof P?f:new P(`Invalid awareness JSON${f instanceof Error?`: ${f.message}`:""}`)}let u={clientId:l,clock:d,state:Ut(s,l,d)};kt(u),o.push(u);}if(!r.done)throw new P("Awareness update has trailing bytes");return o}function Rt(t,e=M,r=$){if(!(t instanceof Uint8Array))throw new P("Frame must be a Uint8Array");if(t.byteLength===0)throw new P("Frame is empty");if(t.byteLength>e)throw new P(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(r)||r<1)throw new P("Message limit must be a positive integer");let n=new pe(t),o=[];for(;!n.done;){if(o.length>=r)throw new P(`Frame exceeds ${r} messages`);let i=n.readVarUint();switch(i){case bt:{let l=n.readVarUint(),d=n.readVarUint8Array();if(l===xt)o.push({type:"sync-step-1",stateVector:d});else if(l===Pt)o.push({type:"sync-step-2",update:d});else if(l===St)o.push({type:"update",update:d});else throw new P(`Unknown sync message type ${l}`);break}case yt:o.push({type:"awareness",update:n.readVarUint8Array()});break;case jr:{let l=n.readVarUint();if(l!==Wr)throw new P(`Unknown auth message type ${l}`);o.push({type:"auth",reason:n.readVarString()});break}case wt:o.push({type:"query-awareness"});break;default:throw new P(`Unknown top-level message type ${i}`)}}return o}function Ut(t,e,r){if(t===null)return null;if(!Ue(t))throw new P("Awareness state must be an object or null");if(t.clientId!==e||t.clock!==r)throw new P("Awareness state identity does not match its entry");if(!Ue(t.user))throw new P("Awareness user must be an object");let n=Re(t.user.name,"Awareness user name"),o=Ie(e,t.user.color);return {clientId:e,clock:r,user:{name:n,color:o},cursor:qr(t.cursor)}}function qr(t){if(t==null)return null;if(!Ue(t))throw new P("Awareness cursor must be an object or null");let e=Re(t.slideId,"Awareness slideId"),r=t.shapeId===void 0?void 0:Re(t.shapeId,"Awareness shapeId");return r?{slideId:e,shapeId:r}:{slideId:e}}function kt(t){mt(t.clientId,"Awareness clientId"),mt(t.clock,"Awareness clock"),t.state!==null&&Ut(t.state,t.clientId,t.clock);}function mt(t,e){if(!Number.isSafeInteger(t)||t<0)throw new P(`${e} must be a non-negative safe integer`)}function Re(t,e){if(typeof t!="string"||t.length===0||t.length>1024)throw new P(`${e} must be between 1 and ${1024} characters`);return t}function Ue(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}var I=class extends Error{constructor(r,n,o){super(n);y(this,"code");y(this,"cause");this.name="CollaborationError",this.code=r,this.cause=o;}};var Gr=16*1024*1024,Je=new TextEncoder().encode("\0betteroffice-document-fingerprint-v1\0");function Me(t,e,r){if(!Number.isSafeInteger(e)||e<(r?0:1))throw new RangeError(`${t} must be ${r?"a non-negative":"a positive"} integer`);return e}function Yr(t){return t instanceof Error&&t.message?t.message:typeof t=="string"&&t?t:"Unknown error"}function v(t,e,r){return r instanceof I?r:new I(t,`${e}: ${Yr(r)}`,r)}function Oe(t,e){if(!(t instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return t.slice()}function Jt(t){let e=Je.byteLength+32,r=t.byteLength-e;if(r<0)return t;for(let n=0;n<Je.byteLength;n+=1)if(t[r+n]!==Je[n])return t;return t.subarray(0,r)}function Fe(t){typeof t=="object"&&t&&"unref"in t&&t.unref();}function Kr(t){if(!Number.isSafeInteger(t)||t<0)throw new RangeError("Replica clientId must be a non-negative safe integer");return t}function Zr(t){if(t===null)return null;if(!t||typeof t.slideId!="string"||t.slideId.length===0)throw new TypeError("Presence cursor slideId must be a non-empty string");if(t.shapeId!==void 0&&(typeof t.shapeId!="string"||t.shapeId.length===0))throw new TypeError("Presence cursor shapeId must be a non-empty string");return t.shapeId?{slideId:t.slideId,shapeId:t.shapeId}:{slideId:t.slideId}}function Qr(t){return t.slideId.length<=1024&&(t.shapeId===void 0||t.shapeId.length<=1024)}var ue=class{constructor(e,r,n={}){y(this,"replica");y(this,"transport");y(this,"maxFrameBytes");y(this,"maxMessagesPerFrame");y(this,"maxPendingBytes");y(this,"localClientId");y(this,"localUser");y(this,"remotePresence");y(this,"statusListeners",new Map);y(this,"errorListeners",new Map);y(this,"presenceListeners",new Map);y(this,"pendingFrames",[]);y(this,"unsubscribeReplica");y(this,"unsubscribeTransport",()=>{});y(this,"hasTransportSubscription",false);y(this,"connectionStatus","disconnected");y(this,"isSynced",false);y(this,"wantsConnection",false);y(this,"isOpen",false);y(this,"isDestroyed",false);y(this,"epoch",0);y(this,"connectAttempt",0);y(this,"nextListenerId",0);y(this,"queuedBytes",0);y(this,"isFlushing",false);y(this,"localClock",0);y(this,"reportedClockExhaustion",false);y(this,"localCursor",null);y(this,"lastAwarenessSentAt",0);y(this,"cursorTimer",null);y(this,"heartbeatTimer",null);y(this,"expiryTimer",null);this.replica=e,this.transport=r,this.localClientId=Kr(e.clientId),this.localUser=_t(this.localClientId,n.user),this.remotePresence=new ce(this.localClientId),this.maxFrameBytes=Me("maxFrameBytes",n.maxFrameBytes??M,false),this.maxMessagesPerFrame=Me("maxMessagesPerFrame",n.maxMessagesPerFrame??$,false),this.maxPendingBytes=Me("maxPendingBytes",n.maxPendingBytes??Gr,true);try{this.unsubscribeReplica=e.onUpdate((o,i)=>{i==="local"&&this.forwardLocalUpdate(o);});}catch(o){throw v("replica","Failed to observe replica updates",o)}}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 r=Zr(e),n=!r||Qr(r)?r:null;r&&!n&&this.report(new I("protocol",`Presence cursor identifiers exceed ${1024} characters; cursor dropped`)),!Ae(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,r=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let n;try{if(n=this.transport.onEvent(o=>this.handleTransportEvent(e,o)),typeof n!="function")throw new TypeError("Transport event subscription must return a function")}catch(o){this.failConnection(e,v("transport","Failed to subscribe to transport events",o));return}if(!this.isCurrent(e)){try{n();}catch(o){this.isDestroyed||this.report(v("transport","Failed to unsubscribe from stale transport events",o));}return}this.unsubscribeTransport=n,this.hasTransportSubscription=true;}try{let n=this.transport.connect();n&&n.catch(o=>{this.isCurrent(e)&&this.connectAttempt===r&&this.failConnection(e,v("transport","Transport connect failed",o));});}catch(n){this.failConnection(e,v("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 o=this.epoch;if(this.broadcastLocalPresence(true),!this.isCurrent(o))return}this.stopPresenceTimers(),this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let r=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(r,true);this.setStatus("disconnected",false);for(let o of n)this.report(o);}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 r=this.takeTransportSubscription();this.clearPending(),this.clearRemotePresence();let n=this.cleanupTransport(r,e);this.setStatus("destroyed",false);for(let o of n)this.report(o);try{this.unsubscribeReplica();}catch(o){this.report(v("replica","Failed to unsubscribe from replica updates",o));}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 r=this.nextListenerId++;return this.statusListeners.set(r,e),()=>this.statusListeners.delete(r)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");let r=this.nextListenerId++;return this.errorListeners.set(r,e),()=>this.errorListeners.delete(r)}onPresence(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("presence listener must be a function");let r=this.nextListenerId++;this.presenceListeners.set(r,e);try{e(this.peers);}catch{}return ()=>this.presenceListeners.delete(r)}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,r){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 o=this.cleanupTransport(n,true);this.setStatus("disconnected",false),this.report(r);for(let i of o)this.report(i);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,r){let n=[];try{e();}catch(o){n.push(v("transport","Failed to unsubscribe from transport events",o));}if(!r)return n;try{let o=this.transport.disconnect();o&&o.catch(i=>{this.isDestroyed||this.report(v("transport","Transport disconnect failed",i));});}catch(o){n.push(v("transport","Transport disconnect failed",o));}return n}handleTransportEvent(e,r){if(this.isCurrent(e))switch(r.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(e,r.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,v("transport","Transport error",r.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new I("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 r;try{r=Oe(this.replica.encodeStateVector(),"encodeStateVector");}catch(n){this.failConnection(e,v("replica","Failed to encode replica state vector",n));return}try{this.sendFrame(vt(r,this.maxFrameBytes));}catch(n){this.failConnection(e,v("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(It(this.maxFrameBytes));}catch(n){this.report(v("protocol","Failed to encode awareness query",n));}}handleMessage(e,r){let n;try{n=Rt(r.slice(),this.maxFrameBytes,this.maxMessagesPerFrame);}catch(o){this.failConnection(e,v("protocol","Invalid collaboration frame",o));return}for(let o of n){if(!this.isCurrent(e)||!this.isOpen)return;switch(o.type){case "sync-step-1":this.respondToSyncStep1(e,o.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,o.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,o.update);break;case "awareness":{try{let i=At(o.update,this.maxMessagesPerFrame);this.remotePresence.apply(i,Date.now())&&this.emitPresence(),this.schedulePresenceExpiry();}catch(i){this.report(v("protocol","Invalid awareness update",i));}break}case "auth":this.failConnection(e,new I("protocol",o.reason?`Authentication denied: ${o.reason}`:"Authentication denied"));return;case "query-awareness":this.broadcastLocalPresence(false);break}}}respondToSyncStep1(e,r){let n;try{n=Oe(this.replica.encodeStateAsUpdate(Jt(r).slice()),"encodeStateAsUpdate");}catch(o){this.failConnection(e,v("replica","Failed to encode replica update",o));return}try{this.sendFrame(Ct(n,this.maxFrameBytes));}catch(o){this.failConnection(e,v("protocol","Failed to encode SyncStep2",o));}}applyRemoteUpdate(e,r){try{return this.replica.applyUpdate(Jt(r).slice()),!0}catch(n){return this.failConnection(e,v("replica","Failed to apply remote update",n)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let r=this.epoch,n;try{n=Oe(e,"Replica update");}catch(o){this.failConnection(r,v("replica","Invalid replica update",o));return}try{this.sendFrame(Et(n,this.maxFrameBytes));}catch(o){this.failConnection(r,v("protocol","Failed to encode update",o));}}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),Fe(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 I("protocol","Awareness clock exceeds Number.MAX_SAFE_INTEGER")));return}this.localClock+=1;let r=this.localClock,n=e?null:{clientId:this.localClientId,clock:r,user:{...this.localUser},cursor:this.localCursor?{...this.localCursor}:null};this.cursorTimer&&clearTimeout(this.cursorTimer),this.cursorTimer=null,this.lastAwarenessSentAt=Date.now();try{let o=Tt([{clientId:this.localClientId,clock:r,state:n}],this.maxFrameBytes);e?this.sendLeaveFrameBestEffort(o):this.sendFrame(o);}catch(o){this.report(v("protocol","Failed to encode awareness update",o));}}sendLeaveFrameBestEffort(e){try{this.transport.send(e.slice());}catch{}}startPresenceTimers(){this.stopPresenceTimers(),this.heartbeatTimer=setInterval(()=>{this.broadcastLocalPresence(false);},2e4),Fe(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())),Fe(this.expiryTimer));}clearRemotePresence(){this.remotePresence.clear()&&this.emitPresence();}emitPresence(){let e=this.peers;for(let[r,n]of [...this.presenceListeners])if(this.presenceListeners.get(r)===n)try{n(e);}catch{}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let r=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(r,e);return}let n;try{n=this.transport.send(e.slice());}catch(o){this.failConnection(r,v("transport","Transport send failed",o));return}if(typeof n!="boolean"){this.failConnection(r,new I("transport","Transport send must return a boolean"));return}!n&&this.isCurrent(r)&&this.isOpen&&this.queueFrame(r,e);}queueFrame(e,r){if(r.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new I("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let n=r.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,r=this.pendingFrames[0],n;try{n=this.transport.send(r.slice());}catch(o){this.failConnection(e,v("transport","Transport send failed",o));return}if(typeof n!="boolean"){this.failConnection(e,new I("transport","Transport send must return a boolean"));return}if(!n||!this.isOpen||this.pendingFrames[0]!==r)return;this.pendingFrames.shift(),this.queuedBytes-=r.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,r){if(this.connectionStatus===e&&this.isSynced===r)return;this.connectionStatus=e,this.isSynced=r;let n={status:e,synced:r};for(let[o,i]of [...this.statusListeners])if(this.statusListeners.get(o)===i)try{i(n);}catch{}}report(e){for(let[r,n]of [...this.errorListeners])if(this.errorListeners.get(r)===n)try{n(e);}catch{}}};export{I as CollaborationError,ue as CollaborationProvider,ht as PRESENCE_LABEL_DURATION_MS,Q as PptxExportError,Z as StaleProposalError,Rr as decodePresentationImage,Pr as exportPptxMarkdown,xr as exportPptxStructured,le as initWasm,wr as inspectPresentation,ve as isProposalsAvailable,br as isWasmAvailable,pt as needsElementDecode,vr as openPresentation,ye as paintSlide,Te as presenceColorForClientId,ct as presentationImageBlob,Sr as renderPptxMarkdown,be as sizeCanvasForSlide,Fr as slideToPng,yr as wasmVersion};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betteroffice/pptx",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
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",
@@ -44,7 +44,7 @@
44
44
  "typecheck": "tsc --noEmit -p ."
45
45
  },
46
46
  "devDependencies": {
47
- "@types/bun": "^1.3.14",
47
+ "@types/bun": "^1.4.2",
48
48
  "@types/node": "^26.0.0",
49
49
  "tsup": "^8.5.1",
50
50
  "typescript": "^6.0.3"