/* esm.sh - prosemirror-changeset@2.4.4 */
function W(n){let e=n.schema.cached.changeSetIDs||(n.schema.cached.changeSetIDs=Object.create(null)),t=e[n.name];return t==null&&(e[n.name]=t=Object.keys(n.schema.nodes).indexOf(n.name)+1),t}var Z={encodeCharacter:n=>n,encodeNodeStart:n=>n.type.name,encodeNodeEnd:n=>-W(n.type),compareTokens:(n,e)=>n===e};function X(n,e,t,l,r){for(let h=0,f=0;h<n.childCount;h++){let i=n.child(h),o=f+i.nodeSize,u=Math.max(f,t),d=Math.min(o,l);if(u<d)if(i.isText)for(let m=u;m<d;m++)r.push(e.encodeCharacter(i.text.charCodeAt(m-f),i.marks));else i.isLeaf?r.push(e.encodeNodeStart(i)):(u==f&&r.push(e.encodeNodeStart(i)),X(i.content,e,Math.max(f+1,u)-f-1,Math.min(o-1,d)-f-1,r),d==o&&r.push(e.encodeNodeEnd(i)));f=o}return r}var F=2500,k=1e4;function q(n,e){return Math.min(15,Math.max(2,Math.floor(Math.max(n,e)/10)))}function K(n,e,t,l=Z){if(Math.max(t.toA-t.fromA,t.toB-t.fromB)>k)return[t];let r=X(n,l,t.fromA,t.toA,[]),h=X(e,l,t.fromB,t.toB,[]);return G(r,h,t,l.compareTokens)}function G(n,e,t,l){let r=0,h=n.length,f=e.length;for(;r<n.length&&r<e.length&&l(n[r],e[r]);)r++;if(r==n.length&&r==e.length)return[];for(;h>r&&f>r&&l(n[h-1],e[f-1]);)h--,f--;if(h==r&&f==r)return[];if(h==r||f==r||h==f&&h==r+1||Math.max(h,f)-r>F)return[t.slice(r,h,r,f)];let i=h-r,o=f-r,u=Math.min(F,i+o),d=[],m=new Int16Array((u+1)*2).fill(-1);for(let a=0;a<=u;a++){for(let s=-a;s<=a;s+=2){let c=m[s+1+u],g=m[s-1+u],B=c<g?g:c+1,p=B+s;for(;B<i&&p<o&&l(n[r+B],e[r+p]);)B++,p++;if(m[s+u]=B,B>=i&&p>=o){let D=[],N=q(h-r,f-r),w=-1,x=-1,M=-1,O=-1,R=(S,j,E,P)=>{w>-1&&w<j+N?(w=S,M=E):(w>-1&&D.push(t.slice(w,x,M,O)),w=S,x=j,M=E,O=P)};for(let S=a-1;S>=0;S--){let j=m[s+1+u],E=m[s-1+u];j<E?(s--,B=E+r,p=B+s,R(B,B,p,p+1)):(s++,B=j+r,p=B+s,R(B,B+1,p,p)),m=d[S>>1]}return w>-1&&D.push(t.slice(w,x,M,O)),D.reverse()}}a%2==0&&d.push(m.slice())}return[t.slice(r,h,r,f)]}var A=class n{constructor(e,t){this.length=e,this.data=t}cut(e){return e==this.length?this:new n(e,this.data)}static slice(e,t,l){if(t==l)return n.none;if(t==0&&l==n.len(e))return e;let r=[];for(let h=0,f=0;f<l;h++){let i=e[h],o=f+i.length,u=Math.min(l,o)-Math.max(t,f);u>0&&r.push(i.cut(u)),f=o}return r}static join(e,t,l){if(e.length==0)return t;if(t.length==0)return e;let r=l(e[e.length-1].data,t[0].data);if(r==null)return e.concat(t);let h=e.slice(0,e.length-1);h.push(new n(e[e.length-1].length+t[0].length,r));for(let f=1;f<t.length;f++)h.push(t[f]);return h}static len(e){let t=0;for(let l=0;l<e.length;l++)t+=e[l].length;return t}};A.none=[];var C=class n{constructor(e,t,l,r,h,f){this.fromA=e,this.toA=t,this.fromB=l,this.toB=r,this.deleted=h,this.inserted=f}get lenA(){return this.toA-this.fromA}get lenB(){return this.toB-this.fromB}slice(e,t,l,r){return e==0&&l==0&&t==this.toA-this.fromA&&r==this.toB-this.fromB?this:new n(this.fromA+e,this.fromA+t,this.fromB+l,this.fromB+r,A.slice(this.deleted,e,t),A.slice(this.inserted,l,r))}static merge(e,t,l){if(e.length==0)return t;if(t.length==0)return e;let r=[];for(let h=0,f=0,i=e[0],o=t[0];;){if(!i&&!o)return r;if(i&&(!o||i.toB<o.fromA)){let u=f?t[f-1].toB-t[f-1].toA:0;r.push(u==0?i:new n(i.fromA,i.toA,i.fromB+u,i.toB+u,i.deleted,i.inserted)),i=h++==e.length?null:e[h]}else if(o&&(!i||o.toA<i.fromB)){let u=h?e[h-1].toB-e[h-1].toA:0;r.push(u==0?o:new n(o.fromA-u,o.toA-u,o.fromB,o.toB,o.deleted,o.inserted)),o=f++==t.length?null:t[f]}else{let u=Math.min(i.fromB,o.fromA),d=Math.min(i.fromA,o.fromA-(h?e[h-1].toB-e[h-1].toA:0)),m=d,a=Math.min(o.fromB,i.fromB+(f?t[f-1].toB-t[f-1].toA:0)),s=a,c=A.none,g=A.none,B=!1,p=!1;for(;;){let D=i?u>=i.fromB?i.toB:i.fromB:2e8,N=o?u>=o.fromA?o.toA:o.fromA:2e8,w=Math.min(D,N),x=i&&u>=i.fromB,M=o&&u>=o.fromA;if(!x&&!M)break;x&&u==i.fromB&&!B&&(c=A.join(c,i.deleted,l),m+=i.lenA,B=!0),x&&!M&&(g=A.join(g,A.slice(i.inserted,u-i.fromB,w-i.fromB),l),s+=w-u),M&&u==o.fromA&&!p&&(g=A.join(g,o.inserted,l),s+=o.lenB,p=!0),M&&!x&&(c=A.join(c,A.slice(o.deleted,u-o.fromA,w-o.fromA),l),m+=w-u),x&&w==i.toB&&(i=h++==e.length?null:e[h],B=!1),M&&w==o.toA&&(o=f++==t.length?null:t[f],p=!1),u=w}(d<m||a<s)&&r.push(new n(d,m,a,s,c,g))}}}static fromJSON(e){return new n(e.fromA,e.toA,e.fromB,e.toB,e.deleted.map(t=>new A(t.length,t.data)),e.inserted.map(t=>new A(t.length,t.data)))}toJSON(){return this}},L;try{L=new RegExp("[\\p{Alphabetic}_]","u")}catch{}var H=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;function I(n){if(n<128)return n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122;let e=String.fromCharCode(n);return L?L.test(e):e.toUpperCase()!=e.toLowerCase()||H.test(e)}function Q(n,e,t){let l="";function r(h,f,i){for(let o=0,u=0;o<h.childCount;o++){let d=h.child(o),m=u+d.nodeSize,a=Math.max(u,f),s=Math.min(m,i);a<s&&(d.isText?l+=d.text.slice(Math.max(0,f-u),Math.min(d.text.length,i-u)):d.isLeaf?l+=" ":(a==u&&(l+=" "),r(d.content,Math.max(0,a-u-1),Math.min(d.content.size,i-u)),s==m&&(l+=" "))),u=m}}return r(n,e,t),l}var T=30;function b(n,e){let t=[];for(let l=0;l<n.length;l++){let r=n[l].toB,h=l;for(;l<n.length-1&&n[l+1].fromB<=r+T;)r=n[++l].toB;V(n,h,l+1,e,t)}return t}function V(n,e,t,l,r){let h=Math.max(0,n[e].fromB-T),f=Math.min(l.content.size,n[t-1].toB+T),i=Q(l.content,h,f);for(let o=e;o<t;o++){let u=o,d=n[o],m=d.lenA,a=d.lenB;for(;o<t-1;){let s=n[o+1],c=!1,g=d.toB==f?!1:I(i.charCodeAt(d.toB-1-h));for(let B=d.toB;!c&&B<s.fromB;B++){let p=B==f?!1:I(i.charCodeAt(B-h));(!g||!p)&&B!=n[u].fromB&&(c=!0),g=p}if(c)break;m+=s.lenA,a+=s.lenB,d=s,o++}if(a>0&&m>0&&!(a==1&&m==1)){let s=n[u].fromB,c=n[o].toB;if(s<f&&I(i.charCodeAt(s-h)))for(;s>h&&I(i.charCodeAt(s-1-h));)s--;if(c>h&&I(i.charCodeAt(c-1-h)))for(;c<f&&I(i.charCodeAt(c-h));)c++;let g=$(n.slice(u,o+1),s,c),B=r.length?r[r.length-1]:null;B&&B.toA==g.fromA?r[r.length-1]=new C(B.fromA,g.toA,B.fromB,g.toB,B.deleted.concat(g.deleted),B.inserted.concat(g.inserted)):r.push(g)}else for(let s=u;s<=o;s++)r.push(n[s])}return n}function v(n,e){return n===e?n:null}function $(n,e,t){let l=n[0].fromA-(n[0].fromB-e),r=n[n.length-1],h=r.toA+(t-r.toB),f=A.none,i=A.none,o=(n[0].deleted.length?n[0].deleted:n[0].inserted)[0].data,u=(n[0].inserted.length?n[0].inserted:n[0].deleted)[0].data;for(let d=l,m=e,a=0;;a++){let s=a==n.length?null:n[a],c=s?s.fromA:h,g=s?s.fromB:t;if(c>d&&(f=A.join(f,[new A(c-d,o)],v)),g>m&&(i=A.join(i,[new A(g-m,u)],v)),!s)break;f=A.join(f,s.deleted,v),i=A.join(i,s.inserted,v),f.length&&(o=f[f.length-1].data),i.length&&(u=i[i.length-1].data),d=s.toA,m=s.toB}return new C(l,h,e,t,f,i)}var Y=class n{constructor(e,t){this.config=e,this.changes=t}addSteps(e,t,l){let r=[];for(let o=0;o<t.length;o++){let u=Array.isArray(l)?l[o]:l,d=0;t[o].forEach((m,a,s,c)=>{r.push(new C(m+d,a+d,s,c,m==a?A.none:[new A(a-m,u)],s==c?A.none:[new A(c-s,u)])),d=c-s-(a-m)})}if(r.length==0)return this;let h=z(r,this.config.combine),f=C.merge(this.changes,h,this.config.combine),i=f;for(let o=0;o<i.length;o++){let u=i[o];if(u.fromA==u.toA||u.fromB==u.toB||!h.some(m=>m.toB>u.fromB&&m.fromB<u.toB))continue;let d=K(this.config.doc.content,e.content,u,this.config.encoder);d.length==1&&d[0].fromB==0&&d[0].toB==u.toB-u.fromB||(i==f&&(i=f.slice()),d.length==1?i[o]=d[0]:(i.splice(o,1,...d),o+=d.length-1))}return new n(this.config,i)}get startDoc(){return this.config.doc}map(e){let t=l=>{let r=e(l);return r===l.data?l:new A(l.length,r)};return new n(this.config,this.changes.map(l=>new C(l.fromA,l.toA,l.fromB,l.toB,l.deleted.map(t),l.inserted.map(t))))}changedRange(e,t){if(e==this)return null;let l=t&&y(t),r=l?l.toB-l.fromB-(l.toA-l.fromA):0;function h(m){return!l||m<=l.fromA?m:m+r}let f=l?l.fromB:2e8,i=l?l.toB:-2e8;function o(m,a=m){f=Math.min(m,f),i=Math.max(a,i)}let u=this.changes,d=e.changes;for(let m=0,a=0;m<u.length&&a<d.length;){let s=u[m],c=d[a];s&&c&&_(s,c,h)?(m++,a++):c&&(!s||h(s.fromB)>=c.fromB)?(o(c.fromB,c.toB),a++):(o(h(s.fromB),h(s.toB)),m++)}return f<=i?{from:f,to:i}:null}static create(e,t=(h,f)=>h===f?h:null,l=Z,r=[]){return new n({combine:t,doc:e,encoder:l},r)}};Y.computeDiff=K;function z(n,e,t=0,l=n.length){if(l==t+1)return[n[t]];let r=t+l>>1;return C.merge(z(n,e,t,r),z(n,e,r,l),e)}function J(n){let e=2e8,t=-2e8;for(let l=0;l<n.length;l++){let r=n[l];e!=2e8&&(e=r.map(e,-1),t=r.map(t,1)),r.forEach((h,f,i,o)=>{e=Math.min(e,i),t=Math.max(t,o)})}return e==2e8?null:{from:e,to:t}}function y(n){let e=J(n);if(!e)return null;let t=J(n.map(l=>l.invert()).reverse());return{fromA:t.from,toA:t.to,fromB:e.from,toB:e.to}}function _(n,e,t){return t(n.fromB)==e.fromB&&t(n.toB)==e.toB&&U(n.deleted,e.deleted)&&U(n.inserted,e.inserted)}function U(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t].length!=e[t].length||n[t].data!==e[t].data)return!1;return!0}export{C as Change,Y as ChangeSet,A as Span,b as simplifyChanges};
//# sourceMappingURL=prosemirror-changeset.mjs.map