@pptx-editor.dev/pro 0.3.1 → 0.3.2-canary.20261110032720.sha-1742572

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,6 +23,7 @@ Commercial capabilities for PPTX Editor, delivered as `EditorModule`s, in the sa
23
23
  - `collaborationModule({ session })`: attaches a host-created collaboration session to each opened deck.
24
24
  - `createYjsCollaborationSession({ doc, documentId, identity, awareness })`: a session over a Y.Doc. It keeps the deck in Yjs, as DOCX Editor does, so concurrent edits merge without a server sequencer.
25
25
  - **History:** while the session is attached, the editor's undo and redo revert only your own changes (`Y.UndoManager`), never a peer's, and return to the slide and selection of the undone change.
26
+ - **Joining:** `readCollaborationFormatVersion(doc)` reads a room's format version without joining, and throws `CollaborationSchemaError` with `not-initialized` while the Y.Doc holds no room. A participant who joins waits for the room before creating the session, so it never seeds a second copy. Compare the version with `COLLABORATION_FORMAT_VERSION`.
26
27
  - **Status:** `statusSnapshot()` and `subscribeStatus()` report the state and a typed `CollaborationFailureCode`, as in DOCX Editor. Call `setConnected()` from your provider's status event.
27
28
  - **Concurrent edits:** two peers that add or replace an element that a slide, shape, or paragraph holds once end with one element, and the other peer's copy stays hidden in the room until the winner undoes. Property elements merge. Concurrent splits of one run keep its text once, and a node moved into content that a peer removes at once goes back. The `collaboration.realtime` row in `docs/site/data/pptx-features.ts` states what is supported and its limits. A room from a pre-release build (room format 1) refuses to attach.
28
29
  - **Presence:** with a Yjs `awareness` (`y-protocols/awareness`), the editor publishes its selection, and the canvas shows each peer's selected shapes and text caret, with the peer's name and color. Your caret stays on its character while peers type before it.
package/dist/index.d.ts CHANGED
@@ -89,5 +89,23 @@ declare class CollaborationSchemaError extends Error {
89
89
  detail?: string | undefined);
90
90
  }
91
91
 
92
- export { CollaborationSchemaError, ProLicenseOptions, collaborationModule, createYjsCollaborationSession, legacyComments };
92
+ /**
93
+ * The room format version that this release writes and opens, as an opaque string. A session
94
+ * refuses a room with another version (`schema-version-mismatch`).
95
+ *
96
+ * @public
97
+ */
98
+ declare const COLLABORATION_FORMAT_VERSION: string;
99
+ /**
100
+ * Read the format version that a room records. Reads only the room's metadata: it does not
101
+ * join the room, change it, or check its content. Compare the result with
102
+ * {@link COLLABORATION_FORMAT_VERSION}.
103
+ *
104
+ * @throws CollaborationSchemaError with `not-initialized` when the Y.Doc holds no room yet,
105
+ * or `schema-version-mismatch` when the room's version information is malformed.
106
+ * @public
107
+ */
108
+ declare function readCollaborationFormatVersion(doc: Y.Doc): string;
109
+
110
+ export { COLLABORATION_FORMAT_VERSION, CollaborationSchemaError, ProLicenseOptions, collaborationModule, createYjsCollaborationSession, legacyComments, readCollaborationFormatVersion };
93
111
  export type { AwarenessLike, CollaborationModuleOptions, YjsCollaborationSession, YjsCollaborationSessionOptions };
package/dist/index.js CHANGED
@@ -3,5 +3,5 @@ Copyright (c) 2026 Eigenpal, Inc. All rights reserved.
3
3
  Licensed under the EigenPal Pro Evaluation License 1.0. See LICENSE.md in this package.
4
4
  Production use requires a commercial agreement: licensing@eigenpal.com
5
5
  */
