@pptx-editor.dev/pro 0.2.0 → 0.3.0-canary.20261109032918.sha-39dc46e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -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 mt}from"./chunk-HCD7IVOL.js";import{attr as Oe,binaryPartOf as Ks,elements as Ut,parseXmlPart as $s,mainPresentationPart as Ws,presentationInfo as Gs,relTargetByType as Fn,textOf as Xs,xmlPartOf as Bs}from"@pptx-editor.dev/core/store";var zn="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Us=`${zn}/comments`,Hs=`${zn}/commentAuthors`;function jn(t,e){let n=Bs(t,e);if(n||!e)return n;let o=Ks(t,e);if(!o)return;let s=$s(e,new TextDecoder().decode(o));return s.ok?s.part:void 0}function Vs(t){let e=Object.create(null),n=Ws(t);if(!n)return e;let o=jn(t,Fn(t,n,Hs));for(let s of Ut(o?.root)){if(s.local!=="cmAuthor")continue;let i=Oe(s,"id"),r=Oe(s,"name");i!==void 0&&r!==void 0&&(e[i]=r)}return e}function Bt(t,e){for(let n of Ut(t)){if(n.local===e)return n;let o=Bt(n,e);if(o)return o}}var _n=(t,e,n)=>`${t}#cm-${e}-${n}`;function Ht(t){let e=Vs(t),n=[];for(let o of Gs(t).slides){let s=jn(t,Fn(t,o.partName,Us));for(let i of Ut(s?.root)){if(i.local!=="cm")continue;let r=Oe(i,"authorId")??"",u=Oe(i,"idx")??"",l=Bt(i,"parentCm"),f=e[r],d=Oe(i,"dt");n.push({id:_n(o.partName,r,u),kind:"comment",slidePart:o.partName,text:Xs(Bt(i,"text")),...f!==void 0?{author:f}:{},...d!==void 0?{date:d}:{},...l?{parentId:_n(o.partName,Oe(l,"authorId")??"",Oe(l,"idx")??"")}:{}})}}return n}function qs(t={}){return mt(t.licenseKey),{id:"review",review:{displayModes:t.displayModes??["final","markup"],collectReviewItems:({package:e})=>Ht(e)}}}function Js(t){return mt(t.licenseKey),{id:"collaboration",collaboration:{session:t.session}}}import*as me from"yjs";import{createCollaborationStatusTracker as ki}from"@pptx-editor.dev/core/editor";var Ke=class extends Error{constructor(n,o){let s=o?`${n}: ${o}`:n;super(n==="schema-version-mismatch"?`${s}
7
- Collaboration upgrade required. Save local changes and use a compatible app version.`:s);this.code=n;this.detail=o;this.name="CollaborationSchemaError"}code;detail};import*as B from"yjs";import{buildReplicaPart as $r}from"@pptx-editor.dev/core/store";import"yjs";var Vt=5,Qs="pptx-meta-v1",Zs="pptx-parts-v1",er="pptx-binaries-v1",tr="pptx-nodes-v1",N=Object.freeze({part:"p",key:"k",shell:"s",attrs:"a",children:"c",text:"x"}),yt="",Kn=2**40,kt=Object.freeze({kind:"pptx-local"}),qt=Object.freeze({kind:"pptx-undo-repair"}),Jt=Object.freeze({kind:"pptx-redo-repair"}),Qt=Object.freeze({kind:"pptx-text-repair"}),Zt=Object.freeze({kind:"pptx-tidy"}),Ze=Object.freeze({kind:"pptx-undone-listing"}),en=Object.freeze({kind:"pptx-seed"}),et=Object.freeze({maxBinaryBytes:256*1024*1024,maxReadDepth:300,maxCopiesPerGroup:256});function $n(t){return{doc:t,meta:t.getMap(Qs),parts:t.getMap(Zs),binaries:t.getMap(er),nodes:t.getMap(tr)}}function $e(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 nr}from"@pptx-editor.dev/core/store";var nn="http://schemas.openxmlformats.org/drawingml/2006/main",Un="http://schemas.openxmlformats.org/presentationml/2006/main",Y=t=>[t,[t]],ne=(t,e)=>[t,e],nt=["*",[]],ot=ne("fill",["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),or=ne("fill",["noFill","solidFill","gradFill","pattFill"]),xt=ne("effect",["effectLst","effectDag"]),sr=[ne("color",["scrgbClr","srgbClr","hslClr","sysClr","schemeClr","prstClr"])],Wn=[Y("xfrm"),ne("geometry",["custGeom","prstGeom"]),ot,Y("ln"),xt,Y("scene3d"),Y("sp3d"),Y("extLst")],Gn=[or,ne("dash",["prstDash","custDash"]),ne("join",["round","bevel","miter"]),Y("headEnd"),Y("tailEnd"),Y("extLst")],tn=[Y("ln"),ot,xt,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")],tt=t=>[Y("cNvPr"),Y(t),Y("nvPr")],wt=t=>[Y(t),Y("extLst")],on=["lnL","lnR","lnT","lnB","lnTlToBr","lnBlToTr"],rr=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:[ot,xt,Y("extLst")],spPr:Wn,grpSpPr:Wn,ln:Gn,...Object.fromEntries(on.map(t=>[t,Gn])),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","buClr","lnRef","fillRef","effectRef","fontRef"].map(t=>[t,sr])),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"),nt,Y("extLst")],graphicFrame:[Y("nvGraphicFramePr"),Y("xfrm"),Y("graphic"),Y("extLst")],nvSpPr:tt("cNvSpPr"),nvPicPr:tt("cNvPicPr"),nvCxnSpPr:tt("cNvCxnSpPr"),nvGrpSpPr:tt("cNvGrpSpPr"),nvGraphicFramePr:tt("cNvGraphicFramePr"),cNvPr:[Y("hlinkClick"),Y("hlinkHover"),Y("extLst")],nvPr:[Y("ph"),ne("media",["audioCd","wavAudioFile","audioFile","videoFile","quickTimeFile"]),Y("custDataLst"),Y("extLst")],cNvSpPr:wt("spLocks"),cNvPicPr:wt("picLocks"),cNvGrpSpPr:wt("grpSpLocks"),cNvGraphicFramePr:wt("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"),nt],bodyPr:[Y("prstTxWarp"),ne("autofit",["noAutofit","normAutofit","spAutoFit"]),Y("scene3d"),ne("text3d",["sp3d","flatTx"]),Y("extLst")],p:[Y("pPr"),nt,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:tn,defRPr:tn,endParaRPr:tn,tbl:[Y("tblPr"),Y("tblGrid"),nt],tblPr:[ot,xt,ne("tableStyle",["tableStyle","tableStyleId"]),Y("extLst")],tc:[Y("txBody"),Y("tcPr"),Y("extLst")],tcPr:[...on.map(Y),Y("cell3D"),ot,Y("headers"),Y("extLst")]}),rn=t=>t.ns===nn||t.ns===Un,ir=new Set(["sld","cSld","bg","bgPr","sp","pic","cxnSp","grpSp","graphicFrame","nvSpPr","nvPicPr","nvCxnSpPr","nvGrpSpPr","nvGraphicFramePr","nvPr","style"]);function Hn(t){if(!(!rn(t)||ir.has(t.local)&&t.ns!==Un))return rr[t.local]}function Vn(t,e){return rn(e)?t.findIndex(([,n])=>n.includes(e.local)):-1}var cr=new Set(["pPr","rPr","defRPr","endParaRPr","bodyPr","tblPr","tcPr","ln",...on]);function qn(t){return rn(t)&&cr.has(t.local)}function ar(t,e){let n=Hn(t),o=n?Vn(n,e):-1;return o<0?void 0:n[o][0]}var lr=(t,e)=>t.ns===nn&&t.local==="tc"&&e.ns===nn&&e.local==="txBody",dr="http://schemas.openxmlformats.org/package/2006/content-types",fr="http://schemas.openxmlformats.org/package/2006/relationships",ur=Object.assign(Object.create(null),{[`${dr}|Types`]:{Default:{attr:"Extension",caseless:!0},Override:{attr:"PartName",caseless:!0}},[`${fr}|Relationships`]:{Relationship:{attr:"Id",caseless:!1}}});function We(t,e,n){let o=ur[`${t.ns}|${t.local}`];if(o&&Object.prototype.hasOwnProperty.call(o,e.local)){let{attr:i,caseless:r}=o[e.local],u=n(i);return u===void 0?void 0:{slot:`${e.local}:${r?nr(u):u}`,rule:"key"}}let s=ar(t,e);if(!(s===void 0||lr(t,e)))return{slot:s,rule:qn(e)?"merge":"first"}}function Ge(t,e,n){let o=Hn(t);if(!o)return e;let s=o.indexOf(nt),i=-1,r=!0,u=e.map((l,f)=>{let d=n(l),c=d?Vn(o,d):-1,g=c>=0?c:s>=0?s:i;return g<i&&(r=!1),i=g,{c:l,rank:g,i:f}});return r?e:u.sort((l,f)=>l.rank-f.rank||l.i-f.i).map(l=>l.c)}var Xn=t=>`${t.ns}${yt}${t.local}`,ge=t=>t.slice(0,Math.max(0,t.indexOf("."))),St="_",Bn=t=>t.slice(t.indexOf(".")+1).startsWith(St);function Jn(t,e){let n=t.get(e);return n||(n={merge:!1,companions:[],attrFrom:new Map,childFrom:new Map,shadowed:new Map},t.set(e,n)),n}var sn=(t,e)=>t.attrs?.find(n=>n.ns===""&&n.local===e)?.value;function pr(t,e,n){let o=Jn(n,t.key);o.merge=!0;let s=new Map;for(let a of t.attrs??[])s.set(Xn(a),a);let i=a=>"text"in a?void 0:We(t,a,h=>sn(a,h))?.slot,r=t.children??[],u=new Set(r.map(i)),l=[...r],f=new Map;for(let a of e){o.companions.push(a.key);for(let h of a.attrs??[]){let p=Xn(h);s.has(p)||(s.set(p,h),o.attrFrom.set(p,a.key))}for(let h of a.children??[]){if("text"in h)continue;let p=i(h);if(p===void 0){l.push(h),f.set(h.key,a.key);continue}if(u.has(p)&&!qn(h)){o.shadowed.set(h.key,p);continue}u.add(p),l.push(h),f.set(h.key,a.key)}}let d=cn(t,l,n);if(!d)return null;for(let a of d){let h="text"in a?void 0:f.get(a.key);h!==void 0&&o.childFrom.set(a.key,h)}let c=Ge(t,d,a=>"text"in a?void 0:a),g=[...s.entries()].sort(([a],[h])=>a<h?-1:a>h?1:0);return{...t,attrs:g.map(([,a])=>a),children:[...c]}}function cn(t,e,n){let o=new Map,s=[],i=new Map;for(let r of e){let u="text"in r?void 0:We(t,r,g=>sn(r,g)),l=u?o.get(u.slot):void 0,f=l===void 0?void 0:s[l],d=f!==void 0&&!(Bn(f.key)&&Bn(r.key));if(u&&l===void 0&&o.set(u.slot,s.length),!d){s.push(r);continue}let c=i.get(l);if(c||i.set(l,c=[]),c.length>=et.maxCopiesPerGroup)return null;c.push(r)}for(let[r,u]of i){let l=s[r];if(We(t,l,f=>sn(l,f))?.rule==="merge"){let f=pr(l,u,n);if(!f)return null;s[r]=f}else{let f=Jn(n,l.key);for(let d of u)f.companions.push(d.key)}}return s}import*as fe from"yjs";var z=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"}),Ne="pptx-pieces-v1",at="pptx-moves-v1",bt="pptx-splits-v1",it=2e4,no=64,oo=`${z.removedWith}.`,un=2**31,pn=300,gn=8,Xe=4096,Ae=t=>Number.isSafeInteger(t)&&t>=0,gr=t=>Number.isSafeInteger(t)&&t>=1&&t<un,so="http://schemas.openxmlformats.org/drawingml/2006/main",ct=new Set,xe=t=>t?.type==="element",hn=t=>t===z.removedWith||t.startsWith(oo);function he(t){for(let e of t.keys())if(hn(e))return!0;return!1}function Qn(t,e,n){t.set(`${oo}${e}`,n)}var ln=t=>t.children.filter(xe);function st(t){let n=ln(t).find(o=>o.local==="t")?.children.find(o=>o.type==="text");return n?.type==="text"?n.value:""}function ro(t){if(!t||"text"in t)return"";let e=t.children?.find(o=>!("text"in o)&&o.local==="t"),n=e&&!("text"in e)?e.children?.find(o=>"text"in o):void 0;return n&&"text"in n?n.text:""}function io(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619)>>>0;return e.toString(36)}function dn(t,e,n,o){let s=`${t}\0${io(e)}\0${n}`;return o===void 0?s:`${s}\0${o}`}var Zn=t=>{let e=Number.parseInt(t,36);return Number.isFinite(e)?e:Number.MAX_SAFE_INTEGER};function co(t,e,n,o,s){if(o.size===0)return;let i=m=>{let k=s.get(m),S=k===void 0?void 0:t.nodes.get(k);return S instanceof fe.Map?S:void 0},r=t.doc.clientID.toString(36),u=new Map,l=[],f=new Set,d=new Set,c=m=>{for(let k of ln(m)){if(k.local!=="r"||d.has(k.id))continue;let S=o.get(k.id);if(!xe(S)||S===k||st(S)===st(k))continue;let w=i(k.id);w&&typeof w.get(z.splitFrom)=="string"&&w.get(z.splitEdited)!==!0&&w.set(z.splitEdited,!0)}},g=m=>{let k=ln(m);k.forEach((S,w)=>{if(S.local!=="r"||!o.has(S.id))return;let A=o.get(S.id);if(!xe(A)||A===S)return;let R=st(A),P=st(S);if(R.length<=P.length||!R.startsWith(P))return;let b=R.slice(P.length),I=[],C="",j=[];for(let D=w+1;D<k.length&&C.length<b.length;D+=1){let K=k[D];if(K.local==="br"&&!o.has(K.id)){j.push({el:K,at:P.length+C.length});continue}if(K.local!=="r"||o.has(K.id))break;let T=st(K);I.push({el:K,at:P.length+C.length,length:T.length}),C+=T}let _=s.get(S.id);if(C!==b||_===void 0||I.length===0)return;d.add(S.id);let E=`${_}\0${io(R)}`,O=Math.min((ao(t).latest.get(E)??0)+1,un-1);for(let{el:D,at:K,length:T}of I){let F=i(D.id);if(!F||F.has(z.splitFrom))continue;F.set(z.splitFrom,_),F.set(z.splitBaseText,R),F.set(z.splitAt,K),F.set(z.splitLength,T),F.set(z.splitGeneration,O);let M=s.get(D.id);M!==void 0&&t.doc.getMap(Ne).set(M,e)}for(let{el:D,at:K}of j){let T=i(D.id);!T||T.has(z.splitBreak)||(T.set(z.splitBreak,dn(_,R,O)),T.set(z.splitAt,K))}t.doc.getMap(bt).set(dn(_,R,O,r),P.length)})},a=(m,k)=>{let S=o.get(m.id);if(S===m)return;let w=s.get(m.id),A=w===void 0?k:[w,...k].slice(0,pn),R=xe(S)?new Set(S.children.map(P=>P.id)):new Set;for(let P of m.children)f.add(P.id),!R.has(P.id)&&o.has(P.id)&&l.push({node:P,path:A});if(xe(S)){let P=new Set(m.children.map(b=>b.id));for(let b of S.children)P.has(b.id)||u.set(b.id,b)}m.ns===so&&m.local==="p"&&xe(S)&&(g(m),c(m));for(let P of m.children)xe(P)&&a(P,A)};if(a(n,[]),l.length>0){let m=new Map;for(let w of o.values())xe(w)&&w.children.forEach((A,R)=>m.set(A.id,{parent:w.id,index:R}));let k=t.doc.getMap(at),S=fe.getState(t.doc.store,t.doc.clientID);for(let{node:w,path:A}of l){let R=m.get(w.id),P=R===void 0?void 0:s.get(R.parent),b=s.get(w.id),I=i(w.id);if(!I||!R||P===void 0||b===void 0)continue;let C=I.get(z.movedFrom);if(typeof C=="string"&&C!==P){let j=I.get(z.movedEarlier),_=Array.isArray(j)?j.filter(E=>typeof E=="string"&&E!==C):[];I.set(z.movedEarlier,[C,..._].slice(0,gn))}I.set(z.movedFrom,P),I.set(z.movedIndex,R.index),I.set(z.movedClock,S),I.set(z.movedTo,A),k.set(b,e)}}let h=t.doc.getMap(Ne),p,y,x=m=>(p??=eo(n,s)).has(m);for(let[m,k]of u){if(f.has(m))continue;let S=new Set,w=[k];for(;w.length>0&&S.size<=it;){let b=w.pop(),I=s.get(b.id);if(I!==void 0&&S.add(I),xe(b))for(let C of b.children)f.has(C.id)||w.push(C)}let A=s.get(m);A!==void 0&&mr(t,A,S,x);let R=i(m);if(!R||S.size>it)continue;let P=[...S];Qn(R,r,P);for(let b of S){if(b===A||!h.has(b)||(p??=eo(n,s)).has(b))continue;let I=t.nodes.get(b);!(I instanceof fe.Map)||he(I)||(y??=new Set([...o.keys()].flatMap(C=>s.get(C)??[])),!(!y.has(b)&&hr(t,e,I,p))&&Qn(I,r,[b]))}}}function eo(t,e){let n=new Set,o=[t];for(;o.length>0;){let s=o.pop(),i=e.get(s.id);if(i!==void 0&&n.add(i),xe(s))for(let r of s.children)o.push(r)}return n}function hr(t,e,n,o){let s=Te(n),i=s?Be(t)(s.group):void 0;if(!s||i===void 0)return!1;let r=0;for(let[u,l]of t.doc.getMap(Ne).entries())if(!(l!==e||ge(u)!==i||!o.has(u))&&((r+=1)>Xe||Te(t.nodes.get(u))?.group===s.group))return!0;return!1}function mr(t,e,n,o){let s=[e],i=new Set;for(;s.length>0&&n.size<=it;){let r=s.pop();if(i.has(r))continue;i.add(r),n.add(r);let u=t.nodes.get(r),l=u instanceof fe.Map?u.get(N.children):void 0;if(l instanceof fe.Array)for(let f of l.toArray())typeof f=="string"&&!i.has(f)&&!o(f)&&s.push(f)}}var an=new WeakMap,to=new WeakSet;function ao(t){let e=t.doc.getMap(bt),n=an.get(e);if(n)return n;let o={groups:new Map,latest:new Map};for(let[s,i]of e.entries()){let r=s.split("\0");if(!Ae(i)||r.length!==4)continue;let[u,l,f,d]=r,c=Number(f);if(!Number.isSafeInteger(c)||c<1||c>=un)continue;let g=`${u}\0${l}`,a=`${g}\0${c}`,h=o.groups.get(a);h||o.groups.set(a,h=new Map),h.set(d,i),o.latest.set(g,Math.max(o.latest.get(g)??0,c))}return an.set(e,o),to.has(e)||(to.add(e),e.observe(()=>an.delete(e))),o}function Te(t){if(!(t instanceof fe.Map))return null;let e=t.get(z.splitFrom),n=t.get(z.splitBaseText),o=t.get(z.splitAt),s=t.get(z.splitLength),i=t.get(z.splitGeneration);return typeof e!="string"||typeof n!="string"||!Ae(o)||!Ae(s)||!gr(i)?null:{from:e,group:dn(e,n,i),original:n.slice(o,o+s),at:o,edited:t.get(z.splitEdited)===!0}}function Be(t){let{groups:e}=ao(t),n=new Map;return o=>{if(n.has(o))return n.get(o);let s=e.get(o),i;if(s&&s.size>=2){let r;for(let[u,l]of s)(!r||l<r[1]||l===r[1]&&Zn(u)<Zn(r[0]))&&(r=[u,l]);i=r?.[0]}return n.set(o,i),i}}function lo(t,e,n){let o=new Map,s=new Set,i=r=>{let u=o.get(r);if(u!==void 0||o.has(r))return u??null;let l=e(r);if(!l||l.edited||s.has(r)||s.size>Xe)return null;s.add(r);let f=n(r);for(let d of t.get(r)??[]){let c=i(d);if(c===null){f=null;break}f+=c}return s.delete(r),o.set(r,f),f};return i}function fn(t){let e=new Map;for(let[o,s]of t){let i=e.get(s.from);i?i.push([o,s.at]):e.set(s.from,[[o,s.at]])}let n=new Map;for(let[o,s]of e)n.set(o,s.sort((i,r)=>i[1]-r[1]||(i[0]<r[0]?-1:i[0]>r[0]?1:0)).map(([i])=>i));return n}function fo(t,e){let n=0;for(let o=0;o<e.length&&n<t.length;o+=1)e[o]===t[n]&&(n+=1);return n===t.length}function uo(t,e,n,o,s=ct){if(e.ns!==so||e.local!=="p")return n;let i=new Map,r=new Map;for(let a of n){if("text"in a)continue;let h=Te(t.nodes.get(a.key));if(h){if(i.size>=Xe)return n;i.set(a.key,h),r.set(a.key,ro(a))}}if(i.size===0)return n;let u=fn(i),l=lo(u,a=>i.get(a),a=>r.get(a)??""),f=Be(t),d=new Set;for(let[a,h]of i){let p=f(h.group);if(p===void 0||ge(a)===p||s.has(h.group))continue;let y=l(a);y!==null&&fo(y,h.original)&&d.add(a)}if(d.size===0)return n;let c=[...d];for(;c.length>0;)for(let a of u.get(c.pop())??[])d.has(a)||(d.add(a),c.push(a));for(let a of d)o.add(a);let g=n.filter(a=>"text"in a||!d.has(a.key));return yr(t,g,d,i,f)}function yr(t,e,n,o,s){let i=new Set;for(let f of n){let d=o.get(f);d&&i.add(`${d.group}\0${ge(f)}`)}let r=new Map;for(let f of e){if("text"in f||f.local!=="br")continue;let d=t.nodes.get(f.key);if(!(d instanceof fe.Map))continue;let c=d.get(z.splitBreak),g=d.get(z.splitAt);if(typeof c!="string"||!Ae(g)||!i.has(`${c}\0${ge(f.key)}`))continue;let a;for(let h of e){let p="text"in h?void 0:o.get(h.key);!p||p.group!==c||ge(h.key)!==s(c)||p.at<g||(!a||p.at<a[1])&&(a=[h.key,p.at])}a&&r.set(f.key,a[0])}if(r.size===0)return e;let u=new Map;for(let f of e){let d=r.get(f.key);if(d===void 0)continue;let c=u.get(d);c?c.push(f):u.set(d,[f])}let l=[];for(let f of e)if(!r.has(f.key)){for(let d of u.get(f.key)??[])l.push(d);l.push(f)}return l}function po(t,e,n){if(!n||n.size===0)return e;let o=new Set(e),s=[...e],i=-1;for(let r of t){let u=s.indexOf(r);if(u>=0&&o.has(r)){i=u;continue}!n.has(r)||o.has(r)||(s.splice(i+1,0,r),i+=1)}return s}function go(t,e,n,o,s=ct){let i=t.doc.getMap(Ne);if(i.size===0)return n;let r=new Map,u=E=>{(E.children??[]).forEach((O,D)=>{r.set(O.key,{parent:E,at:D,order:r.size}),"text"in O||u(O)})};u(n);let l=new Map;for(let[E,O]of i.entries()){if(O!==e)continue;let D=t.nodes.get(E);if(!(D instanceof fe.Map)||he(D))continue;let K=Te(D);K&&(l.size>=Xe&&(r.has(E)||l.size>=2*Xe)||l.set(E,K))}let f=Be(t),d=new Map,c=E=>{let O=d.get(E);if(O===void 0){let D=r.get(E);O=ro(D?D.parent.children[D.at]:o(E,new Set,1)??void 0),d.set(E,O)}return O},g=lo(fn(l),E=>l.get(E),c),a=new Map;for(let[E,O]of l){if(ge(E)!==f(O.group))continue;let D=r.get(E)?.order;if(D===void 0)continue;let K=a.get(O.group);(!K||D>K.order)&&a.set(O.group,{key:E,order:D})}let h=new Map,p=E=>{let O=l.get(E).from;O!==E&&h.set(E,O)},y=[];for(let E of[...l.keys()].sort()){let O=l.get(E),D=f(O.group);if(D===void 0||ge(E)===D){s.has(E)&&!r.has(E)&&y.push(E);continue}let K=g(E);if(K!==null&&fo(K,O.original))continue;let T=a.get(O.group)?.key??(r.has(O.from)?O.from:void 0);T!==void 0&&T!==E&&h.set(E,T)}let x=new Set(y);for(let E of y){let O=l.get(E).from;(r.has(O)||x.has(O))&&p(E)}let m=fn(l),k=[...h.keys()];for(;k.length>0;)for(let E of m.get(k.pop())??[])!h.has(E)&&r.has(E)&&(p(E),k.push(E));if(h.size===0)return n;let S=new Map,w=new Set(r.keys());for(let E of h.keys()){let O=r.get(E),D=O?O.parent.children[O.at]:o(E,w,1);D&&S.set(E,D)}let A=new Map,R=E=>{let O=A.get(E);if(O!==void 0)return O;let D=h.get(E);A.set(E,!1);let K=D===void 0?r.has(E):S.has(E)&&R(D);return A.set(E,K),K},P=new Map,b=new Set;for(let[E,O]of h){let D=S.get(E);if(!D||!R(E))continue;b.add(E);let K=P.get(O);K?K.push(D):P.set(O,[D])}if(b.size===0)return n;let I=(E,O)=>{let D=l.get(O);return D?.from===E?D.at:1/0};for(let[E,O]of P)O.sort((D,K)=>I(E,D.key)-I(E,K.key)||(D.key<K.key?-1:D.key>K.key?1:0));let C=new Set,j=(E,O)=>{for(let D of P.get(E)??[])C.has(D.key)||(C.add(D.key),O.push(D),j(D.key,O))},_=E=>{let O=[];for(let D of E.children??[])b.has(D.key)||(O.push("text"in D?D:_(D)),j(D.key,O));return{...E,children:O}};return _(n)}var rt=Object.freeze({unseenWinners:ct,lost:ct});function lt(t,e,n,o=ct){let s=t.doc.getMap(Ne);if(s.size===0)return rt;let i=Be(t),r=new Set,u=new Map,l=0;for(let[y,x]of s.entries()){if(x!==e)continue;let m=t.nodes.get(y);if(!(m instanceof fe.Map)||m.get(N.part)!==e)continue;let k=Te(m);if(k){if(he(m)){ge(y)===i(k.group)&&r.add(k.group);continue}if((l+=1)>Xe)return rt;u.set(y,k)}}if(u.size===0)return rt;let f=new Set,d=[n];for(;d.length>0;){let y=d.pop();if(f.has(y))continue;f.add(y);let x=t.nodes.get(y);if(!(x instanceof fe.Map)||x.get(N.part)!==e)continue;let m=x.get(N.children);if(m instanceof fe.Array)for(let k of m.toArray())typeof k=="string"&&!f.has(k)&&d.push(k)}let c=new Set,g=new Map;for(let[y,x]of u){let m=ge(y)===i(x.group);if(f.has(y)||o.has(y)){m&&r.add(x.group);continue}if(c.add(y),!m)continue;let k=g.get(x.group);k?k.push(y):g.set(x.group,[y])}let a=new Map,h=y=>{let x=a.get(y);if(x!==void 0)return x;a.set(y,!1);let m=u.get(y)?.from,k=m!==void 0&&(f.has(m)||o.has(m)||c.has(m)&&h(m));return a.set(y,k),k},p=new Set;for(let[y,x]of g)!r.has(y)&&!x.some(h)&&p.add(y);return{unseenWinners:p,lost:c}}import*as Mt from"yjs";var kr=1024;function wr(t){if(!(t instanceof Mt.Map))return null;let e=null,n=0;for(let[o,s]of t.entries())if(!(!hn(o)||!Array.isArray(s))){if(s.length>it+1||(n+=1)>no)return"all";e??=new Set;for(let i of s)typeof i=="string"&&e.add(i)}return e}function xr(t,e,n,o,s){if(n.length>pn)return null;for(let i of n){if(typeof i!="string"||o.has(i))return null;let r=s.get(i);if(r===void 0&&(r=wr(t.nodes.get(i)),s.set(i,r)),r==="all")return null;if(r)return r.has(e)?null:i}return null}var mn=(t,e)=>t<e?-1:t>e?1:0,yn=class extends Set{#e;constructor(e){super(),this.#e=e}has(e){return this.#e.has(e)||super.has(e)}};function mo(t,e,n,o,s){let i=t.doc.getMap(at);if(i.size===0)return n;let r=new Map,u=new Map,l=new Map,f=(R,P,b)=>{if(r.set(R.key,P),l.set(R.key,l.size),b!==null&&u.set(R.key,b),!("text"in R))for(let I of R.children??[])f(I,P+1,R.key)};f(n,0,null);let d=[],c=[],g=new Map,a,h=R=>{if(!a){a=new Map;for(let P of i.keys()){if(!u.has(P))continue;let b=t.nodes.get(P),I=b instanceof Mt.Map?b.get(z.movedFrom):void 0;if(typeof I!="string")continue;let C=a.get(I);(C===void 0||l.get(P)>l.get(C))&&a.set(I,P)}}return a.get(R)};for(let[R,P]of i.entries()){if(P!==e||r.has(R))continue;let b=t.nodes.get(R);if(!(b instanceof Mt.Map)||b.get(N.part)!==e||he(b))continue;let I=b.get(z.movedFrom),C=b.get(z.movedTo);if(typeof I!="string"||!Array.isArray(C))continue;let j=b.get(z.movedEarlier),_=r.has(I)?I:(Array.isArray(j)?j.slice(0,gn):[]).find(T=>typeof T=="string"&&r.has(T)),E=b.get(z.movedIndex),O=b.get(z.movedClock),D=typeof O=="number"&&Number.isFinite(O)?O:0,K=xr(t,R,C,r,g);if(K!==null){if(d.length+c.length>=kr)return n;if(_!==void 0){let T=_===I&&Ae(E)?E:1/0;d.push({key:R,from:_,index:T,clock:D,to:C})}else c.push({key:R,last:I,removed:K,index:Ae(E)?E:1/0,clock:D,to:C})}}let p=new Map,y=c,x=0;for(;y.length>0;){let R=[],P=[];for(let b of y){let I=p.get(b.removed),C=I?void 0:h(b.removed),j=I?I.into:C===void 0?void 0:u.get(C),_=I?I.key:C;_===void 0||j===void 0?P.push(b):R.push({...b,after:_,into:j})}if(R.length===0)break;R.sort((b,I)=>b.clock-I.clock||b.index-I.index||mn(b.key,I.key));for(let b of R)d.push({...b,from:b.into,seq:x++}),p.set(b.last,{key:b.key,into:b.into});y=P}if(d.length===0)return n;let m=new Set(d.map(R=>R.key)),k=new Map(d.map(R=>[R.key,R.to.filter(P=>typeof P=="string"&&m.has(P)).length]));d.sort((R,P)=>k.get(R.key)-k.get(P.key)||mn(R.key,P.key));let S=new yn(new Set(r.keys())),w=new Map;for(let R of d){let P=o(R.key,S,r.get(R.from)+1);if(!P)continue;s?.add(P.key);let b={node:P,index:R.index,clock:R.clock,after:R.after,seq:R.seq??0},I=w.get(R.from);I?I.push(b):w.set(R.from,[b])}if(w.size===0)return n;let A=R=>{let P=w.get(R.key),b=(R.children??[]).map(O=>"text"in O?O:A(O));if(!P)return{...R,children:b};let I=[...b],C=P.filter(O=>O.after===void 0).sort((O,D)=>D.clock-O.clock||O.index-D.index||mn(O.node.key,D.node.key));for(let{node:O,index:D}of C)I.splice(Math.min(D,I.length),0,O);let j=P.filter(O=>O.after!==void 0).sort((O,D)=>O.seq-D.seq),_=new Map;for(let{node:O,after:D}of j){let K=_.get(D)??D,T=I.findIndex(F=>F.key===K);I.splice(T<0?I.length:T+1,0,O),_.set(D,O.key)}let E={ns:R.ns,local:R.local};return{...R,children:[...Ge(E,I,O=>"text"in O?void 0:O)]}};return A(n)}function Rt(t){let e=new Set,n=[t];for(;n.length>0;){let o=n.pop();if(e.add(o.key),!("text"in o))for(let s of o.children??[])n.push(s)}return e}var ho=(t,e)=>t.size===e.size&&[...t].every(n=>e.has(n));function yo(t,e){return ho(t.lost,e.lost)&&ho(t.unseenWinners,e.unseenWinners)}import*as ft from"yjs";import{children as kn,elements as Ue,isStructureEdited as Sr,path as ko,TABLE_MAX_COLUMNS as br,TABLE_MAX_ROWS as Mr,tableGridOf as Rr}from"@pptx-editor.dev/core/store";var Yt=Object.freeze({holder:"mh",cover:"cv."}),xn="http://schemas.openxmlformats.org/drawingml/2006/main",Yr="http://schemas.openxmlformats.org/presentationml/2006/main",It=256,wo=4096,dt=t=>t?.type==="element",Et=(t,e)=>!!t&&!("text"in t)&&t.ns===xn&&t.local===e;function Er(t){return(Ue(t).find(n=>n.local==="t")?.children??[]).map(n=>n.type==="text"?n.value:"").join("")}function Sn(t){return Ue(t).some(e=>e.local==="br"||(e.local==="r"||e.local==="fld")&&Er(e).length>0)}function xo(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 n=e.children?.find(o=>!("text"in o)&&o.local==="t");return!!n&&!("text"in n)&&(n.children??[]).some(o=>"text"in o&&o.text!=="")})}function So(t,e){let n=[],o=(s,i)=>{if(s.ns===Yr&&s.local==="graphicFrame"){n.push(s);return}if(i<It)for(let r of e(s))o(r,i+1)};return o(t,0),n}function bo(t){let e=ko(t,"a:graphic","a:graphicData","a:tbl"),n=Math.min(kn(ko(e,"a:tblGrid"),"a:gridCol").length,br),o=kn(e,"a:tr").slice(0,Mr).map(r=>kn(r,"a:tc"));if(n===0||o.length===0)return[];let s=Rr(t,o,n),i=[];return o.forEach((r,u)=>r.slice(0,n).forEach((l,f)=>{let d=s.blocks[s.owner[u*n+f]],c=d&&o[d.row][d.col];c&&(d.row!==u||d.col!==f)&&i.push({tc:l,over:c})})),i}var wn=t=>Ue(t).filter(e=>e.ns===xn&&e.local==="txBody");function Mo(t){let e=new Set;if(!(t instanceof ft.Map))return e;for(let[n,o]of t.entries())if(!(!n.startsWith(Yt.cover)||!Array.isArray(o))){if(o.length>wo)return"all";for(let s of o)typeof s=="string"&&e.add(s)}return e}function Ro(t,e,n,o){if(n.size===0)return;let s=d=>{let c=o.get(d),g=c===void 0?void 0:t.nodes.get(c);return g instanceof ft.Map?g:void 0},i=new Set,r=[],u=(d,c)=>{let g=n.get(d.id);if(g!==d){for(let a of d.children)i.add(a.id);if(d.ns===xn&&d.local==="txBody"&&dt(g)){let a=new Set(d.children.map(p=>p.id)),h=g.children.filter(p=>dt(p)&&p.local==="p");h.length>0&&h.every(p=>!a.has(p.id))&&r.push({body:d,old:g})}if(c<It)for(let a of d.children)dt(a)&&u(a,c+1)}};u(e,0);for(let{body:d,old:c}of r)if(c.children.filter(a=>dt(a)&&a.local==="p").every(a=>i.has(a.id)))for(let a of d.children)dt(a)&&a.local==="p"&&!n.has(a.id)&&!Sn(a)&&s(a.id)?.set(Yt.holder,!0);let l=`${Yt.cover}${t.doc.clientID.toString(36)}`,f=d=>Ue(d).filter(c=>n.get(c.id)!==c);for(let d of So(e,f))for(let{tc:c}of bo(d)){let g=s(c.id),a=wn(c);if(!g||a.length===0)continue;let h=Mo(g);if(h==="all")continue;let p=a.flatMap(m=>Ue(m).filter(k=>k.local==="p")).map(m=>o.get(m.id)).filter(m=>m!==void 0&&!h.has(m));if(p.length===0)continue;let y=g.get(l),x=Array.isArray(y)?y.filter(m=>typeof m=="string"):[];g.set(l,[...x,...p].slice(0,wo+1))}}function Yo(t,e){let n=new Map(t);return n.delete(e),n}function Eo(t,e,n){let o=[];if(!e||e.size===0)return o;let s=(i,r)=>{let u=n.get(i.id);if(u!==void 0&&e.has(u)&&o.push(i),r<It)for(let l of Ue(i))s(l,r+1)};return s(t,0),o}function Io(t,e){e.set(t.key,t);let n=(t.children??[]).map(o=>"text"in o?{type:"text",id:o.key,value:o.text}:Io(o,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:n}}function Ir(t,e,n,o,s){let i=new Map,r=Io(n,i),u=Sr(r);for(let{tc:l,over:f}of bo(r)){let d=wn(f)[0],c=d&&i.get(d.id);if(!c)continue;let g=Mo(t.nodes.get(l.id)),a=x=>{if(g==="all"||g.has(x))return!1;let m=t.nodes.get(x);return m instanceof ft.Map?u?!0:typeof m.get(z.movedFrom)=="string"||he(m):!1},h=wn(l).flatMap(x=>{let m=i.get(x.id);if(!m)return[];let k=m.children??[],S=k.filter(w=>Et(w,"p")&&(e.has(w.key)||xo(w)&&a(w.key)));return[{from:m,kids:k,going:S,paragraphs:k.filter(w=>Et(w,"p")).length}]});h.every(x=>x.going.length===x.paragraphs)&&[...h].reverse().find(x=>x.going.length>0)?.going.pop();let p=new Set(h.filter(x=>x.going.length===x.paragraphs).map(x=>x.from)),y=i.get(l.id);y&&p.size>0&&p.size<h.length&&s.set(y.key,(y.children??[]).filter(x=>!p.has(x)));for(let{from:x,kids:m,going:k}of h){if(k.length===0)continue;let S=new Set(k);s.set(x.key,m.filter(A=>!S.has(A)));let w=o.get(c.key);if(w)for(let A of k)w.push(A);else o.set(c.key,k)}}}function vo(t,e,n,o){let s=new Map,i=new Map,r=So(e,f=>(f.children??[]).filter(d=>!("text"in d)));for(let f of r)Ir(t,n,f,s,i);if(s.size===0&&n.size===0)return e;let u=f=>{if(!Et(f,"p")||xo(f))return!1;let d=t.nodes.get(f.key);return d instanceof ft.Map&&d.get(Yt.holder)===!0},l=(f,d)=>{let c=i.get(f.key)??f.children??[],g=s.get(f.key);g&&(c=[...c,...g]),f.local==="txBody"&&c.some(p=>Et(p,"p")&&n.has(p.key))&&(c=c.filter(p=>!u(p)));let a=d<It?c.map(p=>"text"in p?p:l(p,d+1)):c,h=a.length===(f.children??[]).length&&a.every((p,y)=>p===f.children[y]);return!h&&f.local==="txBody"&&o?.add(f.key),h?f:{...f,children:a}};return l(e,0)}import*as U from"yjs";var ee=Object.freeze({copyOf:"ci",newParagraph:"cp",seen:"cs",followed:"cf.",removedRun:"rr."}),De="pptx-copies-v1",Po=1<<20,Co=4096,vr=1024,Mn=32,bn=1024,vt=1024,Nt="http://schemas.openxmlformats.org/drawingml/2006/main",H=(t,e)=>`${t}:${e}`,Ye=t=>Number.isSafeInteger(t)&&t>=0,Oo=new WeakMap;function Ee(t){if(!(t instanceof U.Map))return null;let e=t.get(ee.copyOf),n=Oo.get(t);if(n&&n.value===e)return n.copy;let o=Do(e,t.get(ee.newParagraph)===!0);return Oo.set(t,{value:e,copy:o}),o}function Do(t,e){if(!Array.isArray(t)||t.length<5||(t.length-2)%3!==0||t.length>2+3*Po)return null;let[n,o]=t;if(!Ye(n)||!Ye(o))return null;let s=[],i=0;for(let u=2;u<t.length;u+=3){let l=t[u],f=t[u+1],d=t[u+2];if(!Ye(l)||!Ye(f)||!Ye(d)||d===0||(s.push(i),i+=d,i>Po))return null}let r=t;return{client:n,clock:o,length:i,newParagraph:e,source(u){let l=0,f=s.length-1;for(;l<f;){let c=l+f+1>>1;s[c]<=u?l=c:f=c-1}let d=2+3*l;return U.createID(r[d],r[d+1]+(u-s[l]))}}}var No=new WeakMap;function At(t){let e=[];if(!(t instanceof U.Map))return e;let n=0;for(let[o,s]of t.entries()){if(++n>vr)break;if(!o.startsWith(ee.followed)||!Array.isArray(s))continue;let i=No.get(s);i===void 0&&No.set(s,i=Do(s,!1)),i&&e.push(i)}return e}function Pr(t,e){let n=s=>s!==null&&s.client===e.client&&e.clock>=s.clock&&e.clock<s.clock+s.length,o=Ee(t);return n(o)?o:At(t).find(n)??null}function Lo(t,e,n,o){t.set(`${ee.followed}${H(e,n)}`,[e,n,...Fo(o)])}function _o(t,e){let n=new Set,o=t.nodes;for(let[s,i]of e.changed){if(s===o){for(let u of i)u!==null&&At(o.get(u)).length>0&&n.add(u);continue}if(!(s instanceof U.Map)||s.parent!==o)continue;let r=s.get(N.key);if(typeof r=="string")for(let u of i)u?.startsWith(ee.followed)&&n.add(r)}return n}var Ie="pptx-restored-v1",Le=65536,Or=/^(\d{1,16}):(\d{1,16})$/,Pt=new WeakMap,Ao=new WeakSet;function Nr(t){let e=Pt.get(t);if(e)return e;Ao.has(t)||(Ao.add(t),t.observe(()=>Pt.delete(t))),e=new Map;for(let[n,o]of t.entries()){let s=Or.exec(n);if(!s||!Array.isArray(o)||o.length!==3||!o.every(Ye))continue;let[i,r,u]=o;if(u===0||u>Le)continue;let l=Number(s[1]),f=Number(s[2]);if(!Number.isSafeInteger(l)||!Number.isSafeInteger(f))continue;let d=e.get(l),c=[f,i,r,u];d?d.push(c):e.set(l,[c])}for(let n of e.values())n.sort((o,s)=>o[0]-s[0]);return Pt.set(t,e),e}function He(t,e){let n=t.getMap(Ie);if(n.size===0)return null;let o=Nr(n).get(e.client);if(!o)return null;let s=0,i=o.length-1;for(;s<i;){let u=s+i+1>>1;o[u][0]<=e.clock?s=u:i=u-1}let r=o[s];return!r||e.clock<r[0]||e.clock>=r[0]+r[3]?null:U.createID(r[1],r[2]+(e.clock-r[0]))}function pt(t,e){if(e.length===0)return;let n=t.getMap(Ie);for(let o=0;o+3<e.length;o+=4)n.set(H(t.clientID,e[o]),[e[o+1],e[o+2],e[o+3]]);Pt.delete(n)}function Fo(t){let e=[];for(let n of t){let o=e.length;o>0&&e[o-3]===n.client&&e[o-2]+e[o-1]===n.clock?e[o-1]+=1:e.push(n.client,n.clock,1)}return e}function Ar(t,e){let n=new Set;for(let s=e._start;s!==null;s=s.right)if(n.add(s.id.client),n.size>Co)return null;let o=[];for(let s of[...n].sort((i,r)=>i-r))o.push(s,U.getState(t.store,s));return o}var To=new WeakMap;function zo(t){if(!(t instanceof U.Map))return null;let e=t.get(ee.seen),n=To.get(t);(!n||n.value!==e)&&(n={value:e,seen:Tr(e)},To.set(t,n));let o=n.seen;return o?s=>s.clock<(o.get(s.client)??0):null}function Tr(t){if(!Array.isArray(t)||t.length%2!==0||t.length>2*Co)return null;let e=new Map;for(let n=0;n<t.length;n+=2){let o=t[n],s=t[n+1];if(!Ye(o)||!Ye(s)||e.has(o))return null;e.set(o,s)}return e}function Tt(t,e,n){let o=[],s=0;for(let i=t._start;i!==null&&o.length<n;i=i.right)if(!(i.deleted||!i.countable))for(let r=0;r<i.length&&o.length<n;r+=1,s+=1)s>=e&&o.push(U.createID(i.id.client,i.id.clock+r));return o}function ye(t,e){if(U.getState(t.store,e.client)<=e.clock)return null;let n=U.getItem(t.store,e);return n instanceof U.Item?n:null}function Rn(t){let e=t.parent,n=e instanceof U.Text?e.parent:null;return n instanceof U.Map?n:null}function Ct(t,e){let n=ye(t,e);return!n||n.deleted}function ue(t,e,n,o=!0){let s=H(e.client,e.clock),i=n?.get(s);if(i)return i;let r=e;for(let u=0;u<Mn;u+=1){let l=ye(t,r),f=l?Pr(Rn(l),r):null;if(f){r=f.source(r.clock-f.clock);continue}let d=o?He(t,r):null;if(!d)break;r=d}return n?.set(s,r),r}var Ce=t=>t?.type==="element",Ot=t=>t.children.filter(Ce),le=(t,e)=>t.ns===Nt&&t.local===e;function jo(t){return Ot(t).find(n=>le(n,"t"))?.children.find(n=>n.type==="text")}var ut=t=>{let e=jo(t);return e?.type==="text"?e.value:""};function Ko(t,e,n,o,s,i){let r=new Set;if(o.size===0||i.size===0)return r;let u=t.doc.getMap(De),l=c=>{let g=jo(c);return g?s.get(g.id):void 0},f=(c,g,a)=>{let h=Ot(c);h.forEach((p,y)=>{if(!le(p,"r"))return;let x=o.get(p.id);if(!Ce(x)||x===p)return;let m=ut(x),k=ut(p);if(m.length<=k.length||!m.startsWith(k))return;let S=l(p),w=S===void 0?void 0:i.get(S),A=m.length-k.length;if(!w||w.deleted.length!==A)return;let R=[],P=0,b=(F,M,L)=>{for(let v=M;v<F.length&&P<A;v+=1){let $=F[v];if(!(!o.has($.id)&&le($,"br"))&&!le($,"pPr")){if(le($,"endParaRPr"))return!0;if(!le($,"r")||o.has($.id))return!1;R.push({run:$,newParagraph:L}),P+=ut($).length}}return!0},I=b(h,y+1,!1),C=g[a+1],j=h.slice(y+1).every(F=>o.has(F.id)||le(F,"endParaRPr"));P<A&&I&&j&&C&&le(C,"p")&&!o.has(C.id)&&b(Ot(C),0,!0);let _=R.length>0&&R.every(F=>F.newParagraph),E=R.map(F=>ut(F.run)).join("");if(P>A||P<A&&!(_&&m.endsWith(E)))return;let O=S===void 0?void 0:t.nodes.get(S),D=O instanceof U.Map?O.get(N.text):void 0,K=D instanceof U.Text?Ar(t.doc,D):null,T=A-P;for(let F of R){let M=l(F.run),L=ut(F.run).length,v=M===void 0?void 0:i.get(M),$=M===void 0?void 0:t.nodes.get(M),G=w.deleted.slice(T,T+L);if(T+=L,!(L===0||!v?.created||v.inserted?.length!==L)&&!(!($ instanceof U.Map)||M===void 0)){$.set(ee.copyOf,[v.inserted.client,v.inserted.clock,...Fo(G)]),F.newParagraph&&$.set(ee.newParagraph,!0),K&&$.set(ee.seen,K),u.set(M,e);for(let oe of G)r.add(H(oe.client,oe.clock))}}})},d=c=>{if(o.get(c.id)===c)return;let g=Ot(c);g.forEach((a,h)=>{le(a,"p")&&Ce(o.get(a.id))&&f(a,g,h)});for(let a of g)d(a)};return d(n),r}function $o(t,e,n,o){let s=[];if(n.size===0)return s;let i=new Set,r=[],u=l=>{let f=n.get(l.id);if(f!==l){for(let d of l.children)i.add(d.id);if(Ce(f)){let d=new Set(l.children.map(g=>g.id)),c="";for(let g of f.children)!d.has(g.id)&&Ce(g)&&(le(g,"r")||le(g,"p"))&&r.push({node:g,from:l,prev:c}),c=o.get(g.id)??c}for(let d of l.children)Ce(d)&&u(d)}};u(e);for(let{node:l,from:f,prev:d}of r){if(i.has(l.id))continue;let c=o.get(l.id),g=o.get(f.id),a=g===void 0?void 0:t.nodes.get(g);(le(l,"r")&&le(f,"p")||le(l,"p")&&le(f,"txBody")&&!Sn(l))&&c!==void 0&&a instanceof U.Map&&a.set(`${ee.removedRun}${c}`,d);let p=[l];for(;p.length>0;){let y=p.pop();if(y!==l&&i.has(y.id))continue;if(Ce(y)){for(let S of y.children)p.push(S);continue}let x=o.get(y.id),m=x===void 0?void 0:t.nodes.get(x),k=m instanceof U.Map?m.get(N.text):void 0;if(!(!(k instanceof U.Text)||y.type!=="text"||y.value.length===0)&&k.toString()===y.value){for(let S of Tt(k,0,k.length))s.push(S);k.delete(0,k.length)}}}return s}function Wo(t,e){let n=o=>{let s=o.get(N.children);return s instanceof U.Array?s.toArray().filter(i=>typeof i=="string"):[]};for(let o of n(e).slice(0,bn)){let s=t.nodes.get(o);if(!(s instanceof U.Map))continue;let i=s.get(N.shell);if(!(i?.ns!==Nt||i.local!=="t"))for(let r of n(s).slice(0,bn)){let u=t.nodes.get(r),l=u instanceof U.Map?u.get(N.text):void 0;if(l instanceof U.Text&&l.length>0)return!0}}return!1}var Cr=t=>(t.children??[]).some(e=>!("text"in e)&&e.local==="t"&&(e.children??[]).some(n=>"text"in n&&n.text.length>0));function Dr(t,e){let n=e.get(N.children);if(!(n instanceof U.Array))return!1;let o=e.get(N.key),s=new Set;for(let r of e.keys())r.startsWith(ee.removedRun)&&s.size<vt&&s.add(r.slice(ee.removedRun.length));let i=n.toArray().slice(0,bn);for(let r of[...i,...s]){let u=typeof r=="string"?t.nodes.get(r):void 0;if(!(u instanceof U.Map))continue;let l=u.get(N.shell);if(l?.ns!==Nt)continue;if(l.local==="br")return!0;if(l.local!=="r"&&l.local!=="fld")continue;if(!(s.has(r)&&(!he(u)||u.get(z.movedFrom)===o))&&Wo(t,u))return!0}return!1}function Go(t,e,n,o,s){let i=new Map;for(let m of n.keys()){if(!m.startsWith(ee.removedRun))continue;let k=n.get(m);if(typeof k=="string"&&(i.set(m.slice(ee.removedRun.length),k),i.size>=vt))break}if(i.size===0)return o;let r=new Set(o.map(m=>m.key)),u=n.get(N.key),l=n.get(N.shell)?.local==="txBody",f=l?"p":"r",d=l?["bodyPr","lstStyle"]:["pPr"],c=new Map;for(let m of[...i.keys()].sort()){if(r.has(m))continue;let k=t.nodes.get(m);if(!(k instanceof U.Map)||k.get(N.part)!==e)continue;let S=k.get(N.shell);if(S?.ns!==Nt||S.local!==f||!he(k)||k.get(z.movedFrom)===u)continue;let A=(l?Dr:Wo)(t,k),R=s(m);R&&(A||Cr(R))&&c.set(m,R)}if(c.size===0)return o;let g=m=>{let k=i.get(m)??"";for(let S=0;S<vt&&k!==""&&!r.has(k)&&!c.has(k);S+=1)k=i.get(k)??"";return r.has(k)||c.has(k)?k:""},a=new Map;for(let[m,k]of c){let S=g(m),w=a.get(S);w?w.push(k):a.set(S,[k])}let h=[],p=new Set,y=(m,k)=>{if(!(k>vt))for(let S of a.get(m)??[])p.has(S.key)||(p.add(S.key),h.push(S),y(S.key,k+1))},x=!1;for(let m of o)!x&&("text"in m||!d.includes(m.local))&&(x=!0,y("",0)),h.push(m),y(m.key,0);x||y("",0);for(let m of c.values())p.has(m.key)||h.push(m);return h}import*as q from"yjs";import*as ke from"yjs";function be(t){if(!(t instanceof ke.AbstractType))return null;let e=t._item;return e instanceof ke.Item?e:null}function pe(t,e,n){for(let[o,s]of e.clients){let i=t.store.clients.get(o);if(!(!i||i.length===0))for(let{clock:r,len:u}of s){let l=i[i.length-1];if(!(r>=l.id.clock+l.length))for(let f=ke.findIndexSS(i,r);f<i.length;f+=1){let d=i[f];if(d.id.clock>=r+u)break;d instanceof ke.Item&&n(d)}}}}function Dt(t,e,n){let o=ke.createDeleteSet();for(let[s,i]of e.clients){let r=t.store.clients.get(s),u=[];for(let{clock:l,len:f}of i){if(!r||r.length===0){u.push({clock:l,len:f});continue}let d=l+f,c=l,g=r[r.length-1];if(l<g.id.clock+g.length)for(let a=ke.findIndexSS(r,l);a<r.length;a+=1){let h=r[a];if(h.id.clock>=d)break;if(!(h instanceof ke.Item)||!n(h))continue;let p=Math.max(l,h.id.clock);p>c&&u.push({clock:c,len:p-c}),c=Math.min(d,h.id.clock+h.length)}d>c&&u.push({clock:c,len:d-c})}u.length>0&&o.clients.set(s,u)}return o}function*Yn(t){for(let e=t._start;e;e=e.right)e.deleted||(yield e)}function*Xo(t){for(let e of t._map.values())e.deleted||(yield e)}function Lt(t,e){let n=0;for(let o=t._start;o!==null;o=o.right)if(!(o.deleted||!o.countable)){if(o.id.client===e.client&&e.clock>=o.id.clock&&e.clock<o.id.clock+o.length)return n+(e.clock-o.id.clock);n+=o.length}return-1}function _e(t,e){let n=[],o=0;for(let s=t._start;s!==null&&n.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}`)&&n.push(o+i);o+=s.length}for(let s=n.length-1;s>=0;){let i=s;for(;i>0&&n[i-1]===n[i]-1;)i-=1;t.delete(n[i],n[s]-n[i]+1),s=i-1}}var Bo=t=>t.left===null;var ve="pptx-undone-v1",Lr=64,Uo=1024,_r=1<<18,Fr=(t,e)=>t.id.client!==e.client||t.id.clock>=e.clock;function zr(t,e,n){if(typeof e!="object"||e===null)return null;let o=e;if(typeof o.p!="string"||n!==void 0&&o.p!==n||typeof o.u!="string"||typeof o.a!="string"||!Number.isSafeInteger(o.c)||o.c<0)return null;let s=Number.isSafeInteger(o.q)&&o.q>=0?o.q:1/0,i=typeof o.n=="string"?o.n:"",r=typeof o.s=="string"?o.s:null;return{key:t,parent:o.u,after:o.a,before:i,client:o.c,clock:s,shownIn:r}}function qo(t,e,n){let o=t.nodes,s=new Map,i=new Set;if(pe(t.doc,e.insertions,d=>{d.parent===t.parts&&d.parentSub!==null&&!d.deleted&&i.add(d.parentSub)}),pe(t.doc,e.insertions,d=>{let c=d.parent;if(d.deleted||!(c instanceof q.Array))return;let g=c.parent;if(!(g instanceof q.Map)||be(g)?.parent!==o||g.get(N.children)!==c||d.parentSub!==null||!(d.content instanceof q.ContentAny))return;let a=s.get(c);a||s.set(c,a=new Set);for(let h of d.content.getContent())typeof h=="string"&&a.add(h)}),s.size===0)return;let r=t.doc.getMap(ve),u=t.doc.clientID,l=q.getState(t.doc.store,u),f=[];for(let[d,c]of s){let g=d.parent;if(!(g instanceof q.Map)||g.get(N.children)!==d)continue;let a=g.get(N.key),h=g.get(N.part);if(typeof a!="string"||typeof h!="string"||i.has(h))continue;let p=d.toArray().filter(y=>typeof y=="string");p.forEach((y,x)=>{if(!c.has(y))return;let m=p[x+1]??"",k={p:h,u:a,a:p[x-1]??"",n:m,c:u,q:l};JSON.stringify(r.get(y))!==JSON.stringify(k)&&f.push([y,k])})}f.length>0&&n(()=>{for(let[d,c]of f)r.set(d,c)})}function Jo(t,e,n,o,s,i){let r=t.doc.getMap(ve),u=t.doc.clientID,l=new Set;for(let f of s){let d=o[f],c=typeof d=="string"?i(d):void 0;if(typeof d!="string"||c===void 0||l.has(d))continue;l.add(d);let g="";for(let p=f-1;p>=0&&g==="";p-=1)o[p]!==d&&typeof o[p]=="string"&&(g=o[p]);let a="";for(let p=f+1;p<o.length&&a==="";p+=1)o[p]!==d&&typeof o[p]=="string"&&(a=o[p]);let h={p:e,u:n,a:g,n:a,c:u,q:0,s:c};JSON.stringify(r.get(d))!==JSON.stringify(h)&&r.set(d,h)}}function Qo(t,e,n){let o=t.doc.getMap(ve);if(o.size===0)return;let s=new Set;pe(t.doc,e.deletions,i=>{if(!(!(i.parent instanceof q.Array)||!(i.content instanceof q.ContentAny)))for(let u of i.content.getContent())typeof u=="string"&&o.has(u)&&s.add(u)}),s.size>0&&n(()=>{for(let i of s)o.delete(i)})}function Zo(t,e,n){let o=new Map;if(pe(t.doc,e.insertions,r=>{if(r.parent!==t.nodes||r.parentSub===null||!(r.content instanceof q.ContentType)||!(r.content.type instanceof q.Map))return;let u=r.content.type;if(t.nodes.get(r.parentSub)!==u)return;let l=u.get(N.part),f=u.get(N.attrs),d=u.get(N.children);if(typeof l!="string"||!(f instanceof q.Map)||!(d instanceof q.Array)||f.size>0||d.length>0||!n(l,r.parentSub))return;let c=o.get(l);c||o.set(l,c=new Set),c.add(r.parentSub)}),o.size===0)return!1;let s=!1,i=0;for(let r of t.nodes.values()){if((i+=1)>_r)break;if(!(r instanceof q.Map))continue;let u=r.get(N.part),l=typeof u=="string"?o.get(u):void 0,f=r.get(N.children);if(!l||!(f instanceof q.Array))continue;let d=f.toArray();for(let c=d.length-1;c>=0;c-=1){let g=d[c];typeof g=="string"&&l.has(g)&&(f.delete(c,1),s=!0)}}return s}var Ho=new WeakMap;function Vo(t,e,n){let o=t.placeOf.get(e);if(o){let l=t.byPart.get(o.part),f=l?.get(o.parent);f?.delete(e),f?.size===0&&l.delete(o.parent),t.placeOf.delete(e)}let s=n===void 0?null:zr(e,n),i=s?n.p:null;if(!s||i===null)return;let r=t.byPart.get(i);r||t.byPart.set(i,r=new Map);let u=r.get(s.parent);u||r.set(s.parent,u=new Map),u.set(e,s),t.placeOf.set(e,{part:i,parent:s.parent})}function jr(t,e){let n=t.doc.getMap(ve),o=Ho.get(n);if(!o){let s={byPart:new Map,placeOf:new Map};o=s;for(let[i,r]of n.entries())Vo(s,i,r);Ho.set(n,s),n.observe(i=>{for(let r of i.keysChanged)Vo(s,r,n.get(r))})}return o.byPart.get(e)??new Map}var En="http://schemas.openxmlformats.org/drawingml/2006/main",es=new Set(["p","pPr","rPr","endParaRPr","ln","bodyPr","tcPr"]);function ts(t){if("text"in t)return t.text.length>0;if(t.ns!==En)return!1;let e=t.children??[];return t.local==="r"?e.some(n=>!("text"in n)&&n.ns===En&&n.local==="t"&&ts(n)):t.local==="t"?e.some(n=>"text"in n&&n.text.length>0):es.has(t.local)&&(e.length>0||(t.attrs??[]).length>0)}var _t=class t{#e;#t;#n;#i=new Map;shown=new Set;constructor(e,n,o){this.#e=e,this.#t=n,this.#n=o}static of(e,n,o){if(e.doc.getMap(ve).size===0)return null;let s=jr(e,n);if(s.size===0)return null;let i=new Set,r=[o];for(;r.length>0;){let u=r.pop();if(i.has(u))continue;i.add(u);let l=e.nodes.get(u);if(!(l instanceof q.Map)||l.get(N.part)!==n)continue;let f=l.get(N.children);if(f instanceof q.Array)for(let d of f.toArray())typeof d=="string"&&!i.has(d)&&r.push(d)}return new t(e,s,i)}#s(e,n,o){let s=`${e}\0${n.client}\0${n.clock}`,i=this.#i.get(s);if(i!==void 0)return i;this.#i.set(s,!1);let r=o<=Lr&&this.#l(e,n,o);return this.#i.set(s,r),r}#l(e,n,o){let s=this.#e.nodes.get(e);if(!(s instanceof q.Map))return!1;let i=d=>Fr(d,n),r=s.get(N.text);if(r instanceof q.Text){for(let d of Yn(r))if(d.countable&&i(d))return!0}let u=s.get(N.attrs);if(u instanceof q.Map){for(let d of Xo(u))if(i(d))return!0}let l=s.get(N.children);if(l instanceof q.Array){for(let d of Yn(l))if(i(d))return!0}let f=0;for(let d of s.keys())if(d.startsWith(ee.removedRun)){if((f+=1)>Uo)break;if(this.#s(d.slice(ee.removedRun.length),n,o+1))return!0}return this.#r(e).some(d=>this.#s(d.key,d,o+1))}#r(e){return[...this.#t.get(e)?.values()??[]].filter(n=>{if(this.#n.has(n.key)||n.shownIn!==null&&!this.#n.has(n.shownIn))return!1;let o=this.#e.nodes.get(n.key);return o instanceof q.Map&&!he(o)})}withUndone(e,n,o,s,i){let r=this.#r(e).filter(g=>!s.has(g.key)&&this.#s(g.key,g,0)).sort((g,a)=>g.key<a.key?-1:g.key>a.key?1:0).slice(0,Uo);if(r.length===0)return o;let u=[...o],l=new Set(u.map(g=>g.key)),f=new Map([...this.#t.get(e)?.values()??[]].map(g=>[g.key,g.after])),d=new Set(r.map(g=>g.key)),c="\0";for(let g=!1;d.size>0;){let a=!1;for(let h of r){if(!d.has(h.key))continue;let p=h.after,y=p!==""&&!l.has(p)&&!d.has(p)&&l.has(h.before)?h.before:null;y!==null&&(p=c);let x=new Set([h.key]),m=!1;for(;p!==""&&p!==c&&!l.has(p);){if(d.has(p)&&!g){m=!0;break}x.has(p)?p=c:(x.add(p),p=f.get(p)??c)}if(m)continue;d.delete(h.key),a=!0;let k=this.#c(h.key,n,s,i);if(!k||!ts(k))continue;let S=y!==null?u.findIndex(w=>w.key===y):p===""?0:p===c?u.length:u.findIndex(w=>w.key===p)+1;u.splice(S,0,k),l.add(h.key),this.shown.add(h.key)}a||(g=!0)}return u}#c(e,n,o,s){let i=this.#e.nodes.get(e);if(!(i instanceof q.Map)||i.get(N.part)!==n)return null;let r=i.get(N.text);if(r instanceof q.Text)return o.add(e),{key:e,text:r.toString()};let u=i.get(N.shell),{ns:l,local:f}=typeof u=="object"&&u!==null?u:{};return l!==En||typeof f!="string"||!es.has(f)&&f!=="r"&&f!=="t"?null:s(e)}};function os(t){let e=new Map;if(!t)return e;let n=[t];for(;n.length>0;){let o=n.pop();if(e.set(o.id,o),o.type==="element")for(let s of o.children)n.push(s)}return e}function Kr(t,e){let n=t.length,o=e.length,s=new Uint32Array((n+1)*(o+1));for(let f=n-1;f>=0;f--)for(let d=o-1;d>=0;d--)s[f*(o+1)+d]=t[f]===e[d]?s[(f+1)*(o+1)+d+1]+1:Math.max(s[(f+1)*(o+1)+d],s[f*(o+1)+d+1]);let i=new Set,r=new Set,u=0,l=0;for(;u<n&&l<o;)t[u]===e[l]?(i.add(u++),r.add(l++)):s[(u+1)*(o+1)+l]>=s[u*(o+1)+l+1]?u++:l++;return{keepA:i,keepB:r}}function In(t,e){let n=t.toArray();if(n.length===e.length&&n.every((r,u)=>r===e[u]))return;if(n.length*e.length>25e4){t.delete(0,n.length),t.insert(0,[...e]);return}let{keepA:o,keepB:s}=Kr(n,e);for(let r=n.length-1;r>=0;r--)o.has(r)||t.delete(r,1);let i=0;e.forEach((r,u)=>{s.has(u)||t.insert(i,[r]),i+=1})}function ss(t,e){if(t.size===0)return t;let n=Rt(e);return new Map([...t].filter(([o])=>n.has(o)))}function ns(t){let e=new Map;if(t?.kind!=="xml")return e;let n=[[t.xml.root,""]];for(;n.length>0;){let[o,s]=n.pop();if(e.set(o.id,s),o.type==="element")for(let i of o.children)n.push([i,`${o.id}/${s}`])}return e}function rs(t,e,n){let o,s;return i=>{let r=t?.get(i);if(r===void 0)return!1;o??=ns(e),s??=ns(n);let u=o.get(r);return u!==void 0&&u===s.get(r)}}function is(t,e,n){let o;return s=>{let i=t?.get(s);if(i===void 0||n?.kind!=="xml")return;if(!o){let u=new Map,l=[n.xml.root];for(;l.length>0;){let f=l.pop();if(f.type==="element")for(let d of f.children)u.set(d.id,f.id),l.push(d)}o=u}let r=o.get(i);return r===void 0?void 0:e?.get(r)}}var Wr="http://schemas.openxmlformats.org/drawingml/2006/main",Gr=1<<20;function Xr(t,e,n){let o=t.toString();if(o===e)return;let s=0;for(;s<o.length&&s<e.length&&o[s]===e[s];)s++;let i=0;for(;i<o.length-s&&i<e.length-s&&o[o.length-1-i]===e[e.length-1-i];)i++;let r=a=>a>=55296&&a<=56319,u=a=>a>=56320&&a<=57343;s>0&&r(o.charCodeAt(s-1))&&s--,i>0&&u(o.charCodeAt(o.length-i))&&i--;let l=o.length-s-i,f=e.length-s-i;if(l===f&&!/[\uD800-\uDFFF]/.test(o.slice(s,s+l)+e.slice(s,s+f))){let a=Tt(t,s,l),h=[];for(let p=s;p<s+l;p++){if(o[p]===e[p])continue;let y=a[p-s];y&&h.push(y),t.insert(p,e[p]),t.delete(p+1,1)}return{created:n,deleted:h}}let d=l>0?Tt(t,s,l):[];l>0&&t.delete(s,l);let c=t.doc,g=c?B.getState(c.store,c.clientID):0;return f>0&&t.insert(s,e.slice(s,e.length-i)),{created:n,deleted:d,...f>0&&c?{inserted:{client:c.clientID,clock:g,length:f}}:{}}}var cs=(t,e)=>t.attrs.find(n=>n.ns===""&&n.local===e)?.value,Br=t=>({ns:t.ns,local:t.local,...t.prefix?{prefix:t.prefix}:{},nsDecls:t.nsDecls.map(e=>({prefix:e.prefix,uri:e.uri}))}),Ft=class{#e;#t=new Map;#n=new Map;#i=new Map;#s=new Set;#l=new Map;#r=new Map;#c=new Map;#g=new Set;#a=new Map;#d=new Map;#f=rt;#u=null;#w=new Map;#h=new Map;#x;#m=new Set;constructor(e,n={value:0}){this.#e=e,this.#x=n;let o=`${e.doc.clientID.toString(36)}.`;for(let s of e.nodes.keys()){if(!s.startsWith(o))continue;let i=Number.parseInt(s.slice(o.length).replace(St,""),36);Number.isSafeInteger(i)&&i<=Kn&&i>n.value&&(n.value=i)}}get seeded(){return this.#e.parts.size>0}#M(e,n){for(let o of this.#i.get(e)??[])this.#n.delete(o);for(let[o,s]of n)this.#n.set(o,s);this.#i.set(e,new Set(n.keys())),this.#s.clear(),this.#w.clear();for(let[o,s]of this.#n)for(let i of s.companions)this.#s.add(i),this.#w.set(i,o)}#S(e,n){for(let o of this.#t.get(e)?.idOf.keys()??[])this.#h.delete(o);if(!n){this.#t.delete(e);return}this.#t.set(e,n);for(let o of n.idOf.keys())this.#h.set(o,e)}#E(e){let n=this.#t.get(e);return n||(n={keyOf:new Map,idOf:new Map},this.#t.set(e,n)),n}#y=!1;#I(){let e=this.#e.doc.clientID.toString(36),n=this.#y?St:"",o;do this.#x.value+=1,o=`${e}.${n}${this.#x.value.toString(36)}`;while(this.#e.nodes.has(o));return o}seed(e){this.#y=!0;try{for(let n of e.parts.values())this.#R(n,void 0)}finally{this.#y=!1}}hasHiddenListings(e){return e.some(n=>this.#a.has(n))}dropHiddenListings(e,n,o){for(let s of e){let i=this.#a.get(s);if(!i)continue;let r=rs(this.#t.get(s)?.idOf,n.parts.get(s),o.parts.get(s)),u=this.#t.get(s),l=is(u?.idOf,u?.keyOf,n.parts.get(s));this.#a.delete(s);for(let[f,d]of i){let c=this.#Y(f);if(!c||c.length!==d.length)continue;let g=[...d.at.keys()].sort((h,p)=>p-h);if(g.some(h=>c.get(h)!==d.at.get(h)))continue;let a=g.filter(h=>r(d.at.get(h)));a.length>0&&Jo(this.#e,s,f,c.toArray(),a,l);for(let h=0;h<g.length;){let p=h+1;for(;p<g.length&&g[p]===g[p-1]-1;)p++;c.delete(g[p-1],p-h),h=p}}}}writeChange(e,n,o){for(let s of o){let i=n.parts.get(s);if(!i){this.#e.parts.delete(s),this.#e.binaries.delete(s),this.#S(s,void 0);continue}this.#R(i,e.parts.get(s))}}#R(e,n){if(e.kind==="binary"){(n?.kind!=="binary"||n.bytes!==e.bytes)&&this.#e.binaries.set(e.partName,e.bytes),$e(this.#e.parts.get(e.partName))?.kind!=="binary"&&this.#e.parts.set(e.partName,{kind:"binary"});return}n?.kind==="binary"&&this.#e.binaries.delete(e.partName);let o={partName:e.partName,ids:this.#E(e.partName),before:os(n?.kind==="xml"?n.xml.root:void 0),texts:new Map},s=this.#b(e.xml.root,o),i=this.#r.get(e.partName);this.#r.delete(e.partName);for(let u of Eo(e.xml.root,i,o.ids.keyOf))this.#b(u,{...o,before:Yo(o.before,u.id)});co(this.#e,e.partName,e.xml.root,o.before,o.ids.keyOf),Ro(this.#e,e.xml.root,o.before,o.ids.keyOf),this.#v(e.partName,e.xml.root,o);let r=$e(this.#e.parts.get(e.partName));(r?.kind!=="xml"||r.root!==s)&&this.#e.parts.set(e.partName,{kind:"xml",root:s})}#v(e,n,o){if(this.#y)return;let s=Ko(this.#e,e,n,o.before,o.ids.keyOf,o.texts),i=$o(this.#e,n,o.before,o.ids.keyOf),r=this.#e.doc,u=new Map,l=f=>{if(this.#m.size>=Gr||s.has(H(f.client,f.clock)))return;let d=ue(r,f,u,!1);this.#m.add(H(d.client,d.clock))};for(let f of o.texts.values())for(let d of f.deleted)l(d);for(let f of i)l(f)}get deletedText(){return this.#m}showingUnlisted(e){return e.filter(n=>(this.#c.get(n)?.size??0)>0)}forgetDeleted(e){for(let n of e)this.#m.delete(n)}newCopies(e){let n=new Map,o=e.changed.get(this.#e.nodes);if(!o)return n;let s=this.#e.doc.getMap(De);for(let i of o){if(i===null)continue;let r=s.get(i),u=this.#e.nodes.get(i),l=Ee(u);if(typeof r!="string"||!l||l.client===this.#e.doc.clientID||u.get(N.part)!==r)continue;let f=n.get(r);f?f.push(i):n.set(r,[i])}return n}#b(e,n){let{partName:o,ids:s,before:i}=n,r=s.keyOf.get(e.id),u=r===void 0?void 0:this.#e.nodes.get(r);if(r!==void 0&&u instanceof B.Map&&i.get(e.id)===e)return r;let l=r===void 0||!(u instanceof B.Map);if(r===void 0||!(u instanceof B.Map)){r=this.#I();let b=new B.Map;this.#e.nodes.set(r,b),b.set(N.part,o),b.set(N.key,r),e.type==="text"?b.set(N.text,new B.Text):(b.set(N.attrs,new B.Map),b.set(N.children,new B.Array)),u=b,s.keyOf.set(e.id,r),s.idOf.set(r,e.id),this.#h.set(r,o)}let f=u;if(e.type==="text"){let b=f.get(N.text),I=b instanceof B.Text?Xr(b,e.value,l):void 0;return I&&n.texts.set(r,I),r}let d=Br(e);JSON.stringify(f.get(N.shell))!==JSON.stringify(d)&&f.set(N.shell,d);let c=this.#n.get(r),g=this.#e.doc.clientID.toString(36),a=c?.merge?[r,...c.companions].find(b=>ge(b)===g)??r:r,h=f.get(N.attrs);if(h instanceof B.Map){let b=new Map;for(let C of e.attrs)b.set(`${C.ns}${yt}${C.local}`,{ns:C.ns,local:C.local,value:C.value,...C.prefix?{prefix:C.prefix}:{}});let I=c?.merge?c.companions.map(C=>this.#k(C)):[];for(let C of[...h.keys()])b.has(C)||h.delete(C);for(let C of I)for(let j of[...C?.keys()??[]])b.has(j)||C.delete(j);for(let[C,j]of b){let _=c?.attrFrom.get(C)??(h.has(C)?r:void 0),E=_===void 0?void 0:this.#k(_);if(E&&JSON.stringify(E.get(C))===JSON.stringify(j))continue;if((this.#k(a)??h).set(C,j),c?.merge)for(let D of[r,...c.companions])D!==a&&this.#k(D)?.delete(C)}}let p=e.children.map(b=>this.#b(b,n)),y=new Set(p),x=f.get(N.children),m=(b,I)=>{let C=[],j=new Set,_=E=>{j.has(E)||(j.add(E),C.push(E))};for(let E of b){_(E);for(let O of this.#n.get(E)?.companions??[])I.has(O)&&_(O)}return C},k=new Set(x instanceof B.Array?x.toArray():[]),S=this.#c.get(o),w=c?p.filter(b=>!c.childFrom.has(b)&&!k.has(b)&&!S?.has(b)):[],A=(c?p.filter(b=>!c.childFrom.has(b)&&(k.has(b)||a===r)):p).filter(b=>!S?.has(b)||k.has(b));if(x instanceof B.Array){let b=x,I=b.toArray();In(b,po(I,this.#P(e,I,m(A,new Set(I))),this.#l.get(o)))}let R=new Set;if(c?.merge)for(let b of e.children)b.type==="element"&&R.add(We(e,b,I=>cs(b,I))?.slot);let P=new Set(w);c?.merge&&e.children.forEach((b,I)=>{b.type==="element"&&P.has(p[I])&&R.delete(We(e,b,C=>cs(b,C))?.slot)});for(let b of c?.merge?c.companions:[]){let I=this.#Y(b);if(!I)continue;let C=I.toArray(),j=C.filter(_=>{if(this.#s.has(_))return y.has(this.#w.get(_));if(c.childFrom.get(_)===b)return y.has(_);let E=c.shadowed.get(_);return E!==void 0&&R.has(E)});In(I,m([...j,...b===a?w:[]],new Set(C)))}return r}#P(e,n,o){let s=new Set(o),i=new Set(n),r=n.filter(a=>s.has(a)),u=o.filter(a=>i.has(a)),l=(a,h)=>a.length===h.length&&a.every((p,y)=>p===h[y]);if(l(r,u)||!l(Ge(e,r,a=>this.#O(a)),u))return o;let f=new Map,d=[],c;for(let a=o.length-1;a>=0;a--){let h=o[a];if(i.has(h))c=h;else if(c===void 0)d.unshift(h);else{let p=f.get(c);p||f.set(c,p=[]),p.unshift(h)}}let g=[];for(let a of r){for(let h of f.get(a)??[])g.push(h);g.push(a)}for(let a of d)g.push(a);return g}#O(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.shell):void 0;if(typeof o!="object"||o===null)return;let{ns:s,local:i}=o;return typeof s=="string"&&typeof i=="string"?{ns:s,local:i}:void 0}#k(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.attrs):void 0;return o instanceof B.Map?o:void 0}#Y(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.children):void 0;return o instanceof B.Array?o:void 0}keyOf(e,n){return this.#t.get(e)?.keyOf.get(n)}idOf(e,n){return this.#t.get(e)?.idOf.get(n)}textOf(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.text):void 0;return o instanceof B.Text?o:void 0}partOf(e){let n=this.#e.nodes.get(e),o=n instanceof B.Map?n.get(N.part):void 0;return typeof o=="string"?o:void 0}recordOfText(e){let n=e.parent,o=n instanceof B.Map?n.get(N.key):void 0;if(typeof o!="string"||this.#e.nodes.get(o)!==n)return;let s=n.get(N.part);return typeof s=="string"?{key:o,part:s}:void 0}touchedParts(e){let n=new Set,o=this.#e.parts,s=this.#e.binaries,i=this.#e.nodes,r=this.#e.doc,u=[r.getMap(Ne),r.getMap(at)],l=r.getMap(bt),f=r.getMap(ve);for(let[d,c]of e.changed){let g=d;if(g===o||g===s){for(let p of c)p!==null&&n.add(p);continue}if(u.includes(g)){for(let p of c){let y=p===null?void 0:d.get(p);typeof y=="string"&&n.add(y)}continue}if(g===f){for(let p of c){if(p===null)continue;let y=this.#e.doc.getMap(ve).get(p),x=typeof y=="object"&&y!==null?y.p:void 0,m=this.#e.nodes.get(p),k=typeof x=="string"?x:m instanceof B.Map?m.get(N.part):void 0;typeof k=="string"&&n.add(k)}continue}if(g===l){for(let p of c){let y=p===null?void 0:this.#e.nodes.get(p.split("\0")[0]),x=y instanceof B.Map?y.get(N.part):void 0;typeof x=="string"&&n.add(x)}continue}if(g===i){for(let p of c){if(p===null)continue;let y=this.#e.nodes.get(p),x=y instanceof B.Map?y.get(N.part):void 0;if(typeof x=="string"){n.add(x);continue}let m=this.#h.get(p);m!==void 0&&n.add(m)}continue}let a=g;for(;a instanceof B.AbstractType&&a.parent!==i;)a=a.parent;let h=a instanceof B.Map?a.get(N.part):void 0;typeof h=="string"&&n.add(h)}return n}allParts(e){let n=new Set(this.#e.parts.keys());for(let o of e.parts.keys())n.add(o);return n}rebuild(e,n,o=!1){let s=[],i=[],r=new Map,u=new Map,l=new Map,f=new Map,d=new Map,c=[...e];for(let a of c)[this.#a,this.#r].forEach(h=>h.delete(a));let g=new Map;for(let a of c){let h=$e(this.#e.parts.get(a));if(!h){if(this.#e.parts.has(a))return{ok:!1,reason:`invalid part entry ${a}`};n.parts.has(a)&&i.push(a);continue}if(h.kind==="binary"){let _=this.#e.binaries.get(a);if(!(_ instanceof Uint8Array)||_.length>et.maxBinaryBytes)return{ok:!1,reason:`invalid binary part ${a}`};s.push({kind:"binary",partName:a,bytes:_});continue}let p=new Map;this.#g=new Set,this.#o=void 0,this.#f=lt(this.#e,a,h.root),this.#d=new Map,this.#u=_t.of(this.#e,a,h.root);let y=(_,E,O)=>this.#p(_,a,E,O,p),x=new Set,m=()=>{x=new Set;let _=this.#p(h.root,a,new Set,0,p);return _&&mo(this.#e,a,_,y,x)},k=m(),S=this.#f;if(k&&(S.lost.size>0||S.unseenWinners.size>0)){let _=lt(this.#e,a,h.root,Rt(k));yo(_,S)||(this.#f=_,this.#g=new Set,this.#d=new Map,p.clear(),k=m())}if(!k)return{ok:!1,reason:`${this.#o??"invalid node records"} in ${a}`};let w=go(this.#e,a,k,y,this.#f.lost);if(this.#o)return{ok:!1,reason:`${this.#o} in ${a}`};let A=new Set,R=vo(this.#e,w,x,A);d.set(a,A);let P=o?void 0:this.#t.get(a),b=n.parts.get(a),I=b?.kind==="xml"?b.xml.nextId:1,C=$r(a,R,{idOf:_=>P?.idOf.get(_),nextId:I});if(!C.ok)return{ok:!1,reason:`${a}: ${C.reason}`};let j={keyOf:new Map,idOf:new Map};for(let[_,E]of C.ids)j.idOf.set(_,E),j.keyOf.set(E,_);r.set(a,j),u.set(a,p),l.set(a,this.#g),f.set(a,ss(this.#d,R)),g.set(a,this.#u?.shown??new Set),s.push({kind:"xml",partName:a,xml:C.part})}for(let[a,h]of r)this.#S(a,h);for(let a of i)this.#S(a,void 0);for(let[a,h]of u)this.#M(a,h);for(let a of i)this.#M(a,new Map);for(let[a,h]of l)this.#l.set(a,h);for(let a of i)this.#l.delete(a);for(let[a,h]of f)h.size>0&&this.#a.set(a,h);for(let a of i)this.#a.delete(a);for(let[a,h]of g)this.#c.set(a,h);for(let a of i)this.#c.delete(a);for(let[a,h]of d)this.#r.set(a,h);return this.#u=null,{ok:!0,parts:s,removed:i}}#o;#p(e,n,o,s,i){if(s>et.maxReadDepth||o.has(e))return null;o.add(e);let r=this.#e.nodes.get(e);if(!(r instanceof B.Map)||r.get(N.part)!==n)return null;let u=r.get(N.shell),l=r.get(N.attrs),f=r.get(N.children);if(typeof u!="object"||u===null||!(l instanceof B.Map)||!(f instanceof B.Array))return null;let d=u,c=[],g=f.toArray();for(let[S,w]of g.entries()){if(typeof w!="string")continue;if(o.has(w)){let P=this.#d.get(e);P||this.#d.set(e,P={length:g.length,at:new Map}),P.at.set(S,w);continue}let A=this.#e.nodes.get(w);if(A instanceof B.Map&&A.get(N.text)instanceof B.Text){if(A.get(N.part)!==n)continue;o.add(w),c.push({key:w,text:A.get(N.text).toString()});continue}let R=this.#p(w,n,o,s+1,i);if(R)c.push(R);else if(this.#o)return null}let a=[...l.entries()].sort(([S],[w])=>S<w?-1:S>w?1:0).map(([,S])=>S),h=d.ns,p=d.local,y=(p==="p"||p==="txBody")&&h===Wr?Go(this.#e,n,r,c,S=>{let w=this.#p(S,n,o,s+1,i);return this.#o?null:w}):c,x=this.#u?this.#u.withUndone(e,n,y,o,S=>this.#p(S,n,o,s+1,i)):y;if(this.#o)return null;let m=uo(this.#e,{ns:h,local:p},x,this.#g,this.#f.unseenWinners),k=cn({ns:h,local:p},m,i);return k?{key:e,ns:h,local:p,...typeof d.prefix=="string"?{prefix:d.prefix}:{},nsDecls:Array.isArray(d.nsDecls)?d.nsDecls:[],attrs:a,children:[...Ge({ns:h,local:p},k,S=>"text"in S?void 0:S)]}:(this.#o="too many concurrent copies of one element",null)}};import*as Se from"yjs";var zt="pptxEditor",Ur=256,ls=256,ds=512,fs=256,us=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,Fe=(t,e=Ur)=>typeof t=="string"&&t.trim().length>0&&t.length<=e;function ps(t){return!Fe(t.actorId)||!Fe(t.name)||t.role!==void 0&&t.role!=="human"&&t.role!=="agent"?"invalid-identity":t.color!==void 0&&!us.test(t.color)?"invalid-identity-color":null}function gs(t){let{actorId:e,name:n,color:o,role:s}=t;return!Fe(e)||!Fe(n)?null:{actorId:e,name:n,...typeof o=="string"&&us.test(o)?{color:o}:{},...s==="human"||s==="agent"?{role:s}:{}}}function hs(t){let e=t?.[zt];return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function ms(t,e){if(t.kind==="shapes"){let i=t.shapes.slice(0,ds).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 n=i=>{let r=e.keyOf(t.part,i.node);if(r===void 0)return;let u=e.textOf(r);if(!u)return{key:r};let l=Math.max(0,Math.min(Math.trunc(i.offset)||0,u.length));return{rel:Se.relativePositionToJSON(Se.createRelativePositionFromTypeIndex(u,l))}},o=n(t.anchor),s=n(t.head);return o&&s?{kind:"text",anchor:o,head:s}:void 0}function ys(t,e){return{actorId:t.actorId,name:t.name,...t.color?{color:t.color}:{},...t.role?{role:t.role}:{},...e?{selection:e}:{}}}function ks(t){let e=[];for(let[n,o]of t.getStates()){if(e.length>=ls)break;let s=hs(o),i=s?gs(s):null;i&&e.push({...i,isLocal:n===t.clientID})}return e}function as(t,e,n){if(typeof t!="object"||t===null)return null;let o=t;if(Fe(o.key,fs)){let l=n.partOf(o.key),f=l?n.idOf(l,o.key):void 0;return l&&f?{part:l,node:f,offset:0}:null}let s=o.rel;if(typeof s!="object"||s===null)return null;let i;try{i=Se.createAbsolutePositionFromRelativePosition(Se.createRelativePositionFromJSON(s),e)}catch{return null}if(!i||!(i.type instanceof Se.Text))return null;let r=n.recordOfText(i.type),u=r?n.idOf(r.part,r.key):void 0;return r&&u?{part:r.part,node:u,offset:i.index}:null}function jt(t,e,n){if(typeof t!="object"||t===null)return null;let o=t;if(o.kind==="shapes"&&Fe(o.part,1024)&&Array.isArray(o.keys)){let s=o.part,i=o.keys.slice(0,ds).filter(r=>Fe(r,fs)).map(r=>n.idOf(s,r)).filter(r=>r!==void 0);return i.length>0?{kind:"shapes",part:s,shapes:i}:null}if(o.kind==="text"){let s=as(o.anchor,e,n),i=as(o.head,e,n);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 ws(t,e,n){let o=[],s=0;for(let[i,r]of t.getStates()){if(++s>ls)break;if(i===t.clientID)continue;let u=hs(r),l=u?gs(u):null;if(!u||!l)continue;let f=jt(u.selection,e,n);f&&o.push({actorId:l.actorId,name:l.name,...l.color?{color:l.color}:{},selection:f})}return o}import*as J from"yjs";var Hr=4096,Ss=1<<20,Vr=65536,qr=1<<20,xs="http://schemas.openxmlformats.org/drawingml/2006/main",Jr=t=>t.type==="element";function Qr(t,e){let n=ye(t,e);if(!n)return null;let o=0;for(let s=n.parent instanceof J.Text?n.parent._start:null;s;s=s.right){if(s===n)return{text:n.parent,at:o+(e.clock-n.id.clock)};o+=s.length}return null}function Zr(t,e){let n=new Map,o=t.package.parts.get(e);if(o?.kind!=="xml")return n;let s=(i,r,u)=>{let l=t.keyOf(e,i.id),f=i.ns===xs&&i.local==="p"&&l&&u?{p:{key:l,parent:u}}:i.ns===xs&&i.local==="r"&&l?{...r,run:l}:r;for(let d of i.children)if(Jr(d))s(d,f,l);else{let c=t.keyOf(e,d.id);c!==void 0&&n.set(c,{order:n.size,...f})}};return s(o.xml.root,{},void 0),n}function bs(t,e,n,o,s,i){let r=t.doc,u=r.clientID,l=M=>{let L=t.nodes.get(M),v=Ee(L),$=L instanceof J.Map?L.get(N.text):void 0;return!v||!($ instanceof J.Text)||L.get(N.part)!==e?null:{key:M,copy:v,text:$}},f=new Set(n.filter(M=>{let L=l(M);return L!==null&&L.copy.client!==u}));if(f.size===0)return;let d=Zr(s,e),c=[],g=0;for(let[M,L]of t.doc.getMap(De).entries()){if(L!==e)continue;let v=l(M);if(!(!v||v.text.length===0&&!d.has(M))){if(c.length>=Hr||(g+=v.copy.length)>Ss)return;c.push(v)}}let a=c.filter(M=>f.has(M.key));if(a.length===0)return;let h=new Map,p=M=>ue(r,M,h),y=new Map,x=new Map,m=M=>(x.has(M.key)||x.set(M.key,Qr(r,p(M.copy.source(0)))),x.get(M.key)),k=(M,L)=>{let v=m(M),$=m(L);return v&&$&&v.text===$.text?v.at-$.at:0},S=M=>d.get(M.key)?.order??-1,w=(M,L)=>(k(M,L)||S(M)-S(L))>=0?M:L,A=(M,L)=>J.createID(M.copy.client,M.copy.clock+L),R=M=>{if(M.copy.newParagraph)return!0;let L=M.copy.source(0);for(let v=0;v<Mn;v+=1){let $=ye(r,L),G=$?Ee(Rn($)):null,oe=G?L.clock-G.clock:-1;if(!G||L.client!==G.client||oe<0||oe>=G.length)return!1;if(G.newParagraph)return!0;L=G.source(oe)}return!1},P=new Map;for(let M of c)if(d.has(M.key))for(let L=0;L<M.copy.length;L+=1){let v=A(M,L);if(Ct(r,v))continue;let $=p(M.copy.source(L)),G=H($.client,$.clock),oe=P.get(G);oe?oe.push({copy:M,id:v}):P.set(G,[{copy:M,id:v}])}let b=M=>P.get(H(M.client,M.clock))?.reduce((L,v)=>w(L.copy,v.copy)===L.copy?L:v);for(let M of a)ti(t,M,zo(t.nodes.get(M.key)),L=>b(p(L)),i);let I=new Map,C=(M,L)=>{let v=I.get(M);v?v.push(L):I.set(M,[L])};if(o.size>0)for(let M of a)for(let L=0;L<M.copy.length;L+=1){let v=ue(r,M.copy.source(L),y,!1);o.has(H(v.client,v.clock))&&!Ct(r,A(M,L))&&C(M.text,A(M,L))}let j=new Map,_=M=>{let L=j.get(M.key);return L===void 0&&j.set(M.key,L=R(M)),L};for(let M of P.values()){if(M.length<2||!M.some(v=>f.has(v.copy.key))||!M.some(v=>_(v.copy))||new Set(M.map(v=>v.copy.key)).size<2)continue;let L=M.reduce((v,$)=>w(v.copy,$.copy)===v.copy?v:$);for(let v of M)v!==L&&C(v.copy.text,v.id)}for(let[M,L]of I)_e(M,new Set(L.map(v=>H(v.client,v.clock))));let E=new Map,O=M=>{let L=E.get(M.key);if(!L){L=new Set;for(let v=0;v<M.copy.length;v+=1){let $=p(M.copy.source(v));L.add(H($.client,$.clock))}E.set(M.key,L)}return L},D=qr,K=(M=1)=>(D-=M)>=0,F={room:t,me:u,incoming:a,all:c,placed:d,share:(M,L)=>{let[v,$]=[O(M),O(L)].sort((G,oe)=>G.size-oe.size);if(!K(v.size))return!1;for(let G of v)if($.has(G))return!0;return!1},laterStart:k,step:K};ni(F),ei(F)}function Kt(t,e){let n=t.nodes.get(e),o=n instanceof J.Map?n.get(N.children):void 0;return o instanceof J.Array?o:void 0}function ei({room:t,me:e,incoming:n,all:o,placed:s,share:i,step:r}){let u=new Map,l=(f,d)=>{let c=u.get(f);if(!c){u.set(f,c=new Map);let g=Vr,a=h=>{let p=Kt(t,h)?.toArray()??[];return g-=p.length,g<0?[]:p};for(let h of a(f))for(let p of a(h))for(let y of a(p))for(let x of a(y))c.set(x,{p:h,run:p})}return c.get(d)};for(let f of n){let d=s.get(f.key);if(!(!d?.p||!d.run))for(let c of o){if(!r())return;if(c.copy.client!==e||c.key===f.key||!i(f,c))continue;let g=l(d.p.parent,c.key),a=g?t.nodes.get(g.run):void 0;if(!g||g.p===d.p.key||!(a instanceof J.Map)||a.get(z.movedFrom)!==d.p.key)continue;let h=Kt(t,d.p.key),p=Kt(t,g.p),y=h?.toArray().indexOf(d.run)??-1;if(!(!h||!p||y<0)){h.delete(y,1),p.insert(p.toArray().indexOf(g.run),[d.run]);break}}}}function ti(t,e,n,o,s){let i=t.doc,r=i.clientID,l=ye(i,e.copy.source(0))?.parent;if(!(l instanceof J.Text))return;let f=new Set;for(let a=0;a<e.copy.length;a+=1){let h=e.copy.source(a);f.add(H(h.client,h.clock))}let d=new Map,c=[],g=null;for(let a=l._start;a!==null;a=a.right){if(a.deleted||!(a.content instanceof J.ContentString))continue;let h=a.content.str;for(let p=0;p<h.length;p+=1){let y=J.createID(a.id.client,a.id.clock+p),x=p===0?a.origin:J.createID(a.id.client,a.id.clock+p-1),m=x?H(x.client,x.clock):"",k=a.id.client!==r||!x?void 0:f.has(m)?x:d.get(m);if(!k){g=null;continue}if(d.set(H(y.client,y.clock),k),n?.(y))continue;(!g||!J.compareIDs(g.anchor,k))&&(g={anchor:k,ids:[],written:[],text:"",marks:[]},c.push(g)),g.ids.push(y);let S=He(i,y);S&&o(y)||(S&&g.marks.push([g.text.length,S]),g.written.push(y),g.text+=h[p])}}for(let a of c){let h=o(a.anchor),p=h?Lt(h.copy.text,h.id):-1;if(!h||p<0||(_e(l,new Set(a.ids.map(m=>H(m.client,m.clock)))),a.text.length===0))continue;let y=J.getState(i.store,r);h.copy.text.insert(p+1,a.text);let x=t.nodes.get(h.copy.key);x instanceof J.Map&&Lo(x,r,y,a.written),pt(i,a.marks.flatMap(([m,k])=>[y+m,k.client,k.clock,1])),s(a.ids[0],J.createID(r,y),a.text.length)}}function Ms(t,e,n){if(n.size===0)return;let o=t.doc,s=new Map,i=0;for(let r of e){let u=t.nodes.get(r),l=u instanceof J.Map?u.get(N.text):void 0;if(!(l instanceof J.Text))continue;let f=[];for(let d of At(u))if(!(d.client===o.clientID||(i+=d.length)>Ss))for(let c=0;c<d.length;c+=1){let g=J.createID(d.client,d.clock+c),a=ue(o,d.source(c),s,!1);n.has(H(a.client,a.clock))&&!Ct(o,g)&&f.push(g)}f.length>0&&_e(l,new Set(f.map(d=>H(d.client,d.clock))))}}function ni({room:t,me:e,incoming:n,all:o,placed:s,share:i,laterStart:r,step:u}){for(let l of o){if(l.copy.client!==e||!l.copy.newParagraph)continue;let f=s.get(l.key)?.p,d=f?Kt(t,f.parent):void 0;if(!f||!d)continue;let c=d.toArray();if(!u(c.length))return;let g=new Map(c.map((p,y)=>[p,y])),a=g.get(f.key)??-1;if(a<0)continue;let h;for(let p of n){if(!u())return;if(p.key===l.key||r(l,p)<=0)continue;let y=s.get(p.key)?.p;if(!y||y.parent!==f.parent||y.key===f.key)continue;let x=g.get(y.key)??-1;x<=a||h&&x<=h.at||!i(p,l)||(h={key:y.key,at:x})}h&&(d.delete(a,1),d.insert(d.toArray().indexOf(h.key)+1,[f.key]))}}import*as Rs from"yjs";var oi=new Set([N.part,N.key,N.shell,ee.copyOf,ee.newParagraph]);function Ys(t){return e=>{let n=e.parent;if(n===t)return!1;let o=be(n);return o===null||o.parent!==t?!0:e.content instanceof Rs.ContentType?!1:!(e.parentSub!==null&&oi.has(e.parentSub)&&Bo(e))}}import*as re from"yjs";var si=4096,ri=4096,ii=32;function ci(t,e,n,o,s=new Set){let i=t.doc,r=new Map,u=0;for(let[l,f]of i.getMap(De).entries()){if(typeof f!="string"||!e.has(f)||!n(f,l))continue;if((u+=1)>si)return null;let d=t.nodes.get(l),c=d instanceof re.Map?d.get(N.text):void 0;if(!(!Ee(d)||!(c instanceof re.Text))){for(let g=c._start;g!==null;g=g.right)if(!(g.deleted||!g.countable))for(let a=0;a<g.length;a+=1){let h=H(g.id.client,g.id.clock+a);if(s.has(h))continue;let p=ue(i,re.createID(g.id.client,g.id.clock+a),o),y=H(p.client,p.clock);y!==h&&!r.has(y)&&r.set(y,{text:c,item:g,j:a})}}}return r}function ze(t,e){let n=e.parent;if(!(n instanceof re.Map)||be(n)?.parent!==t.nodes)return null;let o=n.get(N.part);return typeof o=="string"?o:null}function Es(t,e){let n=t.content.getContent();return n.length>0&&typeof n[0]=="string"?String(n.join("")).charAt(e):""}var ai=t=>re.createID(t.item.id.client,t.item.id.clock+t.j);function Is(t,e,n){let o=t.doc,s=[],i=new Map,r=!1;return pe(o,e,u=>{if(r||!u.countable||!(u.parent instanceof re.Text)||u.redone===null)return;let l=u.parent,f=ye(o,u.redone);if(!ze(t,l)||!f||f.deleted||f.parent!==l)return;let d=Math.min(u.length,f.length);for(let c=0;c<d;c+=1){if(s.length>=Le){r=!0;return}let g=ue(o,re.createID(u.id.client,u.id.clock+c),i);s.push({text:l,item:f,j:c,root:g,char:Es(f,c)})}}),!r&&vs(t,s,n,i,()=>!0)}function vs(t,e,n,o,s){let i=t.doc;if(e.length===0)return!1;let r=new Set;for(let p of e)r.add(ze(t,p.text));let u=p=>H(p.item.id.client,p.item.id.clock+p.j),l=new Set(e.map(u)),f=ci(t,r,n,o,l);if(!f||f.size===0)return!1;let d=p=>{let y=0,x=p.item,m=p.j-1;for(;x!==null&&y<ri;){for(;m>=0&&x.countable;m-=1,y+=1){let k=re.createID(x.id.client,x.id.clock+m);if(l.has(H(k.client,k.clock)))continue;let S=ue(i,k,o),w=f.get(H(S.client,S.clock));if(w&&w.text!==p.text)return w;if(!x.deleted)return null}x=x.left,m=x?x.length-1:-1}return null},c=[],g=[];for(let p of e){let y=f.get(H(p.root.client,p.root.clock));if(y&&y.text!==p.text){c.push(p);continue}let x=s(p)?d(p):null;if(!x)continue;let m=g[g.length-1];m&&m.to.item===x.item&&m.to.j===x.j?m.chars.push(p):g.push({to:x,chars:[p]})}if(c.length===0&&g.length===0)return!1;let a=[];for(let{to:p,chars:y}of g){let x=Lt(p.text,ai(p));if(x<0)continue;let m=y.map(S=>S.char).join("");if(m.length===0)continue;let k=re.getState(i.store,i.clientID);p.text.insert(x+1,m),y.forEach((S,w)=>a.push(k+w,S.root.client,S.root.clock,1)),c.push(...y)}pt(i,a);let h=new Map;for(let p of c){let y=h.get(p.text);y?y.add(u(p)):h.set(p.text,new Set([u(p)]))}for(let[p,y]of h)_e(p,y);return!0}function vn(t,e){let n=t.doc,o=[],s=new Set,i=new Set,r=new Map,u=0;return pe(n,e,l=>{if(!l.countable||!(l.parent instanceof re.Text)||l.redone===null)return;let f=l.parent,d=l.redone;if(d.client!==n.clientID||ze(t,f)===null)return;let c=ye(n,d);if(!(!c||c.parent!==f)){i.add(f);for(let g=0;g<l.length;g+=1){if((u+=1)>Le)return;let a=re.createID(l.id.client,l.id.clock+g);for(let m=0;m<ii;m+=1){let k=He(n,a);if(!k)break;a=k}let h=ue(n,a,r,!1);s.add(H(h.client,h.clock));let p=d.clock+g,y=o.length;y>0&&o[y-4]+o[y-1]===p&&o[y-3]===a.client&&o[y-2]+o[y-1]===a.clock?o[y-1]+=1:o.push(p,a.client,a.clock,1)}}}),pt(n,o),{roots:s,texts:i}}function Pn(t,e){let n=t.doc,o=n.getMap(Ie),s=new Set;for(let i of e){let r=i===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(i),u=i===null?void 0:o.get(i);if(!r||!Array.isArray(u))continue;let l=Math.min(Number(u[2])||0,Le),f=Number(r[1]);for(let d=Number(r[2]),c=d+l;d<c;){let g=ye(n,re.createID(f,d));if(!g)break;if(!g.deleted&&g.parent instanceof re.Text&&ze(t,g.parent)){s.add(g.parent);break}d=g.id.clock+g.length}}return s}function On(t,e){let n=new Set,o=0;for(let s of t.doc.getMap(Ie).keys()){if((o+=1)>Le)break;for(let i of Pn(t,[s])){let r=ze(t,i);r!==null&&e.has(r)&&n.add(i)}}return n}function li(t,e){let n=be(e.parent);return n&&n.parent===t.nodes&&typeof n.parentSub=="string"?n.parentSub:null}var di=(t,e)=>t.client<e.client||t.client===e.client&&t.clock>e.clock;function Nn(t,e,n){let o=t.doc,s=new Map,i=[...e],r=new Set;for(let p of i){let y=ze(t,p);y!==null&&r.add(y)}if(r.size===0)return!1;let u=new Set(On(t,r));for(let p of i)u.add(p);let l=new Map,f=new Map,d=(p,y)=>{let x=f.get(p);x?x.add(H(y.client,y.clock)):f.set(p,new Set([H(y.client,y.clock)]))},c=0;for(let p of u){let y=ze(t,p),x=li(t,p);if(y===null||x===null)continue;let m=n(y,x)?"":`${x}\0`;for(let k=p._start;k!==null&&c<Le;k=k.right)if(!(k.deleted||!k.countable))for(let S=0;S<k.length;S+=1,c+=1){let w=re.createID(k.id.client,k.id.clock+S);if(!He(o,w))continue;let A=ue(o,w,s),R=m+H(A.client,A.clock),P=l.get(R);P?di(w,P.id)?(d(P.text,P.id),l.set(R,{id:w,text:p})):d(p,w):l.set(R,{id:w,text:p})}}for(let[p,y]of f)_e(p,y);let g=[];for(let{id:p,text:y}of l.values()){let x=ye(o,p);if(!x||x.deleted||x.parent!==y)continue;let m=p.clock-x.id.clock;g.push({text:y,item:x,j:m,root:ue(o,p,s),char:Es(x,m)})}let a=o.clientID;return vs(t,g,n,s,p=>p.item.id.client===a)||f.size>0}import*as ie from"yjs";function Ps(t,e,n){let o=s=>{let i=t.nodes.get(s),r=i instanceof ie.Map?i.get(N.children):void 0;return r instanceof ie.Array?r.toArray():[]};for(let s of o(e))if(!(typeof s!="string"||t.nodes.get(s)?.get?.(N.shell)?.local!=="t"))for(let r of o(s)){let u=typeof r=="string"?t.nodes.get(r):void 0,l=u instanceof ie.Map?u.get(N.text):void 0;l instanceof ie.Text&&n.add(l)}}var Ve=(t,e)=>be(e)?.parent===t.nodes&&e instanceof ie.Map?e:null;function Os(t,e){let n=t.doc.clientID.toString(36),o=Be(t),s=new Set,i=new Map,r=l=>{if(typeof l!="string")return new Set;let f=i.get(l);if(!f){let d=$e(t.parts.get(l));f=d?.kind==="xml"?lt(t,l,d.root).unseenWinners:new Set,i.set(l,f)}return f};if(pe(t.doc,e.insertions,l=>{if(l.parent!==t.nodes||l.deleted||!(l.content instanceof ie.ContentType))return;let f=l.content.type,d=Te(f),c=d?o(d.group):void 0;!d||c===void 0||c===n||r(f.get(N.part)).has(d.group)||s.add(d.from)}),s.size===0)return e.deletions;let u=new Set;for(let l of s)Ps(t,l,u);return u.size===0?e.deletions:Dt(t.doc,e.deletions,l=>u.has(l.parent))}function Ns(t,e){let n=new Map;if(pe(t.doc,e.insertions,c=>{let g=c.parent;!(g instanceof ie.Text)||!c.countable||Ve(t,g.parent)&&n.set(g,(n.get(g)??!1)||c.deleted)}),![...n.values()].some(Boolean))return e;let o=new Map,s=new Set;if(pe(t.doc,e.deletions,c=>{let g=Ve(t,c.parent);if(!g||c.parentSub!==z.splitFrom||!(c.content instanceof ie.ContentAny))return;let a=c.content.getContent()[0];if(typeof a!="string")return;let h=new Set;Ps(t,a,h);let p=[...h].filter(x=>n.get(x)===!0);if(p.length===0)return;for(let x of p)s.add(x);let y=g.get(N.key);typeof y=="string"&&o.set(g,y)}),o.size===0)return e;let i=new Map;pe(t.doc,e.deletions,c=>{let g=c.parent,h=(g instanceof ie.Array?Ve(t,g.parent):null)?.get(N.key);if(typeof h!="string"||!(c.content instanceof ie.ContentAny))return;let p=i.get(h);p||i.set(h,p=[]);for(let y of c.content.getContent())typeof y=="string"&&p.push(y)});let r=new Set(o.values()),u=new Set,l=[...r];for(;l.length>0;){let c=l.pop(),g=t.nodes.get(c);if(!(u.has(g)||!(g instanceof ie.Map))){u.add(g);for(let a of i.get(c)??[])l.push(a)}}let f=c=>Ve(t,c.parent)??Ve(t,c.parent?.parent),d=c=>c.parent instanceof ie.Array&&Ve(t,c.parent.parent)!==null&&c.content instanceof ie.ContentAny&&c.content.getContent().some(g=>typeof g=="string"&&r.has(g));return{insertions:Dt(t.doc,e.insertions,c=>s.has(c.parent)),deletions:Dt(t.doc,e.deletions,c=>u.has(f(c))||d(c))}}import*as Ds from"yjs";import{CONTENT_TYPES_PART as $t,asciiFold as je,NS as ae,attr as we,children as Gt,materialize as fi,relationshipsOf as gt,relsPartName as Wt,specOf as ui}from"@pptx-editor.dev/core/store";var Tn=Symbol("absent");function Ls(t,e,n){let o=pi(n);for(let s of t){let i=s.target;if(!(i instanceof Ds.Map)||!e(i))continue;let r=o.get(i);r||o.set(i,r=new Map);for(let[u,l]of s.changes.keys){let f=i.get(u),d=r.get(u);if(d)d[3]=f;else{let c=[i,u,l.action==="add"?Tn:l.oldValue,f];n.push(c),r.set(u,c)}}}}var As=new WeakMap;function pi(t){let e=As.get(t);if(e)return e;e=new Map;for(let n of t){let o=e.get(n[0]);o||e.set(n[0],o=new Map),o.has(n[1])||o.set(n[1],n)}return As.set(t,e),e}var _s=t=>t._item?.deleted!==!0;function Fs(t){return t.filter(([e,n,o])=>o!==Tn&&_s(e)&&!e.has(n)).map(([e,n,o])=>[e,n,o])}function Cn(t){let e=(n,o)=>JSON.stringify(n)===JSON.stringify(o);return t.filter(([n,o,s,i])=>_s(n)&&i!==void 0&&s!==Tn&&e(n.get(o),s)&&!e(s,i)).map(([n,o,,s])=>[n,o,s])}function gi(t){let e=new Set,n=[t];for(;n.length>0;){let o=n.pop();if(!(o.type!=="element"||zs(o))){for(let s of o.attrs)s.ns===ae.r&&e.add(s.value);for(let s of o.children)n.push(s)}}return e}function Ts(t,e){let n={next:t.nextId},o=e.map(s=>fi(ui(s),t.root.kind,n));return{partName:t.partName,root:{...t.root,children:[...t.root.children,...o]},nextId:n.next}}var zs=t=>t.ns===ae.p&&t.local==="sldId";function hi(t,e){for(let n of t.parts.values()){if(n.kind!=="xml")continue;let o=n.xml.root;if(o.ns!==ae.p||o.local!=="presentation")continue;let s=o.children.find(m=>m.type==="element"&&m.ns===ae.p&&m.local==="sldIdLst");if(!s)return;let i=[],r=new Set;for(let m of s.children){if(m.type!=="element"||!zs(m))continue;let k=m.attrs.find(S=>S.ns===ae.r&&S.local==="id")?.value;k===void 0||!e.has(k)?r.add(m):i.push(we(m,"id")??"")}let u=[],l=m=>{for(let k of m.children)k.type==="element"&&(k.ns===ae.p14&&k.local==="section"?u.push(k):l(k))};l(o);let f=new Map(u.map((m,k)=>[m,k])),d=new Map;u.forEach((m,k)=>{let S=m.children.find(w=>w.type==="element"&&w.ns===ae.p14&&w.local==="sldIdLst");if(S)for(let w of Gt(S,{ns:ae.p14,local:"sldId"})){let A=we(w,"id")??"",R=d.get(A);R?R[R.length-1]!==k&&R.push(k):d.set(A,[k])}});let c=new Map,g=0;for(let m of i){let k=d.get(m);if(!k)continue;let S=k.find(w=>w>=g)??k[0];c.set(m,S),g=Math.max(g,S)}let a=new Map(i.map((m,k)=>[m,k])),h=r.size>0,p=(m,k)=>{let S=m.children.map(w=>{if(w.type!=="element"||w.ns!==ae.p14||w.local!=="sldIdLst")return w;let A=new Set,P=[...w.children.filter(b=>{if(b.type!=="element"||b.ns!==ae.p14||b.local!=="sldId")return!0;let I=we(b,"id")??"";return c.get(I)!==k||A.has(I)?!1:(A.add(I),!0)})].sort((b,I)=>{let C=b.type==="element"?a.get(we(b,"id")??"")??0:0,j=I.type==="element"?a.get(we(I,"id")??"")??0:0;return C-j});return P.length===w.children.length&&P.every((b,I)=>b===w.children[I])?w:(h=!0,{...w,children:P})});return S.every((w,A)=>w===m.children[A])?m:{...m,children:S}},y=m=>{let k=m.children.filter(w=>w.type!=="element"||!r.has(w)).map(w=>{if(w.type!=="element")return w;let A=f.get(w)??-1;return A>=0?p(w,A):y(w)});return k.length===m.children.length&&k.every((w,A)=>w===m.children[A])?m:{...m,children:k}},x=y(o);return h?{...n.xml,root:x}:void 0}}var mi=new Set(["hlinkClick","hlinkHover","hlinkMouseOver"]),An=t=>t.endsWith("/relationships/slide");function Cs(t,e){let n=!1,o=i=>{let r=!1,u=[];for(let l of i.children){if(l.type!=="element"){u.push(l);continue}let f=l.attrs.some(c=>c.ns===ae.r&&c.value===e);if(f&&l.ns===ae.a&&mi.has(l.local)){r=!0;continue}f&&(n=!0);let d=o(l);d!==l&&(r=!0),u.push(d)}return r?{...i,children:u}:i},s=o(t);return n?void 0:s}function yi(t,e){return{...t,root:{...t.root,children:t.root.children.filter(n=>n.type!=="element"||n.local!=="Relationship"||we(n,"Id")!==e)}}}var qe=(t,e)=>{let n=t.parts.get(e);return n?.kind==="xml"?n.xml:void 0};function Dn(t,e){let n=new Map,o=new Set;for(let c of e.parts.keys())o.add(je(c));let s=c=>e.parts.has(c)||o.has(je(c)),i=[],r=new Set,u=c=>{!c||r.has(c.partName)||(r.add(c.partName),i.push(c))},l=!1;for(let c of t.parts.keys())e.parts.has(c)||(l=!0);for(let[c,g]of e.parts){if(g.kind!=="xml")continue;let a=Wt(c);if(!l&&t.parts.get(c)===g&&t.parts.get(a)===e.parts.get(a))continue;let h=w=>{let A=Cs((n.get(c)??g.xml).root,w);if(!A)return!1;n.set(c,{...n.get(c)??g.xml,root:A});let R=n.get(a)??qe(e,a);return R&&n.set(a,yi(R,w)),!0};for(let w of gt(e,c))!w.external&&w.target&&!s(w.target)&&An(w.type)&&h(w.id);let p=gi((n.get(c)??g.xml).root);if(p.size===0)continue;for(let w of gt(e,c))!p.has(w.id)||w.external||!w.target||s(w.target)||An(w.type)||u(t.parts.get(w.target));let y=new Set(gt(e,c).map(w=>w.id)),x=qe(t,a);if(!x)continue;let m=Gt(x.root,{ns:ae.rel,local:"Relationship"}).filter(w=>{let A=we(w,"Id");return A!==void 0&&p.has(A)&&!y.has(A)});for(let w of gt(t,c)){let A=m.findIndex(P=>we(P,"Id")===w.id);if(A<0||w.external||!w.target||s(w.target)||!An(w.type))continue;let R=Cs((n.get(c)??g.xml).root,w.id);R&&(n.set(c,{...n.get(c)??g.xml,root:R}),m.splice(A,1))}if(m.length===0)continue;let k=n.get(a)??qe(e,a)??{partName:a,root:{...x.root,children:[]},nextId:x.nextId};n.set(a,Ts(k,m));let S=new Set(m.map(w=>we(w,"Id")));for(let w of gt(t,c))!S.has(w.id)||w.external||!w.target||s(w.target)||u(t.parts.get(w.target))}{let c=[...e.parts.values()].find(p=>p.kind==="xml"&&p.xml.root.ns===ae.p&&p.xml.root.local==="presentation"),g=c&&(n.get(Wt(c.partName))??qe(e,Wt(c.partName))),a=c&&Wt(c.partName),h=c&&(t.parts.get(c.partName)!==c||t.parts.get(a)!==e.parts.get(a)||n.has(a));if(g&&h&&a&&e.parts.has(a)){let p=new Set(Gt(g.root,{ns:ae.rel,local:"Relationship"}).map(x=>we(x,"Id")??"")),y=hi(e,p);y&&n.set(y.partName,y)}}let f=qe(e,$t),d=qe(t,$t);if(f&&d){let c=(m,k,S)=>{let w=new Map;for(let A of Gt(m,{ns:ae.ct,local:k})){let R=we(A,S);R!==void 0&&!w.has(je(R))&&w.set(je(R),A)}return w},g=c(f.root,"Override","PartName"),a=c(f.root,"Default","Extension"),h=c(d.root,"Override","PartName"),p=c(d.root,"Default","Extension"),y=new Set,x=new Set(e.parts.keys());for(let m of i)x.add(m.partName);for(let m of x){if(m===$t)continue;let k=je(m.slice(m.lastIndexOf(".")+1));if(g.has(je(m))||a.has(k))continue;let S=h.get(je(m))??p.get(k);S&&y.add(S)}y.size>0&&n.set($t,Ts(f,[...y]))}return[...[...n.values()].map(c=>({kind:"xml",partName:c.partName,xml:c})),...i]}var js=0;function Ln(t,...e){for(let n of[...t])try{n(...e)}catch(o){console.warn("[pptx-editor] collaboration listener failed",o)}}function wi(t){let{doc:e,documentId:n,identity:o,awareness:s}=t;if(typeof n!="string"||n.trim()===""||n.length>256)throw new Ke("invalid-document-id");let i=ps(o);if(i)throw new Ke(i);let r=$n(e),u=ki("initializing"),l=new Set,f=new Set,d=new Set,c=null,g=null,a={value:0},h=null,p=null,y=null,x=!1,m=!0,k=[{...o,isLocal:!0}],S=[],w=null,A=null,R=null,P=!1;js+=1;let b=`${e.clientID.toString(36)}-${js}`,I=(T,F,M,L=!1)=>{if(!u.set(T,F,M,L))return;let v=u.snapshot().reason;Ln(l,T,v?.code,v?.detail)},C=()=>m?I("ready"):I("disconnected","transport-disconnected"),j=T=>{s&&!x&&s.setLocalStateField(zt,ys(o,T))},_=()=>{if(!s)return;let T=ks(s);JSON.stringify(T)!==JSON.stringify(k)&&(k=T,Ln(f,k));let F=g?ws(s,e,g):[];JSON.stringify(F)!==JSON.stringify(S)&&(S=F,Ln(d,S))};j(void 0),s?.on("change",_),_();let E=(T,F,M,L=!0)=>{let v=F?T.redoStack:T.undoStack,$=v.length;F?T.undoing=!0:T.redoing=!0;try{e.transact(M,Jt)}finally{T.undoing=!1,T.redoing=!1}if(v.length!==$+1)return!1;let G=v[v.length-2];if(!L||!G)return!0;let oe=v.pop();return G.deletions=me.mergeDeleteSets([G.deletions,oe.deletions]),G.insertions=me.mergeDeleteSets([G.insertions,oe.insertions]),!0},O=(T,F,M)=>F.length>0&&E(T,!1,()=>{for(let[L,v,$]of F)L.set(v,$)},M),D=(T,F)=>{let M=F?T?.undoStack:T?.redoStack;if(!T||!M||M.length===0)return!1;P=!1;let L=p?.package(),v=M[M.length-1];if(F)qo(r,v,X=>e.transact(X,Ze)),v.deletions=Os(r,v);else{let X=Ns(r,v);v.insertions=X.insertions,v.deletions=X.deletions}let $=[...M];y=null,F?T.undo():T.redo(),!F&&y===v&&Qo(r,v,X=>e.transact(X,Ze));let G=y,oe=new Set(M),Xt=$.reverse().filter(X=>!oe.has(X)&&X!==G),Je=X=>X.meta.get("attrs")??[],Qe=!1,Me=!1,Re=null;if(F&&G&&G!==v)y=null,T.redo(),Re=y,Me=!0;else if(!F&&G===v)Qe=O(T,Cn(Je(v)),!0);else if(!F){G&&(y=null,T.undo(),Re=y);for(let X of Xt.slice(1).reverse())T.redoStack.push(X);Qe=O(T,Cn(Je(v)),!1)}if(Re){let X=Re;e.transact(()=>vn(r,X.deletions),Ze)}let W=G&&!Me&&(F||G===v)?G:null;if(W&&g){let X=g,te=W,Q=(ce,Pe)=>X.idOf(ce,Pe)!==void 0,de=new Set;E(T,F,()=>{let ce=vn(r,te.deletions);de=ce.roots,F&&Zo(r,te,Q),Is(r,te.deletions,Q),Nn(r,ce.texts,Q)}),X.forgetDeleted(de)}let V=p?.package(),se=F&&G&&!Me?Fs(Je(G)):[],Z=L&&V&&!Me?Dn(L,V):[];if((se.length>0||Z.length>0)&&V&&g){let X=g;e.transact(()=>{for(let[Q,de,ce]of se)Q.set(de,ce);if(Z.length===0)return;let te=new Map(V.parts);for(let Q of Z)te.set(Q.partName,Q);X.writeChange(V,{parts:te},Z.map(Q=>Q.partName))},qt)}return!P&&(F?G!==null&&!Me:G===v||Qe)};return{documentId:n,sessionId:b,identity:o,get attached(){return c!==null},status:()=>u.status(),statusSnapshot:()=>u.snapshot(),subscribeStatus(T){return l.add(T),()=>l.delete(T)},setConnected(T){if(x||T===m)return;m=T;let F=u.snapshot();(F.status==="ready"||F.status==="disconnected")&&C()},participants:()=>k,subscribeParticipants(T){return f.add(T),()=>f.delete(T)},remoteSelections:()=>S,subscribeRemoteSelections(T){return d.add(T),()=>d.delete(T)},setLocalSelection(T){let F=T&&g?ms(T,g):void 0;w=T&&F?{selection:T,encoded:F}:null,j(F)},remoteSelectionMove:()=>A,historySelection:()=>R&&g?jt(R,e,g):null,canUndo:()=>h?h.undoStack.length>0:!1,canRedo:()=>h?h.redoStack.length>0:!1,undo:()=>D(h,!0),redo:()=>D(h,!1),attach(T){if(x)return()=>{};c?.(),I("initializing");let F=r.meta.get("schema");if(F!==void 0&&F!==Vt)return I("error","schema-version-mismatch",`room schema ${String(F)}`),()=>{};let M=new Ft(r,a);p=T,g=M;let L=(W,V,se=!1)=>{let Z=T.package(),X=M.rebuild(W,Z,V);if(!X.ok)return P=!0,I("error","remote-apply-failed",X.reason,!0);let te=w?jt(w.encoded,e,M):null;if(A=w&&te&&JSON.stringify(te)!==JSON.stringify(w.selection)?{from:w.selection,to:te}:null,A&&w&&(w={selection:A.to,encoded:w.encoded}),X.parts.length>0||X.removed.length>0){let de=T.applyRemoteParts(X.parts,X.removed,"collaboration");if(A=null,!de.ok){P=!0;let ce=de.rejection.code;return ce==="unsafe-part-name"?I("error","unsafe-part-name",ce):I("error","remote-apply-failed",ce,!0)}}A=null,se&&Xt(Z,T.package());let Q=u.snapshot();Q.status==="error"&&Q.recovering&&C(),_()};M.seeded?L(M.allParts(T.package()),!0):e.transact(()=>{r.meta.set("schema",Vt),r.meta.set("documentId",n),M.seed(T.package())},en);let v=new me.UndoManager([r.parts,r.binaries,r.nodes],{trackedOrigins:new Set([kt,Jt]),captureTimeout:Number.POSITIVE_INFINITY,deleteFilter:Ys(r.nodes)}),$=W=>{let V=W.parent;return V instanceof me.Map&&V.get(N.attrs)===W},G=W=>{let V=v.currStackItem;if((v.undoing||v.redoing)&&V){W.stackItem.meta.set("attrs",V.meta.get("attrs")??[]);return}let se=W.stackItem.meta.get("attrs")??[],Z=new Set;for(let X of W.changedParentTypes?.values()??[])for(let te of X)Z.add(te);Ls(Z,$,se),W.stackItem.meta.set("attrs",se)};v.on("stack-item-added",W=>{w&&W.stackItem.meta.set("selection",w.encoded),G(W)}),v.on("stack-item-updated",G),v.on("stack-item-popped",W=>{R=W.stackItem.meta.get("selection")??null,y=W.stackItem}),h=v;let oe=T.subscribeLocal(W=>{W.merged||v.stopCapturing(),M.hasHiddenListings(W.parts)&&e.transact(()=>M.dropHiddenListings(W.parts,W.before,W.after),Zt),e.transact(()=>M.writeChange(W.before,W.after,W.parts),kt);let V=M.showingUnlisted(W.parts);V.length>0&&L(V,!1),_()}),Xt=(W,V)=>{let se=Dn(W,V);if(se.length===0)return;let Z=new Map(V.parts);for(let X of se)Z.set(X.partName,X);e.transact(()=>M.writeChange(V,{parts:Z},se.map(X=>X.partName)),qt)},Je=(W,V)=>{let se=M.deletedText,Z=se.size>0?_o(r,W):new Set;if(V.size===0&&Z.size===0)return;let X={keyOf:M.keyOf.bind(M),package:T.package()},te=[];e.transact(()=>{for(let[Q,de]of V)bs(r,Q,de,se,X,(ce,Pe,ht)=>te.push([ce,Pe,ht]));Ms(r,Z,se)},Qt);for(let[Q,de,ce]of te)for(let Pe of[...v.undoStack,...v.redoStack]){if(!me.isDeleted(Pe.insertions,Q))continue;let ht=me.createDeleteSet();ht.clients.set(de.client,[{clock:de.clock,len:ce}]),Pe.insertions=me.mergeDeleteSets([Pe.insertions,ht])}},Qe=e.getMap(Ie),Me=W=>{let V=W.origin;if(V===kt||V===en||V===Ze||V===Zt)return;let se=M.touchedParts(W);if(se.size>0&&L(se,!1,!W.local),W.local)return;let Z=M.newCopies(W);Je(W,Z);let X=W.changed.get(Qe),te=X?Pn(r,X):new Set;if(Z.size>0&&r.doc.getMap(Ie).size>0)for(let Q of On(r,new Set(Z.keys())))te.add(Q);if(te.size>0){let Q=(de,ce)=>M.idOf(de,ce)!==void 0;e.transact(()=>Nn(r,te,Q),Qt)}};e.on("afterTransaction",Me),u.status()==="initializing"&&C(),_();let Re=()=>{oe(),e.off("afterTransaction",Me),v.destroy(),h===v&&(h=null),g===M&&(g=null),p===T&&(p=null),w=null,R=null,j(void 0),_(),c===Re&&(c=null)};return c=Re,Re},destroy(){x||(c?.(),s?.off("change",_),s?.setLocalStateField(zt,null),x=!0,I("destroyed","collaboration-session-destroyed"),l.clear(),f.clear(),d.clear())}}}export{Ke as CollaborationSchemaError,Js as collaborationModule,wi as createYjsCollaborationSession,Ht as legacyComments,qs as reviewModule};
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};