@pptx-editor.dev/pro 0.6.0 → 0.7.0-canary.20261120032841.sha-d450255
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 +2 -2
- package/package.json +4 -4
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
|
|
7
|
-
Collaboration upgrade required. Save local changes and use a compatible app version.`:r);this.code=n;this.detail=o;this.name="CollaborationSchemaError"}code;detail};import"yjs";var wn=8,Sn="pptx-meta-v1",Cc="pptx-parts-v1",Tc="pptx-binaries-v1",Nc="pptx-nodes-v1",E=Object.freeze({part:"p",key:"k",shell:"s",attrs:"a",children:"c",text:"x"}),xn="",lr=2**40,bn=Object.freeze({kind:"pptx-local"}),no=Object.freeze({kind:"pptx-undo-repair"}),oo=Object.freeze({kind:"pptx-redo-repair"}),pt=Object.freeze({kind:"pptx-text-repair"}),ro=Object.freeze({kind:"pptx-tidy"}),Ot=Object.freeze({kind:"pptx-undone-listing"}),so=Object.freeze({kind:"pptx-seed"}),Xt=Object.freeze({maxBinaryBytes:256*1024*1024,maxReadDepth:300,maxCopiesPerGroup:256});function fr(e){return{doc:e,meta:e.getMap(Sn),parts:e.getMap(Cc),binaries:e.getMap(Tc),nodes:e.getMap(Nc)}}function et(e){if(typeof e!="object"||e===null)return null;let t=e;return t.kind==="binary"?{kind:"binary"}:t.kind==="xml"&&typeof t.root=="string"?{kind:"xml",root:t.root}:null}var io=Object.freeze({protocolVersion:1,sharedSchemaVersion:wn,repairVersion:1,canonicalModelVersion:1}),Vt=["protocolVersion","sharedSchemaVersion","repairVersion","canonicalModelVersion"],dr=e=>`pptx-collaboration:${e.join(".")}`,ur=dr(Vt.map(e=>io[e]));function _c(e){if(e!==ur)throw new ve("schema-version-mismatch","incompatible collaboration format")}function pr(e){e.set("schema",wn);for(let t of Vt)e.set(t,io[t])}function co(e){return e.get("schema")===wn&&Vt.every(t=>e.get(t)===io[t])}function Lc(e){if(!e.share.has(Sn))throw new ve("not-initialized");let t;try{t=e.getMap(Sn)}catch{throw new ve("schema-version-mismatch","room metadata is not a map")}let n=t.get("schema");if(n===void 0)throw new ve(t.size===0?"not-initialized":"schema-version-mismatch");if(typeof n!="number"||!Number.isSafeInteger(n)||n<1)throw new ve("schema-version-mismatch","invalid room schema");if(Vt.every(r=>!t.has(r)))return`pptx-collaboration-${n}`;let o=Vt.map(r=>{let i=t.get(r);if(typeof i!="number"||!Number.isSafeInteger(i)||i<1)throw new ve("schema-version-mismatch","invalid collaboration version metadata");return i});if(o[1]!==n)throw new ve("schema-version-mismatch","conflicting room schema");return dr(o)}import*as Pt from"yjs";import*as Be from"yjs";function Oe(e){if(!(e instanceof Be.AbstractType))return null;let t=e._item;return t instanceof Be.Item?t:null}function ae(e,t,n){for(let[o,r]of t.clients){let i=e.store.clients.get(o);if(!(!i||i.length===0))for(let{clock:s,len:a}of r){let c=i[i.length-1];if(!(s>=c.id.clock+c.length))for(let f=Be.findIndexSS(i,s);f<i.length;f+=1){let l=i[f];if(l.id.clock>=s+a)break;l instanceof Be.Item&&n(l)}}}}function Mn(e,t,n){let o=Be.createDeleteSet();for(let[r,i]of t.clients){let s=e.store.clients.get(r),a=[];for(let{clock:c,len:f}of i){if(!s||s.length===0){a.push({clock:c,len:f});continue}let l=c+f,d=c,g=s[s.length-1];if(c<g.id.clock+g.length)for(let u=Be.findIndexSS(s,c);u<s.length;u+=1){let h=s[u];if(h.id.clock>=l)break;if(!(h instanceof Be.Item)||!n(h))continue;let p=Math.max(c,h.id.clock);p>d&&a.push({clock:d,len:p-d}),d=Math.min(l,h.id.clock+h.length)}l>d&&a.push({clock:d,len:l-d})}a.length>0&&o.clients.set(r,a)}return o}function*Gt(e){for(let t=e._start;t;t=t.right)t.deleted||(yield t)}function*gr(e){for(let t of e._map.values())t.deleted||(yield t)}function Yn(e,t){let n=0;for(let o=e._start;o!==null;o=o.right)if(!(o.deleted||!o.countable)){if(o.id.client===t.client&&t.clock>=o.id.clock&&t.clock<o.id.clock+o.length)return n+(t.clock-o.id.clock);n+=o.length}return-1}function _e(e,t){let n=[],o=0;for(let r=e._start;r!==null&&n.length<t.size;r=r.right)if(!(r.deleted||!r.countable)){for(let i=0;i<r.length;i+=1)t.has(`${r.id.client}:${r.id.clock+i}`)&&n.push(o+i);o+=r.length}for(let r=n.length-1;r>=0;){let i=r;for(;i>0&&n[i-1]===n[i]-1;)i-=1;e.delete(n[i],n[r]-n[i]+1),r=i-1}}var hr=e=>e.left===null;var yr="listed-children",mr=65536;function ao(e){let t=e.meta?.get(yr);return t instanceof Map?t:new Map}function kr(e,t){let n=new Map(ao(t)),o=mr;for(let r of n.values())o-=r.keys.size+r.siblings.length;o<=0||(ae(e.doc,t.insertions,r=>{if(--o<0||r.deleted||!(r.parent instanceof Pt.Array)||!(r.content instanceof Pt.ContentAny))return;let i=r.parent,s=i.parent;if(!(s instanceof Pt.Map)||s.parent!==e.nodes||s.get(E.children)!==i)return;let a=new Set(n.get(i)?.keys);for(let f of r.content.getContent()){if(--o<0)return;typeof f=="string"&&a.add(f)}let c=i.slice(0,mr).filter(f=>typeof f=="string");o-=c.length,o>=0&&n.set(i,{keys:a,siblings:c})}),t.meta.set(yr,n))}import*as lt from"yjs";import*as ne from"yjs";import"yjs";var Sr="pptx-case-base-v1",lo="cc.",fo=1<<20,Rn=new WeakMap,wr=new WeakSet;function xr(e){let t=Rn.get(e);if(t)return t;wr.has(e)||(wr.add(e),e.observe(()=>Rn.delete(e)));let n=new Map;if(e.size>fo)return n;for(let[o,r]of e){if(!o.startsWith(lo))continue;let i=/^cc\.(\d{1,16}:\d{1,16}):(\d{1,16})$/.exec(o);if(!i||!Array.isArray(r)||r.length!==2)continue;let[s,a]=r,c=Number(i[2]);if(!Number.isSafeInteger(s)||s<0||!Number.isSafeInteger(c)||!Number.isInteger(a)||a<0||a>65535)continue;let f=i[1],l=n.get(f);(!l||s>l.order||s===l.order&&c>l.author)&&n.set(f,{order:s,author:c,value:a})}return Rn.set(e,n),n}function ct(e){let t=e.toString(),n=e.doc;if(!n)return t;let o=n.getMap(Sr);if(o.size===0)return t;let r=Ce(e,0,e.length),i=new Map;return r.map((s,a)=>{let c=U(n,s,i),f=z(c.client,c.clock),l=o.get(f);if(typeof l!="number"||!Number.isInteger(l)||l<0||l>65535)return t[a]??"";let d=Z(n,c),g=d&&xe(d);return String.fromCharCode((g&&xr(g).get(f)?.value)??l)}).join("")}function br(e,t,n){let o=e.doc;if(!o||t.length!==n.length||t===n)return!1;for(let c=0;c<t.length;){let f=String.fromCodePoint(t.codePointAt(c)),l=String.fromCodePoint(n.codePointAt(c));if(f.length!==l.length||f!==l&&f.toUpperCase()!==l&&f.toLowerCase()!==l)return!1;c+=f.length}let r=Ce(e,0,e.length),i=o.getMap(Sr),s=new Map,a=[];for(let c=0;c<t.length;c++){if(t[c]===n[c])continue;let f=U(o,r[c]),l=Z(o,f),d=l&&xe(l);if(!d||d.size>=fo)return!1;let g=z(f.client,f.clock),u=(xr(d).get(g)?.order??0)+1;if(!Number.isSafeInteger(u))return!1;let h=`${lo}${g}:${o.clientID}`;if(!d.has(h)){let p=s.get(d)??new Set;if(p.add(h),s.set(d,p),d.size+p.size>fo)return!1}a.push({record:d,key:g,order:u,index:c})}for(let{record:c,key:f,order:l,index:d}of a)i.has(f)||i.set(f,t.charCodeAt(d)),c.set(`${lo}${f}:${o.clientID}`,[l,n.charCodeAt(d)]),Rn.delete(c);return!0}var uo="rv.",oe=Object.freeze({copyOf:"ci",newParagraph:"cp",seen:"cs",followed:"cf.",removedRun:"rr."}),Xe="pptx-copies-v1",Mr=1<<20,vr=4096,Fc=1024,Je=32,Or="http://schemas.openxmlformats.org/drawingml/2006/main",zc="http://schemas.openxmlformats.org/presentationml/2006/main",At=e=>e.local==="txBody"&&(e.ns===Or||e.ns===zc),z=(e,t)=>`${e}:${t}`,at=e=>Number.isSafeInteger(e)&&e>=0,Yr=new WeakMap;function ie(e){if(!(e instanceof ne.Map))return null;let t=e.get(oe.copyOf),n=Yr.get(e);if(n&&n.value===t)return n.copy;let o=Pr(t,e.get(oe.newParagraph)===!0);return Yr.set(e,{value:t,copy:o}),o}function Pr(e,t){if(!Array.isArray(e)||e.length<5||(e.length-2)%3!==0||e.length>2+3*Mr)return null;let[n,o]=e;if(!at(n)||!at(o))return null;let r=[],i=0;for(let a=2;a<e.length;a+=3){let c=e[a],f=e[a+1],l=e[a+2];if(!at(c)||!at(f)||!at(l)||l===0||(r.push(i),i+=l,i>Mr))return null}let s=e;return{client:n,clock:o,length:i,newParagraph:t,source(a){let c=0,f=r.length-1;for(;c<f;){let d=c+f+1>>1;r[d]<=a?c=d:f=d-1}let l=2+3*c;return ne.createID(s[l],s[l+1]+(a-r[c]))}}}var Rr=new WeakMap;function Ht(e){let t=[];if(!(e instanceof ne.Map))return t;let n=[];for(let o of e.keys())o.startsWith(oe.followed)&&n.push(o);for(let o of n.sort().slice(0,Fc)){let r=e.get(o);if(!Array.isArray(r))continue;let i=Rr.get(r);i===void 0&&Rr.set(r,i=Pr(r,!1)),i&&t.push(i)}return t}function Ar(e,t){let n=r=>r!==null&&r.client===t.client&&t.clock>=r.clock&&t.clock<r.clock+r.length,o=ie(e);return n(o)?o:Ht(e).find(n)??null}function Dr(e,t,n,o){e.set(`${oe.followed}${z(t,n)}`,[t,n,..._r(o)])}function Cr(e,t){let n=new Set,o=e.nodes;for(let[r,i]of t.changed){if(r===o){for(let a of i)a!==null&&Ht(o.get(a)).length>0&&n.add(a);continue}if(!(r instanceof ne.Map)||r.parent!==o)continue;let s=r.get(E.key);if(typeof s=="string")for(let a of i)a?.startsWith(oe.followed)&&n.add(s)}return n}var Le="pptx-restored-v1",Tr="pptx-delete-clock-v1",Pe="pptx-restored-steps-v1",Dt="pptx-restored-starts-v1";function Ve(e,t){let n=e.getMap(Dt).get(z(t.client,t.clock));return!Array.isArray(n)||n.length!==5||![n[0],n[1],n[3]].every(o=>Number.isSafeInteger(o)&&o>=0)||typeof n[2]!="boolean"||typeof n[4]!="string"?null:{start:ne.createID(n[0],n[1]),enter:n[2],client:n[3],key:n[4]}}function Nr(e,t){return Ve(e,t)?.start??null}var Ge=65536,Kc=/^(\d{1,16}):(\d{1,16})$/,In=new WeakMap,Ir=new WeakSet;function jc(e){let t=In.get(e);if(t)return t;Ir.has(e)||(Ir.add(e),e.observe(()=>In.delete(e))),t=new Map;for(let[n,o]of e.entries()){let r=Kc.exec(n);if(!r||!Array.isArray(o)||o.length!==3||!o.every(at))continue;let[i,s,a]=o;if(a===0||a>Ge)continue;let c=Number(r[1]),f=Number(r[2]);if(!Number.isSafeInteger(c)||!Number.isSafeInteger(f))continue;let l=t.get(c),d=[f,i,s,a];l?l.push(d):t.set(c,[d])}for(let n of t.values())n.sort((o,r)=>o[0]-r[0]);return In.set(e,t),t}function Me(e,t){let n=e.getMap(Le);if(n.size===0)return null;let o=jc(n).get(t.client);if(!o)return null;let r=0,i=o.length-1;for(;r<i;){let a=r+i+1>>1;o[a][0]<=t.clock?r=a:i=a-1}let s=o[r];return!s||t.clock<s[0]||t.clock>=s[0]+s[3]?null:ne.createID(s[1],s[2]+(t.clock-s[0]))}function qt(e,t){if(t.length===0)return;let n=e.getMap(Le);for(let o=0;o+3<t.length;o+=4)n.set(z(e.clientID,t[o]),[t[o+1],t[o+2],t[o+3]]);In.delete(n)}function _r(e){let t=[];for(let n of e){let o=t.length;o>0&&t[o-3]===n.client&&t[o-2]+t[o-1]===n.clock?t[o-1]+=1:t.push(n.client,n.clock,1)}return t}function Wc(e,t){let n=new Set;for(let r=t._start;r!==null;r=r.right)if(n.add(r.id.client),n.size>vr)return null;let o=[];for(let r of[...n].sort((i,s)=>i-s))o.push(r,ne.getState(e.store,r));return o}var Er=new WeakMap;function Lr(e){if(!(e instanceof ne.Map))return null;let t=e.get(oe.seen),n=Er.get(e);(!n||n.value!==t)&&(n={value:t,seen:$c(t)},Er.set(e,n));let o=n.seen;return o?r=>r.clock<(o.get(r.client)??0):null}function $c(e){if(!Array.isArray(e)||e.length%2!==0||e.length>2*vr)return null;let t=new Map;for(let n=0;n<e.length;n+=2){let o=e[n],r=e[n+1];if(!at(o)||!at(r)||t.has(o))return null;t.set(o,r)}return t}function Ce(e,t,n){let o=[],r=0;for(let i=e._start;i!==null&&o.length<n;i=i.right)if(!(i.deleted||!i.countable))for(let s=0;s<i.length&&o.length<n;s+=1,r+=1)r>=t&&o.push(ne.createID(i.id.client,i.id.clock+s));return o}function Z(e,t){if(ne.getState(e.store,t.client)<=t.clock)return null;let n=ne.getItem(e.store,t);return n instanceof ne.Item?n:null}function xe(e){let t=e.parent,n=t instanceof ne.Text?t.parent:null;return n instanceof ne.Map?n:null}function Jt(e,t){let n=Z(e,t);return!n||n.deleted}function U(e,t,n,o=!0){let r=z(t.client,t.clock),i=n?.get(r);if(i)return i;let s=t;for(let a=0;a<Je;a+=1){let c=Z(e,s),f=c?Ar(xe(c),s):null;if(f){s=f.source(s.clock-f.clock);continue}let l=o?Me(e,s):null;if(!l)break;s=l}return n?.set(r,s),s}function Ue(e,t,n=new Map){let o=z(t.client,t.clock),r=n.get(o);if(r)return r;let i=t;for(let s=0;s<Je;s+=1){let a=Z(e,i),c=a?Ar(xe(a),i):null;if(c){i=c.source(i.clock-c.clock);continue}let f=e.getMap(Pe).get(z(i.client,i.clock));if(!Array.isArray(f)||f.length!==3&&f.length!==4||f[2]!==!0||!Number.isSafeInteger(f[0])||f[0]<0||!Number.isSafeInteger(f[1])||f[1]<0)break;i=ne.createID(f[0],f[1])}return n.set(o,i),i}var gt=e=>e?.type==="element",En=e=>e.children.filter(gt),ue=(e,t)=>e.ns===Or&&e.local===t;function Fr(e){return En(e).find(n=>ue(n,"t"))?.children.find(n=>n.type==="text")}var Ut=e=>{let t=Fr(e);return t?.type==="text"?t.value:""};function zr(e,t,n,o,r,i){let s=new Set;if(o.size===0||i.size===0)return s;let a=e.doc.getMap(Xe),c=d=>{let g=Fr(d);return g?r.get(g.id):void 0},f=(d,g,u)=>{let h=En(d);h.forEach((p,k)=>{if(!ue(p,"r"))return;let x=o.get(p.id);if(!gt(x)||x===p)return;let y=Ut(x),S=Ut(p);if(y.length<=S.length||!y.startsWith(S))return;let w=c(p),m=w===void 0?void 0:i.get(w),b=y.length-S.length;if(!m||m.deleted.length!==b)return;let Y=[],M=0,I=(L,K,D)=>{for(let O=K;O<L.length&&M<b;O+=1){let j=L[O];if(!(!o.has(j.id)&&ue(j,"br"))&&!ue(j,"pPr")){if(ue(j,"endParaRPr"))return!0;if(!ue(j,"r")||o.has(j.id))return!1;Y.push({run:j,newParagraph:D}),M+=Ut(j).length}}return!0},v=I(h,k+1,!1),R=g[u+1],F=h.slice(k+1).every(L=>o.has(L.id)||ue(L,"endParaRPr"));M<b&&v&&F&&R&&ue(R,"p")&&!o.has(R.id)&&I(En(R),0,!0);let A=Y.length>0&&Y.every(L=>L.newParagraph),T=Y.map(L=>Ut(L.run)).join("");if(M>b||M<b&&!(A&&y.endsWith(T)))return;let P=w===void 0?void 0:e.nodes.get(w),N=P instanceof ne.Map?P.get(E.text):void 0,W=N instanceof ne.Text?Wc(e.doc,N):null,C=b-M;for(let L of Y){let K=c(L.run),D=Ut(L.run).length,O=K===void 0?void 0:i.get(K),j=K===void 0?void 0:e.nodes.get(K),B=m.deleted.slice(C,C+D);if(C+=D,!(D===0||!O?.created||O.inserted?.length!==D)&&!(!(j instanceof ne.Map)||K===void 0)){j.set(oe.copyOf,[O.inserted.client,O.inserted.clock,..._r(B)]),L.newParagraph&&j.set(oe.newParagraph,!0),W&&j.set(oe.seen,W),a.set(K,t);for(let X of B)s.add(z(X.client,X.clock))}}})},l=d=>{if(o.get(d.id)===d)return;let g=En(d);g.forEach((u,h)=>{ue(u,"p")&>(o.get(u.id))&&f(u,g,h)});for(let u of g)l(u)};return l(n),s}function Kr(e,t,n,o){let r=[];if(n.size===0)return r;let i=new Set,s=[],a=c=>{let f=n.get(c.id);if(f!==c){for(let l of c.children)i.add(l.id);if(gt(f)){let l=new Set(c.children.map(g=>g.id)),d="";for(let g of f.children)!l.has(g.id)&>(g)&&(ue(g,"r")||ue(g,"p")||ue(g,"tr")||ue(g,"tc"))&&s.push({node:g,from:c,prev:d}),d=o.get(g.id)??d}for(let l of c.children)gt(l)&&a(l)}};a(t);for(let{node:c,from:f,prev:l}of s){if(i.has(c.id))continue;let d=o.get(c.id),g=o.get(f.id),u=g===void 0?void 0:e.nodes.get(g);if((ue(c,"r")&&ue(f,"p")||ue(c,"p")&&At(f)||ue(c,"tr")&&ue(f,"tbl")||ue(c,"tc")&&ue(f,"tr"))&&d!==void 0&&u instanceof ne.Map&&u.set(`${oe.removedRun}${d}`,l),d!==void 0&&(ue(c,"tr")||ue(c,"tc"))){let k=e.nodes.get(d);k instanceof ne.Map&&k.set(`${uo}${e.doc.clientID}`,ne.encodeStateVector(e.doc))}let p=[c];for(;p.length>0;){let k=p.pop();if(k!==c&&i.has(k.id))continue;if(gt(k)){for(let w of k.children)p.push(w);continue}let x=o.get(k.id),y=x===void 0?void 0:e.nodes.get(x),S=y instanceof ne.Map?y.get(E.text):void 0;if(!(!(S instanceof ne.Text)||k.type!=="text"||k.value.length===0)&&ct(S)===k.value){for(let w of Ce(S,0,S.length))r.push(w);S.delete(0,S.length)}}}return r}function jr(e,t,n=!0){let o=new Map,r=t.changed.get(e.nodes);for(let a of n?t.changed.keys():[]){if(!(a instanceof lt.Text)||!(a.parent instanceof lt.Map))continue;let c=a.parent,f=c.get(E.key),l=c.get(E.part);if(typeof f!="string"||typeof l!="string"||!ie(c))continue;let d=o.get(l)??[];d.includes(f)||d.push(f),o.set(l,d)}let i=e.doc.getMap(Xe),s=new Set(r??[]);for(let[a,c]of t.changed){if(!(a instanceof lt.Map)||a.parent!==e.nodes||!ie(a)||!c.has(oe.copyOf)&&!c.has(oe.newParagraph))continue;let f=a.get(E.key);typeof f=="string"&&s.add(f)}for(let a of t.changed.get(i)??[])typeof a=="string"&&s.add(a);for(let a of s){if(a===null)continue;let c=i.get(a),f=e.nodes.get(a),l=ie(f);if(typeof c!="string"||!l||l.client===e.doc.clientID||f.get(E.part)!==c)continue;let d=o.get(c);d?d.push(a):o.set(c,[a])}return o}function Wr(e,t){let n=1048576,o=new Set,r=i=>{let s=i;for(let a=0;a<Je;a+=1){if(--n<0)return!0;let c=`${s.client}:${s.clock}`;if(o.has(c))return!0;let f=Z(e.doc,s);if(!f)return!1;o.add(c);let l=ie(xe(f)),d=l?s.clock-l.clock:-1;if(l&&s.client===l.client&&d>=0&&d<l.length){s=l.source(d);continue}let g=Me(e.doc,s);if(!g)return!0;s=g}return!0};for(let[i,s]of e.doc.getMap(Xe)){if(--n<0)return!0;if(s!==t)continue;let a=e.nodes.get(i),c=ie(a);if(!c||!(a instanceof lt.Map))continue;let f=Z(e.doc,lt.createID(c.client,c.clock));if(!(!f||f.parent!==a.get(E.text))){for(let l=0;l<c.length;l+=1)if(!r(c.source(l)))return!1}}return!0}import{createCollaborationStatusTracker as ul}from"@pptx-editor.dev/core/editor";import*as te from"yjs";import"yjs";function $r(e,t,n,o){let r=U(e,t),i=1<<20;for(let[s,a]of n){if(--i<0)return null;let c=o(s);if(!c)continue;if((i-=c.length)<0)return null;let f=Ce(c,0,c.length);for(let l=0;l<f.length;l++){let d=U(e,f[l]);if(d.client===r.client&&d.clock===r.clock)return{node:a,offset:l,text:c}}}return null}import*as Fe from"yjs";import*as Ct from"yjs";var Br="http://schemas.openxmlformats.org/drawingml/2006/main",Qt=1<<18,tt=(e,t)=>!("text"in e)&&e.ns===Br&&e.local===t;function vn(e,t,n,o,r,i,s=o){if(n.length===0)return t;let a=new Map,c=new Map,f=Qt,l=(m,b=0)=>{if(--f<0||b>64){f=-1;return}if(c.set(m.key,b),a.set(m.key,m),!("text"in m))for(let Y of m.children??[])l(Y,b+1)};if(l(t),f<0||n.length>Qt)return t;let d=n.filter(m=>!a.has(m.key)&&!a.has(m.parent));if(d.length===0)return t;let g=new Map,u=e.nodes.get(t.key),h=u instanceof Ct.Map?u.get(E.part):void 0,p=0;for(let[m,b]of e.nodes){if((p+=1)>Qt)return t;let Y=b instanceof Ct.Map&&b.get(E.part)===h?b.get(E.children):void 0;if(Y instanceof Ct.Array)for(let M of Y.toArray()){if((p+=1)>Qt)return t;if(typeof M!="string")continue;let I=g.get(M)??[];I.push(m),g.set(M,I)}}let k=m=>{let b=[m],Y=new Set;for(let M=0;M<64&&b.length>0;M+=1){let I=[];for(let v of b.sort()){if(Y.has(v))continue;if(Y.add(v),Y.size>Qt)return;let R=a.get(v);if(R&&tt(R,"tbl"))return R;I.push(...g.get(v)??[])}b=I}},x=new Map,y=new Map,S=new Set(a.keys());for(let m of d.sort((b,Y)=>b.key<Y.key?-1:b.key>Y.key?1:0)){let b=m.table?a.get(m.table):void 0,Y=b&&tt(b,"tbl")?b:k(m.parent);if(!Y)continue;let M=m.row?a.get(m.row):void 0,v=(M&&tt(M,"tr")?[M]:Y.children??[]).filter(C=>tt(C,"tr")).flatMap(C=>C.children??[]).filter(C=>tt(C,"tc")),R=v.flatMap(C=>[...C.children??[],...y.has(C.key)?[y.get(C.key)]:[]]).find(C=>tt(C,"txBody")),F;if(!R){if(F=v[0],!F||S.has(m.parent))continue;let C=s(m.parent,new Set(S),(c.get(F.key)??64)+1);if(!C||!tt(C,"txBody"))continue;R={...C,children:(C.children??[]).filter(L=>!tt(L,"p"))},c.set(R.key,(c.get(F.key)??64)+1)}let A=e.nodes.get(m.key),T=A instanceof Ct.Map?A.get(E.shell):void 0;if(T?.ns!==Br||T.local!=="p")continue;let P=o(m.key,S,(c.get(R.key)??64)+1);if(!P||!tt(P,"p"))continue;let N=C=>"text"in C?C.text.length>0:(C.children??[]).some(N);if(!N(P))continue;F&&(y.set(F.key,R),i.add(R.key),r.set(R.key,F.key),S.add(R.key));let W=x.get(R.key)??[];W.push(P),x.set(R.key,W),i.add(m.key),r.set(m.key,R.key)}if(x.size===0)return t;let w=m=>({...m,children:[...y.has(m.key)?[w(y.get(m.key))]:[],...(m.children??[]).map(b=>"text"in b?b:w(b)),...x.get(m.key)??[]]});return w(t)}var Xr="http://schemas.openxmlformats.org/drawingml/2006/main",Vr=65536;function Gr(e,t,n,o,r){let i=Vr,s=new Map,a=[],c=w=>e.nodes.get(w),f=w=>{let m=c(w),b=m instanceof Fe.Map?m.get(E.shell):void 0;return b?.ns===Xr&&typeof b.local=="string"?b.local:void 0},l=w=>{let m=c(w),b=m instanceof Fe.Map?m.get(E.children):void 0;return!(b instanceof Fe.Array)||(i-=b.length)<0?[]:b.toArray().filter(Y=>typeof Y=="string")},d=(w,m)=>{let b=c(w);if(!(b instanceof Fe.Map))return[];let Y=[];for(let[M,I]of b){if(--i<0)return[];if(!M.startsWith(oe.removedRun)||typeof I!="string")continue;let v=M.slice(oe.removedRun.length);f(v)===m&&Y.push(v)}return Y.sort()},g=w=>{let m=c(w),b=[];if(!(m instanceof Fe.Map))return b;for(let[Y,M]of m){if(--i<0)return[];if(Y.startsWith(uo)){if(!(M instanceof Uint8Array)||(i-=M.length)<0)return i=-1,[];try{b.push(Fe.decodeStateVector(M))}catch{return i=-1,[]}}}return b},u=(w,m,b,Y)=>{let M=g(b);if(M.length)for(let I of l(w).filter(v=>f(v)==="txBody"))for(let v of[...l(I),...d(I,"p")])f(v)==="p"&&(a.push({key:v,parent:I,table:m,...Y?{row:Y}:{}}),s.set(v,[...s.get(v)??[],...M]))},h=(w,m=0)=>{if(--i<0||m>64){i=-1;return}if(w.ns===Xr&&w.local==="tbl"){for(let b of d(w.key,"tr"))for(let Y of l(b).filter(M=>f(M)==="tc"))u(Y,w.key,b);for(let b of l(w.key).filter(Y=>f(Y)==="tr"))for(let Y of d(b,"tc"))u(Y,w.key,Y,b)}for(let b of w.children??[])"text"in b||h(b,m+1)};if(h(t),i<0)return t;let p=[...new Map(a.map(w=>[w.key,w])).values()],k=(w,m,b)=>{let Y=n(w,m,b),M=s.get(w)??[];if(!Y||!M.length)return null;let I=v=>{for(let R of v.children??[]){if(!("text"in R)){if(I(R))return!0;continue}let F=c(R.key),A=F instanceof Fe.Map?F.get(E.text):void 0;if(!(!(A instanceof Fe.Text)||A.length>Vr))for(let T of Ce(A,0,A.length)){if((i-=1+M.length)<0)return!1;let P=U(e.doc,T);if(M.every(N=>P.clock>=(N.get(P.client)??0)))return!0}}return!1};return I(Y)?Y:null},x=new Map,y=new Set,S=vn(e,t,p,k,x,y,n);if(i<0)return t;for(let[w,m]of x)o.set(w,m);for(let w of y)r.add(w);return S}import*as V from"yjs";import*as Ae from"yjs";var po=4096,Ur="http://schemas.openxmlformats.org/drawingml/2006/main",Bc=e=>e.type==="element";function Tt(e,t){let n=Z(e,t);if(!n)return null;let o=0,r=po;for(let i=n.parent instanceof Ae.Text?n.parent._start:null;i&&--r>=0;i=i.right){if(i===n)return{text:n.parent,at:o+(t.clock-n.id.clock)};o+=i.length}return null}function Xc(e,t){let n=t,o=0,r=po;for(let i=0;i<Je;i+=1){let s=Z(e,n),a=Tt(e,n);if(!s||!a)return null;let c=ie(xe(s));if(!c)return{text:a.text,at:a.at+o};let f=n.clock-c.clock;if(n.client===c.client&&f>=0&&f<c.length){n=c.source(f);continue}let l=null,d=null;for(let u=0;u<c.length&&r-- >0;u+=1){let h=Tt(e,Ae.createID(c.client,c.clock+u));if(!(!h||h.text!==a.text))if(h.at<a.at)l=u;else{d=u;break}}let g=l??d;if(g===null)return{text:a.text,at:a.at+o};o=(l!==null?.5:-.5)+o/2,n=c.source(g)}return null}function Nt(e,t){let n=new Map,o=e.package.parts.get(t);if(o?.kind!=="xml")return n;let r=(i,s,a)=>{let c=e.keyOf(t,i.id),f=i.ns===Ur&&i.local==="p"&&c&&a?{p:{key:c,parent:a}}:i.ns===Ur&&i.local==="r"&&c?{...s,run:c}:s;for(let l of i.children)if(Bc(l))r(l,f,c);else{let d=e.keyOf(t,l.id);d!==void 0&&n.set(d,{order:n.size,...f})}};return r(o.xml.root,{},void 0),n}function Zt(e,t){let n=new Map,o=u=>{let h=`${u.client}:${u.clock}`;return n.has(h)||n.set(h,Tt(e,u)),n.get(h)},r=(u,h)=>{let p=o(u),k=o(h);return p&&k&&p.text===k.text?p.at-k.at:null},i=new Map,s=u=>{let h=`${u.client}:${u.clock}`;return i.has(h)||i.set(h,Xc(e,u)),i.get(h)},a=(u,h)=>{let p=s(u.start),k=s(h.start);return p&&k&&p.text===k.text?p.at-k.at:0},c=(u,h)=>r(u.from,h.from)??a(u,h),f=u=>t.get(u.key)?.order??-1,l=(u,h)=>r(u.start,h.start)!==0?0:+!!u.enter-+!!h.enter||(u.enter&&h.enter?(u.client??0)-(h.client??0):0),d=(u,h)=>u.client!==void 0&&h.client!==void 0?h.client-u.client||(u.key<h.key?1:u.key>h.key?-1:0):f(u)-f(h);return{laterStart:c,laterRoot:a,ahead:(u,h)=>(a(u,h)||c(u,h)||l(u,h)||d(u,h))>=0,shown:u=>t.has(u)}}function go(e,t){if(t.newParagraph)return!0;let n=t.source(0);for(let o=0;o<Je;o+=1){let r=Z(e,n),i=r?ie(xe(r)):null,s=i?n.clock-i.clock:-1;if(!i||n.client!==i.client||s<0||s>=i.length)return!1;if(i.newParagraph)return!0;n=i.source(s)}return!1}function Vc(e,t){let n=Oe(t.parent);return n&&n.parent===e.nodes&&typeof n.parentSub=="string"?n.parentSub:null}function On(e,t,n){let o=Ae.createID(e.id.client,e.id.clock+t),r=e.parent instanceof Ae.Text?e.parent.doc:null,i=r?Nr(r,o):null;if(i)return i;let s=0,a=e,c=t-1;for(;a!==null&&s++<po;){if(!a.deleted&&a.countable)for(;c>=0;c-=1,s+=1){let f=Ae.createID(a.id.client,a.id.clock+c);if(!n(f))return o;o=f}a=a.left,c=a?a.length-1:-1}return o}function Pn(e,t,n,o,r,i,s=o){let a=e.doc,c=Vc(e,n);if(c===null||!t.shown(c)||r.length===0)return!1;let f=U(a,s,i),l=(h,p)=>{let k=p;for(let x=0;x<Je;x+=1){let y=a.getMap(Pe).get(`${k.client}:${k.clock}`),S=Array.isArray(y)&&Number.isSafeInteger(y[0])&&Number.isSafeInteger(y[1])?Ae.createID(y[0],y[1]):Me(a,k);if(!S||Ae.compareIDs(S,k))return!1;if(Ae.compareIDs(S,h))return!0;k=S}return!1};for(let{copy:h}of r)for(let p=0;p<h.length;p+=1){let k=h.source(p);if(Ae.compareIDs(U(a,k,i),f))for(let x=0;x<Je;x+=1){if(Ae.compareIDs(k,s))return!1;let y=Me(a,k);if(y){if(!l(k,s))return!1;let b=a.getMap(Pe).get(`${k.client}:${k.clock}`);k=Array.isArray(b)&&Number.isSafeInteger(b[0])&&Number.isSafeInteger(b[1])?Ae.createID(b[0],b[1]):y;continue}let S=Z(a,k),w=S?ie(xe(S)):null,m=w?k.clock-w.clock:-1;if(!w||k.client!==w.client||m<0||m>=w.length)break;k=w.source(m)}}let d=a.getMap(Pe).get(`${s.client}:${s.clock}`);if(Array.isArray(d)&&d[2]===!1)return!0;let g=Ve(a,s),u={key:g?.key??c,from:Hr(a,o),start:U(a,o,i),enter:g?.enter,client:g?.client};return!r.some(h=>t.ahead(ho(a,h,i),u))}function ho(e,t,n){let o=t.copy.source(0);return{key:t.key,from:Hr(e,o),start:U(e,o,n),enter:go(e,t.copy),client:t.copy.client}}function Hr(e,t){let n=t;for(let o=0;o<Je;o+=1){let r=Me(e,n);if(!r)break;n=r}return n}import*as De from"yjs";import{asciiFold as Gc}from"@pptx-editor.dev/core/store";var yo="http://schemas.openxmlformats.org/drawingml/2006/main",es="http://schemas.openxmlformats.org/presentationml/2006/main",_=e=>[e,[e]],ke=(e,t)=>[e,t],tn=["*",[]],nn=ke("fill",["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),Uc=ke("fill",["noFill","solidFill","gradFill","pattFill"]),Dn=ke("effect",["effectLst","effectDag"]),Hc=[ke("color",["scrgbClr","srgbClr","hslClr","sysClr","schemeClr","prstClr"])],qr=[_("xfrm"),ke("geometry",["custGeom","prstGeom"]),nn,_("ln"),Dn,_("scene3d"),_("sp3d"),_("extLst")],Jr=[Uc,ke("dash",["prstDash","custDash"]),ke("join",["round","bevel","miter"]),_("headEnd"),_("tailEnd"),_("extLst")],mo=[_("ln"),nn,Dn,_("highlight"),ke("uLn",["uLnTx","uLn"]),ke("uFill",["uFillTx","uFill"]),_("latin"),_("ea"),_("cs"),_("sym"),_("hlinkClick"),_("hlinkMouseOver"),_("rtl"),_("extLst")],en=e=>[_("cNvPr"),_(e),_("nvPr")],An=e=>[_(e),_("extLst")],ko=["lnL","lnR","lnT","lnB","lnTlToBr","lnBlToTr"],qc=Object.assign(Object.create(null),{sld:[_("cSld"),_("clrMapOvr"),_("transition"),_("timing"),_("extLst")],cSld:[_("bg"),_("spTree"),_("custDataLst"),_("controls"),_("extLst")],bg:[ke("background",["bgPr","bgRef"])],bgPr:[nn,Dn,_("extLst")],spPr:qr,grpSpPr:qr,ln:Jr,...Object.fromEntries(ko.map(e=>[e,Jr])),effectLst:[_("blur"),_("fillOverlay"),_("glow"),_("innerShdw"),_("outerShdw"),_("prstShdw"),_("reflection"),_("softEdge")],...Object.fromEntries(["solidFill","outerShdw","innerShdw","prstShdw","glow","highlight","extrusionClr","contourClr","buClr","lnRef","fillRef","effectRef","fontRef"].map(e=>[e,Hc])),scene3d:[_("camera"),_("lightRig"),_("backdrop"),_("extLst")],camera:[_("rot")],lightRig:[_("rot")],sp3d:[_("bevelT"),_("bevelB"),_("extrusionClr"),_("contourClr"),_("extLst")],style:[_("lnRef"),_("fillRef"),_("effectRef"),_("fontRef")],sp:[_("nvSpPr"),_("spPr"),_("style"),_("txBody"),_("extLst")],pic:[_("nvPicPr"),_("blipFill"),_("spPr"),_("style"),_("extLst")],cxnSp:[_("nvCxnSpPr"),_("spPr"),_("style"),_("extLst")],grpSp:[_("nvGrpSpPr"),_("grpSpPr"),tn,_("extLst")],graphicFrame:[_("nvGraphicFramePr"),_("xfrm"),_("graphic"),_("extLst")],nvSpPr:en("cNvSpPr"),nvPicPr:en("cNvPicPr"),nvCxnSpPr:en("cNvCxnSpPr"),nvGrpSpPr:en("cNvGrpSpPr"),nvGraphicFramePr:en("cNvGraphicFramePr"),cNvPr:[_("hlinkClick"),_("hlinkHover"),_("extLst")],nvPr:[_("ph"),ke("media",["audioCd","wavAudioFile","audioFile","videoFile","quickTimeFile"]),_("custDataLst"),_("extLst")],cNvSpPr:An("spLocks"),cNvPicPr:An("picLocks"),cNvGrpSpPr:An("grpSpLocks"),cNvGraphicFramePr:An("graphicFrameLocks"),cNvCxnSpPr:[_("cxnSpLocks"),_("stCxn"),_("endCxn"),_("extLst")],xfrm:[_("off"),_("ext"),_("chOff"),_("chExt")],blipFill:[_("blip"),_("srcRect"),ke("fillMode",["tile","stretch"])],txBody:[_("bodyPr"),_("lstStyle"),tn],bodyPr:[_("prstTxWarp"),ke("autofit",["noAutofit","normAutofit","spAutoFit"]),_("scene3d"),ke("text3d",["sp3d","flatTx"]),_("extLst")],p:[_("pPr"),tn,_("endParaRPr")],r:[_("rPr"),_("t")],fld:[_("rPr"),_("pPr"),_("t")],br:[_("rPr")],pPr:[_("lnSpc"),_("spcBef"),_("spcAft"),ke("buClr",["buClrTx","buClr"]),ke("buSz",["buSzTx","buSzPct","buSzPts"]),ke("buFont",["buFontTx","buFont"]),ke("bullet",["buNone","buAutoNum","buChar","buBlip"]),_("tabLst"),_("defRPr"),_("extLst")],rPr:mo,defRPr:mo,endParaRPr:mo,tbl:[_("tblPr"),_("tblGrid"),tn],tblPr:[nn,Dn,ke("tableStyle",["tableStyle","tableStyleId"]),_("extLst")],tc:[_("txBody"),_("tcPr"),_("extLst")],tcPr:[...ko.map(_),_("cell3D"),nn,_("headers"),_("extLst")]}),So=e=>e.ns===yo||e.ns===es,Jc=new Set(["sld","cSld","bg","bgPr","sp","pic","cxnSp","grpSp","graphicFrame","nvSpPr","nvPicPr","nvCxnSpPr","nvGrpSpPr","nvGraphicFramePr","nvPr","style"]);function ts(e){if(!(!So(e)||Jc.has(e.local)&&e.ns!==es))return qc[e.local]}function ns(e,t){return So(t)?e.findIndex(([,n])=>n.includes(t.local)):-1}var Qc=new Set(["pPr","rPr","defRPr","endParaRPr","bodyPr","tblPr","tcPr","ln",...ko]);function os(e){return So(e)&&Qc.has(e.local)}function Zc(e,t){let n=ts(e),o=n?ns(n,t):-1;return o<0?void 0:n[o][0]}var ea=(e,t)=>e.ns===yo&&e.local==="tc"&&t.ns===yo&&t.local==="txBody",ta="http://schemas.openxmlformats.org/package/2006/content-types",na="http://schemas.openxmlformats.org/package/2006/relationships",oa=Object.assign(Object.create(null),{[`${ta}|Types`]:{Default:{attr:"Extension",caseless:!0},Override:{attr:"PartName",caseless:!0}},[`${na}|Relationships`]:{Relationship:{attr:"Id",caseless:!1}}});function _t(e,t,n){let o=oa[`${e.ns}|${e.local}`];if(o&&Object.prototype.hasOwnProperty.call(o,t.local)){let{attr:i,caseless:s}=o[t.local],a=n(i);return a===void 0?void 0:{slot:`${t.local}:${s?Gc(a):a}`,rule:"key"}}let r=Zc(e,t);if(!(r===void 0||ea(e,t)))return{slot:r,rule:os(t)?"merge":"first"}}function ht(e,t,n){let o=ts(e);if(!o)return t;let r=o.indexOf(tn),i=-1,s=!0,a=t.map((c,f)=>{let l=n(c),d=l?ns(o,l):-1,g=d>=0?d:r>=0?r:i;return g<i&&(s=!1),i=g,{c,rank:g,i:f}});return s?t:a.sort((c,f)=>c.rank-f.rank||c.i-f.i).map(c=>c.c)}var Qr=e=>`${e.ns}${xn}${e.local}`,Te=e=>e.slice(0,Math.max(0,e.indexOf("."))),Cn="_",Zr=e=>e.slice(e.indexOf(".")+1).startsWith(Cn);function rs(e,t){let n=e.get(t);return n||(n={merge:!1,companions:[],attrFrom:new Map,childFrom:new Map,shadowed:new Map},e.set(t,n)),n}var wo=(e,t)=>e.attrs?.find(n=>n.ns===""&&n.local===t)?.value;function ra(e,t,n){let o=rs(n,e.key);o.merge=!0;let r=new Map;for(let u of e.attrs??[])r.set(Qr(u),u);let i=u=>"text"in u?void 0:_t(e,u,h=>wo(u,h))?.slot,s=e.children??[],a=new Set(s.map(i)),c=[...s],f=new Map;for(let u of t){o.companions.push(u.key);for(let h of u.attrs??[]){let p=Qr(h);r.has(p)||(r.set(p,h),o.attrFrom.set(p,u.key))}for(let h of u.children??[]){if("text"in h)continue;let p=i(h);if(p===void 0){c.push(h),f.set(h.key,u.key);continue}if(a.has(p)&&!os(h)){o.shadowed.set(h.key,p);continue}a.add(p),c.push(h),f.set(h.key,u.key)}}let l=xo(e,c,n);if(!l)return null;for(let u of l){let h="text"in u?void 0:f.get(u.key);h!==void 0&&o.childFrom.set(u.key,h)}let d=ht(e,l,u=>"text"in u?void 0:u),g=[...r.entries()].sort(([u],[h])=>u<h?-1:u>h?1:0);return{...e,attrs:g.map(([,u])=>u),children:[...d]}}function xo(e,t,n){let o=new Map,r=[],i=new Map;for(let s of t){let a="text"in s?void 0:_t(e,s,g=>wo(s,g)),c=a?o.get(a.slot):void 0,f=c===void 0?void 0:r[c],l=f!==void 0&&!(Zr(f.key)&&Zr(s.key));if(a&&c===void 0&&o.set(a.slot,r.length),!l){r.push(s);continue}let d=i.get(c);if(d||i.set(c,d=[]),d.length>=Xt.maxCopiesPerGroup)return null;d.push(s)}for(let[s,a]of i){let c=r[s];if(_t(e,c,f=>wo(c,f))?.rule==="merge"){let f=ra(c,a,n);if(!f)return null;r[s]=f}else{let f=rs(n,c.key);for(let l of a)f.companions.push(l.key)}}return r}function ss(e,t,n){let o=new Map,r=new Map;for(let[i,s]of e){if(Te(i)!==n(s.group))continue;let a=t.get(i)?.order;if(a===void 0)continue;let c=o.get(s.group)??[];c.push({key:i,at:s.at,order:a,rank:c.length}),o.set(s.group,c);let f=r.get(s.group);(f===void 0||a>t.get(f).order)&&r.set(s.group,i)}for(let i of o.values())i.sort((s,a)=>s.at-a.at||s.order-a.order||a.rank-s.rank);return{last:r,preceding(i,s){let a=o.get(i);if(!a)return;let c=0,f=a.length;for(;c<f;){let l=c+Math.floor((f-c)/2);a[l].at<=s?c=l+1:f=l}return a[c-1]?.key}}}var $=Object.freeze({splitFrom:"sf",splitBaseText:"sb",splitAt:"sa",splitLength:"sl",splitGeneration:"sg",splitEdited:"se",copyWinner:"cw",splitBreak:"sk",movedFrom:"mf",movedIndex:"mi",movedClock:"mq",movedTo:"mt",movedEarlier:"mo",removedWith:"rw"}),mt="pptx-pieces-v1",St="pptx-moves-v1",Tn="pptx-splits-v1",yt=2e4,Nn=64,fs=`${$.removedWith}.`,Io=2**31,_n=300,Eo=8,Lt=4096,kt=e=>Number.isSafeInteger(e)&&e>=0,sa=e=>Number.isSafeInteger(e)&&e>=1&&e<Io,ds="http://schemas.openxmlformats.org/drawingml/2006/main",sn=new Set,Qe=e=>e?.type==="element",cn=e=>e===$.removedWith||e.startsWith(fs);function we(e){for(let t of e.keys())if(cn(t))return!0;return!1}function is(e,t,n){e.set(`${fs}${t}`,n)}var Mo=e=>e.children.filter(Qe);function on(e){let n=Mo(e).find(o=>o.local==="t")?.children.find(o=>o.type==="text");return n?.type==="text"?n.value:""}function us(e){if(!e||"text"in e)return"";let t=e.children?.find(o=>!("text"in o)&&o.local==="t"),n=t&&!("text"in t)?t.children?.find(o=>"text"in o):void 0;return n&&"text"in n?n.text:""}function ps(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t.toString(36)}function Yo(e,t,n,o){let r=`${e}\0${ps(t)}\0${n}`;return o===void 0?r:`${r}\0${o}`}var cs=e=>{let t=Number.parseInt(e,36);return Number.isFinite(t)?t:Number.MAX_SAFE_INTEGER};function gs(e,t,n,o,r){if(o.size===0)return;let i=y=>{let S=r.get(y),w=S===void 0?void 0:e.nodes.get(S);return w instanceof De.Map?w:void 0},s=e.doc.clientID.toString(36),a=new Map,c=[],f=new Set,l=new Set,d=y=>{for(let S of Mo(y)){if(S.local!=="r"||l.has(S.id))continue;let w=o.get(S.id);if(!Qe(w)||w===S||on(w)===on(S))continue;let m=i(S.id);m&&typeof m.get($.splitFrom)=="string"&&m.get($.splitEdited)!==!0&&m.set($.splitEdited,!0)}},g=y=>{let S=Mo(y);S.forEach((w,m)=>{if(w.local!=="r"||!o.has(w.id))return;let b=o.get(w.id);if(!Qe(b)||b===w)return;let Y=on(b),M=on(w);if(Y.length<=M.length||!Y.startsWith(M))return;let I=Y.slice(M.length),v=[],R="",F=[];for(let N=m+1;N<S.length&&R.length<I.length;N+=1){let W=S[N];if(W.local==="br"&&!o.has(W.id)){F.push({el:W,at:M.length+R.length});continue}if(W.local!=="r"||o.has(W.id))break;let C=on(W);v.push({el:W,at:M.length+R.length,length:C.length}),R+=C}let A=r.get(w.id);if(R!==I||A===void 0||v.length===0)return;l.add(w.id);let T=`${A}\0${ps(Y)}`,P=Math.min((hs(e).latest.get(T)??0)+1,Io-1);for(let{el:N,at:W,length:C}of v){let L=i(N.id);if(!L||L.has($.splitFrom))continue;L.set($.splitFrom,A),L.set($.splitBaseText,Y),L.set($.splitAt,W),L.set($.splitLength,C),L.set($.splitGeneration,P);let K=r.get(N.id);K!==void 0&&e.doc.getMap(mt).set(K,t)}for(let{el:N,at:W}of F){let C=i(N.id);!C||C.has($.splitBreak)||(C.set($.splitBreak,Yo(A,Y,P)),C.set($.splitAt,W))}e.doc.getMap(Tn).set(Yo(A,Y,P,s),M.length)})},u=(y,S)=>{let w=o.get(y.id);if(w===y)return;let m=r.get(y.id),b=m===void 0?S:[m,...S].slice(0,_n),Y=Qe(w)?new Set(w.children.map(M=>M.id)):new Set;for(let M of y.children)f.add(M.id),!Y.has(M.id)&&o.has(M.id)&&c.push({node:M,path:b});if(Qe(w)){let M=new Set(y.children.map(I=>I.id));for(let I of w.children)M.has(I.id)||a.set(I.id,I)}y.ns===ds&&y.local==="p"&&Qe(w)&&(g(y),d(y));for(let M of y.children)Qe(M)&&u(M,b)};if(u(n,[]),c.length>0){let y=new Map;for(let m of o.values())Qe(m)&&m.children.forEach((b,Y)=>y.set(b.id,{parent:m.id,index:Y}));let S=e.doc.getMap(St),w=De.getState(e.doc.store,e.doc.clientID);for(let{node:m,path:b}of c){let Y=y.get(m.id),M=Y===void 0?void 0:r.get(Y.parent),I=r.get(m.id),v=i(m.id);if(!v||!Y||M===void 0||I===void 0)continue;let R=v.get($.movedFrom);if(typeof R=="string"&&R!==M){let F=v.get($.movedEarlier),A=Array.isArray(F)?F.filter(T=>typeof T=="string"&&T!==R):[];v.set($.movedEarlier,[R,...A].slice(0,Eo))}v.set($.movedFrom,M),v.set($.movedIndex,Y.index),v.set($.movedClock,w),v.set($.movedTo,b),S.set(I,t)}}let h=e.doc.getMap(mt),p,k,x=y=>(p??=as(n,r)).has(y);for(let[y,S]of a){if(f.has(y))continue;let w=new Set,m=[S];for(;m.length>0&&w.size<=yt;){let I=m.pop(),v=r.get(I.id);if(v!==void 0&&w.add(v),Qe(I))for(let R of I.children)f.has(R.id)||m.push(R)}let b=r.get(y);b!==void 0&&ca(e,b,w,x);let Y=i(y);if(!Y||w.size>yt)continue;let M=[...w];is(Y,s,M);for(let I of w){if(I===b||!h.has(I)||(p??=as(n,r)).has(I))continue;let v=e.nodes.get(I);!(v instanceof De.Map)||we(v)||(k??=new Set([...o.keys()].flatMap(R=>r.get(R)??[])),!(!k.has(I)&&ia(e,t,v,p))&&is(v,s,[I]))}}}function as(e,t){let n=new Set,o=[e];for(;o.length>0;){let r=o.pop(),i=t.get(r.id);if(i!==void 0&&n.add(i),Qe(r))for(let s of r.children)o.push(s)}return n}function ia(e,t,n,o){let r=wt(n),i=r?Ft(e)(r.group):void 0;if(!r||i===void 0)return!1;let s=0;for(let[a,c]of e.doc.getMap(mt).entries())if(!(c!==t||Te(a)!==i||!o.has(a))&&((s+=1)>Lt||wt(e.nodes.get(a))?.group===r.group))return!0;return!1}function ca(e,t,n,o){let r=[t],i=new Set;for(;r.length>0&&n.size<=yt;){let s=r.pop();if(i.has(s))continue;i.add(s),n.add(s);let a=e.nodes.get(s),c=a instanceof De.Map?a.get(E.children):void 0;if(c instanceof De.Array)for(let f of c.toArray())typeof f=="string"&&!i.has(f)&&!o(f)&&r.push(f)}}var bo=new WeakMap,ls=new WeakSet;function hs(e){let t=e.doc.getMap(Tn),n=bo.get(t);if(n)return n;let o={groups:new Map,latest:new Map};for(let[r,i]of t.entries()){let s=r.split("\0");if(!kt(i)||s.length!==4)continue;let[a,c,f,l]=s,d=Number(f);if(!Number.isSafeInteger(d)||d<1||d>=Io)continue;let g=`${a}\0${c}`,u=`${g}\0${d}`,h=o.groups.get(u);h||o.groups.set(u,h=new Map),h.set(l,i),o.latest.set(g,Math.max(o.latest.get(g)??0,d))}return bo.set(t,o),ls.has(t)||(ls.add(t),t.observe(()=>bo.delete(t))),o}function wt(e){if(!(e instanceof De.Map))return null;let t=e.get($.splitFrom),n=e.get($.splitBaseText),o=e.get($.splitAt),r=e.get($.splitLength),i=e.get($.splitGeneration);return typeof t!="string"||typeof n!="string"||!kt(o)||!kt(r)||!sa(i)?null:{from:t,group:Yo(t,n,i),original:n.slice(o,o+r),at:o,edited:e.get($.splitEdited)===!0,copyWinner:e.get($.copyWinner)===!0}}function Ft(e){let{groups:t}=hs(e),n=new Map;return o=>{if(n.has(o))return n.get(o);let r=t.get(o),i;if(r&&r.size>=2){let s;for(let[a,c]of r)(!s||c<s[1]||c===s[1]&&cs(a)<cs(s[0]))&&(s=[a,c]);i=s?.[0]}return n.set(o,i),i}}function ms(e,t,n){let o=new Map,r=new Set,i=s=>{let a=o.get(s);if(a!==void 0||o.has(s))return a??null;let c=t(s);if(!c||c.edited||r.has(s)||r.size>Lt)return null;r.add(s);let f=n(s);for(let l of e.get(s)??[]){let d=i(l);if(d===null){f=null;break}f+=d}return r.delete(s),o.set(s,f),f};return i}function Ro(e){let t=new Map;for(let[o,r]of e){let i=t.get(r.from);i?i.push([o,r.at]):t.set(r.from,[[o,r.at]])}let n=new Map;for(let[o,r]of t)n.set(o,r.sort((i,s)=>i[1]-s[1]||(i[0]<s[0]?-1:i[0]>s[0]?1:0)).map(([i])=>i));return n}function ys(e,t){let n=0;for(let o=0;o<t.length&&n<e.length;o+=1)t[o]===e[n]&&(n+=1);return n===e.length}function ks(e,t,n,o,r=sn){if(t.ns!==ds||t.local!=="p")return n;let i=new Map,s=new Map;for(let u of n){if("text"in u)continue;let h=wt(e.nodes.get(u.key));if(h){if(i.size>=Lt)return n;i.set(u.key,h),s.set(u.key,us(u))}}if(i.size===0)return n;let a=Ro(i),c=ms(a,u=>i.get(u),u=>s.get(u)??""),f=Ft(e),l=new Set;for(let[u,h]of i){let p=f(h.group);if(p===void 0||Te(u)===p||r.has(h.group))continue;let k=c(u);k!==null&&ys(k,h.original)&&!(h.copyWinner&&k.length>0)&&l.add(u)}if(l.size===0)return n;let d=[...l];for(;d.length>0;)for(let u of a.get(d.pop())??[])!l.has(u)&&!(i.get(u)?.copyWinner&&(s.get(u)?.length??0)>0)&&(l.add(u),d.push(u));for(let u of l)o.add(u);let g=n.filter(u=>"text"in u||!l.has(u.key));return aa(e,g,l,i,f)}function aa(e,t,n,o,r){let i=new Set;for(let f of n){let l=o.get(f);l&&i.add(`${l.group}\0${Te(f)}`)}let s=new Map;for(let f of t){if("text"in f||f.local!=="br")continue;let l=e.nodes.get(f.key);if(!(l instanceof De.Map))continue;let d=l.get($.splitBreak),g=l.get($.splitAt);if(typeof d!="string"||!kt(g)||!i.has(`${d}\0${Te(f.key)}`))continue;let u;for(let h of t){let p="text"in h?void 0:o.get(h.key);!p||p.group!==d||Te(h.key)!==r(d)||p.at<g||(!u||p.at<u[1])&&(u=[h.key,p.at])}u&&s.set(f.key,u[0])}if(s.size===0)return t;let a=new Map;for(let f of t){let l=s.get(f.key);if(l===void 0)continue;let d=a.get(l);d?d.push(f):a.set(l,[f])}let c=[];for(let f of t)if(!s.has(f.key)){for(let l of a.get(f.key)??[])c.push(l);c.push(f)}return c}function vo(e,t,n){if(!n||n.size===0)return t;let o=new Set(t),r=[...t],i=-1;for(let s of e){let a=r.indexOf(s);if(a>=0&&o.has(s)){i=a;continue}!n.has(s)||o.has(s)||(r.splice(i+1,0,s),i+=1)}return r}function ws(e,t,n,o,r=sn){let i=e.doc.getMap(mt);if(i.size===0)return n;let s=new Map,a=T=>{(T.children??[]).forEach((P,N)=>{s.set(P.key,{parent:T,at:N,order:s.size}),"text"in P||a(P)})};a(n);let c=new Map;for(let[T,P]of i.entries()){if(P!==t)continue;let N=e.nodes.get(T);if(!(N instanceof De.Map)||we(N))continue;let W=wt(N);W&&(c.size>=Lt&&(s.has(T)||c.size>=2*Lt)||c.set(T,W))}let f=Ft(e),l=new Map,d=T=>{let P=l.get(T);if(P===void 0){let N=s.get(T);P=us(N?N.parent.children[N.at]:o(T,new Set,1)??void 0),l.set(T,P)}return P},g=ms(Ro(c),T=>c.get(T),d),u=ss(c,s,f),h=new Map,p=T=>{let P=c.get(T).from;P!==T&&h.set(T,P)},k=[];for(let T of[...c.keys()].sort()){let P=c.get(T),N=f(P.group);if(N===void 0||Te(T)===N){r.has(T)&&!s.has(T)&&k.push(T);continue}let W=g(T);if(W!==null&&ys(W,P.original)&&!(P.copyWinner&&W.length>0))continue;let C=u.preceding(P.group,P.at)??(s.has(P.from)?P.from:u.last.get(P.group));C!==void 0&&C!==T&&h.set(T,C)}let x=new Set(k);for(let T of k){let P=c.get(T).from;(s.has(P)||x.has(P))&&p(T)}let y=Ro(c),S=[...h.keys()];for(;S.length>0;)for(let T of y.get(S.pop())??[])!h.has(T)&&s.has(T)&&(p(T),S.push(T));if(h.size===0)return n;let w=new Map,m=new Set(s.keys());for(let T of h.keys()){let P=s.get(T),N=P?P.parent.children[P.at]:o(T,m,1);N&&w.set(T,N)}let b=new Map,Y=T=>{let P=b.get(T);if(P!==void 0)return P;let N=h.get(T);b.set(T,!1);let W=N===void 0?s.has(T):w.has(T)&&Y(N);return b.set(T,W),W},M=new Map,I=new Set;for(let[T,P]of h){let N=w.get(T);if(!N||!Y(T))continue;I.add(T);let W=M.get(P);W?W.push(N):M.set(P,[N])}if(I.size===0)return n;let v=(T,P)=>{let N=c.get(P);return N?.from===T?N.at:1/0};for(let[T,P]of M)P.sort((N,W)=>v(T,N.key)-v(T,W.key)||(N.key<W.key?-1:N.key>W.key?1:0));let R=new Set,F=(T,P)=>{for(let N of M.get(T)??[])R.has(N.key)||(R.add(N.key),P.push(N),F(N.key,P))},A=T=>{let P=[];for(let N of T.children??[])I.has(N.key)||(P.push("text"in N?N:A(N)),F(N.key,P));return{...T,children:P}};return A(n)}var rn=Object.freeze({unseenWinners:sn,lost:sn});function an(e,t,n,o=sn){let r=e.doc.getMap(mt);if(r.size===0)return rn;let i=Ft(e),s=new Set,a=new Map,c=0;for(let[k,x]of r.entries()){if(x!==t)continue;let y=e.nodes.get(k);if(!(y instanceof De.Map)||y.get(E.part)!==t)continue;let S=wt(y);if(S){if(we(y)){Te(k)===i(S.group)&&s.add(S.group);continue}if((c+=1)>Lt)return rn;a.set(k,S)}}if(a.size===0)return rn;let f=new Set,l=[n];for(;l.length>0;){let k=l.pop();if(f.has(k))continue;f.add(k);let x=e.nodes.get(k);if(!(x instanceof De.Map)||x.get(E.part)!==t)continue;let y=x.get(E.children);if(y instanceof De.Array)for(let S of y.toArray())typeof S=="string"&&!f.has(S)&&l.push(S)}let d=new Set,g=new Map;for(let[k,x]of a){let y=Te(k)===i(x.group);if(f.has(k)||o.has(k)){y&&s.add(x.group);continue}if(d.add(k),!y)continue;let S=g.get(x.group);S?S.push(k):g.set(x.group,[k])}let u=new Map,h=k=>{let x=u.get(k);if(x!==void 0)return x;u.set(k,!1);let y=a.get(k)?.from,S=y!==void 0&&(f.has(y)||o.has(y)||d.has(y)&&h(y));return u.set(k,S),S},p=new Set;for(let[k,x]of g)!s.has(k)&&!x.some(h)&&p.add(k);return{unseenWinners:p,lost:d}}var Ss=4096,ze=1<<20,xs=65536,la=1<<20;function bs(e,t,n,o,r,i,s,a=new Set(n)){let c=e.doc,f=c.clientID,l=D=>{let O=e.nodes.get(D),j=ie(O),B=O instanceof V.Map?O.get(E.text):void 0;return!j||!(B instanceof V.Text)||O.get(E.part)!==t?null:{key:D,copy:j,text:B}},d=new Set(n.filter(D=>l(D)!==null));if(d.size===0)return;let g=Nt(r,t),u=[],h=0;for(let[D,O]of e.doc.getMap(Xe).entries()){if(O!==t)continue;let j=l(D);if(!(!j||j.text.length===0&&!g.has(D))){if(u.length>=Ss||(h+=j.copy.length)>ze)return;u.push(j)}}let p=u.filter(D=>d.has(D.key));if(p.length===0)return;let k=new Map,x=D=>U(c,D,k),y=new Map,S=Zt(c,g),w=D=>ho(c,D,k),m=(D,O)=>S.laterRoot(w(D),w(O)),b=(D,O)=>V.createID(D.copy.client,D.copy.clock+O),Y=new Set;for(let D of g.keys()){let O=e.nodes.get(D),j=O instanceof V.Map?O.get(E.text):null;if(j instanceof V.Text)for(let B=j._start;B;B=B.right){if(++h>ze)return;if(!(B.deleted||!B.countable))for(let X=0;X<B.length;X+=1){if(++h>ze)return;let q=x(V.createID(B.id.client,B.id.clock+X));Y.add(z(q.client,q.clock))}}}let M=new Map;for(let[D,O]of e.nodes){if(++h>ze)return;if(!(O instanceof V.Map)||O.get(E.part)!==t)continue;let j=O.get(E.children);if(j instanceof V.Array)for(let B of j.toArray()){if(++h>ze)return;typeof B=="string"&&M.set(B,D)}}let I=new Set;for(let D of[...u].sort((O,j)=>O.key<j.key?-1:O.key>j.key?1:0)){if(g.has(D.key))continue;let O=[];for(let q=D.text._start;q;q=q.right){if(++h>ze)return;if(!(q.deleted||!q.countable))for(let le=0;le<q.length;le+=1){if(++h>ze)return;O.push(x(V.createID(q.id.client,q.id.clock+le)))}}if(!O.some(q=>!Y.has(z(q.client,q.clock))))continue;let j=M.get(D.key),B=j?M.get(j):void 0,X=B?e.nodes.get(B):void 0;if(!(!(X instanceof V.Map)||!X.has($.splitFrom))){X.set($.copyWinner,!0),I.add(D.key),d.add(D.key);for(let q of O)Y.add(z(q.client,q.clock))}}let v=new Map;for(let D of u){if(!g.has(D.key)&&!I.has(D.key))continue;let O=[D.copy,...Ht(e.nodes.get(D.key))];for(let j of O)for(let B=0;B<j.length;B+=1){if((h+=1)>ze)return;let X=V.createID(j.client,j.clock+B);if(Jt(c,X))continue;let q=x(X),le=z(q.client,q.clock),Ee=v.get(le);Ee?Ee.some(it=>V.compareIDs(it.id,X))||Ee.push({copy:D,id:X}):v.set(le,[{copy:D,id:X}])}}let R=(D,O)=>{let j=Ue(c,D.id,y),B=Ue(c,O.id,y);if(!V.compareIDs(j,B)){let q=x(D.id);if(V.compareIDs(j,q))return O;if(V.compareIDs(B,q))return D}let X=q=>{let le=Ve(c,q.id);return le?{key:le.key,from:le.start,start:x(le.start),enter:le.enter,client:le.client}:w(q.copy)};return S.ahead(X(D),X(O))?D:O},F=D=>v.get(z(D.client,D.clock))?.reduce(R);for(let D of p.filter(O=>O.copy.client!==f))pa(e,D,Lr(e.nodes.get(D.key)),O=>F(x(O)),i,(O,j,B,X)=>{let q=v.get(z(x(X).client,x(X).clock))??[],le=On(j,B,Ee=>Me(c,Ee)!==null);return Pn(e,S,O,le,q.map(Ee=>Ee.copy),k,X)},u.map(O=>O.text));let A=new Map,T=(D,O)=>{let j=A.get(D);j?j.push(O):A.set(D,[O])};if(o.size>0)for(let D of p)for(let O=0;O<D.copy.length;O+=1){let j=Ue(c,D.copy.source(O),y);o.has(z(j.client,j.clock))&&!Jt(c,b(D,O))&&T(D.text,b(D,O))}for(let D of v.values()){if(D.length<2||!D.some(X=>d.has(X.copy.key)))continue;let O=D.reduce(R),j=g.get(O.copy.key)?.run,B=j?e.nodes.get(j):void 0;B instanceof V.Map&&B.get($.copyWinner)!==!0&&B.set($.copyWinner,!0);for(let X of D)X!==O&&T(X.copy.text,X.id)}for(let[D,O]of A)_e(D,new Set(O.map(j=>z(j.client,j.clock))));let P=new Map,N=D=>{let O=P.get(D.key);if(!O){O=new Set;for(let j=0;j<D.copy.length;j+=1){let B=x(D.copy.source(j));O.add(z(B.client,B.clock))}P.set(D.key,O)}return O},W=la,C=(D=1)=>(W-=D)>=0,L=(D,O)=>{let[j,B]=[N(D),N(O)].sort((X,q)=>X.size-q.size);if(!C(j.size))return!1;for(let X of j)if(B.has(X))return!0;return!1},K={room:e,me:f,incoming:p.filter(D=>D.copy.client!==f&&a.has(D.key)),all:u,placed:g,share:L,laterStart:m,step:C,movedRun:s};ga(K),fa(K)}function Ln(e,t){let n=e.nodes.get(t),o=n instanceof V.Map?n.get(E.children):void 0;return o instanceof V.Array?o:void 0}function fa(e){let{room:t,me:n,incoming:o,all:r,placed:i,share:s,laterStart:a,step:c,movedRun:f}=e,l=new Map,d=(u,h)=>{let p=l.get(u);if(!p){l.set(u,p=new Map);let k=xs,x=y=>{let S=Ln(t,y)?.toArray()??[];return k-=S.length,k<0?[]:S};for(let y of x(u))for(let S of x(y))for(let w of x(S))for(let m of x(w))p.set(m,{p:y,run:S})}return p.get(h)},g=new Map;for(let u of[...o].sort(a)){let h=i.get(u.key);if(!(!h?.p||!h.run))for(let p of r){if(!c())return;if(p.copy.client!==n||p.key===u.key||!s(u,p))continue;let k=d(h.p.parent,p.key),x=k?t.nodes.get(k.run):void 0;if(!k||k.p===h.p.key||!(x instanceof V.Map))continue;let y=x.get($.movedFrom)===h.p.key,S=!y&&p.copy.newParagraph&&a(u,p)>0&&ua(t,p,d,h.p.parent)===h.p.key;if(!y&&!S)continue;let w=Ln(t,h.p.key),m=Ln(t,k.p),b=w?.toArray().indexOf(h.run)??-1;if(!w||!m||b<0)continue;let Y=da(w,b);if(w.delete(b,1),!S){m.insert(m.toArray().indexOf(k.run),[h.run]);break}let M=g.get(k.run)??k.run,I=V.getState(t.doc.store,n);m.insert(m.toArray().indexOf(M)+1,[h.run]),g.set(k.run,h.run),Y&&f?.({anchor:V.createID(p.copy.client,p.copy.clock),gone:Y,added:V.createID(n,I),run:h.run,from:w,to:m});break}}}function da(e,t){let n=0;for(let o=e._start;o!==null;o=o.right)if(!(o.deleted||!o.countable)){if(t<n+o.length){for(let r=o;r!==null&&!r.keep;)r.keep=!0,r=r.parent._item;return V.createID(o.id.client,o.id.clock+t-n)}n+=o.length}}function ua(e,t,n,o){let r=Z(e.doc,t.copy.source(0)),i=r?xe(r)?.get(E.key):void 0;return typeof i=="string"?n(o,i)?.p:void 0}function pa(e,t,n,o,r,i,s){let a=e.doc,c=a.clientID,l=Z(a,t.copy.source(0))?.parent;if(!(l instanceof V.Text))return;let d=new Map,g=x=>{let y=U(a,x,d);return z(y.client,y.clock)},u=new Set,h=new Set;for(let x=0;x<t.copy.length;x+=1){let y=t.copy.source(x);h.add(z(y.client,y.clock)),u.add(g(y))}let p=ze,k=new Map;for(let x of s){let y=ie(x.parent);if(!(!y||y.client!==c))for(let S=0;S<y.length;S+=1){if(--p<0)return;let w=y.source(S),m=z(w.client,w.clock);k.set(m,Math.min(k.get(m)??1/0,y.clock))}}for(let x of new Set([l,...s])){let y=new Map,S=[],w=null;for(let m=x._start;m!==null;m=m.right){if(--p<0)return;if(m.deleted||!(m.content instanceof V.ContentString))continue;let b=m.content.str;for(let Y=0;Y<b.length;Y+=1){if(--p<0)return;let M=V.createID(m.id.client,m.id.clock+Y),I=ie(x.parent);if(I&&M.client===I.client&&M.clock>=I.clock&&M.clock<I.clock+I.length)continue;let v=Y===0?m.origin:V.createID(m.id.client,m.id.clock+Y-1),R=v&&(k.get(z(v.client,v.clock))??1/0)<m.id.clock;if(Y===0&&v&&R&&Jt(a,v)){let N=m.left,W=0;for(;N&&(N.deleted||!N.countable)&&W++<xs;)N=N.left;N&&!N.deleted&&N.countable&&(v=V.createID(N.id.client,N.id.clock+N.length-1))}let F=v?z(v.client,v.clock):"",A=Y===0?m.rightOrigin:null,T=m.id.client!==c?void 0:v&&(h.has(F)||u.has(g(v)))?{id:v,before:!1}:y.get(F)??(!v&&A&&u.has(g(A))?{id:A,before:!0}:void 0);if(!T){w=null;continue}if(y.set(z(M.client,M.clock),T),n?.(M))continue;(!w||!V.compareIDs(w.anchor,T.id)||w.before!==T.before)&&(w={anchor:T.id,before:T.before,ids:[],written:[],text:"",marks:[]},S.push(w));let P=Me(a,M);P&&u.has(g(M))||P&&i(x,m,Y,M)||(w.ids.push(M),!(P&&o(M))&&(P&&w.marks.push([w.text.length,P]),w.written.push(M),w.text+=b[Y]))}}for(let m of S){let b=o(m.anchor),Y=b?Yn(b.copy.text,b.id):-1;if(!b||Y<0||b.copy.text===x||(_e(x,new Set(m.ids.map(v=>z(v.client,v.clock)))),m.text.length===0))continue;let M=V.getState(a.store,c);b.copy.text.insert(Y+ +!m.before,m.text);let I=e.nodes.get(b.copy.key);I instanceof V.Map&&Dr(I,c,M,m.written);for(let v=0;v<m.written.length;v+=1)for(let R of[Pe,Dt]){let F=a.getMap(R),A=m.written[v],T=F.get(z(A.client,A.clock));T!==void 0&&F.set(z(c,M+v),T)}qt(a,m.marks.flatMap(([v,R])=>[M+v,R.client,R.clock,1])),r(m.ids[0],V.createID(c,M),m.text.length)}}}function Ms(e,t,n){if(n.size===0)return;let o=e.doc,r=new Map,i=0;for(let s of t){let a=e.nodes.get(s),c=a instanceof V.Map?a.get(E.text):void 0;if(!(c instanceof V.Text))continue;let f=[];for(let l of Ht(a))if(!(l.client===o.clientID||(i+=l.length)>ze))for(let d=0;d<l.length;d+=1){let g=V.createID(l.client,l.clock+d),u=Ue(o,l.source(d),r);n.has(z(u.client,u.clock))&&!Jt(o,g)&&f.push(g)}f.length>0&&_e(c,new Set(f.map(l=>z(l.client,l.clock))))}}function ga({room:e,me:t,incoming:n,all:o,placed:r,share:i,laterStart:s,step:a}){for(let c of o){if(c.copy.client!==t||!c.copy.newParagraph)continue;let f=r.get(c.key)?.p,l=f?Ln(e,f.parent):void 0;if(!f||!l)continue;let d=l.toArray();if(!a(d.length))return;let g=new Map(d.map((p,k)=>[p,k])),u=g.get(f.key)??-1;if(u<0)continue;let h;for(let p of n){if(!a())return;if(p.key===c.key||s(c,p)<=0)continue;let k=r.get(p.key)?.p;if(!k||k.parent!==f.parent||k.key===f.key)continue;let x=g.get(k.key)??-1;x<=u||h&&x<=h.at||!i(p,c)||(h={key:k.key,at:x})}h&&(l.delete(u,1),l.insert(l.toArray().indexOf(h.key)+1,[f.key]))}}function Ys(e,t,n,o){if(o.size===0)return;let r=new Map,i=ze;for(let s of n.slice(0,Ss)){let a=e.nodes.get(s),c=ie(a),f=a instanceof V.Map?a.get(E.text):null;if(!c||!(f instanceof V.Text)||!(a instanceof V.Map)||a.get(E.part)!==t)continue;let l=new Set;for(let d=f._start;d&&i-- >0;d=d.right)if(!(d.deleted||!d.countable))for(let g=0;g<d.length&&i-- >0;g+=1){let u=V.createID(d.id.client,d.id.clock+g),h=Ue(e.doc,u,r);o.has(z(h.client,h.clock))&&l.add(z(u.client,u.clock))}if(_e(f,l),i<=0)return}}function Rs(e,t,n){if(n.size===0)return;let o=new Map,r=ze;for(let i of e.nodes.values()){if(--r<0)return;if(!(i instanceof V.Map)||i.get(E.part)!==t)continue;let s=i.get(E.text);if(!(s instanceof V.Text))continue;let a=new Set;for(let c=s._start;c&&--r>=0;c=c.right)if(!(c.deleted||!c.countable))for(let f=0;f<c.length&&--r>=0;f+=1){let l=V.createID(c.id.client,c.id.clock+f),d=U(e.doc,l,o);n.has(z(d.client,d.clock))&&a.add(z(l.client,l.clock))}_e(s,a)}}import*as bt from"yjs";import*as G from"yjs";import*as Oo from"yjs";function xt(e,t){if(!(e instanceof Oo.Map))return null;let n=null,o=0;for(let[r,i]of e.entries()){if(!cn(r)||!Array.isArray(i))continue;let s=e._map.get(r);if(!(s&&t&&s.id.clock<(t.get(s.id.client)??0))){if(i.length>yt+1||(o+=1)>Nn)return"all";n??=new Set;for(let a of i)typeof a=="string"&&n.add(a)}}return n}var ha=1<<18;function Fn(e,t,n){let o=new Set,r=0;for(let i of e.nodes.values()){if((r+=1)>ha)break;if(!(i instanceof Oo.Map)||i.get(E.part)!==t||!we(i))continue;let s=xt(i,n);if(s==="all")return"all";for(let a of s??[])o.add(a)}return o}var ma="http://schemas.openxmlformats.org/drawingml/2006/main";var ln=(e,t)=>!!e&&!("text"in e)&&e.ns===ma&&e.local===t;function Is(e,t,n){let o=[],r=0;for(let i of e.childrenOf(t))if(e.localOf(i)==="txBody")for(let s of e.childrenOf(i)){if((r+=1)>4096)return o;if(e.localOf(s)!=="p"||!e.holdsForeign(s,n))continue;let a=e.readParagraph(s);a&&o.push(a)}return o}function Es(e,t,n){let o=i=>e.findIndex(s=>s.key===i),r=new Set([t.key]);for(let i=t.after;i!==""&&!r.has(i);i=n.get(i)??""){r.add(i);let s=o(i);if(s>=0)return s}return t.before===""?-1:o(t.before)}function vs(e,t,n){let o=e.children??[],r=o.findIndex(a=>ln(a,"txBody"));if(r<0)return null;let i=o[r],s=[...o];s[r]={...i,children:[...i.children??[],...t]};for(let a of t)n.set(a.key,i.key);return{...e,children:s}}function ya(e,t,n,o){let r=e.children??[],i=r.flatMap((c,f)=>ln(c,"tc")?[f]:[]);if(i.length===0)return null;let s=Math.max(0,Math.min(t,i.length-1)),a=[...i.slice(s),...i.slice(0,s).reverse()];for(let c of a){let f=vs(r[c],n,o);if(!f)continue;let l=[...r];return l[c]=f,{...e,children:l}}return null}function Os(e,t,n,o,r){let i=[...e];for(let s of t){let a=o.localOf(s.key);if(a==="tc"){let c=Is(o,s.key,s);if(c.length===0)continue;let f=i.flatMap((g,u)=>ln(g,"tc")?[u]:[]),l=Es(i,s,n),d=l>=0?[l,...f.filter(g=>g!==l)]:f;for(let g of d){let u=vs(i[g],c,r);if(u){i[g]=u;break}}}else if(a==="tr"){let c=i.flatMap((g,u)=>ln(g,"tr")?[u]:[]),f=Es(i,s,n),l=f>=0&&ln(i[f],"tr")?f:c[0];if(l===void 0)continue;o.childrenOf(s.key).filter(g=>o.localOf(g)==="tc").forEach((g,u)=>{let h=Is(o,g,s);if(h.length===0)return;let p=ya(i[l],u,h,r);p&&(i[l]=p)})}}return i}var Ke="pptx-undone-v1",Ds=64,zt=1024,Cs=1<<18,Ts=(e,t)=>e.id.client!==t.client||e.id.clock>=t.clock;function Kt(e,t,n){if(typeof t!="object"||t===null)return null;let o=t;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 r=Number.isSafeInteger(o.q)&&o.q>=0?o.q:1/0,i=typeof o.n=="string"?o.n:"",s=typeof o.s=="string"?o.s:null,a=o.m===1,c=new Map;if(Array.isArray(o.v)&&o.v.length<=8192&&o.v.length%2===0)for(let f=0;f<o.v.length;f+=2){let[l,d]=o.v.slice(f,f+2);typeof l=="number"&&Number.isSafeInteger(l)&&l>=0&&typeof d=="number"&&Number.isSafeInteger(d)&&d>=0&&c.set(l,d)}return{key:e,parent:o.u,after:o.a,before:i,client:o.c,clock:r,shownIn:s,moved:a,seen:c,redo:o.d===1,table:typeof o.t=="string"?o.t:null}}var ka=64;function wa(e,t){let n=t;for(let o=0;n&&n.deleted&&o<ka;o+=1)n=n.redone?Z(e,n.redone):null;return n&&!n.deleted?n:null}function Ns(e,t,n){if(!n)return!1;let o=Kt(t,e.doc.getMap(Ke).get(t));return o!==null&&o.shownIn===null&&!o.moved&&Ts(n,o)}function Ao(e,t,n,o=new Set,r=!1){let i=e.nodes,s=new Map,a=new Set;ae(e.doc,t.insertions,p=>{p.parent===e.parts&&p.parentSub!==null&&!p.deleted&&a.add(p.parentSub)});let c=new Map;ae(e.doc,t.deletions,p=>{let k=p.parent;if(!(k instanceof G.Array)||!(p.content instanceof G.ContentAny))return;let x=k.parent,S=(x instanceof G.Map?x.get(E.shell):void 0)?.local;if(S!=="txBody"&&S!=="tc")return;let w=x.get(E.key);if(typeof w=="string")for(let m of p.content.getContent())typeof m=="string"&&c.set(m,w)}),ae(e.doc,t.insertions,p=>{let k=wa(e.doc,p)??p,x=k?.parent;if(!k||!(x instanceof G.Array))return;let y=x.parent;if(!(y instanceof G.Map)||Oe(y)?.parent!==i||y.get(E.children)!==x||k.parentSub!==null||!(k.content instanceof G.ContentAny))return;let S=s.get(x);S||s.set(x,S=new Set);for(let w of k.content.getContent())typeof w=="string"&&S.add(w)});let f=ao(t);for(let[p,k]of f){let x=s.get(p)??new Set;for(let y of k.keys)x.add(y);s.set(p,x)}if(s.size===0)return;for(let p of s.values())for(let k of o)p.delete(k);let l=e.doc.getMap(Ke),d=e.doc.clientID,g=G.getState(e.doc.store,d),u=[],h=new Map;{let p=Cs,k=(x,y,S)=>{if(--p<0||S>Ds||h.has(x))return;let w=e.nodes.get(x);if(!(w instanceof G.Map))return;let m=w.get(E.shell);m?.ns===nt&&m.local==="tbl"&&(y=x),y&&h.set(x,y);let b=w.get(E.children);if(b instanceof G.Array)for(let Y of b.toArray())typeof Y=="string"&&k(Y,y,S+1)};for(let x of e.parts.values()){let y=et(x);y?.kind==="xml"&&k(y.root,void 0,0)}}for(let[p,k]of s){let x=p.parent;if(!(x instanceof G.Map)||x.get(E.children)!==p)continue;let y=x.get(E.key),S=x.get(E.part);if(typeof y!="string"||typeof S!="string"||a.has(S))continue;let w=p.toArray().filter(m=>typeof m=="string");for(let m of f.get(p)?.siblings??[])k.has(m)&&!w.includes(m)&&w.push(m);w.forEach((m,b)=>{if(!k.has(m))return;if(r){let R=e.nodes.get(m),F=R instanceof G.Map?R.get(E.shell):void 0;if(F?.ns!==nt||F.local!=="tr"&&F.local!=="tc")return}if(x.get(E.shell)?.local==="txBody"&&(Kt(m,l.get(m))?.parent??y)!==y)return;let I=w[b+1]??"",v={p:S,u:y,a:w[b-1]??"",n:I,c:d,q:g};v.t=h.get(y),r&&(v.d=1),c.has(m)&&(v.m=1,v.v=[...G.decodeStateVector(G.encodeStateVector(e.doc))].flatMap(([R,F])=>[R,F])),JSON.stringify(l.get(m))!==JSON.stringify(v)&&u.push([m,v])})}u.length>0&&n(()=>{for(let[p,k]of u)l.set(p,k)})}function _s(e,t,n,o,r,i){let s=e.doc.getMap(Ke),a=e.doc.clientID,c=new Set;for(let f of r){let l=o[f],d=typeof l=="string"?i(l):void 0;if(typeof l!="string"||d===void 0||c.has(l))continue;c.add(l);let g="";for(let p=f-1;p>=0&&g==="";p-=1)o[p]!==l&&typeof o[p]=="string"&&(g=o[p]);let u="";for(let p=f+1;p<o.length&&u==="";p+=1)o[p]!==l&&typeof o[p]=="string"&&(u=o[p]);let h={p:t,u:n,a:g,n:u,c:a,q:0,s:d};JSON.stringify(s.get(l))!==JSON.stringify(h)&&s.set(l,h)}}function Ls(e,t,n){let o=e.doc.getMap(Ke);if(o.size===0)return;let r=new Set;ae(e.doc,t.deletions,i=>{let s=i.parent;if(!(s instanceof G.Array)||!(i.content instanceof G.ContentAny))return;let a=s.parent instanceof G.Map?s.parent.get(E.key):void 0;for(let c of i.content.getContent())typeof c=="string"&&Kt(c,o.get(c))?.parent===a&&!Kt(c,o.get(c))?.redo&&r.add(c)}),r.size>0&&n(()=>{for(let i of r)o.delete(i)})}function Fs(e,t,n){let o=new Map,r=new Map,i=c=>{if(!r.has(c)){let f=et(e.parts.get(c));r.set(c,f?.kind==="xml"?fn.of(e,c,f.root):null)}return r.get(c)};if(ae(e.doc,t.insertions,c=>{if(c.parent!==e.nodes||c.parentSub===null||!(c.content instanceof G.ContentType)||!(c.content.type instanceof G.Map))return;let f=c.content.type;if(e.nodes.get(c.parentSub)!==f)return;let l=f.get(E.part),d=f.get(E.attrs),g=f.get(E.children);if(typeof l!="string"||!(d instanceof G.Map)||!(g instanceof G.Array)||d.size>0||g.length>0||!n(l,c.parentSub)||i(l)?.showsUnder(c.parentSub))return;let u=o.get(l);u||o.set(l,u=new Set),u.add(c.parentSub)}),o.size===0)return!1;let s=!1,a=0;for(let c of e.nodes.values()){if((a+=1)>Cs)break;if(!(c instanceof G.Map))continue;let f=c.get(E.part),l=typeof f=="string"?o.get(f):void 0,d=c.get(E.children);if(!l||!(d instanceof G.Array))continue;let g=d.toArray();for(let u=g.length-1;u>=0;u-=1){let h=g[u];if(typeof h=="string"&&l.has(h)){let p=e.doc.getMap(Ke),k=p.get(h),x=c.get(E.key);Kt(h,k)&&typeof x=="string"&&p.set(h,{...k,u:x,a:typeof g[u-1]=="string"?g[u-1]:"",n:typeof g[u+1]=="string"?g[u+1]:""}),d.delete(u,1),s=!0}}}return s}var Ps=new WeakMap;function As(e,t,n){let o=e.placeOf.get(t);if(o){let c=e.byPart.get(o.part),f=c?.get(o.parent);f?.delete(t),f?.size===0&&c.delete(o.parent),e.placeOf.delete(t)}let r=n===void 0?null:Kt(t,n),i=r?n.p:null;if(!r||i===null)return;let s=e.byPart.get(i);s||e.byPart.set(i,s=new Map);let a=s.get(r.parent);a||s.set(r.parent,a=new Map),a.set(t,r),e.placeOf.set(t,{part:i,parent:r.parent})}function Sa(e,t){let n=e.doc.getMap(Ke),o=Ps.get(n);if(!o){let r={byPart:new Map,placeOf:new Map};o=r;for(let[i,s]of n.entries())As(r,i,s);Ps.set(n,r),n.observe(i=>{for(let s of i.keysChanged)As(r,s,n.get(s))})}return o.byPart.get(t)??new Map}function xa(e,t,n){let o=new Set,r=[n];for(;r.length>0;){let i=r.pop();if(o.has(i))continue;o.add(i);let s=e.nodes.get(i);if(!(s instanceof G.Map)||s.get(E.part)!==t)continue;let a=s.get(E.children);if(a instanceof G.Array)for(let c of a.toArray())typeof c=="string"&&!o.has(c)&&r.push(c)}return o}var nt="http://schemas.openxmlformats.org/drawingml/2006/main",zs=new Set(["p","pPr","rPr","endParaRPr","ln","bodyPr","tcPr"]);function Ks(e){if("text"in e)return e.text.length>0;if(e.ns!==nt)return!1;let t=e.children??[];return e.local==="r"?t.some(n=>!("text"in n)&&n.ns===nt&&n.local==="t"&&Ks(n)):e.local==="t"?t.some(n=>"text"in n&&n.text.length>0):zs.has(e.local)&&(t.length>0||(e.attrs??[]).length>0)}function Po(e){return"text"in e?e.text.length>0:(e.children??[]).some(Po)}var fn=class e{#e;#t;#r;#f=new Map;shown=new Set;rehomed=new Set;shownIn=new Map;#a;#d=new Map;constructor(t,n,o,r){this.#e=t,this.#a=n,this.#t=o,this.#r=r}static of(t,n,o){if(t.doc.getMap(Ke).size===0)return null;let r=Sa(t,n);return r.size===0?null:new e(t,n,r,xa(t,n,o))}withStranded(t,n){let o=[...this.#t.keys()].flatMap(r=>this.#o(r)).filter(r=>r.moved||this.#n(r.key,r,0));return vn(this.#e,t,o,n,this.shownIn,this.rehomed)}#n(t,n,o){let r=`${t}\0${n.client}\0${n.clock}`,i=this.#f.get(r);if(i!==void 0)return i;this.#f.set(r,!1);let s=o<=Ds&&this.#u(t,n,o);return this.#f.set(r,s),s}#u(t,n,o){let r=this.#e.nodes.get(t);if(!(r instanceof G.Map))return!1;let i=d=>Ts(d,n),s=r.get(E.text);if(s instanceof G.Text){for(let d of Gt(s))if(d.countable&&i(d))return!0}let a=r.get(E.attrs);if(a instanceof G.Map){for(let d of gr(a))if(i(d))return!0}let c=r.get(E.children);if(c instanceof G.Array){for(let d of Gt(c))if(i(d))return!0}let f=r.get(E.shell);if(f?.ns===nt&&(f.local==="p"||f.local==="r"||f.local==="t")&&c instanceof G.Array){for(let d of c.toArray().slice(0,zt))if(typeof d=="string"&&this.#n(d,n,o+1))return!0}let l=[];for(let d of r.keys())d.startsWith(oe.removedRun)&&l.push(d);for(let d of l.sort().slice(0,zt))if(this.#n(d.slice(oe.removedRun.length),n,o+1))return!0;return this.#o(t).some(d=>this.#n(d.key,d,o+1))}showsUnder(t){return this.#o(t).some(n=>this.#n(n.key,n,1))}showsBelow(t){let n=[t],o=new Set;for(;n.length>0&&o.size<zt;){let r=n.pop();if(o.has(r))continue;if(o.add(r),this.showsUnder(r))return!0;let i=this.#e.nodes.get(r);if(!(i instanceof G.Map)||i.get(E.part)!==this.#a)continue;let s=i.get(E.shell),a=i.get(E.children);if(s?.ns!==nt||!["p","r","t"].includes(s.local??"")||!(a instanceof G.Array))continue;for(let f of a.slice(0,zt))typeof f=="string"&&n.push(f);let c=[...i.keys()].filter(f=>f.startsWith(oe.removedRun)).sort().slice(0,zt);for(let f of c)n.push(f.slice(oe.removedRun.length))}return!1}#o(t){return[...this.#t.get(t)?.values()??[]].filter(n=>{if(this.#r.has(n.key))return!1;if(n.shownIn!==null&&!this.#r.has(n.shownIn)){let i=xt(this.#e.nodes.get(n.shownIn));if(!i||i==="all"||i.has(n.key))return!1}let o=this.#e.nodes.get(n.key);if(!(o instanceof G.Map))return!1;if(!n.redo&&we(o)){let i=o.get(E.shell);if(i?.ns!==nt||i.local!=="p"&&i.local!=="r")return!1}if(!n.moved)return!0;let r=this.#d.get(n);return r||(r=Fn(this.#e,this.#a,n.seen),this.#d.set(n,r)),r!=="all"&&!r.has(n.key)})}withUndone(t,n,o,r,i){let s=this.#o(t).filter(p=>!r.has(p.key)&&(p.moved||this.#n(p.key,p,0))).sort((p,k)=>p.key<k.key?-1:p.key>k.key?1:0).slice(0,zt);if(s.length===0)return o;let a=[...o],c=new Set(a.map(p=>p.key)),f=new Map([...this.#t.get(t)?.values()??[]].map(p=>[p.key,p.after])),l=new Set(s.map(p=>p.key)),d=[],g="\0";for(let p=!1;l.size>0;){let k=!1;for(let x of s){if(!l.has(x.key))continue;let y=x.after,S=y!==""&&!c.has(y)&&!l.has(y)&&c.has(x.before)?x.before:null;S!==null&&(y=g);let w=new Set([x.key]),m=!1;for(;y!==""&&y!==g&&!c.has(y);){if(l.has(y)&&!p){m=!0;break}w.has(y)?y=g:(w.add(y),y=f.get(y)??g)}if(m)continue;l.delete(x.key),k=!0;let b=this.#p(x.key,n,r,i);if(!b||!Ks(b)){d.push(x);continue}let Y=this.#e.nodes.get(x.key);if(Y instanceof G.Map&&we(Y)&&!Po(b))continue;let M=S!==null?a.findIndex(I=>I.key===S):y===""?0:y===g?a.length:a.findIndex(I=>I.key===y)+1;a.splice(M,0,b),c.add(x.key),this.shown.add(x.key),this.shownIn.set(x.key,t)}k||(p=!0)}if(d.length===0)return a;let u=new Map,h=Os(a,d,f,this.#y(n,r,i),u);for(let[p,k]of u)[this.shown,this.rehomed].forEach(x=>x.add(p)),this.shownIn.set(p,k);return h}#y(t,n,o){let r=this.#e.nodes;return{localOf:i=>{let s=r.get(i),a=s instanceof G.Map?s.get(E.shell):void 0,{ns:c,local:f}=typeof a=="object"&&a!==null?a:{};return c===nt&&typeof f=="string"?f:void 0},childrenOf:i=>{let s=r.get(i),a=s instanceof G.Map?s.get(E.children):void 0,c=a instanceof G.Array?a.toArray():[],f=[];if(s instanceof G.Map)for(let l of s.keys())l.startsWith(oe.removedRun)&&f.push(l.slice(oe.removedRun.length));return[...c.filter(l=>typeof l=="string"),...this.#o(i).map(l=>l.key),...f.sort()]},holdsForeign:(i,s)=>this.#n(i,s,0),readParagraph:i=>{let s=r.get(i);if(n.has(i)||!(s instanceof G.Map)||typeof s.get($.movedFrom)=="string")return null;let a=this.#p(i,t,n,o);return a&&Po(a)?a:null}}}#p(t,n,o,r){let i=this.#e.nodes.get(t);if(!(i instanceof G.Map)||i.get(E.part)!==n)return null;let s=i.get(E.text);if(s instanceof G.Text)return o.add(t),{key:t,text:ct(s)};let a=i.get(E.shell),{ns:c,local:f}=typeof a=="object"&&a!==null?a:{};return c!==nt||typeof f!="string"||!zs.has(f)&&f!=="r"&&f!=="t"?null:r(t)}};function js(e,t,n){let o=new Set,r=e.parts,i=e.binaries,s=e.nodes,a=e.doc,c=[a.getMap(mt),a.getMap(St)],f=a.getMap(Tn),l=a.getMap(Ke);for(let[d,g]of t.changed){let u=d;if(u===r||u===i){for(let k of g)k!==null&&o.add(k);continue}if(c.includes(u)){for(let k of g){let x=k===null?void 0:d.get(k);typeof x=="string"&&o.add(x)}continue}if(u===l){for(let k of g){if(k===null)continue;let x=e.doc.getMap(Ke).get(k),y=typeof x=="object"&&x!==null?x.p:void 0,S=e.nodes.get(k),w=typeof y=="string"?y:S instanceof bt.Map?S.get(E.part):void 0;typeof w=="string"&&o.add(w)}continue}if(u===f){for(let k of g){let x=k===null?void 0:e.nodes.get(k.split("\0")[0]),y=x instanceof bt.Map?x.get(E.part):void 0;typeof y=="string"&&o.add(y)}continue}if(u===s){for(let k of g){if(k===null)continue;let x=e.nodes.get(k),y=x instanceof bt.Map?x.get(E.part):void 0;if(typeof y=="string"){o.add(y);continue}let S=n.get(k);S!==void 0&&o.add(S)}continue}let h=u;for(;h instanceof bt.AbstractType&&h.parent!==s;)h=h.parent;let p=h instanceof bt.Map?h.get(E.part):void 0;typeof p=="string"&&o.add(p)}return o}import*as jt from"yjs";import*as Hs from"yjs";import*as rt from"yjs";var Kn=1024;function ba(e,t,n,o,r,i){if(n.length>_n)return null;for(let s of n){if(typeof s!="string"||o.has(s))return null;let a=r.get(s);if(a===void 0&&(a=xt(e.nodes.get(s)),r.set(s,a)),a==="all")return null;if(a)return a.has(t)?null:s;if(Ns(e,s,i))return s}return null}function Ma(e,t){let n=e._map.get(t);return n&&!n.deleted?n:void 0}function Ws(e,t,n,o){for(let r of t.slice(0,_n)){if(typeof r!="string")return!0;let i=o.get(r);if(i===void 0&&(i=xt(e.nodes.get(r)),o.set(r,i)),i==="all"||i?.has(n))return!0}return!1}var Ya=64;function Ra(e,t,n){let o=t.to[0];if(typeof o!="string")return null;let r=e.nodes.get(o),i=r instanceof rt.Map?r.get(E.children):void 0;if(!(i instanceof rt.Array))return null;let s=i.toArray().slice(0,Kn),a=s.indexOf(t.key);if(a<0)return null;let c=l=>l.key!==t.key&&l.clock===t.clock&&l.to.length===t.to.length&&l.to.every((d,g)=>d===t.to[g]),f=new Map(n.filter(c).map(l=>[l.key,l]));if(f.size===0)return null;for(let l=a-1;l>=0;l-=1){let d=f.get(s[l]);if(d)return{with:d,after:!0,at:a}}for(let l=a+1;l<s.length;l+=1){let d=f.get(s[l]);if(d)return{with:d,after:!1,at:a}}return null}function zn(e,t,n,o,r){let i=!1,s=new Set,a=[t];for(let c=0;c<Ya&&a.length>0;c+=1){let f=[];for(let l of a){if(s.has(l))continue;s.add(l);let d=r.get(l);if(d===void 0&&(d=xt(e.nodes.get(l)),r.set(l,d)),d==="all"||d?.has(n))return"seen";d&&(i=!0);for(let g of o().get(l)??[])f.push(g)}a=f.slice(0,Kn)}return i?"unseen":"none"}var Xs="http://schemas.openxmlformats.org/drawingml/2006/main",ot=(e,t)=>!!e&&!("text"in e)&&e.ns===Xs&&e.local===t;function Ia(e,t){let n=e.nodes.get(t),o=n instanceof rt.Map?n.get(E.children):void 0;return o instanceof rt.Array?o.toArray().slice(0,Kn):[]}function un(e,t){let n=typeof t=="string"?e.nodes.get(t):void 0,o=n instanceof rt.Map?n.get(E.shell):void 0;if(typeof o!="object"||o===null)return;let{ns:r,local:i}=o;return r===Xs&&typeof i=="string"?i:void 0}function $s(e,t,n,o){let r=un(e,t),i=r==="p"?1:r==="txBody"?0:-1;if(i<0||un(e,n[i])!=="tc")return;let[s,a,c]=n.slice(i,i+3);if(un(e,a)!=="tr")return;let f=u=>{if(ot(u,"tc"))return r==="txBody"?u.key:(u.children??[]).find(h=>ot(h,"txBody"))?.key},l=o.get(a);if(!o.has(s)&&ot(l,"tr"))for(let u of l.children??[]){let h=f(u);if(h)return h}let d=o.get(c??"");if(l||!ot(d,"tbl"))return;let g=Math.max(0,Ia(e,a).indexOf(s));for(let u of d.children??[]){if(!ot(u,"tr"))continue;let h=(u.children??[]).filter(k=>ot(k,"tc")),p=f(h[Math.min(g,h.length-1)]);if(p)return p}}var dn=(e,t)=>e<t?-1:e>t?1:0,Do=class extends Set{#e;constructor(t){super(),this.#e=t}has(t){return this.#e.has(t)||super.has(t)}};function Vs(e,t,n,o,r,i,s){let a=e.doc.getMap(St);if(a.size===0)return n;let c=new Map,f=new Map,l=new Map,d=new Map,g=(A,T,P)=>{if(c.set(A.key,T),l.set(A.key,l.size),P!==null&&f.set(A.key,P),"text"in A||d.set(A.key,A),!("text"in A))for(let N of A.children??[])g(N,T+1,A.key)};g(n,0,null);let u=[],h=[],p=new Map,k,x=A=>{if(!k){k=new Map;for(let T of a.keys()){if(!f.has(T))continue;let P=e.nodes.get(T),N=P instanceof rt.Map?P.get($.movedFrom):void 0;if(typeof N!="string")continue;let W=k.get(N);(W===void 0||l.get(T)>l.get(W))&&k.set(N,T)}}return k.get(A)};for(let[A,T]of a.entries()){if(T!==t||c.has(A))continue;let P=e.nodes.get(A);if(!(P instanceof rt.Map)||P.get(E.part)!==t||we(P))continue;let N=P.get($.movedFrom),W=P.get($.movedTo);if(typeof N!="string"||!Array.isArray(W))continue;let C=P.get($.movedEarlier),L=c.has(N)?N:(Array.isArray(C)?C.slice(0,Eo):[]).find(X=>typeof X=="string"&&c.has(X)),K=P.get($.movedIndex),D=P.get($.movedClock),O=typeof D=="number"&&Number.isFinite(D)?D:0,j=Ma(P,$.movedTo),B=ba(e,A,W,c,p,j);if(B!==null&&!(s&&zn(e,A,A,s,p)==="seen")){if(u.length+h.length>=Kn)return n;if(L!==void 0){let X=L===N&&kt(K)?K:1/0;u.push({key:A,from:L,index:X,clock:O,to:W})}else h.push({key:A,last:N,removed:B,index:kt(K)?K:1/0,clock:O,to:W})}}let y=new Map,S=h,w=0,m=A=>{if(!s)return[...A];let T=[...A];for(let P=0;P<A.length&&T.length>0;P+=1){let N=[],W=[];for(let C of T){let L=Ra(e,C,u),K=!Ws(e,C.to,C.key,p)&&zn(e,C.key,C.key,s,p)!=="seen"&&zn(e,C.last,C.key,s,p)==="unseen";if(!L||!K){N.push(C);continue}let D=L.after?{after:L.with.key}:{before:L.with.key},{key:O,clock:j,to:B}=C;W.push({key:O,from:L.with.from,index:1/0,clock:j,to:B,...D,seq:L.at})}if(W.length===0)break;W.sort((C,L)=>C.seq-L.seq||dn(C.key,L.key));for(let C of W)u.push({...C,seq:w++});T=N}return T},b,Y=A=>{if(!s||!(!Ws(e,A.to,A.key,p)&&zn(e,A.last,A.key,s,p)!=="seen")||(b??=Fn(e,t),b==="all"||b.has(A.key)))return;let P=$s(e,A.key,A.to,d);if(P)return P;let N=A.to.find(D=>un(e,D)==="tr"),W=A.to.find(D=>un(e,D)==="tbl"),C=typeof W=="string"?d.get(W):void 0;if(typeof N!="string"||!ot(C,"tbl")||C.children?.some(D=>ot(D,"tr")))return;let L=o(N,new Set(c.keys()),c.get(C.key)+1);if(!ot(L??void 0,"tr"))return;let K=D=>({...D,children:D.key===C.key?[...D.children??[],L]:(D.children??[]).map(O=>"text"in O?O:K(O))});return n=K(n),g(n,0,null),r?.add(L.key),P=$s(e,A.key,A.to,d),P};for(;S.length>0;){let A=[],T=[];for(let P of S){let N=y.get(P.removed),W=N?void 0:x(P.removed),C=N?N.into:W===void 0?void 0:f.get(W),L=N?N.key:W;L===void 0||C===void 0?T.push(P):A.push({...P,after:L,into:C})}if(A.length===0){for(let P of m(T).sort((N,W)=>dn(N.key,W.key))){let N=s&&Y(P);N?u.push({key:P.key,from:N,index:1/0,clock:P.clock,to:P.to}):i?.add(P.removed)}break}A.sort((P,N)=>P.clock-N.clock||P.index-N.index||dn(P.key,N.key));for(let P of A)u.push({...P,from:P.into,seq:w++}),y.set(P.last,{key:P.key,into:P.into});S=T}if(u.length===0)return n;let M=new Set(u.map(A=>A.key)),I=new Map(u.map(A=>[A.key,A.to.filter(T=>typeof T=="string"&&M.has(T)).length]));u.sort((A,T)=>I.get(A.key)-I.get(T.key)||dn(A.key,T.key));let v=new Do(new Set(c.keys())),R=new Map;for(let A of u){let T=o(A.key,v,c.get(A.from)+1);if(!T)continue;r?.add(T.key);let P={node:T,index:A.index,clock:A.clock,after:A.after,before:A.before,seq:A.seq??0},N=R.get(A.from);N?N.push(P):R.set(A.from,[P])}if(R.size===0)return n;let F=A=>{let T=R.get(A.key),P=(A.children??[]).map(D=>"text"in D?D:F(D));if(!T)return{...A,children:P};let N=[...P],W=T.filter(D=>D.after===void 0&&D.before===void 0).sort((D,O)=>O.clock-D.clock||D.index-O.index||dn(D.node.key,O.node.key));for(let{node:D,index:O}of W)N.splice(Math.min(O,N.length),0,D);let C=T.filter(D=>D.after!==void 0||D.before!==void 0).sort((D,O)=>D.seq-O.seq),L=new Map;for(let{node:D,after:O,before:j}of C){if(O===void 0){let q=N.findIndex(le=>le.key===j);N.splice(q<0?N.length:q,0,D);continue}let B=L.get(O)??O,X=N.findIndex(q=>q.key===B);N.splice(X<0?N.length:X+1,0,D),L.set(O,D.key)}let K={ns:A.ns,local:A.local};return{...A,children:[...ht(K,N,D=>"text"in D?void 0:D)]}};return F(n)}function pn(e){let t=new Set,n=[e];for(;n.length>0;){let o=n.pop();if(t.add(o.key),!("text"in o))for(let r of o.children??[])n.push(r)}return t}var Bs=(e,t)=>e.size===t.size&&[...e].every(n=>t.has(n));function Gs(e,t){return Bs(e.lost,t.lost)&&Bs(e.unseenWinners,t.unseenWinners)}var Ea="http://schemas.openxmlformats.org/drawingml/2006/main";function gn(e){let t=new Map;if(!e)return t;let n=[e];for(;n.length>0;){let o=n.pop();if(t.set(o.id,o),o.type==="element")for(let r of o.children)n.push(r)}return t}function va(e,t){let n=e.length,o=t.length,r=new Uint32Array((n+1)*(o+1));for(let f=n-1;f>=0;f--)for(let l=o-1;l>=0;l--)r[f*(o+1)+l]=e[f]===t[l]?r[(f+1)*(o+1)+l+1]+1:Math.max(r[(f+1)*(o+1)+l],r[f*(o+1)+l+1]);let i=new Set,s=new Set,a=0,c=0;for(;a<n&&c<o;)e[a]===t[c]?(i.add(a++),s.add(c++)):r[(a+1)*(o+1)+c]>=r[a*(o+1)+c+1]?a++:c++;return{keepA:i,keepB:s}}function Co(e,t){let n=e.toArray();if(n.length===t.length&&n.every((s,a)=>s===t[a]))return;if(n.length*t.length>25e4){e.delete(0,n.length),e.insert(0,[...t]);return}let{keepA:o,keepB:r}=va(n,t);for(let s=n.length-1;s>=0;s--)o.has(s)||e.delete(s,1);let i=0;t.forEach((s,a)=>{r.has(a)||e.insert(i,[s]),i+=1})}function qs(e,t){if(e.size===0)return e;let n=pn(t);return new Map([...e].filter(([o])=>n.has(o)))}function Us(e){let t=new Map;if(e?.kind!=="xml")return t;let n=[[e.xml.root,""]];for(;n.length>0;){let[o,r]=n.pop();if(t.set(o.id,r),o.type==="element")for(let i of o.children)n.push([i,`${o.id}/${r}`])}return t}function Js(e,t,n){let o,r;return i=>{let s=e?.get(i);if(s===void 0)return!1;o??=Us(t),r??=Us(n);let a=o.get(s);return a!==void 0&&a===r.get(s)}}function Qs(e,t,n){let o;return r=>{let i=e?.get(r);if(i===void 0||n?.kind!=="xml")return;if(!o){let a=new Map,c=[n.xml.root];for(;c.length>0;){let f=c.pop();if(f.type==="element")for(let l of f.children)a.set(l.id,f.id),c.push(l)}o=a}let s=o.get(i);return s===void 0?void 0:t?.get(s)}}function Zs(e,t,n,o=!1){let r=ct(e);if(r===t)return;if(o&&!n&&br(e,r,t))return{created:n,deleted:[]};let i=0;for(;i<r.length&&i<t.length&&r[i]===t[i];)i++;let s=0;for(;s<r.length-i&&s<t.length-i&&r[r.length-1-s]===t[t.length-1-s];)s++;let a=h=>h>=55296&&h<=56319,c=h=>h>=56320&&h<=57343;i>0&&a(r.charCodeAt(i-1))&&i--,s>0&&c(r.charCodeAt(r.length-s))&&s--;let f=r.length-i-s,l=t.length-i-s;if(f===l&&!/[\uD800-\uDFFF]/.test(r.slice(i,i+f)+t.slice(i,i+l))){let h=Ce(e,i,f),p=[];for(let k=i;k<i+f;k++){if(r[k]===t[k])continue;let x=h[k-i];x&&p.push(x),e.insert(k,t[k]),e.delete(k+1,1)}return{created:n,deleted:p}}let d=f>0?Ce(e,i,f):[];f>0&&e.delete(i,f);let g=e.doc,u=g?Hs.getState(g.store,g.clientID):0;return l>0&&e.insert(i,t.slice(i,t.length-s)),{created:n,deleted:d,...l>0&&g?{inserted:{client:g.clientID,clock:u,length:l}}:{}}}function ei(e,t){let n=new Map,o=new Set;if(t.size===0)return{inParent:n,watch:o};let r=new Map,i=[e];for(;i.length>0;){let s=i.pop();for(let a of s.children??[])"text"in a||(r.set(a.key,s.key),t.has(a.key)&&a.ns===Ea&&Oa.has(a.local)&&n.set(a.key,s.key),i.push(a))}for(let s of n.values()){o.add(s);let a=r.get(s);a!==void 0&&o.add(a)}return{inParent:n,watch:o}}var Oa=new Set(["r","br","fld"]);function ti(e,t,n,o){let r=new Set(n),i=new Set(t),s=t.filter(u=>r.has(u)),a=n.filter(u=>i.has(u)),c=(u,h)=>u.length===h.length&&u.every((p,k)=>p===h[k]);if(c(s,a)||!c(ht(e,s,o),a))return n;let f=new Map,l=[],d;for(let u=n.length-1;u>=0;u--){let h=n[u];if(i.has(h))d=h;else if(d===void 0)l.unshift(h);else{let p=f.get(d);p||f.set(d,p=[]),p.unshift(h)}}let g=[];for(let u of s){for(let h of f.get(u)??[])g.push(h);g.push(u)}for(let u of l)g.push(u);return g}var Pa="http://schemas.openxmlformats.org/drawingml/2006/main",Aa=65536;function ni(e,t,n,o){let r=new Map,i=Aa;if(e.doc.store.pendingStructs&&n?.kind==="xml")for(let s of gn(n.xml.root).values()){if(--i<0)return new Map;if(s.type!=="element"||!(At(s)||s.ns===Pa&&s.local==="p"))continue;let a=o?.get(s.id);a&&r.set(a,s.children.flatMap(c=>{let f=o?.get(c.id);return f?[f]:[]}))}if(e.doc.store.pendingStructs)for(let[s,a]of e.doc.getMap(St)){if(--i<0)return new Map;if(a!==t)continue;let c=e.nodes.get(s);if(!(c instanceof jt.Map)||c.get(E.part)!==t||we(c))continue;let f=c.get($.movedTo),l=c.get($.movedIndex);if(!Array.isArray(f)||typeof f[0]!="string"||!Number.isSafeInteger(l)||l<0)continue;let d=e.nodes.get(f[0]),g=d instanceof jt.Map?d.get(E.children):void 0;if(!(d instanceof jt.Map)||!(g instanceof jt.Array)||d.get(E.part)!==t)continue;if(i-=g.length,i<0)return new Map;let u=r.get(f[0])??g.toArray();u.includes(s)||u.splice(Math.min(l,u.length),0,s),r.set(f[0],u)}return r}import{buildReplicaPart as Wa}from"@pptx-editor.dev/core/store";import*as ft from"yjs";import{children as To,elements as Wt,isStructureEdited as Da,path as oi,TABLE_MAX_COLUMNS as Ca,TABLE_MAX_ROWS as Ta,tableGridOf as Na}from"@pptx-editor.dev/core/store";var jn=Object.freeze({holder:"mh",cover:"cv."}),Lo="http://schemas.openxmlformats.org/drawingml/2006/main",_a="http://schemas.openxmlformats.org/presentationml/2006/main",Wn=256,Fo=4096,hn=e=>e?.type==="element",mn=(e,t)=>!!e&&!("text"in e)&&e.ns===Lo&&e.local===t;function ri(e,t){if(!mn(t,"p")||No(t))return!1;let n=e.nodes.get(t.key);return n instanceof ft.Map&&n.get(jn.holder)===!0}function La(e){return(Wt(e).find(n=>n.local==="t")?.children??[]).map(n=>n.type==="text"?n.value:"").join("")}function Fa(e){return Wt(e).some(t=>t.local==="br"||(t.local==="r"||t.local==="fld")&&La(t).length>0)}function No(e){return"text"in e?!1:(e.children??[]).some(t=>{if("text"in t||!(t.local==="br"||t.local==="r"||t.local==="fld"))return!1;if(t.local==="br")return!0;let n=t.children?.find(o=>!("text"in o)&&o.local==="t");return!!n&&!("text"in n)&&(n.children??[]).some(o=>"text"in o&&o.text!=="")})}function si(e,t){let n=[],o=(r,i)=>{if(r.ns===_a&&r.local==="graphicFrame"){n.push(r);return}if(i<Wn)for(let s of t(r))o(s,i+1)};return o(e,0),n}function ii(e){let t=oi(e,"a:graphic","a:graphicData","a:tbl"),n=Math.min(To(oi(t,"a:tblGrid"),"a:gridCol").length,Ca),o=To(t,"a:tr").slice(0,Ta).map(s=>To(s,"a:tc"));if(n===0||o.length===0)return[];let r=Na(e,o,n),i=[];return o.forEach((s,a)=>s.slice(0,n).forEach((c,f)=>{let l=r.blocks[r.owner[a*n+f]],d=l&&o[l.row][l.col];d&&(l.row!==a||l.col!==f)&&i.push({tc:c,over:d})})),i}var _o=e=>Wt(e).filter(t=>t.ns===Lo&&t.local==="txBody");function ci(e){let t=new Map;if(!(e instanceof ft.Map))return t;for(let[n,o]of e.entries()){if(!n.startsWith(jn.cover)||!Array.isArray(o))continue;if(o.length>Fo)return"all";let r=e._map.get(n);if(r)for(let i of o)typeof i=="string"&&t.set(i,[...t.get(i)??[],r.id])}return t}function ai(e,t){let n=e.get(E.children);if(!(n instanceof ft.Array))return!0;let o=0;for(let r of Gt(n)){if((o+=1)>Fo)break;if(!t.some(s=>s.client===r.id.client&&s.clock>r.id.clock))return!1}return!0}function li(e,t,n,o){if(n.size===0)return;let r=l=>{let d=o.get(l),g=d===void 0?void 0:e.nodes.get(d);return g instanceof ft.Map?g:void 0},i=new Set,s=[],a=(l,d)=>{let g=n.get(l.id);if(g!==l){for(let u of l.children)i.add(u.id);if(l.ns===Lo&&l.local==="txBody"&&hn(g)){let u=new Set(l.children.map(p=>p.id)),h=g.children.filter(p=>hn(p)&&p.local==="p");h.length>0&&h.every(p=>!u.has(p.id))&&s.push({body:l,old:g})}if(d<Wn)for(let u of l.children)hn(u)&&a(u,d+1)}};a(t,0);for(let{body:l,old:d}of s)if(d.children.filter(u=>hn(u)&&u.local==="p").every(u=>i.has(u.id)))for(let u of l.children)hn(u)&&u.local==="p"&&!n.has(u.id)&&!Fa(u)&&r(u.id)?.set(jn.holder,!0);let c=`${jn.cover}${e.doc.clientID.toString(36)}`,f=l=>Wt(l).filter(d=>n.get(d.id)!==d);for(let l of si(t,f))for(let{tc:d}of ii(l)){let g=r(d.id),u=_o(d);if(!g||u.length===0)continue;let h=ci(g);if(h==="all")continue;let p=u.flatMap(y=>Wt(y).filter(S=>S.local==="p")).map(y=>o.get(y.id)).filter(y=>{if(y===void 0)return!1;let S=h.get(y),w=e.nodes.get(y);return!S||!(w instanceof ft.Map)||!ai(w,S)});if(p.length===0)continue;let k=g.get(c),x=Array.isArray(k)?k.filter(y=>typeof y=="string"):[];g.set(c,[...new Set([...x,...p])].slice(0,Fo+1))}}function fi(e,t){let n=new Map(e);return n.delete(t),n}function di(e,t,n){let o=[];if(!t||t.size===0)return o;let r=(i,s)=>{let a=n.get(i.id);if(a!==void 0&&t.has(a)&&o.push(i),s<Wn)for(let c of Wt(i))r(c,s+1)};return r(e,0),o}function ui(e,t){t.set(e.key,e);let n=(e.children??[]).map(o=>"text"in o?{type:"text",id:o.key,value:o.text}:ui(o,t));return{type:"element",id:e.key,kind:"generic",ns:e.ns,local:e.local,...e.prefix?{prefix:e.prefix}:{},nsDecls:[],attrs:e.attrs??[],children:n}}function za(e,t,n,o,r,i,s,a){let c=new Map,f=ui(n,c),l=Da(f),d=new Map;for(let{tc:g,over:u}of ii(f)){let h=_o(u)[0],p=h&&c.get(h.id)||d.get(u.id),k=ci(e.nodes.get(g.id)),x=Y=>{if(k==="all")return!1;let M=e.nodes.get(Y);if(!(M instanceof ft.Map))return!1;let I=k.get(Y);return I&&ai(M,I)?!1:l?!0:typeof M.get($.movedFrom)=="string"||we(M)},y=_o(g).flatMap(Y=>{let M=c.get(Y.id);if(!M)return[];let I=M.children??[],v=I.filter(R=>mn(R,"p")&&(t.has(R.key)||No(R)&&x(R.key)));return[{from:M,kids:I,going:v,paragraphs:I.filter(R=>mn(R,"p")).length}]}),S=c.get(g.id),w=c.get(u.id),m;if(!p){if(m=y.find(Y=>Y.going.length>0&&Y.kids.every(M=>!mn(M,"p")||Y.going.includes(M)||!No(M)))?.from,!m||!S||!w)continue;p=m,d.set(u.id,m),s.set(w.key,m),a?.add(S.key).add(w.key)}let b=new Set(y.filter(Y=>Y.going.length===Y.paragraphs&&Y.from!==m).map(Y=>Y.from));for(let Y of b)i.add(Y.key);S&&(b.size>0||m)&&r.set(S.key,(S.children??[]).filter(Y=>Y!==m&&!b.has(Y)));for(let{from:Y,kids:M,going:I}of y){if(I.length===0||Y===m)continue;let v=new Set(I);r.set(Y.key,M.filter(F=>!v.has(F)));let R=o.get(p.key);if(R)for(let F of I)R.push(F);else o.set(p.key,I)}}}function pi(e,t,n,o,r=new Set){let i=new Map,s=new Map,a=si(t,l=>(l.children??[]).filter(d=>!("text"in d))),c=new Map;for(let l of a)za(e,n,l,i,s,r,c,o);let f=(l,d)=>{let g=s.get(l.key)??l.children??[],u=i.get(l.key);u&&(g=[...g,...u]);let h=c.get(l.key);if(h&&(g=[h,...g]),l.local==="txBody"){let x=g.filter(S=>mn(S,"p")),y=x.some(S=>!ri(e,S))?void 0:x.at(-1);g=g.filter(S=>!ri(e,S)||S===y?!0:(r.add(S.key),!1))}let p=d<Wn?g.map(x=>"text"in x?x:f(x,d+1)):g,k=p.length===(l.children??[]).length&&p.every((x,y)=>x===l.children[y]);return!k&&l.local==="txBody"&&o?.add(l.key),k?l:{...l,children:p}};return f(t,0)}import*as Ie from"yjs";var gi=1024,$n=1024,hi=1<<20,Ko="http://schemas.openxmlformats.org/drawingml/2006/main",mi=()=>({left:hi,fields:new WeakMap,runs:new Map,paragraphs:new Map,seen:new Map,placed:new Map});function yn(e,t,n){let o=t.fields.get(e);if(o)return o;let r=!1,i=0,s=new Map,a=[];for(let[f,l]of e.entries())i+=1,cn(f)?(r=!0,a.push(f)):f.startsWith(oe.removedRun)&&typeof l=="string"&&s.set(f.slice(oe.removedRun.length),l);n&&dt(t,i);let c={removed:r,places:s,removedRuns:[...s.keys()].sort().slice(0,$n),removals:a.sort().slice(0,Nn)};return t.fields.set(e,c),c}var dt=(e,t=1)=>(e.left-=t)>=0;function zo(e){let t=e.get(E.children);if(!(t instanceof Ie.Array))return[];let n=new Set;for(let o of t.slice(0,gi))typeof o=="string"&&n.add(o);return[...n]}function yi(e,t,n,o){let r=o.runs.get(t);if(r!==void 0)return r;let i=zo(n).some(s=>{if(!dt(o))return!1;let a=e.nodes.get(s);if(!(a instanceof Ie.Map))return!1;let c=a.get(E.shell);return c?.ns!==Ko||c.local!=="t"?!1:zo(a).some(f=>{if(!dt(o))return!1;let l=e.nodes.get(f),d=l instanceof Ie.Map?l.get(E.text):void 0;return d instanceof Ie.Text&&d.length>0})});return o.runs.set(t,i),i}var ki=e=>(e.children??[]).some(t=>!("text"in t)&&t.local==="t"&&(t.children??[]).some(n=>"text"in n&&n.text.length>0));function wi(e,t,n){let o=n.seen.get(e);if(o)return o;let r=new Set,i=yn(t,n,!0);for(let s of i.removals){let a=t.get(s);if(!(!Array.isArray(a)||a.length>yt||!dt(n,a.length)))for(let c of a)typeof c=="string"&&r.add(c)}for(let s of i.removedRuns)r.add(s);return n.seen.set(e,r),r}function jo(e){let t,n=new Map,o=()=>{let r=new Map;for(let[i,s]of e.nodes.entries()){if(!(s instanceof Ie.Map))continue;let a=s.get(E.part),c=s.get(E.children);if(typeof a!="string"||!(c instanceof Ie.Array))continue;let f=r.get(a);f||r.set(a,f=new Map);for(let l of c.toArray()){if(typeof l!="string")continue;let d=f.get(l);d?d.push(i):f.set(l,[i])}}return r};return r=>()=>(t??=o()).get(r)??n}var Wo=(e,t)=>({rescued:new Set,stranded:e,listings:t,walk:mi()});function Si(e,t,n,o,r){return t.get($.movedFrom)!==o?!1:(r().get(n)??[]).some(i=>{let s=e.nodes.get(i);return i!==o&&!(s instanceof Ie.Map&&we(s))})}function xi(e,t,n,o,r,i){let s=t.get(E.shell);if(s?.ns!==Ko||Si(e,t,n,o,i.listings))return null;let a=t.get($.movedFrom),c=t.get($.splitFrom);return(typeof c=="string"&&(i.listings().get(c)??[]).some(d=>{let g=e.nodes.get(d);return d!==o&&g instanceof Ie.Map&&!we(g)})||typeof a=="string"&&!i.stranded)&&!r().has(n)?null:s.local==="br"?r().has(n)?null:"br":s.local==="r"||s.local==="fld"?"run":null}function bi(e,t,n,o){let r=n.get(E.key),i=()=>wi(t.key,n,o.walk);for(let s of(t.children??[]).slice(0,gi)){if("text"in s)continue;if(!dt(o.walk))return!1;let a=e.nodes.get(s.key),c=a instanceof Ie.Map?xi(e,a,s.key,r,i,o):null;if(c==="br"||c==="run"&&ki(s))return!0}return!1}function Ka(e,t,n,o){let r=o.walk.paragraphs.get(t);if(r!==void 0)return r;let i=n.get(E.key),s=new Set(yn(n,o.walk,!0).removedRuns),a=()=>wi(t,n,o.walk),c=[...new Set([...zo(n),...s])].some(f=>{if(!dt(o.walk))return!1;let l=e.nodes.get(f);if(!(l instanceof Ie.Map))return!1;let d=xi(e,l,f,i,a,o);if(d==="br")return!0;let g=s.has(f)&&!yn(l,o.walk,!0).removed;return d==="run"&&!g&&yi(e,f,l,o.walk)});return o.walk.paragraphs.set(t,c),c}function ja(e,t){let n=0,o=[e];for(;o.length>0&&n<t;){let r=o.pop();if(n+=1,!("text"in r))for(let i of r.children??[])o.push(i)}return n}function Mi(e,t,n,o,r,i=Wo(new Set,jo(e)(t)),s=()=>!1,a=()=>{}){let c=i.walk,f=yn(n,c,!1).places;if(f.size===0)return o;let l=new Set(o.map(M=>M.key)),d=n.get(E.key),g=n.get(E.shell)?.local==="txBody",u=g?"p":"r",h=g?["bodyPr","lstStyle"]:["pPr"],p=new Map,k=M=>{let I=r(M);return I&&dt(c,ja(I,hi))?I:null},x=(M,I)=>{a(I),p.set(M,I),c.placed.set(M,String(d))};for(let M of[...f.keys()].sort()){if(p.size>=$n||!dt(c))break;let I=c.placed.get(M);if(l.has(M)||I!==void 0&&I!==String(d))continue;let v=e.nodes.get(M);if(!(v instanceof Ie.Map)||v.get(E.part)!==t)continue;let R=v.get(E.shell);if(R?.ns!==Ko||R.local!==u||!yn(v,c,!0).removed||Si(e,v,M,d,i.listings))continue;if(g){let T={stranded:i.stranded.has(M),listings:i.listings,walk:c};if(!Ka(e,M,v,T)&&!s(M))continue;let P=k(M);if(!P||!bi(e,P,v,T))continue;x(M,P),i.rescued.add(M);continue}let F=yi(e,M,v,c),A=k(M);A&&(F||ki(A))&&x(M,A)}if(p.size===0)return o;let y=M=>{let I=f.get(M)??"";for(let v=0;v<$n&&I!==""&&!l.has(I)&&!p.has(I);v+=1)I=f.get(I)??"";return l.has(I)||p.has(I)?I:""},S=new Map;for(let[M,I]of p){let v=y(M),R=S.get(v);R?R.push(I):S.set(v,[I])}let w=[],m=new Set,b=(M,I)=>{if(!(I>$n))for(let v of S.get(M)??[])m.has(v.key)||(m.add(v.key),w.push(v),b(v.key,I+1))},Y=!1;for(let M of o)!Y&&("text"in M||!h.includes(M.local))&&(Y=!0,b("",0)),w.push(M),b(M.key,0);Y||b("",0);for(let M of p.values())m.has(M.key)||w.push(M);return w}function Yi(e,t,n){if(n.rescued.size===0)return t;let o=mi(),r=s=>{if("text"in s||!n.rescued.has(s.key))return!0;let a=e.nodes.get(s.key),c={stranded:n.stranded.has(s.key),listings:n.listings,walk:o};return a instanceof Ie.Map&&bi(e,s,a,c)},i=s=>{let a=s.children??[];if(!a.some(c=>!r(c))){let c=a.map(f=>"text"in f?f:i(f));return c.every((f,l)=>f===a[l])?s:{...s,children:c}}return{...s,children:a.filter(r).map(c=>"text"in c?c:i(c))}};return i(t)}var Ri="http://schemas.openxmlformats.org/drawingml/2006/main",$o=1<<20,Ii=(e,t)=>e.attrs.find(n=>n.ns===""&&n.local===t)?.value,$a=e=>({ns:e.ns,local:e.local,...e.prefix?{prefix:e.prefix}:{},nsDecls:e.nsDecls.map(t=>({prefix:t.prefix,uri:t.uri}))}),Bn=class{#e;#t=new Map;#r=new Map;#f=new Map;#a=new Set;#d=new Map;#n=new Map;#u=new Map;#o=new Map;#y=new Set;#p=new Set;#g=new Set;#h=new Map;#m=new Map;#k=rn;#s=null;#S;#Y=new Map;#x=new Map;#R;#i=new Set;#l=new Map;constructor(t,n={value:0}){this.#e=t,this.#R=n;let o=`${t.doc.clientID.toString(36)}.`;for(let r of t.nodes.keys()){if(!r.startsWith(o))continue;let i=Number.parseInt(r.slice(o.length).replace(Cn,""),36);Number.isSafeInteger(i)&&i<=lr&&i>n.value&&(n.value=i)}}get seeded(){return this.#e.parts.size>0}#P(t,n){for(let o of this.#f.get(t)??[])this.#r.delete(o);for(let[o,r]of n)this.#r.set(o,r);this.#f.set(t,new Set(n.keys())),this.#a.clear(),this.#Y.clear();for(let[o,r]of this.#r)for(let i of r.companions)this.#a.add(i),this.#Y.set(i,o)}#I(t,n){for(let o of this.#t.get(t)?.idOf.keys()??[])this.#x.delete(o);if(!n){this.#t.delete(t);return}this.#t.set(t,n);for(let o of n.idOf.keys())this.#x.set(o,t)}#T(t){let n=this.#t.get(t);return n||(n={keyOf:new Map,idOf:new Map},this.#t.set(t,n)),n}#b=!1;#N(){let t=this.#e.doc.clientID.toString(36),n=this.#b?Cn:"",o;do this.#R.value+=1,o=`${t}.${n}${this.#R.value.toString(36)}`;while(this.#e.nodes.has(o));return o}seed(t){this.#b=!0;try{for(let n of t.parts.values())this.#A(n,void 0)}finally{this.#b=!1}}hasHiddenListings(t){return t.some(n=>this.#h.has(n))}dropHiddenListings(t,n,o){for(let r of t){let i=this.#h.get(r);if(!i)continue;let s=Js(this.#t.get(r)?.idOf,n.parts.get(r),o.parts.get(r)),a=this.#t.get(r),c=Qs(a?.idOf,a?.keyOf,n.parts.get(r));this.#h.delete(r);for(let[f,l]of i){let d=this.#v(f);if(!d||d.length!==l.length)continue;let g=[...l.at.keys()].sort((h,p)=>p-h);if(g.some(h=>d.get(h)!==l.at.get(h)))continue;let u=g.filter(h=>s(l.at.get(h)));u.length>0&&_s(this.#e,r,f,d.toArray(),u,c);for(let h=0;h<g.length;){let p=h+1;for(;p<g.length&&g[p]===g[p-1]-1;)p++;d.delete(g[p-1],p-h),h=p}}}}writeChange(t,n,o,r=!1){for(let i of o){this.#y.delete(i),this.#p.delete(i);let s=n.parts.get(i);if(!s){this.#e.parts.delete(i),this.#e.binaries.delete(i),this.#I(i,void 0);continue}this.#A(s,t.parts.get(i),r)}}#A(t,n,o=!1){if(t.kind==="binary"){(n?.kind!=="binary"||n.bytes!==t.bytes)&&this.#e.binaries.set(t.partName,t.bytes),et(this.#e.parts.get(t.partName))?.kind!=="binary"&&this.#e.parts.set(t.partName,{kind:"binary"});return}n?.kind==="binary"&&this.#e.binaries.delete(t.partName);let r={partName:t.partName,caseChange:o,ids:this.#T(t.partName),before:gn(n?.kind==="xml"?n.xml.root:void 0),texts:new Map,materialize:new Set,force:new Set},i=gn(t.xml.root),s=this.#o.get(t.partName)?.inParent,a=new Set;for(let[d]of r.before){if(i.has(d))continue;let g=r.ids.keyOf.get(d);g&&a.add(g);let u=g?this.#v(g):void 0;if(u)for(let h of u.toArray())s?.has(h)&&r.materialize.add(h)}for(let[d,g]of this.#e.doc.getMap(Ke)){let u=g;typeof u?.s=="string"&&a.has(u.s)&&r.materialize.add(d)}if(r.materialize.size>0){let d=g=>{let u=g.type==="element"?g.children.map(d).some(Boolean):!1,h=r.ids.keyOf.get(g.id),p=u||h!==void 0&&r.materialize.has(h);return p&&r.force.add(g.id),p};d(t.xml.root)}let c=this.#E(t.xml.root,r),f=this.#n.get(t.partName);this.#n.delete(t.partName);for(let d of di(t.xml.root,f,r.ids.keyOf))this.#E(d,{...r,before:fi(r.before,d.id)});gs(this.#e,t.partName,t.xml.root,r.before,r.ids.keyOf),li(this.#e,t.xml.root,r.before,r.ids.keyOf),this.#_(t.partName,t.xml.root,r);let l=et(this.#e.parts.get(t.partName));(l?.kind!=="xml"||l.root!==c)&&this.#e.parts.set(t.partName,{kind:"xml",root:c})}#_(t,n,o){if(this.#b)return;let r=zr(this.#e,t,n,o.before,o.ids.keyOf,o.texts),i=Kr(this.#e,n,o.before,o.ids.keyOf),s=this.#e.doc,a=new Map,c,f=new Set,l=d=>{if(this.#i.size>=$o||r.has(z(d.client,d.clock)))return;let g=Ue(s,d,a);c??=this.#D(),this.#i.add(z(g.client,g.clock)),this.#l.set(z(g.client,g.clock),c);let u=U(s,d);f.add(z(u.client,u.clock)),this.#i.add(z(u.client,u.clock)),this.#l.set(z(u.client,u.clock),c)};for(let d of o.texts.values())for(let g of d.deleted)l(g);for(let d of i)l(d);Rs(this.#e,t,f)}#D(){let t=this.#e.doc,n=te.getState(t.store,t.clientID);return t.getMap(Tr).set(String(t.clientID),n),n}get deletedAt(){return this.#l}noteRejected(t,n){if(this.#i.size>=$o)return;this.#i.add(t);let o=this.#l.get(n);o!==void 0&&this.#l.set(t,o)}get deletedText(){return this.#i}showingUnlisted(t){return t.filter(n=>this.#p.has(n)||(this.#u.get(n)?.size??0)>0||this.#y.has(n))}noteStep(t,n){for(let r of t)this.#i.delete(r),this.#l.delete(r);let o;for(let r of n)this.#i.size<$o&&(o??=this.#D(),this.#i.add(r),this.#l.set(r,o))}newCopies(t,n=!0){return jr(this.#e,t,n)}#E(t,n){let{partName:o,ids:r,before:i}=n,s=r.keyOf.get(t.id),a=s===void 0?void 0:this.#e.nodes.get(s);if(s!==void 0&&a instanceof te.Map&&i.get(t.id)===t&&!n.force.has(t.id))return s;t.type==="element"&&(t.ns===Ri||At(t))&&this.#p.add(o),s!==void 0&&this.#o.get(o)?.watch.has(s)&&this.#y.add(o);let c=s===void 0||!(a instanceof te.Map);if(s===void 0||!(a instanceof te.Map)){s=this.#N();let R=new te.Map;this.#e.nodes.set(s,R),R.set(E.part,o),R.set(E.key,s),t.type==="text"?R.set(E.text,new te.Text):(R.set(E.attrs,new te.Map),R.set(E.children,new te.Array)),a=R,r.keyOf.set(t.id,s),r.idOf.set(s,t.id),this.#x.set(s,o)}let f=a;if(t.type==="text"){let R=f.get(E.text),F=R instanceof te.Text?Zs(R,t.value,c,n.caseChange):void 0;return F&&n.texts.set(s,F),s}let l=$a(t);JSON.stringify(f.get(E.shell))!==JSON.stringify(l)&&f.set(E.shell,l);let d=this.#r.get(s),g=this.#e.doc.clientID.toString(36),u=d?.merge?[s,...d.companions].find(R=>Te(R)===g)??s:s,h=f.get(E.attrs);if(h instanceof te.Map){let R=new Map;for(let A of t.attrs)R.set(`${A.ns}${xn}${A.local}`,{ns:A.ns,local:A.local,value:A.value,...A.prefix?{prefix:A.prefix}:{}});let F=d?.merge?d.companions.map(A=>this.#M(A)):[];for(let A of[...h.keys()])R.has(A)||h.delete(A);for(let A of F)for(let T of[...A?.keys()??[]])R.has(T)||A.delete(T);for(let[A,T]of R){let P=d?.attrFrom.get(A)??(h.has(A)?s:void 0),N=P===void 0?void 0:this.#M(P);if(N&&JSON.stringify(N.get(A))===JSON.stringify(T))continue;if((this.#M(u)??h).set(A,T),d?.merge)for(let C of[s,...d.companions])C!==u&&this.#M(C)?.delete(A)}}let p=t.children.map(R=>this.#E(R,n)),k=new Set(p),x=f.get(E.children),y=(R,F)=>{let A=[],T=new Set,P=N=>{T.has(N)||(T.add(N),A.push(N))};for(let N of R){P(N);for(let W of this.#r.get(N)?.companions??[])F.has(W)&&P(W)}return A},S=new Set(x instanceof te.Array?x.toArray():[]),w=this.#u.get(o),m=this.#o.get(o)?.inParent,b={has:R=>!n.materialize.has(R)&&(w?.get(R)===s||m?.get(R)===s)},Y=d?p.filter(R=>!d.childFrom.has(R)&&!S.has(R)&&!b?.has(R)):[],M=(d?p.filter(R=>!d.childFrom.has(R)&&(S.has(R)||u===s)):p).filter(R=>!b?.has(R)||S.has(R));if(x instanceof te.Array){let R=x,F=R.toArray();Co(R,vo(F,ti(t,F,y(M,new Set(F)),A=>this.#L(A)),this.#d.get(o)))}let I=new Set;if(d?.merge)for(let R of t.children)R.type==="element"&&I.add(_t(t,R,F=>Ii(R,F))?.slot);let v=new Set(Y);d?.merge&&t.children.forEach((R,F)=>{R.type==="element"&&v.has(p[F])&&I.delete(_t(t,R,A=>Ii(R,A))?.slot)});for(let R of d?.merge?d.companions:[]){let F=this.#v(R);if(!F)continue;let A=F.toArray(),T=A.filter(P=>{if(this.#a.has(P))return k.has(this.#Y.get(P));if(d.childFrom.get(P)===R)return k.has(P);let N=d.shadowed.get(P);return N!==void 0&&I.has(N)});Co(F,y([...T,...R===u?Y:[]],new Set(A)))}return s}#L(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(E.shell):void 0;if(typeof o!="object"||o===null)return;let{ns:r,local:i}=o;return typeof r=="string"&&typeof i=="string"?{ns:r,local:i}:void 0}#M(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(E.attrs):void 0;return o instanceof te.Map?o:void 0}#v(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(E.children):void 0;return o instanceof te.Array?o:void 0}keyOf(t,n){return this.#t.get(t)?.keyOf.get(n)}idOf(t,n){return this.#t.get(t)?.idOf.get(n)}textOf(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(E.text):void 0;return o instanceof te.Text?o:void 0}locateCharacter(t,n){return $r(this.#e.doc,n,this.#t.get(t)?.idOf??[],o=>this.textOf(o))}partOf(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(E.part):void 0;return typeof o=="string"?o:void 0}recordOfText(t){let n=t.parent,o=n instanceof te.Map?n.get(E.key):void 0;if(typeof o!="string"||this.#e.nodes.get(o)!==n)return;let r=n.get(E.part);return typeof r=="string"?{key:o,part:r}:void 0}touchedParts(t){return js(this.#e,t,this.#x)}allParts(t){let n=new Set(this.#e.parts.keys());for(let o of t.parts.keys())n.add(o);return n}rebuild(t,n,o=!1){let r=[],i=[],s=new Map,a=new Map,c=new Map,f=new Map,l=new Map,d=[...t];for(let p of d)[this.#h,this.#n].forEach(k=>k.delete(p));let g=new Map,u=new Map,h=jo(this.#e);for(let p of d){let k=et(this.#e.parts.get(p));if(!k){if(this.#e.parts.has(p))return{ok:!1,reason:`invalid part entry ${p}`};n.parts.has(p)&&i.push(p);continue}if(k.kind==="binary"){let L=this.#e.binaries.get(p);if(!(L instanceof Uint8Array)||L.length>Xt.maxBinaryBytes)return{ok:!1,reason:`invalid binary part ${p}`};r.push({kind:"binary",partName:p,bytes:L});continue}this.#C=ni(this.#e,p,n.parts.get(p),this.#t.get(p)?.keyOf),this.#O=new Map;let x=new Map;this.#g=new Set,this.#c=void 0,this.#k=an(this.#e,p,k.root),this.#m=new Map,this.#s=fn.of(this.#e,p,k.root);let y=(L,K,D)=>this.#w(L,p,K,D,x),[S,w]=[new Set,new Set],m=new Map,b=h(p),Y=(L=new Set)=>{[S,w]=[new Set,new Set],this.#S=Wo(L,b);let K=this.#w(k.root,p,new Set,0,x);K&&this.#s&&(K=this.#s.withStranded(K,y));let D=K&&Vs(this.#e,p,K,y,S,w,b);return m.clear(),D&&Gr(this.#e,D,y,m,S)},M=Y(),I=this.#k;if(M&&(I.lost.size>0||I.unseenWinners.size>0)){let L=an(this.#e,p,k.root,pn(M));Gs(L,I)||(this.#k=L,this.#g=new Set,this.#m=new Map,x.clear(),M=Y())}if(M&&w.size>0&&(this.#g=new Set,this.#m=new Map,x.clear(),M=Y(w)),!M)return{ok:!1,reason:`${this.#c??"invalid node records"} in ${p}`};let v=Yi(this.#e,ws(this.#e,p,M,y,this.#k.lost),this.#S);if(this.#c)return{ok:!1,reason:`${this.#c} in ${p}`};let R=new Set,F=new Set([...S,...this.#S.rescued,...this.#s?.rehomed??[]]),A=pi(this.#e,v,F,R,this.#g);l.set(p,R);let T=o?void 0:this.#t.get(p),P=n.parts.get(p),N=P?.kind==="xml"?P.xml.nextId:1,W=Wa(p,A,{idOf:L=>T?.idOf.get(L),nextId:N});if(!W.ok)return{ok:!1,reason:`${p}: ${W.reason}`};let C={keyOf:new Map,idOf:new Map};for(let[L,K]of W.ids)C.idOf.set(L,K),C.keyOf.set(K,L);s.set(p,C),a.set(p,x),c.set(p,this.#g),f.set(p,qs(this.#m,A)),g.set(p,new Map([...this.#s?.shownIn??[],...this.#O,...m])),u.set(p,ei(A,S)),r.push({kind:"xml",partName:p,xml:W.part})}for(let[p,k]of s)this.#I(p,k);for(let p of i)this.#I(p,void 0);for(let[p,k]of a)this.#P(p,k);for(let p of i)this.#P(p,new Map);for(let[p,k]of c)this.#d.set(p,k);for(let p of i)this.#d.delete(p);for(let[p,k]of f)k.size>0&&this.#h.set(p,k);for(let p of i)this.#h.delete(p);for(let[p,k]of g)this.#u.set(p,k);for(let[p,k]of u)this.#o.set(p,k);for(let p of i)this.#o.delete(p);for(let p of i)this.#u.delete(p);for(let[p,k]of l)this.#n.set(p,k);return this.#s=null,{ok:!0,parts:r,removed:i}}#c;#C=new Map;#O=new Map;#w(t,n,o,r,i){if(r>Xt.maxReadDepth||o.has(t))return null;o.add(t);let s=this.#e.nodes.get(t);if(!(s instanceof te.Map)||s.get(E.part)!==n)return null;let a=s.get(E.shell),c=s.get(E.attrs),f=s.get(E.children);if(typeof a!="object"||a===null||!(c instanceof te.Map)||!(f instanceof te.Array))return null;let l=a,d=[],g=f.toArray(),u=this.#C.get(t);if(u){let m=new Set(u.filter(Y=>{let M=this.#e.nodes.get(Y);return M instanceof te.Map&&!we(M)})),b=new Set(g);g=vo(u,g,m);for(let Y of g)typeof Y=="string"&&!b.has(Y)&&this.#O.set(Y,t)}for(let[m,b]of g.entries()){if(typeof b!="string")continue;if(o.has(b)){let I=this.#m.get(t);I||this.#m.set(t,I={length:g.length,at:new Map}),I.at.set(m,b);continue}let Y=this.#e.nodes.get(b);if(Y instanceof te.Map&&Y.get(E.text)instanceof te.Text){if(Y.get(E.part)!==n)continue;o.add(b),d.push({key:b,text:ct(Y.get(E.text))});continue}let M=this.#w(b,n,o,r+1,i);if(M)d.push(M);else if(this.#c)return null}let h=[...c.entries()].sort(([m],[b])=>m<b?-1:m>b?1:0).map(([,m])=>m),p=l.ns,k=l.local,x=k==="p"&&p===Ri||At({ns:p,local:k})?Mi(this.#e,n,s,d,m=>{let b=this.#w(m,n,new Set(o),r+1,i);return this.#c?null:b},this.#S,m=>this.#s?.showsBelow(m)??!1,m=>{for(let b of pn(m))o.add(b)}):d,y=this.#s?this.#s.withUndone(t,n,x,o,m=>this.#w(m,n,o,r+1,i)):x;if(this.#c)return null;let S=ks(this.#e,{ns:p,local:k},y,this.#g,this.#k.unseenWinners),w=xo({ns:p,local:k},S,i);return w?{key:t,ns:p,local:k,...typeof l.prefix=="string"?{prefix:l.prefix}:{},nsDecls:Array.isArray(l.nsDecls)?l.nsDecls:[],attrs:h,children:[...ht({ns:p,local:k},w,m=>"text"in m?void 0:m)]}:(this.#c="too many concurrent copies of one element",null)}};import*as je from"yjs";var Xn="pptxEditor",Ba=256,vi=256,Oi=512,Pi=256,Ai=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,Mt=(e,t=Ba)=>typeof e=="string"&&e.trim().length>0&&e.length<=t;function Di(e){return!Mt(e.actorId)||!Mt(e.name)||e.role!==void 0&&e.role!=="human"&&e.role!=="agent"?"invalid-identity":e.color!==void 0&&!Ai.test(e.color)?"invalid-identity-color":null}function Ci(e){let{actorId:t,name:n,color:o,role:r}=e;return!Mt(t)||!Mt(n)?null:{actorId:t,name:n,...typeof o=="string"&&Ai.test(o)?{color:o}:{},...r==="human"||r==="agent"?{role:r}:{}}}function Ti(e){let t=e?.[Xn];return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:null}function Ni(e,t){if(e.kind==="shapes"){let i=e.shapes.slice(0,Oi).map(s=>t.keyOf(e.part,s)).filter(s=>s!==void 0);return i.length>0?{kind:"shapes",part:e.part,keys:i}:void 0}let n=i=>{let s=t.keyOf(e.part,i.node);if(s===void 0)return;let a=t.textOf(s);if(!a)return{key:s};let c=Math.max(0,Math.min(Math.trunc(i.offset)||0,a.length)),f=c===a.length&&c>0?Ce(a,c-1,1)[0]:void 0;return{rel:je.relativePositionToJSON(je.createRelativePositionFromTypeIndex(a,c)),...f?{left:{client:f.client,clock:f.clock}}:{}}},o=n(e.anchor),r=n(e.head);return o&&r?{kind:"text",anchor:o,head:r}:void 0}function _i(e,t){return{actorId:e.actorId,name:e.name,...e.color?{color:e.color}:{},...e.role?{role:e.role}:{},...t?{selection:t}:{}}}function Li(e){let t=[];for(let[n,o]of e.getStates()){if(t.length>=vi)break;let r=Ti(o),i=r?Ci(r):null;i&&t.push({...i,isLocal:n===e.clientID})}return t}function Ei(e,t,n){if(typeof e!="object"||e===null)return null;let o=e;if(Mt(o.key,Pi)){let l=n.partOf(o.key),d=l?n.idOf(l,o.key):void 0;return l&&d?{part:l,node:d,offset:0}:null}let r=o.rel;if(typeof r!="object"||r===null)return null;let i;try{i=je.createAbsolutePositionFromRelativePosition(je.createRelativePositionFromJSON(r),t)}catch{return null}if(!i||!(i.type instanceof je.Text))return null;let s=n.recordOfText(i.type);if(!s)return null;let a=n.idOf(s.part,s.key),c=r,f=c.item??o.left;if(f&&typeof f=="object"){let{client:l,clock:d}=f;if(typeof l=="number"&&Number.isSafeInteger(l)&&l>=0&&typeof d=="number"&&Number.isSafeInteger(d)&&d>=0){let g=je.createID(l,d),u=Z(t,g);if(a&&u&&!u.deleted&&u.parent===i.type)return{part:s.part,node:a,offset:i.index};let h=n.locateCharacter(s.part,g);if(h&&(c.item||h.text!==i.type))return{part:s.part,node:h.node,offset:h.offset+(c.item?typeof c.assoc=="number"&&c.assoc<0?1:0:1)}}}return a?{part:s.part,node:a,offset:i.index}:null}function Vn(e,t,n){if(typeof e!="object"||e===null)return null;let o=e;if(o.kind==="shapes"&&Mt(o.part,1024)&&Array.isArray(o.keys)){let r=o.part,i=o.keys.slice(0,Oi).filter(s=>Mt(s,Pi)).map(s=>n.idOf(r,s)).filter(s=>s!==void 0);return i.length>0?{kind:"shapes",part:r,shapes:i}:null}if(o.kind==="text"){let r=Ei(o.anchor,t,n),i=Ei(o.head,t,n);return!r||!i||r.part!==i.part?null:{kind:"text",part:r.part,anchor:{node:r.node,offset:r.offset},head:{node:i.node,offset:i.offset}}}return null}function Fi(e,t,n){let o=[],r=0;for(let[i,s]of e.getStates()){if(++r>vi)break;if(i===e.clientID)continue;let a=Ti(s),c=a?Ci(a):null;if(!a||!c)continue;let f=Vn(a.selection,t,n);f&&o.push({actorId:c.actorId,name:c.name,...c.color?{color:c.color}:{},selection:f})}return o}import*as Yt from"yjs";var Xa=65536,Va=64,Ga=(e,t)=>e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock;function zi(e,t){let n=t.clock-e.id.clock;if(t.client!==e.id.client||n<0||n>=e.length)return;let o=e.content.getContent()[n];return typeof o=="string"?o:void 0}function Gn(e,t){let n=e.nodes.get(t);return n instanceof Yt.Map?n:void 0}function Ki(e,t){let o=Gn(e,t)?.get(E.children);if(!(o instanceof Yt.Array))return null;for(let r of o.toArray().slice(0,8)){let i=Gn(e,r)?.get(E.children);if(i instanceof Yt.Array)for(let s of i.toArray().slice(0,8)){let a=ie(Gn(e,s));if(a)return Tt(e.doc,U(e.doc,a.source(0)))}}return null}function Ua(e,t,n,o,r){let i=n.origin;if(!i)return null;let s=w=>w.id.client===o&&Ga(w.origin,i),a=[],c=n.left;for(;c!==null;c=c.left){if(!r())return null;if(!c.deleted){if(zi(c,i)!==void 0)break;if(!s(c))return null;a.unshift(c)}}let f=c?zi(c,i):void 0;if(!f)return null;let l=[],d=w=>typeof w=="string"&&Gn(e,w)?.get($.splitFrom)===f,g=n,u=!0;for(let w=n;w!==null;w=w.right){if(!r())return null;if(w.deleted)continue;if(w.id.client!==n.id.client)break;let m=w.content.getContent(),b=m.findIndex(Y=>!d(Y));if(b===0)break;if(l.push(...m.slice(0,b<0?m.length:b)),l.length>Va)return null;if(g=w,u=b<0,!u)break}let h=[];for(let w=g.right;u&&w!==null&&a.length===0;w=w.right){if(!r())return null;if(!w.deleted){if(!s(w))break;h.push(w)}}let p=[...a,...h].flatMap(w=>w.content.getContent().filter(m=>typeof m=="string"));if(l.length===0||p.length===0||p.some(d))return null;let k=a.length>0?p[p.length-1]:f,x=new Map,y=w=>(x.has(w)||x.set(w,Ki(e,w)),x.get(w)),S=[];for(let w of l){let m=Ki(e,w);if(!m)return null;let b=f;for(let M of p){if(!r())return null;let I=y(M);if(!I||I.text!==m.text||I.at>=m.at)break;b=M}let Y=S[S.length-1];Y?.after===b?Y.keys.push(w):S.push({after:b,keys:[w]})}return S.every(w=>w.after===k)?null:{list:t,groups:S}}function ji(e,t,n){let o=e.doc.clientID,r=[],i=Xa,s=()=>(i-=1)>=0;for(let a of t.changed.keys()){if(!(a instanceof Yt.Array))continue;let c=a.parent;if(!(c instanceof Yt.Map)||c.get(E.children)!==a)continue;let f=a;for(let l=f._start;l!==null;l=l.right){if(!s())return;if(l.deleted||l.id.client===o||l.id.clock<(t.beforeState.get(l.id.client)??0))continue;let d=Ua(e,f,l,o,s);d&&r.push(d)}}r.length!==0&&e.doc.transact(()=>{for(let{list:a,groups:c}of r){let f=c.flatMap(u=>u.keys),l=a.toArray(),d=f.map(u=>l.indexOf(u)),g=u=>l.indexOf(u)>=0&&l.indexOf(u)===l.lastIndexOf(u);if(!(!f.every(g)||!c.every(u=>g(u.after)))){for(let u of[...d].sort((h,p)=>p-h))a.delete(u,1);for(let{after:u,keys:h}of c)a.insert(a.toArray().indexOf(u)+1,[...h])}}},n)}import*as Wi from"yjs";var Ha=new Set([E.part,E.key,E.shell,oe.copyOf,oe.newParagraph]);function $i(e){return t=>{let n=t.parent;if(n===e)return!1;let o=Oe(n);return o===null||o.parent!==e?!0:t.content instanceof Wi.ContentType?!1:!(t.parentSub!==null&&Ha.has(t.parentSub)&&hr(t))}}import*as Ze from"yjs";var Bo="followed",Xi=65536,Bi=e=>{let t=Ze.createDeleteSet();return t.clients.set(e.client,[{clock:e.clock,len:1}]),t},Xo=e=>{let t=e.meta.get(Bo);return t instanceof Map?t:void 0};function Vi(e,t){for(let n of t)for(let o of e){if(!Ze.isDeleted(o.insertions,n.anchor))continue;o.insertions=Ze.mergeDeleteSets([o.insertions,Bi(n.added)]),o.deletions=Ze.mergeDeleteSets([o.deletions,Bi(n.gone)]);let r=Xo(o);r||o.meta.set(Bo,r=new Map),r.set(n.run,{from:n.from,to:n.to})}}function Gi(e,t){let n=Xo(e);n&&t.meta.set(Bo,new Map(n))}var qa=(e,t)=>{let n=0;for(let o=e._start;o!==null;o=o.right)if((n+=1)>Xi||!o.deleted&&o.countable&&o.content.getContent().includes(t))return!0;return!1};function Ja(e,t){let n=[],o=0;for(let r=e._start;r!==null&&o<Xi;r=r.right){if(o+=1,!r.deleted||!r.countable)continue;let i=r.content.getContent();for(let s=0;s<i.length;s+=1)i[s]===t&&n.push(Ze.createID(r.id.client,r.id.clock+s))}return n}function Qa(e,t){if(t.length===0)return e;let n=Ze.createDeleteSet();for(let[o,r]of e.clients){let i=t.filter(a=>a.client===o).map(a=>a.clock),s=[];for(let{clock:a,len:c}of r){let f=a;for(let l of i.filter(d=>d>=a&&d<a+c).sort((d,g)=>d-g))l>f&&s.push({clock:f,len:l-f}),f=l+1;f<a+c&&s.push({clock:f,len:a+c-f})}s.length>0&&n.clients.set(o,s)}return n}function Vo(e){let t=Xo(e),n=new Set;if(!t)return n;for(let[o,{from:r,to:i}]of t){if(qa(i,o)){n.add(o);continue}e.deletions=Qa(e.deletions,Ja(r,o)),t.delete(o)}return n}import*as de from"yjs";var Za=4096,el=4096,tl=32;function nl(e,t,n,o,r=new Set){let i=e.doc,s=new Map,a=0;for(let[c,f]of i.getMap(Xe).entries()){if(typeof f!="string"||!t.has(f)||!n(f,c))continue;if((a+=1)>Za)return null;let l=e.nodes.get(c),d=l instanceof de.Map?l.get(E.text):void 0;if(!(!ie(l)||!(d instanceof de.Text))){for(let g=d._start;g!==null;g=g.right)if(!(g.deleted||!g.countable))for(let u=0;u<g.length;u+=1){let h=z(g.id.client,g.id.clock+u);if(r.has(h))continue;let p=U(i,de.createID(g.id.client,g.id.clock+u),o),k=z(p.client,p.clock);if(k!==h){let x=s.get(k)??[];x.push({text:d,item:g,j:u}),s.set(k,x)}}}}return s}function st(e,t){let n=t.parent;if(!(n instanceof de.Map)||Oe(n)?.parent!==e.nodes)return null;let o=n.get(E.part);return typeof o=="string"?o:null}function Hi(e,t){let n=e.content.getContent();return n.length>0&&typeof n[0]=="string"?String(n.join("")).charAt(t):""}var Ui=e=>de.createID(e.item.id.client,e.item.id.clock+e.j);function qi(e,t,n,o){let r=e.doc,i=[],s=new Map,a=!1;return ae(r,t,c=>{if(a||!c.countable||!(c.parent instanceof de.Text)||c.redone===null)return;let f=c.parent,l=Z(r,c.redone);if(!st(e,f)||!l||l.deleted||l.parent!==f)return;let d=Math.min(c.length,l.length);for(let g=0;g<d;g+=1){if(i.length>=Ge){a=!0;return}let u=U(r,de.createID(c.id.client,c.id.clock+g),s);i.push({text:f,item:l,j:g,root:u,char:Hi(l,g)})}}),!a&&Ji(e,i,n,s,()=>!0,o)}function Ji(e,t,n,o,r,i){let s=e.doc;if(t.length===0)return!1;let a=new Set;for(let y of t)a.add(st(e,y.text));let c=y=>z(y.item.id.client,y.item.id.clock+y.j),f=new Set(t.map(c)),l=nl(e,a,n,o,f);if(!l||l.size===0)return!1;let d=y=>{let S=0,w=y.item,m=y.j-1;for(;w!==null&&S<el;){for(;m>=0&&w.countable;m-=1,S+=1){let b=de.createID(w.id.client,w.id.clock+m);if(f.has(z(b.client,b.clock)))continue;let Y=U(s,b,o),M=l.get(z(Y.client,Y.clock))?.[0];if(M&&M.text!==y.text)return M;if(!w.deleted)return null}w=w.left,m=w?w.length-1:-1}return null},g=[],u=[],h=new Map([...a].map(y=>[y,Zt(s,Nt(i,y))])),p=[];for(let y of t){let S=(l.get(z(y.root.client,y.root.clock))??[]).filter(b=>b.text!==y.text);if(S.length>0){let b=S.flatMap(I=>{let v=Qi(e,I.text),R=ie(I.text.parent);return v&&R?[{key:v,copy:R}]:[]}),Y=On(y.item,y.j,I=>f.has(z(I.client,I.clock))||Me(s,I)!==null),M=h.get(st(e,y.text));if(M&&Pn(e,M,y.text,Y,b,o,Ui(y)))p.push(...S);else{let I=Nt(i,st(e,y.text));for(let v of b){let R=I.get(v.key)?.run,F=R?e.nodes.get(R):void 0;F instanceof de.Map&&F.get($.copyWinner)!==!0&&F.set($.copyWinner,!0)}g.push(y);continue}}let w=r(y)?d(y):null;if(!w)continue;let m=u[u.length-1];m&&m.to.item===w.item&&m.to.j===w.j?m.chars.push(y):u.push({to:w,chars:[y]})}if(g.length===0&&u.length===0&&p.length===0)return!1;let k=[];for(let{to:y,chars:S}of u){let w=Yn(y.text,Ui(y));if(w<0)continue;let m=S.map(Y=>Y.char).join("");if(m.length===0)continue;let b=de.getState(s.store,s.clientID);y.text.insert(w+1,m),S.forEach((Y,M)=>{k.push(b+M,Y.root.client,Y.root.clock,1);for(let I of[Pe,Dt]){let v=s.getMap(I),R=v.get(c(Y));R!==void 0&&v.set(z(s.clientID,b+M),R)}}),g.push(...S)}qt(s,k);let x=new Map;for(let y of[...g,...p]){let S=x.get(y.text);S?S.add(c(y)):x.set(y.text,new Set([c(y)]))}for(let[y,S]of x)_e(y,S);return!0}function Un(e,t,n,o){let r=e.doc,i=[],s=new Set,a=new Set,c=new Map,f=[...de.decodeStateVector(de.encodeStateVector(r))].flatMap(([d,g])=>[d,g]),l=0;return ae(r,t,d=>{if(!d.countable||!(d.parent instanceof de.Text)||d.redone===null)return;let g=d.parent,u=d.redone;if(u.client!==r.clientID||st(e,g)===null)return;let h=Z(r,u);if(!(!h||h.parent!==g)){a.add(g);for(let p=0;p<d.length;p+=1){if((l+=1)>Ge)return;let k=de.createID(d.id.client,d.id.clock+p);for(let Y=0;Y<tl;Y+=1){let M=Me(r,k);if(!M)break;k=M}let x=U(r,k,c,!1);s.add(z(x.client,x.clock));let y=u.clock+p,S=U(r,k),w=o?.get(z(S.client,S.clock))??Ve(r,de.createID(d.id.client,d.id.clock+p));if(w&&r.getMap(Dt).set(z(r.clientID,y),[w.start.client,w.start.clock,w.enter,w.client,w.key]),n){let Y=U(r,k);r.getMap(Pe).set(z(r.clientID,y),[d.id.client,d.id.clock+p,n.has(z(Y.client,Y.clock)),f])}let m=i.length;m>0&&i[m-4]+i[m-1]===y&&i[m-3]===k.client&&i[m-2]+i[m-1]===k.clock?i[m-1]+=1:i.push(y,k.client,k.clock,1)}}}),qt(r,i),{roots:s,texts:a}}function Go(e,t){let n=e.doc,o=n.getMap(Le),r=new Set;for(let i of t){let s=i===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(i),a=i===null?void 0:o.get(i);if(!s||!Array.isArray(a))continue;let c=Math.min(Number(a[2])||0,Ge),f=Number(s[1]);for(let l=Number(s[2]),d=l+c;l<d;){let g=Z(n,de.createID(f,l));if(!g)break;if(!g.deleted&&g.parent instanceof de.Text&&st(e,g.parent)){r.add(g.parent);break}l=g.id.clock+g.length}}return r}function Uo(e,t){let n=new Set,o=[...e.doc.getMap(Le).keys()].sort().slice(0,Ge);for(let r of o)for(let i of Go(e,[r])){let s=st(e,i);s!==null&&t.has(s)&&n.add(i)}return n}function Qi(e,t){let n=Oe(t.parent);return n&&n.parent===e.nodes&&typeof n.parentSub=="string"?n.parentSub:null}var ol=(e,t)=>e.client<t.client||e.client===t.client&&e.clock>t.clock;function Ho(e,t,n,o){let r=e.doc,i=new Map,s=[...t],a=new Set;for(let y of s){let S=st(e,y);S!==null&&a.add(S)}if(a.size===0)return!1;let c=new Set(Uo(e,a));for(let y of s)c.add(y);let f=new Map([...a].map(y=>[y,Zt(r,Nt(o,y))])),l=(y,S,w)=>{let m=r.getMap(Pe).get(z(y.client,y.clock)),b=r.getMap(Pe).get(z(S.client,S.clock));if(Array.isArray(m)&&Array.isArray(b)&&m[2]!==b[2])return m[2]===!1;let Y=Ve(r,y),M=Ve(r,S);if(Y&&M&&Y.key!==M.key){let I=v=>({key:v.key,from:v.start,start:U(r,v.start,i),enter:v.enter,client:v.client});return f.get(w).ahead(I(Y),I(M))}return ol(y,S)},d=new Map,g=new Map,u=(y,S)=>{let w=g.get(y);w?w.add(z(S.client,S.clock)):g.set(y,new Set([z(S.client,S.clock)]))},h=0;for(let y of c){let S=st(e,y),w=Qi(e,y);if(S===null||w===null)continue;let m=n(S,w)?"":`${w}\0`;for(let b=y._start;b!==null&&h<Ge;b=b.right)if(!(b.deleted||!b.countable))for(let Y=0;Y<b.length;Y+=1,h+=1){let M=de.createID(b.id.client,b.id.clock+Y);if(!Me(r,M))continue;let I=U(r,M,i),v=m+z(I.client,I.clock),R=d.get(v);R?l(M,R.id,S)?(u(R.text,R.id),d.set(v,{id:M,text:y})):u(y,M):d.set(v,{id:M,text:y})}}for(let[y,S]of g)_e(y,S);let p=[];for(let{id:y,text:S}of d.values()){let w=Z(r,y);if(!w||w.deleted||w.parent!==S)continue;let m=y.clock-w.id.clock;p.push({text:S,item:w,j:m,root:U(r,y,i),char:Hi(w,m)})}let k=r.clientID;return Ji(e,p,n,i,y=>y.item.id.client===k,o)||g.size>0}import*as ee from"yjs";var $e=1<<20,ec=4096;function We(e,t){if(!(t instanceof ee.Text))return!1;let n=t.parent;return n instanceof ee.Map&&Oe(n)?.parent===e.nodes}function Hn(e,t){let n=e.doc,o=new Set,r=new Map,i=0,s=!1;return ae(n,t,a=>{if(!(s||!a.countable||!We(e,a.parent)))for(let c=0;c<a.length;c+=1){if((i+=1)>$e){s=!0;return}let f=U(n,ee.createID(a.id.client,a.id.clock+c),r);o.add(z(f.client,f.clock))}}),s?null:o}function qo(e,t){let n=new Map,o=$e,r=new Map;return ae(e.doc,t,i=>{if(o<=0||!i.countable||!We(e,i.parent))return;let s=ie(xe(i));for(let a=0;a<i.length&&--o>=0;a+=1){let c=ee.createID(i.id.client,i.id.clock+a),f=s&&c.client===s.client&&c.clock>=s.clock&&c.clock<s.clock+s.length?{start:s.source(0),enter:go(e.doc,s),client:s.client,key:String(xe(i)?.get(E.key)??"")}:Ve(e.doc,c);if(!f)continue;let l=U(e.doc,c,r);n.set(z(l.client,l.clock),f)}}),n}function Zi(e,t){let n=e.parent,o=Oe(n)?.parentSub,r=n.get(E.part);return typeof o=="string"&&typeof r=="string"&&t(r,o)}function tc(e,t,n){let o=e.doc,r=new Set;if(t.size===0)return r;let i=new Map,s=0,a=(d,g)=>{if(!Zi(d,n))return!0;for(let u=d._start;u!==null;u=u.right)if(!(u.deleted||!u.countable))for(let h=0;h<u.length;h+=1){if((s+=1)>$e)return!1;let p=ee.createID(u.id.client,u.id.clock+h);if(!g(p))continue;let k=U(o,p,i),x=z(k.client,k.clock);t.has(x)&&r.add(x)}return!0};for(let d of t){let[g,u]=d.split(":").map(Number),h=Z(o,ee.createID(g,u));h&&!h.deleted&&We(e,h.parent)&&Zi(h.parent,n)&&r.add(d)}let c=0;for(let d of o.getMap(Xe).keys()){if((c+=1)>ec)return null;let g=e.nodes.get(d),u=g instanceof ee.Map?g.get(E.text):void 0;if(!(!ie(g)||!We(e,u))&&!a(u,()=>!0))return null}let f=new Set,l=0;for(let[d,g]of o.getMap(Le).entries()){if((l+=1)>Ge)return null;let u=/^(\d{1,16}):(\d{1,16})$/.exec(d);if(!u||!Array.isArray(g))continue;let h=Z(o,ee.createID(Number(u[1]),Number(u[2])));h&&We(e,h.parent)&&f.add(h.parent)}for(let d of f)if(!a(d,g=>Me(o,g)!==null))return null;return r}function Jo(e,t,n,o){let r=e.doc,i=new Map,s=new Map,a=0;ae(r,t,c=>{if(a>$e||!c.countable||c.redone===null)return;let f=c.parent;if(!We(e,f))return;let l=Z(r,c.redone);if(!l||l.deleted||l.parent!==f)return;let d=Math.min(c.length,l.length);for(let g=0;g<d;g+=1){if((a+=1)>$e)return;let u=U(r,ee.createID(c.id.client,c.id.clock+g),s),h=z(u.client,u.clock);if(!n.has(h)||o.has(h))continue;let p=i.get(f)??new Set;p.add(z(l.id.client,l.id.clock+g)),i.set(f,p)}});for(let[c,f]of i)_e(c,f);return i.size>0}function nc(e,t,n,o,r){if(n.size===0)return!1;let i=e.doc,s=i.getMap(Le),a=new Map,c=h=>{if(a.has(h))return a.get(h);let p=rl(e,h);return a.set(h,p),p},f=new Map,l=null,d=new Map,g=h=>{if(!l){l=new Set;let k=0;for(let x of n){if((k+=1)>$e)break;let[y,S]=x.split(":").map(Number),w=U(i,ee.createID(y,S),d);l.add(z(w.client,w.clock))}}let p=U(i,h,d);return l.has(z(p.client,p.clock))},u=new Map;for(let h of t){let p=h===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(h),k=h===null?void 0:s.get(h);if(!p||!Array.isArray(k)||k.length!==3)continue;let[x,y,S]=k;if(!Number.isSafeInteger(x)||!Number.isSafeInteger(y)||!Number.isSafeInteger(S))continue;let w=Number(p[1]),m=Number(p[2]);if(w===i.clientID)continue;let b=c(w);if(!b)continue;let Y=Math.min(S,Ge);for(let M=0;M<Y;M+=1){let I=ee.createID(x,y+M),v=z(I.client,I.clock),R=b.copies.get(v),F=i.getMap(Pe).get(z(w,m+M)),A=Array.isArray(F)&&(F.length===3||F.length===4)&&Number.isSafeInteger(F[0])&&F[0]>=0&&Number.isSafeInteger(F[1])&&F[1]>=0&&typeof F[2]=="boolean",T="";if(A){let W=Ue(i,ee.createID(F[0],F[1]),f),C=z(W.client,W.clock);if(!n.has(C))continue;if(!F[2]){let L=F[3],K=r?.get(C);if(!Array.isArray(L)||L.length>8192||K===void 0)continue;let D=!1;for(let O=0;O+1<L.length;O+=2)L[O]===i.clientID&&Number.isSafeInteger(L[O+1])&&L[O+1]>K&&(D=!0);if(D)continue}T=C}else{if(!b.sources.has(v)&&!(R!==void 0&&b.restored.has(R)))continue;let W=U(i,I,f,!1);if(!n.has(z(W.client,W.clock))&&!g(I))continue}o?.(z(w,m+M),T);let P=Z(i,ee.createID(w,m+M));if(!P||P.deleted||!We(e,P.parent))continue;let N=u.get(P.parent)??new Set;N.add(z(w,m+M)),u.set(P.parent,N)}}for(let[h,p]of u)_e(h,p);return u.size>0}function rl(e,t){let n=e.doc,o={sources:new Set,copies:new Map,restored:new Set},r=0,i=0;for(let c of n.getMap(Xe).keys()){if((r+=1)>ec)return null;let f=ie(e.nodes.get(c));if(!(!f||f.client!==t))for(let l=0;l<f.length;l+=1){if((i+=1)>$e)return null;let d=f.source(l),g=z(d.client,d.clock);o.sources.add(g),o.copies.set(z(f.client,f.clock+l),g)}}let s=`${t}:`,a=0;for(let[c,f]of n.getMap(Le).entries()){if(!c.startsWith(s)||!Array.isArray(f)||f.length!==3)continue;let[l,d,g]=f;if(!(!Number.isSafeInteger(l)||!Number.isSafeInteger(d)||!Number.isSafeInteger(g)))for(let u=0;u<Math.min(g,Ge);u+=1){if((a+=1)>$e)return null;o.restored.add(z(l,d+u))}}return o}function oc(e,t){let n=t;for(let o=0;o<32;o+=1){let r=Z(e,n);if(!r||!r.redone)return r;n=ee.createID(r.redone.client,r.redone.clock+n.clock-r.id.clock)}return null}function rc(e,t){let n=new Set,o=!1;return ae(e.doc,t,r=>{if(!(o||!r.countable||!We(e,r.parent)))for(let i=0;i<r.length;i+=1){if(n.size>=$e){o=!0;return}let s=ee.createID(r.id.client,r.id.clock+i),a=oc(e.doc,s);a&&!a.deleted&&n.add(z(s.client,s.clock))}}),o?null:n}function sc(e,t,n){let o=e.doc,r=new Set;if(n.size===0)return r;let i=new Map,s=new Map,a=new Set,c=new Set,f=0;ae(o,t.insertions,d=>{if(!(!d.countable||!We(e,d.parent)))for(let g=0;g<d.length&&f++<$e;g+=1){let u=ee.createID(d.id.client,d.id.clock+g);ee.compareIDs(U(o,u,i),u)&&c.add(z(u.client,u.clock))}});let l=0;return ae(o,t.deletions,d=>{if(!(l>$e||!d.countable||d.redone===null)&&We(e,d.parent))for(let g=0;g<d.length;g+=1,l+=1){let u=U(o,ee.createID(d.id.client,d.id.clock+g),i);a.add(z(u.client,u.clock))}}),ae(o,t.insertions,d=>{if(!d.deleted||!d.countable||!We(e,d.parent))return;let g=ie(xe(d));for(let u=0;u<d.length;u+=1){let h=ee.createID(d.id.client,d.id.clock+u);if(!n.has(z(h.client,h.clock))||oc(o,h)?.deleted!==!0)continue;let p=U(o,h,i);if(g&&g.client===h.client&&h.clock>=g.clock&&h.clock<g.clock+g.length&&!c.has(z(p.client,p.clock))||a.has(z(p.client,p.clock)))continue;let k=Ue(o,h,s);r.add(z(k.client,k.clock)),r.add(z(p.client,p.clock))}}),r}function ic(e,t){let n=new Set,o=new Map,r=$e;if(ae(e.doc,t.insertions,s=>{if(!(!s.countable||!We(e,s.parent)))for(let a=0;a<s.length&&r-- >0;a+=1){let c=ee.createID(s.id.client,s.id.clock+a);ee.compareIDs(U(e.doc,c,o),c)&&n.add(z(c.client,c.clock))}}),r<=0||n.size===0)return;let i=ee.createDeleteSet();for(let s of e.nodes.values()){if(--r<0)return;let a=s instanceof ee.Map?s.get(E.text):null;if(a instanceof ee.Text){for(let c=a._start;c&&--r>=0;c=c.right)if(!(c.deleted||!c.countable))for(let f=0;f<c.length&&--r>=0;f+=1){let l=ee.createID(c.id.client,c.id.clock+f),d=U(e.doc,l,o);if(!n.has(z(d.client,d.clock)))continue;let g=i.clients.get(l.client)??[];g.push({clock:l.clock,len:1}),i.clients.set(l.client,g)}if(r<0)return}}t.insertions=ee.mergeDeleteSets([t.insertions,i])}import*as me from"yjs";function cc(e,t,n){let o=r=>{let i=e.nodes.get(r),s=i instanceof me.Map?i.get(E.children):void 0;return s instanceof me.Array?s.toArray():[]};for(let r of o(t))if(!(typeof r!="string"||e.nodes.get(r)?.get?.(E.shell)?.local!=="t"))for(let s of o(r)){let a=typeof s=="string"?e.nodes.get(s):void 0,c=a instanceof me.Map?a.get(E.text):void 0;c instanceof me.Text&&n.add(c)}}var $t=(e,t)=>Oe(t)?.parent===e.nodes&&t instanceof me.Map?t:null;function ac(e,t){let n=e.doc.clientID.toString(36),o=Ft(e),r=new Set,i=new Map,s=c=>{if(typeof c!="string")return new Set;let f=i.get(c);if(!f){let l=et(e.parts.get(c));f=l?.kind==="xml"?an(e,c,l.root).unseenWinners:new Set,i.set(c,f)}return f};if(ae(e.doc,t.insertions,c=>{if(c.parent!==e.nodes||c.deleted||!(c.content instanceof me.ContentType))return;let f=c.content.type,l=wt(f),d=l?o(l.group):void 0;!l||d===void 0||d===n||s(f.get(E.part)).has(l.group)||r.add(l.from)}),r.size===0)return t.deletions;let a=new Set;for(let c of r)cc(e,c,a);return a.size===0?t.deletions:Mn(e.doc,t.deletions,c=>a.has(c.parent))}function lc(e,t){let n=new Map,o=e.doc,r=new Map,i=new Set,s=[];ae(o,t.insertions,p=>{let k=p.parent;if(!(!(k instanceof me.Text)||!p.countable)&&$t(e,k.parent)){n.has(k)||n.set(k,!1);for(let x=0;x<p.length;x+=1){let y=U(o,me.createID(p.id.client,p.id.clock+x),r),S=`${y.client}:${y.clock}`;p.deleted?s.push([k,S]):i.add(S)}}});for(let[p,k]of s)i.has(k)||n.set(p,!0);if(![...n.values()].some(Boolean))return t;let a=new Map,c=new Set;if(ae(e.doc,t.deletions,p=>{let k=$t(e,p.parent);if(!k||p.parentSub!==$.splitFrom||!(p.content instanceof me.ContentAny))return;let x=p.content.getContent()[0];if(typeof x!="string")return;let y=new Set;cc(e,x,y);let S=[...y].filter(m=>n.get(m)===!0);if(S.length===0)return;for(let m of S)c.add(m);let w=k.get(E.key);typeof w=="string"&&a.set(k,w)}),a.size===0)return t;let f=new Map;ae(e.doc,t.deletions,p=>{let k=p.parent,y=(k instanceof me.Array?$t(e,k.parent):null)?.get(E.key);if(typeof y!="string"||!(p.content instanceof me.ContentAny))return;let S=f.get(y);S||f.set(y,S=[]);for(let w of p.content.getContent())typeof w=="string"&&S.push(w)});let l=new Set(a.values()),d=new Set,g=[...l];for(;g.length>0;){let p=g.pop(),k=e.nodes.get(p);if(!(d.has(k)||!(k instanceof me.Map))){d.add(k);for(let x of f.get(p)??[])g.push(x)}}let u=p=>$t(e,p.parent)??$t(e,p.parent?.parent),h=p=>p.parent instanceof me.Array&&$t(e,p.parent.parent)!==null&&p.content instanceof me.ContentAny&&p.content.getContent().some(k=>typeof k=="string"&&l.has(k));return{insertions:Mn(e.doc,t.insertions,p=>c.has(p.parent)),deletions:Mn(e.doc,t.deletions,p=>d.has(u(p))||h(p))}}import*as pc from"yjs";import{CONTENT_TYPES_PART as qn,asciiFold as Rt,NS as Ye,attr as He,children as Qn,materialize as sl,relationshipsOf as kn,relsPartName as Jn,specOf as il}from"@pptx-editor.dev/core/store";var Zo=Symbol("absent");function gc(e,t,n){let o=cl(n);for(let r of e){let i=r.target;if(!(i instanceof pc.Map)||!t(i))continue;let s=o.get(i);s||o.set(i,s=new Map);for(let[a,c]of r.changes.keys){let f=i.get(a),l=s.get(a);if(l)l[3]=f;else{let d=[i,a,c.action==="add"?Zo:c.oldValue,f];n.push(d),s.set(a,d)}}}}var fc=new WeakMap;function cl(e){let t=fc.get(e);if(t)return t;t=new Map;for(let n of e){let o=t.get(n[0]);o||t.set(n[0],o=new Map),o.has(n[1])||o.set(n[1],n)}return fc.set(e,t),t}var hc=e=>e._item?.deleted!==!0;function mc(e){return e.filter(([t,n,o])=>o!==Zo&&hc(t)&&!t.has(n)).map(([t,n,o])=>[t,n,o])}function er(e){let t=(n,o)=>JSON.stringify(n)===JSON.stringify(o);return e.filter(([n,o,r,i])=>hc(n)&&i!==void 0&&r!==Zo&&t(n.get(o),r)&&!t(r,i)).map(([n,o,,r])=>[n,o,r])}function al(e){let t=new Set,n=[e];for(;n.length>0;){let o=n.pop();if(!(o.type!=="element"||yc(o))){for(let r of o.attrs)r.ns===Ye.r&&t.add(r.value);for(let r of o.children)n.push(r)}}return t}function dc(e,t){let n={next:e.nextId},o=t.map(r=>sl(il(r),e.root.kind,n));return{partName:e.partName,root:{...e.root,children:[...e.root.children,...o]},nextId:n.next}}var yc=e=>e.ns===Ye.p&&e.local==="sldId";function ll(e,t){for(let n of e.parts.values()){if(n.kind!=="xml")continue;let o=n.xml.root;if(o.ns!==Ye.p||o.local!=="presentation")continue;let r=o.children.find(y=>y.type==="element"&&y.ns===Ye.p&&y.local==="sldIdLst");if(!r)return;let i=[],s=new Set;for(let y of r.children){if(y.type!=="element"||!yc(y))continue;let S=y.attrs.find(w=>w.ns===Ye.r&&w.local==="id")?.value;S===void 0||!t.has(S)?s.add(y):i.push(He(y,"id")??"")}let a=[],c=y=>{for(let S of y.children)S.type==="element"&&(S.ns===Ye.p14&&S.local==="section"?a.push(S):c(S))};c(o);let f=new Map(a.map((y,S)=>[y,S])),l=new Map;a.forEach((y,S)=>{let w=y.children.find(m=>m.type==="element"&&m.ns===Ye.p14&&m.local==="sldIdLst");if(w)for(let m of Qn(w,{ns:Ye.p14,local:"sldId"})){let b=He(m,"id")??"",Y=l.get(b);Y?Y[Y.length-1]!==S&&Y.push(S):l.set(b,[S])}});let d=new Map,g=0;for(let y of i){let S=l.get(y);if(!S)continue;let w=S.find(m=>m>=g)??S[0];d.set(y,w),g=Math.max(g,w)}let u=new Map(i.map((y,S)=>[y,S])),h=s.size>0,p=(y,S)=>{let w=y.children.map(m=>{if(m.type!=="element"||m.ns!==Ye.p14||m.local!=="sldIdLst")return m;let b=new Set,M=[...m.children.filter(I=>{if(I.type!=="element"||I.ns!==Ye.p14||I.local!=="sldId")return!0;let v=He(I,"id")??"";return d.get(v)!==S||b.has(v)?!1:(b.add(v),!0)})].sort((I,v)=>{let R=I.type==="element"?u.get(He(I,"id")??"")??0:0,F=v.type==="element"?u.get(He(v,"id")??"")??0:0;return R-F});return M.length===m.children.length&&M.every((I,v)=>I===m.children[v])?m:(h=!0,{...m,children:M})});return w.every((m,b)=>m===y.children[b])?y:{...y,children:w}},k=y=>{let S=y.children.filter(m=>m.type!=="element"||!s.has(m)).map(m=>{if(m.type!=="element")return m;let b=f.get(m)??-1;return b>=0?p(m,b):k(m)});return S.length===y.children.length&&S.every((m,b)=>m===y.children[b])?y:{...y,children:S}},x=k(o);return h?{...n.xml,root:x}:void 0}}var fl=new Set(["hlinkClick","hlinkHover","hlinkMouseOver"]),Qo=e=>e.endsWith("/relationships/slide");function uc(e,t){let n=!1,o=i=>{let s=!1,a=[];for(let c of i.children){if(c.type!=="element"){a.push(c);continue}let f=c.attrs.some(d=>d.ns===Ye.r&&d.value===t);if(f&&c.ns===Ye.a&&fl.has(c.local)){s=!0;continue}f&&(n=!0);let l=o(c);l!==c&&(s=!0),a.push(l)}return s?{...i,children:a}:i},r=o(e);return n?void 0:r}function dl(e,t){return{...e,root:{...e.root,children:e.root.children.filter(n=>n.type!=="element"||n.local!=="Relationship"||He(n,"Id")!==t)}}}var Bt=(e,t)=>{let n=e.parts.get(t);return n?.kind==="xml"?n.xml:void 0};function tr(e,t){let n=new Map,o=new Set;for(let d of t.parts.keys())o.add(Rt(d));let r=d=>t.parts.has(d)||o.has(Rt(d)),i=[],s=new Set,a=d=>{!d||s.has(d.partName)||(s.add(d.partName),i.push(d))},c=!1;for(let d of e.parts.keys())t.parts.has(d)||(c=!0);for(let[d,g]of t.parts){if(g.kind!=="xml")continue;let u=Jn(d);if(!c&&e.parts.get(d)===g&&e.parts.get(u)===t.parts.get(u))continue;let h=m=>{let b=uc((n.get(d)??g.xml).root,m);if(!b)return!1;n.set(d,{...n.get(d)??g.xml,root:b});let Y=n.get(u)??Bt(t,u);return Y&&n.set(u,dl(Y,m)),!0};for(let m of kn(t,d))!m.external&&m.target&&!r(m.target)&&Qo(m.type)&&h(m.id);let p=al((n.get(d)??g.xml).root);if(p.size===0)continue;for(let m of kn(t,d))!p.has(m.id)||m.external||!m.target||r(m.target)||Qo(m.type)||a(e.parts.get(m.target));let k=new Set(kn(t,d).map(m=>m.id)),x=Bt(e,u);if(!x)continue;let y=Qn(x.root,{ns:Ye.rel,local:"Relationship"}).filter(m=>{let b=He(m,"Id");return b!==void 0&&p.has(b)&&!k.has(b)});for(let m of kn(e,d)){let b=y.findIndex(M=>He(M,"Id")===m.id);if(b<0||m.external||!m.target||r(m.target)||!Qo(m.type))continue;let Y=uc((n.get(d)??g.xml).root,m.id);Y&&(n.set(d,{...n.get(d)??g.xml,root:Y}),y.splice(b,1))}if(y.length===0)continue;let S=n.get(u)??Bt(t,u)??{partName:u,root:{...x.root,children:[]},nextId:x.nextId};n.set(u,dc(S,y));let w=new Set(y.map(m=>He(m,"Id")));for(let m of kn(e,d))!w.has(m.id)||m.external||!m.target||r(m.target)||a(e.parts.get(m.target))}{let d=[...t.parts.values()].find(p=>p.kind==="xml"&&p.xml.root.ns===Ye.p&&p.xml.root.local==="presentation"),g=d&&(n.get(Jn(d.partName))??Bt(t,Jn(d.partName))),u=d&&Jn(d.partName),h=d&&(e.parts.get(d.partName)!==d||e.parts.get(u)!==t.parts.get(u)||n.has(u));if(g&&h&&u&&t.parts.has(u)){let p=new Set(Qn(g.root,{ns:Ye.rel,local:"Relationship"}).map(x=>He(x,"Id")??"")),k=ll(t,p);k&&n.set(k.partName,k)}}let f=Bt(t,qn),l=Bt(e,qn);if(f&&l){let d=(y,S,w)=>{let m=new Map;for(let b of Qn(y,{ns:Ye.ct,local:S})){let Y=He(b,w);Y!==void 0&&!m.has(Rt(Y))&&m.set(Rt(Y),b)}return m},g=d(f.root,"Override","PartName"),u=d(f.root,"Default","Extension"),h=d(l.root,"Override","PartName"),p=d(l.root,"Default","Extension"),k=new Set,x=new Set(t.parts.keys());for(let y of i)x.add(y.partName);for(let y of x){if(y===qn)continue;let S=Rt(y.slice(y.lastIndexOf(".")+1));if(g.has(Rt(y))||u.has(S))continue;let w=h.get(Rt(y))??p.get(S);w&&k.add(w)}k.size>0&&n.set(qn,dc(f,[...k]))}return[...[...n.values()].map(d=>({kind:"xml",partName:d.partName,xml:d})),...i]}var kc=0;function nr(e,...t){for(let n of[...e])try{n(...t)}catch(o){console.warn("[pptx-editor] collaboration listener failed",o)}}function pl(e){let{doc:t,documentId:n,identity:o,awareness:r}=e;if(typeof n!="string"||n.trim()===""||n.length>256)throw new ve("invalid-document-id");let i=Di(o);if(i)throw new ve(i);let s=fr(t),a=ul("initializing"),c=new Set,f=new Set,l=new Set,d=null,g=null,u={value:0},h=null,p=null,k=null,x=!1,y=!0,S=[{...o,isLocal:!0}],w=[],m=null,b=null,Y=null,M=!1;kc+=1;let I=`${t.clientID.toString(36)}-${kc}`,v=(C,L,K,D=!1)=>{if(!a.set(C,L,K,D))return;let O=a.snapshot().reason;nr(c,C,O?.code,O?.detail)},R=()=>y?v("ready"):v("disconnected","transport-disconnected"),F=C=>{r&&!x&&r.setLocalStateField(Xn,_i(o,C))},A=()=>{if(!r)return;let C=Li(r);JSON.stringify(C)!==JSON.stringify(S)&&(S=C,nr(f,S));let L=g?Fi(r,t,g):[];JSON.stringify(L)!==JSON.stringify(w)&&(w=L,nr(l,w))};F(void 0),r?.on("change",A),A();let T=(C,L,K,D=!0)=>{let O=L?C.redoStack:C.undoStack,j=O.length;L?C.undoing=!0:C.redoing=!0;try{t.transact(K,oo)}finally{C.undoing=!1,C.redoing=!1}if(O.length!==j+1)return!1;let B=O[O.length-2];if(!D||!B)return!0;let X=O.pop();return B.deletions=Ne.mergeDeleteSets([B.deletions,X.deletions]),B.insertions=Ne.mergeDeleteSets([B.insertions,X.insertions]),!0},P=(C,L,K)=>L.length>0&&T(C,!1,()=>{for(let[D,O,j]of L)D.set(O,j)},K),N=(C,L)=>{let K=L?C?.undoStack:C?.redoStack;if(!C||!K||K.length===0)return!1;M=!1;let D=p?.package(),O=K[K.length-1];L&&ic(s,O);let j=Hn(s,O.insertions),B=qo(s,O.insertions),X=L&&K.length>1?K[K.length-2]:null,q=X?Hn(s,X.insertions):null,le=rc(s,O.insertions),Ee=g,it=j&&Ee?tc(s,q?new Set([...j,...q]):j,(J,ce)=>Ee.idOf(J,ce)!==void 0):null;if(L){for(let J of K.slice(0,-1))Vo(J);Ao(s,O,J=>t.transact(J,Ot),Vo(O)),O.deletions=ac(s,O)}else{let J=lc(s,O);O.insertions=J.insertions,O.deletions=J.deletions,Ao(s,O,ce=>t.transact(ce,Ot),new Set,!0)}let Zn=[...K];k=null;let It=J=>{let ce=J?C.undoStack:C.redoStack,fe=ce[ce.length-1],Et=fe===O?j:fe?Hn(s,fe.insertions):null,vt=fe===O?B:fe?qo(s,fe.insertions):void 0;try{t.transact(()=>{let qe=J?C.undo():C.redo();C.undoing=J,C.redoing=!J,C.currStackItem=qe,qe&&Un(s,qe.deletions,qe===fe?Et:q,qe===fe?vt:void 0)},C)}finally{C.undoing=!1,C.redoing=!1,C.currStackItem=null}};It(L),!L&&k===O&&Ls(s,O,J=>t.transact(J,Ot));let ye=k,H=new Set(K),se=Zn.reverse().filter(J=>!H.has(J)&&J!==ye),pe=J=>J.meta.get("attrs")??[],ge=!1,re=!1,be=null;if(L&&ye&&ye!==O)ye===X&&q&&it&&t.transact(()=>Jo(s,ye.deletions,q,it),pt),k=null,It(!1),be=k,re=!0;else if(!L&&ye===O)ge=P(C,er(pe(O)),!0);else if(!L){ye&&(k=null,It(!0),be=k);for(let J of se.slice(1).reverse())C.redoStack.push(J);ge=P(C,er(pe(O)),!1)}if(be){let J=be;t.transact(()=>Un(s,J.deletions),Ot)}let Re=ye&&!re&&(L||ye===O)?ye:null;if(Re&&g&&p){let J=g,ce=Re,fe=(qe,wc)=>J.idOf(qe,wc)!==void 0,Et={keyOf:J.keyOf.bind(J),package:p.package()},vt=new Set;Re===O&&j&&it&&t.transact(()=>Jo(s,ce.deletions,j,it),pt),T(C,L,()=>{let qe=Un(s,ce.deletions,Re===O?j:q,Re===O?B:void 0);vt=qe.roots,L&&Fs(s,ce,fe),qi(s,ce.deletions,fe,Et),Ho(s,qe.texts,fe,Et)}),J.noteStep(vt,le?sc(s,ce,le):[])}let Se=p?.package(),Q=L&&ye&&!re?mc(pe(ye)):[],he=D&&Se&&!re?tr(D,Se):[];if((Q.length>0||he.length>0)&&Se&&g){let J=g;t.transact(()=>{for(let[fe,Et,vt]of Q)fe.set(Et,vt);if(he.length===0)return;let ce=new Map(Se.parts);for(let fe of he)ce.set(fe.partName,fe);J.writeChange(Se,{parts:ce},he.map(fe=>fe.partName))},no)}return!M&&(L?ye!==null&&!re:ye===O||ge)};return{documentId:n,sessionId:I,identity:o,get attached(){return d!==null},status:()=>a.status(),statusSnapshot:()=>a.snapshot(),subscribeStatus(C){return c.add(C),()=>c.delete(C)},setConnected(C){if(x||C===y)return;y=C;let L=a.snapshot();(L.status==="ready"||L.status==="disconnected")&&R()},participants:()=>S,subscribeParticipants(C){return f.add(C),()=>f.delete(C)},remoteSelections:()=>w,subscribeRemoteSelections(C){return l.add(C),()=>l.delete(C)},setLocalSelection(C){let L=C&&g?Ni(C,g):void 0;m=C&&L?{selection:C,encoded:L}:null,F(L)},remoteSelectionMove:()=>b,historySelection:()=>Y&&g?Vn(Y,t,g):null,canUndo:()=>h?h.undoStack.length>0:!1,canRedo:()=>h?h.redoStack.length>0:!1,undo:()=>N(h,!0),redo:()=>N(h,!1),attach(C){if(x)return()=>{};d?.(),v("initializing");let L=s.meta.get("schema");if(s.meta.size>0&&!co(s.meta))return v("error","schema-version-mismatch",`room schema ${String(L)}`),()=>{};let K=new Bn(s,u);p=C,g=K;let D=(H,se,pe=!1)=>{let ge=C.package(),re=K.rebuild(H,ge,se);if(!re.ok)return M=!0,v("error","remote-apply-failed",re.reason,!0);let be=m?Vn(m.encoded,t,K):null;if(b=m&&be&&JSON.stringify(be)!==JSON.stringify(m.selection)?{from:m.selection,to:be}:null,b&&m&&(m={selection:b.to,encoded:m.encoded}),re.parts.length>0||re.removed.length>0){let Se=C.applyRemoteParts(re.parts,re.removed,"collaboration");if(b=null,!Se.ok){M=!0;let Q=Se.rejection.code;return Q==="unsafe-part-name"?v("error","unsafe-part-name",Q):v("error","remote-apply-failed",Q,!0)}}b=null,pe&&q(ge,C.package());let Re=a.snapshot();Re.status==="error"&&Re.recovering&&R(),A()};K.seeded?D(K.allParts(C.package()),!0):t.transact(()=>{pr(s.meta),s.meta.set("documentId",n),K.seed(C.package())},so);let O=new Ne.UndoManager([s.parts,s.binaries,s.nodes],{trackedOrigins:new Set([bn,oo]),captureTimeout:Number.POSITIVE_INFINITY,deleteFilter:$i(s.nodes)}),j=H=>{let se=H.parent;return se instanceof Ne.Map&&se.get(E.attrs)===H},B=H=>{kr(s,H.stackItem);let se=O.currStackItem;if((O.undoing||O.redoing)&&se){H.stackItem.meta.set("attrs",se.meta.get("attrs")??[]),Gi(se,H.stackItem);return}let pe=H.stackItem.meta.get("attrs")??[],ge=new Set;for(let re of H.changedParentTypes?.values()??[])for(let be of re)ge.add(be);gc(ge,j,pe),H.stackItem.meta.set("attrs",pe)};O.on("stack-item-added",H=>{m&&H.stackItem.meta.set("selection",m.encoded),B(H)}),O.on("stack-item-updated",B),O.on("stack-item-popped",H=>{Y=H.stackItem.meta.get("selection")??null,k=H.stackItem}),h=O;let X=C.subscribeLocal(H=>{H.merged||O.stopCapturing(),K.hasHiddenListings(H.parts)&&t.transact(()=>K.dropHiddenListings(H.parts,H.before,H.after),ro),t.transact(()=>K.writeChange(H.before,H.after,H.parts,H.label==="changeCase"),bn);let se=K.showingUnlisted(H.parts);se.length>0&&D(se,!1),A()}),q=(H,se)=>{let pe=tr(H,se);if(pe.length===0)return;let ge=new Map(se.parts);for(let re of pe)ge.set(re.partName,re);t.transact(()=>K.writeChange(se,{parts:ge},pe.map(re=>re.partName)),no)},le=new Map,Ee=new Map,it=(H,se)=>{let pe=K.deletedText,ge=K.newCopies(H,!1);for(let[Q,he]of le)se.set(Q,[...new Set([...se.get(Q)??[],...he])]);for(let[Q,he]of Ee)ge.set(Q,[...new Set([...ge.get(Q)??[],...he])]);let re=Cr(s,H);for(let Q of re){let he=s.nodes.get(Q),J=he instanceof Ne.Map?he.get(E.part):void 0;if(typeof J!="string")continue;let ce=se.get(J)??[];ce.includes(Q)||ce.push(Q),se.set(J,ce)}if(se.size===0&&re.size===0)return;let be={keyOf:K.keyOf.bind(K),package:C.package()},Re=[],Se=[];t.transact(()=>{for(let[Q,he]of se){if(!Wr(s,Q)){Ys(s,Q,he,pe),le.set(Q,new Set(he)),Ee.set(Q,new Set(ge.get(Q)??[]));continue}le.delete(Q),Ee.delete(Q),bs(s,Q,he,pe,be,(J,ce,fe)=>Re.push([J,ce,fe]),J=>Se.push(J),new Set(ge.get(Q)??[]))}Ms(s,re,pe)},pt),Vi([...O.undoStack,...O.redoStack],Se);for(let[Q,he,J]of Re)for(let ce of[...O.undoStack,...O.redoStack]){if(!Ne.isDeleted(ce.insertions,Q))continue;let fe=Ne.createDeleteSet();fe.clients.set(he.client,[{clock:he.clock,len:J}]),ce.insertions=Ne.mergeDeleteSets([ce.insertions,fe])}},Zn=t.getMap(Le),It=H=>{let se=s.meta.get("schema");if(!co(s.meta)&&H.changed.has(s.meta)){ye(),v("error","schema-version-mismatch",`room schema ${String(se)}`);return}let pe=H.origin;if(pe===bn||pe===so||pe===Ot||pe===ro)return;let ge=K.touchedParts(H);if(ge.size>0&&D(ge,!1,!H.local),H.local)return;let re=H.changed.get(Zn);re&&K.deletedText.size>0&&t.transact(()=>nc(s,re,K.deletedText,(Se,Q)=>K.noteRejected(Se,Q),K.deletedAt),pt);let be=K.newCopies(H);it(H,be),ji(s,H,pt);let Re=re?Go(s,re):new Set;if(be.size>0&&s.doc.getMap(Le).size>0)for(let Se of Uo(s,new Set(be.keys())))Re.add(Se);if(Re.size>0){let Se=(he,J)=>K.idOf(he,J)!==void 0,Q={keyOf:K.keyOf.bind(K),package:C.package()};t.transact(()=>Ho(s,Re,Se,Q),pt)}};t.on("afterTransaction",It),a.status()==="initializing"&&R(),A();let ye=()=>{X(),t.off("afterTransaction",It),O.destroy(),h===O&&(h=null),g===K&&(g=null),p===C&&(p=null),m=null,Y=null,F(void 0),A(),d===ye&&(d=null)};return d=ye,ye},destroy(){x||(d?.(),r?.off("change",A),r?.setLocalStateField(Xn,null),x=!0,v("destroyed","collaboration-session-destroyed"),c.clear(),f.clear(),l.clear())}}}export{ur as COLLABORATION_FORMAT_VERSION,ve as CollaborationSchemaError,_c as assertCollaborationFormatCompatibility,Dc as collaborationModule,Sc as comparePresentations,pl as createYjsCollaborationSession,Ac as legacyComments,Lc as readCollaborationFormatVersion,xc as reviewModule};
|
|
6
|
+
import{a as Yc,b as Rc}from"./chunk-NXOSE66U.js";import{a as or}from"./chunk-HCD7IVOL.js";import{attr as ut,binaryPartOf as Ic,elements as to,parseXmlPart as Ec,mainPresentationPart as vc,presentationInfo as Oc,relTargetByType as ir,textOf as Pc,xmlPartOf as Ac}from"@pptx-editor.dev/core/store";var cr="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Dc=`${cr}/comments`,Cc=`${cr}/commentAuthors`;function ar(e,t){let n=Ac(e,t);if(n||!t)return n;let o=Ic(e,t);if(!o)return;let r=Ec(t,new TextDecoder().decode(o));return r.ok?r.part:void 0}function Tc(e){let t=Object.create(null),n=vc(e);if(!n)return t;let o=ar(e,ir(e,n,Cc));for(let r of to(o?.root)){if(r.local!=="cmAuthor")continue;let i=ut(r,"id"),s=ut(r,"name");i!==void 0&&s!==void 0&&(t[i]=s)}return t}function eo(e,t){for(let n of to(e)){if(n.local===t)return n;let o=eo(n,t);if(o)return o}}var rr=e=>encodeURIComponent(e).replace(/-/g,"%2D"),sr=(e,t,n)=>`${e}#cm-${rr(t)}-${rr(n)}`;function Nc(e){let t=Tc(e),n=[];for(let o of Oc(e).slides){let r=ar(e,ir(e,o.partName,Dc));for(let i of to(r?.root)){if(i.local!=="cm")continue;let s=ut(i,"authorId")??"",a=ut(i,"idx")??"",c=eo(i,"parentCm"),f=t[s],l=ut(i,"dt");n.push({id:sr(o.partName,s,a),kind:"comment",slidePart:o.partName,text:Pc(eo(i,"text")),...f!==void 0?{author:f}:{},...l!==void 0?{date:l}:{},...c?{parentId:sr(o.partName,ut(c,"authorId")??"",ut(c,"idx")??"")}:{}})}}return n}function _c(e){return or(e.licenseKey),{id:"collaboration",collaboration:{session:e.session}}}import*as Ne from"yjs";var ve=class extends Error{constructor(n,o){let r=o?`${n}: ${o}`:n;super(n==="schema-version-mismatch"?`${r}
|
|
7
|
+
Collaboration upgrade required. Save local changes and use a compatible app version.`:r);this.code=n;this.detail=o;this.name="CollaborationSchemaError"}code;detail};import"yjs";var Sn=8,xn="pptx-meta-v1",Lc="pptx-parts-v1",Fc="pptx-binaries-v1",zc="pptx-nodes-v1",I=Object.freeze({part:"p",key:"k",shell:"s",attrs:"a",attrOrder:"ao",children:"c",text:"x"}),lr="",fr=2**40,bn=Object.freeze({kind:"pptx-local"}),no=Object.freeze({kind:"pptx-undo-repair"}),oo=Object.freeze({kind:"pptx-redo-repair"}),pt=Object.freeze({kind:"pptx-text-repair"}),ro=Object.freeze({kind:"pptx-tidy"}),Ot=Object.freeze({kind:"pptx-undone-listing"}),so=Object.freeze({kind:"pptx-seed"}),Vt=Object.freeze({maxBinaryBytes:256*1024*1024,maxReadDepth:300,maxCopiesPerGroup:256});function dr(e){return{doc:e,meta:e.getMap(xn),parts:e.getMap(Lc),binaries:e.getMap(Fc),nodes:e.getMap(zc)}}function et(e){if(typeof e!="object"||e===null)return null;let t=e;return t.kind==="binary"?{kind:"binary"}:t.kind==="xml"&&typeof t.root=="string"?{kind:"xml",root:t.root}:null}var io=Object.freeze({protocolVersion:1,sharedSchemaVersion:Sn,repairVersion:1,canonicalModelVersion:1}),Gt=["protocolVersion","sharedSchemaVersion","repairVersion","canonicalModelVersion"],ur=e=>`pptx-collaboration:${e.join(".")}`,pr=ur(Gt.map(e=>io[e]));function Kc(e){if(e!==pr)throw new ve("schema-version-mismatch","incompatible collaboration format")}function gr(e){e.set("schema",Sn);for(let t of Gt)e.set(t,io[t])}function co(e){return e.get("schema")===Sn&&Gt.every(t=>e.get(t)===io[t])}function jc(e){if(!e.share.has(xn))throw new ve("not-initialized");let t;try{t=e.getMap(xn)}catch{throw new ve("schema-version-mismatch","room metadata is not a map")}let n=t.get("schema");if(n===void 0)throw new ve(t.size===0?"not-initialized":"schema-version-mismatch");if(typeof n!="number"||!Number.isSafeInteger(n)||n<1)throw new ve("schema-version-mismatch","invalid room schema");if(Gt.every(r=>!t.has(r)))return`pptx-collaboration-${n}`;let o=Gt.map(r=>{let i=t.get(r);if(typeof i!="number"||!Number.isSafeInteger(i)||i<1)throw new ve("schema-version-mismatch","invalid collaboration version metadata");return i});if(o[1]!==n)throw new ve("schema-version-mismatch","conflicting room schema");return ur(o)}import*as Pt from"yjs";import*as Be from"yjs";function Oe(e){if(!(e instanceof Be.AbstractType))return null;let t=e._item;return t instanceof Be.Item?t:null}function ae(e,t,n){for(let[o,r]of t.clients){let i=e.store.clients.get(o);if(!(!i||i.length===0))for(let{clock:s,len:a}of r){let c=i[i.length-1];if(!(s>=c.id.clock+c.length))for(let f=Be.findIndexSS(i,s);f<i.length;f+=1){let l=i[f];if(l.id.clock>=s+a)break;l instanceof Be.Item&&n(l)}}}}function Mn(e,t,n){let o=Be.createDeleteSet();for(let[r,i]of t.clients){let s=e.store.clients.get(r),a=[];for(let{clock:c,len:f}of i){if(!s||s.length===0){a.push({clock:c,len:f});continue}let l=c+f,d=c,p=s[s.length-1];if(c<p.id.clock+p.length)for(let u=Be.findIndexSS(s,c);u<s.length;u+=1){let y=s[u];if(y.id.clock>=l)break;if(!(y instanceof Be.Item)||!n(y))continue;let g=Math.max(c,y.id.clock);g>d&&a.push({clock:d,len:g-d}),d=Math.min(l,y.id.clock+y.length)}l>d&&a.push({clock:d,len:l-d})}a.length>0&&o.clients.set(r,a)}return o}function*Ut(e){for(let t=e._start;t;t=t.right)t.deleted||(yield t)}function*hr(e){for(let t of e._map.values())t.deleted||(yield t)}function Yn(e,t){let n=0;for(let o=e._start;o!==null;o=o.right)if(!(o.deleted||!o.countable)){if(o.id.client===t.client&&t.clock>=o.id.clock&&t.clock<o.id.clock+o.length)return n+(t.clock-o.id.clock);n+=o.length}return-1}function _e(e,t){let n=[],o=0;for(let r=e._start;r!==null&&n.length<t.size;r=r.right)if(!(r.deleted||!r.countable)){for(let i=0;i<r.length;i+=1)t.has(`${r.id.client}:${r.id.clock+i}`)&&n.push(o+i);o+=r.length}for(let r=n.length-1;r>=0;){let i=r;for(;i>0&&n[i-1]===n[i]-1;)i-=1;e.delete(n[i],n[r]-n[i]+1),r=i-1}}var yr=e=>e.left===null;var kr="listed-children",mr=65536;function ao(e){let t=e.meta?.get(kr);return t instanceof Map?t:new Map}function wr(e,t){let n=new Map(ao(t)),o=mr;for(let r of n.values())o-=r.keys.size+r.siblings.length;o<=0||(ae(e.doc,t.insertions,r=>{if(--o<0||r.deleted||!(r.parent instanceof Pt.Array)||!(r.content instanceof Pt.ContentAny))return;let i=r.parent,s=i.parent;if(!(s instanceof Pt.Map)||s.parent!==e.nodes||s.get(I.children)!==i)return;let a=new Set(n.get(i)?.keys);for(let f of r.content.getContent()){if(--o<0)return;typeof f=="string"&&a.add(f)}let c=i.slice(0,mr).filter(f=>typeof f=="string");o-=c.length,o>=0&&n.set(i,{keys:a,siblings:c})}),t.meta.set(kr,n))}import*as lt from"yjs";import*as ne from"yjs";import"yjs";var xr="pptx-case-base-v1",lo="cc.",fo=1<<20,Rn=new WeakMap,Sr=new WeakSet;function br(e){let t=Rn.get(e);if(t)return t;Sr.has(e)||(Sr.add(e),e.observe(()=>Rn.delete(e)));let n=new Map;if(e.size>fo)return n;for(let[o,r]of e){if(!o.startsWith(lo))continue;let i=/^cc\.(\d{1,16}:\d{1,16}):(\d{1,16})$/.exec(o);if(!i||!Array.isArray(r)||r.length!==2)continue;let[s,a]=r,c=Number(i[2]);if(!Number.isSafeInteger(s)||s<0||!Number.isSafeInteger(c)||!Number.isInteger(a)||a<0||a>65535)continue;let f=i[1],l=n.get(f);(!l||s>l.order||s===l.order&&c>l.author)&&n.set(f,{order:s,author:c,value:a})}return Rn.set(e,n),n}function ct(e){let t=e.toString(),n=e.doc;if(!n)return t;let o=n.getMap(xr);if(o.size===0)return t;let r=Ce(e,0,e.length),i=new Map;return r.map((s,a)=>{let c=U(n,s,i),f=z(c.client,c.clock),l=o.get(f);if(typeof l!="number"||!Number.isInteger(l)||l<0||l>65535)return t[a]??"";let d=Z(n,c),p=d&&xe(d);return String.fromCharCode((p&&br(p).get(f)?.value)??l)}).join("")}function Mr(e,t,n){let o=e.doc;if(!o||t.length!==n.length||t===n)return!1;for(let c=0;c<t.length;){let f=String.fromCodePoint(t.codePointAt(c)),l=String.fromCodePoint(n.codePointAt(c));if(f.length!==l.length||f!==l&&f.toUpperCase()!==l&&f.toLowerCase()!==l)return!1;c+=f.length}let r=Ce(e,0,e.length),i=o.getMap(xr),s=new Map,a=[];for(let c=0;c<t.length;c++){if(t[c]===n[c])continue;let f=U(o,r[c]),l=Z(o,f),d=l&&xe(l);if(!d||d.size>=fo)return!1;let p=z(f.client,f.clock),u=(br(d).get(p)?.order??0)+1;if(!Number.isSafeInteger(u))return!1;let y=`${lo}${p}:${o.clientID}`;if(!d.has(y)){let g=s.get(d)??new Set;if(g.add(y),s.set(d,g),d.size+g.size>fo)return!1}a.push({record:d,key:p,order:u,index:c})}for(let{record:c,key:f,order:l,index:d}of a)i.has(f)||i.set(f,t.charCodeAt(d)),c.set(`${lo}${f}:${o.clientID}`,[l,n.charCodeAt(d)]),Rn.delete(c);return!0}var uo="rv.",oe=Object.freeze({copyOf:"ci",newParagraph:"cp",seen:"cs",followed:"cf.",removedRun:"rr."}),Xe="pptx-copies-v1",Yr=1<<20,Or=4096,Wc=1024,Je=32,Pr="http://schemas.openxmlformats.org/drawingml/2006/main",$c="http://schemas.openxmlformats.org/presentationml/2006/main",At=e=>e.local==="txBody"&&(e.ns===Pr||e.ns===$c),z=(e,t)=>`${e}:${t}`,at=e=>Number.isSafeInteger(e)&&e>=0,Rr=new WeakMap;function ie(e){if(!(e instanceof ne.Map))return null;let t=e.get(oe.copyOf),n=Rr.get(e);if(n&&n.value===t)return n.copy;let o=Ar(t,e.get(oe.newParagraph)===!0);return Rr.set(e,{value:t,copy:o}),o}function Ar(e,t){if(!Array.isArray(e)||e.length<5||(e.length-2)%3!==0||e.length>2+3*Yr)return null;let[n,o]=e;if(!at(n)||!at(o))return null;let r=[],i=0;for(let a=2;a<e.length;a+=3){let c=e[a],f=e[a+1],l=e[a+2];if(!at(c)||!at(f)||!at(l)||l===0||(r.push(i),i+=l,i>Yr))return null}let s=e;return{client:n,clock:o,length:i,newParagraph:t,source(a){let c=0,f=r.length-1;for(;c<f;){let d=c+f+1>>1;r[d]<=a?c=d:f=d-1}let l=2+3*c;return ne.createID(s[l],s[l+1]+(a-r[c]))}}}var Ir=new WeakMap;function qt(e){let t=[];if(!(e instanceof ne.Map))return t;let n=[];for(let o of e.keys())o.startsWith(oe.followed)&&n.push(o);for(let o of n.sort().slice(0,Wc)){let r=e.get(o);if(!Array.isArray(r))continue;let i=Ir.get(r);i===void 0&&Ir.set(r,i=Ar(r,!1)),i&&t.push(i)}return t}function Dr(e,t){let n=r=>r!==null&&r.client===t.client&&t.clock>=r.clock&&t.clock<r.clock+r.length,o=ie(e);return n(o)?o:qt(e).find(n)??null}function Cr(e,t,n,o){e.set(`${oe.followed}${z(t,n)}`,[t,n,...Lr(o)])}function Tr(e,t){let n=new Set,o=e.nodes;for(let[r,i]of t.changed){if(r===o){for(let a of i)a!==null&&qt(o.get(a)).length>0&&n.add(a);continue}if(!(r instanceof ne.Map)||r.parent!==o)continue;let s=r.get(I.key);if(typeof s=="string")for(let a of i)a?.startsWith(oe.followed)&&n.add(s)}return n}var Le="pptx-restored-v1",Nr="pptx-delete-clock-v1",Pe="pptx-restored-steps-v1",Dt="pptx-restored-starts-v1";function Ve(e,t){let n=e.getMap(Dt).get(z(t.client,t.clock));return!Array.isArray(n)||n.length!==5||![n[0],n[1],n[3]].every(o=>Number.isSafeInteger(o)&&o>=0)||typeof n[2]!="boolean"||typeof n[4]!="string"?null:{start:ne.createID(n[0],n[1]),enter:n[2],client:n[3],key:n[4]}}function _r(e,t){return Ve(e,t)?.start??null}var Ge=65536,Bc=/^(\d{1,16}):(\d{1,16})$/,In=new WeakMap,Er=new WeakSet;function Xc(e){let t=In.get(e);if(t)return t;Er.has(e)||(Er.add(e),e.observe(()=>In.delete(e))),t=new Map;for(let[n,o]of e.entries()){let r=Bc.exec(n);if(!r||!Array.isArray(o)||o.length!==3||!o.every(at))continue;let[i,s,a]=o;if(a===0||a>Ge)continue;let c=Number(r[1]),f=Number(r[2]);if(!Number.isSafeInteger(c)||!Number.isSafeInteger(f))continue;let l=t.get(c),d=[f,i,s,a];l?l.push(d):t.set(c,[d])}for(let n of t.values())n.sort((o,r)=>o[0]-r[0]);return In.set(e,t),t}function Me(e,t){let n=e.getMap(Le);if(n.size===0)return null;let o=Xc(n).get(t.client);if(!o)return null;let r=0,i=o.length-1;for(;r<i;){let a=r+i+1>>1;o[a][0]<=t.clock?r=a:i=a-1}let s=o[r];return!s||t.clock<s[0]||t.clock>=s[0]+s[3]?null:ne.createID(s[1],s[2]+(t.clock-s[0]))}function Jt(e,t){if(t.length===0)return;let n=e.getMap(Le);for(let o=0;o+3<t.length;o+=4)n.set(z(e.clientID,t[o]),[t[o+1],t[o+2],t[o+3]]);In.delete(n)}function Lr(e){let t=[];for(let n of e){let o=t.length;o>0&&t[o-3]===n.client&&t[o-2]+t[o-1]===n.clock?t[o-1]+=1:t.push(n.client,n.clock,1)}return t}function Vc(e,t){let n=new Set;for(let r=t._start;r!==null;r=r.right)if(n.add(r.id.client),n.size>Or)return null;let o=[];for(let r of[...n].sort((i,s)=>i-s))o.push(r,ne.getState(e.store,r));return o}var vr=new WeakMap;function Fr(e){if(!(e instanceof ne.Map))return null;let t=e.get(oe.seen),n=vr.get(e);(!n||n.value!==t)&&(n={value:t,seen:Gc(t)},vr.set(e,n));let o=n.seen;return o?r=>r.clock<(o.get(r.client)??0):null}function Gc(e){if(!Array.isArray(e)||e.length%2!==0||e.length>2*Or)return null;let t=new Map;for(let n=0;n<e.length;n+=2){let o=e[n],r=e[n+1];if(!at(o)||!at(r)||t.has(o))return null;t.set(o,r)}return t}function Ce(e,t,n){let o=[],r=0;for(let i=e._start;i!==null&&o.length<n;i=i.right)if(!(i.deleted||!i.countable))for(let s=0;s<i.length&&o.length<n;s+=1,r+=1)r>=t&&o.push(ne.createID(i.id.client,i.id.clock+s));return o}function Z(e,t){if(ne.getState(e.store,t.client)<=t.clock)return null;let n=ne.getItem(e.store,t);return n instanceof ne.Item?n:null}function xe(e){let t=e.parent,n=t instanceof ne.Text?t.parent:null;return n instanceof ne.Map?n:null}function Qt(e,t){let n=Z(e,t);return!n||n.deleted}function U(e,t,n,o=!0){let r=z(t.client,t.clock),i=n?.get(r);if(i)return i;let s=t;for(let a=0;a<Je;a+=1){let c=Z(e,s),f=c?Dr(xe(c),s):null;if(f){s=f.source(s.clock-f.clock);continue}let l=o?Me(e,s):null;if(!l)break;s=l}return n?.set(r,s),s}function Ue(e,t,n=new Map){let o=z(t.client,t.clock),r=n.get(o);if(r)return r;let i=t;for(let s=0;s<Je;s+=1){let a=Z(e,i),c=a?Dr(xe(a),i):null;if(c){i=c.source(i.clock-c.clock);continue}let f=e.getMap(Pe).get(z(i.client,i.clock));if(!Array.isArray(f)||f.length!==3&&f.length!==4||f[2]!==!0||!Number.isSafeInteger(f[0])||f[0]<0||!Number.isSafeInteger(f[1])||f[1]<0)break;i=ne.createID(f[0],f[1])}return n.set(o,i),i}var gt=e=>e?.type==="element",En=e=>e.children.filter(gt),ue=(e,t)=>e.ns===Pr&&e.local===t;function zr(e){return En(e).find(n=>ue(n,"t"))?.children.find(n=>n.type==="text")}var Ht=e=>{let t=zr(e);return t?.type==="text"?t.value:""};function Kr(e,t,n,o,r,i){let s=new Set;if(o.size===0||i.size===0)return s;let a=e.doc.getMap(Xe),c=d=>{let p=zr(d);return p?r.get(p.id):void 0},f=(d,p,u)=>{let y=En(d);y.forEach((g,k)=>{if(!ue(g,"r"))return;let x=o.get(g.id);if(!gt(x)||x===g)return;let h=Ht(x),S=Ht(g);if(h.length<=S.length||!h.startsWith(S))return;let w=c(g),m=w===void 0?void 0:i.get(w),b=h.length-S.length;if(!m||m.deleted.length!==b)return;let Y=[],M=0,v=(L,j,D)=>{for(let O=j;O<L.length&&M<b;O+=1){let W=L[O];if(!(!o.has(W.id)&&ue(W,"br"))&&!ue(W,"pPr")){if(ue(W,"endParaRPr"))return!0;if(!ue(W,"r")||o.has(W.id))return!1;Y.push({run:W,newParagraph:D}),M+=Ht(W).length}}return!0},E=v(y,k+1,!1),F=p[u+1],_=y.slice(k+1).every(L=>o.has(L.id)||ue(L,"endParaRPr"));M<b&&E&&_&&F&&ue(F,"p")&&!o.has(F.id)&&v(En(F),0,!0);let T=Y.length>0&&Y.every(L=>L.newParagraph),R=Y.map(L=>Ht(L.run)).join("");if(M>b||M<b&&!(T&&h.endsWith(R)))return;let P=w===void 0?void 0:e.nodes.get(w),C=P instanceof ne.Map?P.get(I.text):void 0,K=C instanceof ne.Text?Vc(e.doc,C):null,A=b-M;for(let L of Y){let j=c(L.run),D=Ht(L.run).length,O=j===void 0?void 0:i.get(j),W=j===void 0?void 0:e.nodes.get(j),B=m.deleted.slice(A,A+D);if(A+=D,!(D===0||!O?.created||O.inserted?.length!==D)&&!(!(W instanceof ne.Map)||j===void 0)){W.set(oe.copyOf,[O.inserted.client,O.inserted.clock,...Lr(B)]),L.newParagraph&&W.set(oe.newParagraph,!0),K&&W.set(oe.seen,K),a.set(j,t);for(let X of B)s.add(z(X.client,X.clock))}}})},l=d=>{if(o.get(d.id)===d)return;let p=En(d);p.forEach((u,y)=>{ue(u,"p")&>(o.get(u.id))&&f(u,p,y)});for(let u of p)l(u)};return l(n),s}function jr(e,t,n,o){let r=[];if(n.size===0)return r;let i=new Set,s=[],a=c=>{let f=n.get(c.id);if(f!==c){for(let l of c.children)i.add(l.id);if(gt(f)){let l=new Set(c.children.map(p=>p.id)),d="";for(let p of f.children)!l.has(p.id)&>(p)&&(ue(p,"r")||ue(p,"p")||ue(p,"tr")||ue(p,"tc"))&&s.push({node:p,from:c,prev:d}),d=o.get(p.id)??d}for(let l of c.children)gt(l)&&a(l)}};a(t);for(let{node:c,from:f,prev:l}of s){if(i.has(c.id))continue;let d=o.get(c.id),p=o.get(f.id),u=p===void 0?void 0:e.nodes.get(p);if((ue(c,"r")&&ue(f,"p")||ue(c,"p")&&At(f)||ue(c,"tr")&&ue(f,"tbl")||ue(c,"tc")&&ue(f,"tr"))&&d!==void 0&&u instanceof ne.Map&&u.set(`${oe.removedRun}${d}`,l),d!==void 0&&(ue(c,"tr")||ue(c,"tc"))){let k=e.nodes.get(d);k instanceof ne.Map&&k.set(`${uo}${e.doc.clientID}`,ne.encodeStateVector(e.doc))}let g=[c];for(;g.length>0;){let k=g.pop();if(k!==c&&i.has(k.id))continue;if(gt(k)){for(let w of k.children)g.push(w);continue}let x=o.get(k.id),h=x===void 0?void 0:e.nodes.get(x),S=h instanceof ne.Map?h.get(I.text):void 0;if(!(!(S instanceof ne.Text)||k.type!=="text"||k.value.length===0)&&ct(S)===k.value){for(let w of Ce(S,0,S.length))r.push(w);S.delete(0,S.length)}}}return r}function Wr(e,t,n=!0){let o=new Map,r=t.changed.get(e.nodes);for(let a of n?t.changed.keys():[]){if(!(a instanceof lt.Text)||!(a.parent instanceof lt.Map))continue;let c=a.parent,f=c.get(I.key),l=c.get(I.part);if(typeof f!="string"||typeof l!="string"||!ie(c))continue;let d=o.get(l)??[];d.includes(f)||d.push(f),o.set(l,d)}let i=e.doc.getMap(Xe),s=new Set(r??[]);for(let[a,c]of t.changed){if(!(a instanceof lt.Map)||a.parent!==e.nodes||!ie(a)||!c.has(oe.copyOf)&&!c.has(oe.newParagraph))continue;let f=a.get(I.key);typeof f=="string"&&s.add(f)}for(let a of t.changed.get(i)??[])typeof a=="string"&&s.add(a);for(let a of s){if(a===null)continue;let c=i.get(a),f=e.nodes.get(a),l=ie(f);if(typeof c!="string"||!l||l.client===e.doc.clientID||f.get(I.part)!==c)continue;let d=o.get(c);d?d.push(a):o.set(c,[a])}return o}function $r(e,t){let n=1048576,o=new Set,r=i=>{let s=i;for(let a=0;a<Je;a+=1){if(--n<0)return!0;let c=`${s.client}:${s.clock}`;if(o.has(c))return!0;let f=Z(e.doc,s);if(!f)return!1;o.add(c);let l=ie(xe(f)),d=l?s.clock-l.clock:-1;if(l&&s.client===l.client&&d>=0&&d<l.length){s=l.source(d);continue}let p=Me(e.doc,s);if(!p)return!0;s=p}return!0};for(let[i,s]of e.doc.getMap(Xe)){if(--n<0)return!0;if(s!==t)continue;let a=e.nodes.get(i),c=ie(a);if(!c||!(a instanceof lt.Map))continue;let f=Z(e.doc,lt.createID(c.client,c.clock));if(!(!f||f.parent!==a.get(I.text))){for(let l=0;l<c.length;l+=1)if(!r(c.source(l)))return!1}}return!0}import{createCollaborationStatusTracker as hl}from"@pptx-editor.dev/core/editor";import*as te from"yjs";import"yjs";function Br(e,t,n,o){let r=U(e,t),i=1<<20;for(let[s,a]of n){if(--i<0)return null;let c=o(s);if(!c)continue;if((i-=c.length)<0)return null;let f=Ce(c,0,c.length);for(let l=0;l<f.length;l++){let d=U(e,f[l]);if(d.client===r.client&&d.clock===r.clock)return{node:a,offset:l,text:c}}}return null}import*as Fe from"yjs";import*as Ct from"yjs";var Xr="http://schemas.openxmlformats.org/drawingml/2006/main",Zt=1<<18,tt=(e,t)=>!("text"in e)&&e.ns===Xr&&e.local===t;function vn(e,t,n,o,r,i,s=o){if(n.length===0)return t;let a=new Map,c=new Map,f=Zt,l=(m,b=0)=>{if(--f<0||b>64){f=-1;return}if(c.set(m.key,b),a.set(m.key,m),!("text"in m))for(let Y of m.children??[])l(Y,b+1)};if(l(t),f<0||n.length>Zt)return t;let d=n.filter(m=>!a.has(m.key)&&!a.has(m.parent));if(d.length===0)return t;let p=new Map,u=e.nodes.get(t.key),y=u instanceof Ct.Map?u.get(I.part):void 0,g=0;for(let[m,b]of e.nodes){if((g+=1)>Zt)return t;let Y=b instanceof Ct.Map&&b.get(I.part)===y?b.get(I.children):void 0;if(Y instanceof Ct.Array)for(let M of Y.toArray()){if((g+=1)>Zt)return t;if(typeof M!="string")continue;let v=p.get(M)??[];v.push(m),p.set(M,v)}}let k=m=>{let b=[m],Y=new Set;for(let M=0;M<64&&b.length>0;M+=1){let v=[];for(let E of b.sort()){if(Y.has(E))continue;if(Y.add(E),Y.size>Zt)return;let F=a.get(E);if(F&&tt(F,"tbl"))return F;v.push(...p.get(E)??[])}b=v}},x=new Map,h=new Map,S=new Set(a.keys());for(let m of d.sort((b,Y)=>b.key<Y.key?-1:b.key>Y.key?1:0)){let b=m.table?a.get(m.table):void 0,Y=b&&tt(b,"tbl")?b:k(m.parent);if(!Y)continue;let M=m.row?a.get(m.row):void 0,E=(M&&tt(M,"tr")?[M]:Y.children??[]).filter(A=>tt(A,"tr")).flatMap(A=>A.children??[]).filter(A=>tt(A,"tc")),F=E.flatMap(A=>[...A.children??[],...h.has(A.key)?[h.get(A.key)]:[]]).find(A=>tt(A,"txBody")),_;if(!F){if(_=E[0],!_||S.has(m.parent))continue;let A=s(m.parent,new Set(S),(c.get(_.key)??64)+1);if(!A||!tt(A,"txBody"))continue;F={...A,children:(A.children??[]).filter(L=>!tt(L,"p"))},c.set(F.key,(c.get(_.key)??64)+1)}let T=e.nodes.get(m.key),R=T instanceof Ct.Map?T.get(I.shell):void 0;if(R?.ns!==Xr||R.local!=="p")continue;let P=o(m.key,S,(c.get(F.key)??64)+1);if(!P||!tt(P,"p"))continue;let C=A=>"text"in A?A.text.length>0:(A.children??[]).some(C);if(!C(P))continue;_&&(h.set(_.key,F),i.add(F.key),r.set(F.key,_.key),S.add(F.key));let K=x.get(F.key)??[];K.push(P),x.set(F.key,K),i.add(m.key),r.set(m.key,F.key)}if(x.size===0)return t;let w=m=>({...m,children:[...h.has(m.key)?[w(h.get(m.key))]:[],...(m.children??[]).map(b=>"text"in b?b:w(b)),...x.get(m.key)??[]]});return w(t)}var Vr="http://schemas.openxmlformats.org/drawingml/2006/main",Gr=65536;function Ur(e,t,n,o,r){let i=Gr,s=new Map,a=[],c=w=>e.nodes.get(w),f=w=>{let m=c(w),b=m instanceof Fe.Map?m.get(I.shell):void 0;return b?.ns===Vr&&typeof b.local=="string"?b.local:void 0},l=w=>{let m=c(w),b=m instanceof Fe.Map?m.get(I.children):void 0;return!(b instanceof Fe.Array)||(i-=b.length)<0?[]:b.toArray().filter(Y=>typeof Y=="string")},d=(w,m)=>{let b=c(w);if(!(b instanceof Fe.Map))return[];let Y=[];for(let[M,v]of b){if(--i<0)return[];if(!M.startsWith(oe.removedRun)||typeof v!="string")continue;let E=M.slice(oe.removedRun.length);f(E)===m&&Y.push(E)}return Y.sort()},p=w=>{let m=c(w),b=[];if(!(m instanceof Fe.Map))return b;for(let[Y,M]of m){if(--i<0)return[];if(Y.startsWith(uo)){if(!(M instanceof Uint8Array)||(i-=M.length)<0)return i=-1,[];try{b.push(Fe.decodeStateVector(M))}catch{return i=-1,[]}}}return b},u=(w,m,b,Y)=>{let M=p(b);if(M.length)for(let v of l(w).filter(E=>f(E)==="txBody"))for(let E of[...l(v),...d(v,"p")])f(E)==="p"&&(a.push({key:E,parent:v,table:m,...Y?{row:Y}:{}}),s.set(E,[...s.get(E)??[],...M]))},y=(w,m=0)=>{if(--i<0||m>64){i=-1;return}if(w.ns===Vr&&w.local==="tbl"){for(let b of d(w.key,"tr"))for(let Y of l(b).filter(M=>f(M)==="tc"))u(Y,w.key,b);for(let b of l(w.key).filter(Y=>f(Y)==="tr"))for(let Y of d(b,"tc"))u(Y,w.key,Y,b)}for(let b of w.children??[])"text"in b||y(b,m+1)};if(y(t),i<0)return t;let g=[...new Map(a.map(w=>[w.key,w])).values()],k=(w,m,b)=>{let Y=n(w,m,b),M=s.get(w)??[];if(!Y||!M.length)return null;let v=E=>{for(let F of E.children??[]){if(!("text"in F)){if(v(F))return!0;continue}let _=c(F.key),T=_ instanceof Fe.Map?_.get(I.text):void 0;if(!(!(T instanceof Fe.Text)||T.length>Gr))for(let R of Ce(T,0,T.length)){if((i-=1+M.length)<0)return!1;let P=U(e.doc,R);if(M.every(C=>P.clock>=(C.get(P.client)??0)))return!0}}return!1};return v(Y)?Y:null},x=new Map,h=new Set,S=vn(e,t,g,k,x,h,n);if(i<0)return t;for(let[w,m]of x)o.set(w,m);for(let w of h)r.add(w);return S}import*as V from"yjs";import*as Ae from"yjs";var po=4096,Hr="http://schemas.openxmlformats.org/drawingml/2006/main",Uc=e=>e.type==="element";function Tt(e,t){let n=Z(e,t);if(!n)return null;let o=0,r=po;for(let i=n.parent instanceof Ae.Text?n.parent._start:null;i&&--r>=0;i=i.right){if(i===n)return{text:n.parent,at:o+(t.clock-n.id.clock)};o+=i.length}return null}function Hc(e,t){let n=t,o=0,r=po;for(let i=0;i<Je;i+=1){let s=Z(e,n),a=Tt(e,n);if(!s||!a)return null;let c=ie(xe(s));if(!c)return{text:a.text,at:a.at+o};let f=n.clock-c.clock;if(n.client===c.client&&f>=0&&f<c.length){n=c.source(f);continue}let l=null,d=null;for(let u=0;u<c.length&&r-- >0;u+=1){let y=Tt(e,Ae.createID(c.client,c.clock+u));if(!(!y||y.text!==a.text))if(y.at<a.at)l=u;else{d=u;break}}let p=l??d;if(p===null)return{text:a.text,at:a.at+o};o=(l!==null?.5:-.5)+o/2,n=c.source(p)}return null}function Nt(e,t){let n=new Map,o=e.package.parts.get(t);if(o?.kind!=="xml")return n;let r=(i,s,a)=>{let c=e.keyOf(t,i.id),f=i.ns===Hr&&i.local==="p"&&c&&a?{p:{key:c,parent:a}}:i.ns===Hr&&i.local==="r"&&c?{...s,run:c}:s;for(let l of i.children)if(Uc(l))r(l,f,c);else{let d=e.keyOf(t,l.id);d!==void 0&&n.set(d,{order:n.size,...f})}};return r(o.xml.root,{},void 0),n}function en(e,t){let n=new Map,o=u=>{let y=`${u.client}:${u.clock}`;return n.has(y)||n.set(y,Tt(e,u)),n.get(y)},r=(u,y)=>{let g=o(u),k=o(y);return g&&k&&g.text===k.text?g.at-k.at:null},i=new Map,s=u=>{let y=`${u.client}:${u.clock}`;return i.has(y)||i.set(y,Hc(e,u)),i.get(y)},a=(u,y)=>{let g=s(u.start),k=s(y.start);return g&&k&&g.text===k.text?g.at-k.at:0},c=(u,y)=>r(u.from,y.from)??a(u,y),f=u=>t.get(u.key)?.order??-1,l=(u,y)=>r(u.start,y.start)!==0?0:+!!u.enter-+!!y.enter||(u.enter&&y.enter?(u.client??0)-(y.client??0):0),d=(u,y)=>u.client!==void 0&&y.client!==void 0?y.client-u.client||(u.key<y.key?1:u.key>y.key?-1:0):f(u)-f(y);return{laterStart:c,laterRoot:a,ahead:(u,y)=>(a(u,y)||c(u,y)||l(u,y)||d(u,y))>=0,shown:u=>t.has(u)}}function go(e,t){if(t.newParagraph)return!0;let n=t.source(0);for(let o=0;o<Je;o+=1){let r=Z(e,n),i=r?ie(xe(r)):null,s=i?n.clock-i.clock:-1;if(!i||n.client!==i.client||s<0||s>=i.length)return!1;if(i.newParagraph)return!0;n=i.source(s)}return!1}function qc(e,t){let n=Oe(t.parent);return n&&n.parent===e.nodes&&typeof n.parentSub=="string"?n.parentSub:null}function On(e,t,n){let o=Ae.createID(e.id.client,e.id.clock+t),r=e.parent instanceof Ae.Text?e.parent.doc:null,i=r?_r(r,o):null;if(i)return i;let s=0,a=e,c=t-1;for(;a!==null&&s++<po;){if(!a.deleted&&a.countable)for(;c>=0;c-=1,s+=1){let f=Ae.createID(a.id.client,a.id.clock+c);if(!n(f))return o;o=f}a=a.left,c=a?a.length-1:-1}return o}function Pn(e,t,n,o,r,i,s=o){let a=e.doc,c=qc(e,n);if(c===null||!t.shown(c)||r.length===0)return!1;let f=U(a,s,i),l=(y,g)=>{let k=g;for(let x=0;x<Je;x+=1){let h=a.getMap(Pe).get(`${k.client}:${k.clock}`),S=Array.isArray(h)&&Number.isSafeInteger(h[0])&&Number.isSafeInteger(h[1])?Ae.createID(h[0],h[1]):Me(a,k);if(!S||Ae.compareIDs(S,k))return!1;if(Ae.compareIDs(S,y))return!0;k=S}return!1};for(let{copy:y}of r)for(let g=0;g<y.length;g+=1){let k=y.source(g);if(Ae.compareIDs(U(a,k,i),f))for(let x=0;x<Je;x+=1){if(Ae.compareIDs(k,s))return!1;let h=Me(a,k);if(h){if(!l(k,s))return!1;let b=a.getMap(Pe).get(`${k.client}:${k.clock}`);k=Array.isArray(b)&&Number.isSafeInteger(b[0])&&Number.isSafeInteger(b[1])?Ae.createID(b[0],b[1]):h;continue}let S=Z(a,k),w=S?ie(xe(S)):null,m=w?k.clock-w.clock:-1;if(!w||k.client!==w.client||m<0||m>=w.length)break;k=w.source(m)}}let d=a.getMap(Pe).get(`${s.client}:${s.clock}`);if(Array.isArray(d)&&d[2]===!1)return!0;let p=Ve(a,s),u={key:p?.key??c,from:qr(a,o),start:U(a,o,i),enter:p?.enter,client:p?.client};return!r.some(y=>t.ahead(ho(a,y,i),u))}function ho(e,t,n){let o=t.copy.source(0);return{key:t.key,from:qr(e,o),start:U(e,o,n),enter:go(e,t.copy),client:t.copy.client}}function qr(e,t){let n=t;for(let o=0;o<Je;o+=1){let r=Me(e,n);if(!r)break;n=r}return n}import*as De from"yjs";import{asciiFold as Jc}from"@pptx-editor.dev/core/store";var mo="http://schemas.openxmlformats.org/drawingml/2006/main",es="http://schemas.openxmlformats.org/presentationml/2006/main",N=e=>[e,[e]],ke=(e,t)=>[e,t],nn=["*",[]],on=ke("fill",["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]),Qc=ke("fill",["noFill","solidFill","gradFill","pattFill"]),Dn=ke("effect",["effectLst","effectDag"]),Zc=[ke("color",["scrgbClr","srgbClr","hslClr","sysClr","schemeClr","prstClr"])],Jr=[N("xfrm"),ke("geometry",["custGeom","prstGeom"]),on,N("ln"),Dn,N("scene3d"),N("sp3d"),N("extLst")],Qr=[Qc,ke("dash",["prstDash","custDash"]),ke("join",["round","bevel","miter"]),N("headEnd"),N("tailEnd"),N("extLst")],yo=[N("ln"),on,Dn,N("highlight"),ke("uLn",["uLnTx","uLn"]),ke("uFill",["uFillTx","uFill"]),N("latin"),N("ea"),N("cs"),N("sym"),N("hlinkClick"),N("hlinkMouseOver"),N("rtl"),N("extLst")],tn=e=>[N("cNvPr"),N(e),N("nvPr")],An=e=>[N(e),N("extLst")],ko=["lnL","lnR","lnT","lnB","lnTlToBr","lnBlToTr"],ea=Object.assign(Object.create(null),{sld:[N("cSld"),N("clrMapOvr"),N("transition"),N("timing"),N("extLst")],cSld:[N("bg"),N("spTree"),N("custDataLst"),N("controls"),N("extLst")],bg:[ke("background",["bgPr","bgRef"])],bgPr:[on,Dn,N("extLst")],spPr:Jr,grpSpPr:Jr,ln:Qr,...Object.fromEntries(ko.map(e=>[e,Qr])),effectLst:[N("blur"),N("fillOverlay"),N("glow"),N("innerShdw"),N("outerShdw"),N("prstShdw"),N("reflection"),N("softEdge")],...Object.fromEntries(["solidFill","outerShdw","innerShdw","prstShdw","glow","highlight","extrusionClr","contourClr","buClr","lnRef","fillRef","effectRef","fontRef"].map(e=>[e,Zc])),scene3d:[N("camera"),N("lightRig"),N("backdrop"),N("extLst")],camera:[N("rot")],lightRig:[N("rot")],sp3d:[N("bevelT"),N("bevelB"),N("extrusionClr"),N("contourClr"),N("extLst")],style:[N("lnRef"),N("fillRef"),N("effectRef"),N("fontRef")],sp:[N("nvSpPr"),N("spPr"),N("style"),N("txBody"),N("extLst")],pic:[N("nvPicPr"),N("blipFill"),N("spPr"),N("style"),N("extLst")],cxnSp:[N("nvCxnSpPr"),N("spPr"),N("style"),N("extLst")],grpSp:[N("nvGrpSpPr"),N("grpSpPr"),nn,N("extLst")],graphicFrame:[N("nvGraphicFramePr"),N("xfrm"),N("graphic"),N("extLst")],nvSpPr:tn("cNvSpPr"),nvPicPr:tn("cNvPicPr"),nvCxnSpPr:tn("cNvCxnSpPr"),nvGrpSpPr:tn("cNvGrpSpPr"),nvGraphicFramePr:tn("cNvGraphicFramePr"),cNvPr:[N("hlinkClick"),N("hlinkHover"),N("extLst")],nvPr:[N("ph"),ke("media",["audioCd","wavAudioFile","audioFile","videoFile","quickTimeFile"]),N("custDataLst"),N("extLst")],cNvSpPr:An("spLocks"),cNvPicPr:An("picLocks"),cNvGrpSpPr:An("grpSpLocks"),cNvGraphicFramePr:An("graphicFrameLocks"),cNvCxnSpPr:[N("cxnSpLocks"),N("stCxn"),N("endCxn"),N("extLst")],xfrm:[N("off"),N("ext"),N("chOff"),N("chExt")],blipFill:[N("blip"),N("srcRect"),ke("fillMode",["tile","stretch"])],txBody:[N("bodyPr"),N("lstStyle"),nn],bodyPr:[N("prstTxWarp"),ke("autofit",["noAutofit","normAutofit","spAutoFit"]),N("scene3d"),ke("text3d",["sp3d","flatTx"]),N("extLst")],p:[N("pPr"),nn,N("endParaRPr")],r:[N("rPr"),N("t")],fld:[N("rPr"),N("pPr"),N("t")],br:[N("rPr")],pPr:[N("lnSpc"),N("spcBef"),N("spcAft"),ke("buClr",["buClrTx","buClr"]),ke("buSz",["buSzTx","buSzPct","buSzPts"]),ke("buFont",["buFontTx","buFont"]),ke("bullet",["buNone","buAutoNum","buChar","buBlip"]),N("tabLst"),N("defRPr"),N("extLst")],rPr:yo,defRPr:yo,endParaRPr:yo,tbl:[N("tblPr"),N("tblGrid"),nn],tblPr:[on,Dn,ke("tableStyle",["tableStyle","tableStyleId"]),N("extLst")],tc:[N("txBody"),N("tcPr"),N("extLst")],tcPr:[...ko.map(N),N("cell3D"),on,N("headers"),N("extLst")]}),So=e=>e.ns===mo||e.ns===es,ta=new Set(["sld","cSld","bg","bgPr","sp","pic","cxnSp","grpSp","graphicFrame","nvSpPr","nvPicPr","nvCxnSpPr","nvGrpSpPr","nvGraphicFramePr","nvPr","style"]);function ts(e){if(!(!So(e)||ta.has(e.local)&&e.ns!==es))return ea[e.local]}function ns(e,t){return So(t)?e.findIndex(([,n])=>n.includes(t.local)):-1}var na=new Set(["pPr","rPr","defRPr","endParaRPr","bodyPr","txBody","tblPr","tcPr","ln",...ko]);function os(e){return So(e)&&na.has(e.local)}function oa(e,t){let n=ts(e),o=n?ns(n,t):-1;return o<0?void 0:n[o][0]}var ra=(e,t)=>e.ns===mo&&e.local==="tc"&&t.ns===mo&&t.local==="txBody",sa="http://schemas.openxmlformats.org/package/2006/content-types",ia="http://schemas.openxmlformats.org/package/2006/relationships",ca=Object.assign(Object.create(null),{[`${sa}|Types`]:{Default:{attr:"Extension",caseless:!0},Override:{attr:"PartName",caseless:!0}},[`${ia}|Relationships`]:{Relationship:{attr:"Id",caseless:!1}}});function _t(e,t,n){let o=ca[`${e.ns}|${e.local}`];if(o&&Object.prototype.hasOwnProperty.call(o,t.local)){let{attr:i,caseless:s}=o[t.local],a=n(i);return a===void 0?void 0:{slot:`${t.local}:${s?Jc(a):a}`,rule:"key"}}let r=oa(e,t);if(!(r===void 0||ra(e,t)))return{slot:r,rule:os(t)?"merge":"first"}}function ht(e,t,n){let o=ts(e);if(!o)return t;let r=o.indexOf(nn),i=-1,s=!0,a=t.map((c,f)=>{let l=n(c),d=l?ns(o,l):-1,p=d>=0?d:r>=0?r:i;return p<i&&(s=!1),i=p,{c,rank:p,i:f}});return s?t:a.sort((c,f)=>c.rank-f.rank||c.i-f.i).map(c=>c.c)}var Lt=e=>`${e.ns}${lr}${e.local}`,Te=e=>e.slice(0,Math.max(0,e.indexOf("."))),Cn="_",Zr=e=>e.slice(e.indexOf(".")+1).startsWith(Cn);function rs(e,t){let n=e.get(t);return n||(n={merge:!1,companions:[],attrFrom:new Map,childFrom:new Map,shadowed:new Map},e.set(t,n)),n}var wo=(e,t)=>e.attrs?.find(n=>n.ns===""&&n.local===t)?.value;function aa(e,t,n){let o=rs(n,e.key);o.merge=!0;let r=new Map;for(let p of e.attrs??[])r.set(Lt(p),p);let i=p=>"text"in p?void 0:_t(e,p,u=>wo(p,u))?.slot,s=e.children??[],a=new Set(s.map(i)),c=[...s],f=new Map;for(let p of t){o.companions.push(p.key);for(let u of p.attrs??[]){let y=Lt(u);r.has(y)||(r.set(y,u),o.attrFrom.set(y,p.key))}for(let u of p.children??[]){if("text"in u)continue;let y=i(u);if(y===void 0){c.push(u),f.set(u.key,p.key);continue}if(a.has(y)&&!os(u)){o.shadowed.set(u.key,y);continue}a.add(y),c.push(u),f.set(u.key,p.key)}}let l=xo(e,c,n);if(!l)return null;for(let p of l){let u="text"in p?void 0:f.get(p.key);u!==void 0&&o.childFrom.set(p.key,u)}let d=ht(e,l,p=>"text"in p?void 0:p);return{...e,attrs:[...r.values()],children:[...d]}}function xo(e,t,n){let o=new Map,r=[],i=new Map;for(let s of t){let a="text"in s?void 0:_t(e,s,p=>wo(s,p)),c=a?o.get(a.slot):void 0,f=c===void 0?void 0:r[c],l=f!==void 0&&!(Zr(f.key)&&Zr(s.key));if(a&&c===void 0&&o.set(a.slot,r.length),!l){r.push(s);continue}let d=i.get(c);if(d||i.set(c,d=[]),d.length>=Vt.maxCopiesPerGroup)return null;d.push(s)}for(let[s,a]of i){let c=r[s];if(_t(e,c,f=>wo(c,f))?.rule==="merge"){let f=aa(c,a,n);if(!f)return null;r[s]=f}else{let f=rs(n,c.key);for(let l of a)f.companions.push(l.key)}}return r}function ss(e,t,n){let o=new Map,r=new Map;for(let[i,s]of e){if(Te(i)!==n(s.group))continue;let a=t.get(i)?.order;if(a===void 0)continue;let c=o.get(s.group)??[];c.push({key:i,at:s.at,order:a,rank:c.length}),o.set(s.group,c);let f=r.get(s.group);(f===void 0||a>t.get(f).order)&&r.set(s.group,i)}for(let i of o.values())i.sort((s,a)=>s.at-a.at||s.order-a.order||a.rank-s.rank);return{last:r,preceding(i,s){let a=o.get(i);if(!a)return;let c=0,f=a.length;for(;c<f;){let l=c+Math.floor((f-c)/2);a[l].at<=s?c=l+1:f=l}return a[c-1]?.key}}}var $=Object.freeze({splitFrom:"sf",splitBaseText:"sb",splitAt:"sa",splitLength:"sl",splitGeneration:"sg",splitEdited:"se",copyWinner:"cw",splitBreak:"sk",movedFrom:"mf",movedIndex:"mi",movedClock:"mq",movedTo:"mt",movedEarlier:"mo",removedWith:"rw"}),yt="pptx-pieces-v1",St="pptx-moves-v1",Tn="pptx-splits-v1",mt=2e4,Nn=64,fs=`${$.removedWith}.`,Io=2**31,_n=300,Eo=8,Ft=4096,kt=e=>Number.isSafeInteger(e)&&e>=0,la=e=>Number.isSafeInteger(e)&&e>=1&&e<Io,ds="http://schemas.openxmlformats.org/drawingml/2006/main",cn=new Set,Qe=e=>e?.type==="element",an=e=>e===$.removedWith||e.startsWith(fs);function we(e){for(let t of e.keys())if(an(t))return!0;return!1}function is(e,t,n){e.set(`${fs}${t}`,n)}var Mo=e=>e.children.filter(Qe);function rn(e){let n=Mo(e).find(o=>o.local==="t")?.children.find(o=>o.type==="text");return n?.type==="text"?n.value:""}function us(e){if(!e||"text"in e)return"";let t=e.children?.find(o=>!("text"in o)&&o.local==="t"),n=t&&!("text"in t)?t.children?.find(o=>"text"in o):void 0;return n&&"text"in n?n.text:""}function ps(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t.toString(36)}function Yo(e,t,n,o){let r=`${e}\0${ps(t)}\0${n}`;return o===void 0?r:`${r}\0${o}`}var cs=e=>{let t=Number.parseInt(e,36);return Number.isFinite(t)?t:Number.MAX_SAFE_INTEGER};function gs(e,t,n,o,r){if(o.size===0)return;let i=h=>{let S=r.get(h),w=S===void 0?void 0:e.nodes.get(S);return w instanceof De.Map?w:void 0},s=e.doc.clientID.toString(36),a=new Map,c=[],f=new Set,l=new Set,d=h=>{for(let S of Mo(h)){if(S.local!=="r"||l.has(S.id))continue;let w=o.get(S.id);if(!Qe(w)||w===S||rn(w)===rn(S))continue;let m=i(S.id);m&&typeof m.get($.splitFrom)=="string"&&m.get($.splitEdited)!==!0&&m.set($.splitEdited,!0)}},p=h=>{let S=Mo(h);S.forEach((w,m)=>{if(w.local!=="r"||!o.has(w.id))return;let b=o.get(w.id);if(!Qe(b)||b===w)return;let Y=rn(b),M=rn(w);if(Y.length<=M.length||!Y.startsWith(M))return;let v=Y.slice(M.length),E=[],F="",_=[];for(let C=m+1;C<S.length&&F.length<v.length;C+=1){let K=S[C];if(K.local==="br"&&!o.has(K.id)){_.push({el:K,at:M.length+F.length});continue}if(K.local!=="r"||o.has(K.id))break;let A=rn(K);E.push({el:K,at:M.length+F.length,length:A.length}),F+=A}let T=r.get(w.id);if(F!==v||T===void 0||E.length===0)return;l.add(w.id);let R=`${T}\0${ps(Y)}`,P=Math.min((hs(e).latest.get(R)??0)+1,Io-1);for(let{el:C,at:K,length:A}of E){let L=i(C.id);if(!L||L.has($.splitFrom))continue;L.set($.splitFrom,T),L.set($.splitBaseText,Y),L.set($.splitAt,K),L.set($.splitLength,A),L.set($.splitGeneration,P);let j=r.get(C.id);j!==void 0&&e.doc.getMap(yt).set(j,t)}for(let{el:C,at:K}of _){let A=i(C.id);!A||A.has($.splitBreak)||(A.set($.splitBreak,Yo(T,Y,P)),A.set($.splitAt,K))}e.doc.getMap(Tn).set(Yo(T,Y,P,s),M.length)})},u=(h,S)=>{let w=o.get(h.id);if(w===h)return;let m=r.get(h.id),b=m===void 0?S:[m,...S].slice(0,_n),Y=Qe(w)?new Set(w.children.map(M=>M.id)):new Set;for(let M of h.children)f.add(M.id),!Y.has(M.id)&&o.has(M.id)&&c.push({node:M,path:b});if(Qe(w)){let M=new Set(h.children.map(v=>v.id));for(let v of w.children)M.has(v.id)||a.set(v.id,v)}h.ns===ds&&h.local==="p"&&Qe(w)&&(p(h),d(h));for(let M of h.children)Qe(M)&&u(M,b)};if(u(n,[]),c.length>0){let h=new Map;for(let m of o.values())Qe(m)&&m.children.forEach((b,Y)=>h.set(b.id,{parent:m.id,index:Y}));let S=e.doc.getMap(St),w=De.getState(e.doc.store,e.doc.clientID);for(let{node:m,path:b}of c){let Y=h.get(m.id),M=Y===void 0?void 0:r.get(Y.parent),v=r.get(m.id),E=i(m.id);if(!E||!Y||M===void 0||v===void 0)continue;let F=E.get($.movedFrom);if(typeof F=="string"&&F!==M){let _=E.get($.movedEarlier),T=Array.isArray(_)?_.filter(R=>typeof R=="string"&&R!==F):[];E.set($.movedEarlier,[F,...T].slice(0,Eo))}E.set($.movedFrom,M),E.set($.movedIndex,Y.index),E.set($.movedClock,w),E.set($.movedTo,b),S.set(v,t)}}let y=e.doc.getMap(yt),g,k,x=h=>(g??=as(n,r)).has(h);for(let[h,S]of a){if(f.has(h))continue;let w=new Set,m=[S];for(;m.length>0&&w.size<=mt;){let v=m.pop(),E=r.get(v.id);if(E!==void 0&&w.add(E),Qe(v))for(let F of v.children)f.has(F.id)||m.push(F)}let b=r.get(h);b!==void 0&&da(e,b,w,x);let Y=i(h);if(!Y||w.size>mt)continue;let M=[...w];is(Y,s,M);for(let v of w){if(v===b||!y.has(v)||(g??=as(n,r)).has(v))continue;let E=e.nodes.get(v);!(E instanceof De.Map)||we(E)||(k??=new Set([...o.keys()].flatMap(F=>r.get(F)??[])),!(!k.has(v)&&fa(e,t,E,g))&&is(E,s,[v]))}}}function as(e,t){let n=new Set,o=[e];for(;o.length>0;){let r=o.pop(),i=t.get(r.id);if(i!==void 0&&n.add(i),Qe(r))for(let s of r.children)o.push(s)}return n}function fa(e,t,n,o){let r=wt(n),i=r?zt(e)(r.group):void 0;if(!r||i===void 0)return!1;let s=0;for(let[a,c]of e.doc.getMap(yt).entries())if(!(c!==t||Te(a)!==i||!o.has(a))&&((s+=1)>Ft||wt(e.nodes.get(a))?.group===r.group))return!0;return!1}function da(e,t,n,o){let r=[t],i=new Set;for(;r.length>0&&n.size<=mt;){let s=r.pop();if(i.has(s))continue;i.add(s),n.add(s);let a=e.nodes.get(s),c=a instanceof De.Map?a.get(I.children):void 0;if(c instanceof De.Array)for(let f of c.toArray())typeof f=="string"&&!i.has(f)&&!o(f)&&r.push(f)}}var bo=new WeakMap,ls=new WeakSet;function hs(e){let t=e.doc.getMap(Tn),n=bo.get(t);if(n)return n;let o={groups:new Map,latest:new Map};for(let[r,i]of t.entries()){let s=r.split("\0");if(!kt(i)||s.length!==4)continue;let[a,c,f,l]=s,d=Number(f);if(!Number.isSafeInteger(d)||d<1||d>=Io)continue;let p=`${a}\0${c}`,u=`${p}\0${d}`,y=o.groups.get(u);y||o.groups.set(u,y=new Map),y.set(l,i),o.latest.set(p,Math.max(o.latest.get(p)??0,d))}return bo.set(t,o),ls.has(t)||(ls.add(t),t.observe(()=>bo.delete(t))),o}function wt(e){if(!(e instanceof De.Map))return null;let t=e.get($.splitFrom),n=e.get($.splitBaseText),o=e.get($.splitAt),r=e.get($.splitLength),i=e.get($.splitGeneration);return typeof t!="string"||typeof n!="string"||!kt(o)||!kt(r)||!la(i)?null:{from:t,group:Yo(t,n,i),original:n.slice(o,o+r),at:o,edited:e.get($.splitEdited)===!0,copyWinner:e.get($.copyWinner)===!0}}function zt(e){let{groups:t}=hs(e),n=new Map;return o=>{if(n.has(o))return n.get(o);let r=t.get(o),i;if(r&&r.size>=2){let s;for(let[a,c]of r)(!s||c<s[1]||c===s[1]&&cs(a)<cs(s[0]))&&(s=[a,c]);i=s?.[0]}return n.set(o,i),i}}function ys(e,t,n){let o=new Map,r=new Set,i=s=>{let a=o.get(s);if(a!==void 0||o.has(s))return a??null;let c=t(s);if(!c||c.edited||r.has(s)||r.size>Ft)return null;r.add(s);let f=n(s);for(let l of e.get(s)??[]){let d=i(l);if(d===null){f=null;break}f+=d}return r.delete(s),o.set(s,f),f};return i}function Ro(e){let t=new Map;for(let[o,r]of e){let i=t.get(r.from);i?i.push([o,r.at]):t.set(r.from,[[o,r.at]])}let n=new Map;for(let[o,r]of t)n.set(o,r.sort((i,s)=>i[1]-s[1]||(i[0]<s[0]?-1:i[0]>s[0]?1:0)).map(([i])=>i));return n}function ms(e,t){let n=0;for(let o=0;o<t.length&&n<e.length;o+=1)t[o]===e[n]&&(n+=1);return n===e.length}function ks(e,t,n,o,r=cn){if(t.ns!==ds||t.local!=="p")return n;let i=new Map,s=new Map;for(let u of n){if("text"in u)continue;let y=wt(e.nodes.get(u.key));if(y){if(i.size>=Ft)return n;i.set(u.key,y),s.set(u.key,us(u))}}if(i.size===0)return n;let a=Ro(i),c=ys(a,u=>i.get(u),u=>s.get(u)??""),f=zt(e),l=new Set;for(let[u,y]of i){let g=f(y.group);if(g===void 0||Te(u)===g||r.has(y.group))continue;let k=c(u);k!==null&&ms(k,y.original)&&!(y.copyWinner&&k.length>0)&&l.add(u)}if(l.size===0)return n;let d=[...l];for(;d.length>0;)for(let u of a.get(d.pop())??[])!l.has(u)&&!(i.get(u)?.copyWinner&&(s.get(u)?.length??0)>0)&&(l.add(u),d.push(u));for(let u of l)o.add(u);let p=n.filter(u=>"text"in u||!l.has(u.key));return ua(e,p,l,i,f)}function ua(e,t,n,o,r){let i=new Set;for(let f of n){let l=o.get(f);l&&i.add(`${l.group}\0${Te(f)}`)}let s=new Map;for(let f of t){if("text"in f||f.local!=="br")continue;let l=e.nodes.get(f.key);if(!(l instanceof De.Map))continue;let d=l.get($.splitBreak),p=l.get($.splitAt);if(typeof d!="string"||!kt(p)||!i.has(`${d}\0${Te(f.key)}`))continue;let u;for(let y of t){let g="text"in y?void 0:o.get(y.key);!g||g.group!==d||Te(y.key)!==r(d)||g.at<p||(!u||g.at<u[1])&&(u=[y.key,g.at])}u&&s.set(f.key,u[0])}if(s.size===0)return t;let a=new Map;for(let f of t){let l=s.get(f.key);if(l===void 0)continue;let d=a.get(l);d?d.push(f):a.set(l,[f])}let c=[];for(let f of t)if(!s.has(f.key)){for(let l of a.get(f.key)??[])c.push(l);c.push(f)}return c}function vo(e,t,n){if(!n||n.size===0)return t;let o=new Set(t),r=[...t],i=-1;for(let s of e){let a=r.indexOf(s);if(a>=0&&o.has(s)){i=a;continue}!n.has(s)||o.has(s)||(r.splice(i+1,0,s),i+=1)}return r}function ws(e,t,n,o,r=cn){let i=e.doc.getMap(yt);if(i.size===0)return n;let s=new Map,a=R=>{(R.children??[]).forEach((P,C)=>{s.set(P.key,{parent:R,at:C,order:s.size}),"text"in P||a(P)})};a(n);let c=new Map;for(let[R,P]of i.entries()){if(P!==t)continue;let C=e.nodes.get(R);if(!(C instanceof De.Map)||we(C))continue;let K=wt(C);K&&(c.size>=Ft&&(s.has(R)||c.size>=2*Ft)||c.set(R,K))}let f=zt(e),l=new Map,d=R=>{let P=l.get(R);if(P===void 0){let C=s.get(R);P=us(C?C.parent.children[C.at]:o(R,new Set,1)??void 0),l.set(R,P)}return P},p=ys(Ro(c),R=>c.get(R),d),u=ss(c,s,f),y=new Map,g=R=>{let P=c.get(R).from;P!==R&&y.set(R,P)},k=[];for(let R of[...c.keys()].sort()){let P=c.get(R),C=f(P.group);if(C===void 0||Te(R)===C){r.has(R)&&!s.has(R)&&k.push(R);continue}let K=p(R);if(K!==null&&ms(K,P.original)&&!(P.copyWinner&&K.length>0))continue;let A=u.preceding(P.group,P.at)??(s.has(P.from)?P.from:u.last.get(P.group));A!==void 0&&A!==R&&y.set(R,A)}let x=new Set(k);for(let R of k){let P=c.get(R).from;(s.has(P)||x.has(P))&&g(R)}let h=Ro(c),S=[...y.keys()];for(;S.length>0;)for(let R of h.get(S.pop())??[])!y.has(R)&&s.has(R)&&(g(R),S.push(R));if(y.size===0)return n;let w=new Map,m=new Set(s.keys());for(let R of y.keys()){let P=s.get(R),C=P?P.parent.children[P.at]:o(R,m,1);C&&w.set(R,C)}let b=new Map,Y=R=>{let P=b.get(R);if(P!==void 0)return P;let C=y.get(R);b.set(R,!1);let K=C===void 0?s.has(R):w.has(R)&&Y(C);return b.set(R,K),K},M=new Map,v=new Set;for(let[R,P]of y){let C=w.get(R);if(!C||!Y(R))continue;v.add(R);let K=M.get(P);K?K.push(C):M.set(P,[C])}if(v.size===0)return n;let E=(R,P)=>{let C=c.get(P);return C?.from===R?C.at:1/0};for(let[R,P]of M)P.sort((C,K)=>E(R,C.key)-E(R,K.key)||(C.key<K.key?-1:C.key>K.key?1:0));let F=new Set,_=(R,P)=>{for(let C of M.get(R)??[])F.has(C.key)||(F.add(C.key),P.push(C),_(C.key,P))},T=R=>{let P=[];for(let C of R.children??[])v.has(C.key)||(P.push("text"in C?C:T(C)),_(C.key,P));return{...R,children:P}};return T(n)}var sn=Object.freeze({unseenWinners:cn,lost:cn});function ln(e,t,n,o=cn){let r=e.doc.getMap(yt);if(r.size===0)return sn;let i=zt(e),s=new Set,a=new Map,c=0;for(let[k,x]of r.entries()){if(x!==t)continue;let h=e.nodes.get(k);if(!(h instanceof De.Map)||h.get(I.part)!==t)continue;let S=wt(h);if(S){if(we(h)){Te(k)===i(S.group)&&s.add(S.group);continue}if((c+=1)>Ft)return sn;a.set(k,S)}}if(a.size===0)return sn;let f=new Set,l=[n];for(;l.length>0;){let k=l.pop();if(f.has(k))continue;f.add(k);let x=e.nodes.get(k);if(!(x instanceof De.Map)||x.get(I.part)!==t)continue;let h=x.get(I.children);if(h instanceof De.Array)for(let S of h.toArray())typeof S=="string"&&!f.has(S)&&l.push(S)}let d=new Set,p=new Map;for(let[k,x]of a){let h=Te(k)===i(x.group);if(f.has(k)||o.has(k)){h&&s.add(x.group);continue}if(d.add(k),!h)continue;let S=p.get(x.group);S?S.push(k):p.set(x.group,[k])}let u=new Map,y=k=>{let x=u.get(k);if(x!==void 0)return x;u.set(k,!1);let h=a.get(k)?.from,S=h!==void 0&&(f.has(h)||o.has(h)||d.has(h)&&y(h));return u.set(k,S),S},g=new Set;for(let[k,x]of p)!s.has(k)&&!x.some(y)&&g.add(k);return{unseenWinners:g,lost:d}}var Ss=4096,ze=1<<20,xs=65536,pa=1<<20;function bs(e,t,n,o,r,i,s,a=new Set(n)){let c=e.doc,f=c.clientID,l=D=>{let O=e.nodes.get(D),W=ie(O),B=O instanceof V.Map?O.get(I.text):void 0;return!W||!(B instanceof V.Text)||O.get(I.part)!==t?null:{key:D,copy:W,text:B}},d=new Set(n.filter(D=>l(D)!==null));if(d.size===0)return;let p=Nt(r,t),u=[],y=0;for(let[D,O]of e.doc.getMap(Xe).entries()){if(O!==t)continue;let W=l(D);if(!(!W||W.text.length===0&&!p.has(D))){if(u.length>=Ss||(y+=W.copy.length)>ze)return;u.push(W)}}let g=u.filter(D=>d.has(D.key));if(g.length===0)return;let k=new Map,x=D=>U(c,D,k),h=new Map,S=en(c,p),w=D=>ho(c,D,k),m=(D,O)=>S.laterRoot(w(D),w(O)),b=(D,O)=>V.createID(D.copy.client,D.copy.clock+O),Y=new Set;for(let D of p.keys()){let O=e.nodes.get(D),W=O instanceof V.Map?O.get(I.text):null;if(W instanceof V.Text)for(let B=W._start;B;B=B.right){if(++y>ze)return;if(!(B.deleted||!B.countable))for(let X=0;X<B.length;X+=1){if(++y>ze)return;let q=x(V.createID(B.id.client,B.id.clock+X));Y.add(z(q.client,q.clock))}}}let M=new Map;for(let[D,O]of e.nodes){if(++y>ze)return;if(!(O instanceof V.Map)||O.get(I.part)!==t)continue;let W=O.get(I.children);if(W instanceof V.Array)for(let B of W.toArray()){if(++y>ze)return;typeof B=="string"&&M.set(B,D)}}let v=new Set;for(let D of[...u].sort((O,W)=>O.key<W.key?-1:O.key>W.key?1:0)){if(p.has(D.key))continue;let O=[];for(let q=D.text._start;q;q=q.right){if(++y>ze)return;if(!(q.deleted||!q.countable))for(let le=0;le<q.length;le+=1){if(++y>ze)return;O.push(x(V.createID(q.id.client,q.id.clock+le)))}}if(!O.some(q=>!Y.has(z(q.client,q.clock))))continue;let W=M.get(D.key),B=W?M.get(W):void 0,X=B?e.nodes.get(B):void 0;if(!(!(X instanceof V.Map)||!X.has($.splitFrom))){X.set($.copyWinner,!0),v.add(D.key),d.add(D.key);for(let q of O)Y.add(z(q.client,q.clock))}}let E=new Map;for(let D of u){if(!p.has(D.key)&&!v.has(D.key))continue;let O=[D.copy,...qt(e.nodes.get(D.key))];for(let W of O)for(let B=0;B<W.length;B+=1){if((y+=1)>ze)return;let X=V.createID(W.client,W.clock+B);if(Qt(c,X))continue;let q=x(X),le=z(q.client,q.clock),Ee=E.get(le);Ee?Ee.some(it=>V.compareIDs(it.id,X))||Ee.push({copy:D,id:X}):E.set(le,[{copy:D,id:X}])}}let F=(D,O)=>{let W=Ue(c,D.id,h),B=Ue(c,O.id,h);if(!V.compareIDs(W,B)){let q=x(D.id);if(V.compareIDs(W,q))return O;if(V.compareIDs(B,q))return D}let X=q=>{let le=Ve(c,q.id);return le?{key:le.key,from:le.start,start:x(le.start),enter:le.enter,client:le.client}:w(q.copy)};return S.ahead(X(D),X(O))?D:O},_=D=>E.get(z(D.client,D.clock))?.reduce(F);for(let D of g.filter(O=>O.copy.client!==f))ma(e,D,Fr(e.nodes.get(D.key)),O=>_(x(O)),i,(O,W,B,X)=>{let q=E.get(z(x(X).client,x(X).clock))??[],le=On(W,B,Ee=>Me(c,Ee)!==null);return Pn(e,S,O,le,q.map(Ee=>Ee.copy),k,X)},u.map(O=>O.text));let T=new Map,R=(D,O)=>{let W=T.get(D);W?W.push(O):T.set(D,[O])};if(o.size>0)for(let D of g)for(let O=0;O<D.copy.length;O+=1){let W=Ue(c,D.copy.source(O),h);o.has(z(W.client,W.clock))&&!Qt(c,b(D,O))&&R(D.text,b(D,O))}for(let D of E.values()){if(D.length<2||!D.some(X=>d.has(X.copy.key)))continue;let O=D.reduce(F),W=p.get(O.copy.key)?.run,B=W?e.nodes.get(W):void 0;B instanceof V.Map&&B.get($.copyWinner)!==!0&&B.set($.copyWinner,!0);for(let X of D)X!==O&&R(X.copy.text,X.id)}for(let[D,O]of T)_e(D,new Set(O.map(W=>z(W.client,W.clock))));let P=new Map,C=D=>{let O=P.get(D.key);if(!O){O=new Set;for(let W=0;W<D.copy.length;W+=1){let B=x(D.copy.source(W));O.add(z(B.client,B.clock))}P.set(D.key,O)}return O},K=pa,A=(D=1)=>(K-=D)>=0,L=(D,O)=>{let[W,B]=[C(D),C(O)].sort((X,q)=>X.size-q.size);if(!A(W.size))return!1;for(let X of W)if(B.has(X))return!0;return!1},j={room:e,me:f,incoming:g.filter(D=>D.copy.client!==f&&a.has(D.key)),all:u,placed:p,share:L,laterStart:m,step:A,movedRun:s};ka(j),ga(j)}function Ln(e,t){let n=e.nodes.get(t),o=n instanceof V.Map?n.get(I.children):void 0;return o instanceof V.Array?o:void 0}function ga(e){let{room:t,me:n,incoming:o,all:r,placed:i,share:s,laterStart:a,step:c,movedRun:f}=e,l=new Map,d=(u,y)=>{let g=l.get(u);if(!g){l.set(u,g=new Map);let k=xs,x=h=>{let S=Ln(t,h)?.toArray()??[];return k-=S.length,k<0?[]:S};for(let h of x(u))for(let S of x(h))for(let w of x(S))for(let m of x(w))g.set(m,{p:h,run:S})}return g.get(y)},p=new Map;for(let u of[...o].sort(a)){let y=i.get(u.key);if(!(!y?.p||!y.run))for(let g of r){if(!c())return;if(g.copy.client!==n||g.key===u.key||!s(u,g))continue;let k=d(y.p.parent,g.key),x=k?t.nodes.get(k.run):void 0;if(!k||k.p===y.p.key||!(x instanceof V.Map))continue;let h=x.get($.movedFrom)===y.p.key,S=!h&&g.copy.newParagraph&&a(u,g)>0&&ya(t,g,d,y.p.parent)===y.p.key;if(!h&&!S)continue;let w=Ln(t,y.p.key),m=Ln(t,k.p),b=w?.toArray().indexOf(y.run)??-1;if(!w||!m||b<0)continue;let Y=ha(w,b);if(w.delete(b,1),!S){m.insert(m.toArray().indexOf(k.run),[y.run]);break}let M=p.get(k.run)??k.run,v=V.getState(t.doc.store,n);m.insert(m.toArray().indexOf(M)+1,[y.run]),p.set(k.run,y.run),Y&&f?.({anchor:V.createID(g.copy.client,g.copy.clock),gone:Y,added:V.createID(n,v),run:y.run,from:w,to:m});break}}}function ha(e,t){let n=0;for(let o=e._start;o!==null;o=o.right)if(!(o.deleted||!o.countable)){if(t<n+o.length){for(let r=o;r!==null&&!r.keep;)r.keep=!0,r=r.parent._item;return V.createID(o.id.client,o.id.clock+t-n)}n+=o.length}}function ya(e,t,n,o){let r=Z(e.doc,t.copy.source(0)),i=r?xe(r)?.get(I.key):void 0;return typeof i=="string"?n(o,i)?.p:void 0}function ma(e,t,n,o,r,i,s){let a=e.doc,c=a.clientID,l=Z(a,t.copy.source(0))?.parent;if(!(l instanceof V.Text))return;let d=new Map,p=x=>{let h=U(a,x,d);return z(h.client,h.clock)},u=new Set,y=new Set;for(let x=0;x<t.copy.length;x+=1){let h=t.copy.source(x);y.add(z(h.client,h.clock)),u.add(p(h))}let g=ze,k=new Map;for(let x of s){let h=ie(x.parent);if(!(!h||h.client!==c))for(let S=0;S<h.length;S+=1){if(--g<0)return;let w=h.source(S),m=z(w.client,w.clock);k.set(m,Math.min(k.get(m)??1/0,h.clock))}}for(let x of new Set([l,...s])){let h=new Map,S=[],w=null;for(let m=x._start;m!==null;m=m.right){if(--g<0)return;if(m.deleted||!(m.content instanceof V.ContentString))continue;let b=m.content.str;for(let Y=0;Y<b.length;Y+=1){if(--g<0)return;let M=V.createID(m.id.client,m.id.clock+Y),v=ie(x.parent);if(v&&M.client===v.client&&M.clock>=v.clock&&M.clock<v.clock+v.length)continue;let E=Y===0?m.origin:V.createID(m.id.client,m.id.clock+Y-1),F=E&&(k.get(z(E.client,E.clock))??1/0)<m.id.clock;if(Y===0&&E&&F&&Qt(a,E)){let C=m.left,K=0;for(;C&&(C.deleted||!C.countable)&&K++<xs;)C=C.left;C&&!C.deleted&&C.countable&&(E=V.createID(C.id.client,C.id.clock+C.length-1))}let _=E?z(E.client,E.clock):"",T=Y===0?m.rightOrigin:null,R=m.id.client!==c?void 0:E&&(y.has(_)||u.has(p(E)))?{id:E,before:!1}:h.get(_)??(!E&&T&&u.has(p(T))?{id:T,before:!0}:void 0);if(!R){w=null;continue}if(h.set(z(M.client,M.clock),R),n?.(M))continue;(!w||!V.compareIDs(w.anchor,R.id)||w.before!==R.before)&&(w={anchor:R.id,before:R.before,ids:[],written:[],text:"",marks:[]},S.push(w));let P=Me(a,M);P&&u.has(p(M))||P&&i(x,m,Y,M)||(w.ids.push(M),!(P&&o(M))&&(P&&w.marks.push([w.text.length,P]),w.written.push(M),w.text+=b[Y]))}}for(let m of S){let b=o(m.anchor),Y=b?Yn(b.copy.text,b.id):-1;if(!b||Y<0||b.copy.text===x||(_e(x,new Set(m.ids.map(E=>z(E.client,E.clock)))),m.text.length===0))continue;let M=V.getState(a.store,c);b.copy.text.insert(Y+ +!m.before,m.text);let v=e.nodes.get(b.copy.key);v instanceof V.Map&&Cr(v,c,M,m.written);for(let E=0;E<m.written.length;E+=1)for(let F of[Pe,Dt]){let _=a.getMap(F),T=m.written[E],R=_.get(z(T.client,T.clock));R!==void 0&&_.set(z(c,M+E),R)}Jt(a,m.marks.flatMap(([E,F])=>[M+E,F.client,F.clock,1])),r(m.ids[0],V.createID(c,M),m.text.length)}}}function Ms(e,t,n){if(n.size===0)return;let o=e.doc,r=new Map,i=0;for(let s of t){let a=e.nodes.get(s),c=a instanceof V.Map?a.get(I.text):void 0;if(!(c instanceof V.Text))continue;let f=[];for(let l of qt(a))if(!(l.client===o.clientID||(i+=l.length)>ze))for(let d=0;d<l.length;d+=1){let p=V.createID(l.client,l.clock+d),u=Ue(o,l.source(d),r);n.has(z(u.client,u.clock))&&!Qt(o,p)&&f.push(p)}f.length>0&&_e(c,new Set(f.map(l=>z(l.client,l.clock))))}}function ka({room:e,me:t,incoming:n,all:o,placed:r,share:i,laterStart:s,step:a}){for(let c of o){if(c.copy.client!==t||!c.copy.newParagraph)continue;let f=r.get(c.key)?.p,l=f?Ln(e,f.parent):void 0;if(!f||!l)continue;let d=l.toArray();if(!a(d.length))return;let p=new Map(d.map((g,k)=>[g,k])),u=p.get(f.key)??-1;if(u<0)continue;let y;for(let g of n){if(!a())return;if(g.key===c.key||s(c,g)<=0)continue;let k=r.get(g.key)?.p;if(!k||k.parent!==f.parent||k.key===f.key)continue;let x=p.get(k.key)??-1;x<=u||y&&x<=y.at||!i(g,c)||(y={key:k.key,at:x})}y&&(l.delete(u,1),l.insert(l.toArray().indexOf(y.key)+1,[f.key]))}}function Ys(e,t,n,o){if(o.size===0)return;let r=new Map,i=ze;for(let s of n.slice(0,Ss)){let a=e.nodes.get(s),c=ie(a),f=a instanceof V.Map?a.get(I.text):null;if(!c||!(f instanceof V.Text)||!(a instanceof V.Map)||a.get(I.part)!==t)continue;let l=new Set;for(let d=f._start;d&&i-- >0;d=d.right)if(!(d.deleted||!d.countable))for(let p=0;p<d.length&&i-- >0;p+=1){let u=V.createID(d.id.client,d.id.clock+p),y=Ue(e.doc,u,r);o.has(z(y.client,y.clock))&&l.add(z(u.client,u.clock))}if(_e(f,l),i<=0)return}}function Rs(e,t,n){if(n.size===0)return;let o=new Map,r=ze;for(let i of e.nodes.values()){if(--r<0)return;if(!(i instanceof V.Map)||i.get(I.part)!==t)continue;let s=i.get(I.text);if(!(s instanceof V.Text))continue;let a=new Set;for(let c=s._start;c&&--r>=0;c=c.right)if(!(c.deleted||!c.countable))for(let f=0;f<c.length&&--r>=0;f+=1){let l=V.createID(c.id.client,c.id.clock+f),d=U(e.doc,l,o);n.has(z(d.client,d.clock))&&a.add(z(l.client,l.clock))}_e(s,a)}}import*as bt from"yjs";import*as G from"yjs";import*as Oo from"yjs";function xt(e,t){if(!(e instanceof Oo.Map))return null;let n=null,o=0;for(let[r,i]of e.entries()){if(!an(r)||!Array.isArray(i))continue;let s=e._map.get(r);if(!(s&&t&&s.id.clock<(t.get(s.id.client)??0))){if(i.length>mt+1||(o+=1)>Nn)return"all";n??=new Set;for(let a of i)typeof a=="string"&&n.add(a)}}return n}var wa=1<<18;function Fn(e,t,n){let o=new Set,r=0;for(let i of e.nodes.values()){if((r+=1)>wa)break;if(!(i instanceof Oo.Map)||i.get(I.part)!==t||!we(i))continue;let s=xt(i,n);if(s==="all")return"all";for(let a of s??[])o.add(a)}return o}var Sa="http://schemas.openxmlformats.org/drawingml/2006/main";var fn=(e,t)=>!!e&&!("text"in e)&&e.ns===Sa&&e.local===t;function Is(e,t,n){let o=[],r=0;for(let i of e.childrenOf(t))if(e.localOf(i)==="txBody")for(let s of e.childrenOf(i)){if((r+=1)>4096)return o;if(e.localOf(s)!=="p"||!e.holdsForeign(s,n))continue;let a=e.readParagraph(s);a&&o.push(a)}return o}function Es(e,t,n){let o=i=>e.findIndex(s=>s.key===i),r=new Set([t.key]);for(let i=t.after;i!==""&&!r.has(i);i=n.get(i)??""){r.add(i);let s=o(i);if(s>=0)return s}return t.before===""?-1:o(t.before)}function vs(e,t,n){let o=e.children??[],r=o.findIndex(a=>fn(a,"txBody"));if(r<0)return null;let i=o[r],s=[...o];s[r]={...i,children:[...i.children??[],...t]};for(let a of t)n.set(a.key,i.key);return{...e,children:s}}function xa(e,t,n,o){let r=e.children??[],i=r.flatMap((c,f)=>fn(c,"tc")?[f]:[]);if(i.length===0)return null;let s=Math.max(0,Math.min(t,i.length-1)),a=[...i.slice(s),...i.slice(0,s).reverse()];for(let c of a){let f=vs(r[c],n,o);if(!f)continue;let l=[...r];return l[c]=f,{...e,children:l}}return null}function Os(e,t,n,o,r){let i=[...e];for(let s of t){let a=o.localOf(s.key);if(a==="tc"){let c=Is(o,s.key,s);if(c.length===0)continue;let f=i.flatMap((p,u)=>fn(p,"tc")?[u]:[]),l=Es(i,s,n),d=l>=0?[l,...f.filter(p=>p!==l)]:f;for(let p of d){let u=vs(i[p],c,r);if(u){i[p]=u;break}}}else if(a==="tr"){let c=i.flatMap((p,u)=>fn(p,"tr")?[u]:[]),f=Es(i,s,n),l=f>=0&&fn(i[f],"tr")?f:c[0];if(l===void 0)continue;o.childrenOf(s.key).filter(p=>o.localOf(p)==="tc").forEach((p,u)=>{let y=Is(o,p,s);if(y.length===0)return;let g=xa(i[l],u,y,r);g&&(i[l]=g)})}}return i}var Ke="pptx-undone-v1",Ds=64,Kt=1024,Cs=1<<18,Ts=(e,t)=>e.id.client!==t.client||e.id.clock>=t.clock;function jt(e,t,n){if(typeof t!="object"||t===null)return null;let o=t;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 r=Number.isSafeInteger(o.q)&&o.q>=0?o.q:1/0,i=typeof o.n=="string"?o.n:"",s=typeof o.s=="string"?o.s:null,a=o.m===1,c=new Map;if(Array.isArray(o.v)&&o.v.length<=8192&&o.v.length%2===0)for(let f=0;f<o.v.length;f+=2){let[l,d]=o.v.slice(f,f+2);typeof l=="number"&&Number.isSafeInteger(l)&&l>=0&&typeof d=="number"&&Number.isSafeInteger(d)&&d>=0&&c.set(l,d)}return{key:e,parent:o.u,after:o.a,before:i,client:o.c,clock:r,shownIn:s,moved:a,seen:c,redo:o.d===1,table:typeof o.t=="string"?o.t:null}}var ba=64;function Ma(e,t){let n=t;for(let o=0;n&&n.deleted&&o<ba;o+=1)n=n.redone?Z(e,n.redone):null;return n&&!n.deleted?n:null}function Ns(e,t,n){if(!n)return!1;let o=jt(t,e.doc.getMap(Ke).get(t));return o!==null&&o.shownIn===null&&!o.moved&&Ts(n,o)}function Ao(e,t,n,o=new Set,r=!1){let i=e.nodes,s=new Map,a=new Set;ae(e.doc,t.insertions,g=>{g.parent===e.parts&&g.parentSub!==null&&!g.deleted&&a.add(g.parentSub)});let c=new Map;ae(e.doc,t.deletions,g=>{let k=g.parent;if(!(k instanceof G.Array)||!(g.content instanceof G.ContentAny))return;let x=k.parent,S=(x instanceof G.Map?x.get(I.shell):void 0)?.local;if(S!=="txBody"&&S!=="tc")return;let w=x.get(I.key);if(typeof w=="string")for(let m of g.content.getContent())typeof m=="string"&&c.set(m,w)}),ae(e.doc,t.insertions,g=>{let k=Ma(e.doc,g)??g,x=k?.parent;if(!k||!(x instanceof G.Array))return;let h=x.parent;if(!(h instanceof G.Map)||Oe(h)?.parent!==i||h.get(I.children)!==x||k.parentSub!==null||!(k.content instanceof G.ContentAny))return;let S=s.get(x);S||s.set(x,S=new Set);for(let w of k.content.getContent())typeof w=="string"&&S.add(w)});let f=ao(t);for(let[g,k]of f){let x=s.get(g)??new Set;for(let h of k.keys)x.add(h);s.set(g,x)}if(s.size===0)return;for(let g of s.values())for(let k of o)g.delete(k);let l=e.doc.getMap(Ke),d=e.doc.clientID,p=G.getState(e.doc.store,d),u=[],y=new Map;{let g=Cs,k=(x,h,S)=>{if(--g<0||S>Ds||y.has(x))return;let w=e.nodes.get(x);if(!(w instanceof G.Map))return;let m=w.get(I.shell);m?.ns===nt&&m.local==="tbl"&&(h=x),h&&y.set(x,h);let b=w.get(I.children);if(b instanceof G.Array)for(let Y of b.toArray())typeof Y=="string"&&k(Y,h,S+1)};for(let x of e.parts.values()){let h=et(x);h?.kind==="xml"&&k(h.root,void 0,0)}}for(let[g,k]of s){let x=g.parent;if(!(x instanceof G.Map)||x.get(I.children)!==g)continue;let h=x.get(I.key),S=x.get(I.part);if(typeof h!="string"||typeof S!="string"||a.has(S))continue;let w=g.toArray().filter(m=>typeof m=="string");for(let m of f.get(g)?.siblings??[])k.has(m)&&!w.includes(m)&&w.push(m);w.forEach((m,b)=>{if(!k.has(m))return;if(r){let F=e.nodes.get(m),_=F instanceof G.Map?F.get(I.shell):void 0;if(_?.ns!==nt||_.local!=="tr"&&_.local!=="tc")return}if(x.get(I.shell)?.local==="txBody"&&(jt(m,l.get(m))?.parent??h)!==h)return;let v=w[b+1]??"",E={p:S,u:h,a:w[b-1]??"",n:v,c:d,q:p};E.t=y.get(h),r&&(E.d=1),c.has(m)&&(E.m=1,E.v=[...G.decodeStateVector(G.encodeStateVector(e.doc))].flatMap(([F,_])=>[F,_])),JSON.stringify(l.get(m))!==JSON.stringify(E)&&u.push([m,E])})}u.length>0&&n(()=>{for(let[g,k]of u)l.set(g,k)})}function _s(e,t,n,o,r,i){let s=e.doc.getMap(Ke),a=e.doc.clientID,c=new Set;for(let f of r){let l=o[f],d=typeof l=="string"?i(l):void 0;if(typeof l!="string"||d===void 0||c.has(l))continue;c.add(l);let p="";for(let g=f-1;g>=0&&p==="";g-=1)o[g]!==l&&typeof o[g]=="string"&&(p=o[g]);let u="";for(let g=f+1;g<o.length&&u==="";g+=1)o[g]!==l&&typeof o[g]=="string"&&(u=o[g]);let y={p:t,u:n,a:p,n:u,c:a,q:0,s:d};JSON.stringify(s.get(l))!==JSON.stringify(y)&&s.set(l,y)}}function Ls(e,t,n){let o=e.doc.getMap(Ke);if(o.size===0)return;let r=new Set;ae(e.doc,t.deletions,i=>{let s=i.parent;if(!(s instanceof G.Array)||!(i.content instanceof G.ContentAny))return;let a=s.parent instanceof G.Map?s.parent.get(I.key):void 0;for(let c of i.content.getContent())typeof c=="string"&&jt(c,o.get(c))?.parent===a&&!jt(c,o.get(c))?.redo&&r.add(c)}),r.size>0&&n(()=>{for(let i of r)o.delete(i)})}function Fs(e,t,n){let o=new Map,r=new Map,i=c=>{if(!r.has(c)){let f=et(e.parts.get(c));r.set(c,f?.kind==="xml"?dn.of(e,c,f.root):null)}return r.get(c)};if(ae(e.doc,t.insertions,c=>{if(c.parent!==e.nodes||c.parentSub===null||!(c.content instanceof G.ContentType)||!(c.content.type instanceof G.Map))return;let f=c.content.type;if(e.nodes.get(c.parentSub)!==f)return;let l=f.get(I.part),d=f.get(I.attrs),p=f.get(I.children);if(typeof l!="string"||!(d instanceof G.Map)||!(p instanceof G.Array)||d.size>0||p.length>0||!n(l,c.parentSub)||i(l)?.showsUnder(c.parentSub))return;let u=o.get(l);u||o.set(l,u=new Set),u.add(c.parentSub)}),o.size===0)return!1;let s=!1,a=0;for(let c of e.nodes.values()){if((a+=1)>Cs)break;if(!(c instanceof G.Map))continue;let f=c.get(I.part),l=typeof f=="string"?o.get(f):void 0,d=c.get(I.children);if(!l||!(d instanceof G.Array))continue;let p=d.toArray();for(let u=p.length-1;u>=0;u-=1){let y=p[u];if(typeof y=="string"&&l.has(y)){let g=e.doc.getMap(Ke),k=g.get(y),x=c.get(I.key);jt(y,k)&&typeof x=="string"&&g.set(y,{...k,u:x,a:typeof p[u-1]=="string"?p[u-1]:"",n:typeof p[u+1]=="string"?p[u+1]:""}),d.delete(u,1),s=!0}}}return s}var Ps=new WeakMap;function As(e,t,n){let o=e.placeOf.get(t);if(o){let c=e.byPart.get(o.part),f=c?.get(o.parent);f?.delete(t),f?.size===0&&c.delete(o.parent),e.placeOf.delete(t)}let r=n===void 0?null:jt(t,n),i=r?n.p:null;if(!r||i===null)return;let s=e.byPart.get(i);s||e.byPart.set(i,s=new Map);let a=s.get(r.parent);a||s.set(r.parent,a=new Map),a.set(t,r),e.placeOf.set(t,{part:i,parent:r.parent})}function Ya(e,t){let n=e.doc.getMap(Ke),o=Ps.get(n);if(!o){let r={byPart:new Map,placeOf:new Map};o=r;for(let[i,s]of n.entries())As(r,i,s);Ps.set(n,r),n.observe(i=>{for(let s of i.keysChanged)As(r,s,n.get(s))})}return o.byPart.get(t)??new Map}function Ra(e,t,n){let o=new Set,r=[n];for(;r.length>0;){let i=r.pop();if(o.has(i))continue;o.add(i);let s=e.nodes.get(i);if(!(s instanceof G.Map)||s.get(I.part)!==t)continue;let a=s.get(I.children);if(a instanceof G.Array)for(let c of a.toArray())typeof c=="string"&&!o.has(c)&&r.push(c)}return o}var nt="http://schemas.openxmlformats.org/drawingml/2006/main",zs=new Set(["p","pPr","rPr","endParaRPr","ln","bodyPr","tcPr"]);function Ks(e){if("text"in e)return e.text.length>0;if(e.ns!==nt)return!1;let t=e.children??[];return e.local==="r"?t.some(n=>!("text"in n)&&n.ns===nt&&n.local==="t"&&Ks(n)):e.local==="t"?t.some(n=>"text"in n&&n.text.length>0):zs.has(e.local)&&(t.length>0||(e.attrs??[]).length>0)}function Po(e){return"text"in e?e.text.length>0:(e.children??[]).some(Po)}var dn=class e{#e;#t;#r;#f=new Map;shown=new Set;rehomed=new Set;shownIn=new Map;#a;#d=new Map;constructor(t,n,o,r){this.#e=t,this.#a=n,this.#t=o,this.#r=r}static of(t,n,o){if(t.doc.getMap(Ke).size===0)return null;let r=Ya(t,n);return r.size===0?null:new e(t,n,r,Ra(t,n,o))}withStranded(t,n){let o=[...this.#t.keys()].flatMap(r=>this.#o(r)).filter(r=>r.moved||this.#n(r.key,r,0));return vn(this.#e,t,o,n,this.shownIn,this.rehomed)}#n(t,n,o){let r=`${t}\0${n.client}\0${n.clock}`,i=this.#f.get(r);if(i!==void 0)return i;this.#f.set(r,!1);let s=o<=Ds&&this.#u(t,n,o);return this.#f.set(r,s),s}#u(t,n,o){let r=this.#e.nodes.get(t);if(!(r instanceof G.Map))return!1;let i=d=>Ts(d,n),s=r.get(I.text);if(s instanceof G.Text){for(let d of Ut(s))if(d.countable&&i(d))return!0}let a=r.get(I.attrs);if(a instanceof G.Map){for(let d of hr(a))if(i(d))return!0}let c=r.get(I.children);if(c instanceof G.Array){for(let d of Ut(c))if(i(d))return!0}let f=r.get(I.shell);if(f?.ns===nt&&(f.local==="p"||f.local==="r"||f.local==="t")&&c instanceof G.Array){for(let d of c.toArray().slice(0,Kt))if(typeof d=="string"&&this.#n(d,n,o+1))return!0}let l=[];for(let d of r.keys())d.startsWith(oe.removedRun)&&l.push(d);for(let d of l.sort().slice(0,Kt))if(this.#n(d.slice(oe.removedRun.length),n,o+1))return!0;return this.#o(t).some(d=>this.#n(d.key,d,o+1))}showsUnder(t){return this.#o(t).some(n=>this.#n(n.key,n,1))}showsBelow(t){let n=[t],o=new Set;for(;n.length>0&&o.size<Kt;){let r=n.pop();if(o.has(r))continue;if(o.add(r),this.showsUnder(r))return!0;let i=this.#e.nodes.get(r);if(!(i instanceof G.Map)||i.get(I.part)!==this.#a)continue;let s=i.get(I.shell),a=i.get(I.children);if(s?.ns!==nt||!["p","r","t"].includes(s.local??"")||!(a instanceof G.Array))continue;for(let f of a.slice(0,Kt))typeof f=="string"&&n.push(f);let c=[...i.keys()].filter(f=>f.startsWith(oe.removedRun)).sort().slice(0,Kt);for(let f of c)n.push(f.slice(oe.removedRun.length))}return!1}#o(t){return[...this.#t.get(t)?.values()??[]].filter(n=>{if(this.#r.has(n.key))return!1;if(n.shownIn!==null&&!this.#r.has(n.shownIn)){let i=xt(this.#e.nodes.get(n.shownIn));if(!i||i==="all"||i.has(n.key))return!1}let o=this.#e.nodes.get(n.key);if(!(o instanceof G.Map))return!1;if(!n.redo&&we(o)){let i=o.get(I.shell);if(i?.ns!==nt||i.local!=="p"&&i.local!=="r")return!1}if(!n.moved)return!0;let r=this.#d.get(n);return r||(r=Fn(this.#e,this.#a,n.seen),this.#d.set(n,r)),r!=="all"&&!r.has(n.key)})}withUndone(t,n,o,r,i){let s=this.#o(t).filter(g=>!r.has(g.key)&&(g.moved||this.#n(g.key,g,0))).sort((g,k)=>g.key<k.key?-1:g.key>k.key?1:0).slice(0,Kt);if(s.length===0)return o;let a=[...o],c=new Set(a.map(g=>g.key)),f=new Map([...this.#t.get(t)?.values()??[]].map(g=>[g.key,g.after])),l=new Set(s.map(g=>g.key)),d=[],p="\0";for(let g=!1;l.size>0;){let k=!1;for(let x of s){if(!l.has(x.key))continue;let h=x.after,S=h!==""&&!c.has(h)&&!l.has(h)&&c.has(x.before)?x.before:null;S!==null&&(h=p);let w=new Set([x.key]),m=!1;for(;h!==""&&h!==p&&!c.has(h);){if(l.has(h)&&!g){m=!0;break}w.has(h)?h=p:(w.add(h),h=f.get(h)??p)}if(m)continue;l.delete(x.key),k=!0;let b=this.#p(x.key,n,r,i);if(!b||!Ks(b)){d.push(x);continue}let Y=this.#e.nodes.get(x.key);if(Y instanceof G.Map&&we(Y)&&!Po(b))continue;let M=S!==null?a.findIndex(v=>v.key===S):h===""?0:h===p?a.length:a.findIndex(v=>v.key===h)+1;a.splice(M,0,b),c.add(x.key),this.shown.add(x.key),this.shownIn.set(x.key,t)}k||(g=!0)}if(d.length===0)return a;let u=new Map,y=Os(a,d,f,this.#m(n,r,i),u);for(let[g,k]of u)[this.shown,this.rehomed].forEach(x=>x.add(g)),this.shownIn.set(g,k);return y}#m(t,n,o){let r=this.#e.nodes;return{localOf:i=>{let s=r.get(i),a=s instanceof G.Map?s.get(I.shell):void 0,{ns:c,local:f}=typeof a=="object"&&a!==null?a:{};return c===nt&&typeof f=="string"?f:void 0},childrenOf:i=>{let s=r.get(i),a=s instanceof G.Map?s.get(I.children):void 0,c=a instanceof G.Array?a.toArray():[],f=[];if(s instanceof G.Map)for(let l of s.keys())l.startsWith(oe.removedRun)&&f.push(l.slice(oe.removedRun.length));return[...c.filter(l=>typeof l=="string"),...this.#o(i).map(l=>l.key),...f.sort()]},holdsForeign:(i,s)=>this.#n(i,s,0),readParagraph:i=>{let s=r.get(i);if(n.has(i)||!(s instanceof G.Map)||typeof s.get($.movedFrom)=="string")return null;let a=this.#p(i,t,n,o);return a&&Po(a)?a:null}}}#p(t,n,o,r){let i=this.#e.nodes.get(t);if(!(i instanceof G.Map)||i.get(I.part)!==n)return null;let s=i.get(I.text);if(s instanceof G.Text)return o.add(t),{key:t,text:ct(s)};let a=i.get(I.shell),{ns:c,local:f}=typeof a=="object"&&a!==null?a:{};return c!==nt||typeof f!="string"||!zs.has(f)&&f!=="r"&&f!=="t"?null:r(t)}};function js(e,t,n){let o=new Set,r=e.parts,i=e.binaries,s=e.nodes,a=e.doc,c=[a.getMap(yt),a.getMap(St)],f=a.getMap(Tn),l=a.getMap(Ke);for(let[d,p]of t.changed){let u=d;if(u===r||u===i){for(let k of p)k!==null&&o.add(k);continue}if(c.includes(u)){for(let k of p){let x=k===null?void 0:d.get(k);typeof x=="string"&&o.add(x)}continue}if(u===l){for(let k of p){if(k===null)continue;let x=e.doc.getMap(Ke).get(k),h=typeof x=="object"&&x!==null?x.p:void 0,S=e.nodes.get(k),w=typeof h=="string"?h:S instanceof bt.Map?S.get(I.part):void 0;typeof w=="string"&&o.add(w)}continue}if(u===f){for(let k of p){let x=k===null?void 0:e.nodes.get(k.split("\0")[0]),h=x instanceof bt.Map?x.get(I.part):void 0;typeof h=="string"&&o.add(h)}continue}if(u===s){for(let k of p){if(k===null)continue;let x=e.nodes.get(k),h=x instanceof bt.Map?x.get(I.part):void 0;if(typeof h=="string"){o.add(h);continue}let S=n.get(k);S!==void 0&&o.add(S)}continue}let y=u;for(;y instanceof bt.AbstractType&&y.parent!==s;)y=y.parent;let g=y instanceof bt.Map?y.get(I.part):void 0;typeof g=="string"&&o.add(g)}return o}import*as Wt from"yjs";import*as Hs from"yjs";import*as rt from"yjs";var Kn=1024;function Ia(e,t,n,o,r,i){if(n.length>_n)return null;for(let s of n){if(typeof s!="string"||o.has(s))return null;let a=r.get(s);if(a===void 0&&(a=xt(e.nodes.get(s)),r.set(s,a)),a==="all")return null;if(a)return a.has(t)?null:s;if(Ns(e,s,i))return s}return null}function Ea(e,t){let n=e._map.get(t);return n&&!n.deleted?n:void 0}function Ws(e,t,n,o){for(let r of t.slice(0,_n)){if(typeof r!="string")return!0;let i=o.get(r);if(i===void 0&&(i=xt(e.nodes.get(r)),o.set(r,i)),i==="all"||i?.has(n))return!0}return!1}var va=64;function Oa(e,t,n){let o=t.to[0];if(typeof o!="string")return null;let r=e.nodes.get(o),i=r instanceof rt.Map?r.get(I.children):void 0;if(!(i instanceof rt.Array))return null;let s=i.toArray().slice(0,Kn),a=s.indexOf(t.key);if(a<0)return null;let c=l=>l.key!==t.key&&l.clock===t.clock&&l.to.length===t.to.length&&l.to.every((d,p)=>d===t.to[p]),f=new Map(n.filter(c).map(l=>[l.key,l]));if(f.size===0)return null;for(let l=a-1;l>=0;l-=1){let d=f.get(s[l]);if(d)return{with:d,after:!0,at:a}}for(let l=a+1;l<s.length;l+=1){let d=f.get(s[l]);if(d)return{with:d,after:!1,at:a}}return null}function zn(e,t,n,o,r){let i=!1,s=new Set,a=[t];for(let c=0;c<va&&a.length>0;c+=1){let f=[];for(let l of a){if(s.has(l))continue;s.add(l);let d=r.get(l);if(d===void 0&&(d=xt(e.nodes.get(l)),r.set(l,d)),d==="all"||d?.has(n))return"seen";d&&(i=!0);for(let p of o().get(l)??[])f.push(p)}a=f.slice(0,Kn)}return i?"unseen":"none"}var Xs="http://schemas.openxmlformats.org/drawingml/2006/main",ot=(e,t)=>!!e&&!("text"in e)&&e.ns===Xs&&e.local===t;function Pa(e,t){let n=e.nodes.get(t),o=n instanceof rt.Map?n.get(I.children):void 0;return o instanceof rt.Array?o.toArray().slice(0,Kn):[]}function pn(e,t){let n=typeof t=="string"?e.nodes.get(t):void 0,o=n instanceof rt.Map?n.get(I.shell):void 0;if(typeof o!="object"||o===null)return;let{ns:r,local:i}=o;return r===Xs&&typeof i=="string"?i:void 0}function $s(e,t,n,o){let r=pn(e,t),i=r==="p"?1:r==="txBody"?0:-1;if(i<0||pn(e,n[i])!=="tc")return;let[s,a,c]=n.slice(i,i+3);if(pn(e,a)!=="tr")return;let f=u=>{if(ot(u,"tc"))return r==="txBody"?u.key:(u.children??[]).find(y=>ot(y,"txBody"))?.key},l=o.get(a);if(!o.has(s)&&ot(l,"tr"))for(let u of l.children??[]){let y=f(u);if(y)return y}let d=o.get(c??"");if(l||!ot(d,"tbl"))return;let p=Math.max(0,Pa(e,a).indexOf(s));for(let u of d.children??[]){if(!ot(u,"tr"))continue;let y=(u.children??[]).filter(k=>ot(k,"tc")),g=f(y[Math.min(p,y.length-1)]);if(g)return g}}var un=(e,t)=>e<t?-1:e>t?1:0,Do=class extends Set{#e;constructor(t){super(),this.#e=t}has(t){return this.#e.has(t)||super.has(t)}};function Vs(e,t,n,o,r,i,s){let a=e.doc.getMap(St);if(a.size===0)return n;let c=new Map,f=new Map,l=new Map,d=new Map,p=(T,R,P)=>{if(c.set(T.key,R),l.set(T.key,l.size),P!==null&&f.set(T.key,P),"text"in T||d.set(T.key,T),!("text"in T))for(let C of T.children??[])p(C,R+1,T.key)};p(n,0,null);let u=[],y=[],g=new Map,k,x=T=>{if(!k){k=new Map;for(let R of a.keys()){if(!f.has(R))continue;let P=e.nodes.get(R),C=P instanceof rt.Map?P.get($.movedFrom):void 0;if(typeof C!="string")continue;let K=k.get(C);(K===void 0||l.get(R)>l.get(K))&&k.set(C,R)}}return k.get(T)};for(let[T,R]of a.entries()){if(R!==t||c.has(T))continue;let P=e.nodes.get(T);if(!(P instanceof rt.Map)||P.get(I.part)!==t||we(P))continue;let C=P.get($.movedFrom),K=P.get($.movedTo);if(typeof C!="string"||!Array.isArray(K))continue;let A=P.get($.movedEarlier),L=c.has(C)?C:(Array.isArray(A)?A.slice(0,Eo):[]).find(X=>typeof X=="string"&&c.has(X)),j=P.get($.movedIndex),D=P.get($.movedClock),O=typeof D=="number"&&Number.isFinite(D)?D:0,W=Ea(P,$.movedTo),B=Ia(e,T,K,c,g,W);if(B!==null&&!(s&&zn(e,T,T,s,g)==="seen")){if(u.length+y.length>=Kn)return n;if(L!==void 0){let X=L===C&&kt(j)?j:1/0;u.push({key:T,from:L,index:X,clock:O,to:K})}else y.push({key:T,last:C,removed:B,index:kt(j)?j:1/0,clock:O,to:K})}}let h=new Map,S=y,w=0,m=T=>{if(!s)return[...T];let R=[...T];for(let P=0;P<T.length&&R.length>0;P+=1){let C=[],K=[];for(let A of R){let L=Oa(e,A,u),j=!Ws(e,A.to,A.key,g)&&zn(e,A.key,A.key,s,g)!=="seen"&&zn(e,A.last,A.key,s,g)==="unseen";if(!L||!j){C.push(A);continue}let D=L.after?{after:L.with.key}:{before:L.with.key},{key:O,clock:W,to:B}=A;K.push({key:O,from:L.with.from,index:1/0,clock:W,to:B,...D,seq:L.at})}if(K.length===0)break;K.sort((A,L)=>A.seq-L.seq||un(A.key,L.key));for(let A of K)u.push({...A,seq:w++});R=C}return R},b,Y=T=>{if(!s||!(!Ws(e,T.to,T.key,g)&&zn(e,T.last,T.key,s,g)!=="seen")||(b??=Fn(e,t),b==="all"||b.has(T.key)))return;let P=$s(e,T.key,T.to,d);if(P)return P;let C=T.to.find(D=>pn(e,D)==="tr"),K=T.to.find(D=>pn(e,D)==="tbl"),A=typeof K=="string"?d.get(K):void 0;if(typeof C!="string"||!ot(A,"tbl")||A.children?.some(D=>ot(D,"tr")))return;let L=o(C,new Set(c.keys()),c.get(A.key)+1);if(!ot(L??void 0,"tr"))return;let j=D=>({...D,children:D.key===A.key?[...D.children??[],L]:(D.children??[]).map(O=>"text"in O?O:j(O))});return n=j(n),p(n,0,null),r?.add(L.key),P=$s(e,T.key,T.to,d),P};for(;S.length>0;){let T=[],R=[];for(let P of S){let C=h.get(P.removed),K=C?void 0:x(P.removed),A=C?C.into:K===void 0?void 0:f.get(K),L=C?C.key:K;L===void 0||A===void 0?R.push(P):T.push({...P,after:L,into:A})}if(T.length===0){for(let P of m(R).sort((C,K)=>un(C.key,K.key))){let C=s&&Y(P);C?u.push({key:P.key,from:C,index:1/0,clock:P.clock,to:P.to}):i?.add(P.removed)}break}T.sort((P,C)=>P.clock-C.clock||P.index-C.index||un(P.key,C.key));for(let P of T)u.push({...P,from:P.into,seq:w++}),h.set(P.last,{key:P.key,into:P.into});S=R}if(u.length===0)return n;let M=new Set(u.map(T=>T.key)),v=new Map(u.map(T=>[T.key,T.to.filter(R=>typeof R=="string"&&M.has(R)).length]));u.sort((T,R)=>v.get(T.key)-v.get(R.key)||un(T.key,R.key));let E=new Do(new Set(c.keys())),F=new Map;for(let T of u){let R=o(T.key,E,c.get(T.from)+1);if(!R)continue;r?.add(R.key);let P={node:R,index:T.index,clock:T.clock,after:T.after,before:T.before,seq:T.seq??0},C=F.get(T.from);C?C.push(P):F.set(T.from,[P])}if(F.size===0)return n;let _=T=>{let R=F.get(T.key),P=(T.children??[]).map(D=>"text"in D?D:_(D));if(!R)return{...T,children:P};let C=[...P],K=R.filter(D=>D.after===void 0&&D.before===void 0).sort((D,O)=>O.clock-D.clock||D.index-O.index||un(D.node.key,O.node.key));for(let{node:D,index:O}of K)C.splice(Math.min(O,C.length),0,D);let A=R.filter(D=>D.after!==void 0||D.before!==void 0).sort((D,O)=>D.seq-O.seq),L=new Map;for(let{node:D,after:O,before:W}of A){if(O===void 0){let q=C.findIndex(le=>le.key===W);C.splice(q<0?C.length:q,0,D);continue}let B=L.get(O)??O,X=C.findIndex(q=>q.key===B);C.splice(X<0?C.length:X+1,0,D),L.set(O,D.key)}let j={ns:T.ns,local:T.local};return{...T,children:[...ht(j,C,D=>"text"in D?void 0:D)]}};return _(n)}function gn(e){let t=new Set,n=[e];for(;n.length>0;){let o=n.pop();if(t.add(o.key),!("text"in o))for(let r of o.children??[])n.push(r)}return t}var Bs=(e,t)=>e.size===t.size&&[...e].every(n=>t.has(n));function Gs(e,t){return Bs(e.lost,t.lost)&&Bs(e.unseenWinners,t.unseenWinners)}var Aa="http://schemas.openxmlformats.org/drawingml/2006/main";function hn(e){let t=new Map;if(!e)return t;let n=[e];for(;n.length>0;){let o=n.pop();if(t.set(o.id,o),o.type==="element")for(let r of o.children)n.push(r)}return t}function Da(e,t){let n=e.length,o=t.length,r=new Uint32Array((n+1)*(o+1));for(let f=n-1;f>=0;f--)for(let l=o-1;l>=0;l--)r[f*(o+1)+l]=e[f]===t[l]?r[(f+1)*(o+1)+l+1]+1:Math.max(r[(f+1)*(o+1)+l],r[f*(o+1)+l+1]);let i=new Set,s=new Set,a=0,c=0;for(;a<n&&c<o;)e[a]===t[c]?(i.add(a++),s.add(c++)):r[(a+1)*(o+1)+c]>=r[a*(o+1)+c+1]?a++:c++;return{keepA:i,keepB:s}}function Co(e,t){let n=e.toArray();if(n.length===t.length&&n.every((s,a)=>s===t[a]))return;if(n.length*t.length>25e4){e.delete(0,n.length),e.insert(0,[...t]);return}let{keepA:o,keepB:r}=Da(n,t);for(let s=n.length-1;s>=0;s--)o.has(s)||e.delete(s,1);let i=0;t.forEach((s,a)=>{r.has(a)||e.insert(i,[s]),i+=1})}function qs(e,t){if(e.size===0)return e;let n=gn(t);return new Map([...e].filter(([o])=>n.has(o)))}function Us(e){let t=new Map;if(e?.kind!=="xml")return t;let n=[[e.xml.root,""]];for(;n.length>0;){let[o,r]=n.pop();if(t.set(o.id,r),o.type==="element")for(let i of o.children)n.push([i,`${o.id}/${r}`])}return t}function Js(e,t,n){let o,r;return i=>{let s=e?.get(i);if(s===void 0)return!1;o??=Us(t),r??=Us(n);let a=o.get(s);return a!==void 0&&a===r.get(s)}}function Qs(e,t,n){let o;return r=>{let i=e?.get(r);if(i===void 0||n?.kind!=="xml")return;if(!o){let a=new Map,c=[n.xml.root];for(;c.length>0;){let f=c.pop();if(f.type==="element")for(let l of f.children)a.set(l.id,f.id),c.push(l)}o=a}let s=o.get(i);return s===void 0?void 0:t?.get(s)}}function Zs(e,t,n,o=!1){let r=ct(e);if(r===t)return;if(o&&!n&&Mr(e,r,t))return{created:n,deleted:[]};let i=0;for(;i<r.length&&i<t.length&&r[i]===t[i];)i++;let s=0;for(;s<r.length-i&&s<t.length-i&&r[r.length-1-s]===t[t.length-1-s];)s++;let a=y=>y>=55296&&y<=56319,c=y=>y>=56320&&y<=57343;i>0&&a(r.charCodeAt(i-1))&&i--,s>0&&c(r.charCodeAt(r.length-s))&&s--;let f=r.length-i-s,l=t.length-i-s;if(f===l&&!/[\uD800-\uDFFF]/.test(r.slice(i,i+f)+t.slice(i,i+l))){let y=Ce(e,i,f),g=[];for(let k=i;k<i+f;k++){if(r[k]===t[k])continue;let x=y[k-i];x&&g.push(x),e.insert(k,t[k]),e.delete(k+1,1)}return{created:n,deleted:g}}let d=f>0?Ce(e,i,f):[];f>0&&e.delete(i,f);let p=e.doc,u=p?Hs.getState(p.store,p.clientID):0;return l>0&&e.insert(i,t.slice(i,t.length-s)),{created:n,deleted:d,...l>0&&p?{inserted:{client:p.clientID,clock:u,length:l}}:{}}}function ei(e,t){let n=new Map,o=new Set;if(t.size===0)return{inParent:n,watch:o};let r=new Map,i=[e];for(;i.length>0;){let s=i.pop();for(let a of s.children??[])"text"in a||(r.set(a.key,s.key),t.has(a.key)&&a.ns===Aa&&Ca.has(a.local)&&n.set(a.key,s.key),i.push(a))}for(let s of n.values()){o.add(s);let a=r.get(s);a!==void 0&&o.add(a)}return{inParent:n,watch:o}}var Ca=new Set(["r","br","fld"]);function ti(e,t,n,o){let r=new Set(n),i=new Set(t),s=t.filter(u=>r.has(u)),a=n.filter(u=>i.has(u)),c=(u,y)=>u.length===y.length&&u.every((g,k)=>g===y[k]);if(c(s,a)||!c(ht(e,s,o),a))return n;let f=new Map,l=[],d;for(let u=n.length-1;u>=0;u--){let y=n[u];if(i.has(y))d=y;else if(d===void 0)l.unshift(y);else{let g=f.get(d);g||f.set(d,g=[]),g.unshift(y)}}let p=[];for(let u of s){for(let y of f.get(u)??[])p.push(y);p.push(u)}for(let u of l)p.push(u);return p}var ni=(e,t)=>e<t?-1:e>t?1:0;function oi(e){let t=e.attrs.map(Lt),n=[...t].sort(ni);if(t.every((r,i)=>r===n[i]))return;let o=new Map(n.map((r,i)=>[r,i]));return t.map(r=>o.get(r))}var ri=e=>({ns:e.ns,local:e.local,...e.prefix?{prefix:e.prefix}:{},nsDecls:e.nsDecls.map(t=>({prefix:t.prefix,uri:t.uri}))});function si(e,t){let n=[...e.keys()].sort(ni),o=n.length;return(Array.isArray(t)&&t.length===o&&t.every(s=>Number.isInteger(s)&&s>=0&&s<o)&&new Set(t).size===o?t.map(s=>n[s]):n).map(s=>e.get(s))}var Ta="http://schemas.openxmlformats.org/drawingml/2006/main",Na=65536;function ii(e,t,n,o){let r=new Map,i=Na;if(e.doc.store.pendingStructs&&n?.kind==="xml")for(let s of hn(n.xml.root).values()){if(--i<0)return new Map;if(s.type!=="element"||!(At(s)||s.ns===Ta&&s.local==="p"))continue;let a=o?.get(s.id);a&&r.set(a,s.children.flatMap(c=>{let f=o?.get(c.id);return f?[f]:[]}))}if(e.doc.store.pendingStructs)for(let[s,a]of e.doc.getMap(St)){if(--i<0)return new Map;if(a!==t)continue;let c=e.nodes.get(s);if(!(c instanceof Wt.Map)||c.get(I.part)!==t||we(c))continue;let f=c.get($.movedTo),l=c.get($.movedIndex);if(!Array.isArray(f)||typeof f[0]!="string"||!Number.isSafeInteger(l)||l<0)continue;let d=e.nodes.get(f[0]),p=d instanceof Wt.Map?d.get(I.children):void 0;if(!(d instanceof Wt.Map)||!(p instanceof Wt.Array)||d.get(I.part)!==t)continue;if(i-=p.length,i<0)return new Map;let u=r.get(f[0])??p.toArray();u.includes(s)||u.splice(Math.min(l,u.length),0,s),r.set(f[0],u)}return r}import{buildReplicaPart as Va}from"@pptx-editor.dev/core/store";import*as ft from"yjs";import{children as To,elements as $t,isStructureEdited as _a,path as ci,TABLE_MAX_COLUMNS as La,TABLE_MAX_ROWS as Fa,tableGridOf as za}from"@pptx-editor.dev/core/store";var jn=Object.freeze({holder:"mh",cover:"cv."}),Lo="http://schemas.openxmlformats.org/drawingml/2006/main",Ka="http://schemas.openxmlformats.org/presentationml/2006/main",Wn=256,Fo=4096,yn=e=>e?.type==="element",mn=(e,t)=>!!e&&!("text"in e)&&e.ns===Lo&&e.local===t;function ai(e,t){if(!mn(t,"p")||No(t))return!1;let n=e.nodes.get(t.key);return n instanceof ft.Map&&n.get(jn.holder)===!0}function ja(e){return($t(e).find(n=>n.local==="t")?.children??[]).map(n=>n.type==="text"?n.value:"").join("")}function Wa(e){return $t(e).some(t=>t.local==="br"||(t.local==="r"||t.local==="fld")&&ja(t).length>0)}function No(e){return"text"in e?!1:(e.children??[]).some(t=>{if("text"in t||!(t.local==="br"||t.local==="r"||t.local==="fld"))return!1;if(t.local==="br")return!0;let n=t.children?.find(o=>!("text"in o)&&o.local==="t");return!!n&&!("text"in n)&&(n.children??[]).some(o=>"text"in o&&o.text!=="")})}function li(e,t){let n=[],o=(r,i)=>{if(r.ns===Ka&&r.local==="graphicFrame"){n.push(r);return}if(i<Wn)for(let s of t(r))o(s,i+1)};return o(e,0),n}function fi(e){let t=ci(e,"a:graphic","a:graphicData","a:tbl"),n=Math.min(To(ci(t,"a:tblGrid"),"a:gridCol").length,La),o=To(t,"a:tr").slice(0,Fa).map(s=>To(s,"a:tc"));if(n===0||o.length===0)return[];let r=za(e,o,n),i=[];return o.forEach((s,a)=>s.slice(0,n).forEach((c,f)=>{let l=r.blocks[r.owner[a*n+f]],d=l&&o[l.row][l.col];d&&(l.row!==a||l.col!==f)&&i.push({tc:c,over:d})})),i}var _o=e=>$t(e).filter(t=>t.ns===Lo&&t.local==="txBody");function di(e){let t=new Map;if(!(e instanceof ft.Map))return t;for(let[n,o]of e.entries()){if(!n.startsWith(jn.cover)||!Array.isArray(o))continue;if(o.length>Fo)return"all";let r=e._map.get(n);if(r)for(let i of o)typeof i=="string"&&t.set(i,[...t.get(i)??[],r.id])}return t}function ui(e,t){let n=e.get(I.children);if(!(n instanceof ft.Array))return!0;let o=0;for(let r of Ut(n)){if((o+=1)>Fo)break;if(!t.some(s=>s.client===r.id.client&&s.clock>r.id.clock))return!1}return!0}function pi(e,t,n,o){if(n.size===0)return;let r=l=>{let d=o.get(l),p=d===void 0?void 0:e.nodes.get(d);return p instanceof ft.Map?p:void 0},i=new Set,s=[],a=(l,d)=>{let p=n.get(l.id);if(p!==l){for(let u of l.children)i.add(u.id);if(l.ns===Lo&&l.local==="txBody"&&yn(p)){let u=new Set(l.children.map(g=>g.id)),y=p.children.filter(g=>yn(g)&&g.local==="p");y.length>0&&y.every(g=>!u.has(g.id))&&s.push({body:l,old:p})}if(d<Wn)for(let u of l.children)yn(u)&&a(u,d+1)}};a(t,0);for(let{body:l,old:d}of s)if(d.children.filter(u=>yn(u)&&u.local==="p").every(u=>i.has(u.id)))for(let u of l.children)yn(u)&&u.local==="p"&&!n.has(u.id)&&!Wa(u)&&r(u.id)?.set(jn.holder,!0);let c=`${jn.cover}${e.doc.clientID.toString(36)}`,f=l=>$t(l).filter(d=>n.get(d.id)!==d);for(let l of li(t,f))for(let{tc:d}of fi(l)){let p=r(d.id),u=_o(d);if(!p||u.length===0)continue;let y=di(p);if(y==="all")continue;let g=u.flatMap(h=>$t(h).filter(S=>S.local==="p")).map(h=>o.get(h.id)).filter(h=>{if(h===void 0)return!1;let S=y.get(h),w=e.nodes.get(h);return!S||!(w instanceof ft.Map)||!ui(w,S)});if(g.length===0)continue;let k=p.get(c),x=Array.isArray(k)?k.filter(h=>typeof h=="string"):[];p.set(c,[...new Set([...x,...g])].slice(0,Fo+1))}}function gi(e,t){let n=new Map(e);return n.delete(t),n}function hi(e,t,n){let o=[];if(!t||t.size===0)return o;let r=(i,s)=>{let a=n.get(i.id);if(a!==void 0&&t.has(a)&&o.push(i),s<Wn)for(let c of $t(i))r(c,s+1)};return r(e,0),o}function yi(e,t){t.set(e.key,e);let n=(e.children??[]).map(o=>"text"in o?{type:"text",id:o.key,value:o.text}:yi(o,t));return{type:"element",id:e.key,kind:"generic",ns:e.ns,local:e.local,...e.prefix?{prefix:e.prefix}:{},nsDecls:[],attrs:e.attrs??[],children:n}}function $a(e,t,n,o,r,i,s,a){let c=new Map,f=yi(n,c),l=_a(f),d=new Map;for(let{tc:p,over:u}of fi(f)){let y=_o(u)[0],g=y&&c.get(y.id)||d.get(u.id),k=di(e.nodes.get(p.id)),x=Y=>{if(k==="all")return!1;let M=e.nodes.get(Y);if(!(M instanceof ft.Map))return!1;let v=k.get(Y);return v&&ui(M,v)?!1:l?!0:typeof M.get($.movedFrom)=="string"||we(M)},h=_o(p).flatMap(Y=>{let M=c.get(Y.id);if(!M)return[];let v=M.children??[],E=v.filter(F=>mn(F,"p")&&(t.has(F.key)||No(F)&&x(F.key)));return[{from:M,kids:v,going:E,paragraphs:v.filter(F=>mn(F,"p")).length}]}),S=c.get(p.id),w=c.get(u.id),m;if(!g){if(m=h.find(Y=>Y.going.length>0&&Y.kids.every(M=>!mn(M,"p")||Y.going.includes(M)||!No(M)))?.from,!m||!S||!w)continue;g=m,d.set(u.id,m),s.set(w.key,m),a?.add(S.key).add(w.key)}let b=new Set(h.filter(Y=>Y.going.length===Y.paragraphs&&Y.from!==m).map(Y=>Y.from));for(let Y of b)i.add(Y.key);S&&(b.size>0||m)&&r.set(S.key,(S.children??[]).filter(Y=>Y!==m&&!b.has(Y)));for(let{from:Y,kids:M,going:v}of h){if(v.length===0||Y===m)continue;let E=new Set(v);r.set(Y.key,M.filter(_=>!E.has(_)));let F=o.get(g.key);if(F)for(let _ of v)F.push(_);else o.set(g.key,v)}}}function mi(e,t,n,o,r=new Set){let i=new Map,s=new Map,a=li(t,l=>(l.children??[]).filter(d=>!("text"in d))),c=new Map;for(let l of a)$a(e,n,l,i,s,r,c,o);let f=(l,d)=>{let p=s.get(l.key)??l.children??[],u=i.get(l.key);u&&(p=[...p,...u]);let y=c.get(l.key);if(y&&(p=[y,...p]),l.local==="txBody"){let x=p.filter(S=>mn(S,"p")),h=x.some(S=>!ai(e,S))?void 0:x.at(-1);p=p.filter(S=>!ai(e,S)||S===h?!0:(r.add(S.key),!1))}let g=d<Wn?p.map(x=>"text"in x?x:f(x,d+1)):p,k=g.length===(l.children??[]).length&&g.every((x,h)=>x===l.children[h]);return!k&&l.local==="txBody"&&o?.add(l.key),k?l:{...l,children:g}};return f(t,0)}import*as Ie from"yjs";var ki=1024,$n=1024,wi=1<<20,Ko="http://schemas.openxmlformats.org/drawingml/2006/main",Si=()=>({left:wi,fields:new WeakMap,runs:new Map,paragraphs:new Map,seen:new Map,placed:new Map});function kn(e,t,n){let o=t.fields.get(e);if(o)return o;let r=!1,i=0,s=new Map,a=[];for(let[f,l]of e.entries())i+=1,an(f)?(r=!0,a.push(f)):f.startsWith(oe.removedRun)&&typeof l=="string"&&s.set(f.slice(oe.removedRun.length),l);n&&dt(t,i);let c={removed:r,places:s,removedRuns:[...s.keys()].sort().slice(0,$n),removals:a.sort().slice(0,Nn)};return t.fields.set(e,c),c}var dt=(e,t=1)=>(e.left-=t)>=0;function zo(e){let t=e.get(I.children);if(!(t instanceof Ie.Array))return[];let n=new Set;for(let o of t.slice(0,ki))typeof o=="string"&&n.add(o);return[...n]}function xi(e,t,n,o){let r=o.runs.get(t);if(r!==void 0)return r;let i=zo(n).some(s=>{if(!dt(o))return!1;let a=e.nodes.get(s);if(!(a instanceof Ie.Map))return!1;let c=a.get(I.shell);return c?.ns!==Ko||c.local!=="t"?!1:zo(a).some(f=>{if(!dt(o))return!1;let l=e.nodes.get(f),d=l instanceof Ie.Map?l.get(I.text):void 0;return d instanceof Ie.Text&&d.length>0})});return o.runs.set(t,i),i}var bi=e=>(e.children??[]).some(t=>!("text"in t)&&t.local==="t"&&(t.children??[]).some(n=>"text"in n&&n.text.length>0));function Mi(e,t,n){let o=n.seen.get(e);if(o)return o;let r=new Set,i=kn(t,n,!0);for(let s of i.removals){let a=t.get(s);if(!(!Array.isArray(a)||a.length>mt||!dt(n,a.length)))for(let c of a)typeof c=="string"&&r.add(c)}for(let s of i.removedRuns)r.add(s);return n.seen.set(e,r),r}function jo(e){let t,n=new Map,o=()=>{let r=new Map;for(let[i,s]of e.nodes.entries()){if(!(s instanceof Ie.Map))continue;let a=s.get(I.part),c=s.get(I.children);if(typeof a!="string"||!(c instanceof Ie.Array))continue;let f=r.get(a);f||r.set(a,f=new Map);for(let l of c.toArray()){if(typeof l!="string")continue;let d=f.get(l);d?d.push(i):f.set(l,[i])}}return r};return r=>()=>(t??=o()).get(r)??n}var Wo=(e,t)=>({rescued:new Set,stranded:e,listings:t,walk:Si()});function Yi(e,t,n,o,r){return t.get($.movedFrom)!==o?!1:(r().get(n)??[]).some(i=>{let s=e.nodes.get(i);return i!==o&&!(s instanceof Ie.Map&&we(s))})}function Ri(e,t,n,o,r,i){let s=t.get(I.shell);if(s?.ns!==Ko||Yi(e,t,n,o,i.listings))return null;let a=t.get($.movedFrom),c=t.get($.splitFrom);return(typeof c=="string"&&(i.listings().get(c)??[]).some(d=>{let p=e.nodes.get(d);return d!==o&&p instanceof Ie.Map&&!we(p)})||typeof a=="string"&&!i.stranded)&&!r().has(n)?null:s.local==="br"?r().has(n)?null:"br":s.local==="r"||s.local==="fld"?"run":null}function Ii(e,t,n,o){let r=n.get(I.key),i=()=>Mi(t.key,n,o.walk);for(let s of(t.children??[]).slice(0,ki)){if("text"in s)continue;if(!dt(o.walk))return!1;let a=e.nodes.get(s.key),c=a instanceof Ie.Map?Ri(e,a,s.key,r,i,o):null;if(c==="br"||c==="run"&&bi(s))return!0}return!1}function Ba(e,t,n,o){let r=o.walk.paragraphs.get(t);if(r!==void 0)return r;let i=n.get(I.key),s=new Set(kn(n,o.walk,!0).removedRuns),a=()=>Mi(t,n,o.walk),c=[...new Set([...zo(n),...s])].some(f=>{if(!dt(o.walk))return!1;let l=e.nodes.get(f);if(!(l instanceof Ie.Map))return!1;let d=Ri(e,l,f,i,a,o);if(d==="br")return!0;let p=s.has(f)&&!kn(l,o.walk,!0).removed;return d==="run"&&!p&&xi(e,f,l,o.walk)});return o.walk.paragraphs.set(t,c),c}function Xa(e,t){let n=0,o=[e];for(;o.length>0&&n<t;){let r=o.pop();if(n+=1,!("text"in r))for(let i of r.children??[])o.push(i)}return n}function Ei(e,t,n,o,r,i=Wo(new Set,jo(e)(t)),s=()=>!1,a=()=>{}){let c=i.walk,f=kn(n,c,!1).places;if(f.size===0)return o;let l=new Set(o.map(M=>M.key)),d=n.get(I.key),p=n.get(I.shell)?.local==="txBody",u=p?"p":"r",y=p?["bodyPr","lstStyle"]:["pPr"],g=new Map,k=M=>{let v=r(M);return v&&dt(c,Xa(v,wi))?v:null},x=(M,v)=>{a(v),g.set(M,v),c.placed.set(M,String(d))};for(let M of[...f.keys()].sort()){if(g.size>=$n||!dt(c))break;let v=c.placed.get(M);if(l.has(M)||v!==void 0&&v!==String(d))continue;let E=e.nodes.get(M);if(!(E instanceof Ie.Map)||E.get(I.part)!==t)continue;let F=E.get(I.shell);if(F?.ns!==Ko||F.local!==u||!kn(E,c,!0).removed||Yi(e,E,M,d,i.listings))continue;if(p){let R={stranded:i.stranded.has(M),listings:i.listings,walk:c};if(!Ba(e,M,E,R)&&!s(M))continue;let P=k(M);if(!P||!Ii(e,P,E,R))continue;x(M,P),i.rescued.add(M);continue}let _=xi(e,M,E,c),T=k(M);T&&(_||bi(T))&&x(M,T)}if(g.size===0)return o;let h=M=>{let v=f.get(M)??"";for(let E=0;E<$n&&v!==""&&!l.has(v)&&!g.has(v);E+=1)v=f.get(v)??"";return l.has(v)||g.has(v)?v:""},S=new Map;for(let[M,v]of g){let E=h(M),F=S.get(E);F?F.push(v):S.set(E,[v])}let w=[],m=new Set,b=(M,v)=>{if(!(v>$n))for(let E of S.get(M)??[])m.has(E.key)||(m.add(E.key),w.push(E),b(E.key,v+1))},Y=!1;for(let M of o)!Y&&("text"in M||!y.includes(M.local))&&(Y=!0,b("",0)),w.push(M),b(M.key,0);Y||b("",0);for(let M of g.values())m.has(M.key)||w.push(M);return w}function vi(e,t,n){if(n.rescued.size===0)return t;let o=Si(),r=s=>{if("text"in s||!n.rescued.has(s.key))return!0;let a=e.nodes.get(s.key),c={stranded:n.stranded.has(s.key),listings:n.listings,walk:o};return a instanceof Ie.Map&&Ii(e,s,a,c)},i=s=>{let a=s.children??[];if(!a.some(c=>!r(c))){let c=a.map(f=>"text"in f?f:i(f));return c.every((f,l)=>f===a[l])?s:{...s,children:c}}return{...s,children:a.filter(r).map(c=>"text"in c?c:i(c))}};return i(t)}var Oi="http://schemas.openxmlformats.org/drawingml/2006/main",$o=1<<20,Pi=(e,t)=>e.attrs.find(n=>n.ns===""&&n.local===t)?.value,Bn=class{#e;#t=new Map;#r=new Map;#f=new Map;#a=new Set;#d=new Map;#n=new Map;#u=new Map;#o=new Map;#m=new Set;#p=new Set;#g=new Set;#h=new Map;#y=new Map;#k=sn;#s=null;#S;#Y=new Map;#x=new Map;#R;#i=new Set;#l=new Map;constructor(t,n={value:0}){this.#e=t,this.#R=n;let o=`${t.doc.clientID.toString(36)}.`;for(let r of t.nodes.keys()){if(!r.startsWith(o))continue;let i=Number.parseInt(r.slice(o.length).replace(Cn,""),36);Number.isSafeInteger(i)&&i<=fr&&i>n.value&&(n.value=i)}}get seeded(){return this.#e.parts.size>0}#P(t,n){for(let o of this.#f.get(t)??[])this.#r.delete(o);for(let[o,r]of n)this.#r.set(o,r);this.#f.set(t,new Set(n.keys())),this.#a.clear(),this.#Y.clear();for(let[o,r]of this.#r)for(let i of r.companions)this.#a.add(i),this.#Y.set(i,o)}#I(t,n){for(let o of this.#t.get(t)?.idOf.keys()??[])this.#x.delete(o);if(!n){this.#t.delete(t);return}this.#t.set(t,n);for(let o of n.idOf.keys())this.#x.set(o,t)}#T(t){let n=this.#t.get(t);return n||(n={keyOf:new Map,idOf:new Map},this.#t.set(t,n)),n}#b=!1;#N(){let t=this.#e.doc.clientID.toString(36),n=this.#b?Cn:"",o;do this.#R.value+=1,o=`${t}.${n}${this.#R.value.toString(36)}`;while(this.#e.nodes.has(o));return o}seed(t){this.#b=!0;try{for(let n of t.parts.values())this.#A(n,void 0)}finally{this.#b=!1}}hasHiddenListings(t){return t.some(n=>this.#h.has(n))}dropHiddenListings(t,n,o){for(let r of t){let i=this.#h.get(r);if(!i)continue;let s=Js(this.#t.get(r)?.idOf,n.parts.get(r),o.parts.get(r)),a=this.#t.get(r),c=Qs(a?.idOf,a?.keyOf,n.parts.get(r));this.#h.delete(r);for(let[f,l]of i){let d=this.#v(f);if(!d||d.length!==l.length)continue;let p=[...l.at.keys()].sort((y,g)=>g-y);if(p.some(y=>d.get(y)!==l.at.get(y)))continue;let u=p.filter(y=>s(l.at.get(y)));u.length>0&&_s(this.#e,r,f,d.toArray(),u,c);for(let y=0;y<p.length;){let g=y+1;for(;g<p.length&&p[g]===p[g-1]-1;)g++;d.delete(p[g-1],g-y),y=g}}}}writeChange(t,n,o,r=!1){for(let i of o){this.#m.delete(i),this.#p.delete(i);let s=n.parts.get(i);if(!s){this.#e.parts.delete(i),this.#e.binaries.delete(i),this.#I(i,void 0);continue}this.#A(s,t.parts.get(i),r)}}#A(t,n,o=!1){if(t.kind==="binary"){(n?.kind!=="binary"||n.bytes!==t.bytes)&&this.#e.binaries.set(t.partName,t.bytes),et(this.#e.parts.get(t.partName))?.kind!=="binary"&&this.#e.parts.set(t.partName,{kind:"binary"});return}n?.kind==="binary"&&this.#e.binaries.delete(t.partName);let r={partName:t.partName,caseChange:o,ids:this.#T(t.partName),before:hn(n?.kind==="xml"?n.xml.root:void 0),texts:new Map,materialize:new Set,force:new Set},i=hn(t.xml.root),s=this.#o.get(t.partName)?.inParent,a=new Set;for(let[d]of r.before){if(i.has(d))continue;let p=r.ids.keyOf.get(d);p&&a.add(p);let u=p?this.#v(p):void 0;if(u)for(let y of u.toArray())s?.has(y)&&r.materialize.add(y)}for(let[d,p]of this.#e.doc.getMap(Ke)){let u=p;typeof u?.s=="string"&&a.has(u.s)&&r.materialize.add(d)}if(r.materialize.size>0){let d=p=>{let u=p.type==="element"?p.children.map(d).some(Boolean):!1,y=r.ids.keyOf.get(p.id),g=u||y!==void 0&&r.materialize.has(y);return g&&r.force.add(p.id),g};d(t.xml.root)}let c=this.#E(t.xml.root,r),f=this.#n.get(t.partName);this.#n.delete(t.partName);for(let d of hi(t.xml.root,f,r.ids.keyOf))this.#E(d,{...r,before:gi(r.before,d.id)});gs(this.#e,t.partName,t.xml.root,r.before,r.ids.keyOf),pi(this.#e,t.xml.root,r.before,r.ids.keyOf),this.#_(t.partName,t.xml.root,r);let l=et(this.#e.parts.get(t.partName));(l?.kind!=="xml"||l.root!==c)&&this.#e.parts.set(t.partName,{kind:"xml",root:c})}#_(t,n,o){if(this.#b)return;let r=Kr(this.#e,t,n,o.before,o.ids.keyOf,o.texts),i=jr(this.#e,n,o.before,o.ids.keyOf),s=this.#e.doc,a=new Map,c,f=new Set,l=d=>{if(this.#i.size>=$o||r.has(z(d.client,d.clock)))return;let p=Ue(s,d,a);c??=this.#D(),this.#i.add(z(p.client,p.clock)),this.#l.set(z(p.client,p.clock),c);let u=U(s,d);f.add(z(u.client,u.clock)),this.#i.add(z(u.client,u.clock)),this.#l.set(z(u.client,u.clock),c)};for(let d of o.texts.values())for(let p of d.deleted)l(p);for(let d of i)l(d);Rs(this.#e,t,f)}#D(){let t=this.#e.doc,n=te.getState(t.store,t.clientID);return t.getMap(Nr).set(String(t.clientID),n),n}get deletedAt(){return this.#l}noteRejected(t,n){if(this.#i.size>=$o)return;this.#i.add(t);let o=this.#l.get(n);o!==void 0&&this.#l.set(t,o)}get deletedText(){return this.#i}showingUnlisted(t){return t.filter(n=>this.#p.has(n)||(this.#u.get(n)?.size??0)>0||this.#m.has(n))}noteStep(t,n){for(let r of t)this.#i.delete(r),this.#l.delete(r);let o;for(let r of n)this.#i.size<$o&&(o??=this.#D(),this.#i.add(r),this.#l.set(r,o))}newCopies(t,n=!0){return Wr(this.#e,t,n)}#E(t,n){let{partName:o,ids:r,before:i}=n,s=r.keyOf.get(t.id),a=s===void 0?void 0:this.#e.nodes.get(s);if(s!==void 0&&a instanceof te.Map&&i.get(t.id)===t&&!n.force.has(t.id))return s;t.type==="element"&&(t.ns===Oi||At(t))&&this.#p.add(o),s!==void 0&&this.#o.get(o)?.watch.has(s)&&this.#m.add(o);let c=s===void 0||!(a instanceof te.Map);if(s===void 0||!(a instanceof te.Map)){s=this.#N();let _=new te.Map;this.#e.nodes.set(s,_),_.set(I.part,o),_.set(I.key,s),t.type==="text"?_.set(I.text,new te.Text):(_.set(I.attrs,new te.Map),_.set(I.children,new te.Array)),a=_,r.keyOf.set(t.id,s),r.idOf.set(s,t.id),this.#x.set(s,o)}let f=a;if(t.type==="text"){let _=f.get(I.text),T=_ instanceof te.Text?Zs(_,t.value,c,n.caseChange):void 0;return T&&n.texts.set(s,T),s}let l=ri(t);JSON.stringify(f.get(I.shell))!==JSON.stringify(l)&&f.set(I.shell,l);let d=oi(t);JSON.stringify(f.get(I.attrOrder))!==JSON.stringify(d)&&(d?f.set(I.attrOrder,d):f.delete(I.attrOrder));let p=this.#r.get(s),u=this.#e.doc.clientID.toString(36),y=p?.merge?[s,...p.companions].find(_=>Te(_)===u)??s:s,g=f.get(I.attrs);if(g instanceof te.Map){let _=new Map;for(let R of t.attrs)_.set(Lt(R),{ns:R.ns,local:R.local,value:R.value,...R.prefix?{prefix:R.prefix}:{}});let T=p?.merge?p.companions.map(R=>this.#M(R)):[];for(let R of[...g.keys()])_.has(R)||g.delete(R);for(let R of T)for(let P of[...R?.keys()??[]])_.has(P)||R.delete(P);for(let[R,P]of _){let C=p?.attrFrom.get(R)??(g.has(R)?s:void 0),K=C===void 0?void 0:this.#M(C);if(K&&JSON.stringify(K.get(R))===JSON.stringify(P))continue;if((this.#M(y)??g).set(R,P),p?.merge)for(let L of[s,...p.companions])L!==y&&this.#M(L)?.delete(R)}}let k=t.children.map(_=>this.#E(_,n)),x=new Set(k),h=f.get(I.children),S=(_,T)=>{let R=[],P=new Set,C=K=>{P.has(K)||(P.add(K),R.push(K))};for(let K of _){C(K);for(let A of this.#r.get(K)?.companions??[])T.has(A)&&C(A)}return R},w=new Set(h instanceof te.Array?h.toArray():[]),m=this.#u.get(o),b=this.#o.get(o)?.inParent,Y={has:_=>!n.materialize.has(_)&&(m?.get(_)===s||b?.get(_)===s)},M=p?k.filter(_=>!p.childFrom.has(_)&&!w.has(_)&&!Y?.has(_)):[],v=(p?k.filter(_=>!p.childFrom.has(_)&&(w.has(_)||y===s)):k).filter(_=>!Y?.has(_)||w.has(_));if(h instanceof te.Array){let _=h,T=_.toArray();Co(_,vo(T,ti(t,T,S(v,new Set(T)),R=>this.#L(R)),this.#d.get(o)))}let E=new Set;if(p?.merge)for(let _ of t.children)_.type==="element"&&E.add(_t(t,_,T=>Pi(_,T))?.slot);let F=new Set(M);p?.merge&&t.children.forEach((_,T)=>{_.type==="element"&&F.has(k[T])&&E.delete(_t(t,_,R=>Pi(_,R))?.slot)});for(let _ of p?.merge?p.companions:[]){let T=this.#v(_);if(!T)continue;let R=T.toArray(),P=R.filter(C=>{if(this.#a.has(C))return x.has(this.#Y.get(C));if(p.childFrom.get(C)===_)return x.has(C);let K=p.shadowed.get(C);return K!==void 0&&E.has(K)});Co(T,S([...P,..._===y?M:[]],new Set(R)))}return s}#L(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(I.shell):void 0;if(typeof o!="object"||o===null)return;let{ns:r,local:i}=o;return typeof r=="string"&&typeof i=="string"?{ns:r,local:i}:void 0}#M(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(I.attrs):void 0;return o instanceof te.Map?o:void 0}#v(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(I.children):void 0;return o instanceof te.Array?o:void 0}keyOf(t,n){return this.#t.get(t)?.keyOf.get(n)}idOf(t,n){return this.#t.get(t)?.idOf.get(n)}textOf(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(I.text):void 0;return o instanceof te.Text?o:void 0}locateCharacter(t,n){return Br(this.#e.doc,n,this.#t.get(t)?.idOf??[],o=>this.textOf(o))}partOf(t){let n=this.#e.nodes.get(t),o=n instanceof te.Map?n.get(I.part):void 0;return typeof o=="string"?o:void 0}recordOfText(t){let n=t.parent,o=n instanceof te.Map?n.get(I.key):void 0;if(typeof o!="string"||this.#e.nodes.get(o)!==n)return;let r=n.get(I.part);return typeof r=="string"?{key:o,part:r}:void 0}touchedParts(t){return js(this.#e,t,this.#x)}allParts(t){let n=new Set(this.#e.parts.keys());for(let o of t.parts.keys())n.add(o);return n}rebuild(t,n,o=!1){let r=[],i=[],s=new Map,a=new Map,c=new Map,f=new Map,l=new Map,d=[...t];for(let g of d)[this.#h,this.#n].forEach(k=>k.delete(g));let p=new Map,u=new Map,y=jo(this.#e);for(let g of d){let k=et(this.#e.parts.get(g));if(!k){if(this.#e.parts.has(g))return{ok:!1,reason:`invalid part entry ${g}`};n.parts.has(g)&&i.push(g);continue}if(k.kind==="binary"){let L=this.#e.binaries.get(g);if(!(L instanceof Uint8Array)||L.length>Vt.maxBinaryBytes)return{ok:!1,reason:`invalid binary part ${g}`};r.push({kind:"binary",partName:g,bytes:L});continue}this.#C=ii(this.#e,g,n.parts.get(g),this.#t.get(g)?.keyOf),this.#O=new Map;let x=new Map;this.#g=new Set,this.#c=void 0,this.#k=ln(this.#e,g,k.root),this.#y=new Map,this.#s=dn.of(this.#e,g,k.root);let h=(L,j,D)=>this.#w(L,g,j,D,x),[S,w]=[new Set,new Set],m=new Map,b=y(g),Y=(L=new Set)=>{[S,w]=[new Set,new Set],this.#S=Wo(L,b);let j=this.#w(k.root,g,new Set,0,x);j&&this.#s&&(j=this.#s.withStranded(j,h));let D=j&&Vs(this.#e,g,j,h,S,w,b);return m.clear(),D&&Ur(this.#e,D,h,m,S)},M=Y(),v=this.#k;if(M&&(v.lost.size>0||v.unseenWinners.size>0)){let L=ln(this.#e,g,k.root,gn(M));Gs(L,v)||(this.#k=L,this.#g=new Set,this.#y=new Map,x.clear(),M=Y())}if(M&&w.size>0&&(this.#g=new Set,this.#y=new Map,x.clear(),M=Y(w)),!M)return{ok:!1,reason:`${this.#c??"invalid node records"} in ${g}`};let E=vi(this.#e,ws(this.#e,g,M,h,this.#k.lost),this.#S);if(this.#c)return{ok:!1,reason:`${this.#c} in ${g}`};let F=new Set,_=new Set([...S,...this.#S.rescued,...this.#s?.rehomed??[]]),T=mi(this.#e,E,_,F,this.#g);l.set(g,F);let R=o?void 0:this.#t.get(g),P=n.parts.get(g),C=P?.kind==="xml"?P.xml.nextId:1,K=Va(g,T,{idOf:L=>R?.idOf.get(L),nextId:C});if(!K.ok)return{ok:!1,reason:`${g}: ${K.reason}`};let A={keyOf:new Map,idOf:new Map};for(let[L,j]of K.ids)A.idOf.set(L,j),A.keyOf.set(j,L);s.set(g,A),a.set(g,x),c.set(g,this.#g),f.set(g,qs(this.#y,T)),p.set(g,new Map([...this.#s?.shownIn??[],...this.#O,...m])),u.set(g,ei(T,S)),r.push({kind:"xml",partName:g,xml:K.part})}for(let[g,k]of s)this.#I(g,k);for(let g of i)this.#I(g,void 0);for(let[g,k]of a)this.#P(g,k);for(let g of i)this.#P(g,new Map);for(let[g,k]of c)this.#d.set(g,k);for(let g of i)this.#d.delete(g);for(let[g,k]of f)k.size>0&&this.#h.set(g,k);for(let g of i)this.#h.delete(g);for(let[g,k]of p)this.#u.set(g,k);for(let[g,k]of u)this.#o.set(g,k);for(let g of i)this.#o.delete(g);for(let g of i)this.#u.delete(g);for(let[g,k]of l)this.#n.set(g,k);return this.#s=null,{ok:!0,parts:r,removed:i}}#c;#C=new Map;#O=new Map;#w(t,n,o,r,i){if(r>Vt.maxReadDepth||o.has(t))return null;o.add(t);let s=this.#e.nodes.get(t);if(!(s instanceof te.Map)||s.get(I.part)!==n)return null;let a=s.get(I.shell),c=s.get(I.attrs),f=s.get(I.children);if(typeof a!="object"||a===null||!(c instanceof te.Map)||!(f instanceof te.Array))return null;let l=a,d=[],p=f.toArray(),u=this.#C.get(t);if(u){let m=new Set(u.filter(Y=>{let M=this.#e.nodes.get(Y);return M instanceof te.Map&&!we(M)})),b=new Set(p);p=vo(u,p,m);for(let Y of p)typeof Y=="string"&&!b.has(Y)&&this.#O.set(Y,t)}for(let[m,b]of p.entries()){if(typeof b!="string")continue;if(o.has(b)){let v=this.#y.get(t);v||this.#y.set(t,v={length:p.length,at:new Map}),v.at.set(m,b);continue}let Y=this.#e.nodes.get(b);if(Y instanceof te.Map&&Y.get(I.text)instanceof te.Text){if(Y.get(I.part)!==n)continue;o.add(b),d.push({key:b,text:ct(Y.get(I.text))});continue}let M=this.#w(b,n,o,r+1,i);if(M)d.push(M);else if(this.#c)return null}let y=si(c,s.get(I.attrOrder)),g=l.ns,k=l.local,x=k==="p"&&g===Oi||At({ns:g,local:k})?Ei(this.#e,n,s,d,m=>{let b=this.#w(m,n,new Set(o),r+1,i);return this.#c?null:b},this.#S,m=>this.#s?.showsBelow(m)??!1,m=>{for(let b of gn(m))o.add(b)}):d,h=this.#s?this.#s.withUndone(t,n,x,o,m=>this.#w(m,n,o,r+1,i)):x;if(this.#c)return null;let S=ks(this.#e,{ns:g,local:k},h,this.#g,this.#k.unseenWinners),w=xo({ns:g,local:k},S,i);return w?{key:t,ns:g,local:k,...typeof l.prefix=="string"?{prefix:l.prefix}:{},nsDecls:Array.isArray(l.nsDecls)?l.nsDecls:[],attrs:y,children:[...ht({ns:g,local:k},w,m=>"text"in m?void 0:m)]}:(this.#c="too many concurrent copies of one element",null)}};import*as je from"yjs";var Xn="pptxEditor",Ga=256,Di=256,Ci=512,Ti=256,Ni=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,Mt=(e,t=Ga)=>typeof e=="string"&&e.trim().length>0&&e.length<=t;function _i(e){return!Mt(e.actorId)||!Mt(e.name)||e.role!==void 0&&e.role!=="human"&&e.role!=="agent"?"invalid-identity":e.color!==void 0&&!Ni.test(e.color)?"invalid-identity-color":null}function Li(e){let{actorId:t,name:n,color:o,role:r}=e;return!Mt(t)||!Mt(n)?null:{actorId:t,name:n,...typeof o=="string"&&Ni.test(o)?{color:o}:{},...r==="human"||r==="agent"?{role:r}:{}}}function Fi(e){let t=e?.[Xn];return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:null}function zi(e,t){if(e.kind==="shapes"){let i=e.shapes.slice(0,Ci).map(s=>t.keyOf(e.part,s)).filter(s=>s!==void 0);return i.length>0?{kind:"shapes",part:e.part,keys:i}:void 0}let n=i=>{let s=t.keyOf(e.part,i.node);if(s===void 0)return;let a=t.textOf(s);if(!a)return{key:s};let c=Math.max(0,Math.min(Math.trunc(i.offset)||0,a.length)),f=c===a.length&&c>0?Ce(a,c-1,1)[0]:void 0;return{rel:je.relativePositionToJSON(je.createRelativePositionFromTypeIndex(a,c)),...f?{left:{client:f.client,clock:f.clock}}:{}}},o=n(e.anchor),r=n(e.head);return o&&r?{kind:"text",anchor:o,head:r}:void 0}function Ki(e,t){return{actorId:e.actorId,name:e.name,...e.color?{color:e.color}:{},...e.role?{role:e.role}:{},...t?{selection:t}:{}}}function ji(e){let t=[];for(let[n,o]of e.getStates()){if(t.length>=Di)break;let r=Fi(o),i=r?Li(r):null;i&&t.push({...i,isLocal:n===e.clientID})}return t}function Ai(e,t,n){if(typeof e!="object"||e===null)return null;let o=e;if(Mt(o.key,Ti)){let l=n.partOf(o.key),d=l?n.idOf(l,o.key):void 0;return l&&d?{part:l,node:d,offset:0}:null}let r=o.rel;if(typeof r!="object"||r===null)return null;let i;try{i=je.createAbsolutePositionFromRelativePosition(je.createRelativePositionFromJSON(r),t)}catch{return null}if(!i||!(i.type instanceof je.Text))return null;let s=n.recordOfText(i.type);if(!s)return null;let a=n.idOf(s.part,s.key),c=r,f=c.item??o.left;if(f&&typeof f=="object"){let{client:l,clock:d}=f;if(typeof l=="number"&&Number.isSafeInteger(l)&&l>=0&&typeof d=="number"&&Number.isSafeInteger(d)&&d>=0){let p=je.createID(l,d),u=Z(t,p);if(a&&u&&!u.deleted&&u.parent===i.type)return{part:s.part,node:a,offset:i.index};let y=n.locateCharacter(s.part,p);if(y&&(c.item||y.text!==i.type))return{part:s.part,node:y.node,offset:y.offset+(c.item?typeof c.assoc=="number"&&c.assoc<0?1:0:1)}}}return a?{part:s.part,node:a,offset:i.index}:null}function Vn(e,t,n){if(typeof e!="object"||e===null)return null;let o=e;if(o.kind==="shapes"&&Mt(o.part,1024)&&Array.isArray(o.keys)){let r=o.part,i=o.keys.slice(0,Ci).filter(s=>Mt(s,Ti)).map(s=>n.idOf(r,s)).filter(s=>s!==void 0);return i.length>0?{kind:"shapes",part:r,shapes:i}:null}if(o.kind==="text"){let r=Ai(o.anchor,t,n),i=Ai(o.head,t,n);return!r||!i||r.part!==i.part?null:{kind:"text",part:r.part,anchor:{node:r.node,offset:r.offset},head:{node:i.node,offset:i.offset}}}return null}function Wi(e,t,n){let o=[],r=0;for(let[i,s]of e.getStates()){if(++r>Di)break;if(i===e.clientID)continue;let a=Fi(s),c=a?Li(a):null;if(!a||!c)continue;let f=Vn(a.selection,t,n);f&&o.push({actorId:c.actorId,name:c.name,...c.color?{color:c.color}:{},selection:f})}return o}import*as Yt from"yjs";var Ua=65536,Ha=64,qa=(e,t)=>e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock;function $i(e,t){let n=t.clock-e.id.clock;if(t.client!==e.id.client||n<0||n>=e.length)return;let o=e.content.getContent()[n];return typeof o=="string"?o:void 0}function Gn(e,t){let n=e.nodes.get(t);return n instanceof Yt.Map?n:void 0}function Bi(e,t){let o=Gn(e,t)?.get(I.children);if(!(o instanceof Yt.Array))return null;for(let r of o.toArray().slice(0,8)){let i=Gn(e,r)?.get(I.children);if(i instanceof Yt.Array)for(let s of i.toArray().slice(0,8)){let a=ie(Gn(e,s));if(a)return Tt(e.doc,U(e.doc,a.source(0)))}}return null}function Ja(e,t,n,o,r){let i=n.origin;if(!i)return null;let s=w=>w.id.client===o&&qa(w.origin,i),a=[],c=n.left;for(;c!==null;c=c.left){if(!r())return null;if(!c.deleted){if($i(c,i)!==void 0)break;if(!s(c))return null;a.unshift(c)}}let f=c?$i(c,i):void 0;if(!f)return null;let l=[],d=w=>typeof w=="string"&&Gn(e,w)?.get($.splitFrom)===f,p=n,u=!0;for(let w=n;w!==null;w=w.right){if(!r())return null;if(w.deleted)continue;if(w.id.client!==n.id.client)break;let m=w.content.getContent(),b=m.findIndex(Y=>!d(Y));if(b===0)break;if(l.push(...m.slice(0,b<0?m.length:b)),l.length>Ha)return null;if(p=w,u=b<0,!u)break}let y=[];for(let w=p.right;u&&w!==null&&a.length===0;w=w.right){if(!r())return null;if(!w.deleted){if(!s(w))break;y.push(w)}}let g=[...a,...y].flatMap(w=>w.content.getContent().filter(m=>typeof m=="string"));if(l.length===0||g.length===0||g.some(d))return null;let k=a.length>0?g[g.length-1]:f,x=new Map,h=w=>(x.has(w)||x.set(w,Bi(e,w)),x.get(w)),S=[];for(let w of l){let m=Bi(e,w);if(!m)return null;let b=f;for(let M of g){if(!r())return null;let v=h(M);if(!v||v.text!==m.text||v.at>=m.at)break;b=M}let Y=S[S.length-1];Y?.after===b?Y.keys.push(w):S.push({after:b,keys:[w]})}return S.every(w=>w.after===k)?null:{list:t,groups:S}}function Xi(e,t,n){let o=e.doc.clientID,r=[],i=Ua,s=()=>(i-=1)>=0;for(let a of t.changed.keys()){if(!(a instanceof Yt.Array))continue;let c=a.parent;if(!(c instanceof Yt.Map)||c.get(I.children)!==a)continue;let f=a;for(let l=f._start;l!==null;l=l.right){if(!s())return;if(l.deleted||l.id.client===o||l.id.clock<(t.beforeState.get(l.id.client)??0))continue;let d=Ja(e,f,l,o,s);d&&r.push(d)}}r.length!==0&&e.doc.transact(()=>{for(let{list:a,groups:c}of r){let f=c.flatMap(u=>u.keys),l=a.toArray(),d=f.map(u=>l.indexOf(u)),p=u=>l.indexOf(u)>=0&&l.indexOf(u)===l.lastIndexOf(u);if(!(!f.every(p)||!c.every(u=>p(u.after)))){for(let u of[...d].sort((y,g)=>g-y))a.delete(u,1);for(let{after:u,keys:y}of c)a.insert(a.toArray().indexOf(u)+1,[...y])}}},n)}import*as Vi from"yjs";var Qa=new Set([I.part,I.key,I.shell,oe.copyOf,oe.newParagraph]);function Gi(e){return t=>{let n=t.parent;if(n===e)return!1;let o=Oe(n);return o===null||o.parent!==e?!0:t.content instanceof Vi.ContentType?!1:!(t.parentSub!==null&&Qa.has(t.parentSub)&&yr(t))}}import*as Ze from"yjs";var Bo="followed",Hi=65536,Ui=e=>{let t=Ze.createDeleteSet();return t.clients.set(e.client,[{clock:e.clock,len:1}]),t},Xo=e=>{let t=e.meta.get(Bo);return t instanceof Map?t:void 0};function qi(e,t){for(let n of t)for(let o of e){if(!Ze.isDeleted(o.insertions,n.anchor))continue;o.insertions=Ze.mergeDeleteSets([o.insertions,Ui(n.added)]),o.deletions=Ze.mergeDeleteSets([o.deletions,Ui(n.gone)]);let r=Xo(o);r||o.meta.set(Bo,r=new Map),r.set(n.run,{from:n.from,to:n.to})}}function Ji(e,t){let n=Xo(e);n&&t.meta.set(Bo,new Map(n))}var Za=(e,t)=>{let n=0;for(let o=e._start;o!==null;o=o.right)if((n+=1)>Hi||!o.deleted&&o.countable&&o.content.getContent().includes(t))return!0;return!1};function el(e,t){let n=[],o=0;for(let r=e._start;r!==null&&o<Hi;r=r.right){if(o+=1,!r.deleted||!r.countable)continue;let i=r.content.getContent();for(let s=0;s<i.length;s+=1)i[s]===t&&n.push(Ze.createID(r.id.client,r.id.clock+s))}return n}function tl(e,t){if(t.length===0)return e;let n=Ze.createDeleteSet();for(let[o,r]of e.clients){let i=t.filter(a=>a.client===o).map(a=>a.clock),s=[];for(let{clock:a,len:c}of r){let f=a;for(let l of i.filter(d=>d>=a&&d<a+c).sort((d,p)=>d-p))l>f&&s.push({clock:f,len:l-f}),f=l+1;f<a+c&&s.push({clock:f,len:a+c-f})}s.length>0&&n.clients.set(o,s)}return n}function Vo(e){let t=Xo(e),n=new Set;if(!t)return n;for(let[o,{from:r,to:i}]of t){if(Za(i,o)){n.add(o);continue}e.deletions=tl(e.deletions,el(r,o)),t.delete(o)}return n}import*as de from"yjs";var nl=4096,ol=4096,rl=32;function sl(e,t,n,o,r=new Set){let i=e.doc,s=new Map,a=0;for(let[c,f]of i.getMap(Xe).entries()){if(typeof f!="string"||!t.has(f)||!n(f,c))continue;if((a+=1)>nl)return null;let l=e.nodes.get(c),d=l instanceof de.Map?l.get(I.text):void 0;if(!(!ie(l)||!(d instanceof de.Text))){for(let p=d._start;p!==null;p=p.right)if(!(p.deleted||!p.countable))for(let u=0;u<p.length;u+=1){let y=z(p.id.client,p.id.clock+u);if(r.has(y))continue;let g=U(i,de.createID(p.id.client,p.id.clock+u),o),k=z(g.client,g.clock);if(k!==y){let x=s.get(k)??[];x.push({text:d,item:p,j:u}),s.set(k,x)}}}}return s}function st(e,t){let n=t.parent;if(!(n instanceof de.Map)||Oe(n)?.parent!==e.nodes)return null;let o=n.get(I.part);return typeof o=="string"?o:null}function Zi(e,t){let n=e.content.getContent();return n.length>0&&typeof n[0]=="string"?String(n.join("")).charAt(t):""}var Qi=e=>de.createID(e.item.id.client,e.item.id.clock+e.j);function ec(e,t,n,o){let r=e.doc,i=[],s=new Map,a=!1;return ae(r,t,c=>{if(a||!c.countable||!(c.parent instanceof de.Text)||c.redone===null)return;let f=c.parent,l=Z(r,c.redone);if(!st(e,f)||!l||l.deleted||l.parent!==f)return;let d=Math.min(c.length,l.length);for(let p=0;p<d;p+=1){if(i.length>=Ge){a=!0;return}let u=U(r,de.createID(c.id.client,c.id.clock+p),s);i.push({text:f,item:l,j:p,root:u,char:Zi(l,p)})}}),!a&&tc(e,i,n,s,()=>!0,o)}function tc(e,t,n,o,r,i){let s=e.doc;if(t.length===0)return!1;let a=new Set;for(let h of t)a.add(st(e,h.text));let c=h=>z(h.item.id.client,h.item.id.clock+h.j),f=new Set(t.map(c)),l=sl(e,a,n,o,f);if(!l||l.size===0)return!1;let d=h=>{let S=0,w=h.item,m=h.j-1;for(;w!==null&&S<ol;){for(;m>=0&&w.countable;m-=1,S+=1){let b=de.createID(w.id.client,w.id.clock+m);if(f.has(z(b.client,b.clock)))continue;let Y=U(s,b,o),M=l.get(z(Y.client,Y.clock))?.[0];if(M&&M.text!==h.text)return M;if(!w.deleted)return null}w=w.left,m=w?w.length-1:-1}return null},p=[],u=[],y=new Map([...a].map(h=>[h,en(s,Nt(i,h))])),g=[];for(let h of t){let S=(l.get(z(h.root.client,h.root.clock))??[]).filter(b=>b.text!==h.text);if(S.length>0){let b=S.flatMap(v=>{let E=nc(e,v.text),F=ie(v.text.parent);return E&&F?[{key:E,copy:F}]:[]}),Y=On(h.item,h.j,v=>f.has(z(v.client,v.clock))||Me(s,v)!==null),M=y.get(st(e,h.text));if(M&&Pn(e,M,h.text,Y,b,o,Qi(h)))g.push(...S);else{let v=Nt(i,st(e,h.text));for(let E of b){let F=v.get(E.key)?.run,_=F?e.nodes.get(F):void 0;_ instanceof de.Map&&_.get($.copyWinner)!==!0&&_.set($.copyWinner,!0)}p.push(h);continue}}let w=r(h)?d(h):null;if(!w)continue;let m=u[u.length-1];m&&m.to.item===w.item&&m.to.j===w.j?m.chars.push(h):u.push({to:w,chars:[h]})}if(p.length===0&&u.length===0&&g.length===0)return!1;let k=[];for(let{to:h,chars:S}of u){let w=Yn(h.text,Qi(h));if(w<0)continue;let m=S.map(Y=>Y.char).join("");if(m.length===0)continue;let b=de.getState(s.store,s.clientID);h.text.insert(w+1,m),S.forEach((Y,M)=>{k.push(b+M,Y.root.client,Y.root.clock,1);for(let v of[Pe,Dt]){let E=s.getMap(v),F=E.get(c(Y));F!==void 0&&E.set(z(s.clientID,b+M),F)}}),p.push(...S)}Jt(s,k);let x=new Map;for(let h of[...p,...g]){let S=x.get(h.text);S?S.add(c(h)):x.set(h.text,new Set([c(h)]))}for(let[h,S]of x)_e(h,S);return!0}function Un(e,t,n,o){let r=e.doc,i=[],s=new Set,a=new Set,c=new Map,f=[...de.decodeStateVector(de.encodeStateVector(r))].flatMap(([d,p])=>[d,p]),l=0;return ae(r,t,d=>{if(!d.countable||!(d.parent instanceof de.Text)||d.redone===null)return;let p=d.parent,u=d.redone;if(u.client!==r.clientID||st(e,p)===null)return;let y=Z(r,u);if(!(!y||y.parent!==p)){a.add(p);for(let g=0;g<d.length;g+=1){if((l+=1)>Ge)return;let k=de.createID(d.id.client,d.id.clock+g);for(let Y=0;Y<rl;Y+=1){let M=Me(r,k);if(!M)break;k=M}let x=U(r,k,c,!1);s.add(z(x.client,x.clock));let h=u.clock+g,S=U(r,k),w=o?.get(z(S.client,S.clock))??Ve(r,de.createID(d.id.client,d.id.clock+g));if(w&&r.getMap(Dt).set(z(r.clientID,h),[w.start.client,w.start.clock,w.enter,w.client,w.key]),n){let Y=U(r,k);r.getMap(Pe).set(z(r.clientID,h),[d.id.client,d.id.clock+g,n.has(z(Y.client,Y.clock)),f])}let m=i.length;m>0&&i[m-4]+i[m-1]===h&&i[m-3]===k.client&&i[m-2]+i[m-1]===k.clock?i[m-1]+=1:i.push(h,k.client,k.clock,1)}}}),Jt(r,i),{roots:s,texts:a}}function Go(e,t){let n=e.doc,o=n.getMap(Le),r=new Set;for(let i of t){let s=i===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(i),a=i===null?void 0:o.get(i);if(!s||!Array.isArray(a))continue;let c=Math.min(Number(a[2])||0,Ge),f=Number(s[1]);for(let l=Number(s[2]),d=l+c;l<d;){let p=Z(n,de.createID(f,l));if(!p)break;if(!p.deleted&&p.parent instanceof de.Text&&st(e,p.parent)){r.add(p.parent);break}l=p.id.clock+p.length}}return r}function Uo(e,t){let n=new Set,o=[...e.doc.getMap(Le).keys()].sort().slice(0,Ge);for(let r of o)for(let i of Go(e,[r])){let s=st(e,i);s!==null&&t.has(s)&&n.add(i)}return n}function nc(e,t){let n=Oe(t.parent);return n&&n.parent===e.nodes&&typeof n.parentSub=="string"?n.parentSub:null}var il=(e,t)=>e.client<t.client||e.client===t.client&&e.clock>t.clock;function Ho(e,t,n,o){let r=e.doc,i=new Map,s=[...t],a=new Set;for(let h of s){let S=st(e,h);S!==null&&a.add(S)}if(a.size===0)return!1;let c=new Set(Uo(e,a));for(let h of s)c.add(h);let f=new Map([...a].map(h=>[h,en(r,Nt(o,h))])),l=(h,S,w)=>{let m=r.getMap(Pe).get(z(h.client,h.clock)),b=r.getMap(Pe).get(z(S.client,S.clock));if(Array.isArray(m)&&Array.isArray(b)&&m[2]!==b[2])return m[2]===!1;let Y=Ve(r,h),M=Ve(r,S);if(Y&&M&&Y.key!==M.key){let v=E=>({key:E.key,from:E.start,start:U(r,E.start,i),enter:E.enter,client:E.client});return f.get(w).ahead(v(Y),v(M))}return il(h,S)},d=new Map,p=new Map,u=(h,S)=>{let w=p.get(h);w?w.add(z(S.client,S.clock)):p.set(h,new Set([z(S.client,S.clock)]))},y=0;for(let h of c){let S=st(e,h),w=nc(e,h);if(S===null||w===null)continue;let m=n(S,w)?"":`${w}\0`;for(let b=h._start;b!==null&&y<Ge;b=b.right)if(!(b.deleted||!b.countable))for(let Y=0;Y<b.length;Y+=1,y+=1){let M=de.createID(b.id.client,b.id.clock+Y);if(!Me(r,M))continue;let v=U(r,M,i),E=m+z(v.client,v.clock),F=d.get(E);F?l(M,F.id,S)?(u(F.text,F.id),d.set(E,{id:M,text:h})):u(h,M):d.set(E,{id:M,text:h})}}for(let[h,S]of p)_e(h,S);let g=[];for(let{id:h,text:S}of d.values()){let w=Z(r,h);if(!w||w.deleted||w.parent!==S)continue;let m=h.clock-w.id.clock;g.push({text:S,item:w,j:m,root:U(r,h,i),char:Zi(w,m)})}let k=r.clientID;return tc(e,g,n,i,h=>h.item.id.client===k,o)||p.size>0}import*as ee from"yjs";var $e=1<<20,rc=4096;function We(e,t){if(!(t instanceof ee.Text))return!1;let n=t.parent;return n instanceof ee.Map&&Oe(n)?.parent===e.nodes}function Hn(e,t){let n=e.doc,o=new Set,r=new Map,i=0,s=!1;return ae(n,t,a=>{if(!(s||!a.countable||!We(e,a.parent)))for(let c=0;c<a.length;c+=1){if((i+=1)>$e){s=!0;return}let f=U(n,ee.createID(a.id.client,a.id.clock+c),r);o.add(z(f.client,f.clock))}}),s?null:o}function qo(e,t){let n=new Map,o=$e,r=new Map;return ae(e.doc,t,i=>{if(o<=0||!i.countable||!We(e,i.parent))return;let s=ie(xe(i));for(let a=0;a<i.length&&--o>=0;a+=1){let c=ee.createID(i.id.client,i.id.clock+a),f=s&&c.client===s.client&&c.clock>=s.clock&&c.clock<s.clock+s.length?{start:s.source(0),enter:go(e.doc,s),client:s.client,key:String(xe(i)?.get(I.key)??"")}:Ve(e.doc,c);if(!f)continue;let l=U(e.doc,c,r);n.set(z(l.client,l.clock),f)}}),n}function oc(e,t){let n=e.parent,o=Oe(n)?.parentSub,r=n.get(I.part);return typeof o=="string"&&typeof r=="string"&&t(r,o)}function sc(e,t,n){let o=e.doc,r=new Set;if(t.size===0)return r;let i=new Map,s=0,a=(d,p)=>{if(!oc(d,n))return!0;for(let u=d._start;u!==null;u=u.right)if(!(u.deleted||!u.countable))for(let y=0;y<u.length;y+=1){if((s+=1)>$e)return!1;let g=ee.createID(u.id.client,u.id.clock+y);if(!p(g))continue;let k=U(o,g,i),x=z(k.client,k.clock);t.has(x)&&r.add(x)}return!0};for(let d of t){let[p,u]=d.split(":").map(Number),y=Z(o,ee.createID(p,u));y&&!y.deleted&&We(e,y.parent)&&oc(y.parent,n)&&r.add(d)}let c=0;for(let d of o.getMap(Xe).keys()){if((c+=1)>rc)return null;let p=e.nodes.get(d),u=p instanceof ee.Map?p.get(I.text):void 0;if(!(!ie(p)||!We(e,u))&&!a(u,()=>!0))return null}let f=new Set,l=0;for(let[d,p]of o.getMap(Le).entries()){if((l+=1)>Ge)return null;let u=/^(\d{1,16}):(\d{1,16})$/.exec(d);if(!u||!Array.isArray(p))continue;let y=Z(o,ee.createID(Number(u[1]),Number(u[2])));y&&We(e,y.parent)&&f.add(y.parent)}for(let d of f)if(!a(d,p=>Me(o,p)!==null))return null;return r}function Jo(e,t,n,o){let r=e.doc,i=new Map,s=new Map,a=0;ae(r,t,c=>{if(a>$e||!c.countable||c.redone===null)return;let f=c.parent;if(!We(e,f))return;let l=Z(r,c.redone);if(!l||l.deleted||l.parent!==f)return;let d=Math.min(c.length,l.length);for(let p=0;p<d;p+=1){if((a+=1)>$e)return;let u=U(r,ee.createID(c.id.client,c.id.clock+p),s),y=z(u.client,u.clock);if(!n.has(y)||o.has(y))continue;let g=i.get(f)??new Set;g.add(z(l.id.client,l.id.clock+p)),i.set(f,g)}});for(let[c,f]of i)_e(c,f);return i.size>0}function ic(e,t,n,o,r){if(n.size===0)return!1;let i=e.doc,s=i.getMap(Le),a=new Map,c=y=>{if(a.has(y))return a.get(y);let g=cl(e,y);return a.set(y,g),g},f=new Map,l=null,d=new Map,p=y=>{if(!l){l=new Set;let k=0;for(let x of n){if((k+=1)>$e)break;let[h,S]=x.split(":").map(Number),w=U(i,ee.createID(h,S),d);l.add(z(w.client,w.clock))}}let g=U(i,y,d);return l.has(z(g.client,g.clock))},u=new Map;for(let y of t){let g=y===null?null:/^(\d{1,16}):(\d{1,16})$/.exec(y),k=y===null?void 0:s.get(y);if(!g||!Array.isArray(k)||k.length!==3)continue;let[x,h,S]=k;if(!Number.isSafeInteger(x)||!Number.isSafeInteger(h)||!Number.isSafeInteger(S))continue;let w=Number(g[1]),m=Number(g[2]);if(w===i.clientID)continue;let b=c(w);if(!b)continue;let Y=Math.min(S,Ge);for(let M=0;M<Y;M+=1){let v=ee.createID(x,h+M),E=z(v.client,v.clock),F=b.copies.get(E),_=i.getMap(Pe).get(z(w,m+M)),T=Array.isArray(_)&&(_.length===3||_.length===4)&&Number.isSafeInteger(_[0])&&_[0]>=0&&Number.isSafeInteger(_[1])&&_[1]>=0&&typeof _[2]=="boolean",R="";if(T){let K=Ue(i,ee.createID(_[0],_[1]),f),A=z(K.client,K.clock);if(!n.has(A))continue;if(!_[2]){let L=_[3],j=r?.get(A);if(!Array.isArray(L)||L.length>8192||j===void 0)continue;let D=!1;for(let O=0;O+1<L.length;O+=2)L[O]===i.clientID&&Number.isSafeInteger(L[O+1])&&L[O+1]>j&&(D=!0);if(D)continue}R=A}else{if(!b.sources.has(E)&&!(F!==void 0&&b.restored.has(F)))continue;let K=U(i,v,f,!1);if(!n.has(z(K.client,K.clock))&&!p(v))continue}o?.(z(w,m+M),R);let P=Z(i,ee.createID(w,m+M));if(!P||P.deleted||!We(e,P.parent))continue;let C=u.get(P.parent)??new Set;C.add(z(w,m+M)),u.set(P.parent,C)}}for(let[y,g]of u)_e(y,g);return u.size>0}function cl(e,t){let n=e.doc,o={sources:new Set,copies:new Map,restored:new Set},r=0,i=0;for(let c of n.getMap(Xe).keys()){if((r+=1)>rc)return null;let f=ie(e.nodes.get(c));if(!(!f||f.client!==t))for(let l=0;l<f.length;l+=1){if((i+=1)>$e)return null;let d=f.source(l),p=z(d.client,d.clock);o.sources.add(p),o.copies.set(z(f.client,f.clock+l),p)}}let s=`${t}:`,a=0;for(let[c,f]of n.getMap(Le).entries()){if(!c.startsWith(s)||!Array.isArray(f)||f.length!==3)continue;let[l,d,p]=f;if(!(!Number.isSafeInteger(l)||!Number.isSafeInteger(d)||!Number.isSafeInteger(p)))for(let u=0;u<Math.min(p,Ge);u+=1){if((a+=1)>$e)return null;o.restored.add(z(l,d+u))}}return o}function cc(e,t){let n=t;for(let o=0;o<32;o+=1){let r=Z(e,n);if(!r||!r.redone)return r;n=ee.createID(r.redone.client,r.redone.clock+n.clock-r.id.clock)}return null}function ac(e,t){let n=new Set,o=!1;return ae(e.doc,t,r=>{if(!(o||!r.countable||!We(e,r.parent)))for(let i=0;i<r.length;i+=1){if(n.size>=$e){o=!0;return}let s=ee.createID(r.id.client,r.id.clock+i),a=cc(e.doc,s);a&&!a.deleted&&n.add(z(s.client,s.clock))}}),o?null:n}function lc(e,t,n){let o=e.doc,r=new Set;if(n.size===0)return r;let i=new Map,s=new Map,a=new Set,c=new Set,f=0;ae(o,t.insertions,d=>{if(!(!d.countable||!We(e,d.parent)))for(let p=0;p<d.length&&f++<$e;p+=1){let u=ee.createID(d.id.client,d.id.clock+p);ee.compareIDs(U(o,u,i),u)&&c.add(z(u.client,u.clock))}});let l=0;return ae(o,t.deletions,d=>{if(!(l>$e||!d.countable||d.redone===null)&&We(e,d.parent))for(let p=0;p<d.length;p+=1,l+=1){let u=U(o,ee.createID(d.id.client,d.id.clock+p),i);a.add(z(u.client,u.clock))}}),ae(o,t.insertions,d=>{if(!d.deleted||!d.countable||!We(e,d.parent))return;let p=ie(xe(d));for(let u=0;u<d.length;u+=1){let y=ee.createID(d.id.client,d.id.clock+u);if(!n.has(z(y.client,y.clock))||cc(o,y)?.deleted!==!0)continue;let g=U(o,y,i);if(p&&p.client===y.client&&y.clock>=p.clock&&y.clock<p.clock+p.length&&!c.has(z(g.client,g.clock))||a.has(z(g.client,g.clock)))continue;let k=Ue(o,y,s);r.add(z(k.client,k.clock)),r.add(z(g.client,g.clock))}}),r}function fc(e,t){let n=new Set,o=new Map,r=$e;if(ae(e.doc,t.insertions,s=>{if(!(!s.countable||!We(e,s.parent)))for(let a=0;a<s.length&&r-- >0;a+=1){let c=ee.createID(s.id.client,s.id.clock+a);ee.compareIDs(U(e.doc,c,o),c)&&n.add(z(c.client,c.clock))}}),r<=0||n.size===0)return;let i=ee.createDeleteSet();for(let s of e.nodes.values()){if(--r<0)return;let a=s instanceof ee.Map?s.get(I.text):null;if(a instanceof ee.Text){for(let c=a._start;c&&--r>=0;c=c.right)if(!(c.deleted||!c.countable))for(let f=0;f<c.length&&--r>=0;f+=1){let l=ee.createID(c.id.client,c.id.clock+f),d=U(e.doc,l,o);if(!n.has(z(d.client,d.clock)))continue;let p=i.clients.get(l.client)??[];p.push({clock:l.clock,len:1}),i.clients.set(l.client,p)}if(r<0)return}}t.insertions=ee.mergeDeleteSets([t.insertions,i])}import*as ye from"yjs";function dc(e,t,n){let o=r=>{let i=e.nodes.get(r),s=i instanceof ye.Map?i.get(I.children):void 0;return s instanceof ye.Array?s.toArray():[]};for(let r of o(t))if(!(typeof r!="string"||e.nodes.get(r)?.get?.(I.shell)?.local!=="t"))for(let s of o(r)){let a=typeof s=="string"?e.nodes.get(s):void 0,c=a instanceof ye.Map?a.get(I.text):void 0;c instanceof ye.Text&&n.add(c)}}var Bt=(e,t)=>Oe(t)?.parent===e.nodes&&t instanceof ye.Map?t:null;function uc(e,t){let n=e.doc.clientID.toString(36),o=zt(e),r=new Set,i=new Map,s=c=>{if(typeof c!="string")return new Set;let f=i.get(c);if(!f){let l=et(e.parts.get(c));f=l?.kind==="xml"?ln(e,c,l.root).unseenWinners:new Set,i.set(c,f)}return f};if(ae(e.doc,t.insertions,c=>{if(c.parent!==e.nodes||c.deleted||!(c.content instanceof ye.ContentType))return;let f=c.content.type,l=wt(f),d=l?o(l.group):void 0;!l||d===void 0||d===n||s(f.get(I.part)).has(l.group)||r.add(l.from)}),r.size===0)return t.deletions;let a=new Set;for(let c of r)dc(e,c,a);return a.size===0?t.deletions:Mn(e.doc,t.deletions,c=>a.has(c.parent))}function pc(e,t){let n=new Map,o=e.doc,r=new Map,i=new Set,s=[];ae(o,t.insertions,g=>{let k=g.parent;if(!(!(k instanceof ye.Text)||!g.countable)&&Bt(e,k.parent)){n.has(k)||n.set(k,!1);for(let x=0;x<g.length;x+=1){let h=U(o,ye.createID(g.id.client,g.id.clock+x),r),S=`${h.client}:${h.clock}`;g.deleted?s.push([k,S]):i.add(S)}}});for(let[g,k]of s)i.has(k)||n.set(g,!0);if(![...n.values()].some(Boolean))return t;let a=new Map,c=new Set;if(ae(e.doc,t.deletions,g=>{let k=Bt(e,g.parent);if(!k||g.parentSub!==$.splitFrom||!(g.content instanceof ye.ContentAny))return;let x=g.content.getContent()[0];if(typeof x!="string")return;let h=new Set;dc(e,x,h);let S=[...h].filter(m=>n.get(m)===!0);if(S.length===0)return;for(let m of S)c.add(m);let w=k.get(I.key);typeof w=="string"&&a.set(k,w)}),a.size===0)return t;let f=new Map;ae(e.doc,t.deletions,g=>{let k=g.parent,h=(k instanceof ye.Array?Bt(e,k.parent):null)?.get(I.key);if(typeof h!="string"||!(g.content instanceof ye.ContentAny))return;let S=f.get(h);S||f.set(h,S=[]);for(let w of g.content.getContent())typeof w=="string"&&S.push(w)});let l=new Set(a.values()),d=new Set,p=[...l];for(;p.length>0;){let g=p.pop(),k=e.nodes.get(g);if(!(d.has(k)||!(k instanceof ye.Map))){d.add(k);for(let x of f.get(g)??[])p.push(x)}}let u=g=>Bt(e,g.parent)??Bt(e,g.parent?.parent),y=g=>g.parent instanceof ye.Array&&Bt(e,g.parent.parent)!==null&&g.content instanceof ye.ContentAny&&g.content.getContent().some(k=>typeof k=="string"&&l.has(k));return{insertions:Mn(e.doc,t.insertions,g=>c.has(g.parent)),deletions:Mn(e.doc,t.deletions,g=>d.has(u(g))||y(g))}}import*as mc from"yjs";import{CONTENT_TYPES_PART as qn,asciiFold as Rt,NS as Ye,attr as He,children as Qn,materialize as al,relationshipsOf as wn,relsPartName as Jn,specOf as ll}from"@pptx-editor.dev/core/store";var Zo=Symbol("absent");function kc(e,t,n){let o=fl(n);for(let r of e){let i=r.target;if(!(i instanceof mc.Map)||!t(i))continue;let s=o.get(i);s||o.set(i,s=new Map);for(let[a,c]of r.changes.keys){let f=i.get(a),l=s.get(a);if(l)l[3]=f;else{let d=[i,a,c.action==="add"?Zo:c.oldValue,f];n.push(d),s.set(a,d)}}}}var gc=new WeakMap;function fl(e){let t=gc.get(e);if(t)return t;t=new Map;for(let n of e){let o=t.get(n[0]);o||t.set(n[0],o=new Map),o.has(n[1])||o.set(n[1],n)}return gc.set(e,t),t}var wc=e=>e._item?.deleted!==!0;function Sc(e){return e.filter(([t,n,o])=>o!==Zo&&wc(t)&&!t.has(n)).map(([t,n,o])=>[t,n,o])}function er(e){let t=(n,o)=>JSON.stringify(n)===JSON.stringify(o);return e.filter(([n,o,r,i])=>wc(n)&&i!==void 0&&r!==Zo&&t(n.get(o),r)&&!t(r,i)).map(([n,o,,r])=>[n,o,r])}function dl(e){let t=new Set,n=[e];for(;n.length>0;){let o=n.pop();if(!(o.type!=="element"||xc(o))){for(let r of o.attrs)r.ns===Ye.r&&t.add(r.value);for(let r of o.children)n.push(r)}}return t}function hc(e,t){let n={next:e.nextId},o=t.map(r=>al(ll(r),e.root.kind,n));return{partName:e.partName,root:{...e.root,children:[...e.root.children,...o]},nextId:n.next}}var xc=e=>e.ns===Ye.p&&e.local==="sldId";function ul(e,t){for(let n of e.parts.values()){if(n.kind!=="xml")continue;let o=n.xml.root;if(o.ns!==Ye.p||o.local!=="presentation")continue;let r=o.children.find(h=>h.type==="element"&&h.ns===Ye.p&&h.local==="sldIdLst");if(!r)return;let i=[],s=new Set;for(let h of r.children){if(h.type!=="element"||!xc(h))continue;let S=h.attrs.find(w=>w.ns===Ye.r&&w.local==="id")?.value;S===void 0||!t.has(S)?s.add(h):i.push(He(h,"id")??"")}let a=[],c=h=>{for(let S of h.children)S.type==="element"&&(S.ns===Ye.p14&&S.local==="section"?a.push(S):c(S))};c(o);let f=new Map(a.map((h,S)=>[h,S])),l=new Map;a.forEach((h,S)=>{let w=h.children.find(m=>m.type==="element"&&m.ns===Ye.p14&&m.local==="sldIdLst");if(w)for(let m of Qn(w,{ns:Ye.p14,local:"sldId"})){let b=He(m,"id")??"",Y=l.get(b);Y?Y[Y.length-1]!==S&&Y.push(S):l.set(b,[S])}});let d=new Map,p=0;for(let h of i){let S=l.get(h);if(!S)continue;let w=S.find(m=>m>=p)??S[0];d.set(h,w),p=Math.max(p,w)}let u=new Map(i.map((h,S)=>[h,S])),y=s.size>0,g=(h,S)=>{let w=h.children.map(m=>{if(m.type!=="element"||m.ns!==Ye.p14||m.local!=="sldIdLst")return m;let b=new Set,M=[...m.children.filter(v=>{if(v.type!=="element"||v.ns!==Ye.p14||v.local!=="sldId")return!0;let E=He(v,"id")??"";return d.get(E)!==S||b.has(E)?!1:(b.add(E),!0)})].sort((v,E)=>{let F=v.type==="element"?u.get(He(v,"id")??"")??0:0,_=E.type==="element"?u.get(He(E,"id")??"")??0:0;return F-_});return M.length===m.children.length&&M.every((v,E)=>v===m.children[E])?m:(y=!0,{...m,children:M})});return w.every((m,b)=>m===h.children[b])?h:{...h,children:w}},k=h=>{let S=h.children.filter(m=>m.type!=="element"||!s.has(m)).map(m=>{if(m.type!=="element")return m;let b=f.get(m)??-1;return b>=0?g(m,b):k(m)});return S.length===h.children.length&&S.every((m,b)=>m===h.children[b])?h:{...h,children:S}},x=k(o);return y?{...n.xml,root:x}:void 0}}var pl=new Set(["hlinkClick","hlinkHover","hlinkMouseOver"]),Qo=e=>e.endsWith("/relationships/slide");function yc(e,t){let n=!1,o=i=>{let s=!1,a=[];for(let c of i.children){if(c.type!=="element"){a.push(c);continue}let f=c.attrs.some(d=>d.ns===Ye.r&&d.value===t);if(f&&c.ns===Ye.a&&pl.has(c.local)){s=!0;continue}f&&(n=!0);let l=o(c);l!==c&&(s=!0),a.push(l)}return s?{...i,children:a}:i},r=o(e);return n?void 0:r}function gl(e,t){return{...e,root:{...e.root,children:e.root.children.filter(n=>n.type!=="element"||n.local!=="Relationship"||He(n,"Id")!==t)}}}var Xt=(e,t)=>{let n=e.parts.get(t);return n?.kind==="xml"?n.xml:void 0};function tr(e,t){let n=new Map,o=new Set;for(let d of t.parts.keys())o.add(Rt(d));let r=d=>t.parts.has(d)||o.has(Rt(d)),i=[],s=new Set,a=d=>{!d||s.has(d.partName)||(s.add(d.partName),i.push(d))},c=!1;for(let d of e.parts.keys())t.parts.has(d)||(c=!0);for(let[d,p]of t.parts){if(p.kind!=="xml")continue;let u=Jn(d);if(!c&&e.parts.get(d)===p&&e.parts.get(u)===t.parts.get(u))continue;let y=m=>{let b=yc((n.get(d)??p.xml).root,m);if(!b)return!1;n.set(d,{...n.get(d)??p.xml,root:b});let Y=n.get(u)??Xt(t,u);return Y&&n.set(u,gl(Y,m)),!0};for(let m of wn(t,d))!m.external&&m.target&&!r(m.target)&&Qo(m.type)&&y(m.id);let g=dl((n.get(d)??p.xml).root);if(g.size===0)continue;for(let m of wn(t,d))!g.has(m.id)||m.external||!m.target||r(m.target)||Qo(m.type)||a(e.parts.get(m.target));let k=new Set(wn(t,d).map(m=>m.id)),x=Xt(e,u);if(!x)continue;let h=Qn(x.root,{ns:Ye.rel,local:"Relationship"}).filter(m=>{let b=He(m,"Id");return b!==void 0&&g.has(b)&&!k.has(b)});for(let m of wn(e,d)){let b=h.findIndex(M=>He(M,"Id")===m.id);if(b<0||m.external||!m.target||r(m.target)||!Qo(m.type))continue;let Y=yc((n.get(d)??p.xml).root,m.id);Y&&(n.set(d,{...n.get(d)??p.xml,root:Y}),h.splice(b,1))}if(h.length===0)continue;let S=n.get(u)??Xt(t,u)??{partName:u,root:{...x.root,children:[]},nextId:x.nextId};n.set(u,hc(S,h));let w=new Set(h.map(m=>He(m,"Id")));for(let m of wn(e,d))!w.has(m.id)||m.external||!m.target||r(m.target)||a(e.parts.get(m.target))}{let d=[...t.parts.values()].find(g=>g.kind==="xml"&&g.xml.root.ns===Ye.p&&g.xml.root.local==="presentation"),p=d&&(n.get(Jn(d.partName))??Xt(t,Jn(d.partName))),u=d&&Jn(d.partName),y=d&&(e.parts.get(d.partName)!==d||e.parts.get(u)!==t.parts.get(u)||n.has(u));if(p&&y&&u&&t.parts.has(u)){let g=new Set(Qn(p.root,{ns:Ye.rel,local:"Relationship"}).map(x=>He(x,"Id")??"")),k=ul(t,g);k&&n.set(k.partName,k)}}let f=Xt(t,qn),l=Xt(e,qn);if(f&&l){let d=(h,S,w)=>{let m=new Map;for(let b of Qn(h,{ns:Ye.ct,local:S})){let Y=He(b,w);Y!==void 0&&!m.has(Rt(Y))&&m.set(Rt(Y),b)}return m},p=d(f.root,"Override","PartName"),u=d(f.root,"Default","Extension"),y=d(l.root,"Override","PartName"),g=d(l.root,"Default","Extension"),k=new Set,x=new Set(t.parts.keys());for(let h of i)x.add(h.partName);for(let h of x){if(h===qn)continue;let S=Rt(h.slice(h.lastIndexOf(".")+1));if(p.has(Rt(h))||u.has(S))continue;let w=y.get(Rt(h))??g.get(S);w&&k.add(w)}k.size>0&&n.set(qn,hc(f,[...k]))}return[...[...n.values()].map(d=>({kind:"xml",partName:d.partName,xml:d})),...i]}var bc=0;function nr(e,...t){for(let n of[...e])try{n(...t)}catch(o){console.warn("[pptx-editor] collaboration listener failed",o)}}function yl(e){let{doc:t,documentId:n,identity:o,awareness:r}=e;if(typeof n!="string"||n.trim()===""||n.length>256)throw new ve("invalid-document-id");let i=_i(o);if(i)throw new ve(i);let s=dr(t),a=hl("initializing"),c=new Set,f=new Set,l=new Set,d=null,p=null,u={value:0},y=null,g=null,k=null,x=!1,h=!0,S=[{...o,isLocal:!0}],w=[],m=null,b=null,Y=null,M=!1;bc+=1;let v=`${t.clientID.toString(36)}-${bc}`,E=(A,L,j,D=!1)=>{if(!a.set(A,L,j,D))return;let O=a.snapshot().reason;nr(c,A,O?.code,O?.detail)},F=()=>h?E("ready"):E("disconnected","transport-disconnected"),_=A=>{r&&!x&&r.setLocalStateField(Xn,Ki(o,A))},T=()=>{if(!r)return;let A=ji(r);JSON.stringify(A)!==JSON.stringify(S)&&(S=A,nr(f,S));let L=p?Wi(r,t,p):[];JSON.stringify(L)!==JSON.stringify(w)&&(w=L,nr(l,w))};_(void 0),r?.on("change",T),T();let R=(A,L,j,D=!0)=>{let O=L?A.redoStack:A.undoStack,W=O.length;L?A.undoing=!0:A.redoing=!0;try{t.transact(j,oo)}finally{A.undoing=!1,A.redoing=!1}if(O.length!==W+1)return!1;let B=O[O.length-2];if(!D||!B)return!0;let X=O.pop();return B.deletions=Ne.mergeDeleteSets([B.deletions,X.deletions]),B.insertions=Ne.mergeDeleteSets([B.insertions,X.insertions]),!0},P=(A,L,j)=>L.length>0&&R(A,!1,()=>{for(let[D,O,W]of L)D.set(O,W)},j),C=(A,L)=>{let j=L?A?.undoStack:A?.redoStack;if(!A||!j||j.length===0)return!1;M=!1;let D=g?.package(),O=j[j.length-1];L&&fc(s,O);let W=Hn(s,O.insertions),B=qo(s,O.insertions),X=L&&j.length>1?j[j.length-2]:null,q=X?Hn(s,X.insertions):null,le=ac(s,O.insertions),Ee=p,it=W&&Ee?sc(s,q?new Set([...W,...q]):W,(J,ce)=>Ee.idOf(J,ce)!==void 0):null;if(L){for(let J of j.slice(0,-1))Vo(J);Ao(s,O,J=>t.transact(J,Ot),Vo(O)),O.deletions=uc(s,O)}else{let J=pc(s,O);O.insertions=J.insertions,O.deletions=J.deletions,Ao(s,O,ce=>t.transact(ce,Ot),new Set,!0)}let Zn=[...j];k=null;let It=J=>{let ce=J?A.undoStack:A.redoStack,fe=ce[ce.length-1],Et=fe===O?W:fe?Hn(s,fe.insertions):null,vt=fe===O?B:fe?qo(s,fe.insertions):void 0;try{t.transact(()=>{let qe=J?A.undo():A.redo();A.undoing=J,A.redoing=!J,A.currStackItem=qe,qe&&Un(s,qe.deletions,qe===fe?Et:q,qe===fe?vt:void 0)},A)}finally{A.undoing=!1,A.redoing=!1,A.currStackItem=null}};It(L),!L&&k===O&&Ls(s,O,J=>t.transact(J,Ot));let me=k,H=new Set(j),se=Zn.reverse().filter(J=>!H.has(J)&&J!==me),pe=J=>J.meta.get("attrs")??[],ge=!1,re=!1,be=null;if(L&&me&&me!==O)me===X&&q&&it&&t.transact(()=>Jo(s,me.deletions,q,it),pt),k=null,It(!1),be=k,re=!0;else if(!L&&me===O)ge=P(A,er(pe(O)),!0);else if(!L){me&&(k=null,It(!0),be=k);for(let J of se.slice(1).reverse())A.redoStack.push(J);ge=P(A,er(pe(O)),!1)}if(be){let J=be;t.transact(()=>Un(s,J.deletions),Ot)}let Re=me&&!re&&(L||me===O)?me:null;if(Re&&p&&g){let J=p,ce=Re,fe=(qe,Mc)=>J.idOf(qe,Mc)!==void 0,Et={keyOf:J.keyOf.bind(J),package:g.package()},vt=new Set;Re===O&&W&&it&&t.transact(()=>Jo(s,ce.deletions,W,it),pt),R(A,L,()=>{let qe=Un(s,ce.deletions,Re===O?W:q,Re===O?B:void 0);vt=qe.roots,L&&Fs(s,ce,fe),ec(s,ce.deletions,fe,Et),Ho(s,qe.texts,fe,Et)}),J.noteStep(vt,le?lc(s,ce,le):[])}let Se=g?.package(),Q=L&&me&&!re?Sc(pe(me)):[],he=D&&Se&&!re?tr(D,Se):[];if((Q.length>0||he.length>0)&&Se&&p){let J=p;t.transact(()=>{for(let[fe,Et,vt]of Q)fe.set(Et,vt);if(he.length===0)return;let ce=new Map(Se.parts);for(let fe of he)ce.set(fe.partName,fe);J.writeChange(Se,{parts:ce},he.map(fe=>fe.partName))},no)}return!M&&(L?me!==null&&!re:me===O||ge)};return{documentId:n,sessionId:v,identity:o,get attached(){return d!==null},status:()=>a.status(),statusSnapshot:()=>a.snapshot(),subscribeStatus(A){return c.add(A),()=>c.delete(A)},setConnected(A){if(x||A===h)return;h=A;let L=a.snapshot();(L.status==="ready"||L.status==="disconnected")&&F()},participants:()=>S,subscribeParticipants(A){return f.add(A),()=>f.delete(A)},remoteSelections:()=>w,subscribeRemoteSelections(A){return l.add(A),()=>l.delete(A)},setLocalSelection(A){let L=A&&p?zi(A,p):void 0;m=A&&L?{selection:A,encoded:L}:null,_(L)},remoteSelectionMove:()=>b,historySelection:()=>Y&&p?Vn(Y,t,p):null,canUndo:()=>y?y.undoStack.length>0:!1,canRedo:()=>y?y.redoStack.length>0:!1,undo:()=>C(y,!0),redo:()=>C(y,!1),attach(A){if(x)return()=>{};d?.(),E("initializing");let L=s.meta.get("schema");if(s.meta.size>0&&!co(s.meta))return E("error","schema-version-mismatch",`room schema ${String(L)}`),()=>{};let j=new Bn(s,u);g=A,p=j;let D=(H,se,pe=!1)=>{let ge=A.package(),re=j.rebuild(H,ge,se);if(!re.ok)return M=!0,E("error","remote-apply-failed",re.reason,!0);let be=m?Vn(m.encoded,t,j):null;if(b=m&&be&&JSON.stringify(be)!==JSON.stringify(m.selection)?{from:m.selection,to:be}:null,b&&m&&(m={selection:b.to,encoded:m.encoded}),re.parts.length>0||re.removed.length>0){let Se=A.applyRemoteParts(re.parts,re.removed,"collaboration");if(b=null,!Se.ok){M=!0;let Q=Se.rejection.code;return Q==="unsafe-part-name"?E("error","unsafe-part-name",Q):E("error","remote-apply-failed",Q,!0)}}b=null,pe&&q(ge,A.package());let Re=a.snapshot();Re.status==="error"&&Re.recovering&&F(),T()};j.seeded?D(j.allParts(A.package()),!0):t.transact(()=>{gr(s.meta),s.meta.set("documentId",n),j.seed(A.package())},so);let O=new Ne.UndoManager([s.parts,s.binaries,s.nodes],{trackedOrigins:new Set([bn,oo]),captureTimeout:Number.POSITIVE_INFINITY,deleteFilter:Gi(s.nodes)}),W=H=>{let se=H.parent;return se instanceof Ne.Map&&se.get(I.attrs)===H},B=H=>{wr(s,H.stackItem);let se=O.currStackItem;if((O.undoing||O.redoing)&&se){H.stackItem.meta.set("attrs",se.meta.get("attrs")??[]),Ji(se,H.stackItem);return}let pe=H.stackItem.meta.get("attrs")??[],ge=new Set;for(let re of H.changedParentTypes?.values()??[])for(let be of re)ge.add(be);kc(ge,W,pe),H.stackItem.meta.set("attrs",pe)};O.on("stack-item-added",H=>{m&&H.stackItem.meta.set("selection",m.encoded),B(H)}),O.on("stack-item-updated",B),O.on("stack-item-popped",H=>{Y=H.stackItem.meta.get("selection")??null,k=H.stackItem}),y=O;let X=A.subscribeLocal(H=>{H.merged||O.stopCapturing(),j.hasHiddenListings(H.parts)&&t.transact(()=>j.dropHiddenListings(H.parts,H.before,H.after),ro),t.transact(()=>j.writeChange(H.before,H.after,H.parts,H.label==="changeCase"),bn);let se=j.showingUnlisted(H.parts);se.length>0&&D(se,!1),T()}),q=(H,se)=>{let pe=tr(H,se);if(pe.length===0)return;let ge=new Map(se.parts);for(let re of pe)ge.set(re.partName,re);t.transact(()=>j.writeChange(se,{parts:ge},pe.map(re=>re.partName)),no)},le=new Map,Ee=new Map,it=(H,se)=>{let pe=j.deletedText,ge=j.newCopies(H,!1);for(let[Q,he]of le)se.set(Q,[...new Set([...se.get(Q)??[],...he])]);for(let[Q,he]of Ee)ge.set(Q,[...new Set([...ge.get(Q)??[],...he])]);let re=Tr(s,H);for(let Q of re){let he=s.nodes.get(Q),J=he instanceof Ne.Map?he.get(I.part):void 0;if(typeof J!="string")continue;let ce=se.get(J)??[];ce.includes(Q)||ce.push(Q),se.set(J,ce)}if(se.size===0&&re.size===0)return;let be={keyOf:j.keyOf.bind(j),package:A.package()},Re=[],Se=[];t.transact(()=>{for(let[Q,he]of se){if(!$r(s,Q)){Ys(s,Q,he,pe),le.set(Q,new Set(he)),Ee.set(Q,new Set(ge.get(Q)??[]));continue}le.delete(Q),Ee.delete(Q),bs(s,Q,he,pe,be,(J,ce,fe)=>Re.push([J,ce,fe]),J=>Se.push(J),new Set(ge.get(Q)??[]))}Ms(s,re,pe)},pt),qi([...O.undoStack,...O.redoStack],Se);for(let[Q,he,J]of Re)for(let ce of[...O.undoStack,...O.redoStack]){if(!Ne.isDeleted(ce.insertions,Q))continue;let fe=Ne.createDeleteSet();fe.clients.set(he.client,[{clock:he.clock,len:J}]),ce.insertions=Ne.mergeDeleteSets([ce.insertions,fe])}},Zn=t.getMap(Le),It=H=>{let se=s.meta.get("schema");if(!co(s.meta)&&H.changed.has(s.meta)){me(),E("error","schema-version-mismatch",`room schema ${String(se)}`);return}let pe=H.origin;if(pe===bn||pe===so||pe===Ot||pe===ro)return;let ge=j.touchedParts(H);if(ge.size>0&&D(ge,!1,!H.local),H.local)return;let re=H.changed.get(Zn);re&&j.deletedText.size>0&&t.transact(()=>ic(s,re,j.deletedText,(Se,Q)=>j.noteRejected(Se,Q),j.deletedAt),pt);let be=j.newCopies(H);it(H,be),Xi(s,H,pt);let Re=re?Go(s,re):new Set;if(be.size>0&&s.doc.getMap(Le).size>0)for(let Se of Uo(s,new Set(be.keys())))Re.add(Se);if(Re.size>0){let Se=(he,J)=>j.idOf(he,J)!==void 0,Q={keyOf:j.keyOf.bind(j),package:A.package()};t.transact(()=>Ho(s,Re,Se,Q),pt)}};t.on("afterTransaction",It),a.status()==="initializing"&&F(),T();let me=()=>{X(),t.off("afterTransaction",It),O.destroy(),y===O&&(y=null),p===j&&(p=null),g===A&&(g=null),m=null,Y=null,_(void 0),T(),d===me&&(d=null)};return d=me,me},destroy(){x||(d?.(),r?.off("change",T),r?.setLocalStateField(Xn,null),x=!0,E("destroyed","collaboration-session-destroyed"),c.clear(),f.clear(),l.clear())}}}export{pr as COLLABORATION_FORMAT_VERSION,ve as CollaborationSchemaError,Kc as assertCollaborationFormatCompatibility,_c as collaborationModule,Yc as comparePresentations,yl as createYjsCollaborationSession,Nc as legacyComments,jc as readCollaborationFormatVersion,Rc as reviewModule};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pptx-editor.dev/pro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-canary.20261120032841.sha-d450255",
|
|
4
4
|
"description": "Commercial capabilities for PPTX Editor, as EditorModules: the review module with the comments pane and review hooks for React and Vue, realtime collaboration, and advanced drawing rendering (charts, glow, inner shadow, reflection, and soft edge).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"api:check": "node ../../scripts/api-extractor.mjs --package @pptx-editor.dev/pro"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@pptx-editor.dev/core": "
|
|
41
|
-
"@pptx-editor.dev/react": "
|
|
42
|
-
"@pptx-editor.dev/vue": "
|
|
40
|
+
"@pptx-editor.dev/core": "0.7.0-canary.20261120032841.sha-d450255",
|
|
41
|
+
"@pptx-editor.dev/react": "0.7.0-canary.20261120032841.sha-d450255",
|
|
42
|
+
"@pptx-editor.dev/vue": "0.7.0-canary.20261120032841.sha-d450255",
|
|
43
43
|
"react": "^18.0.0 || ^19.0.0",
|
|
44
44
|
"vue": "^3.5.0"
|
|
45
45
|
},
|