@betteroffice/pptx 0.2.0 → 0.5.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/worker.js ADDED
@@ -0,0 +1 @@
1
+ import {e,h,g}from'./chunk-NNSP5326.js';export{j as createPptxWorkerEditorSession,i as openPresentationSession}from'./chunk-NNSP5326.js';import {n,j,m,g as g$1,h as h$1}from'./chunk-2NCQ2IE7.js';export{m as CommandOutcomeUnknown,a as DEFAULT_EDITOR_TEXT_STYLE,l as PRESENTATION_COMMAND_ADMISSION,n as PRESENTATION_COMMAND_METHODS,k as PRESENTATION_COMMAND_MUTATIONS,r as decodeCommandDisplayList,d as effectiveStyleFromSelection,u as findLine,x as hitGeometry,s as indexGeometry,t as indexHitGeometry,y as navigateGeometry,b as selectionFormattingFromStory,w as selectionGeometry,c as storyFormattingFromStory,v as transformedRect}from'./chunk-2NCQ2IE7.js';import {a,L,K,N,E,b,O,D,J}from'./chunk-4FWJR3UX.js';export{B as PptxPeerHydrationError,C as PptxPeerNotReadyError,F as PptxWorkerEditorCollaborationError,E as PptxWorkerEditorDisposedError,D as PptxWorkerEditorFailedError,Q as frameAssetIds}from'./chunk-4FWJR3UX.js';import {a as a$1,v}from'./chunk-H3SEEI4U.js';function En(){let t=new Map,o=false,P=a=>{a.retained||a.references||a.closed||!a.source||(a.closed=true,"close"in a.source&&typeof a.source.close=="function"&&a.source.close(),a.source=null);};return {resolve(a$1){let h=new Map,l=false;return Object.assign(w=>{if(o||l)return Promise.resolve(null);let x=a$1.media.get(w);if(!x||a(x))return Promise.resolve(null);let O=h.get(w)??t.get(w);if(O)t.get(w)===O&&(t.delete(w),t.set(w,O));else {let M={promise:Promise.resolve(null),source:null,references:0,retained:true,closed:false};M.promise=e(x,"Unable to decode slide image").catch(()=>null).then(z=>(M.source=z,P(M),z)),O=M,t.set(w,O);}for(h.has(w)||(h.set(w,O),O.references+=1);t.size>25;){let M=t.entries().next().value;if(!M)break;t.delete(M[0]),M[1].retained=false,P(M[1]);}return O.promise},{release(){if(!l){l=true;for(let w of h.values())w.references-=1,P(w);h.clear();}}})},dispose(){o=true;for(let a of t.values())a.retained=false,P(a);t.clear();}}}function At(){let t=new Map,o=0,P;return {channel(a){return {open(h,l){let k=++o;return P?queueMicrotask(()=>l(P)):t.set(k,{receive:h,lost:l}),{post(w){return P||!t.has(k)?Promise.reject(new Error(P??"Collaboration replica is retired")):a({provider:k,ops:w})},close(){t.delete(k);}}}}},receive(a){for(let h of a)t.get(h.provider)?.receive(h.out);},lose(a){P=a;let h=[...t.values()];t.clear();for(let l of h)l.lost(a);}}}var nt=Symbol.for("betteroffice.pptx.collaborationPipe"),we={get(t){return t[nt]},set(t,o){Object.defineProperty(t,nt,{value:o,configurable:true});},delete(t){delete t[nt];}};var it=new WeakMap;function It(t){it.get(t)?.fence();}function st(t,o){return it.get(t)?.cancel(o)??[]}function rt(){let t=new Map,o=Array.from({length:11},()=>new Map);function P(l,k){t.set(l,k);let w=l;for(let x of o){let O=Math.floor(w/32),M=x.get(O)??0;if(x.set(O,M|1<<w%32),M!==0)break;w=O;}}function a(l){if(!t.delete(l))return;let k=l;for(let w of o){let x=Math.floor(k/32),O=(w.get(x)??0)&~(1<<k%32);if(O!==0){w.set(x,O);break}w.delete(x),k=x;}}function*h(l,k){let w=o[l].get(k)??0;for(;w!==0;){let x=31-Math.clz32(w&-w),O=k*32+x;l===0?yield t.get(O):yield*h(l-1,O),w&=w-1;}}return {set:P,delete:a,values:()=>h(o.length-1,0)}}function ot(){return {size:0,lanes:{input:rt(),collab:rt(),background:rt()}}}function Mt(t){let o=new Map,P=new WeakMap,a=new Map,h=new Set,l=ot(),k=l,w,x=0,O=Number.isSafeInteger(t.inputBurstCap)&&t.inputBurstCap>0?t.inputBurstCap:8,M=0;function z(){if(k.size===0)return;let v=ot();k.next=v,k=v;}function Q(v){v.segment.lanes[xe(v.entry.draft)].set(v.order,v);}function ne(v,T){let F=v.entry.draft,u=T.options.after,f=u&&P.get(u)===P.get(v.tickets[0])?{...T,options:{...T.options,after:F.options.after}}:T,c=qn(F,f)?t.coalesce?.(F,f):void 0;return c&&xe(c)===xe(F)&&c.options.after===F.options.after&&!c.options.fence?c:void 0}function A(v,T){let F=w?.segment===k?w:void 0,u=F&&ne(F,v);if(u&&F)return F.tickets.push(T),F.entry={id:F.entry.id,draft:u,tickets:F.tickets},P.set(T,P.get(F.tickets[0])),F.entry;if(v.options.fence&&z(),x===Number.MAX_SAFE_INTEGER)throw new RangeError("Outbox order space is exhausted");let f=[T],c={id:T.id,draft:v,tickets:f},b={entry:c,tickets:f,segment:k,order:++x,previous:w};w&&(w.next=b),w=b,o.set(c.id,b),P.set(T,{id:c.id}),k.size+=1;let m=v.options.after;if(m){b.afterId=P.get(m)?.id??m.id;let C=a.get(b.afterId);C||a.set(b.afterId,C=new Set),C.add(b);}return (!m||!o.has(b.afterId))&&Q(b),v.options.fence&&z(),c}function R(v){if(o.delete(v.entry.id),v.segment.lanes[xe(v.entry.draft)].delete(v.order),v.segment.size-=1,v.previous&&(v.previous.next=v.next),v.next&&(v.next.previous=v.previous),w===v&&(w=v.previous),v.afterId!==void 0){let F=a.get(v.afterId);F?.delete(v),F?.size===0&&a.delete(v.afterId);}let T=a.get(v.entry.id);if(T)for(let F of T)Q(F);for(;l.size===0&&l.next;)l=l.next;o.size===0&&(M=0);}function L(v,T,F){for(let u of l.lanes[v].values()){if(F?.(u.entry))return;let f=u.entry.draft.options.after;if(!(f&&(o.has(u.afterId)||f.seq===void 0))&&T(u.entry))return u}}function $(v,T){for(;l.size===0&&l.next;)l=l.next;let u=(M>=O?L("collab",v,T):void 0)??L("input",v,T)??L("collab",v,T)??L("background",v,T);if(!u)return;let f=xe(u.entry.draft)==="input"?Math.min(O,M+1):0;return R(u),M=f,u.entry}function _(v,T){let F=v.map(u=>P.get(u)?.id??u.id);for(let u=0;u<F.length;u+=1){let f=a.get(F[u]);if(f)for(let c of f)T.has(c)||(T.add(c),F.push(c.entry.id));}}function N(v){for(let F of v){let u=P.get(F)?.id??F.id,f=a.get(u);f&&(h.add(f.values()),a.delete(u));}let T=[];for(;h.size&&T.length<64;){let F=h.values().next().value,u=F.next();if(u.done){h.delete(F);continue}let f=u.value;if(!o.has(f.entry.id))continue;let c=a.get(f.entry.id);c&&(h.add(c.values()),a.delete(f.entry.id)),T.push(f.entry),R(f);}return T}function Y(v){let T=new Set,F=[];for(let f of o.values())v(f.entry)&&(T.add(f),F.push(f.tickets[0]));_(F,T);let u=[];for(let f of o.values())T.has(f)&&(u.push(f.entry),R(f));return u}let J={get size(){return o.size},get entries(){return [...o.values()].map(v=>v.entry)},enqueue:A,takeNext:$,remove:Y,clear(){let v=[...o.values()].map(T=>T.entry);return o.clear(),P=new WeakMap,a.clear(),h.clear(),l=ot(),k=l,w=void 0,M=0,v}};return it.set(J,{fence:z,cancel:N}),J}function xe(t){return t.options.lane??"input"}function qn(t,o){let P=t.options,a=o.options;return !P.fence&&!a.fence&&P.coalesceKey!==void 0&&P.coalesceKey===a.coalesceKey&&t.kind===o.kind&&xe(t)===xe(o)&&P.group===a.group&&P.after?.id===a.after?.id&&(P.expectVersion??false)===(a.expectVersion??false)}function Xt(t){let o=Number.isSafeInteger(t.maxEchoEntries)&&t.maxEchoEntries>=0?t.maxEchoEntries:64,P=t.now??Date.now,a=new Map,h=new Set,l=[],k=-1,w=-1,x=-1,O,M,z=0,Q=false,ne=0,A=0;function R(c){ne===0&&(A=0),ne+=1;try{return c()}finally{ne-=1;}}function L(c,b){let m=$(),C=A;try{return b(),!0}catch{return false}finally{let X=Math.max(0,$()-m);if(A=C+X,A>2)try{t.onEchoOverrun?.({hook:c,elapsedMs:X,eventTotalMs:A});}catch{}}}function $(){try{let c=P();return Number.isFinite(c)?c:0}catch{return 0}}function _(c,b){let m=a.get(c);m&&(a.delete(c),m.resolve(b));}function N(c){h.has(c)||(h.size>=256&&h.delete(h.values().next().value),h.add(c)),_(c,"dropped");}function Y(c){return R(()=>{if(Q||o===0)return !1;if(l.length>=o){if(t.echoOverflow!=="evict-oldest")return !1;l=l.slice(l.length-o+1);}return l=[...l,c],t.echo&&L("paint",()=>t.echo.paint(l)),!0})}function J(c){return R(()=>{if(Q)return !1;let b=[...l,...c].sort((m,C)=>m.ticket.id-C.ticket.id);return b.length>o?!1:(l=b,c.length>0&&t.echo&&L("paint",()=>t.echo.paint(l)),!0)})}function v(c,b){R(()=>{if(Q)return;let m=new Set(c.map(se=>se.id)),C=l.filter(se=>!m.has(se.ticket.id)),X=C.length!==l.length;b!==void 0&&o>0&&C.length>=o&&t.echoOverflow==="evict-oldest"&&(C=C.slice(C.length-o+1));let K=b!==void 0&&C.length<o;l=K?[...C,b]:C,(X||K)&&t.echo&&L("paint",()=>t.echo.paint(l));});}function T(c,b){R(()=>{if(Q)return;let m=new Set(c.map(X=>X.id)),C=l.filter(X=>m.has(X.ticket.id));l=l.filter(X=>!m.has(X.ticket.id));for(let X of C){let K=X.seq??X.ticket.seq;K!==void 0&&N(K);}for(let X of c)X.seq!==void 0&&N(X.seq);C.length>0&&t.echo&&L("drop",()=>t.echo.drop(C,b));});}function F(c,b,m){let C=[],X=[];for(let ae of l){let oe=ae.seq??ae.ticket.seq;(!b&&oe!==void 0&&oe<=c.coversThroughSeq?C:X).push(ae);}let K=M,se=z;M={coverage:c.coversThroughSeq,revision:c.revision};try{if(!m(C,X)||Q||se!==z)return "stale";if(k=Math.max(k,c.coversThroughSeq),O=O===void 0?c.revision:Math.max(O,c.revision),b)return "presented";let ae=new Set(C);l=l.filter(G=>!ae.has(G));let oe=Math.min(k,c.coversThroughSeq);x=Math.max(x,oe);for(let G of a.keys())G<=oe&&_(G,h.has(G)?"dropped":"presented");return w=Math.max(w,oe),"presented"}finally{se===z&&(M=K);}}function u(c){return R(()=>{let b=!1;function m(C,X){return t.echo?L("present",()=>{let se=t.echo.present(c,C,X);b=!t.transactionalPresentation||se!==!1;})&&b:(b=!0,!0)}try{let C=c.coversThroughSeq===k;if(Q||c.coversThroughSeq<k||C&&(!t.sameCoverageFrames||k<0||O===void 0||c.revision<=O)||M&&(c.coversThroughSeq<M.coverage||c.coversThroughSeq===M.coverage&&(!t.sameCoverageFrames||c.revision<=M.revision)))return "stale";if(c.baseRevision!==void 0&&c.baseRevision!==O)return t.requestFullFrame(),"base-mismatch";if(t.transactionalPresentation&&t.echo)return F(c,C,m);if(C)return O=c.revision,m([],l),Q?"stale":"presented";let X=[],K=[],se=k,ae=x;for(let V of l){let ce=V.seq??V.ticket.seq;(ce!==void 0&&ce<=c.coversThroughSeq?X:K).push(V);}l=K,k=c.coversThroughSeq,O=c.revision;let oe=m(X,K);if(Q)return "stale";let G=Math.min(k,c.coversThroughSeq);if(oe&&(x=Math.max(x,G)),!oe)for(let V of X){let ce=V.seq??V.ticket.seq;ce!==void 0&&ce<=c.coversThroughSeq&&(x===ae||ce>x)&&N(ce);}for(let V of a.keys())V>G||(oe?_(V,h.has(V)?"dropped":"presented"):V>se&&N(V));if(!oe)for(let V=Math.max(se+1,x+1,G-256+1);V<=G;V+=1)N(V);return w=Math.max(w,G),"presented"}finally{if(!b)try{t.discardFrame?.(c);}catch{}}})}function f(c){if(Q||h.has(c))return Promise.resolve("dropped");if(c<=w)return Promise.resolve("presented");let b=a.get(c);if(b)return b.promise;a.size>=1024&&N(a.keys().next().value);let m,C=new Promise(X=>{m=X;});return a.set(c,{promise:C,resolve:m}),C}return {get presentedThroughSeq(){return k},get revision(){return O},get pending(){return l.slice()},event:R,add:Y,attach:J,replace:v,drop:T,present:u,whenPresented:f,reset(){Q||(z+=1,M=void 0,k=-1,w=-1,x=-1,O=void 0);},dispose(){R(()=>{if(Q)return;Q=!0;let c=l;l=[];for(let b of a.keys())_(b,"dropped");h.clear(),c.length>0&&t.echo&&L("drop",()=>t.echo.drop(c,"disposed"));});}}}function Oe(t){let o=globalThis;return typeof o.structuredClone=="function"?o.structuredClone(t):Te(t,new Map)}function Te(t,o){if(typeof t=="function"||typeof t=="symbol")throw new TypeError("Unsupported command data");if(t===null||typeof t!="object")return t;if(o.has(t))return o.get(t);if(typeof Blob<"u"&&t instanceof Blob||typeof File<"u"&&t instanceof File)return o.set(t,t),t;if(ArrayBuffer.isView(t)){let a=Te(t.buffer,o),h=t.constructor,l=t instanceof DataView?new DataView(a,t.byteOffset,t.byteLength):new h(a,t.byteOffset,t.byteLength/h.BYTES_PER_ELEMENT);return o.set(t,l),l}if(typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer)return o.set(t,t),t;if(t instanceof ArrayBuffer){let a=t.slice(0);return o.set(t,a),a}if(t instanceof Date){let a=new Date(t.getTime());return o.set(t,a),a}if(t instanceof RegExp){let a=new RegExp(t.source,t.flags);return o.set(t,a),a}if(t instanceof Number||t instanceof String||t instanceof Boolean||Object.getPrototypeOf(t)===BigInt.prototype){let a=Object(t.valueOf());return o.set(t,a),a}if(t instanceof Map){let a=new Map;o.set(t,a);for(let[h,l]of t)a.set(Te(h,o),Te(l,o));return a}if(t instanceof Set){let a=new Set;o.set(t,a);for(let h of t)a.add(Te(h,o));return a}let P=Array.isArray(t)?new Array(t.length):{};o.set(t,P);for(let a of Object.keys(t))Object.defineProperty(P,a,{value:Te(t[a],o),enumerable:true,configurable:true,writable:true});return P}var Fn=4096;function Bt(){let t=[];function o(a){let h=0,l=t.length;for(;h<l;){let k=Math.floor((h+l)/2),w=t[k];if(a<w[0])l=k;else if(a>w[1])h=k+1;else return true}return false}function P(a){let h=0;for(;h<t.length&&t[h][1]<a-1;)h+=1;let l=t[h];if(l&&l[0]<=a+1){l[0]=Math.min(l[0],a),l[1]=Math.max(l[1],a);let k=t[h+1];k&&k[0]<=l[1]+1&&(l[1]=Math.max(l[1],k[1]),t.splice(h+1,1));return}if(t.length===Fn)throw new N("out-of-memory","Command replay ledger exhausted: 4096 disjoint ranges per epoch");t.splice(h,0,[a,a]);}return {contains:o,add:P,values(){let a=[];for(let[h,l]of t)for(let k=h;k<=l;k+=1)a.push(k);return a},clear(){t.length=0;}}}function Qt(t){return at(t)?t.ok===false?at(t.refusal)&&typeof t.refusal.code=="string"&&(t.refusal.detail===void 0||typeof t.refusal.detail=="string"):t.ok===true&&J(t,"value")&&at(t.at)&&["incarnation","epoch","throughSeq","doc","selection","layout"].every(o=>Rn(t.at[o])):false}function at(t){return t!==null&&typeof t=="object"}function Rn(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0}function Ae(){let t,o,P=new Promise((a,h)=>{t=a,o=h;});return P.catch(()=>{}),{promise:P,resolve:t,reject:o}}function re(t){return t instanceof N?t:new N("crash",t instanceof Error?t.message:String(t))}function ct(t){return t.code==="crash"||t.code==="trap"||t.code==="out-of-memory"||t.code==="silence"}function be(t){return t?.status==="refused"||t?.status==="cancelled"}function De(t){return t?.status==="applied"&&t.committed!==false}function Dt(t,o){return t!==void 0&&Number.isSafeInteger(t)&&t>0?t:o}function Wt(t){let o=t.connection.initial,P=t.maxRecoveryAttempts===0?0:Dt(t.maxRecoveryAttempts,2),a=P===0?void 0:Oe(t.source),h=o.session,l=o.epoch,k=Dt(t.maxInFlight,4),w=t.enqueue??queueMicrotask,x=new WeakMap,O=new WeakMap,M=new Set,z=new Set,Q=new Map,ne=new Map,A=new Set,R=false,L,$=new Map,_=new Map,N$1=new Map,Y=Bt(),J$1=new Map,v=0,T=o.throughSeq,F=o.incarnation,u,f,c={epoch:l,version:o.version,throughSeq:o.throughSeq,presentedThroughSeq:-1,selection:o.selection,editState:o.editState},b=false,m,C=false,X=false,K=false,se=-1,ae=true,oe=o.throughSeq,G=0,V,ce=0,Ie=o.throughSeq,Me=o.throughSeq,ve=o.throughSeq,he=o.revisions?.selection??0,Pe=o.revisions?.layout??0,me=0,Ce=0,Z=0,pe=new Set,ye=t.holdTimeoutMs??2e3;if(!Number.isFinite(ye)||ye<0)throw new TypeError("Invalid hold timeout");let r=t.now??Date.now,S=t.timer??((e,n)=>{let i=setTimeout(e,n);return ()=>{clearTimeout(i);}}),y=new Map,E=new Set,H=new Set,D=Mt({inputBurstCap:t.inputBurstCap,coalesce:t.coalesce}),I=Xt({echo:t.echo&&{paint:e=>t.echo.paint(e),drop:(e,n)=>t.echo.drop(e,n),present(e,n,i){ae=false;let s=t.echo.present(e,n,i);return ae=!t.transactionalPresentation||s!==false,s}},maxEchoEntries:t.maxEchoEntries,now:t.now,sameCoverageFrames:t.sameCoverageFrames,transactionalPresentation:t.transactionalPresentation,echoOverflow:t.echoOverflow,discardFrame:fe,onEchoOverrun:t.onEchoOverrun,requestFullFrame:()=>Ht(oe,G)});function B(e){return !b&&!m&&e.active&&f===e}function ee(e,n){e.done||(e.done=true,E.delete(e),H.delete(e),e.cleanup(),n instanceof N?e.result.reject(n):e.result.resolve(n));}function de(e,n){return {ok:false,refusal:{code:e,...n===void 0?{}:{detail:n}}}}function ue(){if(b||m||C)return;let e=f;if(!(!e||!B(e)))for(let n of H){if(!B(e)||C)return;if(n.signal?.aborted){ee(n,de("superseded","aborted"));continue}let i=false;for(let q of M)if(q.ticket.id<=n.watermark&&q.seq===void 0&&!q.ackSettled){i=true;break}if(i)continue;H.delete(n);let s=e.connection.client.call.query;if(!s){ee(n,de("unsupported"));continue}let p={session:h,incarnation:F,epoch:l,afterSeq:T>e.seenMark?T:e.seenSeq},d=++n.attempt;n.connection=e;let g=()=>!n.done&&n.attempt===d&&B(e);try{s.call(e.connection.client.call,p,n.kind,n.args).then(q=>{if(!g())return;if(!Qt(q)||q.ok&&(q.at.incarnation!==p.incarnation||q.at.epoch!==p.epoch||q.at.throughSeq<p.afterSeq)){ie(new N("message","Malformed or unfenced query reply"));return}let W=t.queries[n.kind].stale;q.ok&&W!=="answer-at-fence"&&W.reject.some(U=>(U==="doc"?c.version:U==="selection"?he:Pe)>q.at[U])?ee(n,de("superseded")):ee(n,q);},q=>{g()&&ie(re(q));}).catch(q=>{g()&&ie(re(q));});}catch(q){g()&&ie(re(q));}}}function We(e,n={}){let i=b||m!==void 0,s={hold:void 0,opened:r(),waiters:new Set},p=n.signal,d={reason:e,get released(){return i},release(){if(!i){i=true,y.delete(d),p?.removeEventListener("abort",d.release);for(let g of s.waiters)g();s.waiters.clear();}}};return s.hold=d,i||(y.set(d,s),p?.aborted?d.release():p?.addEventListener("abort",d.release,{once:true})),d}function Ne(e,n,i={}){let s=Ae(),p={kind:e,args:n,watermark:v,attempt:0,done:false,signal:i.signal,result:s,cleanup:()=>{}},d=[...y.values()].filter(U=>U.hold!==i.within),g=new Map,q=i.signal,W=()=>ee(p,de("superseded","aborted"));if(p.cleanup=()=>{q?.removeEventListener("abort",W);for(let[U,te]of g)U.waiters.delete(te.release),te.cancel();g.clear();},E.add(p),b)ee(p,de("disposed"));else if(m)ee(p,m);else if(!t.queries||!J(t.queries,e)||!f?.connection.client.call.query)ee(p,de("unsupported"));else if(q?.aborted)W();else if(d.some(U=>r()-U.opened>=ye))ee(p,de("busy"));else if(q?.addEventListener("abort",W,{once:true}),d.length===0)H.add(p),ue();else for(let U of d){let te=()=>{if(q?.aborted){W();return}if(r()-U.opened>=ye){ee(p,de("busy"));return}g.get(U).cancel(),g.delete(U),U.waiters.delete(te),g.size===0&&!p.done&&(p.watermark=v,H.add(p),ue());},Re={release:te,cancel:()=>{}};g.set(U,Re),U.waiters.add(te),Re.cancel=S(()=>ee(p,de("busy")),Math.max(0,ye-(r()-U.opened)));}return s.promise}function ft(){for(let e of y.keys())e.release();}function fe(e){if(e!==void 0)try{t.discardFrame?.(e);}catch{}}function mt(){c={...c,presentedThroughSeq:I.presentedThroughSeq};let e=c;for(let n of [...z]){if(b||m||c!==e)break;if(z.has(n))try{n(e);}catch{}}}function pt(e){!e.ackSettled||!e.presentationSettled||e.released||(e.released=true,M.delete(e));}function ge(e,n){e.presentationSettled||(e.presentationSettled=true,O.delete(e),e.presentation.resolve(n),e.seq!==void 0&&($.delete(e.seq),_.delete(e.seq),N$1.get(e.seq)?.resolve(n),N$1.delete(e.seq)),pt(e));}function qe(e,n){e.ackSettled||(e.ackSettled=true,e.outcome=n,e.ack.resolve(n),pt(e));}function jt(){let e=Ae(),n=Ae(),i={ticket:{id:++v,get seq(){return x.get(i.ticket).seq},get ack(){return x.get(i.ticket).ack.promise},get presented(){return x.get(i.ticket).presentation.promise}},ack:e,presentation:n,ackSettled:false,presentationSettled:false};return x.set(i.ticket,i),M.add(i),i}function Ut(e,n){for(let i of e){let s=x.get(i);qe(s,{seq:s.seq,status:"cancelled",reason:n}),ge(s,"dropped");}I.drop(e,n);}function Le(e,n=false){let i=st(D,e);for(;;){if(Ut(i.map(s=>s.tickets[0]),"dependency-refused"),i.length<64){H.size&&ue();return}if(!n){ht(()=>Le([]));return}i=st(D,[]);}}function ht(e){try{w(()=>{if(!(b||m))try{I.event(e);}catch(n){le(re(n));}});}catch(n){le(re(n));}}function yt(e){let n=x.get(e);if(n?.seq!==void 0&&Y.contains(n.seq))return true;let i=n?.seq===void 0?void 0:Q.get(n.seq);return be(i?.outcome??n?.outcome)}function gt(e){try{Y.add(e);}catch(n){throw le(re(n)),n}}function je(e,n){try{t.recovery.onRecovery?.({phase:e,incarnation:F,attempt:ce,diverged:[...pe].sort((i,s)=>i-s),historyReset:u!==void 0,failure:n});}catch{}}function Pt(e,n,i,s=false){if(e.outcome&&!i&&!s||e.outcome&&n.status==="duplicate")return;let p=e.outcome,d=e.group;if(p||(Z-=1),De(p)&&(me-=1),e.outcome=n,De(n)&&(me+=1),J$1.delete(n.seq),be(n)&&gt(n.seq),d.outcome=n,qe(d,n),!be(n)){e.presentationStatus!==void 0&&ge(d,e.presentationStatus);return}ge(d,"dropped"),I.drop([e.ticket],n.reason??n.status),Le([e.ticket]),i&&!be(p)&&(pe.add(e.envelope.seq),St(e.envelope.seq),je("diverged"));}function St(e){let n=ne.get(e);n&&(A.add(n.values()),ne.delete(e)),!R&&Ve();}function Ve(e=false){if(R=true,b||m)return;let n=e?1/0:64;for(;A.size&&n>0;){n-=1;let i=A.values().next().value,s=i.next();if(s.done){A.delete(i);continue}let p=ne.get(s.value);p&&(A.add(p.values()),ne.delete(s.value));let d=Q.get(s.value);!d||be(d.outcome)||(gt(d.envelope.seq),d.outcome||(Z-=1),De(d.outcome)&&(me-=1),d.outcome={seq:d.envelope.seq,status:"cancelled",reason:"dependency-refused"},J$1.delete(d.envelope.seq),C&&pe.add(d.envelope.seq),d.group.outcome=d.outcome,qe(d.group,d.outcome),ge(d.group,"dropped"),I.drop([d.ticket],"dependency-refused"),Le([d.ticket],e));}A.size?(L??(L=Ae()),ht(Ve)):(R=false,L?.resolve(),L=void 0);}function Fe(e,n,i=false){let s=n?.frame;if(!B(e))return fe(s),false;if(!g$1(n))return fe(s),ie(new N("message","Malformed command acknowledgement")),false;if(n.session!==h||n.incarnation!==F||n.epoch!==l)return fe(n.frame),false;if(n.throughSeq>T||n.frame&&n.frame.coversThroughSeq>T||n.outcomes.some(g=>g.seq>n.throughSeq))return fe(n.frame),ie(new N("message","Command acknowledgement exceeds sent coverage")),false;let p=false,d=false;try{I.event(()=>{for(let q of n.outcomes){let W=Q.get(q.seq);W&&Pt(W,q,i);}let g=Q.get(n.throughSeq);g&&(g.confirmedVersion=n.version),(n.throughSeq>c.throughSeq||n.throughSeq===c.throughSeq&&n.version>=c.version)&&(c={...c,throughSeq:n.throughSeq,version:n.version}),"selection"in n&&n.throughSeq>=Ie&&(c={...c,selection:n.selection},Ie=n.throughSeq),"editState"in n&&n.throughSeq>=Me&&(c={...c,editState:n.editState},Me=n.throughSeq),n.revisions&&n.throughSeq>=ve&&(he=n.throughSeq===ve?Math.max(he,n.revisions.selection):n.revisions.selection,Pe=n.throughSeq===ve?Math.max(Pe,n.revisions.layout):n.revisions.layout,ve=n.throughSeq),n.frame&&(d=!0,p=bt(n.frame)),P===0&&A.size===0&&$e(c.throughSeq,!0),mt(),t.onAck?.(n);});}catch(g){return d||fe(n.frame),le(g instanceof N?g:new N("message",g instanceof Error?g.message:String(g))),false}return ke(),p}function bt(e){let n=I.presentedThroughSeq,i=ae;ae=true,oe=e.coversThroughSeq,G=e.revision;try{let s=I.present(e),p=!!t.transactionalPresentation&&!ae;if(s!=="presented"||I.presentedThroughSeq<=n)return p;let d=ae?"presented":"dropped",g=Math.min(I.presentedThroughSeq,e.coversThroughSeq);for(let[q,W]of _){if(q>g)break;_.delete(q),W.presentationStatus=d,!(!W.outcome||be(W.outcome))&&ge(W.group,d);}return p}finally{ae=i;}}function zt(e,n){if(!B(e)||C){fe(n);return}if(n===void 0||!g$1({session:h,incarnation:F,epoch:l,throughSeq:c.throughSeq,version:c.version,outcomes:[],frame:n})){fe(n),ie(new N("message","Malformed command frame"));return}if(n.coversThroughSeq>c.throughSeq){fe(n);return}try{I.event(()=>{bt(n),mt();});}catch(i){le(i instanceof N?i:new N("message",i instanceof Error?i.message:String(i)));}}function Se(e,n){if(!e.active)return Promise.resolve();e.active=false,e.failure=n;try{e.unsubscribe();}catch{}try{e.unsubscribeFrame?.();}catch{}try{e.unsubscribeAck?.();}catch{}for(let i of E)i.connection===e&&(i.connection=void 0,i.attempt+=1,H.add(i));e.cancelReplay?.(n),e.cancelReplay=void 0;try{return Promise.resolve(e.connection.client.dispose()).catch(()=>{})}catch{return Promise.resolve()}}function vt(e){let n={connection:e,active:true,fullFrameBusy:false,fullFrameThroughSeq:-1,fullFrameRetries:0,seenSeq:T,seenMark:T,unsubscribe:()=>{}};f=n;let i=e.client.onFailure(s=>{B(n)&&(C?Se(n,s):ie(s));});if(n.active?n.unsubscribe=i:i(),n.active&&e.client.onFrame){let s=e.client.onFrame(p=>zt(n,p));n.active?n.unsubscribeFrame=s:s();}if(n.active&&e.client.onAck){let s=e.client.onAck(p=>Fe(n,p));n.active?n.unsubscribeAck=s:s();}return n}function le(e){if(!(b||m)){m=e,C=false;for(let n of E)ee(n,e);ft(),f&&Se(f,e),D.clear(),J$1.clear(),I.dispose();for(let n of [...M])n.ackSettled||(n.ackSettled=true,n.ack.reject(e)),ge(n,"dropped");Q.clear(),ne.clear(),A.clear(),L?.resolve(),L=void 0,$.clear(),_.clear();for(let n of N$1.values())n.resolve("dropped");N$1.clear(),Y.clear(),z.clear(),je("failed",e),pe.clear();}}function ie(e){if(!(b||m)){if(C){f&&Se(f,e);return}if(P===0||!ct(e)){if(P===0&&ct(e))try{I.event(()=>{Le([],!0),Ve(!0);});}catch(n){le(re(n));return}le(e);return}C=true,ce=0,pe.clear(),f&&Se(f,e),J$1.clear(),K=false,Kt(e).catch(n=>le(re(n)));}}function Ge(e,n,i){let s=h$1(n)?n.refusal.seq:e.envelope.seq,p=Q.get(s)??e;return I.event(()=>{Pt(p,{seq:p.envelope.seq,status:"refused",reason:"unknown-outcome"},i,true),St(p.envelope.seq);}),re(n)}function _t(e,n){return new Promise((i,s)=>{let p=false;function d(q){p||(p=true,e.cancelReplay===g&&(e.cancelReplay=void 0),q());}let g=q=>d(()=>s(q));if(e.cancelReplay=g,!B(e)){g(e.failure??new N("disposed","Command connection is closed"));return}try{e.connection.client.call.edit(t.copyCommandForDispatch?.(n)??Oe(n)).then(q=>{p?fe(q?.frame):d(()=>i(q));},q=>d(()=>s(q)));}catch(q){d(()=>s(q));}})}async function Kt(e){let n=e;for(;!b&&!m&&ce<P;){if(ce+=1,F+=1,je("recovering",n),b||m)return;let i;try{if(L&&await L.promise,b||m)return;let s=u&&{...u,state:u.state.slice()},p=await t.recovery.reopen({source:Oe(a),checkpoint:s,session:h,incarnation:F,epoch:l,refusedSeqs:Y.values(),replayAppliedSeqs:[...Q.values()].filter(U=>De(U.outcome)).map(U=>U.envelope.seq)}),d=p.initial;if(i=d?.frame,b||m){fe(i),i=void 0;try{await p.client.dispose();}catch{}return}let g=vt(p);if(!g$1(d)||d.session!==h||d.incarnation!==F||d.epoch!==l||d.throughSeq!==(u?.throughSeq??o.throughSeq)||d.version!==(u?.version??o.version))throw new N("message","Reopened command connection has invalid initial state");if(p.client.failure)throw p.client.failure;I.reset(),_.clear();for(let[U,te]of $)te.presentationStatus=void 0,_.set(U,te);c={epoch:l,version:d.version,throughSeq:d.throughSeq,presentedThroughSeq:-1,selection:d.selection,editState:d.editState},Ie=d.throughSeq,Me=d.throughSeq,ve=d.throughSeq,he=d.revisions?.selection??0,Pe=d.revisions?.layout??0,i=void 0,Fe(g,d);let q=[...Q.values()].sort((U,te)=>U.envelope.seq-te.envelope.seq),W=d.throughSeq;for(let U of q){if(!B(g))throw g.failure;if(be(U.outcome))continue;let te={...U.envelope,incarnation:F,replay:!0},Re;try{Re=await _t(g,te);}catch(Xe){throw Xe instanceof N?Xe:Ge(U,Xe,!0)}if(W=Math.max(W,U.envelope.seq),Fe(g,Re,!0),L&&await L.promise,!B(g)){if(b||m)return;throw g.failure}if(!Re.outcomes.some(Xe=>Xe.seq===U.envelope.seq))throw new N("message","Replay acknowledgement omitted command outcome")}if(!B(g))throw g.failure;g.seenSeq=W,g.seenMark=T,C=!1,se=-1,je("recovered"),pe.clear(),H.size&&ue(),ke();return}catch(s){if(n=re(s),f&&Se(f,n),b||m)return;if(!ct(n))break}finally{fe(i);}}!b&&!m&&le(n);}function Ht(e,n){let i=f;!i||!B(i)||((i.fullFrameRevision===void 0||e>i.fullFrameThroughSeq||e===i.fullFrameThroughSeq&&n>i.fullFrameRevision)&&(i.fullFrameThroughSeq=e,i.fullFrameRevision=n),Ye(i));}function Ct(e){return I.presentedThroughSeq>e.fullFrameThroughSeq||I.presentedThroughSeq===e.fullFrameThroughSeq&&(!t.sameCoverageFrames||I.revision!==void 0&&I.revision>=e.fullFrameRevision)}function Ye(e){if(!B(e)||e.fullFrameBusy)return;e.fullFrameBusy=true;let n=e.fullFrameThroughSeq,i=e.fullFrameRevision;try{t.requestFullFrame(e.connection).then(s=>{if(!B(e)){fe(s?.frame);return}let p=I.presentedThroughSeq,d=Fe(e,s);if(e.fullFrameBusy=!1,!!B(e)){if(d){if(e.fullFrameRetries=0,(e.fullFrameThroughSeq>n||e.fullFrameThroughSeq===n&&e.fullFrameRevision>i)&&!Ct(e)){Ye(e);return}e.fullFrameThroughSeq=-1,e.fullFrameRevision=void 0;return}if(Ct(e)){e.fullFrameRetries=0,e.fullFrameThroughSeq=-1,e.fullFrameRevision=void 0;return}if(e.fullFrameRetries=I.presentedThroughSeq>p?0:e.fullFrameRetries+1,e.fullFrameRetries>=4){let g=new N("message","Full frame responses did not satisfy requested coverage and revision");C?Se(e,g):le(g);return}Ye(e);}},s=>{B(e)&&(e.fullFrameBusy=!1,C?Se(e,re(s)):ie(re(s)));}).catch(s=>{B(e)&&(e.fullFrameBusy=!1,ie(re(s)));});}catch(s){e.fullFrameBusy=false,C?Se(e,re(s)):ie(re(s));}}function Vt(){if(P===0||!t.recovery.checkpoint||c.throughSeq===se)return false;let e=me,n=Ce;return e===0&&n===0?false:t.checkpointPolicy?t.checkpointPolicy({applied:e,bytes:n}):e>=128||n>=1024*1024}function Gt(e){if(!e||typeof e!="object"||!(e.state instanceof Uint8Array)||e.epoch!==l||!Number.isSafeInteger(e.throughSeq)||e.throughSeq<0||e.throughSeq>c.throughSeq||!Number.isFinite(e.version)||e.version>c.version||u&&(e.throughSeq<u.throughSeq||e.version<u.version)||e.throughSeq===c.throughSeq&&e.version!==c.version)return false;let n=Q.get(e.throughSeq),i=u?.throughSeq===e.throughSeq?u.version:o.throughSeq===e.throughSeq?o.version:n?.confirmedVersion;if(i===void 0||i!==e.version)return false;for(let s of Q.values())if(s.envelope.seq<=e.throughSeq&&!s.outcome)return false;return true}function Yt(e){K=true,se=c.throughSeq;let n=t.recovery.checkpoint,i;try{i=n(e.connection);}catch(s){K=false,s instanceof N?ie(s):ke();return}i.then(s=>{B(e)&&(Gt(s)&&(u={...s,state:s.state.slice()},$e(s.throughSeq)),K=false,ke());},s=>{B(e)&&(K=false,s instanceof N?ie(s):ke());}).catch(s=>{B(e)&&(K=false,ie(re(s)));});}function $e(e,n=false){for(let[i,s]of Q){if(i>e||n&&(!s.outcome||!s.rpcSettled))break;De(s.outcome)&&(me-=1),Ce-=s.bytes;let p=s.envelope.afterSeq;if(p!==void 0){let d=ne.get(p);d?.delete(i),d?.size===0&&ne.delete(p);}Q.delete(i);}}function Je(e){e.rpcSettled=true,P===0&&A.size===0&&$e(c.throughSeq,true);}function $t(e){if(t.holdForCoalescing?.(e.draft)!==true)return false;let n=e.draft.options.after;if(n)return n.seq!==void 0&&J$1.get(n.seq)===true;for(let i of J$1.values())if(i)return true;return false}function Jt(e){let n=e.draft.options.after;if(!n)return true;let i=x.get(n);return i!==void 0&&i.seq!==void 0&&!yt(n)}function Zt(e,n){if(T>=Number.MAX_SAFE_INTEGER){le(new N("message","Command sequence space is exhausted"));return}let i=++T,s=e.draft,p=s.options,d={session:h,incarnation:F,seq:i,basis:{epoch:l,version:c.version},kind:s.kind,payload:s.payload,...p.after?{afterSeq:p.after.seq}:{},...p.expectVersion!==void 0?{expectVersion:p.expectVersion}:{},...p.inputTime!==void 0?{inputTime:p.inputTime}:{},...p.lastInputTime!==void 0?{lastInputTime:p.lastInputTime}:{},...p.group!==void 0?{group:p.group}:{}},g=x.get(e.tickets[0]),q={envelope:d,ticket:e.tickets[0],group:g,rpcSettled:false,bytes:0};if(Q.set(i,q),$.set(i,q),_.set(i,q),Z+=1,g.seq=i,d.afterSeq!==void 0){let W=ne.get(d.afterSeq);W||ne.set(d.afterSeq,W=new Set),W.add(i);}if($.size>1024){let W=$.values().next().value;W.presentationStatus="dropped",ge(W.group,"dropped"),I.drop([W.ticket],"presentation-overflow");}if(B(n)){J$1.set(i,t.holdForCoalescing?.(s)===true);try{q.envelope=Oe(d);let W=t.commandBytes?.(q.envelope)??0;q.bytes=Number.isFinite(W)&&W>=0?W:0,Ce+=q.bytes;let U=t.copyCommandForDispatch?.(d)??Oe(q.envelope);n.connection.client.call.edit(U).then(te=>{try{Fe(n,te);}finally{Je(q);}},te=>{try{B(n)&&ie(te instanceof N?te:Ge(q,te,!1));}finally{Je(q);}}).catch(te=>{B(n)&&ie(re(te));});}catch(W){try{B(n)&&ie(W instanceof N?W:Ge(q,W,!1));}finally{Je(q);}}H.size&&ue();}}function en(){let e=f;if(!(!e||!B(e)||C||K)){if(Vt()){J$1.size===0&&Z===0&&Yt(e);return}for(;B(e)&&!C&&J$1.size<k;){let n=D.takeNext(Jt,t.holdForCoalescing?$t:void 0);if(!n)break;Zt(n,e);}}}function ke(){if(!(b||m||C||X)){X=true;try{w(()=>{X=!1;try{en();}catch(e){le(re(e));}});}catch(e){X=false,le(re(e));}}}function tn(e,n,i={}){let s=jt();if(b)return qe(s,{status:"cancelled",reason:"disposed"}),ge(s,"dropped"),s.ticket;if(m)return s.ackSettled=true,s.ack.reject(m),ge(s,"dropped"),s.ticket;let p=i.after&&x.get(i.after);if(i.after&&(!p||yt(i.after)))return qe(s,{status:"cancelled",reason:"dependency-refused"}),ge(s,"dropped"),s.ticket;let d={kind:e,payload:n,options:{...i}};try{I.event(()=>{let g=D.enqueue(d,s.ticket);g.tickets.length>1&&(x.set(s.ticket,x.get(g.tickets[0])),M.delete(s)),O.set(x.get(g.tickets[0]),{draft:g.draft,originalIntentCount:g.tickets.length});let q=g.draft.options.echo,W=q===void 0?void 0:{ticket:g.tickets[0],value:q};g.tickets.length>1?I.replace([g.tickets[0]],W):W&&I.add(W);});}catch(g){le(re(g));}return ke(),s.ticket}function nn(e,n){if(b||m||C)return false;let i=new Set,s=[];for(let p of e){let d=x.get(p);if(!d||d.presentationSettled||be(d.outcome)||d.seq!==void 0&&d.seq<=I.presentedThroughSeq)return false;i.add(d);}for(let p of [...i].sort((d,g)=>d.ticket.id-g.ticket.id)){let d=O.get(p);if(!d||d.draft.options.echo!==void 0)return false;let g=n(d.draft,d.originalIntentCount);if(g===void 0)return false;s.push({record:p,entry:d,value:g});}return I.event(()=>{if(b||m||C||s.some(({record:d,entry:g})=>d.presentationSettled||be(d.outcome)||d.seq!==void 0&&d.seq<=I.presentedThroughSeq||O.get(d)!==g||g.draft.options.echo!==void 0))return false;for(let{entry:d,value:g}of s)d.draft.options.echo=g;let p=I.attach(s.map(({record:d,value:g})=>({ticket:d.ticket,value:g})));if(!p)for(let{entry:d}of s)d.draft.options.echo=void 0;return p})}let rn={backend:"worker",get state(){return c},submit:tn,attachEcho:nn,read:Ne,hold:We,get stage(){return b?"disposed":m?"failed":C?"recovering":"ready"},whenPresented(e){if(b||m)return Promise.resolve("dropped");let n=Q.get(e)??$.get(e);if(Y.contains(e))return Promise.resolve("dropped");let i=n&&x.get(n.ticket);if(i)return i.presentation.promise;if(e<=T)return I.whenPresented(e);let s=N$1.get(e);if(s)return s.promise;if(N$1.size>=1024){let d=N$1.keys().next().value;N$1.get(d).resolve("dropped"),N$1.delete(d);}let p=Ae();return N$1.set(e,p),p.promise},subscribe(e){return b||m?()=>{}:(z.add(e),()=>{z.delete(e);})},flush(){if(It(D),m)return Promise.reject(m);let e=[...M].filter(i=>!i.ackSettled).map(i=>i.ack.promise);ke();let n=Promise.all(e).then(()=>{});return n.catch(()=>{}),n},dispose(){if(V)return V;let e=Ae();V=e.promise,b=true,C=false;for(let i of E)ee(i,de("disposed"));ft();let n=f?Se(f,new N("disposed","Edit session was disposed")):Promise.resolve();D.clear(),J$1.clear(),I.dispose();for(let i of [...M])qe(i,{seq:i.seq,status:"cancelled",reason:"disposed"}),ge(i,"dropped");Q.clear(),ne.clear(),A.clear(),L?.resolve(),L=void 0,$.clear(),_.clear();for(let i of N$1.values())i.resolve("dropped");return N$1.clear(),Y.clear(),z.clear(),pe.clear(),n.then(()=>e.resolve()),V}},on=vt(t.connection);return Fe(on,o),t.connection.client.failure&&ie(t.connection.client.failure),rn}var dt=Symbol.for("betteroffice.pptx.sharedInput"),Ee={get(t){return t[dt]},set(t,o){Object.defineProperty(t,dt,{value:o,configurable:true});},delete(t){delete t[dt];}};async function Tn(t,o,P){return Lt(t,o,P,false)}async function Nt(t,o,P){return Lt(t,o,P,true)}async function Lt(t,o,P,a){let h$1=At(),l=[],k=new WeakMap,w=false;function x(){if(!w){w=true;try{for(;l[0]?.ready;)h$1.receive(l.shift().batches);}finally{w=false;}}}function O(r,S){let y=S!==null&&typeof S=="object"&&"outcomes"in S,E={batches:r,ready:!y};l.push(E),y&&k.set(S,E),x();}function M(r){let S=k.get(r);S&&(S.ready=true,k.delete(r)),x();}let z=new Set,Q=new Set,A=h({post(r,S){let y=K(r)&&r.kind==="call"?r.id:void 0;y!==void 0&&Q.add(y);try{P.post(r,S);}catch(E){y!==void 0&&Q.delete(y);let H=E instanceof N?E:new N("crash",E instanceof Error?E.message:String(E));for(let D of [...z])D(H);throw H}},listen(r){return P.listen(S=>{if(L(S)&&(S.kind==="reply"||S.kind==="event"&&S.name==="ack")){let y=S.collabPipe,E=S.kind==="event"||Q.delete(S.id);y&&O(y,E?S.kind==="event"?S.payload:S.ok?S.value:void 0:void 0);}r(S);})},onError(r){z.add(r);let S=P.onError(r);return ()=>{z.delete(r),S();}},close(){P.close();}},{methods:{...n,edit:true,checkpoint:true}}),R,L$1,$;try{let r=He(t),S=[r],y={...o,fonts:o.fonts?.map(D=>{let I=He(D.bytes);return S.push(I),{...D,bytes:I}}),fallbackFonts:o.fallbackFonts?.map(D=>{let I=He(D.bytes);return S.push(I),{...D,bytes:I}})};if(o.initialUpdate!==void 0){let D=He(o.initialUpdate);y.initialUpdate=new Uint8Array(D),S.push(D);}if(o.wasm instanceof ArrayBuffer&&(y.wasm=o.wasm.slice(0),S.push(y.wasm)),R=await A.callWithTransfer("openCommandEditor",[r,y],S),A.failure)throw A.failure;let{shared:E,...H}=R;a&&(L$1=j(E),$=E),M(R),R=H;}catch(r){throw await A.dispose(),r}let _=R.throughSeq,N$1=false,Y,J,v$1=new Set,T=new Set,F=new Set,u=new Set,f=new Set,c=R.throughSeq,b=new Set,m$1=new Map;for(let r of R.frame?.media??[])m$1.set(r.assetId,r.bytes);function C(r){if(r?.incarnation!==R.incarnation||r.documentEpoch!==R.epoch)return;let S=r.media.filter(y=>m$1.get(y.assetId)!==y.bytes);for(let y of S)m$1.set(y.assetId,y.bytes);S.length&&X(F,S);}function X(r,S,y=true){for(let E of [...r]){if(N$1||y&&Y)break;if(r.has(E))try{E(S);}catch{}}}function K$1(r){let S=se(r);return M(r),S}function se(r){if(N$1||Y||r.session!==R.session||r.incarnation!==R.incarnation||r.epoch!==R.epoch||(C(r.frame),N$1||Y)||r.throughSeq<R.throughSeq)return r;let S=r.throughSeq>R.throughSeq,y=r.frame,E=y!=null&&y.incarnation===R.incarnation&&y.documentEpoch===R.epoch&&y.coversThroughSeq===r.throughSeq&&(y.slideId===R.activeSlideId||y.slideId===r.activeSlideId)&&y.version===r.version&&y.epoch>(R.frame?.epoch??0);if(R={...R,...r,frame:E?y:r.frame===null?null:R.frame,activeSlideId:E?y.slideId:r.activeSlideId===null?null:R.activeSlideId},E&&X(T,y),S&&!Y&&X(v$1,r),r.throughSeq>c){c=r.throughSeq;for(let H of r.updates??[])for(let D of [...f]){if(N$1||Y)break;if(f.has(D))try{D(new Uint8Array(H.bytes).slice(),H.origin);}catch{}}}return r}function ae(){R={...R,editState:{...R.editState,readOnly:true,toolbar:{...R.editState.toolbar,canEditText:false}}};}function oe(r){N$1||Y||(Y=r,l.length=0,h$1.lose("Collaboration worker failed"),ae(),X(u,r,false));}function G(){return N$1?new Error("Presentation command client is disposed"):Y}function V(r,S){if(r instanceof Error&&r.name==="CommandOutcomeUnknown"){let y="refusal"in r?r.refusal:void 0,E=y!==null&&typeof y=="object"&&"seq"in y&&typeof y.seq=="number"?y.seq:S;oe(new m(E,r.message));}throw A.failure&&oe(A.failure),Y??r}let ce={session:R.session,incarnation:R.incarnation},Ie=A.on("ack",K$1),Me=A.on("collaborationPipe",O),ve=A.onFailure(oe),he=(r=_)=>({...ce,seq:r}),Pe=new Map,me=new Map,Ce=$,Z=$&&L$1?Wt({source:void 0,connection:{initial:$,client:{call:{edit(r){let S=G();if(S)return Promise.reject(S);_=r.seq,X(b,void 0);let{basis:y,intent:E}=r.payload,H="at"in E.payload?E.payload.at:void 0,D=r.afterSeq??(H?.source==="afterSeq"?H.seq:void 0),I=D===void 0?E:An(E,D),B=L$1.envelope({...ce,seq:r.seq,basis:y,...I,...D===void 0?{}:{afterSeq:D}}),ee=E.kind==="insertPicture"?E.payload.bytes.slice(0):null;return (ee?A.callWithTransfer("edit",[{...B,payload:{...B.payload,bytes:ee}}],[ee]):I.kind==="collabPipe"?A.callWithTransfer("edit",[B],v(I.payload.ops)):A.call.edit(B)).then(ue=>{ue.throughSeq>=Ce.throughSeq&&(Ce=ue);let We=L$1.ack(ue),Ne=k.get(ue);return Ne&&(k.set(We,Ne),k.delete(ue)),Pe.set(r.seq,We),ue},ue=>V(ue,r.seq))},checkpoint:()=>Promise.reject(new Error("Presentation recovery is disabled"))},get failure(){return A.failure},onFailure:r=>A.onFailure(r),dispose:()=>A.dispose()}},recovery:{reopen:()=>Promise.reject(new Error("Presentation recovery is disabled"))},maxRecoveryAttempts:0,maxInFlight:256,sameCoverageFrames:true,discardFrame:r=>In(r.payload),echoOverflow:"decline",enqueue:r=>r(),requestFullFrame:async()=>({...Ce,outcomes:[],frame:void 0})}):void 0,pe=Z&&{subscribeSent(r){return N$1||b.add(r),()=>{b.delete(r);}},submit(r,S,y){let E="at"in r.payload?r.payload.at:void 0,H=y??(E?.source==="afterSeq"?me.get(E.seq):void 0),D=Z.submit(r.kind,{intent:r,basis:S},{...H?{after:H}:{}});if(D.seq!==void 0)for(me.set(D.seq,D);me.size>256;)me.delete(me.keys().next().value);let I=D.ack.then(B=>{let ee=D.seq===void 0?void 0:Pe.get(D.seq);if(D.seq!==void 0&&Pe.delete(D.seq),ee)return K$1(ee);let de={seq:B.seq??_+1,status:B.status==="duplicate"?"noop":B.status,reason:On(B.reason),committed:false};return K$1({...R,frame:void 0,outcomes:[de]})},B=>{throw Y??B});return {ticket:D,operation:I}}},ye={get state(){return R},dispatch(r,S){let y=G();if(y)return Promise.reject(y);if(pe)return pe.submit(r,S??{epoch:R.epoch,version:R.version}).operation;let E=++_,H="at"in r.payload?r.payload.at:void 0,D=H?.source==="afterSeq"?H.seq:void 0,I={...ce,seq:E,basis:S??{epoch:R.epoch,version:R.version},...D===void 0?{}:{afterSeq:D},...r},B=r.kind==="insertPicture"?r.payload.bytes.slice(0):null;return (B?A.callWithTransfer("command",[{...I,payload:{...I.payload,bytes:B}}],[B]):r.kind==="collabPipe"?A.callWithTransfer("command",[I],v(r.payload.ops)):A.call.command(I)).then(K$1,de=>V(de,E))},async flush(r){let S=G();if(S)return Promise.reject(S);Z&&await Z.flush();let y=he(r);return A.call.flushCommandEditor(y).then(K$1,E=>V(E,y.seq))},async save(){let r=G();if(r)throw r;Z&&await Z.flush();let S=he();try{let y=await A.call.saveCommandEditor(S);return new Uint8Array(y.bytes)}catch(y){return V(y,S.seq)}},async access(r,...S){let y=G();if(y)throw y;Z&&await Z.flush();let E=await A.call.accessCommandEditor(he(),r,S),H=G();if(H)throw H;return E},async checkpoint(){let r=G();if(r)throw r;return Z&&await Z.flush(),A.call.checkpointCommandEditor(he())},async preparePicture(r){let S=G();if(S)throw S;Z&&await Z.flush();let y=r.slice(0);return A.callWithTransfer("prepareCommandPicture",[he(),y],[y])},async read(r){let S=G();if(S)throw S;Z&&await Z.flush();let y=he();try{let E=await A.call.readEditor(y,r);return K$1(E),E}catch(E){return V(E,y.seq)}},thumbnail(r,S){let y=G();return y?Promise.reject(y):A.call.thumbnailFrame({...ce,slideId:r,knownRevision:S}).then(E=>(N$1||Y||E.session!==R.session||E.incarnation!==R.incarnation||E.epoch!==R.epoch||E.status!=="frame"||C(E.frame),E)).catch(E=>V(E,_))},subscribe(r){return N$1||v$1.add(r),()=>{v$1.delete(r);}},subscribeFrame(r){return N$1||T.add(r),()=>{T.delete(r);}},subscribeMedia(r){return !N$1&&!Y&&(F.add(r),m$1.size&&X(new Set([r]),[...m$1].map(([S,y])=>({assetId:S,bytes:y})))),()=>{F.delete(r);}},subscribeUpdate(r){return N$1||f.add(r),()=>{f.delete(r);}},subscribeFailure(r){return N$1||u.add(r),()=>{u.delete(r);}},dispose(){return J||(N$1=true,l.length=0,h$1.lose("Collaboration replica is retired"),we.delete(ye),Me(),Ie(),ve(),v$1.clear(),T.clear(),F.clear(),u.clear(),b.clear(),f.clear(),Ee.delete(ye),m$1.clear(),Pe.clear(),me.clear(),J=Z?Z.dispose():A.dispose(),J)}};return we.set(ye,h$1),pe&&Ee.set(ye,pe),ye}function On(t){switch(t){case void 0:case "bad-target":case "invalid-offset":case "stale-basis":case "read-only":case "dependency-refused":case "invalid-composition":case "invalid-payload":case "unsupported":case "unknown-outcome":return t;case "stale-epoch":case "stale-incarnation":case "wrong-session":case "stale-version":return "stale-basis";default:return "unknown-outcome"}}function An(t,o){return {...t,payload:{...t.payload,at:{source:"afterSeq",seq:o}}}}function He(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength).slice().buffer:t.slice(0)}function In(t){if(typeof ImageBitmap!="function")return;let o=new WeakSet,P=[t];for(;P.length;){let a=P.pop();if(!(a===null||typeof a!="object"||o.has(a)))if(o.add(a),a instanceof ImageBitmap)try{a.close();}catch{}else !(a instanceof ArrayBuffer)&&!ArrayBuffer.isView(a)&&P.push(...Object.values(a));}}var ut=new Map,lt=class extends Error{constructor(P,a){super(`${P} is unavailable in the worker presentation editor${a?`; use ${a} instead`:""}`);a$1(this,"operation",P);a$1(this,"alternative",a);a$1(this,"code","sync-api-unavailable");this.name="PptxWorkerUnsupportedError";}};function Mn(t,o={}){if(o.signal?.aborted)throw new E;let P=!o.worker&&o.wasm===void 0?b().href:void 0,a=o.wasm??(P?ut.get(P):void 0),h=O(o.worker?o.worker():new Worker(new URL("./pptxSessionWorker.mjs",import.meta.url),{type:"module"}));P&&!a&&g(h);let l={session:crypto.randomUUID(),incarnation:crypto.randomUUID(),clientId:o.collaboration?.clientId??o.clientId,collaboration:o.collaboration!=null,fonts:o.fonts,fallbackFonts:o.fallbackFonts,initialUpdate:o.collaboration?.initialUpdate??o.initialUpdate,wasm:a,observeChanges:o.observeChanges,readOnly:o.readOnly,activeSlideIndex:o.activeSlideIndex},k=new Set,w=new Set,x,O$1=false,M,z,Q,ne,A,R=new Promise((u,f)=>{A=f;});R.catch(()=>{});function L$1(u){if(!(O$1||x)){x=u instanceof N||u instanceof m?u:new N(u instanceof Error&&u.name==="RuntimeError"?"trap":"crash",u instanceof Error?u.message:String(u)),z&&(ne={...z.state,editState:{...z.state.editState,readOnly:true,toolbar:{...z.state.editState.toolbar,canEditText:false}}}),A(x);for(let f of [...k])try{f(x);}catch{}try{o.onError?.(new D(x));}catch{}for(let f of [...w])f(x);h.close();}}function $(){if(O$1)throw new E;if(x)throw x}async function _(u){$();try{let f=await u();return $(),f}catch(f){throw (f instanceof N||f instanceof Error&&(f.name==="CommandOutcomeUnknown"||f.name==="RuntimeError"))&&L$1(f),x??f}}let N$1=h.onError(L$1),J=Nt(t,l,{post:(u,f)=>h.post(u,f),listen:u=>h.listen(f=>{L(f)&&(f.kind==="wasm-module"&&P&&!O$1&&!x&&f.url===P&&!ut.has(P)&&ut.set(P,f.module),f.kind==="failure"&&L$1(new N(f.code,f.message,f.diagnostics))),u(f);}),onError(u){w.add(u);let f=h.onError(u);return ()=>{w.delete(u),f();}},close(){!O$1&&!x&&L$1(new N("crash","Presentation command connection closed")),h.close();}}).then(u=>{z=u,Q=u.subscribeFailure(L$1),O$1&&Q(),$();let f={get state(){return ne??u.state},dispatch:(m,C)=>_(()=>u.dispatch(m,C)),flush:m=>_(()=>u.flush(m)),read:m=>_(()=>u.read(m)),save:()=>_(()=>u.save()),access:(m,...C)=>_(()=>u.access(m,...C)),checkpoint:()=>_(()=>u.checkpoint()),preparePicture:m=>_(()=>u.preparePicture(m)),thumbnail:(m,C)=>_(()=>u.thumbnail(m,C)),subscribe:m=>u.subscribe(m),subscribeFrame:m=>u.subscribeFrame(m),subscribeMedia:m=>u.subscribeMedia(m),subscribeUpdate:m=>u.subscribeUpdate(m),subscribeFailure:m=>T.subscribeFailure(m),dispose:()=>T.dispose()},c=we.get(u);c&&we.set(f,c);let b=Ee.get(u);return b&&Ee.set(f,{subscribeSent:m=>b.subscribeSent(m),submit(m,C,X){$();let K=b.submit(m,C,X);return {ticket:K.ticket,operation:_(()=>K.operation)}}}),f}).catch(u=>{throw O$1||L$1(u),x??u}),v=Promise.race([J,R]);v.catch(()=>{});let T={ready:v,get failure(){return x},subscribeFailure(u){return x?u(x):O$1||k.add(u),()=>{k.delete(u);}},dispose(){if(M)return M;O$1=true,A(new E),o.signal?.removeEventListener("abort",F),N$1(),Q?.(),k.clear();for(let u of [...w])u(new N("disposed","Session was disposed"));return h.close(),M=z?z.dispose():J.then(async()=>{await z?.dispose();},async()=>{await z?.dispose();}),M}};function F(){T.dispose();}return o.signal?.addEventListener("abort",F,{once:true}),o.signal?.aborted&&F(),T}export{lt as PptxWorkerUnsupportedError,En as browserFrameImages,Mn as createPptxWorkerSession,Tn as createPresentationCommandClient,we as presentationCollaborationPipes,Ee as presentationSharedInputs};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@betteroffice/pptx",
3
- "version": "0.2.0",
4
- "description": "PowerPoint-faithful PPTX editor and viewer core — full OOXML fidelity, real-time human + AI agent collaboration. Framework-free (Rust/Wasm).",
3
+ "version": "0.5.0",
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",
7
7
  "powerpoint",
