@pptx-editor.dev/pro 0.5.1-canary.20261117032847.sha-31be6ab → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ /*!
2
+ Copyright (c) 2026 Eigenpal, Inc. All rights reserved.
3
+ Licensed under the EigenPal Pro Evaluation License 1.0. See LICENSE.md in this package.
4
+ Production use requires a commercial agreement: licensing@eigenpal.com
5
+ */
6
+ import{a as B}from"./chunk-HCD7IVOL.js";import{canonicalForm as Ke,presentationInfo as z,readPptx as je}from"@pptx-editor.dev/core/store";import{canonicalForm as we,elements as be}from"@pptx-editor.dev/core/store";var G=1e4,W="http://schemas.microsoft.com/office/powerpoint/2010/main",re=new WeakMap;function k(n){if(!n)return"";let e=re.get(n);return e===void 0&&re.set(n,e=we(n)),e}var w=(n,e)=>n?be(n).find(t=>t.local===e):void 0,C=(n,e)=>n?.attrs.find(t=>t.ns===""&&t.local===e)?.value;function N(n,e){let t=e?n.parts.get(e):void 0;return t?.kind==="xml"?t.xml.root:void 0}function E(n,e){let t=e?n.parts.get(e):void 0;if(t)return t.kind==="xml"?k(t.xml.root):t.bytes}function T(n,e){if(typeof n=="string"||typeof e=="string"||!n||!e)return n===e;if(n===e)return!0;if(n.length!==e.length)return!1;let t=0;if(n.byteOffset%4===0&&e.byteOffset%4===0){let o=n.length>>2,r=new Uint32Array(n.buffer,n.byteOffset,o),s=new Uint32Array(e.buffer,e.byteOffset,o);for(let i=0;i<o;i+=1)if(r[i]!==s[i])return!1;t=o<<2}for(;t<n.length;t+=1)if(n[t]!==e[t])return!1;return!0}function K(n,e){return n.length===e.length&&n.every((t,o)=>T(t,e[o]))}var D=class{changes=[];truncated=!1;ids=new Set;add(e){if(this.changes.length>=G){this.truncated=!0;return}let t=e.id;for(let o=2;this.ids.has(t);o+=1)t=`${e.id}#${o}`;this.ids.add(t),this.changes.push(t===e.id?e:{...e,id:t})}};import{elements as ke,relationshipById as ve,relationshipsOf as q}from"@pptx-editor.dev/core/store";var Re=3,$e=/\/(slide|slideLayout|slideMaster|theme|notesSlide|notesMaster|handoutMaster|comments|commentAuthors)$/,V=n=>$e.test(n);function j(n,e,t,o){let r=[],s=new Set,i=(a,p,y)=>{let l=ve(n,a,p);if(!l){r.push(`${p}|none`);return}if(l.external){r.push(`${p}|${l.type}|external|${l.externalTarget??l.relativeTarget??""}`);return}let x=l.target;if(y>0&&V(l.type)){r.push(`${p}|${l.type}|${x}`);return}if(r.push(`${p}|${l.type}`),!s.has(x)&&(s.add(x),o.add(x),r.push(E(n,x)),!(y>=Re)))for(let S of q(n,x))i(x,S.id,y+1)};return i(e,t,0),r}function F(n,e=new Set,t=0){if(t>64)return e;for(let o of n.attrs)o.ns.endsWith("/relationships")&&e.add(o.value);for(let o of ke(n))F(o,e,t+1);return e}function H(n,e){return e?q(n,e).filter(t=>t.external||!V(t.type)).map(t=>t.id):[]}function se(n,e,t,o,r){let s=new Set,i=H(n,t),a=H(e,o);for(let p of new Set([...i,...a])){let y=i.includes(p)?j(n,t,p,r):[],l=a.includes(p)?j(e,o,p,r):[];K(y,l)||s.add(p)}return s}function Z(n,e,t){for(let o of H(n,e))j(n,e,o,t)}function J(n,e){let t=[E(n,e)],o=new Set;for(let r of q(n,e))!r.external&&V(r.type)?t.push(`${r.id}|${r.type}|${r.target}`):t.push(...j(n,e,r.id,o));return t}import{elements as L}from"@pptx-editor.dev/core/store";import{shapeParagraphTexts as pe,shapesById as Oe}from"@pptx-editor.dev/core/editor";import{elements as Ce}from"@pptx-editor.dev/core/store";var Ie=25e4;function le(n,e){let t=[],o=[],r=[],s=0;for(;s<n.length&&s<e.length&&n[s]===e[s];)r.push([s,s]),s+=1;let i=0;for(;i<n.length-s&&i<e.length-s&&n[n.length-1-i]===e[e.length-1-i];)i+=1;let a=n.length-s-i,p=e.length-s-i;if(a>0&&p>0&&(a+1)*(p+1)>Ie)return null;let y=p+1,l=new Uint32Array(a>0&&p>0?(a+1)*y:0);if(l.length>0)for(let u=a-1;u>=0;u-=1)for(let h=p-1;h>=0;h-=1)l[u*y+h]=n[s+u]===e[s+h]?l[(u+1)*y+h+1]+1:Math.max(l[(u+1)*y+h],l[u*y+h+1]);let x=(u,h)=>l.length>0?l[u*y+h]:0,S=[],g=0,b=u=>{S.forEach((h,P)=>t.push([s+h,g+P<u?s+g+P:null]));for(let h=g+S.length;h<u;h+=1)o.push(s+h);S.length=0},c=0,d=0;for(;c<a||d<p;)c<a&&d<p&&n[s+c]===e[s+d]?(b(c),r.push([s+d,s+c]),c+=1,d+=1,g=c):d<p&&(c>=a||x(c,d+1)>=x(c+1,d))?(S.push(d),d+=1):c+=1;b(c);for(let u=0;u<i;u+=1)r.push([e.length-i+u,n.length-i+u]);return{changed:t,removed:o,kept:r}}function ce(n,e){let t=0;for(;t<n.length&&t<e.length&&n[t]===e[t];)t+=1;let o=0;for(;o<n.length-t&&o<e.length-t&&n[n.length-1-o]===e[e.length-1-o];)o+=1;return{start:t,end:e.length-o}}var ie=(()=>{let n=Intl.Segmenter;return n?new n(void 0,{granularity:"word"}):void 0})(),Ae=/^[\s\p{Z}]+$/u,Ee=/^[\p{P}\p{Sc}\p{Sm}]+$/u;function Me(n){let e=[];if(!ie){for(let o of n.matchAll(/[^\s\p{Z}]+/gu))e.push([o.index,o.index+o[0].length]);return e}let t;for(let o of ie.segment(n)){if(Ae.test(o.segment)){t=void 0;continue}let r=o.index,s=r+o.segment.length,i=o.isWordLike===!0,a=i||Ee.test(o.segment),p=e[e.length-1];p&&p[1]===r&&t!==void 0&&a&&!(t&&i)?p[1]=s:e.push([r,s]),t=a?i:void 0}return e}var ae=n=>n>=55296&&n<=56319,de=n=>n>=56320&&n<=57343;function fe(n,e,t){let o=e,r=t;for(let[s,i]of Me(n))if(!(i<e||s>t)){if(e===t){s<=e&&e<=i&&(o=Math.min(o,s),r=Math.max(r,i));continue}s<=e&&e<i&&(o=Math.min(o,s)),s<t&&t<=i&&(r=Math.max(r,i))}return o>0&&o<n.length&&de(n.charCodeAt(o))&&ae(n.charCodeAt(o-1))&&(o-=1),r>0&&r<n.length&&de(n.charCodeAt(r))&&ae(n.charCodeAt(r-1))&&(r+=1),{start:o,end:r}}function Y(n,e=0){return e>64?"":`<${n.local} ${n.attrs.map(t=>`${t.local}=${t.value}`).join(" ")}>`+Ce(n).filter(t=>t.local!=="t").map(t=>Y(t,e+1)).join("")}function Q(n){let e=w(n,"txBody");if(!e)return;let t=[],o={...e,children:e.children.filter(r=>r.type!=="element"||r.kind!=="paragraph"?!0:(t.push(Y(r)),!1))};return{body:Y(o),paragraphs:t}}function ue(n,e,t){return!n||!e?n===e:n.body!==e.body?!1:t?[...t.kept,...t.changed].every(([r,s])=>s===null||n.paragraphs[s]===e.paragraphs[r]):n.paragraphs.join("")===e.paragraphs.join("")}var Ne=50;function Fe(n){let e=L(n)[0];if(!e||!e.local.startsWith("nv"))return;let t=w(e,"cNvPr"),o=Number(C(t,"id"));return{el:n,id:Number.isSafeInteger(o)?o:void 0,name:C(t,"name")}}function me(n){let e=w(w(n,"cSld"),"spTree"),t=[];for(let o of L(e)){let r=o.local==="AlternateContent"?L(w(o,"Choice")):[o];for(let s of r){let i=Fe(s);i&&t.push(i)}}return t}function Le(n,e){let t=new Map,o=new Set,r=(i,a)=>{let p=new Map;for(let y of i){let l=a(y);l!==void 0&&p.set(l,p.has(l)?null:y)}return p},s=new Map;for(let i of[n,e]){let a=new Map;for(let p of i){if(p.id===void 0)continue;let y=`${p.el.local}#${p.id}`,l=a.get(y)??0;a.set(y,l+1),s.set(p,l)}}for(let i of[a=>a.id===void 0?void 0:`${a.el.local}#${a.id}`,a=>a.name===void 0?void 0:`${a.el.local}:${a.name}`,a=>a.id===void 0?void 0:`${a.el.local}#${a.id}#${s.get(a)}`]){let a=r(n.filter(y=>!o.has(y)),i),p=r(e.filter(y=>!t.has(y)),i);for(let y of e){if(t.has(y))continue;let l=i(y);if(l===void 0||p.get(l)!==y)continue;let x=a.get(l);!x||o.has(x)||(t.set(y,x),o.add(x))}}return t}var X=(n,e)=>n&&e.size>0?[...F(n)].filter(t=>e.has(t)):[];function _e(n,e,t){let o=new Set,r=L(n).find(g=>g.local.endsWith("spPr")),s=L(e).find(g=>g.local.endsWith("spPr")),i=w(r,"xfrm")??w(n,"xfrm"),a=w(s,"xfrm")??w(e,"xfrm");k(w(i,"off"))!==k(w(a,"off"))&&o.add("position"),k(w(i,"ext"))!==k(w(a,"ext"))&&o.add("size");let p=g=>`${C(g,"rot")}|${C(g,"flipH")}|${C(g,"flipV")}`;p(i)!==p(a)&&o.add("rotation");let y=(g,b)=>L(g).filter(c=>b.includes(c.local)).map(k).join(""),l=[["geometry",["prstGeom","custGeom"]],["fill",["noFill","solidFill","gradFill","blipFill","pattFill","grpFill"]],["line",["ln"]],["effects",["effectLst","effectDag","scene3d","sp3d"]]];for(let[g,b]of l)y(r,b)!==y(s,b)&&o.add(g);let x=new Set,S=g=>{let b=g?[...F(g)].filter(c=>t.has(c)):[];for(let c of b)x.add(c);return b.length>0};if(e.local==="pic"){let g=w(e,"blipFill");(k(w(n,"blipFill"))!==k(g)||S(g))&&o.add("picture")}if(e.local==="graphicFrame"){let g=d=>w(w(d,"graphic"),"graphicData"),b=C(g(e),"uri")??"",c=b.endsWith("/table")?"table":b.endsWith("/chart")?"chart":b.endsWith("/diagram")?"diagram":"other";(k(g(n))!==k(g(e))||S(g(e)))&&o.add(c)}return[...t].some(g=>!x.has(g))&&o.add("other"),o.size===0&&o.add("other"),[...o]}var Te=(n,e)=>n.length===e.length&&n.every((t,o)=>t===e[o]),Ue={changed:[],removed:[],kept:[]};function ge(n,e){let{a:t,b:o,sa:r,sb:s,index:i,key:a,reached:p}=e,y=0,l=d=>{y+=1,n.add(d)},x=N(t,r.partName),S=N(o,s.partName),g=se(t,o,r.partName,s.partName,p),b=k(x)===k(S),c=!1;if(!b||g.size>0||r.layoutPart!==s.layoutPart){let d=new Set;r.layoutPart!==s.layoutPart&&d.add("layout"),r.hidden!==s.hidden&&d.add("visibility");let u=w(w(x,"cSld"),"bg"),h=w(w(S,"cSld"),"bg");(k(u)!==k(h)||X(u,g).length+X(h,g).length>0)&&d.add("background");let P=(A,m)=>L(A).filter(f=>m.includes(f.local)||f.local==="AlternateContent"&&k(f).includes("transition")).map(k).join("");P(x,["transition"])!==P(S,["transition"])&&d.add("transition"),P(x,["timing"])!==P(S,["timing"])&&d.add("animation");let R=me(x),I=me(S);if(g.size>0){let A=new Set;for(let f of[...R,...I])F(f.el,A);for(let f of[u,h])f&&F(f,A);let m=new Set;for(let f of[x,S])f&&F(f,m);for(let f of g)A.has(f)||(m.has(f)?d.add("other"):c=!0)}d.size>0&&l({id:`slide:${a}`,location:{slideIndex:i},computed:{scope:"slide",action:"changed",aspects:[...d]}}),ze(l,e,S,R,I,g),y===0&&!b&&l({id:`slide:${a}`,location:{slideIndex:i},computed:{scope:"slide",action:"changed",aspects:["other"]}})}return s.notesPart?T(E(t,r.notesPart),E(o,s.notesPart))||l({id:`notes:${a}`,location:{slideIndex:i,notes:!0},computed:{scope:"notes",action:"changed",aspects:["text"]}}):r.notesPart&&l({id:`notes:${a}`,location:{slideIndex:i},computed:{scope:"notes",action:"removed"}}),c}function ze(n,e,t,o,r,s){let{index:i,key:a}=e,p=Le(o,r),y=new Set(p.values());for(let l of o)y.has(l)||n({id:`shape:${a}:${l.id??l.name??"?"}:removed`,location:{slideIndex:i},computed:{scope:"shape",action:"removed"}});for(let l of r){let x=p.get(l),S=`${a}:${l.id??l.name??"?"}`,g=l.id!==void 0&&Oe(t,l.id).length===1?l.id:void 0,b=g===void 0?{slideIndex:i}:{slideIndex:i,shapeId:g};if(!x){n({id:`shape:${S}`,location:b,computed:{scope:"shape",action:"added"}});continue}let c=new Set([...X(x.el,s),...X(l.el,s)]);if(k(x.el)===k(l.el)&&c.size===0)continue;let d=pe(x.el),u=pe(l.el),h=!Te(d,u),P=h?le(d,u):Ue,R=v=>k({...v,children:v.children.filter(M=>M.type!=="element"||M.local!=="txBody")}),I=R(x.el)===R(l.el),A=ue(Q(x.el),Q(l.el),P),m=P?P.changed.length+(P.removed.length>0?1:0):1/0;if(I&&A&&c.size===0&&h&&P&&m<=Ne&&g!==void 0){for(let[v,M]of P.changed){let _=u[v],O=M===null?{start:0,end:_.length}:(()=>{let oe=ce(d[M],_);return fe(_,oe.start,oe.end)})();n({id:`text:${S}:${v}`,location:O.end>O.start?{slideIndex:i,shapeId:g,paragraphIndex:v,start:O.start,end:O.end,text:_.slice(O.start,O.end)}:b,computed:{scope:"text",action:"changed",aspects:["text"]}})}P.removed.length>0&&n({id:`text:${S}:removed`,location:b,computed:{scope:"text",action:"changed",aspects:["text"]}});continue}let f=I&&c.size===0?[]:_e(x.el,l.el,c);h&&f.push("text"),A||f.push("textFormat");let $=[...new Set(f.length>0?f:["other"])];n({id:`shape:${S}`,location:b,computed:{scope:"shape",action:"changed",aspects:$}})}}import{elements as U}from"@pptx-editor.dev/core/store";var he=.5,Be=4e4;function xe(n,e){let t=N(n,e);for(let o of U(w(t,"extLst")))for(let r of U(o))if(r.ns===W&&r.local==="creationId")return C(r,"val")}function De(n){let e=new Set,t=new Set,o=w(w(n,"cSld"),"spTree");for(let s of U(o)){let i=U(s)[0],a=i&&i.local.startsWith("nv")?w(i,"cNvPr"):void 0;a&&e.add(`${s.local}#${C(a,"id")}:${C(a,"name")}`)}let r=(s,i)=>{if(!(i>64))for(let a of U(s)){if(a.local==="t"){for(let p of a.children)if(p.type==="text")for(let y of p.value.toLowerCase().matchAll(/[\p{L}\p{N}]+/gu))t.add(y[0])}r(a,i+1)}};return o&&r(o,0),{shapes:e,words:t}}function ye(n,e){if(n.size===0&&e.size===0)return 0;let t=0;for(let o of n)e.has(o)&&(t+=1);return t/(n.size+e.size-t)}function We(n,e){let t=ye(n.shapes,e.shapes);return n.words.size===0&&e.words.size===0?t:(t+3*ye(n.words,e.words))/4}function Pe(n,e,t,o){let r=new Map,s=new Set,i=(c,d)=>{r.set(c,d),s.add(d)},a=c=>{let d=new Map;t.forEach((u,h)=>{if(s.has(h))return;let P=c(n,u);P!==void 0&&d.set(P,d.has(P)?null:h)}),o.forEach((u,h)=>{if(r.has(h))return;let P=c(e,u),R=P===void 0?void 0:d.get(P);R==null||s.has(R)||i(h,R)})};a((c,d)=>xe(c,d.partName)),a((c,d)=>{let u=E(c,d.partName);return typeof u=="string"?`${d.layoutPart}|${u}`:void 0});let p=new Map,y=(c,d)=>{let u=`${c}${d.partName}`,h=p.get(u);return h||p.set(u,h=De(N(c==="a"?n:e,d.partName))),h},l=(c,d)=>We(y("a",t[c]),y("b",o[d])),x=new Map;t.forEach((c,d)=>s.has(d)||x.set(c.sldId,d)),o.forEach((c,d)=>{if(r.has(d))return;let u=x.get(c.sldId);u!==void 0&&!s.has(u)&&l(u,d)>=he&&i(d,u)});let S=t.flatMap((c,d)=>s.has(d)?[]:[d]),g=o.flatMap((c,d)=>r.has(d)?[]:[d]);if(S.length>0&&g.length>0&&S.length*g.length<=Be){let c=new Map,d=new Map;for(let u of g)for(let h of S){let P=l(h,u);if(P<he)continue;let R=c.get(h);!R||P>R.score?c.set(h,{j:u,score:P,tie:!1}):P===R.score&&(R.tie=!0);let I=d.get(u);!I||P>I.score?d.set(u,{i:h,score:P,tie:!1}):P===I.score&&(I.tie=!0)}for(let[u,h]of d){let P=c.get(h.i);!h.tie&&P&&!P.tie&&P.j===u&&i(u,h.i)}}a((c,d)=>d.sldId);let b=new Set(t.map(c=>c.sldId));return o.some(c=>b.has(c.sldId))||a((c,d)=>d.partName),r}function ee(n,e){return e.map(t=>xe(n,t.partName)??`id${t.sldId}`)}function ne(n,e){return n.map(t=>{let o=t;for(let r=2;e.has(o);r+=1)o=`${t}#${r}`;return e.add(o),o})}function Xe(n){let e=[],t=new Array(n.length).fill(-1);for(let r=0;r<n.length;r+=1){let s=0,i=e.length;for(;s<i;){let a=s+i>>1;n[e[a]]<n[r]?s=a+1:i=a}s>0&&(t[r]=e[s-1]),e[s]=r}let o=new Set;for(let r=e[e.length-1]??-1;r>=0;r=t[r])o.add(r);return o}function Se(n,e){let t=N(n,z(n).presentationPart);if(!t)return"";let o=(r,s)=>({...r,children:r.children.flatMap(i=>{if(i.type!=="element")return[i];if(s===0&&i.local==="sldIdLst")return[];if(i.ns===W&&i.local==="sldId"){let a=e(C(i,"id")??"");return a===void 0?[]:[{...i,attrs:[{ns:"",local:"id",value:a}]}]}return[s<64?o(i,s+1):i]})});return Ke(o(t,0))}var Ge=/\[Content_Types\]\.xml$|^\/docProps\/|^\/_rels\/\.rels$/i;function He(n){let e=/^(.*)\/_rels\/([^/]+)\.rels$/i.exec(n);return e?`${e[1]}/${e[2]}`:void 0}function te(n,e){let t=new D,o=z(n).slides,r=z(e).slides,s=Pe(n,e,o,r),i=new Set(s.values()),a=new Set,p=ne(ee(n,o),a),y=ee(e,r),l=r.map((m,f)=>{let $=s.get(f);return $!==void 0?p[$]:ne([y[f]],a)[0]}),x=new Set,S=!1;o.forEach((m,f)=>{i.has(f)||(Z(n,m.partName,x),t.add({id:`slide:${p[f]}:removed`,unavailableReason:"deleted",computed:{scope:"slide",action:"removed",previousSlideIndex:f}}))});let g=[...s.entries()].sort((m,f)=>m[0]-f[0]),b=new Map(g.map(([m],f)=>[m,f])),c=Xe(g.map(([,m])=>m));r.forEach((m,f)=>{let $=l[f],v=s.get(f);if(v===void 0){Z(e,m.partName,x),t.add({id:`slide:${$}`,location:{slideIndex:f},computed:{scope:"slide",action:"added"}});return}c.has(b.get(f))||t.add({id:`slide:${$}:moved`,location:{slideIndex:f},computed:{scope:"slide",action:"moved",previousSlideIndex:v}});let M={a:n,b:e,sa:o[v],sb:m,index:f,key:$,reached:x};ge(t,M)&&(S=!0)});let d=[["layout",m=>m.layoutPart],["master",m=>m.masterPart],["theme",m=>m.themePart]],u=new Set(x);for(let[m,f]of d){let $=new Set(r.map(f).filter(v=>!!v));for(let v of $){if(u.add(v),K(J(n,v),J(e,v)))continue;let M=r.flatMap((_,O)=>f(_)===v?[O]:[]);t.add({id:`${m}:${v}`,computed:{scope:m,action:"changed",affectedSlides:M}})}}for(let m of[...o,...r])for(let f of[m.partName,m.notesPart])f&&u.add(f);u.add(z(n).presentationPart),u.add(z(e).presentationPart);let h=new Map(o.map((m,f)=>[m.sldId,f])),P=new Map(r.map((m,f)=>[m.sldId,f])),R=m=>{let f=h.get(m);return f!==void 0&&i.has(f)?String(f):void 0},I=m=>{let f=P.get(m),$=f===void 0?void 0:s.get(f);return $===void 0?void 0:String($)};S||(S=Se(n,R)!==Se(e,I));let A=m=>{if(Ge.test(m))return!0;let f=He(m);return u.has(m)||f!==void 0&&u.has(f)};for(let[m,f]of e.parts){if(S)break;if(A(m))continue;let $=n.parts.get(m);(!$||$.kind!==f.kind||!T(E(n,m),E(e,m)))&&(S=!0)}for(let m of n.parts.keys()){if(S)break;!A(m)&&!e.parts.has(m)&&(S=!0)}return S&&t.add({id:"package",computed:{scope:"package",action:"changed"}}),{changes:t.changes,truncated:t.truncated}}function kn(n,e,t={}){B(t.licenseKey);let o=i=>je(i instanceof Uint8Array?i:new Uint8Array(i)),r=o(n);if(!r.ok)return{ok:!1,code:"invalidDocument",message:"The original is not a valid PPTX file."};let s=o(e);return s.ok?{ok:!0,...te(r.pkg,s.pkg)}:{ok:!1,code:"invalidDocument",message:"The revised file is not a valid PPTX file."}}import{readCommentThreads as qe}from"@pptx-editor.dev/core/editor";import{presentationInfo as Ve}from"@pptx-editor.dev/core/store";var Ze={opening:["auto","manual"],commentMarkers:["initials","icon"]};function Je(n){if(n!==void 0){for(let[e,t]of Object.entries(n)){let o=Ze[e];if(!o)throw new TypeError(`reviewModule: unknown pane option "${e}"`);if(t!==void 0&&!o.includes(t))throw new TypeError(`reviewModule: pane.${e} must be one of ${o.map(r=>`"${r}"`).join(", ")}`)}return Object.freeze({...n})}}function Ye(n){let e=[];for(let t of Ve(n).slides)for(let o of qe(n,t.partName)){let r=(s,i)=>e.push({id:s.id,kind:"comment",slidePart:t.partName,text:s.text,...s.author?{author:s.author}:{},...s.date!==void 0?{date:s.date}:{},...i?{parentId:i}:{}});r(o);for(let s of o.replies)r(s,o.id)}return e}function En(n={}){let e=Je(n.pane);return B(n.licenseKey),{id:"review",review:{displayModes:n.displayModes??["final","markup"],collectReviewItems:({package:t})=>Ye(t),refreshChanges:(t,o)=>{let{changes:r,truncated:s}=te(t,o);return s?[...r.slice(0,G-1),{id:"truncated",computed:{scope:"package",action:"changed"}}]:r},...e?{pane:e}:{}}}}export{kn as a,En as b};
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ Production use requires a commercial agreement: licensing@eigenpal.com
5
5
  */