6
- import{a as gr}from"./chunk-B3UUTQS4.js";import{a as Bn}from"./chunk-HCD7IVOL.js";import{attr as Ce,binaryPartOf as hr,elements as en,parseXmlPart as mr,mainPresentationPart as yr,presentationInfo as kr,relTargetByType as Vn,textOf as wr,xmlPartOf as Sr}from"@pptx-editor.dev/core/store";var qn="http://schemas.openxmlformats.org/officeDocument/2006/relationships",xr=`${qn}/comments`,Mr=`${qn}/commentAuthors`;function Jn(t,e){let o=Sr(t,e);if(o||!e)return o;let n=hr(t,e);if(!n)return;let s=mr(e,new TextDecoder().decode(n));return s.ok?s.part:void 0}function br(t){let e=Object.create(null),o=yr(t);if(!o)return e;let n=Jn(t,Vn(t,o,Mr));for(let s of en(n?.root)){if(s.local!=="cmAuthor")continue;let i=Ce(s,"id"),r=Ce(s,"name");i!==void 0&&r!==void 0&&(e[i]=r)}return e}function Zt(t,e){for(let o of en(t)){if(o.local===e)return o;let n=Zt(o,e);if(n)return n}}var Un=t=>encodeURIComponent(t).replace(/-/g,"%2D"),Hn=(t,e,o)=>`${t}#cm-${Un(e)}-${Un(o)}`;function Rr(t){let e=br(t),o=[];for(let n of kr(t).slides){let s=Jn(t,Vn(t,n.partName,xr));for(let i of en(s?.root)){if(i.local!=="cm")continue;let r=Ce(i,"authorId")??"",c=Ce(i,"idx")??"",l=Zt(i,"parentCm"),f=e[r],u=Ce(i,"dt");o.push({id:Hn(n.partName,r,c),kind:"comment",slidePart:n.partName,text:wr(Zt(i,"text")),...f!==void 0?{author:f}:{},...u!==void 0?{date:u}:{},...l?{parentId:Hn(n.partName,Ce(l,"authorId")??"",Ce(l,"idx")??"")}:{}})}}return o}function Yr(t){return Bn(t.licenseKey),{id:"collaboration",collaboration:{session:t.session}}}import*as ke from"yjs";import{createCollaborationStatusTracker as ec}from"@pptx-editor.dev/core/editor";var Be=class extends Error{constructor(o,n){let s=n?`${o}: ${n}`:o;super(o==="schema-version-mismatch"?`${s}
7
- Collaboration upgrade required. Save local changes and use a compatible app version.`:s);this.code=o;this.detail=n;this.name="CollaborationSchemaError"}code;detail};import*as B from"yjs";import{buildReplicaPart as Si}from"@pptx-editor.dev/core/store";import"yjs";var bt=7,Er="pptx-meta-v1",Ir="pptx-parts-v1",vr="pptx-binaries-v1",Pr="pptx-nodes-v1",A=Object.freeze({part:"p",key:"k",shell:"s",attrs:"a",children:"c",text:"x"}),Rt="",Qn=2**40,Yt=Object.freeze({kind:"pptx-local"}),tn=Object.freeze({kind:"pptx-undo-repair"}),nn=Object.freeze({kind:"pptx-redo-repair"}),on=Object.freeze({kind:"pptx-text-repair"}),sn=Object.freeze({kind:"pptx-tidy"}),rt=Object.freeze({kind:"pptx-undone-listing"}),rn=Object.freeze({kind:"pptx-seed"}),it=Object.freeze({maxBinaryBytes:256*1024*1024,maxReadDepth:300,maxCopiesPerGroup:256});function Zn(t){return{doc:t,meta:t.getMap(Er),parts:t.getMap(Ir),binaries:t.getMap(vr),nodes:t.getMap(Pr)}}function Ue(t){if(typeof t!="object"||t===null)return null;let e=t;return e.kind==="binary"?{kind:"binary"}:e.kind==="xml"&&typeof e.root=="string"?{kind:"xml",root:e.root}:null}import{asciiFold as Or}from"@pptx-editor.dev/core/store";var an="http://schemas.openxmlformats.org/drawingml/2006/main",so="http://schemas.openxmlformats.org/presentationml/2006/main",Y=t=>[t,[t]],ne=(t,e)=>[t,e],at=["*",[]],lt=ne("fill",["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),Ar=ne("fill",["noFill","solidFill","gradFill","pattFill"]),It=ne("effect",["effectLst","effectDag"]),Nr=[ne("color",["scrgbClr","srgbClr","hslClr","sysClr","schemeClr","prstClr"])],eo=[Y("xfrm"),ne("geometry",["custGeom","prstGeom"]),lt,Y("ln"),It,Y("scene3d"),Y("sp3d"),Y("extLst")],to=[Ar,ne("dash",["prstDash","custDash"]),ne("join",["round","bevel","miter"]),Y("headEnd"),Y("tailEnd"),Y("extLst")],cn=[Y("ln"),lt,It,Y("highlight"),ne("uLn",["uLnTx","uLn"]),ne("uFill",["uFillTx","uFill"]),Y("latin"),Y("ea"),Y("cs"),Y("sym"),Y("hlinkClick"),Y("hlinkMouseOver"),Y("rtl"),Y("extLst")],ct=t=>[Y("cNvPr"),Y(t),Y("nvPr")],Et=t=>[Y(t),Y("extLst")],ln=["lnL","lnR","lnT","lnB","lnTlToBr","lnBlToTr"],Tr=Object.assign(Object.create(null),{sld:[Y("cSld"),Y("clrMapOvr"),Y("transition"),Y("timing"),Y("extLst")],cSld:[Y("bg"),Y("spTree"),Y("custDataLst"),Y("controls"),Y("extLst")],bg:[ne("background",["bgPr","bgRef"])],bgPr:[lt,It,Y("extLst")],spPr:eo,grpSpPr:eo,ln:to,...Object.fromEntries(ln.map(t=>[t,to])),effectLst:[Y("blur"),Y("fillOverlay"),Y("glow"),Y("innerShdw"),Y("outerShdw"),Y("prstShdw"),Y("reflection"),Y("softEdge")],...Object.fromEntries(["solidFill","outerShdw","innerShdw","prstShdw","glow","highlight","extrusionClr","contourClr","buClr","lnRef","fillRef","effectRef","fontRef"].map(t=>[t,Nr])),scene3d:[Y("camera"),Y("lightRig"),Y("backdrop"),Y("extLst")],camera:[Y("rot")],lightRig:[Y("rot")],sp3d:[Y("bevelT"),Y("bevelB"),Y("extrusionClr"),Y("contourClr"),Y("extLst")],style:[Y("lnRef"),Y("fillRef"),Y("effectRef"),Y("fontRef")],sp:[Y("nvSpPr"),Y("spPr"),Y("style"),Y("txBody"),Y("extLst")],pic:[Y("nvPicPr"),Y("blipFill"),Y("spPr"),Y("style"),Y("extLst")],cxnSp:[Y("nvCxnSpPr"),Y("spPr"),Y("style"),Y("extLst")],grpSp:[Y("nvGrpSpPr"),Y("grpSpPr"),at,Y("extLst")],graphicFrame:[Y("nvGraphicFramePr"),Y("xfrm"),Y("graphic"),Y("extLst")],nvSpPr:ct("cNvSpPr"),nvPicPr:ct("cNvPicPr"),nvCxnSpPr:ct("cNvCxnSpPr"),nvGrpSpPr:ct("cNvGrpSpPr"),nvGraphicFramePr:ct("cNvGraphicFramePr"),cNvPr:[Y("hlinkClick"),Y("hlinkHover"),Y("extLst")],nvPr:[Y("ph"),ne("media",["audioCd","wavAudioFile","audioFile","videoFile","quickTimeFile"]),Y("custDataLst"),Y("extLst")],cNvSpPr:Et("spLocks"),cNvPicPr:Et("picLocks"),cNvGrpSpPr:Et("grpSpLocks"),cNvGraphicFramePr:Et("graphicFrameLocks"),cNvCxnSpPr:[Y("cxnSpLocks"),Y("stCxn"),Y("endCxn"),Y("extLst")],xfrm:[Y("off"),Y("ext"),Y("chOff"),Y("chExt")],blipFill:[Y("blip"),Y("srcRect"),ne("fillMode",["tile","stretch"])],txBody:[Y("bodyPr"),Y("lstStyle"),at],bodyPr:[Y("prstTxWarp"),ne("autofit",["noAutofit","normAutofit","spAutoFit"]),Y("scene3d"),ne("text3d",["sp3d","flatTx"]),Y("extLst")],p:[Y("pPr"),at,Y("endParaRPr")],r:[Y("rPr"),Y("t")],fld:[Y("rPr"),Y("pPr"),Y("t")],br:[Y("rPr")],pPr:[Y("lnSpc"),Y("spcBef"),Y("spcAft"),ne("buClr",["buClrTx","buClr"]),ne("buSz",["buSzTx","buSzPct","buSzPts"]),ne("buFont",["buFontTx","buFont"]),ne("bullet",["buNone","buAutoNum","buChar","buBlip"]),Y("tabLst"),Y("defRPr"),Y("extLst")],rPr:cn,defRPr:cn,endParaRPr:cn,tbl:[Y("tblPr"),Y("tblGrid"),at],tblPr:[lt,It,ne("tableStyle",["tableStyle","tableStyleId"]),Y("extLst")],tc:[Y("txBody"),Y("tcPr"),Y("extLst")],tcPr:[...ln.map(Y),Y("cell3D"),lt,Y("headers"),Y("extLst")]}),fn=t=>t.ns===an||t.ns===so,Cr=new Set(["sld","cSld","bg","bgPr","sp","pic","cxnSp","grpSp","graphicFrame","nvSpPr","nvPicPr","nvCxnSpPr","nvGrpSpPr","nvGraphicFramePr","nvPr","style"]);function ro(t){if(!(!fn(t)||Cr.has(t.local)&&t.ns!==so))return Tr[t.local]}function io(t,e){return fn(e)?t.findIndex(([,o])=>o.includes(e.local)):-1}var Dr=new Set(["pPr","rPr","defRPr","endParaRPr","bodyPr","tblPr","tcPr","ln",...ln]);function co(t){return fn(t)&&Dr.has(t.local)}function Lr(t,e){let o=ro(t),n=o?io(o,e):-1;return n<0?void 0:o[n][0]}var _r=(t,e)=>t.ns===an&&t.local==="tc"&&e.ns===an&&e.local==="txBody",Fr="http://schemas.openxmlformats.org/package/2006/content-types",zr="http://schemas.openxmlformats.org/package/2006/relationships",jr=Object.assign(Object.create(null),{[`${Fr}|Types`]:{Default:{attr:"Extension",caseless:!0},Override:{attr:"PartName",caseless:!0}},[`${zr}|Relationships`]:{Relationship:{attr:"Id",caseless:!1}}});function He(t,e,o){let n=jr[`${t.ns}|${t.local}`];if(n&&Object.prototype.hasOwnProperty.call(n,e.local)){let{attr:i,caseless:r}=n[e.local],c=o(i);return c===void 0?void 0:{slot:`${e.local}:${r?Or(c):c}`,rule:"key"}}let s=Lr(t,e);if(!(s===void 0||_r(t,e)))return{slot:s,rule:co(e)?"merge":"first"}}function Ve(t,e,o){let n=ro(t);if(!n)return e;let s=n.indexOf(at),i=-1,r=!0,c=e.map((l,f)=>{let u=o(l),a=u?io(n,u):-1,g=a>=0?a:s>=0?s:i;return g<i&&(r=!1),i=g,{c:l,rank:g,i:f}});return r?e:c.sort((l,f)=>l.rank-f.rank||l.i-f.i).map(l=>l.c)}var no=t=>`${t.ns}${Rt}${t.local}`,me=t=>t.slice(0,Math.max(0,t.indexOf("."))),vt="_",oo=t=>t.slice(t.indexOf(".")+1).startsWith(vt);function ao(t,e){let o=t.get(e);return o||(o={merge:!1,companions:[],attrFrom:new Map,childFrom:new Map,shadowed:new Map},t.set(e,o)),o}var dn=(t,e)=>t.attrs?.find(o=>o.ns===""&&o.local===e)?.value;function Wr(t,e,o){let n=ao(o,t.key);n.merge=!0;let s=new Map;for(let p of t.attrs??[])s.set(no(p),p);let i=p=>"text"in p?void 0:He(t,p,h=>dn(p,h))?.slot,r=t.children??[],c=new Set(r.map(i)),l=[...r],f=new Map;for(let p of e){n.companions.push(p.key);for(let h of p.attrs??[]){let d=no(h);s.has(d)||(s.set(d,h),n.attrFrom.set(d,p.key))}for(let h of p.children??[]){if("text"in h)continue;let d=i(h);if(d===void 0){l.push(h),f.set(h.key,p.key);continue}if(c.has(d)&&!co(h)){n.shadowed.set(h.key,d);continue}c.add(d),l.push(h),f.set(h.key,p.key)}}let u=un(t,l,o);if(!u)return null;for(let p of u){let h="text"in p?void 0:f.get(p.key);h!==void 0&&n.childFrom.set(p.key,h)}let a=Ve(t,u,p=>"text"in p?void 0:p),g=[...s.entries()].sort(([p],[h])=>p<h?-1:p>h?1:0);return{...t,attrs:g.map(([,p])=>p),children:[...a]}}function un(t,e,o){let n=new Map,s=[],i=new Map;for(let r of e){let c="text"in r?void 0:He(t,r,g=>dn(r,g)),l=c?n.get(c.slot):void 0,f=l===void 0?void 0:s[l],u=f!==void 0&&!(oo(f.key)&&oo(r.key));if(c&&l===void 0&&n.set(c.slot,s.length),!u){s.push(r);continue}let a=i.get(l);if(a||i.set(l,a=[]),a.length>=it.maxCopiesPerGroup)return null;a.push(r)}for(let[r,c]of i){let l=s[r];if(He(t,l,f=>dn(l,f))?.rule==="merge"){let f=Wr(l,c,o);if(!f)return null;s[r]=f}else{let f=ao(o,l.key);for(let u of c)f.companions.push(u.key)}}return s}import*as de from"yjs";var K=Object.freeze({splitFrom:"sf",splitBaseText:"sb",splitAt:"sa",splitLength:"sl",splitGeneration:"sg",splitEdited:"se",splitBreak:"sk",movedFrom:"mf",movedIndex:"mi",movedClock:"mq",movedTo:"mt",movedEarlier:"mo",removedWith:"rw"}),De="pptx-pieces-v1",pt="pptx-moves-v1",Pt="pptx-splits-v1",Le=2e4,Ot=64,go=`${K.removedWith}.`,yn=2**31,kn=300,wn=8,qe=4096,_e=t=>Number.isSafeInteger(t)&&t>=0,Kr=t=>Number.isSafeInteger(t)&&t>=1&&t<yn,ho="http://schemas.openxmlformats.org/drawingml/2006/main",ut=new Set,xe=t=>t?.type==="element",gt=t=>t===K.removedWith||t.startsWith(go);function Ee(t){for(let e of t.keys())if(gt(e))return!0;return!1}function lo(t,e,o){t.set(`${go}${e}`,o)}var gn=t=>t.children.filter(xe);function dt(t){let o=gn(t).find(n=>n.local==="t")?.children.find(n=>n.type==="text");return o?.type==="text"?o.value:""}function mo(t){if(!t||"text"in t)return"";let e=t.children?.find(n=>!("text"in n)&&n.local==="t"),o=e&&!("text"in e)?e.children?.find(n=>"text"in n):void 0;return o&&"text"in o?o.text:""}function yo(t){let e=2166136261;for(let o=0;o<t.length;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619)>>>0;return e.toString(36)}function hn(t,e,o,n){let s=`${t}\0${yo(e)}\0${o}`;return n===void 0?s:`${s}\0${n}`}var fo=t=>{let e=Number.parseInt(t,36);return Number.isFinite(e)?e:Number.MAX_SAFE_INTEGER};function ko(t,e,o,n,s){if(n.size===0)return;let i=y=>{let w=s.get(y),x=w===void 0?void 0:t.nodes.get(w);return x instanceof de.Map?x:void 0},r=t.doc.clientID.toString(36),c=new Map,l=[],f=new Set,u=new Set,a=y=>{for(let w of gn(y)){if(w.local!=="r"||u.has(w.id))continue;let x=n.get(w.id);if(!xe(x)||x===w||dt(x)===dt(w))continue;let k=i(w.id);k&&typeof k.get(K.splitFrom)=="string"&&k.get(K.splitEdited)!==!0&&k.set(K.splitEdited,!0)}},g=y=>{let w=gn(y);w.forEach((x,k)=>{if(x.local!=="r"||!n.has(x.id))return;let b=n.get(x.id);if(!xe(b)||b===x)return;let v=dt(b),M=dt(x);if(v.length<=M.length||!v.startsWith(M))return;let C=v.slice(M.length),T=[],R="",j=[];for(let I=k+1;I<w.length&&R.length<C.length;I+=1){let _=w[I];if(_.local==="br"&&!n.has(_.id)){j.push({el:_,at:M.length+R.length});continue}if(_.local!=="r"||n.has(_.id))break;let N=dt(_);T.push({el:_,at:M.length+R.length,length:N.length}),R+=N}let F=s.get(x.id);if(R!==C||F===void 0||T.length===0)return;u.add(x.id);let P=`${F}\0${yo(v)}`,D=Math.min((wo(t).latest.get(P)??0)+1,yn-1);for(let{el:I,at:_,length:N}of T){let z=i(I.id);if(!z||z.has(K.splitFrom))continue;z.set(K.splitFrom,F),z.set(K.splitBaseText,v),z.set(K.splitAt,_),z.set(K.splitLength,N),z.set(K.splitGeneration,D);let W=s.get(I.id);W!==void 0&&t.doc.getMap(De).set(W,e)}for(let{el:I,at:_}of j){let N=i(I.id);!N||N.has(K.splitBreak)||(N.set(K.splitBreak,hn(F,v,D)),N.set(K.splitAt,_))}t.doc.getMap(Pt).set(hn(F,v,D,r),M.length)})},p=(y,w)=>{let x=n.get(y.id);if(x===y)return;let k=s.get(y.id),b=k===void 0?w:[k,...w].slice(0,kn),v=xe(x)?new Set(x.children.map(M=>M.id)):new Set;for(let M of y.children)f.add(M.id),!v.has(M.id)&&n.has(M.id)&&l.push({node:M,path:b});if(xe(x)){let M=new Set(y.children.map(C=>C.id));for(let C of x.children)M.has(C.id)||c.set(C.id,C)}y.ns===ho&&y.local==="p"&&xe(x)&&(g(y),a(y));for(let M of y.children)xe(M)&&p(M,b)};if(p(o,[]),l.length>0){let y=new Map;for(let k of n.values())xe(k)&&k.children.forEach((b,v)=>y.set(b.id,{parent:k.id,index:v}));let w=t.doc.getMap(pt),x=de.getState(t.doc.store,t.doc.clientID);for(let{node:k,path:b}of l){let v=y.get(k.id),M=v===void 0?void 0:s.get(v.parent),C=s.get(k.id),T=i(k.id);if(!T||!v||M===void 0||C===void 0)continue;let R=T.get(K.movedFrom);if(typeof R=="string"&&R!==M){let j=T.get(K.movedEarlier),F=Array.isArray(j)?j.filter(P=>typeof P=="string"&&P!==R):[];T.set(K.movedEarlier,[R,...F].slice(0,wn))}T.set(K.movedFrom,M),T.set(K.movedIndex,v.index),T.set(K.movedClock,x),T.set(K.movedTo,b),w.set(C,e)}}let h=t.doc.getMap(De),d,m,S=y=>(d??=uo(o,s)).has(y);for(let[y,w]of c){if(f.has(y))continue;let x=new Set,k=[w];for(;k.length>0&&x.size<=Le;){let C=k.pop(),T=s.get(C.id);if(T!==void 0&&x.add(T),xe(C))for(let R of C.children)f.has(R.id)||k.push(R)}let b=s.get(y);b!==void 0&&Gr(t,b,x,S);let v=i(y);if(!v||x.size>Le)continue;let M=[...x];lo(v,r,M);for(let C of x){if(C===b||!h.has(C)||(d??=uo(o,s)).has(C))continue;let T=t.nodes.get(C);!(T instanceof de.Map)||Ee(T)||(m??=new Set([...n.keys()].flatMap(R=>s.get(R)??[])),!(!m.has(C)&&$r(t,e,T,d))&&lo(T,r,[C]))}}}function uo(t,e){let o=new Set,n=[t];for(;n.length>0;){let s=n.pop(),i=e.get(s.id);if(i!==void 0&&o.add(i),xe(s))for(let r of s.children)n.push(r)}return o}function $r(t,e,o,n){let s=Fe(o),i=s?Je(t)(s.group):void 0;if(!s||i===void 0)return!1;let r=0;for(let[c,l]of t.doc.getMap(De).entries())if(!(l!==e||me(c)!==i||!n.has(c))&&((r+=1)>qe||Fe(t.nodes.get(c))?.group===s.group))return!0;return!1}function Gr(t,e,o,n){let s=[e],i=new Set;for(;s.length>0&&o.size<=Le;){let r=s.pop();if(i.has(r))continue;i.add(r),o.add(r);let c=t.nodes.get(r),l=c instanceof de.Map?c.get(A.children):void 0;if(l instanceof de.Array)for(let f of l.toArray())typeof f=="string"&&!i.has(f)&&!n(f)&&s.push(f)}}var pn=new WeakMap,po=new WeakSet;function wo(t){let e=t.doc.getMap(Pt),o=pn.get(e);if(o)return o;let n={groups:new Map,latest:new Map};for(let[s,i]of e.entries()){let r=s.split("\0");if(!_e(i)||r.length!==4)continue;let[c,l,f,u]=r,a=Number(f);if(!Number.isSafeInteger(a)||a<1||a>=yn)continue;let g=`${c}\0${l}`,p=`${g}\0${a}`,h=n.groups.get(p);h||n.groups.set(p,h=new Map),h.set(u,i),n.latest.set(g,Math.max(n.latest.get(g)??0,a))}return pn.set(e,n),po.has(e)||(po.add(e),e.observe(()=>pn.delete(e))),n}function Fe(t){if(!(t instanceof de.Map))return null;let e=t.get(K.splitFrom),o=t.get(K.splitBaseText),n=t.get(K.splitAt),s=t.get(K.splitLength),i=t.get(K.splitGeneration);return typeof e!="string"||typeof o!="string"||!_e(n)||!_e(s)||!Kr(i)?null:{from:e,group:hn(e,o,i),original:o.slice(n,n+s),at:n,edited:t.get(K.splitEdited)===!0}}function Je(t){let{groups:e}=wo(t),o=new Map;return n=>{if(o.has(n))return o.get(n);let s=e.get(n),i;if(s&&s.size>=2){let r;for(let[c,l]of s)(!r||l<r[1]||l===r[1]&&fo(c)<fo(r[0]))&&(r=[c,l]);i=r?.[0]}return o.set(n,i),i}}function So(t,e,o){let n=new Map,s=new Set,i=r=>{let c=n.get(r);if(c!==void 0||n.has(r))return c??null;let l=e(r);if(!l||l.edited||s.has(r)||s.size>qe)return null;s.add(r);let f=o(r);for(let u of t.get(r)??[]){let a=i(u);if(a===null){f=null;break}f+=a}return s.delete(r),n.set(r,f),f};return i}function mn(t){let e=new Map;for(let[n,s]of t){let i=e.get(s.from);i?i.push([n,s.at]):e.set(s.from,[[n,s.at]])}let o=new Map;for(let[n,s]of e)o.set(n,s.sort((i,r)=>i[1]-r[1]||(i[0]<r[0]?-1:i[0]>r[0]?1:0)).map(([i])=>i));return o}function xo(t,e){let o=0;for(let n=0;n<e.length&&o<t.length;n+=1)e[n]===t[o]&&(o+=1);return o===t.length}function Mo(t,e,o,n,s=ut){if(e.ns!==ho||e.local!=="p")return o;let i=new Map,r=new Map;for(let p of o){if("text"in p)continue;let h=Fe(t.nodes.get(p.key));if(h){if(i.size>=qe)return o;i.set(p.key,h),r.set(p.key,mo(p))}}if(i.size===0)return o;let c=mn(i),l=So(c,p=>i.get(p),p=>r.get(p)??""),f=Je(t),u=new Set;for(let[p,h]of i){let d=f(h.group);if(d===void 0||me(p)===d||s.has(h.group))continue;let m=l(p);m!==null&&xo(m,h.original)&&u.add(p)}if(u.size===0)return o;let a=[...u];for(;a.length>0;)for(let p of c.get(a.pop())??[])u.has(p)||(u.add(p),a.push(p));for(let p of u)n.add(p);let g=o.filter(p=>"text"in p||!u.has(p.key));return Xr(t,g,u,i,f)}function Xr(t,e,o,n,s){let i=new Set;for(let f of o){let u=n.get(f);u&&i.add(`${u.group}\0${me(f)}`)}let r=new Map;for(let f of e){if("text"in f||f.local!=="br")continue;let u=t.nodes.get(f.key);if(!(u instanceof de.Map))continue;let a=u.get(K.splitBreak),g=u.get(K.splitAt);if(typeof a!="string"||!_e(g)||!i.has(`${a}\0${me(f.key)}`))continue;let p;for(let h of e){let d="text"in h?void 0:n.get(h.key);!d||d.group!==a||me(h.key)!==s(a)||d.at<g||(!p||d.at<p[1])&&(p=[h.key,d.at])}p&&r.set(f.key,p[0])}if(r.size===0)return e;let c=new Map;for(let f of e){let u=r.get(f.key);if(u===void 0)continue;let a=c.get(u);a?a.push(f):c.set(u,[f])}let l=[];for(let f of e)if(!r.has(f.key)){for(let u of c.get(f.key)??[])l.push(u);l.push(f)}return l}function bo(t,e,o){if(!o||o.size===0)return e;let n=new Set(e),s=[...e],i=-1;for(let r of t){let c=s.indexOf(r);if(c>=0&&n.has(r)){i=c;continue}!o.has(r)||n.has(r)||(s.splice(i+1,0,r),i+=1)}return s}function Ro(t,e,o,n,s=ut){let i=t.doc.getMap(De);if(i.size===0)return o;let r=new Map,c=P=>{(P.children??[]).forEach((D,I)=>{r.set(D.key,{parent:P,at:I,order:r.size}),"text"in D||c(D)})};c(o);let l=new Map;for(let[P,D]of i.entries()){if(D!==e)continue;let I=t.nodes.get(P);if(!(I instanceof de.Map)||Ee(I))continue;let _=Fe(I);_&&(l.size>=qe&&(r.has(P)||l.size>=2*qe)||l.set(P,_))}let f=Je(t),u=new Map,a=P=>{let D=u.get(P);if(D===void 0){let I=r.get(P);D=mo(I?I.parent.children[I.at]:n(P,new Set,1)??void 0),u.set(P,D)}return D},g=So(mn(l),P=>l.get(P),a),p=new Map;for(let[P,D]of l){if(me(P)!==f(D.group))continue;let I=r.get(P)?.order;if(I===void 0)continue;let _=p.get(D.group);(!_||I>_.order)&&p.set(D.group,{key:P,order:I})}let h=new Map,d=P=>{let D=l.get(P).from;D!==P&&h.set(P,D)},m=[];for(let P of[...l.keys()].sort()){let D=l.get(P),I=f(D.group);if(I===void 0||me(P)===I){s.has(P)&&!r.has(P)&&m.push(P);continue}let _=g(P);if(_!==null&&xo(_,D.original))continue;let N=p.get(D.group)?.key??(r.has(D.from)?D.from:void 0);N!==void 0&&N!==P&&h.set(P,N)}let S=new Set(m);for(let P of m){let D=l.get(P).from;(r.has(D)||S.has(D))&&d(P)}let y=mn(l),w=[...h.keys()];for(;w.length>0;)for(let P of y.get(w.pop())??[])!h.has(P)&&r.has(P)&&(d(P),w.push(P));if(h.size===0)return o;let x=new Map,k=new Set(r.keys());for(let P of h.keys()){let D=r.get(P),I=D?D.parent.children[D.at]:n(P,k,1);I&&x.set(P,I)}let b=new Map,v=P=>{let D=b.get(P);if(D!==void 0)return D;let I=h.get(P);b.set(P,!1);let _=I===void 0?r.has(P):x.has(P)&&v(I);return b.set(P,_),_},M=new Map,C=new Set;for(let[P,D]of h){let I=x.get(P);if(!I||!v(P))continue;C.add(P);let _=M.get(D);_?_.push(I):M.set(D,[I])}if(C.size===0)return o;let T=(P,D)=>{let I=l.get(D);return I?.from===P?I.at:1/0};for(let[P,D]of M)D.sort((I,_)=>T(P,I.key)-T(P,_.key)||(I.key<_.key?-1:I.key>_.key?1:0));let R=new Set,j=(P,D)=>{for(let I of M.get(P)??[])R.has(I.key)||(R.add(I.key),D.push(I),j(I.key,D))},F=P=>{let D=[];for(let I of P.children??[])C.has(I.key)||(D.push("text"in I?I:F(I)),j(I.key,D));return{...P,children:D}};return F(o)}var ft=Object.freeze({unseenWinners:ut,lost:ut});function ht(t,e,o,n=ut){let s=t.doc.getMap(De);if(s.size===0)return ft;let i=Je(t),r=new Set,c=new Map,l=0;for(let[m,S]of s.entries()){if(S!==e)continue;let y=t.nodes.get(m);if(!(y instanceof de.Map)||y.get(A.part)!==e)continue;let w=Fe(y);if(w){if(Ee(y)){me(m)===i(w.group)&&r.add(w.group);continue}if((l+=1)>qe)return ft;c.set(m,w)}}if(c.size===0)return ft;let f=new Set,u=[o];for(;u.length>0;){let m=u.pop();if(f.has(m))continue;f.add(m);let S=t.nodes.get(m);if(!(S instanceof de.Map)||S.get(A.part)!==e)continue;let y=S.get(A.children);if(y instanceof de.Array)for(let w of y.toArray())typeof w=="string"&&!f.has(w)&&u.push(w)}let a=new Set,g=new Map;for(let[m,S]of c){let y=me(m)===i(S.group);if(f.has(m)||n.has(m)){y&&r.add(S.group);continue}if(a.add(m),!y)continue;let w=g.get(S.group);w?w.push(m):g.set(S.group,[m])}let p=new Map,h=m=>{let S=p.get(m);if(S!==void 0)return S;p.set(m,!1);let y=c.get(m)?.from,w=y!==void 0&&(f.has(y)||n.has(y)||a.has(y)&&h(y));return p.set(m,w),w},d=new Set;for(let[m,S]of g)!r.has(m)&&!S.some(h)&&d.add(m);return{unseenWinners:d,lost:a}}import*as At from"yjs";var Br=1024;function Ur(t){if(!(t instanceof At.Map))return null;let e=null,o=0;for(let[n,s]of t.entries())if(!(!gt(n)||!Array.isArray(s))){if(s.length>Le+1||(o+=1)>Ot)return"all";e??=new Set;for(let i of s)typeof i=="string"&&e.add(i)}return e}function Hr(t,e,o,n,s){if(o.length>kn)return null;for(let i of o){if(typeof i!="string"||n.has(i))return null;let r=s.get(i);if(r===void 0&&(r=Ur(t.nodes.get(i)),s.set(i,r)),r==="all")return null;if(r)return r.has(e)?null:i}return null}var Sn=(t,e)=>t<e?-1:t>e?1:0,xn=class extends Set{#e;constructor(e){super(),this.#e=e}has(e){return this.#e.has(e)||super.has(e)}};function Eo(t,e,o,n,s,i){let r=t.doc.getMap(pt);if(r.size===0)return o;let c=new Map,l=new Map,f=new Map,u=(M,C,T)=>{if(c.set(M.key,C),f.set(M.key,f.size),T!==null&&l.set(M.key,T),!("text"in M))for(let R of M.children??[])u(R,C+1,M.key)};u(o,0,null);let a=[],g=[],p=new Map,h,d=M=>{if(!h){h=new Map;for(let C of r.keys()){if(!l.has(C))continue;let T=t.nodes.get(C),R=T instanceof At.Map?T.get(K.movedFrom):void 0;if(typeof R!="string")continue;let j=h.get(R);(j===void 0||f.get(C)>f.get(j))&&h.set(R,C)}}return h.get(M)};for(let[M,C]of r.entries()){if(C!==e||c.has(M))continue;let T=t.nodes.get(M);if(!(T instanceof At.Map)||T.get(A.part)!==e||Ee(T))continue;let R=T.get(K.movedFrom),j=T.get(K.movedTo);if(typeof R!="string"||!Array.isArray(j))continue;let F=T.get(K.movedEarlier),P=c.has(R)?R:(Array.isArray(F)?F.slice(0,wn):[]).find(z=>typeof z=="string"&&c.has(z)),D=T.get(K.movedIndex),I=T.get(K.movedClock),_=typeof I=="number"&&Number.isFinite(I)?I:0,N=Hr(t,M,j,c,p);if(N!==null){if(a.length+g.length>=Br)return o;if(P!==void 0){let z=P===R&&_e(D)?D:1/0;a.push({key:M,from:P,index:z,clock:_,to:j})}else g.push({key:M,last:R,removed:N,index:_e(D)?D:1/0,clock:_,to:j})}}let m=new Map,S=g,y=0;for(;S.length>0;){let M=[],C=[];for(let T of S){let R=m.get(T.removed),j=R?void 0:d(T.removed),F=R?R.into:j===void 0?void 0:l.get(j),P=R?R.key:j;P===void 0||F===void 0?C.push(T):M.push({...T,after:P,into:F})}if(M.length===0){for(let T of C)i?.add(T.removed);break}M.sort((T,R)=>T.clock-R.clock||T.index-R.index||Sn(T.key,R.key));for(let T of M)a.push({...T,from:T.into,seq:y++}),m.set(T.last,{key:T.key,into:T.into});S=C}if(a.length===0)return o;let w=new Set(a.map(M=>M.key)),x=new Map(a.map(M=>[M.key,M.to.filter(C=>typeof C=="string"&&w.has(C)).length]));a.sort((M,C)=>x.get(M.key)-x.get(C.key)||Sn(M.key,C.key));let k=new xn(new Set(c.keys())),b=new Map;for(let M of a){let C=n(M.key,k,c.get(M.from)+1);if(!C)continue;s?.add(C.key);let T={node:C,index:M.index,clock:M.clock,after:M.after,seq:M.seq??0},R=b.get(M.from);R?R.push(T):b.set(M.from,[T])}if(b.size===0)return o;let v=M=>{let C=b.get(M.key),T=(M.children??[]).map(I=>"text"in I?I:v(I));if(!C)return{...M,children:T};let R=[...T],j=C.filter(I=>I.after===void 0).sort((I,_)=>_.clock-I.clock||I.index-_.index||Sn(I.node.key,_.node.key));for(let{node:I,index:_}of j)R.splice(Math.min(_,R.length),0,I);let F=C.filter(I=>I.after!==void 0).sort((I,_)=>I.seq-_.seq),P=new Map;for(let{node:I,after:_}of F){let N=P.get(_)??_,z=R.findIndex(W=>W.key===N);R.splice(z<0?R.length:z+1,0,I),P.set(_,I.key)}let D={ns:M.ns,local:M.local};return{...M,children:[...Ve(D,R,I=>"text"in I?void 0:I)]}};return v(o)}function Nt(t){let e=new Set,o=[t];for(;o.length>0;){let n=o.pop();if(e.add(n.key),!("text"in n))for(let s of n.children??[])o.push(s)}return e}var Yo=(t,e)=>t.size===e.size&&[...t].every(o=>e.has(o));function Io(t,e){return Yo(t.lost,e.lost)&&Yo(t.unseenWinners,e.unseenWinners)}import*as yt from"yjs";import{children as Mn,elements as Qe,isStructureEdited as Vr,path as vo,TABLE_MAX_COLUMNS as qr,TABLE_MAX_ROWS as Jr,tableGridOf as Qr}from"@pptx-editor.dev/core/store";var Tt=Object.freeze({holder:"mh",cover:"cv."}),Rn="http://schemas.openxmlformats.org/drawingml/2006/main",Zr="http://schemas.openxmlformats.org/presentationml/2006/main",Dt=256,Po=4096,mt=t=>t?.type==="element",Ct=(t,e)=>!!t&&!("text"in t)&&t.ns===Rn&&t.local===e;function ei(t){return(Qe(t).find(o=>o.local==="t")?.children??[]).map(o=>o.type==="text"?o.value:"").join("")}function ti(t){return Qe(t).some(e=>e.local==="br"||(e.local==="r"||e.local==="fld")&&ei(e).length>0)}function Oo(t){return"text"in t?!1:(t.children??[]).some(e=>{if("text"in e||!(e.local==="br"||e.local==="r"||e.local==="fld"))return!1;if(e.local==="br")return!0;let o=e.children?.find(n=>!("text"in n)&&n.local==="t");return!!o&&!("text"in o)&&(o.children??[]).some(n=>"text"in n&&n.text!=="")})}function Ao(t,e){let o=[],n=(s,i)=>{if(s.ns===Zr&&s.local==="graphicFrame"){o.push(s);return}if(i<Dt)for(let r of e(s))n(r,i+1)};return n(t,0),o}function No(t){let e=vo(t,"a:graphic","a:graphicData","a:tbl"),o=Math.min(Mn(vo(e,"a:tblGrid"),"a:gridCol").length,qr),n=Mn(e,"a:tr").slice(0,Jr).map(r=>Mn(r,"a:tc"));if(o===0||n.length===0)return[];let s=Qr(t,n,o),i=[];return n.forEach((r,c)=>r.slice(0,o).forEach((l,f)=>{let u=s.blocks[s.owner[c*o+f]],a=u&&n[u.row][u.col];a&&(u.row!==c||u.col!==f)&&i.push({tc:l,over:a})})),i}var bn=t=>Qe(t).filter(e=>e.ns===Rn&&e.local==="txBody");function To(t){let e=new Set;if(!(t instanceof yt.Map))return e;for(let[o,n]of t.entries())if(!(!o.startsWith(Tt.cover)||!Array.isArray(n))){if(n.length>Po)return"all";for(let s of n)typeof s=="string"&&e.add(s)}return e}function Co(t,e,o,n){if(o.size===0)return;let s=u=>{let a=n.get(u),g=a===void 0?void 0:t.nodes.get(a);return g instanceof yt.Map?g:void 0},i=new Set,r=[],c=(u,a)=>{let g=o.get(u.id);if(g!==u){for(let p of u.children)i.add(p.id);if(u.ns===Rn&&u.local==="txBody"&&mt(g)){let p=new Set(u.children.map(d=>d.id)),h=g.children.filter(d=>mt(d)&&d.local==="p");h.length>0&&h.every(d=>!p.has(d.id))&&r.push({body:u,old:g})}if(a<Dt)for(let p of u.children)mt(p)&&c(p,a+1)}};c(e,0);for(let{body:u,old:a}of r)if(a.children.filter(p=>mt(p)&&p.local==="p").every(p=>i.has(p.id)))for(let p of u.children)mt(p)&&p.local==="p"&&!o.has(p.id)&&!ti(p)&&s(p.id)?.set(Tt.holder,!0);let l=`${Tt.cover}${t.doc.clientID.toString(36)}`,f=u=>Qe(u).filter(a=>o.get(a.id)!==a);for(let u of Ao(e,f))for(let{tc:a}of No(u)){let g=s(a.id),p=bn(a);if(!g||p.length===0)continue;let h=To(g);if(h==="all")continue;let d=p.flatMap(y=>Qe(y).filter(w=>w.local==="p")).map(y=>n.get(y.id)).filter(y=>y!==void 0&&!h.has(y));if(d.length===0)continue;let m=g.get(l),S=Array.isArray(m)?m.filter(y=>typeof y=="string"):[];g.set(l,[...S,...d].slice(0,Po+1))}}function Do(t,e){let o=new Map(t);return o.delete(e),o}function Lo(t,e,o){let n=[];if(!e||e.size===0)return n;let s=(i,r)=>{let c=o.get(i.id);if(c!==void 0&&e.has(c)&&n.push(i),r<Dt)for(let l of Qe(i))s(l,r+1)};return s(t,0),n}function _o(t,e){e.set(t.key,t);let o=(t.children??[]).map(n=>"text"in n?{type:"text",id:n.key,value:n.text}:_o(n,e));return{type:"element",id:t.key,kind:"generic",ns:t.ns,local:t.local,...t.prefix?{prefix:t.prefix}:{},nsDecls:[],attrs:t.attrs??[],children:o}}function ni(t,e,o,n,s){let i=new Map,r=_o(o,i),c=Vr(r);for(let{tc:l,over:f}of No(r)){let u=bn(f)[0],a=u&&i.get(u.id);if(!a)continue;let g=To(t.nodes.get(l.id)),p=S=>{if(g==="all"||g.has(S))return!1;let y=t.nodes.get(S);return y instanceof yt.Map?c?!0:typeof y.get(K.movedFrom)=="string"||Ee(y):!1},h=bn(l).flatMap(S=>{let y=i.get(S.id);if(!y)return[];let w=y.children??[],x=w.filter(k=>Ct(k,"p")&&(e.has(k.key)||Oo(k)&&p(k.key)));return[{from:y,kids:w,going:x,paragraphs:w.filter(k=>Ct(k,"p")).length}]});h.every(S=>S.going.length===S.paragraphs)&&[...h].reverse().find(S=>S.going.length>0)?.going.pop();let d=new Set(h.filter(S=>S.going.length===S.paragraphs).map(S=>S.from)),m=i.get(l.id);m&&d.size>0&&d.size<h.length&&s.set(m.key,(m.children??[]).filter(S=>!d.has(S)));for(let{from:S,kids:y,going:w}of h){if(w.length===0)continue;let x=new Set(w);s.set(S.key,y.filter(b=>!x.has(b)));let k=n.get(a.key);if(k)for(let b of w)k.push(b);else n.set(a.key,w)}}}function Fo(t,e,o,n){let s=new Map,i=new Map,r=Ao(e,f=>(f.children??[]).filter(u=>!("text"in u)));for(let f of r)ni(t,o,f,s,i);if(s.size===0&&o.size===0)return e;let c=f=>{if(!Ct(f,"p")||Oo(f))return!1;let u=t.nodes.get(f.key);return u instanceof yt.Map&&u.get(Tt.holder)===!0},l=(f,u)=>{let a=i.get(f.key)??f.children??[],g=s.get(f.key);g&&(a=[...a,...g]),f.local==="txBody"&&a.some(d=>Ct(d,"p")&&o.has(d.key))&&(a=a.filter(d=>!c(d)));let p=u<Dt?a.map(d=>"text"in d?d:l(d,u+1)):a,h=p.length===(f.children??[]).length&&p.every((d,m)=>d===f.children[m]);return!h&&f.local==="txBody"&&n?.add(f.key),h?f:{...f,children:p}};return l(e,0)}import*as J from"yjs";var oe=Object.freeze({copyOf:"ci",newParagraph:"cp",seen:"cs",followed:"cf.",removedRun:"rr."}),je="pptx-copies-v1",zo=1<<20,Go=4096,oi=1024,Yn=32,Xo="http://schemas.openxmlformats.org/drawingml/2006/main",si="http://schemas.openxmlformats.org/presentationml/2006/main",En=t=>t.local==="txBody"&&(t.ns===Xo||t.ns===si),U=(t,e)=>`${t}:${e}`,Pe=t=>Number.isSafeInteger(t)&&t>=0,jo=new WeakMap;function Oe(t){if(!(t instanceof J.Map))return null;let e=t.get(oe.copyOf),o=jo.get(t);if(o&&o.value===e)return o.copy;let n=Bo(e,t.get(oe.newParagraph)===!0);return jo.set(t,{value:e,copy:n}),n}function Bo(t,e){if(!Array.isArray(t)||t.length<5||(t.length-2)%3!==0||t.length>2+3*zo)return null;let[o,n]=t;if(!Pe(o)||!Pe(n))return null;let s=[],i=0;for(let c=2;c<t.length;c+=3){let l=t[c],f=t[c+1],u=t[c+2];if(!Pe(l)||!Pe(f)||!Pe(u)||u===0||(s.push(i),i+=u,i>zo))return null}let r=t;return{client:o,clock:n,length:i,newParagraph:e,source(c){let l=0,f=s.length-1;for(;l<f;){let a=l+f+1>>1;s[a]<=c?l=a:f=a-1}let u=2+3*l;return J.createID(r[u],r[u+1]+(c-s[l]))}}}var Wo=new WeakMap;function Ft(t){let e=[];if(!(t instanceof J.Map))return e;let o=[];for(let n of t.keys())n.startsWith(oe.followed)&&o.push(n);for(let n of o.sort().slice(0,oi)){let s=t.get(n);if(!Array.isArray(s))continue;let i=Wo.get(s);i===void 0&&Wo.set(s,i=Bo(s,!1)),i&&e.push(i)}return e}function ri(t,e){let o=s=>s!==null&&s.client===e.client&&e.clock>=s.clock&&e.clock<s.clock+s.length,n=Oe(t);return o(n)?n:Ft(t).find(o)??null}function Uo(t,e,o,n){t.set(`${oe.followed}${U(e,o)}`,[e,o,...Vo(n)])}function Ho(t,e){let o=new Set,n=t.nodes;for(let[s,i]of e.changed){if(s===n){for(let c of i)c!==null&&Ft(n.get(c)).length>0&&o.add(c);continue}if(!(s instanceof J.Map)||s.parent!==n)continue;let r=s.get(A.key);if(typeof r=="string")for(let c of i)c?.startsWith(oe.followed)&&o.add(r)}return o}var Ae="pptx-restored-v1",We=65536,ii=/^(\d{1,16}):(\d{1,16})$/,Lt=new WeakMap,Ko=new WeakSet;function ci(t){let e=Lt.get(t);if(e)return e;Ko.has(t)||(Ko.add(t),t.observe(()=>Lt.delete(t))),e=new Map;for(let[o,n]of t.entries()){let s=ii.exec(o);if(!s||!Array.isArray(n)||n.length!==3||!n.every(Pe))continue;let[i,r,c]=n;if(c===0||c>We)continue;let l=Number(s[1]),f=Number(s[2]);if(!Number.isSafeInteger(l)||!Number.isSafeInteger(f))continue;let u=e.get(l),a=[f,i,r,c];u?u.push(a):e.set(l,[a])}for(let o of e.values())o.sort((n,s)=>n[0]-s[0]);return Lt.set(t,e),e}function Ze(t,e){let o=t.getMap(Ae);if(o.size===0)return null;let n=ci(o).get(e.client);if(!n)return null;let s=0,i=n.length-1;for(;s<i;){let c=s+i+1>>1;n[c][0]<=e.clock?s=c:i=c-1}let r=n[s];return!r||e.clock<r[0]||e.clock>=r[0]+r[3]?null:J.createID(r[1],r[2]+(e.clock-r[0]))}function wt(t,e){if(e.length===0)return;let o=t.getMap(Ae);for(let n=0;n+3<e.length;n+=4)o.set(U(t.clientID,e[n]),[e[n+1],e[n+2],e[n+3]]);Lt.delete(o)}function Vo(t){let e=[];for(let o of t){let n=e.length;n>0&&e[n-3]===o.client&&e[n-2]+e[n-1]===o.clock?e[n-1]+=1:e.push(o.client,o.clock,1)}return e}function ai(t,e){let o=new Set;for(let s=e._start;s!==null;s=s.right)if(o.add(s.id.client),o.size>Go)return null;let n=[];for(let s of[...o].sort((i,r)=>i-r))n.push(s,J.getState(t.store,s));return n}var $o=new WeakMap;function qo(t){if(!(t instanceof J.Map))return null;let e=t.get(oe.seen),o=$o.get(t);(!o||o.value!==e)&&(o={value:e,seen:li(e)},$o.set(t,o));let n=o.seen;return n?s=>s.clock<(n.get(s.client)??0):null}function li(t){if(!Array.isArray(t)||t.length%2!==0||t.length>2*Go)return null;let e=new Map;for(let o=0;o<t.length;o+=2){let n=t[o],s=t[o+1];if(!Pe(n)||!Pe(s)||e.has(n))return null;e.set(n,s)}return e}function zt(t,e,o){let n=[],s=0;for(let i=t._start;i!==null&&n.length<o;i=i.right)if(!(i.deleted||!i.countable))for(let r=0;r<i.length&&n.length<o;r+=1,s+=1)s>=e&&n.push(J.createID(i.id.client,i.id.clock+r));return n}function ye(t,e){if(J.getState(t.store,e.client)<=e.clock)return null;let o=J.getItem(t.store,e);return o instanceof J.Item?o:null}function jt(t){let e=t.parent,o=e instanceof J.Text?e.parent:null;return o instanceof J.Map?o:null}function Wt(t,e){let o=ye(t,e);return!o||o.deleted}function ue(t,e,o,n=!0){let s=U(e.client,e.clock),i=o?.get(s);if(i)return i;let r=e;for(let c=0;c<Yn;c+=1){let l=ye(t,r),f=l?ri(jt(l),r):null;if(f){r=f.source(r.clock-f.clock);continue}let u=n?Ze(t,r):null;if(!u)break;r=u}return o?.set(s,r),r}var ze=t=>t?.type==="element",_t=t=>t.children.filter(ze),fe=(t,e)=>t.ns===Xo&&t.local===e;function Jo(t){return _t(t).find(o=>fe(o,"t"))?.children.find(o=>o.type==="text")}var kt=t=>{let e=Jo(t);return e?.type==="text"?e.value:""};function Qo(t,e,o,n,s,i){let r=new Set;if(n.size===0||i.size===0)return r;let c=t.doc.getMap(je),l=a=>{let g=Jo(a);return g?s.get(g.id):void 0},f=(a,g,p)=>{let h=_t(a);h.forEach((d,m)=>{if(!fe(d,"r"))return;let S=n.get(d.id);if(!ze(S)||S===d)return;let y=kt(S),w=kt(d);if(y.length<=w.length||!y.startsWith(w))return;let x=l(d),k=x===void 0?void 0:i.get(x),b=y.length-w.length;if(!k||k.deleted.length!==b)return;let v=[],M=0,C=(z,W,O)=>{for(let E=W;E<z.length&&M<b;E+=1){let L=z[E];if(!(!n.has(L.id)&&fe(L,"br"))&&!fe(L,"pPr")){if(fe(L,"endParaRPr"))return!0;if(!fe(L,"r")||n.has(L.id))return!1;v.push({run:L,newParagraph:O}),M+=kt(L).length}}return!0},T=C(h,m+1,!1),R=g[p+1],j=h.slice(m+1).every(z=>n.has(z.id)||fe(z,"endParaRPr"));M<b&&T&&j&&R&&fe(R,"p")&&!n.has(R.id)&&C(_t(R),0,!0);let F=v.length>0&&v.every(z=>z.newParagraph),P=v.map(z=>kt(z.run)).join("");if(M>b||M<b&&!(F&&y.endsWith(P)))return;let D=x===void 0?void 0:t.nodes.get(x),I=D instanceof J.Map?D.get(A.text):void 0,_=I instanceof J.Text?ai(t.doc,I):null,N=b-M;for(let z of v){let W=l(z.run),O=kt(z.run).length,E=W===void 0?void 0:i.get(W),L=W===void 0?void 0:t.nodes.get(W),$=k.deleted.slice(N,N+O);if(N+=O,!(O===0||!E?.created||E.inserted?.length!==O)&&!(!(L instanceof J.Map)||W===void 0)){L.set(oe.copyOf,[E.inserted.client,E.inserted.clock,...Vo($)]),z.newParagraph&&L.set(oe.newParagraph,!0),_&&L.set(oe.seen,_),c.set(W,e);for(let Q of $)r.add(U(Q.client,Q.clock))}}})},u=a=>{if(n.get(a.id)===a)return;let g=_t(a);g.forEach((p,h)=>{fe(p,"p")&&ze(n.get(p.id))&&f(p,g,h)});for(let p of g)u(p)};return u(o),r}function Zo(t,e,o,n){let s=[];if(o.size===0)return s;let i=new Set,r=[],c=l=>{let f=o.get(l.id);if(f!==l){for(let u of l.children)i.add(u.id);if(ze(f)){let u=new Set(l.children.map(g=>g.id)),a="";for(let g of f.children)!u.has(g.id)&&ze(g)&&(fe(g,"r")||fe(g,"p"))&&r.push({node:g,from:l,prev:a}),a=n.get(g.id)??a}for(let u of l.children)ze(u)&&c(u)}};c(e);for(let{node:l,from:f,prev:u}of r){if(i.has(l.id))continue;let a=n.get(l.id),g=n.get(f.id),p=g===void 0?void 0:t.nodes.get(g);(fe(l,"r")&&fe(f,"p")||fe(l,"p")&&En(f))&&a!==void 0&&p instanceof J.Map&&p.set(`${oe.removedRun}${a}`,u);let d=[l];for(;d.length>0;){let m=d.pop();if(m!==l&&i.has(m.id))continue;if(ze(m)){for(let x of m.children)d.push(x);continue}let S=n.get(m.id),y=S===void 0?void 0:t.nodes.get(S),w=y instanceof J.Map?y.get(A.text):void 0;if(!(!(w instanceof J.Text)||m.type!=="text"||m.value.length===0)&&w.toString()===m.value){for(let x of zt(w,0,w.length))s.push(x);w.delete(0,w.length)}}}return s}import*as pe from"yjs";var es=1024,Kt=1024,ts=1<<20,vn="http://schemas.openxmlformats.org/drawingml/2006/main",ns=()=>({left:ts,fields:new WeakMap,runs:new Map,paragraphs:new Map,seen:new Map,placed:new Map});function St(t,e,o){let n=e.fields.get(t);if(n)return n;let s=!1,i=0,r=new Map,c=[];for(let[f,u]of t.entries())i+=1,gt(f)?(s=!0,c.push(f)):f.startsWith(oe.removedRun)&&typeof u=="string"&&r.set(f.slice(oe.removedRun.length),u);o&&Ne(e,i);let l={removed:s,places:r,removedRuns:[...r.keys()].sort().slice(0,Kt),removals:c.sort().slice(0,Ot)};return e.fields.set(t,l),l}var Ne=(t,e=1)=>(t.left-=e)>=0;function In(t){let e=t.get(A.children);if(!(e instanceof pe.Array))return[];let o=new Set;for(let n of e.slice(0,es))typeof n=="string"&&o.add(n);return[...o]}function os(t,e,o,n){let s=n.runs.get(e);if(s!==void 0)return s;let i=In(o).some(r=>{if(!Ne(n))return!1;let c=t.nodes.get(r);if(!(c instanceof pe.Map))return!1;let l=c.get(A.shell);return l?.ns!==vn||l.local!=="t"?!1:In(c).some(f=>{if(!Ne(n))return!1;let u=t.nodes.get(f),a=u instanceof pe.Map?u.get(A.text):void 0;return a instanceof pe.Text&&a.length>0})});return n.runs.set(e,i),i}var ss=t=>(t.children??[]).some(e=>!("text"in e)&&e.local==="t"&&(e.children??[]).some(o=>"text"in o&&o.text.length>0));function rs(t,e,o){let n=o.seen.get(t);if(n)return n;let s=new Set,i=St(e,o,!0);for(let r of i.removals){let c=e.get(r);if(!(!Array.isArray(c)||c.length>Le||!Ne(o,c.length)))for(let l of c)typeof l=="string"&&s.add(l)}for(let r of i.removedRuns)s.add(r);return o.seen.set(t,s),s}function Pn(t){let e,o=new Map,n=()=>{let s=new Map;for(let[i,r]of t.nodes.entries()){if(!(r instanceof pe.Map))continue;let c=r.get(A.part),l=r.get(A.children);if(typeof c!="string"||!(l instanceof pe.Array))continue;let f=s.get(c);f||s.set(c,f=new Map);for(let u of l.toArray()){if(typeof u!="string")continue;let a=f.get(u);a?a.push(i):f.set(u,[i])}}return s};return s=>()=>(e??=n()).get(s)??o}var On=(t,e)=>({rescued:new Set,stranded:t,listings:e,walk:ns()});function is(t,e,o,n){return t.get(K.movedFrom)!==o?!1:(n().get(e)??[]).some(s=>s!==o)}function cs(t,e,o,n,s){let i=t.get(A.shell);if(i?.ns!==vn||is(t,e,o,s.listings))return null;let r=t.get(K.movedFrom);return(typeof t.get(K.splitFrom)=="string"||typeof r=="string"&&!s.stranded)&&!n().has(e)?null:i.local==="br"?n().has(e)?null:"br":i.local==="r"||i.local==="fld"?"run":null}function as(t,e,o,n){let s=o.get(A.key),i=()=>rs(e.key,o,n.walk);for(let r of(e.children??[]).slice(0,es)){if("text"in r)continue;if(!Ne(n.walk))return!1;let c=t.nodes.get(r.key),l=c instanceof pe.Map?cs(c,r.key,s,i,n):null;if(l==="br"||l==="run"&&ss(r))return!0}return!1}function di(t,e,o,n){let s=n.walk.paragraphs.get(e);if(s!==void 0)return s;let i=o.get(A.key),r=new Set(St(o,n.walk,!0).removedRuns),c=()=>rs(e,o,n.walk),l=[...new Set([...In(o),...r])].some(f=>{if(!Ne(n.walk))return!1;let u=t.nodes.get(f);if(!(u instanceof pe.Map))return!1;let a=cs(u,f,i,c,n);if(a==="br")return!0;let g=r.has(f)&&!St(u,n.walk,!0).removed;return a==="run"&&!g&&os(t,f,u,n.walk)});return n.walk.paragraphs.set(e,l),l}function fi(t,e){let o=0,n=[t];for(;n.length>0&&o<e;){let s=n.pop();if(o+=1,!("text"in s))for(let i of s.children??[])n.push(i)}return o}function ls(t,e,o,n,s,i=On(new Set,Pn(t)(e))){let r=i.walk,c=St(o,r,!1).places;if(c.size===0)return n;let l=new Set(n.map(b=>b.key)),f=o.get(A.key),u=o.get(A.shell)?.local==="txBody",a=u?"p":"r",g=u?["bodyPr","lstStyle"]:["pPr"],p=new Map,h=b=>{let v=s(b);return v&&Ne(r,fi(v,ts))?v:null},d=(b,v)=>{p.set(b,v),r.placed.set(b,String(f))};for(let b of[...c.keys()].sort()){if(p.size>=Kt||!Ne(r))break;let v=r.placed.get(b);if(l.has(b)||v!==void 0&&v!==String(f))continue;let M=t.nodes.get(b);if(!(M instanceof pe.Map)||M.get(A.part)!==e)continue;let C=M.get(A.shell);if(C?.ns!==vn||C.local!==a||!St(M,r,!0).removed||is(M,b,f,i.listings))continue;if(u){let j={stranded:i.stranded.has(b),listings:i.listings,walk:r};if(!di(t,b,M,j))continue;let F=h(b);if(!F||!as(t,F,M,j))continue;d(b,F),i.rescued.add(b);continue}let T=os(t,b,M,r),R=h(b);R&&(T||ss(R))&&d(b,R)}if(p.size===0)return n;let m=b=>{let v=c.get(b)??"";for(let M=0;M<Kt&&v!==""&&!l.has(v)&&!p.has(v);M+=1)v=c.get(v)??"";return l.has(v)||p.has(v)?v:""},S=new Map;for(let[b,v]of p){let M=m(b),C=S.get(M);C?C.push(v):S.set(M,[v])}let y=[],w=new Set,x=(b,v)=>{if(!(v>Kt))for(let M of S.get(b)??[])w.has(M.key)||(w.add(M.key),y.push(M),x(M.key,v+1))},k=!1;for(let b of n)!k&&("text"in b||!g.includes(b.local))&&(k=!0,x("",0)),y.push(b),x(b.key,0);k||x("",0);for(let b of p.values())w.has(b.key)||y.push(b);return y}function ds(t,e,o){if(o.rescued.size===0)return e;let n=ns(),s=r=>{if("text"in r||!o.rescued.has(r.key))return!0;let c=t.nodes.get(r.key),l={stranded:o.stranded.has(r.key),listings:o.listings,walk:n};return c instanceof pe.Map&&as(t,r,c,l)},i=r=>{let c=r.children??[];if(!c.some(l=>!s(l))){let l=c.map(f=>"text"in f?f:i(f));return l.every((f,u)=>f===c[u])?r:{...r,children:l}}return{...r,children:c.filter(s).map(l=>"text"in l?l:i(l))}};return i(e)}import*as V from"yjs";import*as we from"yjs";function Ie(t){if(!(t instanceof we.AbstractType))return null;let e=t._item;return e instanceof we.Item?e:null}function ge(t,e,o){for(let[n,s]of e.clients){let i=t.store.clients.get(n);if(!(!i||i.length===0))for(let{clock:r,len:c}of s){let l=i[i.length-1];if(!(r>=l.id.clock+l.length))for(let f=we.findIndexSS(i,r);f<i.length;f+=1){let u=i[f];if(u.id.clock>=r+c)break;u instanceof we.Item&&o(u)}}}}function $t(t,e,o){let n=we.createDeleteSet();for(let[s,i]of e.clients){let r=t.store.clients.get(s),c=[];for(let{clock:l,len:f}of i){if(!r||r.length===0){c.push({clock:l,len:f});continue}let u=l+f,a=l,g=r[r.length-1];if(l<g.id.clock+g.length)for(let p=we.findIndexSS(r,l);p<r.length;p+=1){let h=r[p];if(h.id.clock>=u)break;if(!(h instanceof we.Item)||!o(h))continue;let d=Math.max(l,h.id.clock);d>a&&c.push({clock:a,len:d-a}),a=Math.min(u,h.id.clock+h.length)}u>a&&c.push({clock:a,len:u-a})}c.length>0&&n.clients.set(s,c)}return n}function*An(t){for(let e=t._start;e;e=e.right)e.deleted||(yield e)}function*fs(t){for(let e of t._map.values())e.deleted||(yield e)}function Gt(t,e){let o=0;for(let n=t._start;n!==null;n=n.right)if(!(n.deleted||!n.countable)){if(n.id.client===e.client&&e.clock>=n.id.clock&&e.clock<n.id.clock+n.length)return o+(e.clock-n.id.clock);o+=n.length}return-1}function Ke(t,e){let o=[],n=0;for(let s=t._start;s!==null&&o.length<e.size;s=s.right)if(!(s.deleted||!s.countable)){for(let i=0;i<s.length;i+=1)e.has(`${s.id.client}:${s.id.clock+i}`)&&o.push(n+i);n+=s.length}for(let s=o.length-1;s>=0;){let i=s;for(;i>0&&o[i-1]===o[i]-1;)i-=1;t.delete(o[i],o[s]-o[i]+1),s=i-1}}var us=t=>t.left===null;var Te="pptx-undone-v1",ui=64,ps=1024,pi=1<<18,gi=(t,e)=>t.id.client!==e.client||t.id.clock>=e.clock;function hi(t,e,o){if(typeof e!="object"||e===null)return null;let n=e;if(typeof n.p!="string"||o!==void 0&&n.p!==o||typeof n.u!="string"||typeof n.a!="string"||!Number.isSafeInteger(n.c)||n.c<0)return null;let s=Number.isSafeInteger(n.q)&&n.q>=0?n.q:1/0,i=typeof n.n=="string"?n.n:"",r=typeof n.s=="string"?n.s:null;return{key:t,parent:n.u,after:n.a,before:i,client:n.c,clock:s,shownIn:r}}function ms(t,e,o,n=new Set){let s=t.nodes,i=new Map,r=new Set;if(ge(t.doc,e.insertions,a=>{a.parent===t.parts&&a.parentSub!==null&&!a.deleted&&r.add(a.parentSub)}),ge(t.doc,e.insertions,a=>{let g=a.parent;if(a.deleted||!(g instanceof V.Array))return;let p=g.parent;if(!(p instanceof V.Map)||Ie(p)?.parent!==s||p.get(A.children)!==g||a.parentSub!==null||!(a.content instanceof V.ContentAny))return;let h=i.get(g);h||i.set(g,h=new Set);for(let d of a.content.getContent())typeof d=="string"&&h.add(d)}),i.size===0)return;for(let a of i.values())for(let g of n)a.delete(g);let c=t.doc.getMap(Te),l=t.doc.clientID,f=V.getState(t.doc.store,l),u=[];for(let[a,g]of i){let p=a.parent;if(!(p instanceof V.Map)||p.get(A.children)!==a)continue;let h=p.get(A.key),d=p.get(A.part);if(typeof h!="string"||typeof d!="string"||r.has(d))continue;let m=a.toArray().filter(S=>typeof S=="string");m.forEach((S,y)=>{if(!g.has(S))return;let w=m[y+1]??"",x={p:d,u:h,a:m[y-1]??"",n:w,c:l,q:f};JSON.stringify(c.get(S))!==JSON.stringify(x)&&u.push([S,x])})}u.length>0&&o(()=>{for(let[a,g]of u)c.set(a,g)})}function ys(t,e,o,n,s,i){let r=t.doc.getMap(Te),c=t.doc.clientID,l=new Set;for(let f of s){let u=n[f],a=typeof u=="string"?i(u):void 0;if(typeof u!="string"||a===void 0||l.has(u))continue;l.add(u);let g="";for(let d=f-1;d>=0&&g==="";d-=1)n[d]!==u&&typeof n[d]=="string"&&(g=n[d]);let p="";for(let d=f+1;d<n.length&&p==="";d+=1)n[d]!==u&&typeof n[d]=="string"&&(p=n[d]);let h={p:e,u:o,a:g,n:p,c,q:0,s:a};JSON.stringify(r.get(u))!==JSON.stringify(h)&&r.set(u,h)}}function ks(t,e,o){let n=t.doc.getMap(Te);if(n.size===0)return;let s=new Set;ge(t.doc,e.deletions,i=>{if(!(!(i.parent instanceof V.Array)||!(i.content instanceof V.ContentAny)))for(let c of i.content.getContent())typeof c=="string"&&n.has(c)&&s.add(c)}),s.size>0&&o(()=>{for(let i of s)n.delete(i)})}function ws(t,e,o){let n=new Map;if(ge(t.doc,e.insertions,r=>{if(r.parent!==t.nodes||r.parentSub===null||!(r.content instanceof V.ContentType)||!(r.content.type instanceof V.Map))return;let c=r.content.type;if(t.nodes.get(r.parentSub)!==c)return;let l=c.get(A.part),f=c.get(A.attrs),u=c.get(A.children);if(typeof l!="string"||!(f instanceof V.Map)||!(u instanceof V.Array)||f.size>0||u.length>0||!o(l,r.parentSub))return;let a=n.get(l);a||n.set(l,a=new Set),a.add(r.parentSub)}),n.size===0)return!1;let s=!1,i=0;for(let r of t.nodes.values()){if((i+=1)>pi)break;if(!(r instanceof V.Map))continue;let c=r.get(A.part),l=typeof c=="string"?n.get(c):void 0,f=r.get(A.children);if(!l||!(f instanceof V.Array))continue;let u=f.toArray();for(let a=u.length-1;a>=0;a-=1){let g=u[a];typeof g=="string"&&l.has(g)&&(f.delete(a,1),s=!0)}}return s}var gs=new WeakMap;function hs(t,e,o){let n=t.placeOf.get(e);if(n){let l=t.byPart.get(n.part),f=l?.get(n.parent);f?.delete(e),f?.size===0&&l.delete(n.parent),t.placeOf.delete(e)}let s=o===void 0?null:hi(e,o),i=s?o.p:null;if(!s||i===null)return;let r=t.byPart.get(i);r||t.byPart.set(i,r=new Map);let c=r.get(s.parent);c||r.set(s.parent,c=new Map),c.set(e,s),t.placeOf.set(e,{part:i,parent:s.parent})}function mi(t,e){let o=t.doc.getMap(Te),n=gs.get(o);if(!n){let s={byPart:new Map,placeOf:new Map};n=s;for(let[i,r]of o.entries())hs(s,i,r);gs.set(o,s),o.observe(i=>{for(let r of i.keysChanged)hs(s,r,o.get(r))})}return n.byPart.get(e)??new Map}var Nn="http://schemas.openxmlformats.org/drawingml/2006/main",Ss=new Set(["p","pPr","rPr","endParaRPr","ln","bodyPr","tcPr"]);function xs(t){if("text"in t)return t.text.length>0;if(t.ns!==Nn)return!1;let e=t.children??[];return t.local==="r"?e.some(o=>!("text"in o)&&o.ns===Nn&&o.local==="t"&&xs(o)):t.local==="t"?e.some(o=>"text"in o&&o.text.length>0):Ss.has(t.local)&&(e.length>0||(t.attrs??[]).length>0)}var Xt=class t{#e;#t;#n;#i=new Map;shown=new Set;constructor(e,o,n){this.#e=e,this.#t=o,this.#n=n}static of(e,o,n){if(e.doc.getMap(Te).size===0)return null;let s=mi(e,o);if(s.size===0)return null;let i=new Set,r=[n];for(;r.length>0;){let c=r.pop();if(i.has(c))continue;i.add(c);let l=e.nodes.get(c);if(!(l instanceof V.Map)||l.get(A.part)!==o)continue;let f=l.get(A.children);if(f instanceof V.Array)for(let u of f.toArray())typeof u=="string"&&!i.has(u)&&r.push(u)}return new t(e,s,i)}#s(e,o,n){let s=`${e}\0${o.client}\0${o.clock}`,i=this.#i.get(s);if(i!==void 0)return i;this.#i.set(s,!1);let r=n<=ui&&this.#d(e,o,n);return this.#i.set(s,r),r}#d(e,o,n){let s=this.#e.nodes.get(e);if(!(s instanceof V.Map))return!1;let i=u=>gi(u,o),r=s.get(A.text);if(r instanceof V.Text){for(let u of An(r))if(u.countable&&i(u))return!0}let c=s.get(A.attrs);if(c instanceof V.Map){for(let u of fs(c))if(i(u))return!0}let l=s.get(A.children);if(l instanceof V.Array){for(let u of An(l))if(i(u))return!0}let f=[];for(let u of s.keys())u.startsWith(oe.removedRun)&&f.push(u);for(let u of f.sort().slice(0,ps))if(this.#s(u.slice(oe.removedRun.length),o,n+1))return!0;return this.#r(e).some(u=>this.#s(u.key,u,n+1))}#r(e){return[...this.#t.get(e)?.values()??[]].filter(o=>{if(this.#n.has(o.key)||o.shownIn!==null&&!this.#n.has(o.shownIn))return!1;let n=this.#e.nodes.get(o.key);return n instanceof V.Map&&!Ee(n)})}withUndone(e,o,n,s,i){let r=this.#r(e).filter(g=>!s.has(g.key)&&this.#s(g.key,g,0)).sort((g,p)=>g.key<p.key?-1:g.key>p.key?1:0).slice(0,ps);if(r.length===0)return n;let c=[...n],l=new Set(c.map(g=>g.key)),f=new Map([...this.#t.get(e)?.values()??[]].map(g=>[g.key,g.after])),u=new Set(r.map(g=>g.key)),a="\0";for(let g=!1;u.size>0;){let p=!1;for(let h of r){if(!u.has(h.key))continue;let d=h.after,m=d!==""&&!l.has(d)&&!u.has(d)&&l.has(h.before)?h.before:null;m!==null&&(d=a);let S=new Set([h.key]),y=!1;for(;d!==""&&d!==a&&!l.has(d);){if(u.has(d)&&!g){y=!0;break}S.has(d)?d=a:(S.add(d),d=f.get(d)??a)}if(y)continue;u.delete(h.key),p=!0;let w=this.#c(h.key,o,s,i);if(!w||!xs(w))continue;let x=m!==null?c.findIndex(k=>k.key===m):d===""?0:d===a?c.length:c.findIndex(k=>k.key===d)+1;c.splice(x,0,w),l.add(h.key),this.shown.add(h.key)}p||(g=!0)}return c}#c(e,o,n,s){let i=this.#e.nodes.get(e);if(!(i instanceof V.Map)||i.get(A.part)!==o)return null;let r=i.get(A.text);if(r instanceof V.Text)return n.add(e),{key:e,text:r.toString()};let c=i.get(A.shell),{ns:l,local:f}=typeof c=="object"&&c!==null?c:{};return l!==Nn||typeof f!="string"||!Ss.has(f)&&f!=="r"&&f!=="t"?null:s(e)}};import*as bs from"yjs";var yi="http://schemas.openxmlformats.org/drawingml/2006/main";function Rs(t){let e=new Map;if(!t)return e;let o=[t];for(;o.length>0;){let n=o.pop();if(e.set(n.id,n),n.type==="element")for(let s of n.children)o.push(s)}return e}function ki(t,e){let o=t.length,n=e.length,s=new Uint32Array((o+1)*(n+1));for(let f=o-1;f>=0;f--)for(let u=n-1;u>=0;u--)s[f*(n+1)+u]=t[f]===e[u]?s[(f+1)*(n+1)+u+1]+1:Math.max(s[(f+1)*(n+1)+u],s[f*(n+1)+u+1]);let i=new Set,r=new Set,c=0,l=0;for(;c<o&&l<n;)t[c]===e[l]?(i.add(c++),r.add(l++)):s[(c+1)*(n+1)+l]>=s[c*(n+1)+l+1]?c++:l++;return{keepA:i,keepB:r}}function Tn(t,e){let o=t.toArray();if(o.length===e.length&&o.every((r,c)=>r===e[c]))return;if(o.length*e.length>25e4){t.delete(0,o.length),t.insert(0,[...e]);return}let{keepA:n,keepB:s}=ki(o,e);for(let r=o.length-1;r>=0;r--)n.has(r)||t.delete(r,1);let i=0;e.forEach((r,c)=>{s.has(c)||t.insert(i,[r]),i+=1})}function Ys(t,e){if(t.size===0)return t;let o=Nt(e);return new Map([...t].filter(([n])=>o.has(n)))}function Ms(t){let e=new Map;if(t?.kind!=="xml")return e;let o=[[t.xml.root,""]];for(;o.length>0;){let[n,s]=o.pop();if(e.set(n.id,s),n.type==="element")for(let i of n.children)o.push([i,`${n.id}/${s}`])}return e}function Es(t,e,o){let n,s;return i=>{let r=t?.get(i);if(r===void 0)return!1;n??=Ms(e),s??=Ms(o);let c=n.get(r);return c!==void 0&&c===s.get(r)}}function Is(t,e,o){let n;return s=>{let i=t?.get(s);if(i===void 0||o?.kind!=="xml")return;if(!n){let c=new Map,l=[o.xml.root];for(;l.length>0;){let f=l.pop();if(f.type==="element")for(let u of f.children)c.set(u.id,f.id),l.push(u)}n=c}let r=n.get(i);return r===void 0?void 0:e?.get(r)}}function vs(t,e,o){let n=t.toString();if(n===e)return;let s=0;for(;s<n.length&&s<e.length&&n[s]===e[s];)s++;let i=0;for(;i<n.length-s&&i<e.length-s&&n[n.length-1-i]===e[e.length-1-i];)i++;let r=p=>p>=55296&&p<=56319,c=p=>p>=56320&&p<=57343;s>0&&r(n.charCodeAt(s-1))&&s--,i>0&&c(n.charCodeAt(n.length-i))&&i--;let l=n.length-s-i,f=e.length-s-i;if(l===f&&!/[\uD800-\uDFFF]/.test(n.slice(s,s+l)+e.slice(s,s+f))){let p=zt(t,s,l),h=[];for(let d=s;d<s+l;d++){if(n[d]===e[d])continue;let m=p[d-s];m&&h.push(m),t.insert(d,e[d]),t.delete(d+1,1)}return{created:o,deleted:h}}let u=l>0?zt(t,s,l):[];l>0&&t.delete(s,l);let a=t.doc,g=a?bs.getState(a.store,a.clientID):0;return f>0&&t.insert(s,e.slice(s,e.length-i)),{created:o,deleted:u,...f>0&&a?{inserted:{client:a.clientID,clock:g,length:f}}:{}}}function Ps(t,e){let o=new Map,n=new Set;if(e.size===0)return{inParent:o,watch:n};let s=new Map,i=[t];for(;i.length>0;){let r=i.pop();for(let c of r.children??[])"text"in c||(s.set(c.key,r.key),e.has(c.key)&&c.ns===yi&&wi.has(c.local)&&o.set(c.key,r.key),i.push(c))}for(let r of o.values()){n.add(r);let c=s.get(r);c!==void 0&&n.add(c)}return{inParent:o,watch:n}}var wi=new Set(["r","br","fld"]);var xi="http://schemas.openxmlformats.org/drawingml/2006/main",Mi=1<<20,Os=(t,e)=>t.attrs.find(o=>o.ns===""&&o.local===e)?.value,bi=t=>({ns:t.ns,local:t.local,...t.prefix?{prefix:t.prefix}:{},nsDecls:t.nsDecls.map(e=>({prefix:e.prefix,uri:e.uri}))}),Bt=class{#e;#t=new Map;#n=new Map;#i=new Map;#s=new Set;#d=new Map;#r=new Map;#c=new Map;#h=new Map;#S=new Set;#f=new Set;#a=new Map;#l=new Map;#u=ft;#p=null;#x;#M=new Map;#m=new Map;#b;#y=new Set;constructor(e,o={value:0}){this.#e=e,this.#b=o;let n=`${e.doc.clientID.toString(36)}.`;for(let s of e.nodes.keys()){if(!s.startsWith(n))continue;let i=Number.parseInt(s.slice(n.length).replace(vt,""),36);Number.isSafeInteger(i)&&i<=Qn&&i>o.value&&(o.value=i)}}get seeded(){return this.#e.parts.size>0}#E(e,o){for(let n of this.#i.get(e)??[])this.#n.delete(n);for(let[n,s]of o)this.#n.set(n,s);this.#i.set(e,new Set(o.keys())),this.#s.clear(),this.#M.clear();for(let[n,s]of this.#n)for(let i of s.companions)this.#s.add(i),this.#M.set(i,n)}#R(e,o){for(let n of this.#t.get(e)?.idOf.keys()??[])this.#m.delete(n);if(!o){this.#t.delete(e);return}this.#t.set(e,o);for(let n of o.idOf.keys())this.#m.set(n,e)}#P(e){let o=this.#t.get(e);return o||(o={keyOf:new Map,idOf:new Map},this.#t.set(e,o)),o}#k=!1;#O(){let e=this.#e.doc.clientID.toString(36),o=this.#k?vt:"",n;do this.#b.value+=1,n=`${e}.${o}${this.#b.value.toString(36)}`;while(this.#e.nodes.has(n));return n}seed(e){this.#k=!0;try{for(let o of e.parts.values())this.#I(o,void 0)}finally{this.#k=!1}}hasHiddenListings(e){return e.some(o=>this.#a.has(o))}dropHiddenListings(e,o,n){for(let s of e){let i=this.#a.get(s);if(!i)continue;let r=Es(this.#t.get(s)?.idOf,o.parts.get(s),n.parts.get(s)),c=this.#t.get(s),l=Is(c?.idOf,c?.keyOf,o.parts.get(s));this.#a.delete(s);for(let[f,u]of i){let a=this.#v(f);if(!a||a.length!==u.length)continue;let g=[...u.at.keys()].sort((h,d)=>d-h);if(g.some(h=>a.get(h)!==u.at.get(h)))continue;let p=g.filter(h=>r(u.at.get(h)));p.length>0&&ys(this.#e,s,f,a.toArray(),p,l);for(let h=0;h<g.length;){let d=h+1;for(;d<g.length&&g[d]===g[d-1]-1;)d++;a.delete(g[d-1],d-h),h=d}}}}writeChange(e,o,n){for(let s of n){this.#S.delete(s);let i=o.parts.get(s);if(!i){this.#e.parts.delete(s),this.#e.binaries.delete(s),this.#R(s,void 0);continue}this.#I(i,e.parts.get(s))}}#I(e,o){if(e.kind==="binary"){(o?.kind!=="binary"||o.bytes!==e.bytes)&&this.#e.binaries.set(e.partName,e.bytes),Ue(this.#e.parts.get(e.partName))?.kind!=="binary"&&this.#e.parts.set(e.partName,{kind:"binary"});return}o?.kind==="binary"&&this.#e.binaries.delete(e.partName);let n={partName:e.partName,ids:this.#P(e.partName),before:Rs(o?.kind==="xml"?o.xml.root:void 0),texts:new Map},s=this.#Y(e.xml.root,n),i=this.#r.get(e.partName);this.#r.delete(e.partName);for(let c of Lo(e.xml.root,i,n.ids.keyOf))this.#Y(c,{...n,before:Do(n.before,c.id)});ko(this.#e,e.partName,e.xml.root,n.before,n.ids.keyOf),Co(this.#e,e.xml.root,n.before,n.ids.keyOf),this.#A(e.partName,e.xml.root,n);let r=Ue(this.#e.parts.get(e.partName));(r?.kind!=="xml"||r.root!==s)&&this.#e.parts.set(e.partName,{kind:"xml",root:s})}#A(e,o,n){if(this.#k)return;let s=Qo(this.#e,e,o,n.before,n.ids.keyOf,n.texts),i=Zo(this.#e,o,n.before,n.ids.keyOf),r=this.#e.doc,c=new Map,l=f=>{if(this.#y.size>=Mi||s.has(U(f.client,f.clock)))return;let u=ue(r,f,c,!1);this.#y.add(U(u.client,u.clock))};for(let f of n.texts.values())for(let u of f.deleted)l(u);for(let f of i)l(f)}get deletedText(){return this.#y}showingUnlisted(e){return e.filter(o=>(this.#c.get(o)?.size??0)>0||this.#S.has(o))}forgetDeleted(e){for(let o of e)this.#y.delete(o)}newCopies(e){let o=new Map,n=e.changed.get(this.#e.nodes);if(!n)return o;let s=this.#e.doc.getMap(je);for(let i of n){if(i===null)continue;let r=s.get(i),c=this.#e.nodes.get(i),l=Oe(c);if(typeof r!="string"||!l||l.client===this.#e.doc.clientID||c.get(A.part)!==r)continue;let f=o.get(r);f?f.push(i):o.set(r,[i])}return o}#Y(e,o){let{partName:n,ids:s,before:i}=o,r=s.keyOf.get(e.id),c=r===void 0?void 0:this.#e.nodes.get(r);if(r!==void 0&&c instanceof B.Map&&i.get(e.id)===e)return r;r!==void 0&&this.#h.get(n)?.watch.has(r)&&this.#S.add(n);let l=r===void 0||!(c instanceof B.Map);if(r===void 0||!(c instanceof B.Map)){r=this.#O();let R=new B.Map;this.#e.nodes.set(r,R),R.set(A.part,n),R.set(A.key,r),e.type==="text"?R.set(A.text,new B.Text):(R.set(A.attrs,new B.Map),R.set(A.children,new B.Array)),c=R,s.keyOf.set(e.id,r),s.idOf.set(r,e.id),this.#m.set(r,n)}let f=c;if(e.type==="text"){let R=f.get(A.text),j=R instanceof B.Text?vs(R,e.value,l):void 0;return j&&o.texts.set(r,j),r}let u=bi(e);JSON.stringify(f.get(A.shell))!==JSON.stringify(u)&&f.set(A.shell,u);let a=this.#n.get(r),g=this.#e.doc.clientID.toString(36),p=a?.merge?[r,...a.companions].find(R=>me(R)===g)??r:r,h=f.get(A.attrs);if(h instanceof B.Map){let R=new Map;for(let F of e.attrs)R.set(`${F.ns}${Rt}${F.local}`,{ns:F.ns,local:F.local,value:F.value,...F.prefix?{prefix:F.prefix}:{}});let j=a?.merge?a.companions.map(F=>this.#w(F)):[];for(let F of[...h.keys()])R.has(F)||h.delete(F);for(let F of j)for(let P of[...F?.keys()??[]])R.has(P)||F.delete(P);for(let[F,P]of R){let D=a?.attrFrom.get(F)??(h.has(F)?r:void 0),I=D===void 0?void 0:this.#w(D);if(I&&JSON.stringify(I.get(F))===JSON.stringify(P))continue;if((this.#w(p)??h).set(F,P),a?.merge)for(let N of[r,...a.companions])N!==p&&this.#w(N)?.delete(F)}}let d=e.children.map(R=>this.#Y(R,o)),m=new Set(d),S=f.get(A.children),y=(R,j)=>{let F=[],P=new Set,D=I=>{P.has(I)||(P.add(I),F.push(I))};for(let I of R){D(I);for(let _ of this.#n.get(I)?.companions??[])j.has(_)&&D(_)}return F},w=new Set(S instanceof B.Array?S.toArray():[]),x=this.#c.get(n),k=this.#h.get(n)?.inParent,b=k&&k.size>0?{has:R=>x?.has(R)===!0||k.get(R)===r}:x,v=a?d.filter(R=>!a.childFrom.has(R)&&!w.has(R)&&!b?.has(R)):[],M=(a?d.filter(R=>!a.childFrom.has(R)&&(w.has(R)||p===r)):d).filter(R=>!b?.has(R)||w.has(R));if(S instanceof B.Array){let R=S,j=R.toArray();Tn(R,bo(j,this.#N(e,j,y(M,new Set(j))),this.#d.get(n)))}let C=new Set;if(a?.merge)for(let R of e.children)R.type==="element"&&C.add(He(e,R,j=>Os(R,j))?.slot);let T=new Set(v);a?.merge&&e.children.forEach((R,j)=>{R.type==="element"&&T.has(d[j])&&C.delete(He(e,R,F=>Os(R,F))?.slot)});for(let R of a?.merge?a.companions:[]){let j=this.#v(R);if(!j)continue;let F=j.toArray(),P=F.filter(D=>{if(this.#s.has(D))return m.has(this.#M.get(D));if(a.childFrom.get(D)===R)return m.has(D);let I=a.shadowed.get(D);return I!==void 0&&C.has(I)});Tn(j,y([...P,...R===p?v:[]],new Set(F)))}return r}#N(e,o,n){let s=new Set(n),i=new Set(o),r=o.filter(p=>s.has(p)),c=n.filter(p=>i.has(p)),l=(p,h)=>p.length===h.length&&p.every((d,m)=>d===h[m]);if(l(r,c)||!l(Ve(e,r,p=>this.#T(p)),c))return n;let f=new Map,u=[],a;for(let p=n.length-1;p>=0;p--){let h=n[p];if(i.has(h))a=h;else if(a===void 0)u.unshift(h);else{let d=f.get(a);d||f.set(a,d=[]),d.unshift(h)}}let g=[];for(let p of r){for(let h of f.get(p)??[])g.push(h);g.push(p)}for(let p of u)g.push(p);return g}#T(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.shell):void 0;if(typeof n!="object"||n===null)return;let{ns:s,local:i}=n;return typeof s=="string"&&typeof i=="string"?{ns:s,local:i}:void 0}#w(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.attrs):void 0;return n instanceof B.Map?n:void 0}#v(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.children):void 0;return n instanceof B.Array?n:void 0}keyOf(e,o){return this.#t.get(e)?.keyOf.get(o)}idOf(e,o){return this.#t.get(e)?.idOf.get(o)}textOf(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.text):void 0;return n instanceof B.Text?n:void 0}partOf(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.part):void 0;return typeof n=="string"?n:void 0}recordOfText(e){let o=e.parent,n=o instanceof B.Map?o.get(A.key):void 0;if(typeof n!="string"||this.#e.nodes.get(n)!==o)return;let s=o.get(A.part);return typeof s=="string"?{key:n,part:s}:void 0}touchedParts(e){let o=new Set,n=this.#e.parts,s=this.#e.binaries,i=this.#e.nodes,r=this.#e.doc,c=[r.getMap(De),r.getMap(pt)],l=r.getMap(Pt),f=r.getMap(Te);for(let[u,a]of e.changed){let g=u;if(g===n||g===s){for(let d of a)d!==null&&o.add(d);continue}if(c.includes(g)){for(let d of a){let m=d===null?void 0:u.get(d);typeof m=="string"&&o.add(m)}continue}if(g===f){for(let d of a){if(d===null)continue;let m=this.#e.doc.getMap(Te).get(d),S=typeof m=="object"&&m!==null?m.p:void 0,y=this.#e.nodes.get(d),w=typeof S=="string"?S:y instanceof B.Map?y.get(A.part):void 0;typeof w=="string"&&o.add(w)}continue}if(g===l){for(let d of a){let m=d===null?void 0:this.#e.nodes.get(d.split("\0")[0]),S=m instanceof B.Map?m.get(A.part):void 0;typeof S=="string"&&o.add(S)}continue}if(g===i){for(let d of a){if(d===null)continue;let m=this.#e.nodes.get(d),S=m instanceof B.Map?m.get(A.part):void 0;if(typeof S=="string"){o.add(S);continue}let y=this.#m.get(d);y!==void 0&&o.add(y)}continue}let p=g;for(;p instanceof B.AbstractType&&p.parent!==i;)p=p.parent;let h=p instanceof B.Map?p.get(A.part):void 0;typeof h=="string"&&o.add(h)}return o}allParts(e){let o=new Set(this.#e.parts.keys());for(let n of e.parts.keys())o.add(n);return o}rebuild(e,o,n=!1){let s=[],i=[],r=new Map,c=new Map,l=new Map,f=new Map,u=new Map,a=[...e];for(let d of a)[this.#a,this.#r].forEach(m=>m.delete(d));let g=new Map,p=new Map,h=Pn(this.#e);for(let d of a){let m=Ue(this.#e.parts.get(d));if(!m){if(this.#e.parts.has(d))return{ok:!1,reason:`invalid part entry ${d}`};o.parts.has(d)&&i.push(d);continue}if(m.kind==="binary"){let _=this.#e.binaries.get(d);if(!(_ instanceof Uint8Array)||_.length>it.maxBinaryBytes)return{ok:!1,reason:`invalid binary part ${d}`};s.push({kind:"binary",partName:d,bytes:_});continue}let S=new Map;this.#f=new Set,this.#o=void 0,this.#u=ht(this.#e,d,m.root),this.#l=new Map,this.#p=Xt.of(this.#e,d,m.root);let y=(_,N,z)=>this.#g(_,d,N,z,S),w=new Set,x=new Set,k=h(d),b=(_=new Set)=>{w=new Set,x=new Set,this.#x=On(_,k);let N=this.#g(m.root,d,new Set,0,S);return N&&Eo(this.#e,d,N,y,w,x)},v=b(),M=this.#u;if(v&&(M.lost.size>0||M.unseenWinners.size>0)){let _=ht(this.#e,d,m.root,Nt(v));Io(_,M)||(this.#u=_,this.#f=new Set,this.#l=new Map,S.clear(),v=b())}if(v&&x.size>0&&(this.#f=new Set,this.#l=new Map,S.clear(),v=b(x)),!v)return{ok:!1,reason:`${this.#o??"invalid node records"} in ${d}`};let C=ds(this.#e,Ro(this.#e,d,v,y,this.#u.lost),this.#x);if(this.#o)return{ok:!1,reason:`${this.#o} in ${d}`};let T=new Set,R=Fo(this.#e,C,w,T);u.set(d,T);let j=n?void 0:this.#t.get(d),F=o.parts.get(d),P=F?.kind==="xml"?F.xml.nextId:1,D=Si(d,R,{idOf:_=>j?.idOf.get(_),nextId:P});if(!D.ok)return{ok:!1,reason:`${d}: ${D.reason}`};let I={keyOf:new Map,idOf:new Map};for(let[_,N]of D.ids)I.idOf.set(_,N),I.keyOf.set(N,_);r.set(d,I),c.set(d,S),l.set(d,this.#f),f.set(d,Ys(this.#l,R)),g.set(d,this.#p?.shown??new Set),p.set(d,Ps(R,w)),s.push({kind:"xml",partName:d,xml:D.part})}for(let[d,m]of r)this.#R(d,m);for(let d of i)this.#R(d,void 0);for(let[d,m]of c)this.#E(d,m);for(let d of i)this.#E(d,new Map);for(let[d,m]of l)this.#d.set(d,m);for(let d of i)this.#d.delete(d);for(let[d,m]of f)m.size>0&&this.#a.set(d,m);for(let d of i)this.#a.delete(d);for(let[d,m]of g)this.#c.set(d,m);for(let[d,m]of p)this.#h.set(d,m);for(let d of i)this.#h.delete(d);for(let d of i)this.#c.delete(d);for(let[d,m]of u)this.#r.set(d,m);return this.#p=null,{ok:!0,parts:s,removed:i}}#o;#g(e,o,n,s,i){if(s>it.maxReadDepth||n.has(e))return null;n.add(e);let r=this.#e.nodes.get(e);if(!(r instanceof B.Map)||r.get(A.part)!==o)return null;let c=r.get(A.shell),l=r.get(A.attrs),f=r.get(A.children);if(typeof c!="object"||c===null||!(l instanceof B.Map)||!(f instanceof B.Array))return null;let u=c,a=[],g=f.toArray();for(let[x,k]of g.entries()){if(typeof k!="string")continue;if(n.has(k)){let M=this.#l.get(e);M||this.#l.set(e,M={length:g.length,at:new Map}),M.at.set(x,k);continue}let b=this.#e.nodes.get(k);if(b instanceof B.Map&&b.get(A.text)instanceof B.Text){if(b.get(A.part)!==o)continue;n.add(k),a.push({key:k,text:b.get(A.text).toString()});continue}let v=this.#g(k,o,n,s+1,i);if(v)a.push(v);else if(this.#o)return null}let p=[...l.entries()].sort(([x],[k])=>x<k?-1:x>k?1:0).map(([,x])=>x),h=u.ns,d=u.local,m=d==="p"&&h===xi||En({ns:h,local:d})?ls(this.#e,o,r,a,x=>{let k=this.#g(x,o,n,s+1,i);return this.#o?null:k},this.#x):a,S=this.#p?this.#p.withUndone(e,o,m,n,x=>this.#g(x,o,n,s+1,i)):m;if(this.#o)return null;let y=Mo(this.#e,{ns:h,local:d},S,this.#f,this.#u.unseenWinners),w=un({ns:h,local:d},y,i);return w?{key:e,ns:h,local:d,...typeof u.prefix=="string"?{prefix:u.prefix}:{},nsDecls:Array.isArray(u.nsDecls)?u.nsDecls:[],attrs:p,children:[...Ve({ns:h,local:d},w,x=>"text"in x?void 0:x)]}:(this.#o="too many concurrent copies of one element",null)}};import*as Me from"yjs";var Ut="pptxEditor",Ri=256,Ns=256,Ts=512,Cs=256,Ds=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,$e=(t,e=Ri)=>typeof t=="string"&&t.trim().length>0&&t.length<=e;function Ls(t){return!$e(t.actorId)||!$e(t.name)||t.role!==void 0&&t.role!=="human"&&t.role!=="agent"?"invalid-identity":t.color!==void 0&&!Ds.test(t.color)?"invalid-identity-color":null}function _s(t){let{actorId:e,name:o,color:n,role:s}=t;return!$e(e)||!$e(o)?null:{actorId:e,name:o,...typeof n=="string"&&Ds.test(n)?{color:n}:{},...s==="human"||s==="agent"?{role:s}:{}}}function Fs(t){let e=t?.[Ut];return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function zs(t,e){if(t.kind==="shapes"){let i=t.shapes.slice(0,Ts).map(r=>e.keyOf(t.part,r)).filter(r=>r!==void 0);return i.length>0?{kind:"shapes",part:t.part,keys:i}:void 0}let o=i=>{let r=e.keyOf(t.part,i.node);if(r===void 0)return;let c=e.textOf(r);if(!c)return{key:r};let l=Math.max(0,Math.min(Math.trunc(i.offset)||0,c.length));return{rel:Me.relativePositionToJSON(Me.createRelativePositionFromTypeIndex(c,l))}},n=o(t.anchor),s=o(t.head);return n&&s?{kind:"text",anchor:n,head:s}:void 0}function js(t,e){return{actorId:t.actorId,name:t.name,...t.color?{color:t.color}:{},...t.role?{role:t.role}:{},...e?{selection:e}:{}}}function Ws(t){let e=[];for(let[o,n]of t.getStates()){if(e.length>=Ns)break;let s=Fs(n),i=s?_s(s):null;i&&e.push({...i,isLocal:o===t.clientID})}return e}function As(t,e,o){if(typeof t!="object"||t===null)return null;let n=t;if($e(n.key,Cs)){let l=o.partOf(n.key),f=l?o.idOf(l,n.key):void 0;return l&&f?{part:l,node:f,offset:0}:null}let s=n.rel;if(typeof s!="object"||s===null)return null;let i;try{i=Me.createAbsolutePositionFromRelativePosition(Me.createRelativePositionFromJSON(s),e)}catch{return null}if(!i||!(i.type instanceof Me.Text))return null;let r=o.recordOfText(i.type),c=r?o.idOf(r.part,r.key):void 0;return r&&c?{part:r.part,node:c,offset:i.index}:null}function Ht(t,e,o){if(typeof t!="object"||t===null)return null;let n=t;if(n.kind==="shapes"&&$e(n.part,1024)&&Array.isArray(n.keys)){let s=n.part,i=n.keys.slice(0,Ts).filter(r=>$e(r,Cs)).map(r=>o.idOf(s,r)).filter(r=>r!==void 0);return i.length>0?{kind:"shapes",part:s,shapes:i}:null}if(n.kind==="text"){let s=As(n.anchor,e,o),i=As(n.head,e,o);return!s||!i||s.part!==i.part?null:{kind:"text",part:s.part,anchor:{node:s.node,offset:s.offset},head:{node:i.node,offset:i.offset}}}return null}function Ks(t,e,o){let n=[],s=0;for(let[i,r]of t.getStates()){if(++s>Ns)break;if(i===t.clientID)continue;let c=Fs(r),l=c?_s(c):null;if(!c||!l)continue;let f=Ht(c.selection,e,o);f&&n.push({actorId:l.actorId,name:l.name,...l.color?{color:l.color}:{},selection:f})}return n}import*as H from"yjs";var Yi=4096,Gs=1<<20,Ei=65536,Ii=1<<20,$s="http://schemas.openxmlformats.org/drawingml/2006/main",vi=t=>t.type==="element";function Pi(t,e){let o=ye(t,e);if(!o)return null;let n=0;for(let s=o.parent instanceof H.Text?o.parent._start:null;s;s=s.right){if(s===o)return{text:o.parent,at:n+(e.clock-o.id.clock)};n+=s.length}return null}function Oi(t,e){let o=new Map,n=t.package.parts.get(e);if(n?.kind!=="xml")return o;let s=(i,r,c)=>{let l=t.keyOf(e,i.id),f=i.ns===$s&&i.local==="p"&&l&&c?{p:{key:l,parent:c}}:i.ns===$s&&i.local==="r"&&l?{...r,run:l}:r;for(let u of i.children)if(vi(u))s(u,f,l);else{let a=t.keyOf(e,u.id);a!==void 0&&o.set(a,{order:o.size,...f})}};return s(n.xml.root,{},void 0),o}function Xs(t,e,o,n,s,i,r){let c=t.doc,l=c.clientID,f=O=>{let E=t.nodes.get(O),L=Oe(E),$=E instanceof H.Map?E.get(A.text):void 0;return!L||!($ instanceof H.Text)||E.get(A.part)!==e?null:{key:O,copy:L,text:$}},u=new Set(o.filter(O=>{let E=f(O);return E!==null&&E.copy.client!==l}));if(u.size===0)return;let a=Oi(s,e),g=[],p=0;for(let[O,E]of t.doc.getMap(je).entries()){if(E!==e)continue;let L=f(O);if(!(!L||L.text.length===0&&!a.has(O))){if(g.length>=Yi||(p+=L.copy.length)>Gs)return;g.push(L)}}let h=g.filter(O=>u.has(O.key));if(h.length===0)return;let d=new Map,m=O=>ue(c,O,d),S=new Map,y=new Map,w=O=>(y.has(O.key)||y.set(O.key,Pi(c,m(O.copy.source(0)))),y.get(O.key)),x=(O,E)=>{let L=w(O),$=w(E);return L&&$&&L.text===$.text?L.at-$.at:0},k=O=>a.get(O.key)?.order??-1,b=(O,E)=>(x(O,E)||k(O)-k(E))>=0?O:E,v=(O,E)=>H.createID(O.copy.client,O.copy.clock+E),M=O=>{if(O.copy.newParagraph)return!0;let E=O.copy.source(0);for(let L=0;L<Yn;L+=1){let $=ye(c,E),Q=$?Oe(jt($)):null,he=Q?E.clock-Q.clock:-1;if(!Q||E.client!==Q.client||he<0||he>=Q.length)return!1;if(Q.newParagraph)return!0;E=Q.source(he)}return!1},C=new Map;for(let O of g)if(a.has(O.key))for(let E=0;E<O.copy.length;E+=1){let L=v(O,E);if(Wt(c,L))continue;let $=m(O.copy.source(E)),Q=U($.client,$.clock),he=C.get(Q);he?he.push({copy:O,id:L}):C.set(Q,[{copy:O,id:L}])}let T=O=>C.get(U(O.client,O.clock))?.reduce((E,L)=>b(E.copy,L.copy)===E.copy?E:L);for(let O of h)Ci(t,O,qo(t.nodes.get(O.key)),E=>T(m(E)),i);let R=new Map,j=(O,E)=>{let L=R.get(O);L?L.push(E):R.set(O,[E])};if(n.size>0)for(let O of h)for(let E=0;E<O.copy.length;E+=1){let L=ue(c,O.copy.source(E),S,!1);n.has(U(L.client,L.clock))&&!Wt(c,v(O,E))&&j(O.text,v(O,E))}let F=new Map,P=O=>{let E=F.get(O.key);return E===void 0&&F.set(O.key,E=M(O)),E};for(let O of C.values()){if(O.length<2||!O.some(L=>u.has(L.copy.key))||!O.some(L=>P(L.copy))||new Set(O.map(L=>L.copy.key)).size<2)continue;let E=O.reduce((L,$)=>b(L.copy,$.copy)===L.copy?L:$);for(let L of O)L!==E&&j(L.copy.text,L.id)}for(let[O,E]of R)Ke(O,new Set(E.map(L=>U(L.client,L.clock))));let D=new Map,I=O=>{let E=D.get(O.key);if(!E){E=new Set;for(let L=0;L<O.copy.length;L+=1){let $=m(O.copy.source(L));E.add(U($.client,$.clock))}D.set(O.key,E)}return E},_=Ii,N=(O=1)=>(_-=O)>=0,W={room:t,me:l,incoming:h,all:g,placed:a,share:(O,E)=>{let[L,$]=[I(O),I(E)].sort((Q,he)=>Q.size-he.size);if(!N(L.size))return!1;for(let Q of L)if($.has(Q))return!0;return!1},laterStart:x,step:N,movedRun:r};Di(W),Ai(W)}function Vt(t,e){let o=t.nodes.get(e),n=o instanceof H.Map?o.get(A.children):void 0;return n instanceof H.Array?n:void 0}function Ai(t){let{room:e,me:o,incoming:n,all:s,placed:i,share:r,laterStart:c,step:l,movedRun:f}=t,u=new Map,a=(p,h)=>{let d=u.get(p);if(!d){u.set(p,d=new Map);let m=Ei,S=y=>{let w=Vt(e,y)?.toArray()??[];return m-=w.length,m<0?[]:w};for(let y of S(p))for(let w of S(y))for(let x of S(w))for(let k of S(x))d.set(k,{p:y,run:w})}return d.get(h)},g=new Map;for(let p of[...n].sort(c)){let h=i.get(p.key);if(!(!h?.p||!h.run))for(let d of s){if(!l())return;if(d.copy.client!==o||d.key===p.key||!r(p,d))continue;let m=a(h.p.parent,d.key),S=m?e.nodes.get(m.run):void 0;if(!m||m.p===h.p.key||!(S instanceof H.Map))continue;let y=S.get(K.movedFrom)===h.p.key,w=!y&&d.copy.newParagraph&&c(p,d)>0&&Ti(e,d,a,h.p.parent)===h.p.key;if(!y&&!w)continue;let x=Vt(e,h.p.key),k=Vt(e,m.p),b=x?.toArray().indexOf(h.run)??-1;if(!x||!k||b<0)continue;let v=Ni(x,b);if(x.delete(b,1),!w){k.insert(k.toArray().indexOf(m.run),[h.run]);break}let M=g.get(m.run)??m.run,C=H.getState(e.doc.store,o);k.insert(k.toArray().indexOf(M)+1,[h.run]),g.set(m.run,h.run),v&&f?.({anchor:H.createID(d.copy.client,d.copy.clock),gone:v,added:H.createID(o,C),run:h.run,from:x,to:k});break}}}function Ni(t,e){let o=0;for(let n=t._start;n!==null;n=n.right)if(!(n.deleted||!n.countable)){if(e<o+n.length){for(let s=n;s!==null&&!s.keep;)s.keep=!0,s=s.parent._item;return H.createID(n.id.client,n.id.clock+e-o)}o+=n.length}}function Ti(t,e,o,n){let s=ye(t.doc,e.copy.source(0)),i=s?jt(s)?.get(A.key):void 0;return typeof i=="string"?o(n,i)?.p:void 0}function Ci(t,e,o,n,s){let i=t.doc,r=i.clientID,l=ye(i,e.copy.source(0))?.parent;if(!(l instanceof H.Text))return;let f=new Set;for(let p=0;p<e.copy.length;p+=1){let h=e.copy.source(p);f.add(U(h.client,h.clock))}let u=new Map,a=[],g=null;for(let p=l._start;p!==null;p=p.right){if(p.deleted||!(p.content instanceof H.ContentString))continue;let h=p.content.str;for(let d=0;d<h.length;d+=1){let m=H.createID(p.id.client,p.id.clock+d),S=d===0?p.origin:H.createID(p.id.client,p.id.clock+d-1),y=S?U(S.client,S.clock):"",w=p.id.client!==r||!S?void 0:f.has(y)?S:u.get(y);if(!w){g=null;continue}if(u.set(U(m.client,m.clock),w),o?.(m))continue;(!g||!H.compareIDs(g.anchor,w))&&(g={anchor:w,ids:[],written:[],text:"",marks:[]},a.push(g)),g.ids.push(m);let x=Ze(i,m);x&&n(m)||(x&&g.marks.push([g.text.length,x]),g.written.push(m),g.text+=h[d])}}for(let p of a){let h=n(p.anchor),d=h?Gt(h.copy.text,h.id):-1;if(!h||d<0||(Ke(l,new Set(p.ids.map(y=>U(y.client,y.clock)))),p.text.length===0))continue;let m=H.getState(i.store,r);h.copy.text.insert(d+1,p.text);let S=t.nodes.get(h.copy.key);S instanceof H.Map&&Uo(S,r,m,p.written),wt(i,p.marks.flatMap(([y,w])=>[m+y,w.client,w.clock,1])),s(p.ids[0],H.createID(r,m),p.text.length)}}function Bs(t,e,o){if(o.size===0)return;let n=t.doc,s=new Map,i=0;for(let r of e){let c=t.nodes.get(r),l=c instanceof H.Map?c.get(A.text):void 0;if(!(l instanceof H.Text))continue;let f=[];for(let u of Ft(c))if(!(u.client===n.clientID||(i+=u.length)>Gs))for(let a=0;a<u.length;a+=1){let g=H.createID(u.client,u.clock+a),p=ue(n,u.source(a),s,!1);o.has(U(p.client,p.clock))&&!Wt(n,g)&&f.push(g)}f.length>0&&Ke(l,new Set(f.map(u=>U(u.client,u.clock))))}}function Di({room:t,me:e,incoming:o,all:n,placed:s,share:i,laterStart:r,step:c}){for(let l of n){if(l.copy.client!==e||!l.copy.newParagraph)continue;let f=s.get(l.key)?.p,u=f?Vt(t,f.parent):void 0;if(!f||!u)continue;let a=u.toArray();if(!c(a.length))return;let g=new Map(a.map((d,m)=>[d,m])),p=g.get(f.key)??-1;if(p<0)continue;let h;for(let d of o){if(!c())return;if(d.key===l.key||r(l,d)<=0)continue;let m=s.get(d.key)?.p;if(!m||m.parent!==f.parent||m.key===f.key)continue;let S=g.get(m.key)??-1;S<=p||h&&S<=h.at||!i(d,l)||(h={key:m.key,at:S})}h&&(u.delete(p,1),u.insert(u.toArray().indexOf(h.key)+1,[f.key]))}}import*as Us from"yjs";var Li=new Set([A.part,A.key,A.shell,oe.copyOf,oe.newParagraph]);function Hs(t){return e=>{let o=e.parent;if(o===t)return!1;let n=Ie(o);return n===null||n.parent!==t?!0:e.content instanceof Us.ContentType?!1:!(e.parentSub!==null&&Li.has(e.parentSub)&&us(e))}}import*as be from"yjs";var Cn="followed",qs=65536,Vs=t=>{let e=be.createDeleteSet();return e.clients.set(t.client,[{clock:t.clock,len:1}]),e},Dn=t=>{let e=t.meta.get(Cn);return e instanceof Map?e:void 0};function Js(t,e){for(let o of e)for(let n of t){if(!be.isDeleted(n.insertions,o.anchor))continue;n.insertions=be.mergeDeleteSets([n.insertions,Vs(o.added)]),n.deletions=be.mergeDeleteSets([n.deletions,Vs(o.gone)]);let s=Dn(n);s||n.meta.set(Cn,s=new Map),s.set(o.run,{from:o.from,to:o.to})}}function Qs(t,e){let o=Dn(t);o&&e.meta.set(Cn,new Map(o))}var _i=(t,e)=>{let o=0;for(let n=t._start;n!==null;n=n.right)if((o+=1)>qs||!n.deleted&&n.countable&&n.content.getContent().includes(e))return!0;return!1};function Fi(t,e){let o=[],n=0;for(let s=t._start;s!==null&&n<qs;s=s.right){if(n+=1,!s.deleted||!s.countable)continue;let i=s.content.getContent();for(let r=0;r<i.length;r+=1)i[r]===e&&o.push(be.createID(s.id.client,s.id.clock+r))}return o}function zi(t,e){if(e.length===0)return t;let o=be.createDeleteSet();for(let[n,s]of t.clients){let i=e.filter(c=>c.client===n).map(c=>c.clock),r=[];for(let{clock:c,len:l}of s){let f=c;for(let u of i.filter(a=>a>=c&&a<c+l).sort((a,g)=>a-g))u>f&&r.push({clock:f,len:u-f}),f=u+1;f<c+l&&r.push({clock:f,len:c+l-f})}r.length>0&&o.clients.set(n,r)}return o}function Ln(t){let e=Dn(t),o=new Set;if(!e)return o;for(let[n,{from:s,to:i}]of e){if(_i(i,n)){o.add(n);continue}t.deletions=zi(t.deletions,Fi(s,n)),e.delete(n)}return o}import*as re from"yjs";var ji=4096,Wi=4096,Ki=32;function $i(t,e,o,n,s=new Set){let i=t.doc,r=new Map,c=0;for(let[l,f]of i.getMap(je).entries()){if(typeof f!="string"||!e.has(f)||!o(f,l))continue;if((c+=1)>ji)return null;let u=t.nodes.get(l),a=u instanceof re.Map?u.get(A.text):void 0;if(!(!Oe(u)||!(a instanceof re.Text))){for(let g=a._start;g!==null;g=g.right)if(!(g.deleted||!g.countable))for(let p=0;p<g.length;p+=1){let h=U(g.id.client,g.id.clock+p);if(s.has(h))continue;let d=ue(i,re.createID(g.id.client,g.id.clock+p),n),m=U(d.client,d.clock);m!==h&&!r.has(m)&&r.set(m,{text:a,item:g,j:p})}}}return r}function Ge(t,e){let o=e.parent;if(!(o instanceof re.Map)||Ie(o)?.parent!==t.nodes)return null;let n=o.get(A.part);return typeof n=="string"?n:null}function Zs(t,e){let o=t.content.getContent();return o.length>0&&typeof o[0]=="string"?String(o.join("")).charAt(e):""}var Gi=t=>re.createID(t.item.id.client,t.item.id.clock+t.j);function er(t,e,o){let n=t.doc,s=[],i=new Map,r=!1;return ge(n,e,c=>{if(r||!c.countable||!(c.parent instanceof re.Text)||c.redone===null)return;let l=c.parent,f=ye(n,c.redone);if(!Ge(t,l)||!f||f.deleted||f.parent!==l)return;let u=Math.min(c.length,f.length);for(let a=0;a<u;a+=1){if(s.length>=We){r=!0;return}let g=ue(n,re.createID(c.id.client,c.id.clock+a),i);s.push({text:l,item:f,j:a,root:g,char:Zs(f,a)})}}),!r&&tr(t,s,o,i,()=>!0)}function tr(t,e,o,n,s){let i=t.doc;if(e.length===0)return!1;let r=new Set;for(let d of e)r.add(Ge(t,d.text));let c=d=>U(d.item.id.client,d.item.id.clock+d.j),l=new Set(e.map(c)),f=$i(t,r,o,n,l);if(!f||f.size===0)return!1;let u=d=>{let m=0,S=d.item,y=d.j-1;for(;S!==null&&m<Wi;){for(;y>=0&&S.countable;y-=1,m+=1){let w=re.createID(S.id.client,S.id.clock+y);if(l.has(U(w.client,w.clock)))continue;let x=ue(i,w,n),k=f.get(U(x.client,x.clock));if(k&&k.text!==d.text)return k;if(!S.deleted)return null}S=S.left,y=S?S.length-1:-1}return null},a=[],g=[];for(let d of e){let m=f.get(U(d.root.client,d.root.clock));if(m&&m.text!==d.text){a.push(d);continue}let S=s(d)?u(d):null;if(!S)continue;let y=g[g.length-1];y&&y.to.item===S.item&&y.to.j===S.j?y.chars.push(d):g.push({to:S,chars:[d]})}if(a.length===0&&g.length===0)return!1;let p=[];for(let{to:d,chars:m}of g){let S=Gt(d.text,Gi(d));if(S<0)continue;let y=m.map(x=>x.char).join("");if(y.length===0)continue;let w=re.getState(i.store,i.clientID);d.text.insert(S+1,y),m.forEach((x,k)=>p.push(w+k,x.root.client,x.root.clock,1)),a.push(...m)}wt(i,p);let h=new Map;for(let d of a){let m=h.get(d.text);m?m.add(c(d)):h.set(d.text,new Set([c(d)]))}for(let[d,m]of h)Ke(d,m);return!0}function _n(t,e){let o=t.doc,n=[],s=new Set,i=new Set,r=new Map,c=0;return ge(o,e,l=>{if(!l.countable||!(l.parent instanceof re.Text)||l.redone===null)return;let f=l.parent,u=l.redone;if(u.client!==o.clientID||Ge(t,f)===null)return;let a=ye(o,u);if(!(!a||a.parent!==f)){i.add(f);for(let g=0;g<l.length;g+=1){if((c+=1)>We)return;let p=re.createID(l.id.client,l.id.clock+g);for(let y=0;y<Ki;y+=1){let w=Ze(o,p);if(!w)break;p=w}let h=ue(o,p,r,!1);s.add(U(h.client,h.clock));let d=u.clock+g,m=n.length;m>0&&n[m-4]+n[m-1]===d&&n[m-3]===p.client&&n[m-2]+n[m-1]===p.clock?n[m-1]+=1:n.push(d,p.client,p.clock,1)}}}),wt(o,n),{roots:s,texts:i}}function Fn(t,e){let o=t.doc,n=o.getMap(Ae),s=new Set;for(let i of e){let r=i===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(i),c=i===null?void 0:n.get(i);if(!r||!Array.isArray(c))continue;let l=Math.min(Number(c[2])||0,We),f=Number(r[1]);for(let u=Number(r[2]),a=u+l;u<a;){let g=ye(o,re.createID(f,u));if(!g)break;if(!g.deleted&&g.parent instanceof re.Text&&Ge(t,g.parent)){s.add(g.parent);break}u=g.id.clock+g.length}}return s}function zn(t,e){let o=new Set,n=[...t.doc.getMap(Ae).keys()].sort().slice(0,We);for(let s of n)for(let i of Fn(t,[s])){let r=Ge(t,i);r!==null&&e.has(r)&&o.add(i)}return o}function Xi(t,e){let o=Ie(e.parent);return o&&o.parent===t.nodes&&typeof o.parentSub=="string"?o.parentSub:null}var Bi=(t,e)=>t.client<e.client||t.client===e.client&&t.clock>e.clock;function jn(t,e,o){let n=t.doc,s=new Map,i=[...e],r=new Set;for(let d of i){let m=Ge(t,d);m!==null&&r.add(m)}if(r.size===0)return!1;let c=new Set(zn(t,r));for(let d of i)c.add(d);let l=new Map,f=new Map,u=(d,m)=>{let S=f.get(d);S?S.add(U(m.client,m.clock)):f.set(d,new Set([U(m.client,m.clock)]))},a=0;for(let d of c){let m=Ge(t,d),S=Xi(t,d);if(m===null||S===null)continue;let y=o(m,S)?"":`${S}\0`;for(let w=d._start;w!==null&&a<We;w=w.right)if(!(w.deleted||!w.countable))for(let x=0;x<w.length;x+=1,a+=1){let k=re.createID(w.id.client,w.id.clock+x);if(!Ze(n,k))continue;let b=ue(n,k,s),v=y+U(b.client,b.clock),M=l.get(v);M?Bi(k,M.id)?(u(M.text,M.id),l.set(v,{id:k,text:d})):u(d,k):l.set(v,{id:k,text:d})}}for(let[d,m]of f)Ke(d,m);let g=[];for(let{id:d,text:m}of l.values()){let S=ye(n,d);if(!S||S.deleted||S.parent!==m)continue;let y=d.clock-S.id.clock;g.push({text:m,item:S,j:y,root:ue(n,d,s),char:Zs(S,y)})}let p=n.clientID;return tr(t,g,o,s,d=>d.item.id.client===p)||f.size>0}import*as ie from"yjs";function nr(t,e,o){let n=s=>{let i=t.nodes.get(s),r=i instanceof ie.Map?i.get(A.children):void 0;return r instanceof ie.Array?r.toArray():[]};for(let s of n(e))if(!(typeof s!="string"||t.nodes.get(s)?.get?.(A.shell)?.local!=="t"))for(let r of n(s)){let c=typeof r=="string"?t.nodes.get(r):void 0,l=c instanceof ie.Map?c.get(A.text):void 0;l instanceof ie.Text&&o.add(l)}}var et=(t,e)=>Ie(e)?.parent===t.nodes&&e instanceof ie.Map?e:null;function or(t,e){let o=t.doc.clientID.toString(36),n=Je(t),s=new Set,i=new Map,r=l=>{if(typeof l!="string")return new Set;let f=i.get(l);if(!f){let u=Ue(t.parts.get(l));f=u?.kind==="xml"?ht(t,l,u.root).unseenWinners:new Set,i.set(l,f)}return f};if(ge(t.doc,e.insertions,l=>{if(l.parent!==t.nodes||l.deleted||!(l.content instanceof ie.ContentType))return;let f=l.content.type,u=Fe(f),a=u?n(u.group):void 0;!u||a===void 0||a===o||r(f.get(A.part)).has(u.group)||s.add(u.from)}),s.size===0)return e.deletions;let c=new Set;for(let l of s)nr(t,l,c);return c.size===0?e.deletions:$t(t.doc,e.deletions,l=>c.has(l.parent))}function sr(t,e){let o=new Map;if(ge(t.doc,e.insertions,a=>{let g=a.parent;!(g instanceof ie.Text)||!a.countable||et(t,g.parent)&&o.set(g,(o.get(g)??!1)||a.deleted)}),![...o.values()].some(Boolean))return e;let n=new Map,s=new Set;if(ge(t.doc,e.deletions,a=>{let g=et(t,a.parent);if(!g||a.parentSub!==K.splitFrom||!(a.content instanceof ie.ContentAny))return;let p=a.content.getContent()[0];if(typeof p!="string")return;let h=new Set;nr(t,p,h);let d=[...h].filter(S=>o.get(S)===!0);if(d.length===0)return;for(let S of d)s.add(S);let m=g.get(A.key);typeof m=="string"&&n.set(g,m)}),n.size===0)return e;let i=new Map;ge(t.doc,e.deletions,a=>{let g=a.parent,h=(g instanceof ie.Array?et(t,g.parent):null)?.get(A.key);if(typeof h!="string"||!(a.content instanceof ie.ContentAny))return;let d=i.get(h);d||i.set(h,d=[]);for(let m of a.content.getContent())typeof m=="string"&&d.push(m)});let r=new Set(n.values()),c=new Set,l=[...r];for(;l.length>0;){let a=l.pop(),g=t.nodes.get(a);if(!(c.has(g)||!(g instanceof ie.Map))){c.add(g);for(let p of i.get(a)??[])l.push(p)}}let f=a=>et(t,a.parent)??et(t,a.parent?.parent),u=a=>a.parent instanceof ie.Array&&et(t,a.parent.parent)!==null&&a.content instanceof ie.ContentAny&&a.content.getContent().some(g=>typeof g=="string"&&r.has(g));return{insertions:$t(t.doc,e.insertions,a=>s.has(a.parent)),deletions:$t(t.doc,e.deletions,a=>c.has(f(a))||u(a))}}import*as ar from"yjs";import{CONTENT_TYPES_PART as qt,asciiFold as Xe,NS as ae,attr as Se,children as Qt,materialize as Ui,relationshipsOf as xt,relsPartName as Jt,specOf as Hi}from"@pptx-editor.dev/core/store";var Kn=Symbol("absent");function lr(t,e,o){let n=Vi(o);for(let s of t){let i=s.target;if(!(i instanceof ar.Map)||!e(i))continue;let r=n.get(i);r||n.set(i,r=new Map);for(let[c,l]of s.changes.keys){let f=i.get(c),u=r.get(c);if(u)u[3]=f;else{let a=[i,c,l.action==="add"?Kn:l.oldValue,f];o.push(a),r.set(c,a)}}}}var rr=new WeakMap;function Vi(t){let e=rr.get(t);if(e)return e;e=new Map;for(let o of t){let n=e.get(o[0]);n||e.set(o[0],n=new Map),n.has(o[1])||n.set(o[1],o)}return rr.set(t,e),e}var dr=t=>t._item?.deleted!==!0;function fr(t){return t.filter(([e,o,n])=>n!==Kn&&dr(e)&&!e.has(o)).map(([e,o,n])=>[e,o,n])}function $n(t){let e=(o,n)=>JSON.stringify(o)===JSON.stringify(n);return t.filter(([o,n,s,i])=>dr(o)&&i!==void 0&&s!==Kn&&e(o.get(n),s)&&!e(s,i)).map(([o,n,,s])=>[o,n,s])}function qi(t){let e=new Set,o=[t];for(;o.length>0;){let n=o.pop();if(!(n.type!=="element"||ur(n))){for(let s of n.attrs)s.ns===ae.r&&e.add(s.value);for(let s of n.children)o.push(s)}}return e}function ir(t,e){let o={next:t.nextId},n=e.map(s=>Ui(Hi(s),t.root.kind,o));return{partName:t.partName,root:{...t.root,children:[...t.root.children,...n]},nextId:o.next}}var ur=t=>t.ns===ae.p&&t.local==="sldId";function Ji(t,e){for(let o of t.parts.values()){if(o.kind!=="xml")continue;let n=o.xml.root;if(n.ns!==ae.p||n.local!=="presentation")continue;let s=n.children.find(y=>y.type==="element"&&y.ns===ae.p&&y.local==="sldIdLst");if(!s)return;let i=[],r=new Set;for(let y of s.children){if(y.type!=="element"||!ur(y))continue;let w=y.attrs.find(x=>x.ns===ae.r&&x.local==="id")?.value;w===void 0||!e.has(w)?r.add(y):i.push(Se(y,"id")??"")}let c=[],l=y=>{for(let w of y.children)w.type==="element"&&(w.ns===ae.p14&&w.local==="section"?c.push(w):l(w))};l(n);let f=new Map(c.map((y,w)=>[y,w])),u=new Map;c.forEach((y,w)=>{let x=y.children.find(k=>k.type==="element"&&k.ns===ae.p14&&k.local==="sldIdLst");if(x)for(let k of Qt(x,{ns:ae.p14,local:"sldId"})){let b=Se(k,"id")??"",v=u.get(b);v?v[v.length-1]!==w&&v.push(w):u.set(b,[w])}});let a=new Map,g=0;for(let y of i){let w=u.get(y);if(!w)continue;let x=w.find(k=>k>=g)??w[0];a.set(y,x),g=Math.max(g,x)}let p=new Map(i.map((y,w)=>[y,w])),h=r.size>0,d=(y,w)=>{let x=y.children.map(k=>{if(k.type!=="element"||k.ns!==ae.p14||k.local!=="sldIdLst")return k;let b=new Set,M=[...k.children.filter(C=>{if(C.type!=="element"||C.ns!==ae.p14||C.local!=="sldId")return!0;let T=Se(C,"id")??"";return a.get(T)!==w||b.has(T)?!1:(b.add(T),!0)})].sort((C,T)=>{let R=C.type==="element"?p.get(Se(C,"id")??"")??0:0,j=T.type==="element"?p.get(Se(T,"id")??"")??0:0;return R-j});return M.length===k.children.length&&M.every((C,T)=>C===k.children[T])?k:(h=!0,{...k,children:M})});return x.every((k,b)=>k===y.children[b])?y:{...y,children:x}},m=y=>{let w=y.children.filter(k=>k.type!=="element"||!r.has(k)).map(k=>{if(k.type!=="element")return k;let b=f.get(k)??-1;return b>=0?d(k,b):m(k)});return w.length===y.children.length&&w.every((k,b)=>k===y.children[b])?y:{...y,children:w}},S=m(n);return h?{...o.xml,root:S}:void 0}}var Qi=new Set(["hlinkClick","hlinkHover","hlinkMouseOver"]),Wn=t=>t.endsWith("/relationships/slide");function cr(t,e){let o=!1,n=i=>{let r=!1,c=[];for(let l of i.children){if(l.type!=="element"){c.push(l);continue}let f=l.attrs.some(a=>a.ns===ae.r&&a.value===e);if(f&&l.ns===ae.a&&Qi.has(l.local)){r=!0;continue}f&&(o=!0);let u=n(l);u!==l&&(r=!0),c.push(u)}return r?{...i,children:c}:i},s=n(t);return o?void 0:s}function Zi(t,e){return{...t,root:{...t.root,children:t.root.children.filter(o=>o.type!=="element"||o.local!=="Relationship"||Se(o,"Id")!==e)}}}var tt=(t,e)=>{let o=t.parts.get(e);return o?.kind==="xml"?o.xml:void 0};function Gn(t,e){let o=new Map,n=new Set;for(let a of e.parts.keys())n.add(Xe(a));let s=a=>e.parts.has(a)||n.has(Xe(a)),i=[],r=new Set,c=a=>{!a||r.has(a.partName)||(r.add(a.partName),i.push(a))},l=!1;for(let a of t.parts.keys())e.parts.has(a)||(l=!0);for(let[a,g]of e.parts){if(g.kind!=="xml")continue;let p=Jt(a);if(!l&&t.parts.get(a)===g&&t.parts.get(p)===e.parts.get(p))continue;let h=k=>{let b=cr((o.get(a)??g.xml).root,k);if(!b)return!1;o.set(a,{...o.get(a)??g.xml,root:b});let v=o.get(p)??tt(e,p);return v&&o.set(p,Zi(v,k)),!0};for(let k of xt(e,a))!k.external&&k.target&&!s(k.target)&&Wn(k.type)&&h(k.id);let d=qi((o.get(a)??g.xml).root);if(d.size===0)continue;for(let k of xt(e,a))!d.has(k.id)||k.external||!k.target||s(k.target)||Wn(k.type)||c(t.parts.get(k.target));let m=new Set(xt(e,a).map(k=>k.id)),S=tt(t,p);if(!S)continue;let y=Qt(S.root,{ns:ae.rel,local:"Relationship"}).filter(k=>{let b=Se(k,"Id");return b!==void 0&&d.has(b)&&!m.has(b)});for(let k of xt(t,a)){let b=y.findIndex(M=>Se(M,"Id")===k.id);if(b<0||k.external||!k.target||s(k.target)||!Wn(k.type))continue;let v=cr((o.get(a)??g.xml).root,k.id);v&&(o.set(a,{...o.get(a)??g.xml,root:v}),y.splice(b,1))}if(y.length===0)continue;let w=o.get(p)??tt(e,p)??{partName:p,root:{...S.root,children:[]},nextId:S.nextId};o.set(p,ir(w,y));let x=new Set(y.map(k=>Se(k,"Id")));for(let k of xt(t,a))!x.has(k.id)||k.external||!k.target||s(k.target)||c(t.parts.get(k.target))}{let a=[...e.parts.values()].find(d=>d.kind==="xml"&&d.xml.root.ns===ae.p&&d.xml.root.local==="presentation"),g=a&&(o.get(Jt(a.partName))??tt(e,Jt(a.partName))),p=a&&Jt(a.partName),h=a&&(t.parts.get(a.partName)!==a||t.parts.get(p)!==e.parts.get(p)||o.has(p));if(g&&h&&p&&e.parts.has(p)){let d=new Set(Qt(g.root,{ns:ae.rel,local:"Relationship"}).map(S=>Se(S,"Id")??"")),m=Ji(e,d);m&&o.set(m.partName,m)}}let f=tt(e,qt),u=tt(t,qt);if(f&&u){let a=(y,w,x)=>{let k=new Map;for(let b of Qt(y,{ns:ae.ct,local:w})){let v=Se(b,x);v!==void 0&&!k.has(Xe(v))&&k.set(Xe(v),b)}return k},g=a(f.root,"Override","PartName"),p=a(f.root,"Default","Extension"),h=a(u.root,"Override","PartName"),d=a(u.root,"Default","Extension"),m=new Set,S=new Set(e.parts.keys());for(let y of i)S.add(y.partName);for(let y of S){if(y===qt)continue;let w=Xe(y.slice(y.lastIndexOf(".")+1));if(g.has(Xe(y))||p.has(w))continue;let x=h.get(Xe(y))??d.get(w);x&&m.add(x)}m.size>0&&o.set(qt,ir(f,[...m]))}return[...[...o.values()].map(a=>({kind:"xml",partName:a.partName,xml:a})),...i]}var pr=0;function Xn(t,...e){for(let o of[...t])try{o(...e)}catch(n){console.warn("[pptx-editor] collaboration listener failed",n)}}function tc(t){let{doc:e,documentId:o,identity:n,awareness:s}=t;if(typeof o!="string"||o.trim()===""||o.length>256)throw new Be("invalid-document-id");let i=Ls(n);if(i)throw new Be(i);let r=Zn(e),c=ec("initializing"),l=new Set,f=new Set,u=new Set,a=null,g=null,p={value:0},h=null,d=null,m=null,S=!1,y=!0,w=[{...n,isLocal:!0}],x=[],k=null,b=null,v=null,M=!1;pr+=1;let C=`${e.clientID.toString(36)}-${pr}`,T=(N,z,W,O=!1)=>{if(!c.set(N,z,W,O))return;let E=c.snapshot().reason;Xn(l,N,E?.code,E?.detail)},R=()=>y?T("ready"):T("disconnected","transport-disconnected"),j=N=>{s&&!S&&s.setLocalStateField(Ut,js(n,N))},F=()=>{if(!s)return;let N=Ws(s);JSON.stringify(N)!==JSON.stringify(w)&&(w=N,Xn(f,w));let z=g?Ks(s,e,g):[];JSON.stringify(z)!==JSON.stringify(x)&&(x=z,Xn(u,x))};j(void 0),s?.on("change",F),F();let P=(N,z,W,O=!0)=>{let E=z?N.redoStack:N.undoStack,L=E.length;z?N.undoing=!0:N.redoing=!0;try{e.transact(W,nn)}finally{N.undoing=!1,N.redoing=!1}if(E.length!==L+1)return!1;let $=E[E.length-2];if(!O||!$)return!0;let Q=E.pop();return $.deletions=ke.mergeDeleteSets([$.deletions,Q.deletions]),$.insertions=ke.mergeDeleteSets([$.insertions,Q.insertions]),!0},D=(N,z,W)=>z.length>0&&P(N,!1,()=>{for(let[O,E,L]of z)O.set(E,L)},W),I=(N,z)=>{let W=z?N?.undoStack:N?.redoStack;if(!N||!W||W.length===0)return!1;M=!1;let O=d?.package(),E=W[W.length-1];if(z){for(let X of W.slice(0,-1))Ln(X);ms(r,E,X=>e.transact(X,rt),Ln(E)),E.deletions=or(r,E)}else{let X=sr(r,E);E.insertions=X.insertions,E.deletions=X.deletions}let L=[...W];m=null,z?N.undo():N.redo(),!z&&m===E&&ks(r,E,X=>e.transact(X,rt));let $=m,Q=new Set(W),he=L.reverse().filter(X=>!Q.has(X)&&X!==$),nt=X=>X.meta.get("attrs")??[],ot=!1,ve=!1,Re=null;if(z&&$&&$!==E)m=null,N.redo(),Re=m,ve=!0;else if(!z&&$===E)ot=D(N,$n(nt(E)),!0);else if(!z){$&&(m=null,N.undo(),Re=m);for(let X of he.slice(1).reverse())N.redoStack.push(X);ot=D(N,$n(nt(E)),!1)}if(Re){let X=Re;e.transact(()=>_n(r,X.deletions),rt)}let G=$&&!ve&&(z||$===E)?$:null;if(G&&g){let X=g,se=G,ee=(ce,Ye)=>X.idOf(ce,Ye)!==void 0,le=new Set;P(N,z,()=>{let ce=_n(r,se.deletions);le=ce.roots,z&&ws(r,se,ee),er(r,se.deletions,ee),jn(r,ce.texts,ee)}),X.forgetDeleted(le)}let q=d?.package(),Z=z&&$&&!ve?fr(nt($)):[],te=O&&q&&!ve?Gn(O,q):[];if((Z.length>0||te.length>0)&&q&&g){let X=g;e.transact(()=>{for(let[ee,le,ce]of Z)ee.set(le,ce);if(te.length===0)return;let se=new Map(q.parts);for(let ee of te)se.set(ee.partName,ee);X.writeChange(q,{parts:se},te.map(ee=>ee.partName))},tn)}return!M&&(z?$!==null&&!ve:$===E||ot)};return{documentId:o,sessionId:C,identity:n,get attached(){return a!==null},status:()=>c.status(),statusSnapshot:()=>c.snapshot(),subscribeStatus(N){return l.add(N),()=>l.delete(N)},setConnected(N){if(S||N===y)return;y=N;let z=c.snapshot();(z.status==="ready"||z.status==="disconnected")&&R()},participants:()=>w,subscribeParticipants(N){return f.add(N),()=>f.delete(N)},remoteSelections:()=>x,subscribeRemoteSelections(N){return u.add(N),()=>u.delete(N)},setLocalSelection(N){let z=N&&g?zs(N,g):void 0;k=N&&z?{selection:N,encoded:z}:null,j(z)},remoteSelectionMove:()=>b,historySelection:()=>v&&g?Ht(v,e,g):null,canUndo:()=>h?h.undoStack.length>0:!1,canRedo:()=>h?h.redoStack.length>0:!1,undo:()=>I(h,!0),redo:()=>I(h,!1),attach(N){if(S)return()=>{};a?.(),T("initializing");let z=r.meta.get("schema");if(z!==void 0&&z!==bt)return T("error","schema-version-mismatch",`room schema ${String(z)}`),()=>{};let W=new Bt(r,p);d=N,g=W;let O=(G,q,Z=!1)=>{let te=N.package(),X=W.rebuild(G,te,q);if(!X.ok)return M=!0,T("error","remote-apply-failed",X.reason,!0);let se=k?Ht(k.encoded,e,W):null;if(b=k&&se&&JSON.stringify(se)!==JSON.stringify(k.selection)?{from:k.selection,to:se}:null,b&&k&&(k={selection:b.to,encoded:k.encoded}),X.parts.length>0||X.removed.length>0){let le=N.applyRemoteParts(X.parts,X.removed,"collaboration");if(b=null,!le.ok){M=!0;let ce=le.rejection.code;return ce==="unsafe-part-name"?T("error","unsafe-part-name",ce):T("error","remote-apply-failed",ce,!0)}}b=null,Z&&he(te,N.package());let ee=c.snapshot();ee.status==="error"&&ee.recovering&&R(),F()};W.seeded?O(W.allParts(N.package()),!0):e.transact(()=>{r.meta.set("schema",bt),r.meta.set("documentId",o),W.seed(N.package())},rn);let E=new ke.UndoManager([r.parts,r.binaries,r.nodes],{trackedOrigins:new Set([Yt,nn]),captureTimeout:Number.POSITIVE_INFINITY,deleteFilter:Hs(r.nodes)}),L=G=>{let q=G.parent;return q instanceof ke.Map&&q.get(A.attrs)===G},$=G=>{let q=E.currStackItem;if((E.undoing||E.redoing)&&q){G.stackItem.meta.set("attrs",q.meta.get("attrs")??[]),Qs(q,G.stackItem);return}let Z=G.stackItem.meta.get("attrs")??[],te=new Set;for(let X of G.changedParentTypes?.values()??[])for(let se of X)te.add(se);lr(te,L,Z),G.stackItem.meta.set("attrs",Z)};E.on("stack-item-added",G=>{k&&G.stackItem.meta.set("selection",k.encoded),$(G)}),E.on("stack-item-updated",$),E.on("stack-item-popped",G=>{v=G.stackItem.meta.get("selection")??null,m=G.stackItem}),h=E;let Q=N.subscribeLocal(G=>{G.merged||E.stopCapturing(),W.hasHiddenListings(G.parts)&&e.transact(()=>W.dropHiddenListings(G.parts,G.before,G.after),sn),e.transact(()=>W.writeChange(G.before,G.after,G.parts),Yt);let q=W.showingUnlisted(G.parts);q.length>0&&O(q,!1),F()}),he=(G,q)=>{let Z=Gn(G,q);if(Z.length===0)return;let te=new Map(q.parts);for(let X of Z)te.set(X.partName,X);e.transact(()=>W.writeChange(q,{parts:te},Z.map(X=>X.partName)),tn)},nt=(G,q)=>{let Z=W.deletedText,te=Z.size>0?Ho(r,G):new Set;if(q.size===0&&te.size===0)return;let X={keyOf:W.keyOf.bind(W),package:N.package()},se=[],ee=[];e.transact(()=>{for(let[le,ce]of q)Xs(r,le,ce,Z,X,(Ye,st,Mt)=>se.push([Ye,st,Mt]),Ye=>ee.push(Ye));Bs(r,te,Z)},on),Js([...E.undoStack,...E.redoStack],ee);for(let[le,ce,Ye]of se)for(let st of[...E.undoStack,...E.redoStack]){if(!ke.isDeleted(st.insertions,le))continue;let Mt=ke.createDeleteSet();Mt.clients.set(ce.client,[{clock:ce.clock,len:Ye}]),st.insertions=ke.mergeDeleteSets([st.insertions,Mt])}},ot=e.getMap(Ae),ve=G=>{let q=r.meta.get("schema");if(q!==bt&&G.changed.has(r.meta)){Re(),T("error","schema-version-mismatch",`room schema ${String(q)}`);return}let Z=G.origin;if(Z===Yt||Z===rn||Z===rt||Z===sn)return;let te=W.touchedParts(G);if(te.size>0&&O(te,!1,!G.local),G.local)return;let X=W.newCopies(G);nt(G,X);let se=G.changed.get(ot),ee=se?Fn(r,se):new Set;if(X.size>0&&r.doc.getMap(Ae).size>0)for(let le of zn(r,new Set(X.keys())))ee.add(le);if(ee.size>0){let le=(ce,Ye)=>W.idOf(ce,Ye)!==void 0;e.transact(()=>jn(r,ee,le),on)}};e.on("afterTransaction",ve),c.status()==="initializing"&&R(),F();let Re=()=>{Q(),e.off("afterTransaction",ve),E.destroy(),h===E&&(h=null),g===W&&(g=null),d===N&&(d=null),k=null,v=null,j(void 0),F(),a===Re&&(a=null)};return a=Re,Re},destroy(){S||(a?.(),s?.off("change",F),s?.setLocalStateField(Ut,null),S=!0,T("destroyed","collaboration-session-destroyed"),l.clear(),f.clear(),u.clear())}}}export{Be as CollaborationSchemaError,Yr as collaborationModule,tc as createYjsCollaborationSession,Rr as legacyComments,gr as reviewModule};
6
+ import{a as ms}from"./chunk-B3UUTQS4.js";import{a as Un}from"./chunk-HCD7IVOL.js";import{attr as De,binaryPartOf as ys,elements as tn,parseXmlPart as ks,mainPresentationPart as ws,presentationInfo as Ss,relTargetByType as qn,textOf as xs,xmlPartOf as Ms}from"@pptx-editor.dev/core/store";var Jn="http://schemas.openxmlformats.org/officeDocument/2006/relationships",bs=`${Jn}/comments`,Rs=`${Jn}/commentAuthors`;function Qn(t,e){let o=Ms(t,e);if(o||!e)return o;let n=ys(t,e);if(!n)return;let r=ks(e,new TextDecoder().decode(n));return r.ok?r.part:void 0}function Ys(t){let e=Object.create(null),o=ws(t);if(!o)return e;let n=Qn(t,qn(t,o,Rs));for(let r of tn(n?.root)){if(r.local!=="cmAuthor")continue;let i=De(r,"id"),s=De(r,"name");i!==void 0&&s!==void 0&&(e[i]=s)}return e}function en(t,e){for(let o of tn(t)){if(o.local===e)return o;let n=en(o,e);if(n)return n}}var Hn=t=>encodeURIComponent(t).replace(/-/g,"%2D"),Vn=(t,e,o)=>`${t}#cm-${Hn(e)}-${Hn(o)}`;function Es(t){let e=Ys(t),o=[];for(let n of Ss(t).slides){let r=Qn(t,qn(t,n.partName,bs));for(let i of tn(r?.root)){if(i.local!=="cm")continue;let s=De(i,"authorId")??"",c=De(i,"idx")??"",l=en(i,"parentCm"),f=e[s],u=De(i,"dt");o.push({id:Vn(n.partName,s,c),kind:"comment",slidePart:n.partName,text:xs(en(i,"text")),...f!==void 0?{author:f}:{},...u!==void 0?{date:u}:{},...l?{parentId:Vn(n.partName,De(l,"authorId")??"",De(l,"idx")??"")}:{}})}}return o}function Is(t){return Un(t.licenseKey),{id:"collaboration",collaboration:{session:t.session}}}import*as ke from"yjs";import{createCollaborationStatusTracker as tc}from"@pptx-editor.dev/core/editor";var we=class extends Error{constructor(o,n){let r=n?`${o}: ${n}`:o;super(o==="schema-version-mismatch"?`${r}
7
+ Collaboration upgrade required. Save local changes and use a compatible app version.`:r);this.code=o;this.detail=n;this.name="CollaborationSchemaError"}code;detail};import*as B from"yjs";import{buildReplicaPart as xi}from"@pptx-editor.dev/core/store";import"yjs";var Ue=7,Rt="pptx-meta-v1",vs="pptx-parts-v1",Ps="pptx-binaries-v1",Os="pptx-nodes-v1",A=Object.freeze({part:"p",key:"k",shell:"s",attrs:"a",children:"c",text:"x"}),Yt="",Zn=2**40,Et=Object.freeze({kind:"pptx-local"}),nn=Object.freeze({kind:"pptx-undo-repair"}),on=Object.freeze({kind:"pptx-redo-repair"}),rn=Object.freeze({kind:"pptx-text-repair"}),sn=Object.freeze({kind:"pptx-tidy"}),it=Object.freeze({kind:"pptx-undone-listing"}),cn=Object.freeze({kind:"pptx-seed"}),ct=Object.freeze({maxBinaryBytes:256*1024*1024,maxReadDepth:300,maxCopiesPerGroup:256});function eo(t){return{doc:t,meta:t.getMap(Rt),parts:t.getMap(vs),binaries:t.getMap(Ps),nodes:t.getMap(Os)}}function He(t){if(typeof t!="object"||t===null)return null;let e=t;return e.kind==="binary"?{kind:"binary"}:e.kind==="xml"&&typeof e.root=="string"?{kind:"xml",root:e.root}:null}import{asciiFold as As}from"@pptx-editor.dev/core/store";var ln="http://schemas.openxmlformats.org/drawingml/2006/main",so="http://schemas.openxmlformats.org/presentationml/2006/main",Y=t=>[t,[t]],ne=(t,e)=>[t,e],lt=["*",[]],dt=ne("fill",["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),Ns=ne("fill",["noFill","solidFill","gradFill","pattFill"]),vt=ne("effect",["effectLst","effectDag"]),Ts=[ne("color",["scrgbClr","srgbClr","hslClr","sysClr","schemeClr","prstClr"])],to=[Y("xfrm"),ne("geometry",["custGeom","prstGeom"]),dt,Y("ln"),vt,Y("scene3d"),Y("sp3d"),Y("extLst")],no=[Ns,ne("dash",["prstDash","custDash"]),ne("join",["round","bevel","miter"]),Y("headEnd"),Y("tailEnd"),Y("extLst")],an=[Y("ln"),dt,vt,Y("highlight"),ne("uLn",["uLnTx","uLn"]),ne("uFill",["uFillTx","uFill"]),Y("latin"),Y("ea"),Y("cs"),Y("sym"),Y("hlinkClick"),Y("hlinkMouseOver"),Y("rtl"),Y("extLst")],at=t=>[Y("cNvPr"),Y(t),Y("nvPr")],It=t=>[Y(t),Y("extLst")],dn=["lnL","lnR","lnT","lnB","lnTlToBr","lnBlToTr"],Cs=Object.assign(Object.create(null),{sld:[Y("cSld"),Y("clrMapOvr"),Y("transition"),Y("timing"),Y("extLst")],cSld:[Y("bg"),Y("spTree"),Y("custDataLst"),Y("controls"),Y("extLst")],bg:[ne("background",["bgPr","bgRef"])],bgPr:[dt,vt,Y("extLst")],spPr:to,grpSpPr:to,ln:no,...Object.fromEntries(dn.map(t=>[t,no])),effectLst:[Y("blur"),Y("fillOverlay"),Y("glow"),Y("innerShdw"),Y("outerShdw"),Y("prstShdw"),Y("reflection"),Y("softEdge")],...Object.fromEntries(["solidFill","outerShdw","innerShdw","prstShdw","glow","highlight","extrusionClr","contourClr","buClr","lnRef","fillRef","effectRef","fontRef"].map(t=>[t,Ts])),scene3d:[Y("camera"),Y("lightRig"),Y("backdrop"),Y("extLst")],camera:[Y("rot")],lightRig:[Y("rot")],sp3d:[Y("bevelT"),Y("bevelB"),Y("extrusionClr"),Y("contourClr"),Y("extLst")],style:[Y("lnRef"),Y("fillRef"),Y("effectRef"),Y("fontRef")],sp:[Y("nvSpPr"),Y("spPr"),Y("style"),Y("txBody"),Y("extLst")],pic:[Y("nvPicPr"),Y("blipFill"),Y("spPr"),Y("style"),Y("extLst")],cxnSp:[Y("nvCxnSpPr"),Y("spPr"),Y("style"),Y("extLst")],grpSp:[Y("nvGrpSpPr"),Y("grpSpPr"),lt,Y("extLst")],graphicFrame:[Y("nvGraphicFramePr"),Y("xfrm"),Y("graphic"),Y("extLst")],nvSpPr:at("cNvSpPr"),nvPicPr:at("cNvPicPr"),nvCxnSpPr:at("cNvCxnSpPr"),nvGrpSpPr:at("cNvGrpSpPr"),nvGraphicFramePr:at("cNvGraphicFramePr"),cNvPr:[Y("hlinkClick"),Y("hlinkHover"),Y("extLst")],nvPr:[Y("ph"),ne("media",["audioCd","wavAudioFile","audioFile","videoFile","quickTimeFile"]),Y("custDataLst"),Y("extLst")],cNvSpPr:It("spLocks"),cNvPicPr:It("picLocks"),cNvGrpSpPr:It("grpSpLocks"),cNvGraphicFramePr:It("graphicFrameLocks"),cNvCxnSpPr:[Y("cxnSpLocks"),Y("stCxn"),Y("endCxn"),Y("extLst")],xfrm:[Y("off"),Y("ext"),Y("chOff"),Y("chExt")],blipFill:[Y("blip"),Y("srcRect"),ne("fillMode",["tile","stretch"])],txBody:[Y("bodyPr"),Y("lstStyle"),lt],bodyPr:[Y("prstTxWarp"),ne("autofit",["noAutofit","normAutofit","spAutoFit"]),Y("scene3d"),ne("text3d",["sp3d","flatTx"]),Y("extLst")],p:[Y("pPr"),lt,Y("endParaRPr")],r:[Y("rPr"),Y("t")],fld:[Y("rPr"),Y("pPr"),Y("t")],br:[Y("rPr")],pPr:[Y("lnSpc"),Y("spcBef"),Y("spcAft"),ne("buClr",["buClrTx","buClr"]),ne("buSz",["buSzTx","buSzPct","buSzPts"]),ne("buFont",["buFontTx","buFont"]),ne("bullet",["buNone","buAutoNum","buChar","buBlip"]),Y("tabLst"),Y("defRPr"),Y("extLst")],rPr:an,defRPr:an,endParaRPr:an,tbl:[Y("tblPr"),Y("tblGrid"),lt],tblPr:[dt,vt,ne("tableStyle",["tableStyle","tableStyleId"]),Y("extLst")],tc:[Y("txBody"),Y("tcPr"),Y("extLst")],tcPr:[...dn.map(Y),Y("cell3D"),dt,Y("headers"),Y("extLst")]}),un=t=>t.ns===ln||t.ns===so,Ds=new Set(["sld","cSld","bg","bgPr","sp","pic","cxnSp","grpSp","graphicFrame","nvSpPr","nvPicPr","nvCxnSpPr","nvGrpSpPr","nvGraphicFramePr","nvPr","style"]);function io(t){if(!(!un(t)||Ds.has(t.local)&&t.ns!==so))return Cs[t.local]}function co(t,e){return un(e)?t.findIndex(([,o])=>o.includes(e.local)):-1}var Ls=new Set(["pPr","rPr","defRPr","endParaRPr","bodyPr","tblPr","tcPr","ln",...dn]);function ao(t){return un(t)&&Ls.has(t.local)}function _s(t,e){let o=io(t),n=o?co(o,e):-1;return n<0?void 0:o[n][0]}var Fs=(t,e)=>t.ns===ln&&t.local==="tc"&&e.ns===ln&&e.local==="txBody",zs="http://schemas.openxmlformats.org/package/2006/content-types",js="http://schemas.openxmlformats.org/package/2006/relationships",Ws=Object.assign(Object.create(null),{[`${zs}|Types`]:{Default:{attr:"Extension",caseless:!0},Override:{attr:"PartName",caseless:!0}},[`${js}|Relationships`]:{Relationship:{attr:"Id",caseless:!1}}});function Ve(t,e,o){let n=Ws[`${t.ns}|${t.local}`];if(n&&Object.prototype.hasOwnProperty.call(n,e.local)){let{attr:i,caseless:s}=n[e.local],c=o(i);return c===void 0?void 0:{slot:`${e.local}:${s?As(c):c}`,rule:"key"}}let r=_s(t,e);if(!(r===void 0||Fs(t,e)))return{slot:r,rule:ao(e)?"merge":"first"}}function qe(t,e,o){let n=io(t);if(!n)return e;let r=n.indexOf(lt),i=-1,s=!0,c=e.map((l,f)=>{let u=o(l),a=u?co(n,u):-1,g=a>=0?a:r>=0?r:i;return g<i&&(s=!1),i=g,{c:l,rank:g,i:f}});return s?e:c.sort((l,f)=>l.rank-f.rank||l.i-f.i).map(l=>l.c)}var oo=t=>`${t.ns}${Yt}${t.local}`,me=t=>t.slice(0,Math.max(0,t.indexOf("."))),Pt="_",ro=t=>t.slice(t.indexOf(".")+1).startsWith(Pt);function lo(t,e){let o=t.get(e);return o||(o={merge:!1,companions:[],attrFrom:new Map,childFrom:new Map,shadowed:new Map},t.set(e,o)),o}var fn=(t,e)=>t.attrs?.find(o=>o.ns===""&&o.local===e)?.value;function Ks(t,e,o){let n=lo(o,t.key);n.merge=!0;let r=new Map;for(let p of t.attrs??[])r.set(oo(p),p);let i=p=>"text"in p?void 0:Ve(t,p,h=>fn(p,h))?.slot,s=t.children??[],c=new Set(s.map(i)),l=[...s],f=new Map;for(let p of e){n.companions.push(p.key);for(let h of p.attrs??[]){let d=oo(h);r.has(d)||(r.set(d,h),n.attrFrom.set(d,p.key))}for(let h of p.children??[]){if("text"in h)continue;let d=i(h);if(d===void 0){l.push(h),f.set(h.key,p.key);continue}if(c.has(d)&&!ao(h)){n.shadowed.set(h.key,d);continue}c.add(d),l.push(h),f.set(h.key,p.key)}}let u=pn(t,l,o);if(!u)return null;for(let p of u){let h="text"in p?void 0:f.get(p.key);h!==void 0&&n.childFrom.set(p.key,h)}let a=qe(t,u,p=>"text"in p?void 0:p),g=[...r.entries()].sort(([p],[h])=>p<h?-1:p>h?1:0);return{...t,attrs:g.map(([,p])=>p),children:[...a]}}function pn(t,e,o){let n=new Map,r=[],i=new Map;for(let s of e){let c="text"in s?void 0:Ve(t,s,g=>fn(s,g)),l=c?n.get(c.slot):void 0,f=l===void 0?void 0:r[l],u=f!==void 0&&!(ro(f.key)&&ro(s.key));if(c&&l===void 0&&n.set(c.slot,r.length),!u){r.push(s);continue}let a=i.get(l);if(a||i.set(l,a=[]),a.length>=ct.maxCopiesPerGroup)return null;a.push(s)}for(let[s,c]of i){let l=r[s];if(Ve(t,l,f=>fn(l,f))?.rule==="merge"){let f=Ks(l,c,o);if(!f)return null;r[s]=f}else{let f=lo(o,l.key);for(let u of c)f.companions.push(u.key)}}return r}import*as de from"yjs";var K=Object.freeze({splitFrom:"sf",splitBaseText:"sb",splitAt:"sa",splitLength:"sl",splitGeneration:"sg",splitEdited:"se",splitBreak:"sk",movedFrom:"mf",movedIndex:"mi",movedClock:"mq",movedTo:"mt",movedEarlier:"mo",removedWith:"rw"}),Le="pptx-pieces-v1",gt="pptx-moves-v1",Ot="pptx-splits-v1",_e=2e4,At=64,ho=`${K.removedWith}.`,kn=2**31,wn=300,Sn=8,Je=4096,Fe=t=>Number.isSafeInteger(t)&&t>=0,$s=t=>Number.isSafeInteger(t)&&t>=1&&t<kn,mo="http://schemas.openxmlformats.org/drawingml/2006/main",pt=new Set,Me=t=>t?.type==="element",ht=t=>t===K.removedWith||t.startsWith(ho);function Ie(t){for(let e of t.keys())if(ht(e))return!0;return!1}function fo(t,e,o){t.set(`${ho}${e}`,o)}var hn=t=>t.children.filter(Me);function ft(t){let o=hn(t).find(n=>n.local==="t")?.children.find(n=>n.type==="text");return o?.type==="text"?o.value:""}function yo(t){if(!t||"text"in t)return"";let e=t.children?.find(n=>!("text"in n)&&n.local==="t"),o=e&&!("text"in e)?e.children?.find(n=>"text"in n):void 0;return o&&"text"in o?o.text:""}function ko(t){let e=2166136261;for(let o=0;o<t.length;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619)>>>0;return e.toString(36)}function mn(t,e,o,n){let r=`${t}\0${ko(e)}\0${o}`;return n===void 0?r:`${r}\0${n}`}var uo=t=>{let e=Number.parseInt(t,36);return Number.isFinite(e)?e:Number.MAX_SAFE_INTEGER};function wo(t,e,o,n,r){if(n.size===0)return;let i=y=>{let w=r.get(y),x=w===void 0?void 0:t.nodes.get(w);return x instanceof de.Map?x:void 0},s=t.doc.clientID.toString(36),c=new Map,l=[],f=new Set,u=new Set,a=y=>{for(let w of hn(y)){if(w.local!=="r"||u.has(w.id))continue;let x=n.get(w.id);if(!Me(x)||x===w||ft(x)===ft(w))continue;let k=i(w.id);k&&typeof k.get(K.splitFrom)=="string"&&k.get(K.splitEdited)!==!0&&k.set(K.splitEdited,!0)}},g=y=>{let w=hn(y);w.forEach((x,k)=>{if(x.local!=="r"||!n.has(x.id))return;let b=n.get(x.id);if(!Me(b)||b===x)return;let v=ft(b),M=ft(x);if(v.length<=M.length||!v.startsWith(M))return;let C=v.slice(M.length),T=[],R="",j=[];for(let I=k+1;I<w.length&&R.length<C.length;I+=1){let _=w[I];if(_.local==="br"&&!n.has(_.id)){j.push({el:_,at:M.length+R.length});continue}if(_.local!=="r"||n.has(_.id))break;let N=ft(_);T.push({el:_,at:M.length+R.length,length:N.length}),R+=N}let F=r.get(x.id);if(R!==C||F===void 0||T.length===0)return;u.add(x.id);let P=`${F}\0${ko(v)}`,D=Math.min((So(t).latest.get(P)??0)+1,kn-1);for(let{el:I,at:_,length:N}of T){let z=i(I.id);if(!z||z.has(K.splitFrom))continue;z.set(K.splitFrom,F),z.set(K.splitBaseText,v),z.set(K.splitAt,_),z.set(K.splitLength,N),z.set(K.splitGeneration,D);let W=r.get(I.id);W!==void 0&&t.doc.getMap(Le).set(W,e)}for(let{el:I,at:_}of j){let N=i(I.id);!N||N.has(K.splitBreak)||(N.set(K.splitBreak,mn(F,v,D)),N.set(K.splitAt,_))}t.doc.getMap(Ot).set(mn(F,v,D,s),M.length)})},p=(y,w)=>{let x=n.get(y.id);if(x===y)return;let k=r.get(y.id),b=k===void 0?w:[k,...w].slice(0,wn),v=Me(x)?new Set(x.children.map(M=>M.id)):new Set;for(let M of y.children)f.add(M.id),!v.has(M.id)&&n.has(M.id)&&l.push({node:M,path:b});if(Me(x)){let M=new Set(y.children.map(C=>C.id));for(let C of x.children)M.has(C.id)||c.set(C.id,C)}y.ns===mo&&y.local==="p"&&Me(x)&&(g(y),a(y));for(let M of y.children)Me(M)&&p(M,b)};if(p(o,[]),l.length>0){let y=new Map;for(let k of n.values())Me(k)&&k.children.forEach((b,v)=>y.set(b.id,{parent:k.id,index:v}));let w=t.doc.getMap(gt),x=de.getState(t.doc.store,t.doc.clientID);for(let{node:k,path:b}of l){let v=y.get(k.id),M=v===void 0?void 0:r.get(v.parent),C=r.get(k.id),T=i(k.id);if(!T||!v||M===void 0||C===void 0)continue;let R=T.get(K.movedFrom);if(typeof R=="string"&&R!==M){let j=T.get(K.movedEarlier),F=Array.isArray(j)?j.filter(P=>typeof P=="string"&&P!==R):[];T.set(K.movedEarlier,[R,...F].slice(0,Sn))}T.set(K.movedFrom,M),T.set(K.movedIndex,v.index),T.set(K.movedClock,x),T.set(K.movedTo,b),w.set(C,e)}}let h=t.doc.getMap(Le),d,m,S=y=>(d??=po(o,r)).has(y);for(let[y,w]of c){if(f.has(y))continue;let x=new Set,k=[w];for(;k.length>0&&x.size<=_e;){let C=k.pop(),T=r.get(C.id);if(T!==void 0&&x.add(T),Me(C))for(let R of C.children)f.has(R.id)||k.push(R)}let b=r.get(y);b!==void 0&&Xs(t,b,x,S);let v=i(y);if(!v||x.size>_e)continue;let M=[...x];fo(v,s,M);for(let C of x){if(C===b||!h.has(C)||(d??=po(o,r)).has(C))continue;let T=t.nodes.get(C);!(T instanceof de.Map)||Ie(T)||(m??=new Set([...n.keys()].flatMap(R=>r.get(R)??[])),!(!m.has(C)&&Gs(t,e,T,d))&&fo(T,s,[C]))}}}function po(t,e){let o=new Set,n=[t];for(;n.length>0;){let r=n.pop(),i=e.get(r.id);if(i!==void 0&&o.add(i),Me(r))for(let s of r.children)n.push(s)}return o}function Gs(t,e,o,n){let r=ze(o),i=r?Qe(t)(r.group):void 0;if(!r||i===void 0)return!1;let s=0;for(let[c,l]of t.doc.getMap(Le).entries())if(!(l!==e||me(c)!==i||!n.has(c))&&((s+=1)>Je||ze(t.nodes.get(c))?.group===r.group))return!0;return!1}function Xs(t,e,o,n){let r=[e],i=new Set;for(;r.length>0&&o.size<=_e;){let s=r.pop();if(i.has(s))continue;i.add(s),o.add(s);let c=t.nodes.get(s),l=c instanceof de.Map?c.get(A.children):void 0;if(l instanceof de.Array)for(let f of l.toArray())typeof f=="string"&&!i.has(f)&&!n(f)&&r.push(f)}}var gn=new WeakMap,go=new WeakSet;function So(t){let e=t.doc.getMap(Ot),o=gn.get(e);if(o)return o;let n={groups:new Map,latest:new Map};for(let[r,i]of e.entries()){let s=r.split("\0");if(!Fe(i)||s.length!==4)continue;let[c,l,f,u]=s,a=Number(f);if(!Number.isSafeInteger(a)||a<1||a>=kn)continue;let g=`${c}\0${l}`,p=`${g}\0${a}`,h=n.groups.get(p);h||n.groups.set(p,h=new Map),h.set(u,i),n.latest.set(g,Math.max(n.latest.get(g)??0,a))}return gn.set(e,n),go.has(e)||(go.add(e),e.observe(()=>gn.delete(e))),n}function ze(t){if(!(t instanceof de.Map))return null;let e=t.get(K.splitFrom),o=t.get(K.splitBaseText),n=t.get(K.splitAt),r=t.get(K.splitLength),i=t.get(K.splitGeneration);return typeof e!="string"||typeof o!="string"||!Fe(n)||!Fe(r)||!$s(i)?null:{from:e,group:mn(e,o,i),original:o.slice(n,n+r),at:n,edited:t.get(K.splitEdited)===!0}}function Qe(t){let{groups:e}=So(t),o=new Map;return n=>{if(o.has(n))return o.get(n);let r=e.get(n),i;if(r&&r.size>=2){let s;for(let[c,l]of r)(!s||l<s[1]||l===s[1]&&uo(c)<uo(s[0]))&&(s=[c,l]);i=s?.[0]}return o.set(n,i),i}}function xo(t,e,o){let n=new Map,r=new Set,i=s=>{let c=n.get(s);if(c!==void 0||n.has(s))return c??null;let l=e(s);if(!l||l.edited||r.has(s)||r.size>Je)return null;r.add(s);let f=o(s);for(let u of t.get(s)??[]){let a=i(u);if(a===null){f=null;break}f+=a}return r.delete(s),n.set(s,f),f};return i}function yn(t){let e=new Map;for(let[n,r]of t){let i=e.get(r.from);i?i.push([n,r.at]):e.set(r.from,[[n,r.at]])}let o=new Map;for(let[n,r]of e)o.set(n,r.sort((i,s)=>i[1]-s[1]||(i[0]<s[0]?-1:i[0]>s[0]?1:0)).map(([i])=>i));return o}function Mo(t,e){let o=0;for(let n=0;n<e.length&&o<t.length;n+=1)e[n]===t[o]&&(o+=1);return o===t.length}function bo(t,e,o,n,r=pt){if(e.ns!==mo||e.local!=="p")return o;let i=new Map,s=new Map;for(let p of o){if("text"in p)continue;let h=ze(t.nodes.get(p.key));if(h){if(i.size>=Je)return o;i.set(p.key,h),s.set(p.key,yo(p))}}if(i.size===0)return o;let c=yn(i),l=xo(c,p=>i.get(p),p=>s.get(p)??""),f=Qe(t),u=new Set;for(let[p,h]of i){let d=f(h.group);if(d===void 0||me(p)===d||r.has(h.group))continue;let m=l(p);m!==null&&Mo(m,h.original)&&u.add(p)}if(u.size===0)return o;let a=[...u];for(;a.length>0;)for(let p of c.get(a.pop())??[])u.has(p)||(u.add(p),a.push(p));for(let p of u)n.add(p);let g=o.filter(p=>"text"in p||!u.has(p.key));return Bs(t,g,u,i,f)}function Bs(t,e,o,n,r){let i=new Set;for(let f of o){let u=n.get(f);u&&i.add(`${u.group}\0${me(f)}`)}let s=new Map;for(let f of e){if("text"in f||f.local!=="br")continue;let u=t.nodes.get(f.key);if(!(u instanceof de.Map))continue;let a=u.get(K.splitBreak),g=u.get(K.splitAt);if(typeof a!="string"||!Fe(g)||!i.has(`${a}\0${me(f.key)}`))continue;let p;for(let h of e){let d="text"in h?void 0:n.get(h.key);!d||d.group!==a||me(h.key)!==r(a)||d.at<g||(!p||d.at<p[1])&&(p=[h.key,d.at])}p&&s.set(f.key,p[0])}if(s.size===0)return e;let c=new Map;for(let f of e){let u=s.get(f.key);if(u===void 0)continue;let a=c.get(u);a?a.push(f):c.set(u,[f])}let l=[];for(let f of e)if(!s.has(f.key)){for(let u of c.get(f.key)??[])l.push(u);l.push(f)}return l}function Ro(t,e,o){if(!o||o.size===0)return e;let n=new Set(e),r=[...e],i=-1;for(let s of t){let c=r.indexOf(s);if(c>=0&&n.has(s)){i=c;continue}!o.has(s)||n.has(s)||(r.splice(i+1,0,s),i+=1)}return r}function Yo(t,e,o,n,r=pt){let i=t.doc.getMap(Le);if(i.size===0)return o;let s=new Map,c=P=>{(P.children??[]).forEach((D,I)=>{s.set(D.key,{parent:P,at:I,order:s.size}),"text"in D||c(D)})};c(o);let l=new Map;for(let[P,D]of i.entries()){if(D!==e)continue;let I=t.nodes.get(P);if(!(I instanceof de.Map)||Ie(I))continue;let _=ze(I);_&&(l.size>=Je&&(s.has(P)||l.size>=2*Je)||l.set(P,_))}let f=Qe(t),u=new Map,a=P=>{let D=u.get(P);if(D===void 0){let I=s.get(P);D=yo(I?I.parent.children[I.at]:n(P,new Set,1)??void 0),u.set(P,D)}return D},g=xo(yn(l),P=>l.get(P),a),p=new Map;for(let[P,D]of l){if(me(P)!==f(D.group))continue;let I=s.get(P)?.order;if(I===void 0)continue;let _=p.get(D.group);(!_||I>_.order)&&p.set(D.group,{key:P,order:I})}let h=new Map,d=P=>{let D=l.get(P).from;D!==P&&h.set(P,D)},m=[];for(let P of[...l.keys()].sort()){let D=l.get(P),I=f(D.group);if(I===void 0||me(P)===I){r.has(P)&&!s.has(P)&&m.push(P);continue}let _=g(P);if(_!==null&&Mo(_,D.original))continue;let N=p.get(D.group)?.key??(s.has(D.from)?D.from:void 0);N!==void 0&&N!==P&&h.set(P,N)}let S=new Set(m);for(let P of m){let D=l.get(P).from;(s.has(D)||S.has(D))&&d(P)}let y=yn(l),w=[...h.keys()];for(;w.length>0;)for(let P of y.get(w.pop())??[])!h.has(P)&&s.has(P)&&(d(P),w.push(P));if(h.size===0)return o;let x=new Map,k=new Set(s.keys());for(let P of h.keys()){let D=s.get(P),I=D?D.parent.children[D.at]:n(P,k,1);I&&x.set(P,I)}let b=new Map,v=P=>{let D=b.get(P);if(D!==void 0)return D;let I=h.get(P);b.set(P,!1);let _=I===void 0?s.has(P):x.has(P)&&v(I);return b.set(P,_),_},M=new Map,C=new Set;for(let[P,D]of h){let I=x.get(P);if(!I||!v(P))continue;C.add(P);let _=M.get(D);_?_.push(I):M.set(D,[I])}if(C.size===0)return o;let T=(P,D)=>{let I=l.get(D);return I?.from===P?I.at:1/0};for(let[P,D]of M)D.sort((I,_)=>T(P,I.key)-T(P,_.key)||(I.key<_.key?-1:I.key>_.key?1:0));let R=new Set,j=(P,D)=>{for(let I of M.get(P)??[])R.has(I.key)||(R.add(I.key),D.push(I),j(I.key,D))},F=P=>{let D=[];for(let I of P.children??[])C.has(I.key)||(D.push("text"in I?I:F(I)),j(I.key,D));return{...P,children:D}};return F(o)}var ut=Object.freeze({unseenWinners:pt,lost:pt});function mt(t,e,o,n=pt){let r=t.doc.getMap(Le);if(r.size===0)return ut;let i=Qe(t),s=new Set,c=new Map,l=0;for(let[m,S]of r.entries()){if(S!==e)continue;let y=t.nodes.get(m);if(!(y instanceof de.Map)||y.get(A.part)!==e)continue;let w=ze(y);if(w){if(Ie(y)){me(m)===i(w.group)&&s.add(w.group);continue}if((l+=1)>Je)return ut;c.set(m,w)}}if(c.size===0)return ut;let f=new Set,u=[o];for(;u.length>0;){let m=u.pop();if(f.has(m))continue;f.add(m);let S=t.nodes.get(m);if(!(S instanceof de.Map)||S.get(A.part)!==e)continue;let y=S.get(A.children);if(y instanceof de.Array)for(let w of y.toArray())typeof w=="string"&&!f.has(w)&&u.push(w)}let a=new Set,g=new Map;for(let[m,S]of c){let y=me(m)===i(S.group);if(f.has(m)||n.has(m)){y&&s.add(S.group);continue}if(a.add(m),!y)continue;let w=g.get(S.group);w?w.push(m):g.set(S.group,[m])}let p=new Map,h=m=>{let S=p.get(m);if(S!==void 0)return S;p.set(m,!1);let y=c.get(m)?.from,w=y!==void 0&&(f.has(y)||n.has(y)||a.has(y)&&h(y));return p.set(m,w),w},d=new Set;for(let[m,S]of g)!s.has(m)&&!S.some(h)&&d.add(m);return{unseenWinners:d,lost:a}}import*as Nt from"yjs";var Us=1024;function Hs(t){if(!(t instanceof Nt.Map))return null;let e=null,o=0;for(let[n,r]of t.entries())if(!(!ht(n)||!Array.isArray(r))){if(r.length>_e+1||(o+=1)>At)return"all";e??=new Set;for(let i of r)typeof i=="string"&&e.add(i)}return e}function Vs(t,e,o,n,r){if(o.length>wn)return null;for(let i of o){if(typeof i!="string"||n.has(i))return null;let s=r.get(i);if(s===void 0&&(s=Hs(t.nodes.get(i)),r.set(i,s)),s==="all")return null;if(s)return s.has(e)?null:i}return null}var xn=(t,e)=>t<e?-1:t>e?1:0,Mn=class extends Set{#e;constructor(e){super(),this.#e=e}has(e){return this.#e.has(e)||super.has(e)}};function Io(t,e,o,n,r,i){let s=t.doc.getMap(gt);if(s.size===0)return o;let c=new Map,l=new Map,f=new Map,u=(M,C,T)=>{if(c.set(M.key,C),f.set(M.key,f.size),T!==null&&l.set(M.key,T),!("text"in M))for(let R of M.children??[])u(R,C+1,M.key)};u(o,0,null);let a=[],g=[],p=new Map,h,d=M=>{if(!h){h=new Map;for(let C of s.keys()){if(!l.has(C))continue;let T=t.nodes.get(C),R=T instanceof Nt.Map?T.get(K.movedFrom):void 0;if(typeof R!="string")continue;let j=h.get(R);(j===void 0||f.get(C)>f.get(j))&&h.set(R,C)}}return h.get(M)};for(let[M,C]of s.entries()){if(C!==e||c.has(M))continue;let T=t.nodes.get(M);if(!(T instanceof Nt.Map)||T.get(A.part)!==e||Ie(T))continue;let R=T.get(K.movedFrom),j=T.get(K.movedTo);if(typeof R!="string"||!Array.isArray(j))continue;let F=T.get(K.movedEarlier),P=c.has(R)?R:(Array.isArray(F)?F.slice(0,Sn):[]).find(z=>typeof z=="string"&&c.has(z)),D=T.get(K.movedIndex),I=T.get(K.movedClock),_=typeof I=="number"&&Number.isFinite(I)?I:0,N=Vs(t,M,j,c,p);if(N!==null){if(a.length+g.length>=Us)return o;if(P!==void 0){let z=P===R&&Fe(D)?D:1/0;a.push({key:M,from:P,index:z,clock:_,to:j})}else g.push({key:M,last:R,removed:N,index:Fe(D)?D:1/0,clock:_,to:j})}}let m=new Map,S=g,y=0;for(;S.length>0;){let M=[],C=[];for(let T of S){let R=m.get(T.removed),j=R?void 0:d(T.removed),F=R?R.into:j===void 0?void 0:l.get(j),P=R?R.key:j;P===void 0||F===void 0?C.push(T):M.push({...T,after:P,into:F})}if(M.length===0){for(let T of C)i?.add(T.removed);break}M.sort((T,R)=>T.clock-R.clock||T.index-R.index||xn(T.key,R.key));for(let T of M)a.push({...T,from:T.into,seq:y++}),m.set(T.last,{key:T.key,into:T.into});S=C}if(a.length===0)return o;let w=new Set(a.map(M=>M.key)),x=new Map(a.map(M=>[M.key,M.to.filter(C=>typeof C=="string"&&w.has(C)).length]));a.sort((M,C)=>x.get(M.key)-x.get(C.key)||xn(M.key,C.key));let k=new Mn(new Set(c.keys())),b=new Map;for(let M of a){let C=n(M.key,k,c.get(M.from)+1);if(!C)continue;r?.add(C.key);let T={node:C,index:M.index,clock:M.clock,after:M.after,seq:M.seq??0},R=b.get(M.from);R?R.push(T):b.set(M.from,[T])}if(b.size===0)return o;let v=M=>{let C=b.get(M.key),T=(M.children??[]).map(I=>"text"in I?I:v(I));if(!C)return{...M,children:T};let R=[...T],j=C.filter(I=>I.after===void 0).sort((I,_)=>_.clock-I.clock||I.index-_.index||xn(I.node.key,_.node.key));for(let{node:I,index:_}of j)R.splice(Math.min(_,R.length),0,I);let F=C.filter(I=>I.after!==void 0).sort((I,_)=>I.seq-_.seq),P=new Map;for(let{node:I,after:_}of F){let N=P.get(_)??_,z=R.findIndex(W=>W.key===N);R.splice(z<0?R.length:z+1,0,I),P.set(_,I.key)}let D={ns:M.ns,local:M.local};return{...M,children:[...qe(D,R,I=>"text"in I?void 0:I)]}};return v(o)}function Tt(t){let e=new Set,o=[t];for(;o.length>0;){let n=o.pop();if(e.add(n.key),!("text"in n))for(let r of n.children??[])o.push(r)}return e}var Eo=(t,e)=>t.size===e.size&&[...t].every(o=>e.has(o));function vo(t,e){return Eo(t.lost,e.lost)&&Eo(t.unseenWinners,e.unseenWinners)}import*as kt from"yjs";import{children as bn,elements as Ze,isStructureEdited as qs,path as Po,TABLE_MAX_COLUMNS as Js,TABLE_MAX_ROWS as Qs,tableGridOf as Zs}from"@pptx-editor.dev/core/store";var Ct=Object.freeze({holder:"mh",cover:"cv."}),Yn="http://schemas.openxmlformats.org/drawingml/2006/main",ei="http://schemas.openxmlformats.org/presentationml/2006/main",Lt=256,Oo=4096,yt=t=>t?.type==="element",Dt=(t,e)=>!!t&&!("text"in t)&&t.ns===Yn&&t.local===e;function ti(t){return(Ze(t).find(o=>o.local==="t")?.children??[]).map(o=>o.type==="text"?o.value:"").join("")}function ni(t){return Ze(t).some(e=>e.local==="br"||(e.local==="r"||e.local==="fld")&&ti(e).length>0)}function Ao(t){return"text"in t?!1:(t.children??[]).some(e=>{if("text"in e||!(e.local==="br"||e.local==="r"||e.local==="fld"))return!1;if(e.local==="br")return!0;let o=e.children?.find(n=>!("text"in n)&&n.local==="t");return!!o&&!("text"in o)&&(o.children??[]).some(n=>"text"in n&&n.text!=="")})}function No(t,e){let o=[],n=(r,i)=>{if(r.ns===ei&&r.local==="graphicFrame"){o.push(r);return}if(i<Lt)for(let s of e(r))n(s,i+1)};return n(t,0),o}function To(t){let e=Po(t,"a:graphic","a:graphicData","a:tbl"),o=Math.min(bn(Po(e,"a:tblGrid"),"a:gridCol").length,Js),n=bn(e,"a:tr").slice(0,Qs).map(s=>bn(s,"a:tc"));if(o===0||n.length===0)return[];let r=Zs(t,n,o),i=[];return n.forEach((s,c)=>s.slice(0,o).forEach((l,f)=>{let u=r.blocks[r.owner[c*o+f]],a=u&&n[u.row][u.col];a&&(u.row!==c||u.col!==f)&&i.push({tc:l,over:a})})),i}var Rn=t=>Ze(t).filter(e=>e.ns===Yn&&e.local==="txBody");function Co(t){let e=new Set;if(!(t instanceof kt.Map))return e;for(let[o,n]of t.entries())if(!(!o.startsWith(Ct.cover)||!Array.isArray(n))){if(n.length>Oo)return"all";for(let r of n)typeof r=="string"&&e.add(r)}return e}function Do(t,e,o,n){if(o.size===0)return;let r=u=>{let a=n.get(u),g=a===void 0?void 0:t.nodes.get(a);return g instanceof kt.Map?g:void 0},i=new Set,s=[],c=(u,a)=>{let g=o.get(u.id);if(g!==u){for(let p of u.children)i.add(p.id);if(u.ns===Yn&&u.local==="txBody"&&yt(g)){let p=new Set(u.children.map(d=>d.id)),h=g.children.filter(d=>yt(d)&&d.local==="p");h.length>0&&h.every(d=>!p.has(d.id))&&s.push({body:u,old:g})}if(a<Lt)for(let p of u.children)yt(p)&&c(p,a+1)}};c(e,0);for(let{body:u,old:a}of s)if(a.children.filter(p=>yt(p)&&p.local==="p").every(p=>i.has(p.id)))for(let p of u.children)yt(p)&&p.local==="p"&&!o.has(p.id)&&!ni(p)&&r(p.id)?.set(Ct.holder,!0);let l=`${Ct.cover}${t.doc.clientID.toString(36)}`,f=u=>Ze(u).filter(a=>o.get(a.id)!==a);for(let u of No(e,f))for(let{tc:a}of To(u)){let g=r(a.id),p=Rn(a);if(!g||p.length===0)continue;let h=Co(g);if(h==="all")continue;let d=p.flatMap(y=>Ze(y).filter(w=>w.local==="p")).map(y=>n.get(y.id)).filter(y=>y!==void 0&&!h.has(y));if(d.length===0)continue;let m=g.get(l),S=Array.isArray(m)?m.filter(y=>typeof y=="string"):[];g.set(l,[...S,...d].slice(0,Oo+1))}}function Lo(t,e){let o=new Map(t);return o.delete(e),o}function _o(t,e,o){let n=[];if(!e||e.size===0)return n;let r=(i,s)=>{let c=o.get(i.id);if(c!==void 0&&e.has(c)&&n.push(i),s<Lt)for(let l of Ze(i))r(l,s+1)};return r(t,0),n}function Fo(t,e){e.set(t.key,t);let o=(t.children??[]).map(n=>"text"in n?{type:"text",id:n.key,value:n.text}:Fo(n,e));return{type:"element",id:t.key,kind:"generic",ns:t.ns,local:t.local,...t.prefix?{prefix:t.prefix}:{},nsDecls:[],attrs:t.attrs??[],children:o}}function oi(t,e,o,n,r){let i=new Map,s=Fo(o,i),c=qs(s);for(let{tc:l,over:f}of To(s)){let u=Rn(f)[0],a=u&&i.get(u.id);if(!a)continue;let g=Co(t.nodes.get(l.id)),p=S=>{if(g==="all"||g.has(S))return!1;let y=t.nodes.get(S);return y instanceof kt.Map?c?!0:typeof y.get(K.movedFrom)=="string"||Ie(y):!1},h=Rn(l).flatMap(S=>{let y=i.get(S.id);if(!y)return[];let w=y.children??[],x=w.filter(k=>Dt(k,"p")&&(e.has(k.key)||Ao(k)&&p(k.key)));return[{from:y,kids:w,going:x,paragraphs:w.filter(k=>Dt(k,"p")).length}]});h.every(S=>S.going.length===S.paragraphs)&&[...h].reverse().find(S=>S.going.length>0)?.going.pop();let d=new Set(h.filter(S=>S.going.length===S.paragraphs).map(S=>S.from)),m=i.get(l.id);m&&d.size>0&&d.size<h.length&&r.set(m.key,(m.children??[]).filter(S=>!d.has(S)));for(let{from:S,kids:y,going:w}of h){if(w.length===0)continue;let x=new Set(w);r.set(S.key,y.filter(b=>!x.has(b)));let k=n.get(a.key);if(k)for(let b of w)k.push(b);else n.set(a.key,w)}}}function zo(t,e,o,n){let r=new Map,i=new Map,s=No(e,f=>(f.children??[]).filter(u=>!("text"in u)));for(let f of s)oi(t,o,f,r,i);if(r.size===0&&o.size===0)return e;let c=f=>{if(!Dt(f,"p")||Ao(f))return!1;let u=t.nodes.get(f.key);return u instanceof kt.Map&&u.get(Ct.holder)===!0},l=(f,u)=>{let a=i.get(f.key)??f.children??[],g=r.get(f.key);g&&(a=[...a,...g]),f.local==="txBody"&&a.some(d=>Dt(d,"p")&&o.has(d.key))&&(a=a.filter(d=>!c(d)));let p=u<Lt?a.map(d=>"text"in d?d:l(d,u+1)):a,h=p.length===(f.children??[]).length&&p.every((d,m)=>d===f.children[m]);return!h&&f.local==="txBody"&&n?.add(f.key),h?f:{...f,children:p}};return l(e,0)}import*as J from"yjs";var oe=Object.freeze({copyOf:"ci",newParagraph:"cp",seen:"cs",followed:"cf.",removedRun:"rr."}),We="pptx-copies-v1",jo=1<<20,Xo=4096,ri=1024,En=32,Bo="http://schemas.openxmlformats.org/drawingml/2006/main",si="http://schemas.openxmlformats.org/presentationml/2006/main",In=t=>t.local==="txBody"&&(t.ns===Bo||t.ns===si),U=(t,e)=>`${t}:${e}`,Oe=t=>Number.isSafeInteger(t)&&t>=0,Wo=new WeakMap;function Ae(t){if(!(t instanceof J.Map))return null;let e=t.get(oe.copyOf),o=Wo.get(t);if(o&&o.value===e)return o.copy;let n=Uo(e,t.get(oe.newParagraph)===!0);return Wo.set(t,{value:e,copy:n}),n}function Uo(t,e){if(!Array.isArray(t)||t.length<5||(t.length-2)%3!==0||t.length>2+3*jo)return null;let[o,n]=t;if(!Oe(o)||!Oe(n))return null;let r=[],i=0;for(let c=2;c<t.length;c+=3){let l=t[c],f=t[c+1],u=t[c+2];if(!Oe(l)||!Oe(f)||!Oe(u)||u===0||(r.push(i),i+=u,i>jo))return null}let s=t;return{client:o,clock:n,length:i,newParagraph:e,source(c){let l=0,f=r.length-1;for(;l<f;){let a=l+f+1>>1;r[a]<=c?l=a:f=a-1}let u=2+3*l;return J.createID(s[u],s[u+1]+(c-r[l]))}}}var Ko=new WeakMap;function zt(t){let e=[];if(!(t instanceof J.Map))return e;let o=[];for(let n of t.keys())n.startsWith(oe.followed)&&o.push(n);for(let n of o.sort().slice(0,ri)){let r=t.get(n);if(!Array.isArray(r))continue;let i=Ko.get(r);i===void 0&&Ko.set(r,i=Uo(r,!1)),i&&e.push(i)}return e}function ii(t,e){let o=r=>r!==null&&r.client===e.client&&e.clock>=r.clock&&e.clock<r.clock+r.length,n=Ae(t);return o(n)?n:zt(t).find(o)??null}function Ho(t,e,o,n){t.set(`${oe.followed}${U(e,o)}`,[e,o,...qo(n)])}function Vo(t,e){let o=new Set,n=t.nodes;for(let[r,i]of e.changed){if(r===n){for(let c of i)c!==null&&zt(n.get(c)).length>0&&o.add(c);continue}if(!(r instanceof J.Map)||r.parent!==n)continue;let s=r.get(A.key);if(typeof s=="string")for(let c of i)c?.startsWith(oe.followed)&&o.add(s)}return o}var Ne="pptx-restored-v1",Ke=65536,ci=/^(\d{1,16}):(\d{1,16})$/,_t=new WeakMap,$o=new WeakSet;function ai(t){let e=_t.get(t);if(e)return e;$o.has(t)||($o.add(t),t.observe(()=>_t.delete(t))),e=new Map;for(let[o,n]of t.entries()){let r=ci.exec(o);if(!r||!Array.isArray(n)||n.length!==3||!n.every(Oe))continue;let[i,s,c]=n;if(c===0||c>Ke)continue;let l=Number(r[1]),f=Number(r[2]);if(!Number.isSafeInteger(l)||!Number.isSafeInteger(f))continue;let u=e.get(l),a=[f,i,s,c];u?u.push(a):e.set(l,[a])}for(let o of e.values())o.sort((n,r)=>n[0]-r[0]);return _t.set(t,e),e}function et(t,e){let o=t.getMap(Ne);if(o.size===0)return null;let n=ai(o).get(e.client);if(!n)return null;let r=0,i=n.length-1;for(;r<i;){let c=r+i+1>>1;n[c][0]<=e.clock?r=c:i=c-1}let s=n[r];return!s||e.clock<s[0]||e.clock>=s[0]+s[3]?null:J.createID(s[1],s[2]+(e.clock-s[0]))}function St(t,e){if(e.length===0)return;let o=t.getMap(Ne);for(let n=0;n+3<e.length;n+=4)o.set(U(t.clientID,e[n]),[e[n+1],e[n+2],e[n+3]]);_t.delete(o)}function qo(t){let e=[];for(let o of t){let n=e.length;n>0&&e[n-3]===o.client&&e[n-2]+e[n-1]===o.clock?e[n-1]+=1:e.push(o.client,o.clock,1)}return e}function li(t,e){let o=new Set;for(let r=e._start;r!==null;r=r.right)if(o.add(r.id.client),o.size>Xo)return null;let n=[];for(let r of[...o].sort((i,s)=>i-s))n.push(r,J.getState(t.store,r));return n}var Go=new WeakMap;function Jo(t){if(!(t instanceof J.Map))return null;let e=t.get(oe.seen),o=Go.get(t);(!o||o.value!==e)&&(o={value:e,seen:di(e)},Go.set(t,o));let n=o.seen;return n?r=>r.clock<(n.get(r.client)??0):null}function di(t){if(!Array.isArray(t)||t.length%2!==0||t.length>2*Xo)return null;let e=new Map;for(let o=0;o<t.length;o+=2){let n=t[o],r=t[o+1];if(!Oe(n)||!Oe(r)||e.has(n))return null;e.set(n,r)}return e}function jt(t,e,o){let n=[],r=0;for(let i=t._start;i!==null&&n.length<o;i=i.right)if(!(i.deleted||!i.countable))for(let s=0;s<i.length&&n.length<o;s+=1,r+=1)r>=e&&n.push(J.createID(i.id.client,i.id.clock+s));return n}function ye(t,e){if(J.getState(t.store,e.client)<=e.clock)return null;let o=J.getItem(t.store,e);return o instanceof J.Item?o:null}function Wt(t){let e=t.parent,o=e instanceof J.Text?e.parent:null;return o instanceof J.Map?o:null}function Kt(t,e){let o=ye(t,e);return!o||o.deleted}function ue(t,e,o,n=!0){let r=U(e.client,e.clock),i=o?.get(r);if(i)return i;let s=e;for(let c=0;c<En;c+=1){let l=ye(t,s),f=l?ii(Wt(l),s):null;if(f){s=f.source(s.clock-f.clock);continue}let u=n?et(t,s):null;if(!u)break;s=u}return o?.set(r,s),s}var je=t=>t?.type==="element",Ft=t=>t.children.filter(je),fe=(t,e)=>t.ns===Bo&&t.local===e;function Qo(t){return Ft(t).find(o=>fe(o,"t"))?.children.find(o=>o.type==="text")}var wt=t=>{let e=Qo(t);return e?.type==="text"?e.value:""};function Zo(t,e,o,n,r,i){let s=new Set;if(n.size===0||i.size===0)return s;let c=t.doc.getMap(We),l=a=>{let g=Qo(a);return g?r.get(g.id):void 0},f=(a,g,p)=>{let h=Ft(a);h.forEach((d,m)=>{if(!fe(d,"r"))return;let S=n.get(d.id);if(!je(S)||S===d)return;let y=wt(S),w=wt(d);if(y.length<=w.length||!y.startsWith(w))return;let x=l(d),k=x===void 0?void 0:i.get(x),b=y.length-w.length;if(!k||k.deleted.length!==b)return;let v=[],M=0,C=(z,W,O)=>{for(let E=W;E<z.length&&M<b;E+=1){let L=z[E];if(!(!n.has(L.id)&&fe(L,"br"))&&!fe(L,"pPr")){if(fe(L,"endParaRPr"))return!0;if(!fe(L,"r")||n.has(L.id))return!1;v.push({run:L,newParagraph:O}),M+=wt(L).length}}return!0},T=C(h,m+1,!1),R=g[p+1],j=h.slice(m+1).every(z=>n.has(z.id)||fe(z,"endParaRPr"));M<b&&T&&j&&R&&fe(R,"p")&&!n.has(R.id)&&C(Ft(R),0,!0);let F=v.length>0&&v.every(z=>z.newParagraph),P=v.map(z=>wt(z.run)).join("");if(M>b||M<b&&!(F&&y.endsWith(P)))return;let D=x===void 0?void 0:t.nodes.get(x),I=D instanceof J.Map?D.get(A.text):void 0,_=I instanceof J.Text?li(t.doc,I):null,N=b-M;for(let z of v){let W=l(z.run),O=wt(z.run).length,E=W===void 0?void 0:i.get(W),L=W===void 0?void 0:t.nodes.get(W),$=k.deleted.slice(N,N+O);if(N+=O,!(O===0||!E?.created||E.inserted?.length!==O)&&!(!(L instanceof J.Map)||W===void 0)){L.set(oe.copyOf,[E.inserted.client,E.inserted.clock,...qo($)]),z.newParagraph&&L.set(oe.newParagraph,!0),_&&L.set(oe.seen,_),c.set(W,e);for(let Q of $)s.add(U(Q.client,Q.clock))}}})},u=a=>{if(n.get(a.id)===a)return;let g=Ft(a);g.forEach((p,h)=>{fe(p,"p")&&je(n.get(p.id))&&f(p,g,h)});for(let p of g)u(p)};return u(o),s}function er(t,e,o,n){let r=[];if(o.size===0)return r;let i=new Set,s=[],c=l=>{let f=o.get(l.id);if(f!==l){for(let u of l.children)i.add(u.id);if(je(f)){let u=new Set(l.children.map(g=>g.id)),a="";for(let g of f.children)!u.has(g.id)&&je(g)&&(fe(g,"r")||fe(g,"p"))&&s.push({node:g,from:l,prev:a}),a=n.get(g.id)??a}for(let u of l.children)je(u)&&c(u)}};c(e);for(let{node:l,from:f,prev:u}of s){if(i.has(l.id))continue;let a=n.get(l.id),g=n.get(f.id),p=g===void 0?void 0:t.nodes.get(g);(fe(l,"r")&&fe(f,"p")||fe(l,"p")&&In(f))&&a!==void 0&&p instanceof J.Map&&p.set(`${oe.removedRun}${a}`,u);let d=[l];for(;d.length>0;){let m=d.pop();if(m!==l&&i.has(m.id))continue;if(je(m)){for(let x of m.children)d.push(x);continue}let S=n.get(m.id),y=S===void 0?void 0:t.nodes.get(S),w=y instanceof J.Map?y.get(A.text):void 0;if(!(!(w instanceof J.Text)||m.type!=="text"||m.value.length===0)&&w.toString()===m.value){for(let x of jt(w,0,w.length))r.push(x);w.delete(0,w.length)}}}return r}import*as pe from"yjs";var tr=1024,$t=1024,nr=1<<20,Pn="http://schemas.openxmlformats.org/drawingml/2006/main",or=()=>({left:nr,fields:new WeakMap,runs:new Map,paragraphs:new Map,seen:new Map,placed:new Map});function xt(t,e,o){let n=e.fields.get(t);if(n)return n;let r=!1,i=0,s=new Map,c=[];for(let[f,u]of t.entries())i+=1,ht(f)?(r=!0,c.push(f)):f.startsWith(oe.removedRun)&&typeof u=="string"&&s.set(f.slice(oe.removedRun.length),u);o&&Te(e,i);let l={removed:r,places:s,removedRuns:[...s.keys()].sort().slice(0,$t),removals:c.sort().slice(0,At)};return e.fields.set(t,l),l}var Te=(t,e=1)=>(t.left-=e)>=0;function vn(t){let e=t.get(A.children);if(!(e instanceof pe.Array))return[];let o=new Set;for(let n of e.slice(0,tr))typeof n=="string"&&o.add(n);return[...o]}function rr(t,e,o,n){let r=n.runs.get(e);if(r!==void 0)return r;let i=vn(o).some(s=>{if(!Te(n))return!1;let c=t.nodes.get(s);if(!(c instanceof pe.Map))return!1;let l=c.get(A.shell);return l?.ns!==Pn||l.local!=="t"?!1:vn(c).some(f=>{if(!Te(n))return!1;let u=t.nodes.get(f),a=u instanceof pe.Map?u.get(A.text):void 0;return a instanceof pe.Text&&a.length>0})});return n.runs.set(e,i),i}var sr=t=>(t.children??[]).some(e=>!("text"in e)&&e.local==="t"&&(e.children??[]).some(o=>"text"in o&&o.text.length>0));function ir(t,e,o){let n=o.seen.get(t);if(n)return n;let r=new Set,i=xt(e,o,!0);for(let s of i.removals){let c=e.get(s);if(!(!Array.isArray(c)||c.length>_e||!Te(o,c.length)))for(let l of c)typeof l=="string"&&r.add(l)}for(let s of i.removedRuns)r.add(s);return o.seen.set(t,r),r}function On(t){let e,o=new Map,n=()=>{let r=new Map;for(let[i,s]of t.nodes.entries()){if(!(s instanceof pe.Map))continue;let c=s.get(A.part),l=s.get(A.children);if(typeof c!="string"||!(l instanceof pe.Array))continue;let f=r.get(c);f||r.set(c,f=new Map);for(let u of l.toArray()){if(typeof u!="string")continue;let a=f.get(u);a?a.push(i):f.set(u,[i])}}return r};return r=>()=>(e??=n()).get(r)??o}var An=(t,e)=>({rescued:new Set,stranded:t,listings:e,walk:or()});function cr(t,e,o,n){return t.get(K.movedFrom)!==o?!1:(n().get(e)??[]).some(r=>r!==o)}function ar(t,e,o,n,r){let i=t.get(A.shell);if(i?.ns!==Pn||cr(t,e,o,r.listings))return null;let s=t.get(K.movedFrom);return(typeof t.get(K.splitFrom)=="string"||typeof s=="string"&&!r.stranded)&&!n().has(e)?null:i.local==="br"?n().has(e)?null:"br":i.local==="r"||i.local==="fld"?"run":null}function lr(t,e,o,n){let r=o.get(A.key),i=()=>ir(e.key,o,n.walk);for(let s of(e.children??[]).slice(0,tr)){if("text"in s)continue;if(!Te(n.walk))return!1;let c=t.nodes.get(s.key),l=c instanceof pe.Map?ar(c,s.key,r,i,n):null;if(l==="br"||l==="run"&&sr(s))return!0}return!1}function fi(t,e,o,n){let r=n.walk.paragraphs.get(e);if(r!==void 0)return r;let i=o.get(A.key),s=new Set(xt(o,n.walk,!0).removedRuns),c=()=>ir(e,o,n.walk),l=[...new Set([...vn(o),...s])].some(f=>{if(!Te(n.walk))return!1;let u=t.nodes.get(f);if(!(u instanceof pe.Map))return!1;let a=ar(u,f,i,c,n);if(a==="br")return!0;let g=s.has(f)&&!xt(u,n.walk,!0).removed;return a==="run"&&!g&&rr(t,f,u,n.walk)});return n.walk.paragraphs.set(e,l),l}function ui(t,e){let o=0,n=[t];for(;n.length>0&&o<e;){let r=n.pop();if(o+=1,!("text"in r))for(let i of r.children??[])n.push(i)}return o}function dr(t,e,o,n,r,i=An(new Set,On(t)(e))){let s=i.walk,c=xt(o,s,!1).places;if(c.size===0)return n;let l=new Set(n.map(b=>b.key)),f=o.get(A.key),u=o.get(A.shell)?.local==="txBody",a=u?"p":"r",g=u?["bodyPr","lstStyle"]:["pPr"],p=new Map,h=b=>{let v=r(b);return v&&Te(s,ui(v,nr))?v:null},d=(b,v)=>{p.set(b,v),s.placed.set(b,String(f))};for(let b of[...c.keys()].sort()){if(p.size>=$t||!Te(s))break;let v=s.placed.get(b);if(l.has(b)||v!==void 0&&v!==String(f))continue;let M=t.nodes.get(b);if(!(M instanceof pe.Map)||M.get(A.part)!==e)continue;let C=M.get(A.shell);if(C?.ns!==Pn||C.local!==a||!xt(M,s,!0).removed||cr(M,b,f,i.listings))continue;if(u){let j={stranded:i.stranded.has(b),listings:i.listings,walk:s};if(!fi(t,b,M,j))continue;let F=h(b);if(!F||!lr(t,F,M,j))continue;d(b,F),i.rescued.add(b);continue}let T=rr(t,b,M,s),R=h(b);R&&(T||sr(R))&&d(b,R)}if(p.size===0)return n;let m=b=>{let v=c.get(b)??"";for(let M=0;M<$t&&v!==""&&!l.has(v)&&!p.has(v);M+=1)v=c.get(v)??"";return l.has(v)||p.has(v)?v:""},S=new Map;for(let[b,v]of p){let M=m(b),C=S.get(M);C?C.push(v):S.set(M,[v])}let y=[],w=new Set,x=(b,v)=>{if(!(v>$t))for(let M of S.get(b)??[])w.has(M.key)||(w.add(M.key),y.push(M),x(M.key,v+1))},k=!1;for(let b of n)!k&&("text"in b||!g.includes(b.local))&&(k=!0,x("",0)),y.push(b),x(b.key,0);k||x("",0);for(let b of p.values())w.has(b.key)||y.push(b);return y}function fr(t,e,o){if(o.rescued.size===0)return e;let n=or(),r=s=>{if("text"in s||!o.rescued.has(s.key))return!0;let c=t.nodes.get(s.key),l={stranded:o.stranded.has(s.key),listings:o.listings,walk:n};return c instanceof pe.Map&&lr(t,s,c,l)},i=s=>{let c=s.children??[];if(!c.some(l=>!r(l))){let l=c.map(f=>"text"in f?f:i(f));return l.every((f,u)=>f===c[u])?s:{...s,children:l}}return{...s,children:c.filter(r).map(l=>"text"in l?l:i(l))}};return i(e)}import*as V from"yjs";import*as Se from"yjs";function ve(t){if(!(t instanceof Se.AbstractType))return null;let e=t._item;return e instanceof Se.Item?e:null}function ge(t,e,o){for(let[n,r]of e.clients){let i=t.store.clients.get(n);if(!(!i||i.length===0))for(let{clock:s,len:c}of r){let l=i[i.length-1];if(!(s>=l.id.clock+l.length))for(let f=Se.findIndexSS(i,s);f<i.length;f+=1){let u=i[f];if(u.id.clock>=s+c)break;u instanceof Se.Item&&o(u)}}}}function Gt(t,e,o){let n=Se.createDeleteSet();for(let[r,i]of e.clients){let s=t.store.clients.get(r),c=[];for(let{clock:l,len:f}of i){if(!s||s.length===0){c.push({clock:l,len:f});continue}let u=l+f,a=l,g=s[s.length-1];if(l<g.id.clock+g.length)for(let p=Se.findIndexSS(s,l);p<s.length;p+=1){let h=s[p];if(h.id.clock>=u)break;if(!(h instanceof Se.Item)||!o(h))continue;let d=Math.max(l,h.id.clock);d>a&&c.push({clock:a,len:d-a}),a=Math.min(u,h.id.clock+h.length)}u>a&&c.push({clock:a,len:u-a})}c.length>0&&n.clients.set(r,c)}return n}function*Nn(t){for(let e=t._start;e;e=e.right)e.deleted||(yield e)}function*ur(t){for(let e of t._map.values())e.deleted||(yield e)}function Xt(t,e){let o=0;for(let n=t._start;n!==null;n=n.right)if(!(n.deleted||!n.countable)){if(n.id.client===e.client&&e.clock>=n.id.clock&&e.clock<n.id.clock+n.length)return o+(e.clock-n.id.clock);o+=n.length}return-1}function $e(t,e){let o=[],n=0;for(let r=t._start;r!==null&&o.length<e.size;r=r.right)if(!(r.deleted||!r.countable)){for(let i=0;i<r.length;i+=1)e.has(`${r.id.client}:${r.id.clock+i}`)&&o.push(n+i);n+=r.length}for(let r=o.length-1;r>=0;){let i=r;for(;i>0&&o[i-1]===o[i]-1;)i-=1;t.delete(o[i],o[r]-o[i]+1),r=i-1}}var pr=t=>t.left===null;var Ce="pptx-undone-v1",pi=64,gr=1024,gi=1<<18,hi=(t,e)=>t.id.client!==e.client||t.id.clock>=e.clock;function mi(t,e,o){if(typeof e!="object"||e===null)return null;let n=e;if(typeof n.p!="string"||o!==void 0&&n.p!==o||typeof n.u!="string"||typeof n.a!="string"||!Number.isSafeInteger(n.c)||n.c<0)return null;let r=Number.isSafeInteger(n.q)&&n.q>=0?n.q:1/0,i=typeof n.n=="string"?n.n:"",s=typeof n.s=="string"?n.s:null;return{key:t,parent:n.u,after:n.a,before:i,client:n.c,clock:r,shownIn:s}}function yr(t,e,o,n=new Set){let r=t.nodes,i=new Map,s=new Set;if(ge(t.doc,e.insertions,a=>{a.parent===t.parts&&a.parentSub!==null&&!a.deleted&&s.add(a.parentSub)}),ge(t.doc,e.insertions,a=>{let g=a.parent;if(a.deleted||!(g instanceof V.Array))return;let p=g.parent;if(!(p instanceof V.Map)||ve(p)?.parent!==r||p.get(A.children)!==g||a.parentSub!==null||!(a.content instanceof V.ContentAny))return;let h=i.get(g);h||i.set(g,h=new Set);for(let d of a.content.getContent())typeof d=="string"&&h.add(d)}),i.size===0)return;for(let a of i.values())for(let g of n)a.delete(g);let c=t.doc.getMap(Ce),l=t.doc.clientID,f=V.getState(t.doc.store,l),u=[];for(let[a,g]of i){let p=a.parent;if(!(p instanceof V.Map)||p.get(A.children)!==a)continue;let h=p.get(A.key),d=p.get(A.part);if(typeof h!="string"||typeof d!="string"||s.has(d))continue;let m=a.toArray().filter(S=>typeof S=="string");m.forEach((S,y)=>{if(!g.has(S))return;let w=m[y+1]??"",x={p:d,u:h,a:m[y-1]??"",n:w,c:l,q:f};JSON.stringify(c.get(S))!==JSON.stringify(x)&&u.push([S,x])})}u.length>0&&o(()=>{for(let[a,g]of u)c.set(a,g)})}function kr(t,e,o,n,r,i){let s=t.doc.getMap(Ce),c=t.doc.clientID,l=new Set;for(let f of r){let u=n[f],a=typeof u=="string"?i(u):void 0;if(typeof u!="string"||a===void 0||l.has(u))continue;l.add(u);let g="";for(let d=f-1;d>=0&&g==="";d-=1)n[d]!==u&&typeof n[d]=="string"&&(g=n[d]);let p="";for(let d=f+1;d<n.length&&p==="";d+=1)n[d]!==u&&typeof n[d]=="string"&&(p=n[d]);let h={p:e,u:o,a:g,n:p,c,q:0,s:a};JSON.stringify(s.get(u))!==JSON.stringify(h)&&s.set(u,h)}}function wr(t,e,o){let n=t.doc.getMap(Ce);if(n.size===0)return;let r=new Set;ge(t.doc,e.deletions,i=>{if(!(!(i.parent instanceof V.Array)||!(i.content instanceof V.ContentAny)))for(let c of i.content.getContent())typeof c=="string"&&n.has(c)&&r.add(c)}),r.size>0&&o(()=>{for(let i of r)n.delete(i)})}function Sr(t,e,o){let n=new Map;if(ge(t.doc,e.insertions,s=>{if(s.parent!==t.nodes||s.parentSub===null||!(s.content instanceof V.ContentType)||!(s.content.type instanceof V.Map))return;let c=s.content.type;if(t.nodes.get(s.parentSub)!==c)return;let l=c.get(A.part),f=c.get(A.attrs),u=c.get(A.children);if(typeof l!="string"||!(f instanceof V.Map)||!(u instanceof V.Array)||f.size>0||u.length>0||!o(l,s.parentSub))return;let a=n.get(l);a||n.set(l,a=new Set),a.add(s.parentSub)}),n.size===0)return!1;let r=!1,i=0;for(let s of t.nodes.values()){if((i+=1)>gi)break;if(!(s instanceof V.Map))continue;let c=s.get(A.part),l=typeof c=="string"?n.get(c):void 0,f=s.get(A.children);if(!l||!(f instanceof V.Array))continue;let u=f.toArray();for(let a=u.length-1;a>=0;a-=1){let g=u[a];typeof g=="string"&&l.has(g)&&(f.delete(a,1),r=!0)}}return r}var hr=new WeakMap;function mr(t,e,o){let n=t.placeOf.get(e);if(n){let l=t.byPart.get(n.part),f=l?.get(n.parent);f?.delete(e),f?.size===0&&l.delete(n.parent),t.placeOf.delete(e)}let r=o===void 0?null:mi(e,o),i=r?o.p:null;if(!r||i===null)return;let s=t.byPart.get(i);s||t.byPart.set(i,s=new Map);let c=s.get(r.parent);c||s.set(r.parent,c=new Map),c.set(e,r),t.placeOf.set(e,{part:i,parent:r.parent})}function yi(t,e){let o=t.doc.getMap(Ce),n=hr.get(o);if(!n){let r={byPart:new Map,placeOf:new Map};n=r;for(let[i,s]of o.entries())mr(r,i,s);hr.set(o,r),o.observe(i=>{for(let s of i.keysChanged)mr(r,s,o.get(s))})}return n.byPart.get(e)??new Map}var Tn="http://schemas.openxmlformats.org/drawingml/2006/main",xr=new Set(["p","pPr","rPr","endParaRPr","ln","bodyPr","tcPr"]);function Mr(t){if("text"in t)return t.text.length>0;if(t.ns!==Tn)return!1;let e=t.children??[];return t.local==="r"?e.some(o=>!("text"in o)&&o.ns===Tn&&o.local==="t"&&Mr(o)):t.local==="t"?e.some(o=>"text"in o&&o.text.length>0):xr.has(t.local)&&(e.length>0||(t.attrs??[]).length>0)}var Bt=class t{#e;#t;#n;#i=new Map;shown=new Set;constructor(e,o,n){this.#e=e,this.#t=o,this.#n=n}static of(e,o,n){if(e.doc.getMap(Ce).size===0)return null;let r=yi(e,o);if(r.size===0)return null;let i=new Set,s=[n];for(;s.length>0;){let c=s.pop();if(i.has(c))continue;i.add(c);let l=e.nodes.get(c);if(!(l instanceof V.Map)||l.get(A.part)!==o)continue;let f=l.get(A.children);if(f instanceof V.Array)for(let u of f.toArray())typeof u=="string"&&!i.has(u)&&s.push(u)}return new t(e,r,i)}#r(e,o,n){let r=`${e}\0${o.client}\0${o.clock}`,i=this.#i.get(r);if(i!==void 0)return i;this.#i.set(r,!1);let s=n<=pi&&this.#d(e,o,n);return this.#i.set(r,s),s}#d(e,o,n){let r=this.#e.nodes.get(e);if(!(r instanceof V.Map))return!1;let i=u=>hi(u,o),s=r.get(A.text);if(s instanceof V.Text){for(let u of Nn(s))if(u.countable&&i(u))return!0}let c=r.get(A.attrs);if(c instanceof V.Map){for(let u of ur(c))if(i(u))return!0}let l=r.get(A.children);if(l instanceof V.Array){for(let u of Nn(l))if(i(u))return!0}let f=[];for(let u of r.keys())u.startsWith(oe.removedRun)&&f.push(u);for(let u of f.sort().slice(0,gr))if(this.#r(u.slice(oe.removedRun.length),o,n+1))return!0;return this.#s(e).some(u=>this.#r(u.key,u,n+1))}#s(e){return[...this.#t.get(e)?.values()??[]].filter(o=>{if(this.#n.has(o.key)||o.shownIn!==null&&!this.#n.has(o.shownIn))return!1;let n=this.#e.nodes.get(o.key);return n instanceof V.Map&&!Ie(n)})}withUndone(e,o,n,r,i){let s=this.#s(e).filter(g=>!r.has(g.key)&&this.#r(g.key,g,0)).sort((g,p)=>g.key<p.key?-1:g.key>p.key?1:0).slice(0,gr);if(s.length===0)return n;let c=[...n],l=new Set(c.map(g=>g.key)),f=new Map([...this.#t.get(e)?.values()??[]].map(g=>[g.key,g.after])),u=new Set(s.map(g=>g.key)),a="\0";for(let g=!1;u.size>0;){let p=!1;for(let h of s){if(!u.has(h.key))continue;let d=h.after,m=d!==""&&!l.has(d)&&!u.has(d)&&l.has(h.before)?h.before:null;m!==null&&(d=a);let S=new Set([h.key]),y=!1;for(;d!==""&&d!==a&&!l.has(d);){if(u.has(d)&&!g){y=!0;break}S.has(d)?d=a:(S.add(d),d=f.get(d)??a)}if(y)continue;u.delete(h.key),p=!0;let w=this.#c(h.key,o,r,i);if(!w||!Mr(w))continue;let x=m!==null?c.findIndex(k=>k.key===m):d===""?0:d===a?c.length:c.findIndex(k=>k.key===d)+1;c.splice(x,0,w),l.add(h.key),this.shown.add(h.key)}p||(g=!0)}return c}#c(e,o,n,r){let i=this.#e.nodes.get(e);if(!(i instanceof V.Map)||i.get(A.part)!==o)return null;let s=i.get(A.text);if(s instanceof V.Text)return n.add(e),{key:e,text:s.toString()};let c=i.get(A.shell),{ns:l,local:f}=typeof c=="object"&&c!==null?c:{};return l!==Tn||typeof f!="string"||!xr.has(f)&&f!=="r"&&f!=="t"?null:r(e)}};import*as Rr from"yjs";var ki="http://schemas.openxmlformats.org/drawingml/2006/main";function Yr(t){let e=new Map;if(!t)return e;let o=[t];for(;o.length>0;){let n=o.pop();if(e.set(n.id,n),n.type==="element")for(let r of n.children)o.push(r)}return e}function wi(t,e){let o=t.length,n=e.length,r=new Uint32Array((o+1)*(n+1));for(let f=o-1;f>=0;f--)for(let u=n-1;u>=0;u--)r[f*(n+1)+u]=t[f]===e[u]?r[(f+1)*(n+1)+u+1]+1:Math.max(r[(f+1)*(n+1)+u],r[f*(n+1)+u+1]);let i=new Set,s=new Set,c=0,l=0;for(;c<o&&l<n;)t[c]===e[l]?(i.add(c++),s.add(l++)):r[(c+1)*(n+1)+l]>=r[c*(n+1)+l+1]?c++:l++;return{keepA:i,keepB:s}}function Cn(t,e){let o=t.toArray();if(o.length===e.length&&o.every((s,c)=>s===e[c]))return;if(o.length*e.length>25e4){t.delete(0,o.length),t.insert(0,[...e]);return}let{keepA:n,keepB:r}=wi(o,e);for(let s=o.length-1;s>=0;s--)n.has(s)||t.delete(s,1);let i=0;e.forEach((s,c)=>{r.has(c)||t.insert(i,[s]),i+=1})}function Er(t,e){if(t.size===0)return t;let o=Tt(e);return new Map([...t].filter(([n])=>o.has(n)))}function br(t){let e=new Map;if(t?.kind!=="xml")return e;let o=[[t.xml.root,""]];for(;o.length>0;){let[n,r]=o.pop();if(e.set(n.id,r),n.type==="element")for(let i of n.children)o.push([i,`${n.id}/${r}`])}return e}function Ir(t,e,o){let n,r;return i=>{let s=t?.get(i);if(s===void 0)return!1;n??=br(e),r??=br(o);let c=n.get(s);return c!==void 0&&c===r.get(s)}}function vr(t,e,o){let n;return r=>{let i=t?.get(r);if(i===void 0||o?.kind!=="xml")return;if(!n){let c=new Map,l=[o.xml.root];for(;l.length>0;){let f=l.pop();if(f.type==="element")for(let u of f.children)c.set(u.id,f.id),l.push(u)}n=c}let s=n.get(i);return s===void 0?void 0:e?.get(s)}}function Pr(t,e,o){let n=t.toString();if(n===e)return;let r=0;for(;r<n.length&&r<e.length&&n[r]===e[r];)r++;let i=0;for(;i<n.length-r&&i<e.length-r&&n[n.length-1-i]===e[e.length-1-i];)i++;let s=p=>p>=55296&&p<=56319,c=p=>p>=56320&&p<=57343;r>0&&s(n.charCodeAt(r-1))&&r--,i>0&&c(n.charCodeAt(n.length-i))&&i--;let l=n.length-r-i,f=e.length-r-i;if(l===f&&!/[\uD800-\uDFFF]/.test(n.slice(r,r+l)+e.slice(r,r+f))){let p=jt(t,r,l),h=[];for(let d=r;d<r+l;d++){if(n[d]===e[d])continue;let m=p[d-r];m&&h.push(m),t.insert(d,e[d]),t.delete(d+1,1)}return{created:o,deleted:h}}let u=l>0?jt(t,r,l):[];l>0&&t.delete(r,l);let a=t.doc,g=a?Rr.getState(a.store,a.clientID):0;return f>0&&t.insert(r,e.slice(r,e.length-i)),{created:o,deleted:u,...f>0&&a?{inserted:{client:a.clientID,clock:g,length:f}}:{}}}function Or(t,e){let o=new Map,n=new Set;if(e.size===0)return{inParent:o,watch:n};let r=new Map,i=[t];for(;i.length>0;){let s=i.pop();for(let c of s.children??[])"text"in c||(r.set(c.key,s.key),e.has(c.key)&&c.ns===ki&&Si.has(c.local)&&o.set(c.key,s.key),i.push(c))}for(let s of o.values()){n.add(s);let c=r.get(s);c!==void 0&&n.add(c)}return{inParent:o,watch:n}}var Si=new Set(["r","br","fld"]);var Mi="http://schemas.openxmlformats.org/drawingml/2006/main",bi=1<<20,Ar=(t,e)=>t.attrs.find(o=>o.ns===""&&o.local===e)?.value,Ri=t=>({ns:t.ns,local:t.local,...t.prefix?{prefix:t.prefix}:{},nsDecls:t.nsDecls.map(e=>({prefix:e.prefix,uri:e.uri}))}),Ut=class{#e;#t=new Map;#n=new Map;#i=new Map;#r=new Set;#d=new Map;#s=new Map;#c=new Map;#h=new Map;#S=new Set;#f=new Set;#a=new Map;#l=new Map;#u=ut;#p=null;#x;#M=new Map;#m=new Map;#b;#y=new Set;constructor(e,o={value:0}){this.#e=e,this.#b=o;let n=`${e.doc.clientID.toString(36)}.`;for(let r of e.nodes.keys()){if(!r.startsWith(n))continue;let i=Number.parseInt(r.slice(n.length).replace(Pt,""),36);Number.isSafeInteger(i)&&i<=Zn&&i>o.value&&(o.value=i)}}get seeded(){return this.#e.parts.size>0}#E(e,o){for(let n of this.#i.get(e)??[])this.#n.delete(n);for(let[n,r]of o)this.#n.set(n,r);this.#i.set(e,new Set(o.keys())),this.#r.clear(),this.#M.clear();for(let[n,r]of this.#n)for(let i of r.companions)this.#r.add(i),this.#M.set(i,n)}#R(e,o){for(let n of this.#t.get(e)?.idOf.keys()??[])this.#m.delete(n);if(!o){this.#t.delete(e);return}this.#t.set(e,o);for(let n of o.idOf.keys())this.#m.set(n,e)}#P(e){let o=this.#t.get(e);return o||(o={keyOf:new Map,idOf:new Map},this.#t.set(e,o)),o}#k=!1;#O(){let e=this.#e.doc.clientID.toString(36),o=this.#k?Pt:"",n;do this.#b.value+=1,n=`${e}.${o}${this.#b.value.toString(36)}`;while(this.#e.nodes.has(n));return n}seed(e){this.#k=!0;try{for(let o of e.parts.values())this.#I(o,void 0)}finally{this.#k=!1}}hasHiddenListings(e){return e.some(o=>this.#a.has(o))}dropHiddenListings(e,o,n){for(let r of e){let i=this.#a.get(r);if(!i)continue;let s=Ir(this.#t.get(r)?.idOf,o.parts.get(r),n.parts.get(r)),c=this.#t.get(r),l=vr(c?.idOf,c?.keyOf,o.parts.get(r));this.#a.delete(r);for(let[f,u]of i){let a=this.#v(f);if(!a||a.length!==u.length)continue;let g=[...u.at.keys()].sort((h,d)=>d-h);if(g.some(h=>a.get(h)!==u.at.get(h)))continue;let p=g.filter(h=>s(u.at.get(h)));p.length>0&&kr(this.#e,r,f,a.toArray(),p,l);for(let h=0;h<g.length;){let d=h+1;for(;d<g.length&&g[d]===g[d-1]-1;)d++;a.delete(g[d-1],d-h),h=d}}}}writeChange(e,o,n){for(let r of n){this.#S.delete(r);let i=o.parts.get(r);if(!i){this.#e.parts.delete(r),this.#e.binaries.delete(r),this.#R(r,void 0);continue}this.#I(i,e.parts.get(r))}}#I(e,o){if(e.kind==="binary"){(o?.kind!=="binary"||o.bytes!==e.bytes)&&this.#e.binaries.set(e.partName,e.bytes),He(this.#e.parts.get(e.partName))?.kind!=="binary"&&this.#e.parts.set(e.partName,{kind:"binary"});return}o?.kind==="binary"&&this.#e.binaries.delete(e.partName);let n={partName:e.partName,ids:this.#P(e.partName),before:Yr(o?.kind==="xml"?o.xml.root:void 0),texts:new Map},r=this.#Y(e.xml.root,n),i=this.#s.get(e.partName);this.#s.delete(e.partName);for(let c of _o(e.xml.root,i,n.ids.keyOf))this.#Y(c,{...n,before:Lo(n.before,c.id)});wo(this.#e,e.partName,e.xml.root,n.before,n.ids.keyOf),Do(this.#e,e.xml.root,n.before,n.ids.keyOf),this.#A(e.partName,e.xml.root,n);let s=He(this.#e.parts.get(e.partName));(s?.kind!=="xml"||s.root!==r)&&this.#e.parts.set(e.partName,{kind:"xml",root:r})}#A(e,o,n){if(this.#k)return;let r=Zo(this.#e,e,o,n.before,n.ids.keyOf,n.texts),i=er(this.#e,o,n.before,n.ids.keyOf),s=this.#e.doc,c=new Map,l=f=>{if(this.#y.size>=bi||r.has(U(f.client,f.clock)))return;let u=ue(s,f,c,!1);this.#y.add(U(u.client,u.clock))};for(let f of n.texts.values())for(let u of f.deleted)l(u);for(let f of i)l(f)}get deletedText(){return this.#y}showingUnlisted(e){return e.filter(o=>(this.#c.get(o)?.size??0)>0||this.#S.has(o))}forgetDeleted(e){for(let o of e)this.#y.delete(o)}newCopies(e){let o=new Map,n=e.changed.get(this.#e.nodes);if(!n)return o;let r=this.#e.doc.getMap(We);for(let i of n){if(i===null)continue;let s=r.get(i),c=this.#e.nodes.get(i),l=Ae(c);if(typeof s!="string"||!l||l.client===this.#e.doc.clientID||c.get(A.part)!==s)continue;let f=o.get(s);f?f.push(i):o.set(s,[i])}return o}#Y(e,o){let{partName:n,ids:r,before:i}=o,s=r.keyOf.get(e.id),c=s===void 0?void 0:this.#e.nodes.get(s);if(s!==void 0&&c instanceof B.Map&&i.get(e.id)===e)return s;s!==void 0&&this.#h.get(n)?.watch.has(s)&&this.#S.add(n);let l=s===void 0||!(c instanceof B.Map);if(s===void 0||!(c instanceof B.Map)){s=this.#O();let R=new B.Map;this.#e.nodes.set(s,R),R.set(A.part,n),R.set(A.key,s),e.type==="text"?R.set(A.text,new B.Text):(R.set(A.attrs,new B.Map),R.set(A.children,new B.Array)),c=R,r.keyOf.set(e.id,s),r.idOf.set(s,e.id),this.#m.set(s,n)}let f=c;if(e.type==="text"){let R=f.get(A.text),j=R instanceof B.Text?Pr(R,e.value,l):void 0;return j&&o.texts.set(s,j),s}let u=Ri(e);JSON.stringify(f.get(A.shell))!==JSON.stringify(u)&&f.set(A.shell,u);let a=this.#n.get(s),g=this.#e.doc.clientID.toString(36),p=a?.merge?[s,...a.companions].find(R=>me(R)===g)??s:s,h=f.get(A.attrs);if(h instanceof B.Map){let R=new Map;for(let F of e.attrs)R.set(`${F.ns}${Yt}${F.local}`,{ns:F.ns,local:F.local,value:F.value,...F.prefix?{prefix:F.prefix}:{}});let j=a?.merge?a.companions.map(F=>this.#w(F)):[];for(let F of[...h.keys()])R.has(F)||h.delete(F);for(let F of j)for(let P of[...F?.keys()??[]])R.has(P)||F.delete(P);for(let[F,P]of R){let D=a?.attrFrom.get(F)??(h.has(F)?s:void 0),I=D===void 0?void 0:this.#w(D);if(I&&JSON.stringify(I.get(F))===JSON.stringify(P))continue;if((this.#w(p)??h).set(F,P),a?.merge)for(let N of[s,...a.companions])N!==p&&this.#w(N)?.delete(F)}}let d=e.children.map(R=>this.#Y(R,o)),m=new Set(d),S=f.get(A.children),y=(R,j)=>{let F=[],P=new Set,D=I=>{P.has(I)||(P.add(I),F.push(I))};for(let I of R){D(I);for(let _ of this.#n.get(I)?.companions??[])j.has(_)&&D(_)}return F},w=new Set(S instanceof B.Array?S.toArray():[]),x=this.#c.get(n),k=this.#h.get(n)?.inParent,b=k&&k.size>0?{has:R=>x?.has(R)===!0||k.get(R)===s}:x,v=a?d.filter(R=>!a.childFrom.has(R)&&!w.has(R)&&!b?.has(R)):[],M=(a?d.filter(R=>!a.childFrom.has(R)&&(w.has(R)||p===s)):d).filter(R=>!b?.has(R)||w.has(R));if(S instanceof B.Array){let R=S,j=R.toArray();Cn(R,Ro(j,this.#N(e,j,y(M,new Set(j))),this.#d.get(n)))}let C=new Set;if(a?.merge)for(let R of e.children)R.type==="element"&&C.add(Ve(e,R,j=>Ar(R,j))?.slot);let T=new Set(v);a?.merge&&e.children.forEach((R,j)=>{R.type==="element"&&T.has(d[j])&&C.delete(Ve(e,R,F=>Ar(R,F))?.slot)});for(let R of a?.merge?a.companions:[]){let j=this.#v(R);if(!j)continue;let F=j.toArray(),P=F.filter(D=>{if(this.#r.has(D))return m.has(this.#M.get(D));if(a.childFrom.get(D)===R)return m.has(D);let I=a.shadowed.get(D);return I!==void 0&&C.has(I)});Cn(j,y([...P,...R===p?v:[]],new Set(F)))}return s}#N(e,o,n){let r=new Set(n),i=new Set(o),s=o.filter(p=>r.has(p)),c=n.filter(p=>i.has(p)),l=(p,h)=>p.length===h.length&&p.every((d,m)=>d===h[m]);if(l(s,c)||!l(qe(e,s,p=>this.#T(p)),c))return n;let f=new Map,u=[],a;for(let p=n.length-1;p>=0;p--){let h=n[p];if(i.has(h))a=h;else if(a===void 0)u.unshift(h);else{let d=f.get(a);d||f.set(a,d=[]),d.unshift(h)}}let g=[];for(let p of s){for(let h of f.get(p)??[])g.push(h);g.push(p)}for(let p of u)g.push(p);return g}#T(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.shell):void 0;if(typeof n!="object"||n===null)return;let{ns:r,local:i}=n;return typeof r=="string"&&typeof i=="string"?{ns:r,local:i}:void 0}#w(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.attrs):void 0;return n instanceof B.Map?n:void 0}#v(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.children):void 0;return n instanceof B.Array?n:void 0}keyOf(e,o){return this.#t.get(e)?.keyOf.get(o)}idOf(e,o){return this.#t.get(e)?.idOf.get(o)}textOf(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.text):void 0;return n instanceof B.Text?n:void 0}partOf(e){let o=this.#e.nodes.get(e),n=o instanceof B.Map?o.get(A.part):void 0;return typeof n=="string"?n:void 0}recordOfText(e){let o=e.parent,n=o instanceof B.Map?o.get(A.key):void 0;if(typeof n!="string"||this.#e.nodes.get(n)!==o)return;let r=o.get(A.part);return typeof r=="string"?{key:n,part:r}:void 0}touchedParts(e){let o=new Set,n=this.#e.parts,r=this.#e.binaries,i=this.#e.nodes,s=this.#e.doc,c=[s.getMap(Le),s.getMap(gt)],l=s.getMap(Ot),f=s.getMap(Ce);for(let[u,a]of e.changed){let g=u;if(g===n||g===r){for(let d of a)d!==null&&o.add(d);continue}if(c.includes(g)){for(let d of a){let m=d===null?void 0:u.get(d);typeof m=="string"&&o.add(m)}continue}if(g===f){for(let d of a){if(d===null)continue;let m=this.#e.doc.getMap(Ce).get(d),S=typeof m=="object"&&m!==null?m.p:void 0,y=this.#e.nodes.get(d),w=typeof S=="string"?S:y instanceof B.Map?y.get(A.part):void 0;typeof w=="string"&&o.add(w)}continue}if(g===l){for(let d of a){let m=d===null?void 0:this.#e.nodes.get(d.split("\0")[0]),S=m instanceof B.Map?m.get(A.part):void 0;typeof S=="string"&&o.add(S)}continue}if(g===i){for(let d of a){if(d===null)continue;let m=this.#e.nodes.get(d),S=m instanceof B.Map?m.get(A.part):void 0;if(typeof S=="string"){o.add(S);continue}let y=this.#m.get(d);y!==void 0&&o.add(y)}continue}let p=g;for(;p instanceof B.AbstractType&&p.parent!==i;)p=p.parent;let h=p instanceof B.Map?p.get(A.part):void 0;typeof h=="string"&&o.add(h)}return o}allParts(e){let o=new Set(this.#e.parts.keys());for(let n of e.parts.keys())o.add(n);return o}rebuild(e,o,n=!1){let r=[],i=[],s=new Map,c=new Map,l=new Map,f=new Map,u=new Map,a=[...e];for(let d of a)[this.#a,this.#s].forEach(m=>m.delete(d));let g=new Map,p=new Map,h=On(this.#e);for(let d of a){let m=He(this.#e.parts.get(d));if(!m){if(this.#e.parts.has(d))return{ok:!1,reason:`invalid part entry ${d}`};o.parts.has(d)&&i.push(d);continue}if(m.kind==="binary"){let _=this.#e.binaries.get(d);if(!(_ instanceof Uint8Array)||_.length>ct.maxBinaryBytes)return{ok:!1,reason:`invalid binary part ${d}`};r.push({kind:"binary",partName:d,bytes:_});continue}let S=new Map;this.#f=new Set,this.#o=void 0,this.#u=mt(this.#e,d,m.root),this.#l=new Map,this.#p=Bt.of(this.#e,d,m.root);let y=(_,N,z)=>this.#g(_,d,N,z,S),w=new Set,x=new Set,k=h(d),b=(_=new Set)=>{w=new Set,x=new Set,this.#x=An(_,k);let N=this.#g(m.root,d,new Set,0,S);return N&&Io(this.#e,d,N,y,w,x)},v=b(),M=this.#u;if(v&&(M.lost.size>0||M.unseenWinners.size>0)){let _=mt(this.#e,d,m.root,Tt(v));vo(_,M)||(this.#u=_,this.#f=new Set,this.#l=new Map,S.clear(),v=b())}if(v&&x.size>0&&(this.#f=new Set,this.#l=new Map,S.clear(),v=b(x)),!v)return{ok:!1,reason:`${this.#o??"invalid node records"} in ${d}`};let C=fr(this.#e,Yo(this.#e,d,v,y,this.#u.lost),this.#x);if(this.#o)return{ok:!1,reason:`${this.#o} in ${d}`};let T=new Set,R=zo(this.#e,C,w,T);u.set(d,T);let j=n?void 0:this.#t.get(d),F=o.parts.get(d),P=F?.kind==="xml"?F.xml.nextId:1,D=xi(d,R,{idOf:_=>j?.idOf.get(_),nextId:P});if(!D.ok)return{ok:!1,reason:`${d}: ${D.reason}`};let I={keyOf:new Map,idOf:new Map};for(let[_,N]of D.ids)I.idOf.set(_,N),I.keyOf.set(N,_);s.set(d,I),c.set(d,S),l.set(d,this.#f),f.set(d,Er(this.#l,R)),g.set(d,this.#p?.shown??new Set),p.set(d,Or(R,w)),r.push({kind:"xml",partName:d,xml:D.part})}for(let[d,m]of s)this.#R(d,m);for(let d of i)this.#R(d,void 0);for(let[d,m]of c)this.#E(d,m);for(let d of i)this.#E(d,new Map);for(let[d,m]of l)this.#d.set(d,m);for(let d of i)this.#d.delete(d);for(let[d,m]of f)m.size>0&&this.#a.set(d,m);for(let d of i)this.#a.delete(d);for(let[d,m]of g)this.#c.set(d,m);for(let[d,m]of p)this.#h.set(d,m);for(let d of i)this.#h.delete(d);for(let d of i)this.#c.delete(d);for(let[d,m]of u)this.#s.set(d,m);return this.#p=null,{ok:!0,parts:r,removed:i}}#o;#g(e,o,n,r,i){if(r>ct.maxReadDepth||n.has(e))return null;n.add(e);let s=this.#e.nodes.get(e);if(!(s instanceof B.Map)||s.get(A.part)!==o)return null;let c=s.get(A.shell),l=s.get(A.attrs),f=s.get(A.children);if(typeof c!="object"||c===null||!(l instanceof B.Map)||!(f instanceof B.Array))return null;let u=c,a=[],g=f.toArray();for(let[x,k]of g.entries()){if(typeof k!="string")continue;if(n.has(k)){let M=this.#l.get(e);M||this.#l.set(e,M={length:g.length,at:new Map}),M.at.set(x,k);continue}let b=this.#e.nodes.get(k);if(b instanceof B.Map&&b.get(A.text)instanceof B.Text){if(b.get(A.part)!==o)continue;n.add(k),a.push({key:k,text:b.get(A.text).toString()});continue}let v=this.#g(k,o,n,r+1,i);if(v)a.push(v);else if(this.#o)return null}let p=[...l.entries()].sort(([x],[k])=>x<k?-1:x>k?1:0).map(([,x])=>x),h=u.ns,d=u.local,m=d==="p"&&h===Mi||In({ns:h,local:d})?dr(this.#e,o,s,a,x=>{let k=this.#g(x,o,n,r+1,i);return this.#o?null:k},this.#x):a,S=this.#p?this.#p.withUndone(e,o,m,n,x=>this.#g(x,o,n,r+1,i)):m;if(this.#o)return null;let y=bo(this.#e,{ns:h,local:d},S,this.#f,this.#u.unseenWinners),w=pn({ns:h,local:d},y,i);return w?{key:e,ns:h,local:d,...typeof u.prefix=="string"?{prefix:u.prefix}:{},nsDecls:Array.isArray(u.nsDecls)?u.nsDecls:[],attrs:p,children:[...qe({ns:h,local:d},w,x=>"text"in x?void 0:x)]}:(this.#o="too many concurrent copies of one element",null)}};import*as be from"yjs";var Ht="pptxEditor",Yi=256,Tr=256,Cr=512,Dr=256,Lr=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,Ge=(t,e=Yi)=>typeof t=="string"&&t.trim().length>0&&t.length<=e;function _r(t){return!Ge(t.actorId)||!Ge(t.name)||t.role!==void 0&&t.role!=="human"&&t.role!=="agent"?"invalid-identity":t.color!==void 0&&!Lr.test(t.color)?"invalid-identity-color":null}function Fr(t){let{actorId:e,name:o,color:n,role:r}=t;return!Ge(e)||!Ge(o)?null:{actorId:e,name:o,...typeof n=="string"&&Lr.test(n)?{color:n}:{},...r==="human"||r==="agent"?{role:r}:{}}}function zr(t){let e=t?.[Ht];return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function jr(t,e){if(t.kind==="shapes"){let i=t.shapes.slice(0,Cr).map(s=>e.keyOf(t.part,s)).filter(s=>s!==void 0);return i.length>0?{kind:"shapes",part:t.part,keys:i}:void 0}let o=i=>{let s=e.keyOf(t.part,i.node);if(s===void 0)return;let c=e.textOf(s);if(!c)return{key:s};let l=Math.max(0,Math.min(Math.trunc(i.offset)||0,c.length));return{rel:be.relativePositionToJSON(be.createRelativePositionFromTypeIndex(c,l))}},n=o(t.anchor),r=o(t.head);return n&&r?{kind:"text",anchor:n,head:r}:void 0}function Wr(t,e){return{actorId:t.actorId,name:t.name,...t.color?{color:t.color}:{},...t.role?{role:t.role}:{},...e?{selection:e}:{}}}function Kr(t){let e=[];for(let[o,n]of t.getStates()){if(e.length>=Tr)break;let r=zr(n),i=r?Fr(r):null;i&&e.push({...i,isLocal:o===t.clientID})}return e}function Nr(t,e,o){if(typeof t!="object"||t===null)return null;let n=t;if(Ge(n.key,Dr)){let l=o.partOf(n.key),f=l?o.idOf(l,n.key):void 0;return l&&f?{part:l,node:f,offset:0}:null}let r=n.rel;if(typeof r!="object"||r===null)return null;let i;try{i=be.createAbsolutePositionFromRelativePosition(be.createRelativePositionFromJSON(r),e)}catch{return null}if(!i||!(i.type instanceof be.Text))return null;let s=o.recordOfText(i.type),c=s?o.idOf(s.part,s.key):void 0;return s&&c?{part:s.part,node:c,offset:i.index}:null}function Vt(t,e,o){if(typeof t!="object"||t===null)return null;let n=t;if(n.kind==="shapes"&&Ge(n.part,1024)&&Array.isArray(n.keys)){let r=n.part,i=n.keys.slice(0,Cr).filter(s=>Ge(s,Dr)).map(s=>o.idOf(r,s)).filter(s=>s!==void 0);return i.length>0?{kind:"shapes",part:r,shapes:i}:null}if(n.kind==="text"){let r=Nr(n.anchor,e,o),i=Nr(n.head,e,o);return!r||!i||r.part!==i.part?null:{kind:"text",part:r.part,anchor:{node:r.node,offset:r.offset},head:{node:i.node,offset:i.offset}}}return null}function $r(t,e,o){let n=[],r=0;for(let[i,s]of t.getStates()){if(++r>Tr)break;if(i===t.clientID)continue;let c=zr(s),l=c?Fr(c):null;if(!c||!l)continue;let f=Vt(c.selection,e,o);f&&n.push({actorId:l.actorId,name:l.name,...l.color?{color:l.color}:{},selection:f})}return n}import*as H from"yjs";var Ei=4096,Xr=1<<20,Ii=65536,vi=1<<20,Gr="http://schemas.openxmlformats.org/drawingml/2006/main",Pi=t=>t.type==="element";function Oi(t,e){let o=ye(t,e);if(!o)return null;let n=0;for(let r=o.parent instanceof H.Text?o.parent._start:null;r;r=r.right){if(r===o)return{text:o.parent,at:n+(e.clock-o.id.clock)};n+=r.length}return null}function Ai(t,e){let o=new Map,n=t.package.parts.get(e);if(n?.kind!=="xml")return o;let r=(i,s,c)=>{let l=t.keyOf(e,i.id),f=i.ns===Gr&&i.local==="p"&&l&&c?{p:{key:l,parent:c}}:i.ns===Gr&&i.local==="r"&&l?{...s,run:l}:s;for(let u of i.children)if(Pi(u))r(u,f,l);else{let a=t.keyOf(e,u.id);a!==void 0&&o.set(a,{order:o.size,...f})}};return r(n.xml.root,{},void 0),o}function Br(t,e,o,n,r,i,s){let c=t.doc,l=c.clientID,f=O=>{let E=t.nodes.get(O),L=Ae(E),$=E instanceof H.Map?E.get(A.text):void 0;return!L||!($ instanceof H.Text)||E.get(A.part)!==e?null:{key:O,copy:L,text:$}},u=new Set(o.filter(O=>{let E=f(O);return E!==null&&E.copy.client!==l}));if(u.size===0)return;let a=Ai(r,e),g=[],p=0;for(let[O,E]of t.doc.getMap(We).entries()){if(E!==e)continue;let L=f(O);if(!(!L||L.text.length===0&&!a.has(O))){if(g.length>=Ei||(p+=L.copy.length)>Xr)return;g.push(L)}}let h=g.filter(O=>u.has(O.key));if(h.length===0)return;let d=new Map,m=O=>ue(c,O,d),S=new Map,y=new Map,w=O=>(y.has(O.key)||y.set(O.key,Oi(c,m(O.copy.source(0)))),y.get(O.key)),x=(O,E)=>{let L=w(O),$=w(E);return L&&$&&L.text===$.text?L.at-$.at:0},k=O=>a.get(O.key)?.order??-1,b=(O,E)=>(x(O,E)||k(O)-k(E))>=0?O:E,v=(O,E)=>H.createID(O.copy.client,O.copy.clock+E),M=O=>{if(O.copy.newParagraph)return!0;let E=O.copy.source(0);for(let L=0;L<En;L+=1){let $=ye(c,E),Q=$?Ae(Wt($)):null,he=Q?E.clock-Q.clock:-1;if(!Q||E.client!==Q.client||he<0||he>=Q.length)return!1;if(Q.newParagraph)return!0;E=Q.source(he)}return!1},C=new Map;for(let O of g)if(a.has(O.key))for(let E=0;E<O.copy.length;E+=1){let L=v(O,E);if(Kt(c,L))continue;let $=m(O.copy.source(E)),Q=U($.client,$.clock),he=C.get(Q);he?he.push({copy:O,id:L}):C.set(Q,[{copy:O,id:L}])}let T=O=>C.get(U(O.client,O.clock))?.reduce((E,L)=>b(E.copy,L.copy)===E.copy?E:L);for(let O of h)Di(t,O,Jo(t.nodes.get(O.key)),E=>T(m(E)),i);let R=new Map,j=(O,E)=>{let L=R.get(O);L?L.push(E):R.set(O,[E])};if(n.size>0)for(let O of h)for(let E=0;E<O.copy.length;E+=1){let L=ue(c,O.copy.source(E),S,!1);n.has(U(L.client,L.clock))&&!Kt(c,v(O,E))&&j(O.text,v(O,E))}let F=new Map,P=O=>{let E=F.get(O.key);return E===void 0&&F.set(O.key,E=M(O)),E};for(let O of C.values()){if(O.length<2||!O.some(L=>u.has(L.copy.key))||!O.some(L=>P(L.copy))||new Set(O.map(L=>L.copy.key)).size<2)continue;let E=O.reduce((L,$)=>b(L.copy,$.copy)===L.copy?L:$);for(let L of O)L!==E&&j(L.copy.text,L.id)}for(let[O,E]of R)$e(O,new Set(E.map(L=>U(L.client,L.clock))));let D=new Map,I=O=>{let E=D.get(O.key);if(!E){E=new Set;for(let L=0;L<O.copy.length;L+=1){let $=m(O.copy.source(L));E.add(U($.client,$.clock))}D.set(O.key,E)}return E},_=vi,N=(O=1)=>(_-=O)>=0,W={room:t,me:l,incoming:h,all:g,placed:a,share:(O,E)=>{let[L,$]=[I(O),I(E)].sort((Q,he)=>Q.size-he.size);if(!N(L.size))return!1;for(let Q of L)if($.has(Q))return!0;return!1},laterStart:x,step:N,movedRun:s};Li(W),Ni(W)}function qt(t,e){let o=t.nodes.get(e),n=o instanceof H.Map?o.get(A.children):void 0;return n instanceof H.Array?n:void 0}function Ni(t){let{room:e,me:o,incoming:n,all:r,placed:i,share:s,laterStart:c,step:l,movedRun:f}=t,u=new Map,a=(p,h)=>{let d=u.get(p);if(!d){u.set(p,d=new Map);let m=Ii,S=y=>{let w=qt(e,y)?.toArray()??[];return m-=w.length,m<0?[]:w};for(let y of S(p))for(let w of S(y))for(let x of S(w))for(let k of S(x))d.set(k,{p:y,run:w})}return d.get(h)},g=new Map;for(let p of[...n].sort(c)){let h=i.get(p.key);if(!(!h?.p||!h.run))for(let d of r){if(!l())return;if(d.copy.client!==o||d.key===p.key||!s(p,d))continue;let m=a(h.p.parent,d.key),S=m?e.nodes.get(m.run):void 0;if(!m||m.p===h.p.key||!(S instanceof H.Map))continue;let y=S.get(K.movedFrom)===h.p.key,w=!y&&d.copy.newParagraph&&c(p,d)>0&&Ci(e,d,a,h.p.parent)===h.p.key;if(!y&&!w)continue;let x=qt(e,h.p.key),k=qt(e,m.p),b=x?.toArray().indexOf(h.run)??-1;if(!x||!k||b<0)continue;let v=Ti(x,b);if(x.delete(b,1),!w){k.insert(k.toArray().indexOf(m.run),[h.run]);break}let M=g.get(m.run)??m.run,C=H.getState(e.doc.store,o);k.insert(k.toArray().indexOf(M)+1,[h.run]),g.set(m.run,h.run),v&&f?.({anchor:H.createID(d.copy.client,d.copy.clock),gone:v,added:H.createID(o,C),run:h.run,from:x,to:k});break}}}function Ti(t,e){let o=0;for(let n=t._start;n!==null;n=n.right)if(!(n.deleted||!n.countable)){if(e<o+n.length){for(let r=n;r!==null&&!r.keep;)r.keep=!0,r=r.parent._item;return H.createID(n.id.client,n.id.clock+e-o)}o+=n.length}}function Ci(t,e,o,n){let r=ye(t.doc,e.copy.source(0)),i=r?Wt(r)?.get(A.key):void 0;return typeof i=="string"?o(n,i)?.p:void 0}function Di(t,e,o,n,r){let i=t.doc,s=i.clientID,l=ye(i,e.copy.source(0))?.parent;if(!(l instanceof H.Text))return;let f=new Set;for(let p=0;p<e.copy.length;p+=1){let h=e.copy.source(p);f.add(U(h.client,h.clock))}let u=new Map,a=[],g=null;for(let p=l._start;p!==null;p=p.right){if(p.deleted||!(p.content instanceof H.ContentString))continue;let h=p.content.str;for(let d=0;d<h.length;d+=1){let m=H.createID(p.id.client,p.id.clock+d),S=d===0?p.origin:H.createID(p.id.client,p.id.clock+d-1),y=S?U(S.client,S.clock):"",w=p.id.client!==s||!S?void 0:f.has(y)?S:u.get(y);if(!w){g=null;continue}if(u.set(U(m.client,m.clock),w),o?.(m))continue;(!g||!H.compareIDs(g.anchor,w))&&(g={anchor:w,ids:[],written:[],text:"",marks:[]},a.push(g)),g.ids.push(m);let x=et(i,m);x&&n(m)||(x&&g.marks.push([g.text.length,x]),g.written.push(m),g.text+=h[d])}}for(let p of a){let h=n(p.anchor),d=h?Xt(h.copy.text,h.id):-1;if(!h||d<0||($e(l,new Set(p.ids.map(y=>U(y.client,y.clock)))),p.text.length===0))continue;let m=H.getState(i.store,s);h.copy.text.insert(d+1,p.text);let S=t.nodes.get(h.copy.key);S instanceof H.Map&&Ho(S,s,m,p.written),St(i,p.marks.flatMap(([y,w])=>[m+y,w.client,w.clock,1])),r(p.ids[0],H.createID(s,m),p.text.length)}}function Ur(t,e,o){if(o.size===0)return;let n=t.doc,r=new Map,i=0;for(let s of e){let c=t.nodes.get(s),l=c instanceof H.Map?c.get(A.text):void 0;if(!(l instanceof H.Text))continue;let f=[];for(let u of zt(c))if(!(u.client===n.clientID||(i+=u.length)>Xr))for(let a=0;a<u.length;a+=1){let g=H.createID(u.client,u.clock+a),p=ue(n,u.source(a),r,!1);o.has(U(p.client,p.clock))&&!Kt(n,g)&&f.push(g)}f.length>0&&$e(l,new Set(f.map(u=>U(u.client,u.clock))))}}function Li({room:t,me:e,incoming:o,all:n,placed:r,share:i,laterStart:s,step:c}){for(let l of n){if(l.copy.client!==e||!l.copy.newParagraph)continue;let f=r.get(l.key)?.p,u=f?qt(t,f.parent):void 0;if(!f||!u)continue;let a=u.toArray();if(!c(a.length))return;let g=new Map(a.map((d,m)=>[d,m])),p=g.get(f.key)??-1;if(p<0)continue;let h;for(let d of o){if(!c())return;if(d.key===l.key||s(l,d)<=0)continue;let m=r.get(d.key)?.p;if(!m||m.parent!==f.parent||m.key===f.key)continue;let S=g.get(m.key)??-1;S<=p||h&&S<=h.at||!i(d,l)||(h={key:m.key,at:S})}h&&(u.delete(p,1),u.insert(u.toArray().indexOf(h.key)+1,[f.key]))}}import*as Hr from"yjs";var _i=new Set([A.part,A.key,A.shell,oe.copyOf,oe.newParagraph]);function Vr(t){return e=>{let o=e.parent;if(o===t)return!1;let n=ve(o);return n===null||n.parent!==t?!0:e.content instanceof Hr.ContentType?!1:!(e.parentSub!==null&&_i.has(e.parentSub)&&pr(e))}}import*as Re from"yjs";var Dn="followed",Jr=65536,qr=t=>{let e=Re.createDeleteSet();return e.clients.set(t.client,[{clock:t.clock,len:1}]),e},Ln=t=>{let e=t.meta.get(Dn);return e instanceof Map?e:void 0};function Qr(t,e){for(let o of e)for(let n of t){if(!Re.isDeleted(n.insertions,o.anchor))continue;n.insertions=Re.mergeDeleteSets([n.insertions,qr(o.added)]),n.deletions=Re.mergeDeleteSets([n.deletions,qr(o.gone)]);let r=Ln(n);r||n.meta.set(Dn,r=new Map),r.set(o.run,{from:o.from,to:o.to})}}function Zr(t,e){let o=Ln(t);o&&e.meta.set(Dn,new Map(o))}var Fi=(t,e)=>{let o=0;for(let n=t._start;n!==null;n=n.right)if((o+=1)>Jr||!n.deleted&&n.countable&&n.content.getContent().includes(e))return!0;return!1};function zi(t,e){let o=[],n=0;for(let r=t._start;r!==null&&n<Jr;r=r.right){if(n+=1,!r.deleted||!r.countable)continue;let i=r.content.getContent();for(let s=0;s<i.length;s+=1)i[s]===e&&o.push(Re.createID(r.id.client,r.id.clock+s))}return o}function ji(t,e){if(e.length===0)return t;let o=Re.createDeleteSet();for(let[n,r]of t.clients){let i=e.filter(c=>c.client===n).map(c=>c.clock),s=[];for(let{clock:c,len:l}of r){let f=c;for(let u of i.filter(a=>a>=c&&a<c+l).sort((a,g)=>a-g))u>f&&s.push({clock:f,len:u-f}),f=u+1;f<c+l&&s.push({clock:f,len:c+l-f})}s.length>0&&o.clients.set(n,s)}return o}function _n(t){let e=Ln(t),o=new Set;if(!e)return o;for(let[n,{from:r,to:i}]of e){if(Fi(i,n)){o.add(n);continue}t.deletions=ji(t.deletions,zi(r,n)),e.delete(n)}return o}import*as se from"yjs";var Wi=4096,Ki=4096,$i=32;function Gi(t,e,o,n,r=new Set){let i=t.doc,s=new Map,c=0;for(let[l,f]of i.getMap(We).entries()){if(typeof f!="string"||!e.has(f)||!o(f,l))continue;if((c+=1)>Wi)return null;let u=t.nodes.get(l),a=u instanceof se.Map?u.get(A.text):void 0;if(!(!Ae(u)||!(a instanceof se.Text))){for(let g=a._start;g!==null;g=g.right)if(!(g.deleted||!g.countable))for(let p=0;p<g.length;p+=1){let h=U(g.id.client,g.id.clock+p);if(r.has(h))continue;let d=ue(i,se.createID(g.id.client,g.id.clock+p),n),m=U(d.client,d.clock);m!==h&&!s.has(m)&&s.set(m,{text:a,item:g,j:p})}}}return s}function Xe(t,e){let o=e.parent;if(!(o instanceof se.Map)||ve(o)?.parent!==t.nodes)return null;let n=o.get(A.part);return typeof n=="string"?n:null}function es(t,e){let o=t.content.getContent();return o.length>0&&typeof o[0]=="string"?String(o.join("")).charAt(e):""}var Xi=t=>se.createID(t.item.id.client,t.item.id.clock+t.j);function ts(t,e,o){let n=t.doc,r=[],i=new Map,s=!1;return ge(n,e,c=>{if(s||!c.countable||!(c.parent instanceof se.Text)||c.redone===null)return;let l=c.parent,f=ye(n,c.redone);if(!Xe(t,l)||!f||f.deleted||f.parent!==l)return;let u=Math.min(c.length,f.length);for(let a=0;a<u;a+=1){if(r.length>=Ke){s=!0;return}let g=ue(n,se.createID(c.id.client,c.id.clock+a),i);r.push({text:l,item:f,j:a,root:g,char:es(f,a)})}}),!s&&ns(t,r,o,i,()=>!0)}function ns(t,e,o,n,r){let i=t.doc;if(e.length===0)return!1;let s=new Set;for(let d of e)s.add(Xe(t,d.text));let c=d=>U(d.item.id.client,d.item.id.clock+d.j),l=new Set(e.map(c)),f=Gi(t,s,o,n,l);if(!f||f.size===0)return!1;let u=d=>{let m=0,S=d.item,y=d.j-1;for(;S!==null&&m<Ki;){for(;y>=0&&S.countable;y-=1,m+=1){let w=se.createID(S.id.client,S.id.clock+y);if(l.has(U(w.client,w.clock)))continue;let x=ue(i,w,n),k=f.get(U(x.client,x.clock));if(k&&k.text!==d.text)return k;if(!S.deleted)return null}S=S.left,y=S?S.length-1:-1}return null},a=[],g=[];for(let d of e){let m=f.get(U(d.root.client,d.root.clock));if(m&&m.text!==d.text){a.push(d);continue}let S=r(d)?u(d):null;if(!S)continue;let y=g[g.length-1];y&&y.to.item===S.item&&y.to.j===S.j?y.chars.push(d):g.push({to:S,chars:[d]})}if(a.length===0&&g.length===0)return!1;let p=[];for(let{to:d,chars:m}of g){let S=Xt(d.text,Xi(d));if(S<0)continue;let y=m.map(x=>x.char).join("");if(y.length===0)continue;let w=se.getState(i.store,i.clientID);d.text.insert(S+1,y),m.forEach((x,k)=>p.push(w+k,x.root.client,x.root.clock,1)),a.push(...m)}St(i,p);let h=new Map;for(let d of a){let m=h.get(d.text);m?m.add(c(d)):h.set(d.text,new Set([c(d)]))}for(let[d,m]of h)$e(d,m);return!0}function Fn(t,e){let o=t.doc,n=[],r=new Set,i=new Set,s=new Map,c=0;return ge(o,e,l=>{if(!l.countable||!(l.parent instanceof se.Text)||l.redone===null)return;let f=l.parent,u=l.redone;if(u.client!==o.clientID||Xe(t,f)===null)return;let a=ye(o,u);if(!(!a||a.parent!==f)){i.add(f);for(let g=0;g<l.length;g+=1){if((c+=1)>Ke)return;let p=se.createID(l.id.client,l.id.clock+g);for(let y=0;y<$i;y+=1){let w=et(o,p);if(!w)break;p=w}let h=ue(o,p,s,!1);r.add(U(h.client,h.clock));let d=u.clock+g,m=n.length;m>0&&n[m-4]+n[m-1]===d&&n[m-3]===p.client&&n[m-2]+n[m-1]===p.clock?n[m-1]+=1:n.push(d,p.client,p.clock,1)}}}),St(o,n),{roots:r,texts:i}}function zn(t,e){let o=t.doc,n=o.getMap(Ne),r=new Set;for(let i of e){let s=i===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(i),c=i===null?void 0:n.get(i);if(!s||!Array.isArray(c))continue;let l=Math.min(Number(c[2])||0,Ke),f=Number(s[1]);for(let u=Number(s[2]),a=u+l;u<a;){let g=ye(o,se.createID(f,u));if(!g)break;if(!g.deleted&&g.parent instanceof se.Text&&Xe(t,g.parent)){r.add(g.parent);break}u=g.id.clock+g.length}}return r}function jn(t,e){let o=new Set,n=[...t.doc.getMap(Ne).keys()].sort().slice(0,Ke);for(let r of n)for(let i of zn(t,[r])){let s=Xe(t,i);s!==null&&e.has(s)&&o.add(i)}return o}function Bi(t,e){let o=ve(e.parent);return o&&o.parent===t.nodes&&typeof o.parentSub=="string"?o.parentSub:null}var Ui=(t,e)=>t.client<e.client||t.client===e.client&&t.clock>e.clock;function Wn(t,e,o){let n=t.doc,r=new Map,i=[...e],s=new Set;for(let d of i){let m=Xe(t,d);m!==null&&s.add(m)}if(s.size===0)return!1;let c=new Set(jn(t,s));for(let d of i)c.add(d);let l=new Map,f=new Map,u=(d,m)=>{let S=f.get(d);S?S.add(U(m.client,m.clock)):f.set(d,new Set([U(m.client,m.clock)]))},a=0;for(let d of c){let m=Xe(t,d),S=Bi(t,d);if(m===null||S===null)continue;let y=o(m,S)?"":`${S}\0`;for(let w=d._start;w!==null&&a<Ke;w=w.right)if(!(w.deleted||!w.countable))for(let x=0;x<w.length;x+=1,a+=1){let k=se.createID(w.id.client,w.id.clock+x);if(!et(n,k))continue;let b=ue(n,k,r),v=y+U(b.client,b.clock),M=l.get(v);M?Ui(k,M.id)?(u(M.text,M.id),l.set(v,{id:k,text:d})):u(d,k):l.set(v,{id:k,text:d})}}for(let[d,m]of f)$e(d,m);let g=[];for(let{id:d,text:m}of l.values()){let S=ye(n,d);if(!S||S.deleted||S.parent!==m)continue;let y=d.clock-S.id.clock;g.push({text:m,item:S,j:y,root:ue(n,d,r),char:es(S,y)})}let p=n.clientID;return ns(t,g,o,r,d=>d.item.id.client===p)||f.size>0}import*as ie from"yjs";function os(t,e,o){let n=r=>{let i=t.nodes.get(r),s=i instanceof ie.Map?i.get(A.children):void 0;return s instanceof ie.Array?s.toArray():[]};for(let r of n(e))if(!(typeof r!="string"||t.nodes.get(r)?.get?.(A.shell)?.local!=="t"))for(let s of n(r)){let c=typeof s=="string"?t.nodes.get(s):void 0,l=c instanceof ie.Map?c.get(A.text):void 0;l instanceof ie.Text&&o.add(l)}}var tt=(t,e)=>ve(e)?.parent===t.nodes&&e instanceof ie.Map?e:null;function rs(t,e){let o=t.doc.clientID.toString(36),n=Qe(t),r=new Set,i=new Map,s=l=>{if(typeof l!="string")return new Set;let f=i.get(l);if(!f){let u=He(t.parts.get(l));f=u?.kind==="xml"?mt(t,l,u.root).unseenWinners:new Set,i.set(l,f)}return f};if(ge(t.doc,e.insertions,l=>{if(l.parent!==t.nodes||l.deleted||!(l.content instanceof ie.ContentType))return;let f=l.content.type,u=ze(f),a=u?n(u.group):void 0;!u||a===void 0||a===o||s(f.get(A.part)).has(u.group)||r.add(u.from)}),r.size===0)return e.deletions;let c=new Set;for(let l of r)os(t,l,c);return c.size===0?e.deletions:Gt(t.doc,e.deletions,l=>c.has(l.parent))}function ss(t,e){let o=new Map;if(ge(t.doc,e.insertions,a=>{let g=a.parent;!(g instanceof ie.Text)||!a.countable||tt(t,g.parent)&&o.set(g,(o.get(g)??!1)||a.deleted)}),![...o.values()].some(Boolean))return e;let n=new Map,r=new Set;if(ge(t.doc,e.deletions,a=>{let g=tt(t,a.parent);if(!g||a.parentSub!==K.splitFrom||!(a.content instanceof ie.ContentAny))return;let p=a.content.getContent()[0];if(typeof p!="string")return;let h=new Set;os(t,p,h);let d=[...h].filter(S=>o.get(S)===!0);if(d.length===0)return;for(let S of d)r.add(S);let m=g.get(A.key);typeof m=="string"&&n.set(g,m)}),n.size===0)return e;let i=new Map;ge(t.doc,e.deletions,a=>{let g=a.parent,h=(g instanceof ie.Array?tt(t,g.parent):null)?.get(A.key);if(typeof h!="string"||!(a.content instanceof ie.ContentAny))return;let d=i.get(h);d||i.set(h,d=[]);for(let m of a.content.getContent())typeof m=="string"&&d.push(m)});let s=new Set(n.values()),c=new Set,l=[...s];for(;l.length>0;){let a=l.pop(),g=t.nodes.get(a);if(!(c.has(g)||!(g instanceof ie.Map))){c.add(g);for(let p of i.get(a)??[])l.push(p)}}let f=a=>tt(t,a.parent)??tt(t,a.parent?.parent),u=a=>a.parent instanceof ie.Array&&tt(t,a.parent.parent)!==null&&a.content instanceof ie.ContentAny&&a.content.getContent().some(g=>typeof g=="string"&&s.has(g));return{insertions:Gt(t.doc,e.insertions,a=>r.has(a.parent)),deletions:Gt(t.doc,e.deletions,a=>c.has(f(a))||u(a))}}import*as ls from"yjs";import{CONTENT_TYPES_PART as Jt,asciiFold as Be,NS as ae,attr as xe,children as Zt,materialize as Hi,relationshipsOf as Mt,relsPartName as Qt,specOf as Vi}from"@pptx-editor.dev/core/store";var $n=Symbol("absent");function ds(t,e,o){let n=qi(o);for(let r of t){let i=r.target;if(!(i instanceof ls.Map)||!e(i))continue;let s=n.get(i);s||n.set(i,s=new Map);for(let[c,l]of r.changes.keys){let f=i.get(c),u=s.get(c);if(u)u[3]=f;else{let a=[i,c,l.action==="add"?$n:l.oldValue,f];o.push(a),s.set(c,a)}}}}var is=new WeakMap;function qi(t){let e=is.get(t);if(e)return e;e=new Map;for(let o of t){let n=e.get(o[0]);n||e.set(o[0],n=new Map),n.has(o[1])||n.set(o[1],o)}return is.set(t,e),e}var fs=t=>t._item?.deleted!==!0;function us(t){return t.filter(([e,o,n])=>n!==$n&&fs(e)&&!e.has(o)).map(([e,o,n])=>[e,o,n])}function Gn(t){let e=(o,n)=>JSON.stringify(o)===JSON.stringify(n);return t.filter(([o,n,r,i])=>fs(o)&&i!==void 0&&r!==$n&&e(o.get(n),r)&&!e(r,i)).map(([o,n,,r])=>[o,n,r])}function Ji(t){let e=new Set,o=[t];for(;o.length>0;){let n=o.pop();if(!(n.type!=="element"||ps(n))){for(let r of n.attrs)r.ns===ae.r&&e.add(r.value);for(let r of n.children)o.push(r)}}return e}function cs(t,e){let o={next:t.nextId},n=e.map(r=>Hi(Vi(r),t.root.kind,o));return{partName:t.partName,root:{...t.root,children:[...t.root.children,...n]},nextId:o.next}}var ps=t=>t.ns===ae.p&&t.local==="sldId";function Qi(t,e){for(let o of t.parts.values()){if(o.kind!=="xml")continue;let n=o.xml.root;if(n.ns!==ae.p||n.local!=="presentation")continue;let r=n.children.find(y=>y.type==="element"&&y.ns===ae.p&&y.local==="sldIdLst");if(!r)return;let i=[],s=new Set;for(let y of r.children){if(y.type!=="element"||!ps(y))continue;let w=y.attrs.find(x=>x.ns===ae.r&&x.local==="id")?.value;w===void 0||!e.has(w)?s.add(y):i.push(xe(y,"id")??"")}let c=[],l=y=>{for(let w of y.children)w.type==="element"&&(w.ns===ae.p14&&w.local==="section"?c.push(w):l(w))};l(n);let f=new Map(c.map((y,w)=>[y,w])),u=new Map;c.forEach((y,w)=>{let x=y.children.find(k=>k.type==="element"&&k.ns===ae.p14&&k.local==="sldIdLst");if(x)for(let k of Zt(x,{ns:ae.p14,local:"sldId"})){let b=xe(k,"id")??"",v=u.get(b);v?v[v.length-1]!==w&&v.push(w):u.set(b,[w])}});let a=new Map,g=0;for(let y of i){let w=u.get(y);if(!w)continue;let x=w.find(k=>k>=g)??w[0];a.set(y,x),g=Math.max(g,x)}let p=new Map(i.map((y,w)=>[y,w])),h=s.size>0,d=(y,w)=>{let x=y.children.map(k=>{if(k.type!=="element"||k.ns!==ae.p14||k.local!=="sldIdLst")return k;let b=new Set,M=[...k.children.filter(C=>{if(C.type!=="element"||C.ns!==ae.p14||C.local!=="sldId")return!0;let T=xe(C,"id")??"";return a.get(T)!==w||b.has(T)?!1:(b.add(T),!0)})].sort((C,T)=>{let R=C.type==="element"?p.get(xe(C,"id")??"")??0:0,j=T.type==="element"?p.get(xe(T,"id")??"")??0:0;return R-j});return M.length===k.children.length&&M.every((C,T)=>C===k.children[T])?k:(h=!0,{...k,children:M})});return x.every((k,b)=>k===y.children[b])?y:{...y,children:x}},m=y=>{let w=y.children.filter(k=>k.type!=="element"||!s.has(k)).map(k=>{if(k.type!=="element")return k;let b=f.get(k)??-1;return b>=0?d(k,b):m(k)});return w.length===y.children.length&&w.every((k,b)=>k===y.children[b])?y:{...y,children:w}},S=m(n);return h?{...o.xml,root:S}:void 0}}var Zi=new Set(["hlinkClick","hlinkHover","hlinkMouseOver"]),Kn=t=>t.endsWith("/relationships/slide");function as(t,e){let o=!1,n=i=>{let s=!1,c=[];for(let l of i.children){if(l.type!=="element"){c.push(l);continue}let f=l.attrs.some(a=>a.ns===ae.r&&a.value===e);if(f&&l.ns===ae.a&&Zi.has(l.local)){s=!0;continue}f&&(o=!0);let u=n(l);u!==l&&(s=!0),c.push(u)}return s?{...i,children:c}:i},r=n(t);return o?void 0:r}function ec(t,e){return{...t,root:{...t.root,children:t.root.children.filter(o=>o.type!=="element"||o.local!=="Relationship"||xe(o,"Id")!==e)}}}var nt=(t,e)=>{let o=t.parts.get(e);return o?.kind==="xml"?o.xml:void 0};function Xn(t,e){let o=new Map,n=new Set;for(let a of e.parts.keys())n.add(Be(a));let r=a=>e.parts.has(a)||n.has(Be(a)),i=[],s=new Set,c=a=>{!a||s.has(a.partName)||(s.add(a.partName),i.push(a))},l=!1;for(let a of t.parts.keys())e.parts.has(a)||(l=!0);for(let[a,g]of e.parts){if(g.kind!=="xml")continue;let p=Qt(a);if(!l&&t.parts.get(a)===g&&t.parts.get(p)===e.parts.get(p))continue;let h=k=>{let b=as((o.get(a)??g.xml).root,k);if(!b)return!1;o.set(a,{...o.get(a)??g.xml,root:b});let v=o.get(p)??nt(e,p);return v&&o.set(p,ec(v,k)),!0};for(let k of Mt(e,a))!k.external&&k.target&&!r(k.target)&&Kn(k.type)&&h(k.id);let d=Ji((o.get(a)??g.xml).root);if(d.size===0)continue;for(let k of Mt(e,a))!d.has(k.id)||k.external||!k.target||r(k.target)||Kn(k.type)||c(t.parts.get(k.target));let m=new Set(Mt(e,a).map(k=>k.id)),S=nt(t,p);if(!S)continue;let y=Zt(S.root,{ns:ae.rel,local:"Relationship"}).filter(k=>{let b=xe(k,"Id");return b!==void 0&&d.has(b)&&!m.has(b)});for(let k of Mt(t,a)){let b=y.findIndex(M=>xe(M,"Id")===k.id);if(b<0||k.external||!k.target||r(k.target)||!Kn(k.type))continue;let v=as((o.get(a)??g.xml).root,k.id);v&&(o.set(a,{...o.get(a)??g.xml,root:v}),y.splice(b,1))}if(y.length===0)continue;let w=o.get(p)??nt(e,p)??{partName:p,root:{...S.root,children:[]},nextId:S.nextId};o.set(p,cs(w,y));let x=new Set(y.map(k=>xe(k,"Id")));for(let k of Mt(t,a))!x.has(k.id)||k.external||!k.target||r(k.target)||c(t.parts.get(k.target))}{let a=[...e.parts.values()].find(d=>d.kind==="xml"&&d.xml.root.ns===ae.p&&d.xml.root.local==="presentation"),g=a&&(o.get(Qt(a.partName))??nt(e,Qt(a.partName))),p=a&&Qt(a.partName),h=a&&(t.parts.get(a.partName)!==a||t.parts.get(p)!==e.parts.get(p)||o.has(p));if(g&&h&&p&&e.parts.has(p)){let d=new Set(Zt(g.root,{ns:ae.rel,local:"Relationship"}).map(S=>xe(S,"Id")??"")),m=Qi(e,d);m&&o.set(m.partName,m)}}let f=nt(e,Jt),u=nt(t,Jt);if(f&&u){let a=(y,w,x)=>{let k=new Map;for(let b of Zt(y,{ns:ae.ct,local:w})){let v=xe(b,x);v!==void 0&&!k.has(Be(v))&&k.set(Be(v),b)}return k},g=a(f.root,"Override","PartName"),p=a(f.root,"Default","Extension"),h=a(u.root,"Override","PartName"),d=a(u.root,"Default","Extension"),m=new Set,S=new Set(e.parts.keys());for(let y of i)S.add(y.partName);for(let y of S){if(y===Jt)continue;let w=Be(y.slice(y.lastIndexOf(".")+1));if(g.has(Be(y))||p.has(w))continue;let x=h.get(Be(y))??d.get(w);x&&m.add(x)}m.size>0&&o.set(Jt,cs(f,[...m]))}return[...[...o.values()].map(a=>({kind:"xml",partName:a.partName,xml:a})),...i]}var gs=0;function Bn(t,...e){for(let o of[...t])try{o(...e)}catch(n){console.warn("[pptx-editor] collaboration listener failed",n)}}function nc(t){let{doc:e,documentId:o,identity:n,awareness:r}=t;if(typeof o!="string"||o.trim()===""||o.length>256)throw new we("invalid-document-id");let i=_r(n);if(i)throw new we(i);let s=eo(e),c=tc("initializing"),l=new Set,f=new Set,u=new Set,a=null,g=null,p={value:0},h=null,d=null,m=null,S=!1,y=!0,w=[{...n,isLocal:!0}],x=[],k=null,b=null,v=null,M=!1;gs+=1;let C=`${e.clientID.toString(36)}-${gs}`,T=(N,z,W,O=!1)=>{if(!c.set(N,z,W,O))return;let E=c.snapshot().reason;Bn(l,N,E?.code,E?.detail)},R=()=>y?T("ready"):T("disconnected","transport-disconnected"),j=N=>{r&&!S&&r.setLocalStateField(Ht,Wr(n,N))},F=()=>{if(!r)return;let N=Kr(r);JSON.stringify(N)!==JSON.stringify(w)&&(w=N,Bn(f,w));let z=g?$r(r,e,g):[];JSON.stringify(z)!==JSON.stringify(x)&&(x=z,Bn(u,x))};j(void 0),r?.on("change",F),F();let P=(N,z,W,O=!0)=>{let E=z?N.redoStack:N.undoStack,L=E.length;z?N.undoing=!0:N.redoing=!0;try{e.transact(W,on)}finally{N.undoing=!1,N.redoing=!1}if(E.length!==L+1)return!1;let $=E[E.length-2];if(!O||!$)return!0;let Q=E.pop();return $.deletions=ke.mergeDeleteSets([$.deletions,Q.deletions]),$.insertions=ke.mergeDeleteSets([$.insertions,Q.insertions]),!0},D=(N,z,W)=>z.length>0&&P(N,!1,()=>{for(let[O,E,L]of z)O.set(E,L)},W),I=(N,z)=>{let W=z?N?.undoStack:N?.redoStack;if(!N||!W||W.length===0)return!1;M=!1;let O=d?.package(),E=W[W.length-1];if(z){for(let X of W.slice(0,-1))_n(X);yr(s,E,X=>e.transact(X,it),_n(E)),E.deletions=rs(s,E)}else{let X=ss(s,E);E.insertions=X.insertions,E.deletions=X.deletions}let L=[...W];m=null,z?N.undo():N.redo(),!z&&m===E&&wr(s,E,X=>e.transact(X,it));let $=m,Q=new Set(W),he=L.reverse().filter(X=>!Q.has(X)&&X!==$),ot=X=>X.meta.get("attrs")??[],rt=!1,Pe=!1,Ye=null;if(z&&$&&$!==E)m=null,N.redo(),Ye=m,Pe=!0;else if(!z&&$===E)rt=D(N,Gn(ot(E)),!0);else if(!z){$&&(m=null,N.undo(),Ye=m);for(let X of he.slice(1).reverse())N.redoStack.push(X);rt=D(N,Gn(ot(E)),!1)}if(Ye){let X=Ye;e.transact(()=>Fn(s,X.deletions),it)}let G=$&&!Pe&&(z||$===E)?$:null;if(G&&g){let X=g,re=G,ee=(ce,Ee)=>X.idOf(ce,Ee)!==void 0,le=new Set;P(N,z,()=>{let ce=Fn(s,re.deletions);le=ce.roots,z&&Sr(s,re,ee),ts(s,re.deletions,ee),Wn(s,ce.texts,ee)}),X.forgetDeleted(le)}let q=d?.package(),Z=z&&$&&!Pe?us(ot($)):[],te=O&&q&&!Pe?Xn(O,q):[];if((Z.length>0||te.length>0)&&q&&g){let X=g;e.transact(()=>{for(let[ee,le,ce]of Z)ee.set(le,ce);if(te.length===0)return;let re=new Map(q.parts);for(let ee of te)re.set(ee.partName,ee);X.writeChange(q,{parts:re},te.map(ee=>ee.partName))},nn)}return!M&&(z?$!==null&&!Pe:$===E||rt)};return{documentId:o,sessionId:C,identity:n,get attached(){return a!==null},status:()=>c.status(),statusSnapshot:()=>c.snapshot(),subscribeStatus(N){return l.add(N),()=>l.delete(N)},setConnected(N){if(S||N===y)return;y=N;let z=c.snapshot();(z.status==="ready"||z.status==="disconnected")&&R()},participants:()=>w,subscribeParticipants(N){return f.add(N),()=>f.delete(N)},remoteSelections:()=>x,subscribeRemoteSelections(N){return u.add(N),()=>u.delete(N)},setLocalSelection(N){let z=N&&g?jr(N,g):void 0;k=N&&z?{selection:N,encoded:z}:null,j(z)},remoteSelectionMove:()=>b,historySelection:()=>v&&g?Vt(v,e,g):null,canUndo:()=>h?h.undoStack.length>0:!1,canRedo:()=>h?h.redoStack.length>0:!1,undo:()=>I(h,!0),redo:()=>I(h,!1),attach(N){if(S)return()=>{};a?.(),T("initializing");let z=s.meta.get("schema");if(z!==void 0&&z!==Ue)return T("error","schema-version-mismatch",`room schema ${String(z)}`),()=>{};let W=new Ut(s,p);d=N,g=W;let O=(G,q,Z=!1)=>{let te=N.package(),X=W.rebuild(G,te,q);if(!X.ok)return M=!0,T("error","remote-apply-failed",X.reason,!0);let re=k?Vt(k.encoded,e,W):null;if(b=k&&re&&JSON.stringify(re)!==JSON.stringify(k.selection)?{from:k.selection,to:re}:null,b&&k&&(k={selection:b.to,encoded:k.encoded}),X.parts.length>0||X.removed.length>0){let le=N.applyRemoteParts(X.parts,X.removed,"collaboration");if(b=null,!le.ok){M=!0;let ce=le.rejection.code;return ce==="unsafe-part-name"?T("error","unsafe-part-name",ce):T("error","remote-apply-failed",ce,!0)}}b=null,Z&&he(te,N.package());let ee=c.snapshot();ee.status==="error"&&ee.recovering&&R(),F()};W.seeded?O(W.allParts(N.package()),!0):e.transact(()=>{s.meta.set("schema",Ue),s.meta.set("documentId",o),W.seed(N.package())},cn);let E=new ke.UndoManager([s.parts,s.binaries,s.nodes],{trackedOrigins:new Set([Et,on]),captureTimeout:Number.POSITIVE_INFINITY,deleteFilter:Vr(s.nodes)}),L=G=>{let q=G.parent;return q instanceof ke.Map&&q.get(A.attrs)===G},$=G=>{let q=E.currStackItem;if((E.undoing||E.redoing)&&q){G.stackItem.meta.set("attrs",q.meta.get("attrs")??[]),Zr(q,G.stackItem);return}let Z=G.stackItem.meta.get("attrs")??[],te=new Set;for(let X of G.changedParentTypes?.values()??[])for(let re of X)te.add(re);ds(te,L,Z),G.stackItem.meta.set("attrs",Z)};E.on("stack-item-added",G=>{k&&G.stackItem.meta.set("selection",k.encoded),$(G)}),E.on("stack-item-updated",$),E.on("stack-item-popped",G=>{v=G.stackItem.meta.get("selection")??null,m=G.stackItem}),h=E;let Q=N.subscribeLocal(G=>{G.merged||E.stopCapturing(),W.hasHiddenListings(G.parts)&&e.transact(()=>W.dropHiddenListings(G.parts,G.before,G.after),sn),e.transact(()=>W.writeChange(G.before,G.after,G.parts),Et);let q=W.showingUnlisted(G.parts);q.length>0&&O(q,!1),F()}),he=(G,q)=>{let Z=Xn(G,q);if(Z.length===0)return;let te=new Map(q.parts);for(let X of Z)te.set(X.partName,X);e.transact(()=>W.writeChange(q,{parts:te},Z.map(X=>X.partName)),nn)},ot=(G,q)=>{let Z=W.deletedText,te=Z.size>0?Vo(s,G):new Set;if(q.size===0&&te.size===0)return;let X={keyOf:W.keyOf.bind(W),package:N.package()},re=[],ee=[];e.transact(()=>{for(let[le,ce]of q)Br(s,le,ce,Z,X,(Ee,st,bt)=>re.push([Ee,st,bt]),Ee=>ee.push(Ee));Ur(s,te,Z)},rn),Qr([...E.undoStack,...E.redoStack],ee);for(let[le,ce,Ee]of re)for(let st of[...E.undoStack,...E.redoStack]){if(!ke.isDeleted(st.insertions,le))continue;let bt=ke.createDeleteSet();bt.clients.set(ce.client,[{clock:ce.clock,len:Ee}]),st.insertions=ke.mergeDeleteSets([st.insertions,bt])}},rt=e.getMap(Ne),Pe=G=>{let q=s.meta.get("schema");if(q!==Ue&&G.changed.has(s.meta)){Ye(),T("error","schema-version-mismatch",`room schema ${String(q)}`);return}let Z=G.origin;if(Z===Et||Z===cn||Z===it||Z===sn)return;let te=W.touchedParts(G);if(te.size>0&&O(te,!1,!G.local),G.local)return;let X=W.newCopies(G);ot(G,X);let re=G.changed.get(rt),ee=re?zn(s,re):new Set;if(X.size>0&&s.doc.getMap(Ne).size>0)for(let le of jn(s,new Set(X.keys())))ee.add(le);if(ee.size>0){let le=(ce,Ee)=>W.idOf(ce,Ee)!==void 0;e.transact(()=>Wn(s,ee,le),rn)}};e.on("afterTransaction",Pe),c.status()==="initializing"&&R(),F();let Ye=()=>{Q(),e.off("afterTransaction",Pe),E.destroy(),h===E&&(h=null),g===W&&(g=null),d===N&&(d=null),k=null,v=null,j(void 0),F(),a===Ye&&(a=null)};return a=Ye,Ye},destroy(){S||(a?.(),r?.off("change",F),r?.setLocalStateField(Ht,null),S=!0,T("destroyed","collaboration-session-destroyed"),l.clear(),f.clear(),u.clear())}}}var hs=t=>`pptx-collaboration-${t}`,oc=hs(Ue);function rc(t){if(!t.share.has(Rt))throw new we("not-initialized");let e;try{e=t.getMap(Rt).get("schema")}catch{throw new we("schema-version-mismatch","room metadata is not a map")}if(e===void 0)throw new we("not-initialized");if(typeof e!="number"||!Number.isSafeInteger(e))throw new we("schema-version-mismatch","room schema is not a number");return hs(e)}export{oc as COLLABORATION_FORMAT_VERSION,we as CollaborationSchemaError,Is as collaborationModule,nc as createYjsCollaborationSession,Es as legacyComments,rc as readCollaborationFormatVersion,ms as reviewModule};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pptx-editor.dev/pro",
3
- "version": "0.3.1",
3
+ "version": "0.3.2-canary.20261110032720.sha-1742572",
4
4
  "description": "Commercial capabilities for PPTX Editor, as EditorModules: the review module with the comments pane and review hooks for React and Vue, realtime collaboration, and advanced drawing rendering (charts, glow, inner shadow, reflection, and soft edge).",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -37,9 +37,9 @@
37
37
  "api:check": "node ../../scripts/api-extractor.mjs --package @pptx-editor.dev/pro"
38
38
  },
39
39
  "peerDependencies": {
40
- "@pptx-editor.dev/core": "~0.3.0",
41
- "@pptx-editor.dev/react": "~0.3.0",
42
- "@pptx-editor.dev/vue": "~0.3.0",
40
+ "@pptx-editor.dev/core": "0.3.2-canary.20261110032720.sha-1742572",
41
+ "@pptx-editor.dev/react": "0.3.2-canary.20261110032720.sha-1742572",
42
+ "@pptx-editor.dev/vue": "0.3.2-canary.20261110032720.sha-1742572",
43
43
  "react": "^18.0.0 || ^19.0.0",
44
44
  "vue": "^3.5.0"
45
45
  },