@@ -25,7 +25,10 @@
25
25
  "rust"
26
26
  ],
27
27
  "type": "module",
28
- "sideEffects": false,
28
+ "sideEffects": [
29
+ "**/pptxSessionWorker.*",
30
+ "**/session/worker.*"
31
+ ],
29
32
  "main": "./dist/index.js",
30
33
  "module": "./dist/index.js",
31
34
  "types": "./dist/index.d.ts",
@@ -33,6 +36,14 @@
33
36
  ".": {
34
37
  "types": "./dist/index.d.ts",
35
38
  "import": "./dist/index.js"
39
+ },
40
+ "./worker": {
41
+ "types": "./dist/worker.d.ts",
42
+ "import": "./dist/worker.js"
43
+ },
44
+ "./collaboration": {
45
+ "types": "./dist/collaboration.d.ts",
46
+ "import": "./dist/collaboration.js"
36
47
  }
37
48
  },
38
49
  "files": [
@@ -56,6 +67,9 @@
56
67
  "url": "https://github.com/openooxml/betteroffice.git",
57
68
  "directory": "packages/pptx"
58
69
  },
70
+ "bugs": {
71
+ "url": "https://github.com/openooxml/betteroffice/issues"
72
+ },
59
73
  "publishConfig": {
60
74
  "access": "public"
61
75
  }