6
6
  export { R as ReviewModuleOptions, r as reviewModule } from './review-module-BreJaYRH.js';
7
7
  import { PptxPackage } from '@pptx-editor.dev/core/store';
8
- import { ReviewItem, EditorCollaborationSession, EditorModule, CollaborationIdentity, CollaborationFailureCode } from '@pptx-editor.dev/core/editor';
8
+ import { ReviewItem, ComputedRefreshChange, EditorCollaborationSession, EditorModule, CollaborationIdentity, CollaborationFailureCode } from '@pptx-editor.dev/core/editor';
9
9
  export { CommentMarkerStyle, ReviewPaneOpening, ReviewPaneOptions } from '@pptx-editor.dev/core/editor';
10
10
  import { P as ProLicenseOptions } from './license-Boo2wwCs.js';
11
11
  import * as Y from 'yjs';
@@ -13,6 +13,42 @@ import * as Y from 'yjs';
13
13
  /** Every legacy comment of every slide, in slide order and then file order. */
14
14
  declare function legacyComments(pkg: PptxPackage): ReviewItem[];
15
15
 
16
+ /** Options of `comparePresentations`. @public */
17
+ type ComparePresentationsOptions = ProLicenseOptions;
18
+ /** The outcome of `comparePresentations`. @public */
19
+ type ComparePresentationsResult = {
20
+ readonly ok: true;
21
+ /** The changes, in the form `RefreshUpdate.changes` takes, with stable ids. */
22
+ readonly changes: readonly ComputedRefreshChange[];
23
+ /** True when the change limit stopped the comparison. */
24
+ readonly truncated: boolean;
25
+ } | {
26
+ readonly ok: false;
27
+ readonly code: 'invalidDocument';
28
+ /** Diagnostic detail, in English; not for display. */
29
+ readonly message: string;
30
+ };
31
+ /**
32
+ * Compare two presentations and list the changes from `original` to `revised`: slides added,
33
+ * removed, moved, or changed; shapes added, removed, or changed, with what changed; text
34
+ * changes, located at the revised text; notes; and layouts, slide masters, and themes with the
35
+ * slides that show them. Runs without a DOM, on a server or in a browser. Both files go through
36
+ * the same limits as a file the editor opens. Requires the EigenPal Pro License.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { comparePresentations } from '@pptx-editor.dev/pro';
41
+ *
42
+ * const result = comparePresentations(originalBytes, revisedBytes);
43
+ * if (result.ok) {
44
+ * await refresh.applyUpdate({ submission, sequence: 1, bytes: revisedBytes, changes: result.changes });
45
+ * }
46
+ * ```
47
+ *
48
+ * @public
49
+ */
50
+ declare function comparePresentations(original: Uint8Array | ArrayBuffer, revised: Uint8Array | ArrayBuffer, options?: ComparePresentationsOptions): ComparePresentationsResult;
51
+
16
52
  /** Options of `collaborationModule`. @public */
17
53
  interface CollaborationModuleOptions extends ProLicenseOptions {
18
54
  /** A ready session, for example from `createYjsCollaborationSession`. */
@@ -112,5 +148,5 @@ declare function assertCollaborationFormatCompatibility(version: unknown): void;
112
148
  */
113
149
  declare function readCollaborationFormatVersion(doc: Y.Doc): string;
114
150
 
115
- export { COLLABORATION_FORMAT_VERSION, CollaborationSchemaError, ProLicenseOptions, assertCollaborationFormatCompatibility, collaborationModule, createYjsCollaborationSession, legacyComments, readCollaborationFormatVersion };
116
- export type { AwarenessLike, CollaborationModuleOptions, YjsCollaborationSession, YjsCollaborationSessionOptions };
151
+ export { COLLABORATION_FORMAT_VERSION, CollaborationSchemaError, ProLicenseOptions, assertCollaborationFormatCompatibility, collaborationModule, comparePresentations, createYjsCollaborationSession, legacyComments, readCollaborationFormatVersion };
152
+ export type { AwarenessLike, CollaborationModuleOptions, ComparePresentationsOptions, ComparePresentationsResult, YjsCollaborationSession, YjsCollaborationSessionOptions };
package/dist/index.js CHANGED
@@ -3,5 +3,5 @@ Copyright (c) 2026 Eigenpal, Inc. All rights reserved.
3
3
  Licensed under the EigenPal Pro Evaluation License 1.0. See LICENSE.md in this package.
4
4
  Production use requires a commercial agreement: licensing@eigenpal.com
5
5
  */
6
- import{a as Sc}from"./chunk-B3UUTQS4.js";import{a as or}from"./chunk-HCD7IVOL.js";import{attr as ut,binaryPartOf as xc,elements as to,parseXmlPart as bc,mainPresentationPart as Mc,presentationInfo as Yc,relTargetByType as ir,textOf as Rc,xmlPartOf as Ic}from"@pptx-editor.dev/core/store";var cr="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Ec=`${cr}/comments`,vc=`${cr}/commentAuthors`;function ar(e,t){let n=Ic(e,t);if(n||!t)return n;let o=xc(e,t);if(!o)return;let r=bc(t,new TextDecoder().decode(o));return r.ok?r.part:void 0}function Oc(e){let t=Object.create(null),n=Mc(e);if(!n)return t;let o=ar(e,ir(e,n,vc));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 Pc(e){let t=Oc(e),n=[];for(let o of Yc(e).slides){let r=ar(e,ir(e,o.partName,Ec));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:Rc(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 Ac(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 wn=8,Sn="pptx-meta-v1",Dc="pptx-parts-v1",Cc="pptx-binaries-v1",Tc="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(Dc),binaries:e.getMap(Cc),nodes:e.getMap(Tc)}}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 Nc(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 _c(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,Lc=1024,Je=32,Or="http://schemas.openxmlformats.org/drawingml/2006/main",Fc="http://schemas.openxmlformats.org/presentationml/2006/main",At=e=>e.local==="txBody"&&(e.ns===Or||e.ns===Fc),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,Lc)){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,zc=/^(\d{1,16}):(\d{1,16})$/,In=new WeakMap,Ir=new WeakSet;function Kc(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=zc.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=Kc(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 jc(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:Wc(t)},Er.set(e,n));let o=n.seen;return o?r=>r.clock<(o.get(r.client)??0):null}function Wc(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?jc(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")&&gt(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)&&gt(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 dl}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",$c=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 Bc(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($c(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,Bc(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 Xc(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=Xc(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 Vc}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"]),Gc=ke("fill",["noFill","solidFill","gradFill","pattFill"]),Dn=ke("effect",["effectLst","effectDag"]),Uc=[ke("color",["scrgbClr","srgbClr","hslClr","sysClr","schemeClr","prstClr"])],qr=[_("xfrm"),ke("geometry",["custGeom","prstGeom"]),nn,_("ln"),Dn,_("scene3d"),_("sp3d"),_("extLst")],Jr=[Gc,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"],Hc=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,Uc])),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,qc=new Set(["sld","cSld","bg","bgPr","sp","pic","cxnSp","grpSp","graphicFrame","nvSpPr","nvPicPr","nvCxnSpPr","nvGrpSpPr","nvGraphicFramePr","nvPr","style"]);function ts(e){if(!(!So(e)||qc.has(e.local)&&e.ns!==es))return Hc[e.local]}function ns(e,t){return So(t)?e.findIndex(([,n])=>n.includes(t.local)):-1}var Jc=new Set(["pPr","rPr","defRPr","endParaRPr","bodyPr","tblPr","tcPr","ln",...ko]);function os(e){return So(e)&&Jc.has(e.local)}function Qc(e,t){let n=ts(e),o=n?ns(n,t):-1;return o<0?void 0:n[o][0]}var Zc=(e,t)=>e.ns===yo&&e.local==="tc"&&t.ns===yo&&t.local==="txBody",ea="http://schemas.openxmlformats.org/package/2006/content-types",ta="http://schemas.openxmlformats.org/package/2006/relationships",na=Object.assign(Object.create(null),{[`${ea}|Types`]:{Default:{attr:"Extension",caseless:!0},Override:{attr:"PartName",caseless:!0}},[`${ta}|Relationships`]:{Relationship:{attr:"Id",caseless:!1}}});function _t(e,t,n){let o=na[`${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?Vc(a):a}`,rule:"key"}}let r=Qc(e,t);if(!(r===void 0||Zc(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 oa(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=oa(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,ra=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&&ia(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)&&sa(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 sa(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 ia(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)||!ra(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 ca(e,g,l,i,f)}function ca(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,aa=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))ua(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=aa,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};pa(K),la(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 la(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&&da(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=fa(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 fa(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 da(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 ua(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 pa({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 ga=1<<18;function Fn(e,t,n){let o=new Set,r=0;for(let i of e.nodes.values()){if((r+=1)>ga)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 ha="http://schemas.openxmlformats.org/drawingml/2006/main";var ln=(e,t)=>!!e&&!("text"in e)&&e.ns===ha&&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 ma(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=ma(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 ya=64;function ka(e,t){let n=t;for(let o=0;n&&n.deleted&&o<ya;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=ka(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 wa(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 Sa(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=wa(t,n);return r.size===0?null:new e(t,n,r,Sa(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 xa(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 ba(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 Ma=64;function Ya(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<Ma&&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 Ra(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,Ra(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=ba(P,$.movedTo),B=xa(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=Ya(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 Ia="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 Ea(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}=Ea(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===Ia&&va.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 va=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 Oa="http://schemas.openxmlformats.org/drawingml/2006/main",Pa=65536;function ni(e,t,n,o){let r=new Map,i=Pa;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===Oa&&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 ja}from"@pptx-editor.dev/core/store";import*as ft from"yjs";import{children as To,elements as Wt,isStructureEdited as Aa,path as oi,TABLE_MAX_COLUMNS as Da,TABLE_MAX_ROWS as Ca,tableGridOf as Ta}from"@pptx-editor.dev/core/store";var jn=Object.freeze({holder:"mh",cover:"cv."}),Lo="http://schemas.openxmlformats.org/drawingml/2006/main",Na="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 _a(e){return(Wt(e).find(n=>n.local==="t")?.children??[]).map(n=>n.type==="text"?n.value:"").join("")}function La(e){return Wt(e).some(t=>t.local==="br"||(t.local==="r"||t.local==="fld")&&_a(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===Na&&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,Da),o=To(t,"a:tr").slice(0,Ca).map(s=>To(s,"a:tc"));if(n===0||o.length===0)return[];let r=Ta(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)&&!La(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 Fa(e,t,n,o,r,i,s,a){let c=new Map,f=ui(n,c),l=Aa(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)Fa(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 za(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 Ka(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,Ka(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(!za(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,Wa=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=Wa(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=ja(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",$a=256,vi=256,Oi=512,Pi=256,Ai=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,Mt=(e,t=$a)=>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 Ba=65536,Xa=64,Va=(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 Ga(e,t,n,o,r){let i=n.origin;if(!i)return null;let s=w=>w.id.client===o&&Va(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>Xa)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=Ba,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=Ga(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 Ua=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&&Ua.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 Ha=(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 qa(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 Ja(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(Ha(i,o)){n.add(o);continue}e.deletions=Ja(e.deletions,qa(r,o)),t.delete(o)}return n}import*as de from"yjs";var Qa=4096,Za=4096,el=32;function tl(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)>Qa)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=tl(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<Za;){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<el;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 nl=(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 nl(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=ol(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 ol(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 rl,relationshipsOf as kn,relsPartName as Jn,specOf as sl}from"@pptx-editor.dev/core/store";var Zo=Symbol("absent");function gc(e,t,n){let o=il(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 il(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 cl(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=>rl(sl(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 al(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 ll=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&&ll.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 fl(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,fl(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=cl((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=al(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 ul(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=dl("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,Nc as assertCollaborationFormatCompatibility,Ac as collaborationModule,ul as createYjsCollaborationSession,Pc as legacyComments,_c as readCollaborationFormatVersion,Sc as reviewModule};
6
+ import{a as Sc,b as xc}from"./chunk-NXOSE66U.js";import{a as or}from"./chunk-HCD7IVOL.js";import{attr as ut,binaryPartOf as bc,elements as to,parseXmlPart as Mc,mainPresentationPart as Yc,presentationInfo as Rc,relTargetByType as ir,textOf as Ic,xmlPartOf as Ec}from"@pptx-editor.dev/core/store";var cr="http://schemas.openxmlformats.org/officeDocument/2006/relationships",vc=`${cr}/comments`,Oc=`${cr}/commentAuthors`;function ar(e,t){let n=Ec(e,t);if(n||!t)return n;let o=bc(e,t);if(!o)return;let r=Mc(t,new TextDecoder().decode(o));return r.ok?r.part:void 0}function Pc(e){let t=Object.create(null),n=Yc(e);if(!n)return t;let o=ar(e,ir(e,n,Oc));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 Ac(e){let t=Pc(e),n=[];for(let o of Rc(e).slides){let r=ar(e,ir(e,o.partName,vc));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:Ic(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 Dc(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 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")&&gt(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)&&gt(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};
package/dist/react.js CHANGED
@@ -3,4 +3,4 @@ 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 Be,b as W,c as Z,d as je,e as j,f as we,g as He,h as K,i as F,j as z,k as qe,l as Ue,m as J,n as Xe,o as Q,p as Ge,q as We,r as Ze}from"./chunk-WVMCUB34.js";import{a as ut}from"./chunk-B3UUTQS4.js";import"./chunk-HCD7IVOL.js";import{Fragment as st,cloneElement as Vt,isValidElement as me,useCallback as De,useEffect as pe,useMemo as U,useRef as it,useState as Oe}from"react";import{currentSlideSummary as Kt,registerCommentDraft as Ft}from"@pptx-editor.dev/core/editor";import{useEditorState as Se,usePptxEditor as $t,useReviewAuthors as Bt}from"@pptx-editor.dev/react";import{useCallback as dt,useMemo as Y,useSyncExternalStore as pt}from"react";import{usePptxEditor as mt}from"@pptx-editor.dev/react";function ye(){return ze(mt())}function ze(e){let n=dt(m=>e?e.subscribe(m):()=>{},[e]),t=pt(n,()=>e?e.snapshot():null,()=>null),o=Y(()=>Ue(e,t),[e,t]),r=Y(()=>Q(e),[e]),i=t?.selection,a=t?.shapes,s=Y(()=>i?z(i,a):null,[i,a]),l=t?.activeComment??null,c=t?.commentAuthor??null,d=J(t),v=Xe(t);return Y(()=>({items:o,activeKey:l,...r,author:c,commentTarget:s,readOnly:d,ready:v}),[o,l,r,c,s,d,v])}import{createContext as Je,useCallback as vt,useContext as ee}from"react";import{useReviewAuthors as ft,useTranslation as wt}from"@pptx-editor.dev/react";var H=Je(null),b=Je(null);function yt(){return ee(b)}function Rt(e){let n=ee(H),t=ft();if(e)return n?n.authors.get(e):t.find(o=>o.author===e)}var xt={items:[],activeKey:null,...Q(null),author:null,commentTarget:null,readOnly:!0,ready:!1},bt={t:void 0,cardClassName:void 0,review:xt,byId:new Map,authors:new Map,drafting:!1,draftTarget:null,beginDraft:()=>{},endDraft:()=>{},editing:null,setEditing:()=>{},focusCard:()=>{}};function _(){return ee(H)??bt}function x(){let e=ee(H)?.t,{t:n}=wt();return vt((t,o)=>{let r=e?.(t);return r===void 0?n(t,o):o?r.replace(/\{(\w+)\}/g,(i,a)=>Object.hasOwn(o,a)?String(o[a]):i):r},[e,n])}import{Children as It,Fragment as Dt,cloneElement as Ot,isValidElement as rt,useContext as L,useMemo as St}from"react";import{Icon as Mt}from"@pptx-editor.dev/react";import{Children as gt,cloneElement as Qe,isValidElement as ht}from"react";function Pt(e,n){return typeof n!="function"?e:typeof e!="function"?n:t=>{e(t),t.defaultPrevented||n(t)}}function _t(e,n){let t={...e,...n};for(let o of Object.keys(e))/^on[A-Z]/.test(o)?t[o]=Pt(n[o],e[o]):o==="className"?t[o]=[e[o],n[o]].filter(Boolean).join(" "):o==="style"&&(t[o]={...e[o],...n[o]});return t}function et(e){return e==="Enter"||e===" "}function Nt(e){return et(e.key)?(e.preventDefault(),e.stopPropagation(),!0):!1}function Ye(e){return e.type==="button"}function Ct(e,n){return e.type==="a"||n.href!=null}function At(e,n,t,o){let r=i=>{typeof t=="function"&&t(i)};return{onClick:i=>{typeof e=="function"&&e(i),i.defaultPrevented||r(i),o&&i.preventDefault()},onKeyDown:i=>{if(typeof n=="function"&&n(i),!et(i.key))return;i.defaultPrevented||r(i),o&&i.preventDefault()}}}function te({engineDisabled:e,disabledReason:n,slotProps:t,children:o}){let r=gt.only(o);if(!ht(r))return null;let i=r.props,a=_t(t,i);if(!e){if(!Ye(r)){let s=At(i.onClick,i.onKeyDown,t.onClick,Ct(r,i));a.onClick=s.onClick,a.onKeyDown=s.onKeyDown}return Qe(r,a)}if(Ye(r))a.disabled=!0,delete a["aria-disabled"];else{delete a.disabled,a["aria-disabled"]=!0,a["data-disabled"]="",a.tabIndex=-1,a.href=void 0,a.role===void 0&&(a.role="button");let s=a.onKeyDown;a.onKeyDown=l=>{Nt(l)||typeof s=="function"&&s(l)}}return n&&(a.title=n),a.onClick=s=>{s.preventDefault(),s.stopPropagation()},Qe(r,a)}import{useContext as Et,useEffect as tt,useId as xe,useRef as Re,useState as M}from"react";import{Icon as nt,usePptxEditor as be}from"@pptx-editor.dev/react";import{commentInitials as Tt}from"@pptx-editor.dev/core/editor";import{Fragment as kt,jsx as p,jsxs as V}from"react/jsx-runtime";var ne=(...e)=>e.filter(Boolean).join(" ");function ge(e){let n=Re(null);return tt(()=>{let t=n.current;!e.autoFocus||!t||(t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))},[]),p("textarea",{ref:n,id:e.id,className:"pptx-review__input","data-comment-field":"",rows:1,value:e.value,maxLength:Be,"aria-label":e.label,"aria-describedby":e.describedBy,placeholder:e.placeholder??e.label,onChange:t=>e.onChange(t.target.value),onClick:t=>t.stopPropagation(),onKeyDown:t=>{let o=We({...t,isComposing:t.nativeEvent.isComposing});o&&(t.preventDefault(),t.stopPropagation(),o==="post"?e.onPost():e.onCancel())}})}function he({id:e,notice:n,current:t}){let o=x(),r=n?.rejection.reason==="errors.commentChanged";return V("span",{id:e,className:"pptx-review__refused pptx-review__notice",role:"status",children:[n?p("span",{children:je(o,n)},n.serial):null,n&&r&&t!==void 0?p("span",{className:"pptx-review__current",children:o("comments.nowReads",{text:t})}):null]})}function Pe({id:e}){let n=x();return p("span",{id:e,className:"pptx-sr-only",children:n("comments.keyHint")})}function oe({className:e,asChild:n,hidden:t,children:o}){let{beginDraft:r,drafting:i,review:a}=_(),s=x();if(t)return null;let l=s("comments.new"),c=i||a.readOnly;return n?p("div",{className:"pptx-review__bar",children:p(te,{engineDisabled:c,disabledReason:null,slotProps:{className:ne("pptx-review__add",e),"data-review-add":"",onClick:r},children:o})}):p("div",{className:"pptx-review__bar",children:V("button",{type:"button",className:ne("pptx-review__add",e),"data-review-add":"",disabled:c,onClick:r,children:[p(nt,{name:"add_comment"}),p("span",{children:o??l})]})})}oe.pptxReviewPart="AddComment";function re({className:e,hidden:n,nodeId:t}){let{drafting:o,draftTarget:r,endDraft:i,review:a,authors:s}=_(),l=be(),c=x(),[d,v]=M(""),[m,g]=M(null),w=xe();if(!o&&m&&g(null),n||!o)return null;let h=a.author??"",y=t??r?.nodeId,T=!t&&r?.range?{range:r.range}:{},k=t?null:r??a.commentTarget,I=a.author===null,A=d.trim()==="",P=()=>{if(A||I||a.readOnly)return;let R=W(l,()=>a.comment(d,void 0,y?{nodeId:y,...T}:void 0));R===null?(v(""),g(null),i()):g(Z(R,"draft",m))},S=()=>{v(""),g(null),i()};return p("div",{className:ne("pptx-review__card",e),"data-draft":"",...K(h,s),style:F(h,s),children:V("form",{className:"pptx-review__compose",onSubmit:R=>{R.preventDefault(),P()},children:[k?p("span",{className:"pptx-review__chip",children:c("comments.pointsAt",{name:k.name})}):null,p(ge,{id:w,value:d,label:c("comments.addComment"),describedBy:`${I?`${w}-blocked`:`${w}-hint`} ${w}-notice`,autoFocus:!0,onChange:R=>{v(R),g(null)},onPost:P,onCancel:S}),p(Pe,{id:`${w}-hint`}),p(he,{id:`${w}-notice`,notice:m}),I?p("span",{id:`${w}-blocked`,className:"pptx-review__refused",children:c("comments.noAuthor")}):null,V("div",{className:"pptx-review__compose-actions",children:[p("button",{type:"button",className:"pptx-review__text-button",onClick:S,children:c("comments.cancel")}),p("button",{type:"submit",className:"pptx-review__submit",disabled:A||I,children:c("comments.text")})]})]})})}re.pptxReviewPart="Draft";function q({className:e,hidden:n,children:t}){let{review:o,authors:r}=_(),i=be(),a=Et(b),s=x(),[l,c]=M(""),d=xe(),v=a?.identity??"",[m,g]=M(v),[w,h]=M(null),[y,T]=M(null);if(v!==m&&(g(v),c(""),h(null),T(null)),y&&!a?.isActive&&T(null),n||!a||!a.isActive||a.resolved||o.readOnly)return null;if(t)return p(kt,{children:t});let k=o.author??"",I=a.author||s("comments.unknownAuthor"),A=l.trim()==="",P=R=>{R?w||h(j(a)):h(null),c(R),T(null)},S=()=>{if(A||o.author===null)return;let R=W(i,()=>o.reply(w?we(a,w):a,l));if(R===null){c(""),h(null),T(null);return}R?.reason==="errors.commentChanged"&&h(j(a)),T(Z(R,"reply",y))};return V("form",{className:ne("pptx-review__reply-line",e),onSubmit:R=>{R.preventDefault(),S()},children:[k?p("span",{className:"pptx-review__avatar pptx-review__reply-avatar","aria-hidden":"true",...K(k,r),style:F(k,r),children:Tt({initials:"",author:k})}):null,p(ge,{id:d,value:l,label:s("comments.replyTo",{author:I}),placeholder:s("comments.replyText"),describedBy:`${o.author===null?`${d}-blocked`:`${d}-hint`} ${d}-notice`,onChange:P,onPost:S,onCancel:()=>{l?P(""):o.setActive(null)}}),p(Pe,{id:`${d}-hint`}),p(he,{id:`${d}-notice`,notice:y}),l?p("button",{type:"button",className:"pptx-review__text-button",onClick:()=>P(""),children:s("comments.cancel")}):null,p("button",{type:"submit",className:"pptx-review__send","aria-label":s("comments.replyTo",{author:I}),"data-pptx-tooltip":s("comments.reply"),disabled:A||o.author===null,children:p(nt,{name:"send"})}),o.author===null?p("span",{id:`${d}-blocked`,className:"pptx-review__refused",children:s("comments.noAuthor")}):null]})}q.pptxReviewPart="Reply";function ot({item:e}){let{review:n,setEditing:t,focusCard:o}=_(),r=be(),i=x(),[a,s]=M(e.text),l=xe(),c=Re(e.identity),d=e.identity!==c.current,v=Re(j(e)),[m,g]=M(null);tt(()=>{d&&t(null)},[d,t]);let w=()=>{t(null),o(e.parentId??e.key)},h=()=>{if(d||a.trim()==="")return;let y=W(r,()=>n.edit(we(e,v.current),a));if(y===null)return w();y?.reason==="errors.commentChanged"&&(v.current=j(e)),g(Z(y,"edit",m))};return V("form",{className:"pptx-review__compose",onSubmit:y=>{y.preventDefault(),h()},children:[p(ge,{id:l,value:a,label:i("comments.editText"),describedBy:`${l}-hint ${l}-notice`,autoFocus:!0,onChange:y=>{s(y),g(null)},onPost:h,onCancel:w}),p(Pe,{id:`${l}-hint`}),p(he,{id:`${l}-notice`,notice:m,current:e.text}),V("div",{className:"pptx-review__compose-actions",children:[p("button",{type:"button",className:"pptx-review__text-button",onClick:w,children:i("comments.cancel")}),p("button",{type:"submit",className:"pptx-review__submit",disabled:a.trim()==="",children:i("comments.save")})]})]})}import{Fragment as Ie,jsx as u,jsxs as D}from"react/jsx-runtime";function E(e,n){return Object.assign(e,{pptxReviewPart:n})}var O=(...e)=>e.filter(Boolean).join(" ");function $(e,n){let t=It.only(e);if(!rt(t))return null;let o=t.props;return Ot(t,{...n,...o,className:O(n.className,o.className)})}function _e(e){let n={},t=[],o=r=>{if(Array.isArray(r))return void r.forEach(o);if(!rt(r)){r!=null&&r!==!1&&t.push(r);return}if(r.type===Dt)return o(r.props.children);let i=r.type.pptxReviewPart;i?n[i]=r:t.push(r)};return o(e),t.length>0&&(n.__extra=t),n}var Ne=E(function({className:n,hidden:t,children:o}){let r=x(),{review:i}=_();return t?null:u("div",{className:O("pptx-review__empty",n),children:o??D(Ie,{children:[u("p",{className:"pptx-review__empty-title",children:r("comments.emptyTitle")}),i.readOnly?null:u("p",{className:"pptx-review__empty-body",children:r("comments.emptyBody")})]})})},"Empty"),Ce=E(function({className:n,asChild:t,hidden:o,children:r}){let{review:i,cardClassName:a,authors:s}=_(),l=L(b),c=x();if(o||!l)return null;let d=()=>{l.isActive||i.setActive(l.key,{identity:l.identity})},v={className:O("pptx-review__card",a,n),"data-comment-id":l.id,...l.isActive?{"data-active":"","aria-current":"true"}:{},...l.resolved?{"data-resolved":""}:{},...K(l.author,s),style:F(l.author,s),role:"group","aria-label":c("comments.thread",{author:l.author||c("comments.unknownAuthor")}),tabIndex:0,onClick:m=>{Ze(m.target)||d()},onKeyDown:m=>{m.target!==m.currentTarget||m.key!=="Enter"&&m.key!==" "||(m.preventDefault(),d())}};return t?$(r,v):u("div",{...v,children:u(Lt,{children:r})})},"Card");function Lt({children:e}){let n=St(()=>_e(e),[e]),t=(o,r)=>o in n?n[o]:r;return D(Ie,{children:[D("div",{className:"pptx-review__head",children:[t("Avatar",u(ie,{})),D("div",{className:"pptx-review__meta",children:[t("Author",u(ae,{})),t("Time",u(se,{}))]}),D("div",{className:"pptx-review__actions",children:[t("Resolve",u(Te,{})),t("Reopen",u(ke,{})),t("Edit",u(ue,{})),t("Delete",u(de,{}))]})]}),t("Anchor",u(Ae,{})),t("Summary",u(le,{})),t("Replies",u(Ee,{})),t("Reply",u(q,{})),n.__extra]})}var ie=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b);if(o||!i)return null;let a={className:O("pptx-review__avatar",n),"aria-hidden":!0};return t?$(r,a):u("span",{...a,children:r??i.initials})},"Avatar"),ae=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),a=x();if(o||!i)return null;let s={className:O("pptx-review__author",n)};return t?$(r,s):u("span",{...s,children:r??(i.author||a("comments.unknownAuthor"))})},"Author"),se=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),a=x();if(o||!i)return null;let s=Ge(i.date),l=i.resolved&&i.parentId===void 0?a("comments.resolved"):"";if(!s&&!l)return null;let c={className:O("pptx-review__time",n)};return t?$(r,c):u("span",{...c,children:r??D(Ie,{children:[s?u("time",{dateTime:i.date,children:s}):null,l?u("span",{className:"pptx-review__status",children:l}):null]})})},"Time"),Ae=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),a=x();if(o||!i||i.parentId!==void 0||i.anchorName===void 0)return null;let s={className:O("pptx-review__chip",n)};return t?$(r,s):u("span",{...s,children:r??a("comments.on",{name:i.anchorName})})},"Anchor"),le=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),{editing:a}=_();if(o||!i)return null;if(a===i.identity)return u(ot,{item:i});let s={className:O("pptx-review__summary",n)};return t?$(r,s):u("div",{...s,children:r??u("p",{className:"pptx-review__text",children:i.text})})},"Summary"),Ee=E(function({className:n,hidden:t}){let{byId:o,authors:r}=_(),i=L(b),a=x();if(t||!i||i.replyIds.length===0)return null;let s=i.replyIds.map(l=>o.get(l)).filter(l=>l!==void 0);return s.length===0?null:u("ol",{className:O("pptx-review__replies",n),"aria-label":a("comments.replies",{author:i.author||a("comments.unknownAuthor")}),children:s.map(l=>u(b.Provider,{value:l,children:D("li",{className:"pptx-review__reply","data-reply-id":l.id,...K(l.author,r),style:F(l.author,r),children:[D("div",{className:"pptx-review__head",children:[u(ie,{}),D("div",{className:"pptx-review__meta",children:[u(ae,{}),u(se,{})]}),D("div",{className:"pptx-review__actions",children:[u(ue,{}),u(de,{})]})]}),u(le,{})]})},l.identity))})},"Replies");function ce(e){function n({className:t,asChild:o,hidden:r,children:i,icon:a}){let s=_(),l=L(b),c=x();if(r||!l||s.review.readOnly||!e.shows(l))return null;let d=c(e.label(l),{author:l.author||c("comments.unknownAuthor")}),v={type:"button",className:O("pptx-review__action",t),"data-action":e.part.toLowerCase(),"aria-label":d,"data-pptx-tooltip":d,onClick:m=>{m.stopPropagation(),e.run(s,l)}};return o?u(te,{engineDisabled:!1,disabledReason:null,slotProps:v,children:i}):u("button",{...v,children:a??i??u(Mt,{name:e.icon})})}return E(n,e.part)}var Te=ce({part:"Resolve",icon:"check",label:()=>"comments.resolveOf",shows:e=>e.parentId===void 0&&!e.resolved&&e.resolvable,run:({review:e},n)=>e.resolve(n)}),ke=ce({part:"Reopen",icon:"refresh",label:()=>"comments.reopenOf",shows:e=>e.parentId===void 0&&e.resolved&&e.resolvable,run:({review:e},n)=>e.reopen(n)}),ue=ce({part:"Edit",icon:"edit",label:()=>"comments.editOf",shows:e=>e.editable,run:({setEditing:e},n)=>e(n.identity)}),de=ce({part:"Delete",icon:"delete",label:()=>"comments.deleteOf",shows:()=>!0,run:({review:e,focusCard:n},t)=>{e.remove(t)&&n(t.parentId??t.key)}});import{Fragment as Gt,jsx as N,jsxs as at}from"react/jsx-runtime";var Me=(...e)=>e.filter(Boolean).join(" "),lt=E(function({className:n,hidden:t,children:o}){let{review:r}=_(),i=x(),a=U(()=>typeof o=="function"?null:_e(o),[o]);if(t)return null;let s=r.items.filter(c=>c.parentId===void 0);if(s.length===0)return typeof o=="function"?null:N(Gt,{children:a&&"Empty"in a?a.Empty:N(Ne,{})});let l=()=>{if(a&&me(a.Card))return a.Card;let c=a?Object.entries(a).filter(([d])=>d!=="Empty"):[];return N(Ce,{children:c.map(([d,v])=>N(st,{children:v},d))})};return N("ul",{className:Me("pptx-review__list",n),"aria-label":i("comments.label"),children:s.map(c=>N(b.Provider,{value:c,children:N("li",{className:"pptx-review__slot",children:typeof o=="function"?o(c):l()})},c.identity))})},"List"),jt=new Set(["List","AddComment","Draft"]);function Ht(e){if(typeof e=="function")return{parts:{},template:e};let n={},t=[],o=r=>{if(Array.isArray(r))return void r.forEach(o);if(me(r)&&r.type===st)return o(r.props.children);let i=me(r)?r.type.pptxReviewPart:void 0;i&&jt.has(i)?n[i]=r:r!=null&&r!==!1&&t.push(r)};return o(e),{parts:n,template:t.length>0?t:void 0}}function qt({className:e,hidden:n,t,card:o,children:r,preset:i=!0,filter:a}){let s=ye(),l=$t(),c=Ut(t),d=Se(f=>f.status==="ready"&&f.comments==null),[v,m]=Oe(!1),[g,w]=Oe(null),h=Se(f=>f.shapes),y=qe(g,h),T=g!==null&&y===null;pe(()=>{T&&w(null)},[T]);let[k,I]=Oe(null),A=it(null),P=U(()=>{if(!a)return s.items;let f=new Set(s.items.filter(C=>C.parentId===void 0&&a(C)).map(C=>C.id));return s.items.filter(C=>f.has(C.parentId??C.id))},[s.items,a]),S=U(()=>new Map(P.map(f=>[f.id,f])),[P]),R=Bt(),Le=U(()=>He(R),[R]),X=Se(f=>Kt(f)?.id??""),ve=it({slide:X,readOnly:s.readOnly});pe(()=>{ve.current.slide===X&&ve.current.readOnly===s.readOnly||(ve.current={slide:X,readOnly:s.readOnly},m(!1),I(null))},[X,s.readOnly]),pe(()=>{if(!(!l||d||n))return Ft(l,()=>{let f=l.snapshot();J(f)||(w(z(f.selection,f.shapes)),m(!0),requestAnimationFrame(()=>A.current?.querySelector("[data-draft] [data-comment-field]")?.focus()))})},[l,d,n]);let Ve=De(f=>{requestAnimationFrame(()=>{let C=A.current;(C?.querySelector(`[data-comment-id="${CSS.escape(f)}"]`)??C?.querySelector("[data-review-add]"))?.focus()})},[]),Ke=De(()=>{w(null),m(!0)},[]),Fe=De(()=>{m(!1),w(null),requestAnimationFrame(()=>A.current?.querySelector("[data-review-add]")?.focus())},[]);pe(()=>{s.activeKey&&A.current?.querySelector(`[data-comment-id="${CSS.escape(s.activeKey)}"]`)?.scrollIntoView?.({block:"nearest"})},[s.activeKey]);let ct=U(()=>({t,cardClassName:o?.className,review:P===s.items?s:{...s,items:P},byId:S,authors:Le,drafting:v,draftTarget:y,beginDraft:Ke,endDraft:Fe,editing:k,setEditing:I,focusCard:Ve}),[t,o?.className,s,P,S,Le,v,y,Ke,Fe,k,Ve]);if(n)return null;if(d)return at("div",{className:Me("pptx-empty",e),children:[N("p",{className:"pptx-empty__title",children:c("panel.comments.emptyTitle")}),N("p",{className:"pptx-empty__body",children:c("panel.comments.emptyBody")})]});let{parts:fe,template:G}=Ht(r),$e=(f,C)=>f in fe?fe[f]:i?C:null,B=fe.List;return N(H.Provider,{value:ct,children:at("section",{ref:A,className:Me("pptx-review",e),"aria-label":c("panel.tabs.comments"),"data-count":P.filter(f=>f.parentId===void 0).length,children:[$e("AddComment",N(oe,{})),$e("Draft",N(re,{})),B!==void 0?me(B)&&B.props.children===void 0&&G?Vt(B,{children:G}):B:i?N(lt,{children:G}):G]})})}function Ut(e){let n=x();return t=>e?.(t)??n(t)}var Xt=Object.assign(qt,{List:lt,AddComment:oe,Draft:re,Empty:Ne,Card:Ce,Avatar:ie,Author:ae,Time:se,Anchor:Ae,Summary:le,Resolve:Te,Reopen:ke,Edit:ue,Delete:de,Replies:Ee,Reply:q});export{Xt as PptxEditorReview,ut as reviewModule,ye as useReview,Rt as useReviewAuthor,yt as useReviewItem,ze as useReviewOf};
6
+ import{a as Be,b as W,c as Z,d as je,e as j,f as we,g as He,h as K,i as F,j as z,k as qe,l as Ue,m as J,n as Xe,o as Q,p as Ge,q as We,r as Ze}from"./chunk-WVMCUB34.js";import{b as ut}from"./chunk-NXOSE66U.js";import"./chunk-HCD7IVOL.js";import{Fragment as st,cloneElement as Vt,isValidElement as me,useCallback as De,useEffect as pe,useMemo as U,useRef as it,useState as Oe}from"react";import{currentSlideSummary as Kt,registerCommentDraft as Ft}from"@pptx-editor.dev/core/editor";import{useEditorState as Se,usePptxEditor as $t,useReviewAuthors as Bt}from"@pptx-editor.dev/react";import{useCallback as dt,useMemo as Y,useSyncExternalStore as pt}from"react";import{usePptxEditor as mt}from"@pptx-editor.dev/react";function ye(){return ze(mt())}function ze(e){let n=dt(m=>e?e.subscribe(m):()=>{},[e]),t=pt(n,()=>e?e.snapshot():null,()=>null),o=Y(()=>Ue(e,t),[e,t]),r=Y(()=>Q(e),[e]),i=t?.selection,a=t?.shapes,s=Y(()=>i?z(i,a):null,[i,a]),l=t?.activeComment??null,c=t?.commentAuthor??null,d=J(t),v=Xe(t);return Y(()=>({items:o,activeKey:l,...r,author:c,commentTarget:s,readOnly:d,ready:v}),[o,l,r,c,s,d,v])}import{createContext as Je,useCallback as vt,useContext as ee}from"react";import{useReviewAuthors as ft,useTranslation as wt}from"@pptx-editor.dev/react";var H=Je(null),b=Je(null);function yt(){return ee(b)}function Rt(e){let n=ee(H),t=ft();if(e)return n?n.authors.get(e):t.find(o=>o.author===e)}var xt={items:[],activeKey:null,...Q(null),author:null,commentTarget:null,readOnly:!0,ready:!1},bt={t:void 0,cardClassName:void 0,review:xt,byId:new Map,authors:new Map,drafting:!1,draftTarget:null,beginDraft:()=>{},endDraft:()=>{},editing:null,setEditing:()=>{},focusCard:()=>{}};function _(){return ee(H)??bt}function x(){let e=ee(H)?.t,{t:n}=wt();return vt((t,o)=>{let r=e?.(t);return r===void 0?n(t,o):o?r.replace(/\{(\w+)\}/g,(i,a)=>Object.hasOwn(o,a)?String(o[a]):i):r},[e,n])}import{Children as It,Fragment as Dt,cloneElement as Ot,isValidElement as rt,useContext as L,useMemo as St}from"react";import{Icon as Mt}from"@pptx-editor.dev/react";import{Children as gt,cloneElement as Qe,isValidElement as ht}from"react";function Pt(e,n){return typeof n!="function"?e:typeof e!="function"?n:t=>{e(t),t.defaultPrevented||n(t)}}function _t(e,n){let t={...e,...n};for(let o of Object.keys(e))/^on[A-Z]/.test(o)?t[o]=Pt(n[o],e[o]):o==="className"?t[o]=[e[o],n[o]].filter(Boolean).join(" "):o==="style"&&(t[o]={...e[o],...n[o]});return t}function et(e){return e==="Enter"||e===" "}function Nt(e){return et(e.key)?(e.preventDefault(),e.stopPropagation(),!0):!1}function Ye(e){return e.type==="button"}function Ct(e,n){return e.type==="a"||n.href!=null}function At(e,n,t,o){let r=i=>{typeof t=="function"&&t(i)};return{onClick:i=>{typeof e=="function"&&e(i),i.defaultPrevented||r(i),o&&i.preventDefault()},onKeyDown:i=>{if(typeof n=="function"&&n(i),!et(i.key))return;i.defaultPrevented||r(i),o&&i.preventDefault()}}}function te({engineDisabled:e,disabledReason:n,slotProps:t,children:o}){let r=gt.only(o);if(!ht(r))return null;let i=r.props,a=_t(t,i);if(!e){if(!Ye(r)){let s=At(i.onClick,i.onKeyDown,t.onClick,Ct(r,i));a.onClick=s.onClick,a.onKeyDown=s.onKeyDown}return Qe(r,a)}if(Ye(r))a.disabled=!0,delete a["aria-disabled"];else{delete a.disabled,a["aria-disabled"]=!0,a["data-disabled"]="",a.tabIndex=-1,a.href=void 0,a.role===void 0&&(a.role="button");let s=a.onKeyDown;a.onKeyDown=l=>{Nt(l)||typeof s=="function"&&s(l)}}return n&&(a.title=n),a.onClick=s=>{s.preventDefault(),s.stopPropagation()},Qe(r,a)}import{useContext as Et,useEffect as tt,useId as xe,useRef as Re,useState as M}from"react";import{Icon as nt,usePptxEditor as be}from"@pptx-editor.dev/react";import{commentInitials as Tt}from"@pptx-editor.dev/core/editor";import{Fragment as kt,jsx as p,jsxs as V}from"react/jsx-runtime";var ne=(...e)=>e.filter(Boolean).join(" ");function ge(e){let n=Re(null);return tt(()=>{let t=n.current;!e.autoFocus||!t||(t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))},[]),p("textarea",{ref:n,id:e.id,className:"pptx-review__input","data-comment-field":"",rows:1,value:e.value,maxLength:Be,"aria-label":e.label,"aria-describedby":e.describedBy,placeholder:e.placeholder??e.label,onChange:t=>e.onChange(t.target.value),onClick:t=>t.stopPropagation(),onKeyDown:t=>{let o=We({...t,isComposing:t.nativeEvent.isComposing});o&&(t.preventDefault(),t.stopPropagation(),o==="post"?e.onPost():e.onCancel())}})}function he({id:e,notice:n,current:t}){let o=x(),r=n?.rejection.reason==="errors.commentChanged";return V("span",{id:e,className:"pptx-review__refused pptx-review__notice",role:"status",children:[n?p("span",{children:je(o,n)},n.serial):null,n&&r&&t!==void 0?p("span",{className:"pptx-review__current",children:o("comments.nowReads",{text:t})}):null]})}function Pe({id:e}){let n=x();return p("span",{id:e,className:"pptx-sr-only",children:n("comments.keyHint")})}function oe({className:e,asChild:n,hidden:t,children:o}){let{beginDraft:r,drafting:i,review:a}=_(),s=x();if(t)return null;let l=s("comments.new"),c=i||a.readOnly;return n?p("div",{className:"pptx-review__bar",children:p(te,{engineDisabled:c,disabledReason:null,slotProps:{className:ne("pptx-review__add",e),"data-review-add":"",onClick:r},children:o})}):p("div",{className:"pptx-review__bar",children:V("button",{type:"button",className:ne("pptx-review__add",e),"data-review-add":"",disabled:c,onClick:r,children:[p(nt,{name:"add_comment"}),p("span",{children:o??l})]})})}oe.pptxReviewPart="AddComment";function re({className:e,hidden:n,nodeId:t}){let{drafting:o,draftTarget:r,endDraft:i,review:a,authors:s}=_(),l=be(),c=x(),[d,v]=M(""),[m,g]=M(null),w=xe();if(!o&&m&&g(null),n||!o)return null;let h=a.author??"",y=t??r?.nodeId,T=!t&&r?.range?{range:r.range}:{},k=t?null:r??a.commentTarget,I=a.author===null,A=d.trim()==="",P=()=>{if(A||I||a.readOnly)return;let R=W(l,()=>a.comment(d,void 0,y?{nodeId:y,...T}:void 0));R===null?(v(""),g(null),i()):g(Z(R,"draft",m))},S=()=>{v(""),g(null),i()};return p("div",{className:ne("pptx-review__card",e),"data-draft":"",...K(h,s),style:F(h,s),children:V("form",{className:"pptx-review__compose",onSubmit:R=>{R.preventDefault(),P()},children:[k?p("span",{className:"pptx-review__chip",children:c("comments.pointsAt",{name:k.name})}):null,p(ge,{id:w,value:d,label:c("comments.addComment"),describedBy:`${I?`${w}-blocked`:`${w}-hint`} ${w}-notice`,autoFocus:!0,onChange:R=>{v(R),g(null)},onPost:P,onCancel:S}),p(Pe,{id:`${w}-hint`}),p(he,{id:`${w}-notice`,notice:m}),I?p("span",{id:`${w}-blocked`,className:"pptx-review__refused",children:c("comments.noAuthor")}):null,V("div",{className:"pptx-review__compose-actions",children:[p("button",{type:"button",className:"pptx-review__text-button",onClick:S,children:c("comments.cancel")}),p("button",{type:"submit",className:"pptx-review__submit",disabled:A||I,children:c("comments.text")})]})]})})}re.pptxReviewPart="Draft";function q({className:e,hidden:n,children:t}){let{review:o,authors:r}=_(),i=be(),a=Et(b),s=x(),[l,c]=M(""),d=xe(),v=a?.identity??"",[m,g]=M(v),[w,h]=M(null),[y,T]=M(null);if(v!==m&&(g(v),c(""),h(null),T(null)),y&&!a?.isActive&&T(null),n||!a||!a.isActive||a.resolved||o.readOnly)return null;if(t)return p(kt,{children:t});let k=o.author??"",I=a.author||s("comments.unknownAuthor"),A=l.trim()==="",P=R=>{R?w||h(j(a)):h(null),c(R),T(null)},S=()=>{if(A||o.author===null)return;let R=W(i,()=>o.reply(w?we(a,w):a,l));if(R===null){c(""),h(null),T(null);return}R?.reason==="errors.commentChanged"&&h(j(a)),T(Z(R,"reply",y))};return V("form",{className:ne("pptx-review__reply-line",e),onSubmit:R=>{R.preventDefault(),S()},children:[k?p("span",{className:"pptx-review__avatar pptx-review__reply-avatar","aria-hidden":"true",...K(k,r),style:F(k,r),children:Tt({initials:"",author:k})}):null,p(ge,{id:d,value:l,label:s("comments.replyTo",{author:I}),placeholder:s("comments.replyText"),describedBy:`${o.author===null?`${d}-blocked`:`${d}-hint`} ${d}-notice`,onChange:P,onPost:S,onCancel:()=>{l?P(""):o.setActive(null)}}),p(Pe,{id:`${d}-hint`}),p(he,{id:`${d}-notice`,notice:y}),l?p("button",{type:"button",className:"pptx-review__text-button",onClick:()=>P(""),children:s("comments.cancel")}):null,p("button",{type:"submit",className:"pptx-review__send","aria-label":s("comments.replyTo",{author:I}),"data-pptx-tooltip":s("comments.reply"),disabled:A||o.author===null,children:p(nt,{name:"send"})}),o.author===null?p("span",{id:`${d}-blocked`,className:"pptx-review__refused",children:s("comments.noAuthor")}):null]})}q.pptxReviewPart="Reply";function ot({item:e}){let{review:n,setEditing:t,focusCard:o}=_(),r=be(),i=x(),[a,s]=M(e.text),l=xe(),c=Re(e.identity),d=e.identity!==c.current,v=Re(j(e)),[m,g]=M(null);tt(()=>{d&&t(null)},[d,t]);let w=()=>{t(null),o(e.parentId??e.key)},h=()=>{if(d||a.trim()==="")return;let y=W(r,()=>n.edit(we(e,v.current),a));if(y===null)return w();y?.reason==="errors.commentChanged"&&(v.current=j(e)),g(Z(y,"edit",m))};return V("form",{className:"pptx-review__compose",onSubmit:y=>{y.preventDefault(),h()},children:[p(ge,{id:l,value:a,label:i("comments.editText"),describedBy:`${l}-hint ${l}-notice`,autoFocus:!0,onChange:y=>{s(y),g(null)},onPost:h,onCancel:w}),p(Pe,{id:`${l}-hint`}),p(he,{id:`${l}-notice`,notice:m,current:e.text}),V("div",{className:"pptx-review__compose-actions",children:[p("button",{type:"button",className:"pptx-review__text-button",onClick:w,children:i("comments.cancel")}),p("button",{type:"submit",className:"pptx-review__submit",disabled:a.trim()==="",children:i("comments.save")})]})]})}import{Fragment as Ie,jsx as u,jsxs as D}from"react/jsx-runtime";function E(e,n){return Object.assign(e,{pptxReviewPart:n})}var O=(...e)=>e.filter(Boolean).join(" ");function $(e,n){let t=It.only(e);if(!rt(t))return null;let o=t.props;return Ot(t,{...n,...o,className:O(n.className,o.className)})}function _e(e){let n={},t=[],o=r=>{if(Array.isArray(r))return void r.forEach(o);if(!rt(r)){r!=null&&r!==!1&&t.push(r);return}if(r.type===Dt)return o(r.props.children);let i=r.type.pptxReviewPart;i?n[i]=r:t.push(r)};return o(e),t.length>0&&(n.__extra=t),n}var Ne=E(function({className:n,hidden:t,children:o}){let r=x(),{review:i}=_();return t?null:u("div",{className:O("pptx-review__empty",n),children:o??D(Ie,{children:[u("p",{className:"pptx-review__empty-title",children:r("comments.emptyTitle")}),i.readOnly?null:u("p",{className:"pptx-review__empty-body",children:r("comments.emptyBody")})]})})},"Empty"),Ce=E(function({className:n,asChild:t,hidden:o,children:r}){let{review:i,cardClassName:a,authors:s}=_(),l=L(b),c=x();if(o||!l)return null;let d=()=>{l.isActive||i.setActive(l.key,{identity:l.identity})},v={className:O("pptx-review__card",a,n),"data-comment-id":l.id,...l.isActive?{"data-active":"","aria-current":"true"}:{},...l.resolved?{"data-resolved":""}:{},...K(l.author,s),style:F(l.author,s),role:"group","aria-label":c("comments.thread",{author:l.author||c("comments.unknownAuthor")}),tabIndex:0,onClick:m=>{Ze(m.target)||d()},onKeyDown:m=>{m.target!==m.currentTarget||m.key!=="Enter"&&m.key!==" "||(m.preventDefault(),d())}};return t?$(r,v):u("div",{...v,children:u(Lt,{children:r})})},"Card");function Lt({children:e}){let n=St(()=>_e(e),[e]),t=(o,r)=>o in n?n[o]:r;return D(Ie,{children:[D("div",{className:"pptx-review__head",children:[t("Avatar",u(ie,{})),D("div",{className:"pptx-review__meta",children:[t("Author",u(ae,{})),t("Time",u(se,{}))]}),D("div",{className:"pptx-review__actions",children:[t("Resolve",u(Te,{})),t("Reopen",u(ke,{})),t("Edit",u(ue,{})),t("Delete",u(de,{}))]})]}),t("Anchor",u(Ae,{})),t("Summary",u(le,{})),t("Replies",u(Ee,{})),t("Reply",u(q,{})),n.__extra]})}var ie=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b);if(o||!i)return null;let a={className:O("pptx-review__avatar",n),"aria-hidden":!0};return t?$(r,a):u("span",{...a,children:r??i.initials})},"Avatar"),ae=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),a=x();if(o||!i)return null;let s={className:O("pptx-review__author",n)};return t?$(r,s):u("span",{...s,children:r??(i.author||a("comments.unknownAuthor"))})},"Author"),se=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),a=x();if(o||!i)return null;let s=Ge(i.date),l=i.resolved&&i.parentId===void 0?a("comments.resolved"):"";if(!s&&!l)return null;let c={className:O("pptx-review__time",n)};return t?$(r,c):u("span",{...c,children:r??D(Ie,{children:[s?u("time",{dateTime:i.date,children:s}):null,l?u("span",{className:"pptx-review__status",children:l}):null]})})},"Time"),Ae=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),a=x();if(o||!i||i.parentId!==void 0||i.anchorName===void 0)return null;let s={className:O("pptx-review__chip",n)};return t?$(r,s):u("span",{...s,children:r??a("comments.on",{name:i.anchorName})})},"Anchor"),le=E(function({className:n,asChild:t,hidden:o,children:r}){let i=L(b),{editing:a}=_();if(o||!i)return null;if(a===i.identity)return u(ot,{item:i});let s={className:O("pptx-review__summary",n)};return t?$(r,s):u("div",{...s,children:r??u("p",{className:"pptx-review__text",children:i.text})})},"Summary"),Ee=E(function({className:n,hidden:t}){let{byId:o,authors:r}=_(),i=L(b),a=x();if(t||!i||i.replyIds.length===0)return null;let s=i.replyIds.map(l=>o.get(l)).filter(l=>l!==void 0);return s.length===0?null:u("ol",{className:O("pptx-review__replies",n),"aria-label":a("comments.replies",{author:i.author||a("comments.unknownAuthor")}),children:s.map(l=>u(b.Provider,{value:l,children:D("li",{className:"pptx-review__reply","data-reply-id":l.id,...K(l.author,r),style:F(l.author,r),children:[D("div",{className:"pptx-review__head",children:[u(ie,{}),D("div",{className:"pptx-review__meta",children:[u(ae,{}),u(se,{})]}),D("div",{className:"pptx-review__actions",children:[u(ue,{}),u(de,{})]})]}),u(le,{})]})},l.identity))})},"Replies");function ce(e){function n({className:t,asChild:o,hidden:r,children:i,icon:a}){let s=_(),l=L(b),c=x();if(r||!l||s.review.readOnly||!e.shows(l))return null;let d=c(e.label(l),{author:l.author||c("comments.unknownAuthor")}),v={type:"button",className:O("pptx-review__action",t),"data-action":e.part.toLowerCase(),"aria-label":d,"data-pptx-tooltip":d,onClick:m=>{m.stopPropagation(),e.run(s,l)}};return o?u(te,{engineDisabled:!1,disabledReason:null,slotProps:v,children:i}):u("button",{...v,children:a??i??u(Mt,{name:e.icon})})}return E(n,e.part)}var Te=ce({part:"Resolve",icon:"check",label:()=>"comments.resolveOf",shows:e=>e.parentId===void 0&&!e.resolved&&e.resolvable,run:({review:e},n)=>e.resolve(n)}),ke=ce({part:"Reopen",icon:"refresh",label:()=>"comments.reopenOf",shows:e=>e.parentId===void 0&&e.resolved&&e.resolvable,run:({review:e},n)=>e.reopen(n)}),ue=ce({part:"Edit",icon:"edit",label:()=>"comments.editOf",shows:e=>e.editable,run:({setEditing:e},n)=>e(n.identity)}),de=ce({part:"Delete",icon:"delete",label:()=>"comments.deleteOf",shows:()=>!0,run:({review:e,focusCard:n},t)=>{e.remove(t)&&n(t.parentId??t.key)}});import{Fragment as Gt,jsx as N,jsxs as at}from"react/jsx-runtime";var Me=(...e)=>e.filter(Boolean).join(" "),lt=E(function({className:n,hidden:t,children:o}){let{review:r}=_(),i=x(),a=U(()=>typeof o=="function"?null:_e(o),[o]);if(t)return null;let s=r.items.filter(c=>c.parentId===void 0);if(s.length===0)return typeof o=="function"?null:N(Gt,{children:a&&"Empty"in a?a.Empty:N(Ne,{})});let l=()=>{if(a&&me(a.Card))return a.Card;let c=a?Object.entries(a).filter(([d])=>d!=="Empty"):[];return N(Ce,{children:c.map(([d,v])=>N(st,{children:v},d))})};return N("ul",{className:Me("pptx-review__list",n),"aria-label":i("comments.label"),children:s.map(c=>N(b.Provider,{value:c,children:N("li",{className:"pptx-review__slot",children:typeof o=="function"?o(c):l()})},c.identity))})},"List"),jt=new Set(["List","AddComment","Draft"]);function Ht(e){if(typeof e=="function")return{parts:{},template:e};let n={},t=[],o=r=>{if(Array.isArray(r))return void r.forEach(o);if(me(r)&&r.type===st)return o(r.props.children);let i=me(r)?r.type.pptxReviewPart:void 0;i&&jt.has(i)?n[i]=r:r!=null&&r!==!1&&t.push(r)};return o(e),{parts:n,template:t.length>0?t:void 0}}function qt({className:e,hidden:n,t,card:o,children:r,preset:i=!0,filter:a}){let s=ye(),l=$t(),c=Ut(t),d=Se(f=>f.status==="ready"&&f.comments==null),[v,m]=Oe(!1),[g,w]=Oe(null),h=Se(f=>f.shapes),y=qe(g,h),T=g!==null&&y===null;pe(()=>{T&&w(null)},[T]);let[k,I]=Oe(null),A=it(null),P=U(()=>{if(!a)return s.items;let f=new Set(s.items.filter(C=>C.parentId===void 0&&a(C)).map(C=>C.id));return s.items.filter(C=>f.has(C.parentId??C.id))},[s.items,a]),S=U(()=>new Map(P.map(f=>[f.id,f])),[P]),R=Bt(),Le=U(()=>He(R),[R]),X=Se(f=>Kt(f)?.id??""),ve=it({slide:X,readOnly:s.readOnly});pe(()=>{ve.current.slide===X&&ve.current.readOnly===s.readOnly||(ve.current={slide:X,readOnly:s.readOnly},m(!1),I(null))},[X,s.readOnly]),pe(()=>{if(!(!l||d||n))return Ft(l,()=>{let f=l.snapshot();J(f)||(w(z(f.selection,f.shapes)),m(!0),requestAnimationFrame(()=>A.current?.querySelector("[data-draft] [data-comment-field]")?.focus()))})},[l,d,n]);let Ve=De(f=>{requestAnimationFrame(()=>{let C=A.current;(C?.querySelector(`[data-comment-id="${CSS.escape(f)}"]`)??C?.querySelector("[data-review-add]"))?.focus()})},[]),Ke=De(()=>{w(null),m(!0)},[]),Fe=De(()=>{m(!1),w(null),requestAnimationFrame(()=>A.current?.querySelector("[data-review-add]")?.focus())},[]);pe(()=>{s.activeKey&&A.current?.querySelector(`[data-comment-id="${CSS.escape(s.activeKey)}"]`)?.scrollIntoView?.({block:"nearest"})},[s.activeKey]);let ct=U(()=>({t,cardClassName:o?.className,review:P===s.items?s:{...s,items:P},byId:S,authors:Le,drafting:v,draftTarget:y,beginDraft:Ke,endDraft:Fe,editing:k,setEditing:I,focusCard:Ve}),[t,o?.className,s,P,S,Le,v,y,Ke,Fe,k,Ve]);if(n)return null;if(d)return at("div",{className:Me("pptx-empty",e),children:[N("p",{className:"pptx-empty__title",children:c("panel.comments.emptyTitle")}),N("p",{className:"pptx-empty__body",children:c("panel.comments.emptyBody")})]});let{parts:fe,template:G}=Ht(r),$e=(f,C)=>f in fe?fe[f]:i?C:null,B=fe.List;return N(H.Provider,{value:ct,children:at("section",{ref:A,className:Me("pptx-review",e),"aria-label":c("panel.tabs.comments"),"data-count":P.filter(f=>f.parentId===void 0).length,children:[$e("AddComment",N(oe,{})),$e("Draft",N(re,{})),B!==void 0?me(B)&&B.props.children===void 0&&G?Vt(B,{children:G}):B:i?N(lt,{children:G}):G]})})}function Ut(e){let n=x();return t=>e?.(t)??n(t)}var Xt=Object.assign(qt,{List:lt,AddComment:oe,Draft:re,Empty:Ne,Card:Ce,Avatar:ie,Author:ae,Time:se,Anchor:Ae,Summary:le,Resolve:Te,Reopen:ke,Edit:ue,Delete:de,Replies:Ee,Reply:q});export{Xt as PptxEditorReview,ut as reviewModule,ye as useReview,Rt as useReviewAuthor,yt as useReviewItem,ze as useReviewOf};
package/dist/vue.js CHANGED
@@ -3,4 +3,4 @@ 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 Se,b as H,c as G,d as ke,e as $,f as ve,g as De,h as L,i as j,j as X,k as Oe,l as Me,m as Z,n as Be,o as z,p as Ke,q as Le,r as je}from"./chunk-WVMCUB34.js";import{a as tt}from"./chunk-B3UUTQS4.js";import"./chunk-HCD7IVOL.js";import{Fragment as Tt,computed as de,defineComponent as We,isVNode as Nt,nextTick as pe,onBeforeUnmount as It,provide as Vt,ref as ze,shallowRef as Je,watch as ce}from"vue";import{currentSlideSummary as Et,registerCommentDraft as St}from"@pptx-editor.dev/core/editor";import{useEditorState as Ve,usePptxEditor as kt,useReviewAuthors as Dt}from"@pptx-editor.dev/vue";import{computed as O,shallowRef as nt,toValue as ot,watch as it}from"vue";import{usePptxEditor as rt}from"@pptx-editor.dev/vue";function me(){return Fe(rt())}function Fe(e){let o=O(()=>ot(e)),t=nt(null);it(o,(n,a,l)=>{t.value=n?n.snapshot():null,n&&l(n.subscribe(()=>t.value=n.snapshot()))},{immediate:!0});let i=O(()=>Me(o.value,t.value)),r=()=>z(o.value);return{items:i,activeKey:O(()=>t.value?.activeComment??null),setActive:(n,a)=>r().setActive(n,a),comment:(n,a,l)=>r().comment(n,a,l),reply:(n,a,l)=>r().reply(n,a,l),edit:(n,a)=>r().edit(n,a),remove:n=>r().remove(n),resolve:n=>r().resolve(n),reopen:n=>r().reopen(n),author:O(()=>t.value?.commentAuthor??null),setAuthor:n=>r().setAuthor(n),commentTarget:O(()=>{let n=t.value;return n?X(n.selection,n.shapes):null}),readOnly:O(()=>Z(t.value)),ready:O(()=>Be(t.value))}}import{computed as x,defineComponent as at,inject as ye,provide as lt,shallowRef as fe,toValue as st}from"vue";import{useReviewAuthors as ut,useTranslation as dt}from"@pptx-editor.dev/vue";var J=Symbol("pptxReviewPane"),$e=Symbol("pptxReviewItem"),pt=x(()=>null),Q=at({name:"PptxReviewItemScope",props:{item:{type:Object,required:!0}},setup(e,{slots:o}){return lt($e,x(()=>e.item)),()=>o.default?.()}});function b(){return ye($e,pt)}function ct(e){let o=ut();return x(()=>{let t=st(e);return t?o.value.find(i=>i.author===t):void 0})}var vt=x(()=>!0),mt={t:()=>{},cardClassName:()=>{},review:{items:x(()=>[]),activeKey:x(()=>null),...z(null),author:x(()=>null),commentTarget:x(()=>null),readOnly:vt,ready:x(()=>!1)},byId:x(()=>new Map),authors:x(()=>new Map),drafting:fe(!1),draftTarget:fe(null),beginDraft:()=>{},endDraft:()=>{},editing:fe(null),setEditing:()=>{},focusCard:()=>{}};function h(){return ye(J,mt)}function w(){let e=ye(J,null),{t:o}=dt();return(t,i)=>{let r=e?.t()?.(t);return r===void 0?o(t,i):i?r.replace(/\{(\w+)\}/g,(n,a)=>Object.hasOwn(i,a)?String(i[a]):n):r}}import{Fragment as xt,cloneVNode as Ct,defineComponent as V,isVNode as Pt}from"vue";import{Icon as _t}from"@pptx-editor.dev/vue";import{cloneVNode as qe,defineComponent as ft,mergeProps as yt}from"vue";function wt(e,o){return typeof o!="function"?e:typeof e!="function"?o:t=>{e(t),t.defaultPrevented||o(t)}}function Rt(e,o){let t=yt(e,o);for(let i of Object.keys(e))/^on[A-Z]/.test(i)?t[i]=wt(o[i],e[i]):i==="class"?t[i]=[e[i],o[i]].filter(Boolean).join(" "):i==="style"&&(t[i]={...e[i],...o[i]});return t}function Ge(e){return e==="Enter"||e===" "}function ht(e){return Ge(e.key)?(e.preventDefault(),e.stopPropagation(),!0):!1}function Ue(e){return e==="button"}function He(e,o){return e==="a"||o.href!=null}var W=ft({name:"ReviewActionSlot",props:{engineDisabled:{type:Boolean,required:!0},disabledReason:{type:String,default:null},slotProps:{type:Object,required:!0}},setup(e,{slots:o}){return()=>{let t=o.default?.()??[];if(t.length!==1)return null;let i=t[0];if(!i||typeof i!="object")return null;let r=i.props??{},n=Rt(e.slotProps,r);if(!e.engineDisabled){if(!Ue(i.type)){let a={onClick:l=>{typeof r.onClick=="function"&&r.onClick(l),!l.defaultPrevented&&typeof e.slotProps.onClick=="function"&&e.slotProps.onClick(l),He(i.type,r)&&l.preventDefault()},onKeydown:l=>{typeof r.onKeydown=="function"&&r.onKeydown(l),Ge(l.key)&&(!l.defaultPrevented&&typeof e.slotProps.onClick=="function"&&e.slotProps.onClick(l),He(i.type,r)&&l.preventDefault())}};n.onClick=a.onClick,n.onKeydown=a.onKeydown}return qe(i,n)}if(Ue(i.type))n.disabled=!0,delete n["aria-disabled"];else{delete n.disabled,n["aria-disabled"]=!0,n["data-disabled"]="",n.tabIndex=-1,n.href=void 0,n.role===void 0&&(n.role="button");let a=n.onKeydown;n.onKeydown=l=>{ht(l)||typeof a=="function"&&a(l)}}return e.disabledReason&&(n.title=e.disabledReason),n.onClick=a=>{a.preventDefault(),a.stopPropagation()},qe(i,n)}}});import{defineComponent as q,onMounted as bt,ref as M,useId as we,watch as Y}from"vue";import{Icon as Xe,usePptxEditor as Re}from"@pptx-editor.dev/vue";import{commentInitials as gt}from"@pptx-editor.dev/core/editor";import{jsx as c,jsxs as B}from"vue/jsx-runtime";var ee=(...e)=>e.filter(Boolean).join(" "),he=q({name:"PptxReviewCommentField",props:{id:{type:String,required:!0},value:{type:String,required:!0},label:{type:String,required:!0},placeholder:{type:String,default:void 0},describedBy:{type:String,required:!0},autoFocus:Boolean,onChange:{type:Function,required:!0},onPost:{type:Function,required:!0},onCancel:{type:Function,required:!0}},setup(e){let o=M(null);return bt(()=>{let t=o.value;!e.autoFocus||!t||(t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),()=>c("textarea",{ref:o,id:e.id,class:"pptx-review__input","data-comment-field":"",rows:1,value:e.value,maxlength:Se,"aria-label":e.label,"aria-describedby":e.describedBy,placeholder:e.placeholder??e.label,onInput:t=>e.onChange(t.target.value),onClick:t=>t.stopPropagation(),onKeydown:t=>{let i=Le(t);i&&(t.preventDefault(),t.stopPropagation(),i==="post"?e.onPost():e.onCancel())}})}});function be(e,o){return c("span",{id:e,class:"pptx-sr-only",children:o("comments.keyHint")})}function ge(e,o,t,i){let r=o?.rejection.reason==="errors.commentChanged";return B("span",{id:e,class:"pptx-review__refused pptx-review__notice",role:"status",children:[o?c("span",{children:ke(t,o)},o.serial):null,o&&r&&i!==void 0?c("span",{class:"pptx-review__current",children:t("comments.nowReads",{text:i})}):null]})}var xe=Object.assign(q({name:"ReviewAddComment",props:{className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean},setup(e,{slots:o}){let{beginDraft:t,drafting:i,review:r}=h(),n=w();return()=>{if(e.hidden)return null;let a=i.value||r.readOnly.value;return e.asChild?c("div",{class:"pptx-review__bar",children:c(W,{engineDisabled:a,disabledReason:null,slotProps:{class:ee("pptx-review__add",e.className),"data-review-add":"",onClick:t},children:{default:()=>o.default?.()}})}):c("div",{class:"pptx-review__bar",children:B("button",{type:"button",class:ee("pptx-review__add",e.className),"data-review-add":"",disabled:a,onClick:t,children:[c(Xe,{name:"add_comment"}),c("span",{children:o.default?.()??n("comments.new")})]})})}}}),{pptxReviewPart:"AddComment"}),Ce=Object.assign(q({name:"ReviewDraft",props:{className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean,nodeId:{type:String,default:void 0}},setup(e){let{drafting:o,draftTarget:t,endDraft:i,review:r,authors:n}=h(),a=Re(),l=w(),d=M(""),v=M(null),f=we();return Y(o,y=>{y||(v.value=null)}),()=>{if(e.hidden||!o.value)return null;let y=r.author.value??"",p=e.nodeId??t.value?.nodeId,P=e.nodeId?null:t.value??r.commentTarget.value,m=r.author.value===null,k=d.value.trim()==="",_=()=>{if(k||m||r.readOnly.value)return;let g=e.nodeId?void 0:t.value?.range,I=p?{nodeId:p,...g?{range:g}:{}}:void 0,s=H(a.value,()=>r.comment(d.value,void 0,I));s===null?(d.value="",v.value=null,i()):v.value=G(s,"draft",v.value)},N=()=>{d.value="",v.value=null,i()};return c("div",{class:ee("pptx-review__card",e.className),"data-draft":"",...L(y,n.value),style:j(y,n.value),children:B("form",{class:"pptx-review__compose",onSubmit:g=>{g.preventDefault(),_()},children:[P?c("span",{class:"pptx-review__chip",children:l("comments.pointsAt",{name:P.name})}):null,c(he,{id:f,value:d.value,label:l("comments.addComment"),describedBy:`${m?`${f}-blocked`:`${f}-hint`} ${f}-notice`,autoFocus:!0,onChange:g=>{d.value=g,v.value=null},onPost:_,onCancel:N}),be(`${f}-hint`,l),ge(`${f}-notice`,v.value,l),m?c("span",{id:`${f}-blocked`,class:"pptx-review__refused",children:l("comments.noAuthor")}):null,B("div",{class:"pptx-review__compose-actions",children:[c("button",{type:"button",class:"pptx-review__text-button",onClick:N,children:l("comments.cancel")}),c("button",{type:"submit",class:"pptx-review__submit",disabled:k||m,children:l("comments.text")})]})]})})}}}),{pptxReviewPart:"Draft"}),te=Object.assign(q({name:"ReviewReply",props:{className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean},setup(e,{slots:o}){let{review:t,authors:i}=h(),r=Re(),n=b(),a=w(),l=M(""),d=we(),v=null,f=M(null);Y(()=>n.value?.identity??"",()=>{l.value="",v=null,f.value=null}),Y(()=>n.value?.isActive??!1,p=>{p||(f.value=null)});let y=p=>{p?!v&&n.value&&(v=$(n.value)):v=null,l.value=p,f.value=null};return()=>{let p=n.value;if(e.hidden||!p||!p.isActive||p.resolved||t.readOnly.value)return null;let P=o.default?.();if(P)return P;let m=t.author.value??"",k=p.author||a("comments.unknownAuthor"),_=l.value.trim()==="",N=t.author.value===null,g=()=>{if(_||N)return;let I=H(r.value,()=>t.reply(v?ve(p,v):p,l.value));if(I===null){l.value="",v=null,f.value=null;return}I?.reason==="errors.commentChanged"&&(v=$(p)),f.value=G(I,"reply",f.value)};return B("form",{class:ee("pptx-review__reply-line",e.className),onSubmit:I=>{I.preventDefault(),g()},children:[m?c("span",{class:"pptx-review__avatar pptx-review__reply-avatar","aria-hidden":"true",...L(m,i.value),style:j(m,i.value),children:gt({initials:"",author:m})}):null,c(he,{id:d,value:l.value,label:a("comments.replyTo",{author:k}),placeholder:a("comments.replyText"),describedBy:`${N?`${d}-blocked`:`${d}-hint`} ${d}-notice`,onChange:y,onPost:g,onCancel:()=>{l.value?y(""):t.setActive(null)}}),be(`${d}-hint`,a),ge(`${d}-notice`,f.value,a),l.value?c("button",{type:"button",class:"pptx-review__text-button",onClick:()=>y(""),children:a("comments.cancel")}):null,c("button",{type:"submit",class:"pptx-review__send","aria-label":a("comments.replyTo",{author:k}),"data-pptx-tooltip":a("comments.reply"),disabled:_||N,children:c(Xe,{name:"send"})}),N?c("span",{id:`${d}-blocked`,class:"pptx-review__refused",children:a("comments.noAuthor")}):null]})}}}),{pptxReviewPart:"Reply"}),Ze=q({name:"PptxReviewEditBox",props:{item:{type:Object,required:!0}},setup(e){let{review:o,setEditing:t,focusCard:i}=h(),r=Re(),n=w(),a=M(e.item.text),l=we(),d=e.item.identity,v=()=>e.item.identity!==d,f=$(e.item),y=M(null);Y(v,m=>{m&&t(null)});let p=()=>{t(null),i(e.item.parentId??e.item.key)},P=()=>{if(v()||a.value.trim()==="")return;let m=H(r.value,()=>o.edit(ve(e.item,f),a.value));if(m===null)return p();m?.reason==="errors.commentChanged"&&(f=$(e.item)),y.value=G(m,"edit",y.value)};return()=>B("form",{class:"pptx-review__compose",onSubmit:m=>{m.preventDefault(),P()},children:[c(he,{id:l,value:a.value,label:n("comments.editText"),describedBy:`${l}-hint ${l}-notice`,autoFocus:!0,onChange:m=>{a.value=m,y.value=null},onPost:P,onCancel:p}),be(`${l}-hint`,n),ge(`${l}-notice`,y.value,n,e.item.text),B("div",{class:"pptx-review__compose-actions",children:[c("button",{type:"button",class:"pptx-review__text-button",onClick:p,children:n("comments.cancel")}),c("button",{type:"submit",class:"pptx-review__submit",disabled:a.value.trim()==="",children:n("comments.save")})]})]})}});import{jsx as u,jsxs as K}from"vue/jsx-runtime";function C(e,o){return Object.assign(e,{pptxReviewPart:o})}var E=(...e)=>e.filter(Boolean).join(" "),S={className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean};function F(e,o){let t=e?.length===1?e[0]:void 0;return t?Ct(t,o):null}function ne(e){let o={},t=[],i=r=>{for(let n of r??[]){if(!Pt(n))continue;if(n.type===xt){i(n.children);continue}let a=n.type.pptxReviewPart;a?o[a]=n:t.push(n)}};return i(e),t.length>0&&(o.__extra=t),o}var Pe=C(V({name:"ReviewEmpty",props:S,setup(e,{slots:o}){let t=w(),{review:i}=h();return()=>e.hidden?null:u("div",{class:E("pptx-review__empty",e.className),children:o.default?.()??[u("p",{class:"pptx-review__empty-title",children:t("comments.emptyTitle")}),i.readOnly.value?null:u("p",{class:"pptx-review__empty-body",children:t("comments.emptyBody")})]})}}),"Empty"),_e=C(V({name:"ReviewCard",props:S,setup(e,{slots:o}){let t=h(),i=b(),r=w();return()=>{let n=i.value;if(e.hidden||!n)return null;let a=()=>{n.isActive||t.review.setActive(n.key,{identity:n.identity})},l={class:E("pptx-review__card",t.cardClassName(),e.className),"data-comment-id":n.id,...n.isActive?{"data-active":"","aria-current":"true"}:{},...n.resolved?{"data-resolved":""}:{},...L(n.author,t.authors.value),style:j(n.author,t.authors.value),role:"group","aria-label":r("comments.thread",{author:n.author||r("comments.unknownAuthor")}),tabindex:0,onClick:d=>{je(d.target)||a()},onKeydown:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),a())}};return e.asChild?F(o.default?.(),l):u("div",{...l,children:At(o.default?.())})}}}),"Card");function At(e){let o=ne(e),t=(i,r)=>i in o?o[i]:r;return[K("div",{class:"pptx-review__head",children:[t("Avatar",u(oe,{})),K("div",{class:"pptx-review__meta",children:[t("Author",u(ie,{})),t("Time",u(re,{}))]}),K("div",{class:"pptx-review__actions",children:[t("Resolve",u(Ne,{})),t("Reopen",u(Ie,{})),t("Edit",u(se,{})),t("Delete",u(ue,{}))]})]}),t("Anchor",u(Ae,{})),t("Summary",u(ae,{})),t("Replies",u(Te,{})),t("Reply",u(te,{})),o.__extra]}var oe=C(V({name:"ReviewAvatar",props:S,setup(e,{slots:o}){let t=b();return()=>{let i=t.value;if(e.hidden||!i)return null;let r={class:E("pptx-review__avatar",e.className),"aria-hidden":!0};return e.asChild?F(o.default?.(),r):u("span",{...r,children:o.default?.()??i.initials})}}}),"Avatar"),ie=C(V({name:"ReviewAuthor",props:S,setup(e,{slots:o}){let t=b(),i=w();return()=>{let r=t.value;if(e.hidden||!r)return null;let n={class:E("pptx-review__author",e.className)};return e.asChild?F(o.default?.(),n):u("span",{...n,children:o.default?.()??(r.author||i("comments.unknownAuthor"))})}}}),"Author"),re=C(V({name:"ReviewTime",props:S,setup(e,{slots:o}){let t=b(),i=w();return()=>{let r=t.value;if(e.hidden||!r)return null;let n=Ke(r.date),a=r.resolved&&r.parentId===void 0?i("comments.resolved"):"";if(!n&&!a)return null;let l={class:E("pptx-review__time",e.className)};return e.asChild?F(o.default?.(),l):u("span",{...l,children:o.default?.()??[n?u("time",{datetime:r.date,children:n}):null,a?u("span",{class:"pptx-review__status",children:a}):null]})}}}),"Time"),Ae=C(V({name:"ReviewAnchor",props:S,setup(e,{slots:o}){let t=b(),i=w();return()=>{let r=t.value;if(e.hidden||!r||r.parentId!==void 0||r.anchorName===void 0)return null;let n={class:E("pptx-review__chip",e.className)};return e.asChild?F(o.default?.(),n):u("span",{...n,children:o.default?.()??i("comments.on",{name:r.anchorName})})}}}),"Anchor"),ae=C(V({name:"ReviewSummary",props:S,setup(e,{slots:o}){let t=b(),{editing:i}=h();return()=>{let r=t.value;if(e.hidden||!r)return null;if(i.value===r.identity)return u(Ze,{item:r},r.identity);let n={class:E("pptx-review__summary",e.className)};return e.asChild?F(o.default?.(),n):u("div",{...n,children:o.default?.()??u("p",{class:"pptx-review__text",children:r.text})})}}}),"Summary"),Te=C(V({name:"ReviewReplies",props:S,setup(e){let{byId:o,authors:t}=h(),i=b(),r=w();return()=>{let n=i.value;if(e.hidden||!n||n.replyIds.length===0)return null;let a=n.replyIds.map(l=>o.value.get(l)).filter(l=>l!==void 0);return a.length===0?null:u("ol",{class:E("pptx-review__replies",e.className),"aria-label":r("comments.replies",{author:n.author||r("comments.unknownAuthor")}),children:a.map(l=>u(Q,{item:l,children:{default:()=>K("li",{class:"pptx-review__reply","data-reply-id":l.id,...L(l.author,t.value),style:j(l.author,t.value),children:[K("div",{class:"pptx-review__head",children:[u(oe,{}),K("div",{class:"pptx-review__meta",children:[u(ie,{}),u(re,{})]}),K("div",{class:"pptx-review__actions",children:[u(se,{}),u(ue,{})]})]}),u(ae,{})]})}},l.identity))})}}}),"Replies");function le(e){return C(V({name:`Review${e.part}`,props:{...S,icon:{type:[Object,String],default:void 0}},setup(o,{slots:t}){let i=h(),r=b(),n=w();return()=>{let a=r.value;if(o.hidden||!a||i.review.readOnly.value||!e.shows(a))return null;let l=n(e.label,{author:a.author||n("comments.unknownAuthor")}),d={type:"button",class:E("pptx-review__action",o.className),"data-action":e.part.toLowerCase(),"aria-label":l,"data-pptx-tooltip":l,onClick:v=>{v.stopPropagation(),e.run(i,a)}};return o.asChild?u(W,{engineDisabled:!1,disabledReason:null,slotProps:d,children:{default:()=>t.default?.()}}):u("button",{...d,children:o.icon??t.default?.()??u(_t,{name:e.icon})})}}}),e.part)}var Ne=le({part:"Resolve",icon:"check",label:"comments.resolveOf",shows:e=>e.parentId===void 0&&!e.resolved&&e.resolvable,run:({review:e},o)=>e.resolve(o)}),Ie=le({part:"Reopen",icon:"refresh",label:"comments.reopenOf",shows:e=>e.parentId===void 0&&e.resolved&&e.resolvable,run:({review:e},o)=>e.reopen(o)}),se=le({part:"Edit",icon:"edit",label:"comments.editOf",shows:e=>e.editable,run:({setEditing:e},o)=>e(o.identity)}),ue=le({part:"Delete",icon:"delete",label:"comments.deleteOf",shows:()=>!0,run:({review:e,focusCard:o},t)=>{e.remove(t)&&o(t.parentId??t.key)}});import{jsx as T,jsxs as Qe}from"vue/jsx-runtime";var Ee=(...e)=>e.filter(Boolean).join(" ");function Ot(e,o,t){let i=ne(o);return e.map(r=>T(Q,{item:r,children:{default:()=>T("li",{class:"pptx-review__slot",children:t?t({item:r}):"Card"in i?i.Card:T(_e,{children:{default:()=>Object.entries(i).filter(([n])=>n!=="Empty").flatMap(([,n])=>n)}})})}},r.identity))}var Ye=C(We({name:"ReviewList",props:{className:{type:String,default:void 0},hidden:Boolean},slots:Object,setup(e,{slots:o}){let{review:t}=h(),i=w();return()=>{if(e.hidden)return null;let r=t.items.value.filter(a=>a.parentId===void 0),n=o.default?.();if(r.length===0){if(o.card)return null;let a=ne(n);return"Empty"in a?a.Empty:T(Pe,{})}return T("ul",{class:Ee("pptx-review__list",e.className),"aria-label":i("comments.label"),children:Ot(r,n,o.card)})}}}),"List"),Mt=new Set(["List","AddComment","Draft"]);function Bt(e){let o={},t=[],i=r=>{for(let n of r??[]){if(!Nt(n))continue;if(n.type===Tt){i(n.children);continue}let a=n.type.pptxReviewPart;a&&Mt.has(a)?o[a]=n:t.push(n)}};return i(e),{parts:o,template:t}}var Kt={className:{type:String,default:void 0},hidden:Boolean,t:{type:Function,default:void 0},card:{type:Object,default:void 0},preset:{type:Boolean,default:!0},filter:{type:Function,default:void 0}},Lt=We({name:"PptxEditorReview",props:Kt,slots:Object,setup(e,{slots:o}){let t=me(),i=w(),r=s=>e.t?.(s)??i(s),n=Ve(s=>s.status==="ready"&&s.comments==null),a=Ve(s=>Et(s)?.id??""),l=ze(!1),d=Je(null),v=Ve(s=>s.shapes),f=de(()=>Oe(d.value,v.value));ce(f,s=>{s===null&&(d.value=null)});let y=Je(null),p=ze(null),P=kt(),m=de(()=>{let s=t.items.value,A=e.filter;if(!A)return s;let D=new Set(s.filter(R=>R.parentId===void 0&&A(R)).map(R=>R.id));return s.filter(R=>D.has(R.parentId??R.id))}),k={...t,items:m};ce([a,t.readOnly],()=>{l.value=!1,y.value=null});let _=null;ce([P,n,()=>e.hidden],([s,A,D])=>{_?.(),_=null,!(!s||A||D)&&(_=St(s,()=>{let R=s.snapshot();Z(R)||(d.value=X(R.selection,R.shapes),l.value=!0,pe(()=>requestAnimationFrame(()=>p.value?.querySelector("[data-draft] [data-comment-field]")?.focus())))}))},{immediate:!0}),It(()=>_?.());let N=s=>{pe(()=>requestAnimationFrame(()=>{let A=p.value;(A?.querySelector(`[data-comment-id="${CSS.escape(s)}"]`)??A?.querySelector("[data-review-add]"))?.focus()}))};ce(t.activeKey,s=>{s&&pe(()=>p.value?.querySelector(`[data-comment-id="${CSS.escape(s)}"]`)?.scrollIntoView?.({block:"nearest"}))});let g=Dt(),I={t:()=>e.t,cardClassName:()=>e.card?.className,review:k,byId:de(()=>new Map(m.value.map(s=>[s.id,s]))),authors:de(()=>De(g.value)),drafting:l,draftTarget:f,beginDraft:()=>{d.value=null,l.value=!0},endDraft:()=>{l.value=!1,d.value=null,pe(()=>requestAnimationFrame(()=>p.value?.querySelector("[data-review-add]")?.focus()))},editing:y,setEditing:s=>y.value=s,focusCard:N};return Vt(J,I),()=>{if(e.hidden)return null;if(n.value)return Qe("div",{class:Ee("pptx-empty",e.className),children:[T("p",{class:"pptx-empty__title",children:r("panel.comments.emptyTitle")}),T("p",{class:"pptx-empty__body",children:r("panel.comments.emptyBody")})]});let{parts:s,template:A}=Bt(o.default?.()),D=(U,et)=>U in s?s[U]:e.preset?et():null,R=s.List;return Qe("section",{ref:p,class:Ee("pptx-review",e.className),"aria-label":r("panel.tabs.comments"),"data-count":m.value.filter(U=>U.parentId===void 0).length,children:[D("AddComment",()=>T(xe,{})),D("Draft",()=>T(Ce,{})),R||(e.preset?T(Ye,{children:{default:()=>A,...o.card?{card:o.card}:{}}}):A)]})}}}),jt=Object.assign(Lt,{List:Ye,AddComment:xe,Draft:Ce,Empty:Pe,Card:_e,Avatar:oe,Author:ie,Time:re,Anchor:Ae,Summary:ae,Resolve:Ne,Reopen:Ie,Edit:se,Delete:ue,Replies:Te,Reply:te});export{jt as PptxEditorReview,tt as reviewModule,me as useReview,ct as useReviewAuthor,b as useReviewItem,Fe as useReviewOf};
6
+ import{a as Se,b as H,c as G,d as ke,e as $,f as ve,g as De,h as L,i as j,j as X,k as Oe,l as Me,m as Z,n as Be,o as z,p as Ke,q as Le,r as je}from"./chunk-WVMCUB34.js";import{b as tt}from"./chunk-NXOSE66U.js";import"./chunk-HCD7IVOL.js";import{Fragment as Tt,computed as de,defineComponent as We,isVNode as Nt,nextTick as pe,onBeforeUnmount as It,provide as Vt,ref as ze,shallowRef as Je,watch as ce}from"vue";import{currentSlideSummary as Et,registerCommentDraft as St}from"@pptx-editor.dev/core/editor";import{useEditorState as Ve,usePptxEditor as kt,useReviewAuthors as Dt}from"@pptx-editor.dev/vue";import{computed as O,shallowRef as nt,toValue as ot,watch as it}from"vue";import{usePptxEditor as rt}from"@pptx-editor.dev/vue";function me(){return Fe(rt())}function Fe(e){let o=O(()=>ot(e)),t=nt(null);it(o,(n,a,l)=>{t.value=n?n.snapshot():null,n&&l(n.subscribe(()=>t.value=n.snapshot()))},{immediate:!0});let i=O(()=>Me(o.value,t.value)),r=()=>z(o.value);return{items:i,activeKey:O(()=>t.value?.activeComment??null),setActive:(n,a)=>r().setActive(n,a),comment:(n,a,l)=>r().comment(n,a,l),reply:(n,a,l)=>r().reply(n,a,l),edit:(n,a)=>r().edit(n,a),remove:n=>r().remove(n),resolve:n=>r().resolve(n),reopen:n=>r().reopen(n),author:O(()=>t.value?.commentAuthor??null),setAuthor:n=>r().setAuthor(n),commentTarget:O(()=>{let n=t.value;return n?X(n.selection,n.shapes):null}),readOnly:O(()=>Z(t.value)),ready:O(()=>Be(t.value))}}import{computed as x,defineComponent as at,inject as ye,provide as lt,shallowRef as fe,toValue as st}from"vue";import{useReviewAuthors as ut,useTranslation as dt}from"@pptx-editor.dev/vue";var J=Symbol("pptxReviewPane"),$e=Symbol("pptxReviewItem"),pt=x(()=>null),Q=at({name:"PptxReviewItemScope",props:{item:{type:Object,required:!0}},setup(e,{slots:o}){return lt($e,x(()=>e.item)),()=>o.default?.()}});function b(){return ye($e,pt)}function ct(e){let o=ut();return x(()=>{let t=st(e);return t?o.value.find(i=>i.author===t):void 0})}var vt=x(()=>!0),mt={t:()=>{},cardClassName:()=>{},review:{items:x(()=>[]),activeKey:x(()=>null),...z(null),author:x(()=>null),commentTarget:x(()=>null),readOnly:vt,ready:x(()=>!1)},byId:x(()=>new Map),authors:x(()=>new Map),drafting:fe(!1),draftTarget:fe(null),beginDraft:()=>{},endDraft:()=>{},editing:fe(null),setEditing:()=>{},focusCard:()=>{}};function h(){return ye(J,mt)}function w(){let e=ye(J,null),{t:o}=dt();return(t,i)=>{let r=e?.t()?.(t);return r===void 0?o(t,i):i?r.replace(/\{(\w+)\}/g,(n,a)=>Object.hasOwn(i,a)?String(i[a]):n):r}}import{Fragment as xt,cloneVNode as Ct,defineComponent as V,isVNode as Pt}from"vue";import{Icon as _t}from"@pptx-editor.dev/vue";import{cloneVNode as qe,defineComponent as ft,mergeProps as yt}from"vue";function wt(e,o){return typeof o!="function"?e:typeof e!="function"?o:t=>{e(t),t.defaultPrevented||o(t)}}function Rt(e,o){let t=yt(e,o);for(let i of Object.keys(e))/^on[A-Z]/.test(i)?t[i]=wt(o[i],e[i]):i==="class"?t[i]=[e[i],o[i]].filter(Boolean).join(" "):i==="style"&&(t[i]={...e[i],...o[i]});return t}function Ge(e){return e==="Enter"||e===" "}function ht(e){return Ge(e.key)?(e.preventDefault(),e.stopPropagation(),!0):!1}function Ue(e){return e==="button"}function He(e,o){return e==="a"||o.href!=null}var W=ft({name:"ReviewActionSlot",props:{engineDisabled:{type:Boolean,required:!0},disabledReason:{type:String,default:null},slotProps:{type:Object,required:!0}},setup(e,{slots:o}){return()=>{let t=o.default?.()??[];if(t.length!==1)return null;let i=t[0];if(!i||typeof i!="object")return null;let r=i.props??{},n=Rt(e.slotProps,r);if(!e.engineDisabled){if(!Ue(i.type)){let a={onClick:l=>{typeof r.onClick=="function"&&r.onClick(l),!l.defaultPrevented&&typeof e.slotProps.onClick=="function"&&e.slotProps.onClick(l),He(i.type,r)&&l.preventDefault()},onKeydown:l=>{typeof r.onKeydown=="function"&&r.onKeydown(l),Ge(l.key)&&(!l.defaultPrevented&&typeof e.slotProps.onClick=="function"&&e.slotProps.onClick(l),He(i.type,r)&&l.preventDefault())}};n.onClick=a.onClick,n.onKeydown=a.onKeydown}return qe(i,n)}if(Ue(i.type))n.disabled=!0,delete n["aria-disabled"];else{delete n.disabled,n["aria-disabled"]=!0,n["data-disabled"]="",n.tabIndex=-1,n.href=void 0,n.role===void 0&&(n.role="button");let a=n.onKeydown;n.onKeydown=l=>{ht(l)||typeof a=="function"&&a(l)}}return e.disabledReason&&(n.title=e.disabledReason),n.onClick=a=>{a.preventDefault(),a.stopPropagation()},qe(i,n)}}});import{defineComponent as q,onMounted as bt,ref as M,useId as we,watch as Y}from"vue";import{Icon as Xe,usePptxEditor as Re}from"@pptx-editor.dev/vue";import{commentInitials as gt}from"@pptx-editor.dev/core/editor";import{jsx as c,jsxs as B}from"vue/jsx-runtime";var ee=(...e)=>e.filter(Boolean).join(" "),he=q({name:"PptxReviewCommentField",props:{id:{type:String,required:!0},value:{type:String,required:!0},label:{type:String,required:!0},placeholder:{type:String,default:void 0},describedBy:{type:String,required:!0},autoFocus:Boolean,onChange:{type:Function,required:!0},onPost:{type:Function,required:!0},onCancel:{type:Function,required:!0}},setup(e){let o=M(null);return bt(()=>{let t=o.value;!e.autoFocus||!t||(t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),()=>c("textarea",{ref:o,id:e.id,class:"pptx-review__input","data-comment-field":"",rows:1,value:e.value,maxlength:Se,"aria-label":e.label,"aria-describedby":e.describedBy,placeholder:e.placeholder??e.label,onInput:t=>e.onChange(t.target.value),onClick:t=>t.stopPropagation(),onKeydown:t=>{let i=Le(t);i&&(t.preventDefault(),t.stopPropagation(),i==="post"?e.onPost():e.onCancel())}})}});function be(e,o){return c("span",{id:e,class:"pptx-sr-only",children:o("comments.keyHint")})}function ge(e,o,t,i){let r=o?.rejection.reason==="errors.commentChanged";return B("span",{id:e,class:"pptx-review__refused pptx-review__notice",role:"status",children:[o?c("span",{children:ke(t,o)},o.serial):null,o&&r&&i!==void 0?c("span",{class:"pptx-review__current",children:t("comments.nowReads",{text:i})}):null]})}var xe=Object.assign(q({name:"ReviewAddComment",props:{className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean},setup(e,{slots:o}){let{beginDraft:t,drafting:i,review:r}=h(),n=w();return()=>{if(e.hidden)return null;let a=i.value||r.readOnly.value;return e.asChild?c("div",{class:"pptx-review__bar",children:c(W,{engineDisabled:a,disabledReason:null,slotProps:{class:ee("pptx-review__add",e.className),"data-review-add":"",onClick:t},children:{default:()=>o.default?.()}})}):c("div",{class:"pptx-review__bar",children:B("button",{type:"button",class:ee("pptx-review__add",e.className),"data-review-add":"",disabled:a,onClick:t,children:[c(Xe,{name:"add_comment"}),c("span",{children:o.default?.()??n("comments.new")})]})})}}}),{pptxReviewPart:"AddComment"}),Ce=Object.assign(q({name:"ReviewDraft",props:{className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean,nodeId:{type:String,default:void 0}},setup(e){let{drafting:o,draftTarget:t,endDraft:i,review:r,authors:n}=h(),a=Re(),l=w(),d=M(""),v=M(null),f=we();return Y(o,y=>{y||(v.value=null)}),()=>{if(e.hidden||!o.value)return null;let y=r.author.value??"",p=e.nodeId??t.value?.nodeId,P=e.nodeId?null:t.value??r.commentTarget.value,m=r.author.value===null,k=d.value.trim()==="",_=()=>{if(k||m||r.readOnly.value)return;let g=e.nodeId?void 0:t.value?.range,I=p?{nodeId:p,...g?{range:g}:{}}:void 0,s=H(a.value,()=>r.comment(d.value,void 0,I));s===null?(d.value="",v.value=null,i()):v.value=G(s,"draft",v.value)},N=()=>{d.value="",v.value=null,i()};return c("div",{class:ee("pptx-review__card",e.className),"data-draft":"",...L(y,n.value),style:j(y,n.value),children:B("form",{class:"pptx-review__compose",onSubmit:g=>{g.preventDefault(),_()},children:[P?c("span",{class:"pptx-review__chip",children:l("comments.pointsAt",{name:P.name})}):null,c(he,{id:f,value:d.value,label:l("comments.addComment"),describedBy:`${m?`${f}-blocked`:`${f}-hint`} ${f}-notice`,autoFocus:!0,onChange:g=>{d.value=g,v.value=null},onPost:_,onCancel:N}),be(`${f}-hint`,l),ge(`${f}-notice`,v.value,l),m?c("span",{id:`${f}-blocked`,class:"pptx-review__refused",children:l("comments.noAuthor")}):null,B("div",{class:"pptx-review__compose-actions",children:[c("button",{type:"button",class:"pptx-review__text-button",onClick:N,children:l("comments.cancel")}),c("button",{type:"submit",class:"pptx-review__submit",disabled:k||m,children:l("comments.text")})]})]})})}}}),{pptxReviewPart:"Draft"}),te=Object.assign(q({name:"ReviewReply",props:{className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean},setup(e,{slots:o}){let{review:t,authors:i}=h(),r=Re(),n=b(),a=w(),l=M(""),d=we(),v=null,f=M(null);Y(()=>n.value?.identity??"",()=>{l.value="",v=null,f.value=null}),Y(()=>n.value?.isActive??!1,p=>{p||(f.value=null)});let y=p=>{p?!v&&n.value&&(v=$(n.value)):v=null,l.value=p,f.value=null};return()=>{let p=n.value;if(e.hidden||!p||!p.isActive||p.resolved||t.readOnly.value)return null;let P=o.default?.();if(P)return P;let m=t.author.value??"",k=p.author||a("comments.unknownAuthor"),_=l.value.trim()==="",N=t.author.value===null,g=()=>{if(_||N)return;let I=H(r.value,()=>t.reply(v?ve(p,v):p,l.value));if(I===null){l.value="",v=null,f.value=null;return}I?.reason==="errors.commentChanged"&&(v=$(p)),f.value=G(I,"reply",f.value)};return B("form",{class:ee("pptx-review__reply-line",e.className),onSubmit:I=>{I.preventDefault(),g()},children:[m?c("span",{class:"pptx-review__avatar pptx-review__reply-avatar","aria-hidden":"true",...L(m,i.value),style:j(m,i.value),children:gt({initials:"",author:m})}):null,c(he,{id:d,value:l.value,label:a("comments.replyTo",{author:k}),placeholder:a("comments.replyText"),describedBy:`${N?`${d}-blocked`:`${d}-hint`} ${d}-notice`,onChange:y,onPost:g,onCancel:()=>{l.value?y(""):t.setActive(null)}}),be(`${d}-hint`,a),ge(`${d}-notice`,f.value,a),l.value?c("button",{type:"button",class:"pptx-review__text-button",onClick:()=>y(""),children:a("comments.cancel")}):null,c("button",{type:"submit",class:"pptx-review__send","aria-label":a("comments.replyTo",{author:k}),"data-pptx-tooltip":a("comments.reply"),disabled:_||N,children:c(Xe,{name:"send"})}),N?c("span",{id:`${d}-blocked`,class:"pptx-review__refused",children:a("comments.noAuthor")}):null]})}}}),{pptxReviewPart:"Reply"}),Ze=q({name:"PptxReviewEditBox",props:{item:{type:Object,required:!0}},setup(e){let{review:o,setEditing:t,focusCard:i}=h(),r=Re(),n=w(),a=M(e.item.text),l=we(),d=e.item.identity,v=()=>e.item.identity!==d,f=$(e.item),y=M(null);Y(v,m=>{m&&t(null)});let p=()=>{t(null),i(e.item.parentId??e.item.key)},P=()=>{if(v()||a.value.trim()==="")return;let m=H(r.value,()=>o.edit(ve(e.item,f),a.value));if(m===null)return p();m?.reason==="errors.commentChanged"&&(f=$(e.item)),y.value=G(m,"edit",y.value)};return()=>B("form",{class:"pptx-review__compose",onSubmit:m=>{m.preventDefault(),P()},children:[c(he,{id:l,value:a.value,label:n("comments.editText"),describedBy:`${l}-hint ${l}-notice`,autoFocus:!0,onChange:m=>{a.value=m,y.value=null},onPost:P,onCancel:p}),be(`${l}-hint`,n),ge(`${l}-notice`,y.value,n,e.item.text),B("div",{class:"pptx-review__compose-actions",children:[c("button",{type:"button",class:"pptx-review__text-button",onClick:p,children:n("comments.cancel")}),c("button",{type:"submit",class:"pptx-review__submit",disabled:a.value.trim()==="",children:n("comments.save")})]})]})}});import{jsx as u,jsxs as K}from"vue/jsx-runtime";function C(e,o){return Object.assign(e,{pptxReviewPart:o})}var E=(...e)=>e.filter(Boolean).join(" "),S={className:{type:String,default:void 0},asChild:Boolean,hidden:Boolean};function F(e,o){let t=e?.length===1?e[0]:void 0;return t?Ct(t,o):null}function ne(e){let o={},t=[],i=r=>{for(let n of r??[]){if(!Pt(n))continue;if(n.type===xt){i(n.children);continue}let a=n.type.pptxReviewPart;a?o[a]=n:t.push(n)}};return i(e),t.length>0&&(o.__extra=t),o}var Pe=C(V({name:"ReviewEmpty",props:S,setup(e,{slots:o}){let t=w(),{review:i}=h();return()=>e.hidden?null:u("div",{class:E("pptx-review__empty",e.className),children:o.default?.()??[u("p",{class:"pptx-review__empty-title",children:t("comments.emptyTitle")}),i.readOnly.value?null:u("p",{class:"pptx-review__empty-body",children:t("comments.emptyBody")})]})}}),"Empty"),_e=C(V({name:"ReviewCard",props:S,setup(e,{slots:o}){let t=h(),i=b(),r=w();return()=>{let n=i.value;if(e.hidden||!n)return null;let a=()=>{n.isActive||t.review.setActive(n.key,{identity:n.identity})},l={class:E("pptx-review__card",t.cardClassName(),e.className),"data-comment-id":n.id,...n.isActive?{"data-active":"","aria-current":"true"}:{},...n.resolved?{"data-resolved":""}:{},...L(n.author,t.authors.value),style:j(n.author,t.authors.value),role:"group","aria-label":r("comments.thread",{author:n.author||r("comments.unknownAuthor")}),tabindex:0,onClick:d=>{je(d.target)||a()},onKeydown:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),a())}};return e.asChild?F(o.default?.(),l):u("div",{...l,children:At(o.default?.())})}}}),"Card");function At(e){let o=ne(e),t=(i,r)=>i in o?o[i]:r;return[K("div",{class:"pptx-review__head",children:[t("Avatar",u(oe,{})),K("div",{class:"pptx-review__meta",children:[t("Author",u(ie,{})),t("Time",u(re,{}))]}),K("div",{class:"pptx-review__actions",children:[t("Resolve",u(Ne,{})),t("Reopen",u(Ie,{})),t("Edit",u(se,{})),t("Delete",u(ue,{}))]})]}),t("Anchor",u(Ae,{})),t("Summary",u(ae,{})),t("Replies",u(Te,{})),t("Reply",u(te,{})),o.__extra]}var oe=C(V({name:"ReviewAvatar",props:S,setup(e,{slots:o}){let t=b();return()=>{let i=t.value;if(e.hidden||!i)return null;let r={class:E("pptx-review__avatar",e.className),"aria-hidden":!0};return e.asChild?F(o.default?.(),r):u("span",{...r,children:o.default?.()??i.initials})}}}),"Avatar"),ie=C(V({name:"ReviewAuthor",props:S,setup(e,{slots:o}){let t=b(),i=w();return()=>{let r=t.value;if(e.hidden||!r)return null;let n={class:E("pptx-review__author",e.className)};return e.asChild?F(o.default?.(),n):u("span",{...n,children:o.default?.()??(r.author||i("comments.unknownAuthor"))})}}}),"Author"),re=C(V({name:"ReviewTime",props:S,setup(e,{slots:o}){let t=b(),i=w();return()=>{let r=t.value;if(e.hidden||!r)return null;let n=Ke(r.date),a=r.resolved&&r.parentId===void 0?i("comments.resolved"):"";if(!n&&!a)return null;let l={class:E("pptx-review__time",e.className)};return e.asChild?F(o.default?.(),l):u("span",{...l,children:o.default?.()??[n?u("time",{datetime:r.date,children:n}):null,a?u("span",{class:"pptx-review__status",children:a}):null]})}}}),"Time"),Ae=C(V({name:"ReviewAnchor",props:S,setup(e,{slots:o}){let t=b(),i=w();return()=>{let r=t.value;if(e.hidden||!r||r.parentId!==void 0||r.anchorName===void 0)return null;let n={class:E("pptx-review__chip",e.className)};return e.asChild?F(o.default?.(),n):u("span",{...n,children:o.default?.()??i("comments.on",{name:r.anchorName})})}}}),"Anchor"),ae=C(V({name:"ReviewSummary",props:S,setup(e,{slots:o}){let t=b(),{editing:i}=h();return()=>{let r=t.value;if(e.hidden||!r)return null;if(i.value===r.identity)return u(Ze,{item:r},r.identity);let n={class:E("pptx-review__summary",e.className)};return e.asChild?F(o.default?.(),n):u("div",{...n,children:o.default?.()??u("p",{class:"pptx-review__text",children:r.text})})}}}),"Summary"),Te=C(V({name:"ReviewReplies",props:S,setup(e){let{byId:o,authors:t}=h(),i=b(),r=w();return()=>{let n=i.value;if(e.hidden||!n||n.replyIds.length===0)return null;let a=n.replyIds.map(l=>o.value.get(l)).filter(l=>l!==void 0);return a.length===0?null:u("ol",{class:E("pptx-review__replies",e.className),"aria-label":r("comments.replies",{author:n.author||r("comments.unknownAuthor")}),children:a.map(l=>u(Q,{item:l,children:{default:()=>K("li",{class:"pptx-review__reply","data-reply-id":l.id,...L(l.author,t.value),style:j(l.author,t.value),children:[K("div",{class:"pptx-review__head",children:[u(oe,{}),K("div",{class:"pptx-review__meta",children:[u(ie,{}),u(re,{})]}),K("div",{class:"pptx-review__actions",children:[u(se,{}),u(ue,{})]})]}),u(ae,{})]})}},l.identity))})}}}),"Replies");function le(e){return C(V({name:`Review${e.part}`,props:{...S,icon:{type:[Object,String],default:void 0}},setup(o,{slots:t}){let i=h(),r=b(),n=w();return()=>{let a=r.value;if(o.hidden||!a||i.review.readOnly.value||!e.shows(a))return null;let l=n(e.label,{author:a.author||n("comments.unknownAuthor")}),d={type:"button",class:E("pptx-review__action",o.className),"data-action":e.part.toLowerCase(),"aria-label":l,"data-pptx-tooltip":l,onClick:v=>{v.stopPropagation(),e.run(i,a)}};return o.asChild?u(W,{engineDisabled:!1,disabledReason:null,slotProps:d,children:{default:()=>t.default?.()}}):u("button",{...d,children:o.icon??t.default?.()??u(_t,{name:e.icon})})}}}),e.part)}var Ne=le({part:"Resolve",icon:"check",label:"comments.resolveOf",shows:e=>e.parentId===void 0&&!e.resolved&&e.resolvable,run:({review:e},o)=>e.resolve(o)}),Ie=le({part:"Reopen",icon:"refresh",label:"comments.reopenOf",shows:e=>e.parentId===void 0&&e.resolved&&e.resolvable,run:({review:e},o)=>e.reopen(o)}),se=le({part:"Edit",icon:"edit",label:"comments.editOf",shows:e=>e.editable,run:({setEditing:e},o)=>e(o.identity)}),ue=le({part:"Delete",icon:"delete",label:"comments.deleteOf",shows:()=>!0,run:({review:e,focusCard:o},t)=>{e.remove(t)&&o(t.parentId??t.key)}});import{jsx as T,jsxs as Qe}from"vue/jsx-runtime";var Ee=(...e)=>e.filter(Boolean).join(" ");function Ot(e,o,t){let i=ne(o);return e.map(r=>T(Q,{item:r,children:{default:()=>T("li",{class:"pptx-review__slot",children:t?t({item:r}):"Card"in i?i.Card:T(_e,{children:{default:()=>Object.entries(i).filter(([n])=>n!=="Empty").flatMap(([,n])=>n)}})})}},r.identity))}var Ye=C(We({name:"ReviewList",props:{className:{type:String,default:void 0},hidden:Boolean},slots:Object,setup(e,{slots:o}){let{review:t}=h(),i=w();return()=>{if(e.hidden)return null;let r=t.items.value.filter(a=>a.parentId===void 0),n=o.default?.();if(r.length===0){if(o.card)return null;let a=ne(n);return"Empty"in a?a.Empty:T(Pe,{})}return T("ul",{class:Ee("pptx-review__list",e.className),"aria-label":i("comments.label"),children:Ot(r,n,o.card)})}}}),"List"),Mt=new Set(["List","AddComment","Draft"]);function Bt(e){let o={},t=[],i=r=>{for(let n of r??[]){if(!Nt(n))continue;if(n.type===Tt){i(n.children);continue}let a=n.type.pptxReviewPart;a&&Mt.has(a)?o[a]=n:t.push(n)}};return i(e),{parts:o,template:t}}var Kt={className:{type:String,default:void 0},hidden:Boolean,t:{type:Function,default:void 0},card:{type:Object,default:void 0},preset:{type:Boolean,default:!0},filter:{type:Function,default:void 0}},Lt=We({name:"PptxEditorReview",props:Kt,slots:Object,setup(e,{slots:o}){let t=me(),i=w(),r=s=>e.t?.(s)??i(s),n=Ve(s=>s.status==="ready"&&s.comments==null),a=Ve(s=>Et(s)?.id??""),l=ze(!1),d=Je(null),v=Ve(s=>s.shapes),f=de(()=>Oe(d.value,v.value));ce(f,s=>{s===null&&(d.value=null)});let y=Je(null),p=ze(null),P=kt(),m=de(()=>{let s=t.items.value,A=e.filter;if(!A)return s;let D=new Set(s.filter(R=>R.parentId===void 0&&A(R)).map(R=>R.id));return s.filter(R=>D.has(R.parentId??R.id))}),k={...t,items:m};ce([a,t.readOnly],()=>{l.value=!1,y.value=null});let _=null;ce([P,n,()=>e.hidden],([s,A,D])=>{_?.(),_=null,!(!s||A||D)&&(_=St(s,()=>{let R=s.snapshot();Z(R)||(d.value=X(R.selection,R.shapes),l.value=!0,pe(()=>requestAnimationFrame(()=>p.value?.querySelector("[data-draft] [data-comment-field]")?.focus())))}))},{immediate:!0}),It(()=>_?.());let N=s=>{pe(()=>requestAnimationFrame(()=>{let A=p.value;(A?.querySelector(`[data-comment-id="${CSS.escape(s)}"]`)??A?.querySelector("[data-review-add]"))?.focus()}))};ce(t.activeKey,s=>{s&&pe(()=>p.value?.querySelector(`[data-comment-id="${CSS.escape(s)}"]`)?.scrollIntoView?.({block:"nearest"}))});let g=Dt(),I={t:()=>e.t,cardClassName:()=>e.card?.className,review:k,byId:de(()=>new Map(m.value.map(s=>[s.id,s]))),authors:de(()=>De(g.value)),drafting:l,draftTarget:f,beginDraft:()=>{d.value=null,l.value=!0},endDraft:()=>{l.value=!1,d.value=null,pe(()=>requestAnimationFrame(()=>p.value?.querySelector("[data-review-add]")?.focus()))},editing:y,setEditing:s=>y.value=s,focusCard:N};return Vt(J,I),()=>{if(e.hidden)return null;if(n.value)return Qe("div",{class:Ee("pptx-empty",e.className),children:[T("p",{class:"pptx-empty__title",children:r("panel.comments.emptyTitle")}),T("p",{class:"pptx-empty__body",children:r("panel.comments.emptyBody")})]});let{parts:s,template:A}=Bt(o.default?.()),D=(U,et)=>U in s?s[U]:e.preset?et():null,R=s.List;return Qe("section",{ref:p,class:Ee("pptx-review",e.className),"aria-label":r("panel.tabs.comments"),"data-count":m.value.filter(U=>U.parentId===void 0).length,children:[D("AddComment",()=>T(xe,{})),D("Draft",()=>T(Ce,{})),R||(e.preset?T(Ye,{children:{default:()=>A,...o.card?{card:o.card}:{}}}):A)]})}}}),jt=Object.assign(Lt,{List:Ye,AddComment:xe,Draft:Ce,Empty:Pe,Card:_e,Avatar:oe,Author:ie,Time:re,Anchor:Ae,Summary:ae,Resolve:Ne,Reopen:Ie,Edit:se,Delete:ue,Replies:Te,Reply:te});export{jt as PptxEditorReview,tt as reviewModule,me as useReview,ct as useReviewAuthor,b as useReviewItem,Fe as useReviewOf};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pptx-editor.dev/pro",
3
- "version": "0.5.1-canary.20261117032847.sha-31be6ab",
3
+ "version": "0.6.0",
4
4
  "description": "Commercial capabilities for PPTX Editor, as EditorModules: the review module with the comments pane and review hooks for React and Vue, realtime collaboration, and advanced drawing rendering (charts, glow, inner shadow, reflection, and soft edge).",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -37,9 +37,9 @@
37
37
  "api:check": "node ../../scripts/api-extractor.mjs --package @pptx-editor.dev/pro"
38
38
  },
39
39
  "peerDependencies": {
40
- "@pptx-editor.dev/core": "0.5.1-canary.20261117032847.sha-31be6ab",
41
- "@pptx-editor.dev/react": "0.5.1-canary.20261117032847.sha-31be6ab",
42
- "@pptx-editor.dev/vue": "0.5.1-canary.20261117032847.sha-31be6ab",
40
+ "@pptx-editor.dev/core": "~0.6.0",
41
+ "@pptx-editor.dev/react": "~0.6.0",
42
+ "@pptx-editor.dev/vue": "~0.6.0",
43
43
  "react": "^18.0.0 || ^19.0.0",
44
44
  "vue": "^3.5.0"
45
45
  },
@@ -62,7 +62,7 @@
62
62
  "@pptx-editor.dev/i18n": "workspace:*",
63
63
  "@pptx-editor.dev/react": "workspace:*",
64
64
  "@pptx-editor.dev/vue": "workspace:*",
65
- "vue": "3.5.44"
65
+ "vue": "3.5.45"
66
66
  },
67
67
  "license": "LicenseRef-EigenPal-Pro-Evaluation-1.0",
68
68
  "dependencies": {
@@ -1,6 +0,0 @@
1
- /*!
2
- Copyright (c) 2026 Eigenpal, Inc. All rights reserved.
3
- Licensed under the EigenPal Pro Evaluation License 1.0. See LICENSE.md in this package.
4
- Production use requires a commercial agreement: licensing@eigenpal.com
5
- */
6
- import{a as d}from"./chunk-HCD7IVOL.js";import{readCommentThreads as s}from"@pptx-editor.dev/core/editor";import{presentationInfo as p}from"@pptx-editor.dev/core/store";var l={opening:["auto","manual"],commentMarkers:["initials","icon"]};function f(e){if(e!==void 0){for(let[n,o]of Object.entries(e)){let i=l[n];if(!i)throw new TypeError(`reviewModule: unknown pane option "${n}"`);if(o!==void 0&&!i.includes(o))throw new TypeError(`reviewModule: pane.${n} must be one of ${i.map(r=>`"${r}"`).join(", ")}`)}return Object.freeze({...e})}}function u(e){let n=[];for(let o of p(e).slides)for(let i of s(e,o.partName)){let r=(t,a)=>n.push({id:t.id,kind:"comment",slidePart:o.partName,text:t.text,...t.author?{author:t.author}:{},...t.date!==void 0?{date:t.date}:{},...a?{parentId:a}:{}});r(i);for(let t of i.replies)r(t,i.id)}return n}function c(e={}){let n=f(e.pane);return d(e.licenseKey),{id:"review",review:{displayModes:e.displayModes??["final","markup"],collectReviewItems:({package:o})=>u(o),...n?{pane:n}:{}}}}export{c as a};