classt{lineAt(t){if(t<0||t>this.length)thrownewRangeError(`Invalid position ${t} in document of length ${this.length}`);returnthis.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)thrownewRangeError(`Invalid line number ${t} in ${this.lines}-line document`);returnthis.lineInner(t,!0,1,0)}replace(t,e,n){[t,e]=h(this,t,e);lets=[];returnthis.decompose(0,t,s,2),n.length&&n.decompose(0,n.length,s,3),this.decompose(e,this.length,s,1),i.from(s,this.length-(e-t)+n.length)}append(t){returnthis.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=h(this,t,e);letn=[];returnthis.decompose(t,e,n,0),i.from(n,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;lete=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),n=newr(this),s=newr(t);for(lett=e,r=e;;){if(n.next(t),s.next(t),t=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(r+=n.value.length,n.done||r>=i)return!0}}iter(t=1){returnnewr(this,t)}iterRange(t,e=this.length){returnnewo(this,t,e)}iterLines(t,e){leti;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);letn=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}returnnewa(i)}toString(){returnthis.sliceString(0)}toJSON(){lett=[];returnthis.flatten(t),t}constructor(){}staticof(n){if(0==n.length)thrownewRangeError("A document must have at least one line");return1!=n.length||n[0]?n.length<=32?newe(n):i.from(e.split(n,[])):t.empty}}classeextendst{constructor(t,e=function(t){lete=-1;for(letioft)e+=i.length+1;returne}(t)){super(),this.text=t,this.length=e}getlines(){returnthis.text.length}getchildren(){returnnull}lineInner(t,e,i,n){for(lets=0;;s++){letr=this.text[s],o=n+r.length;if((e?i:o)>=t)returnnewl(n,o,i,r);n=o+1,i++}}decompose(t,i,r,o){leta=t<=0&&i>=this.length?this:newe(s(this.text,t,i),Math.min(i,this.length)-Math.max(0,t));if(1&o){lett=r.pop(),i=n(a.text,t.text.slice(),0,a.length);if(i.length<=32)r.push(newe(i,t.length+a.length));else{lett=i.length>>1;r.push(newe(i.slice(0,t)),newe(i.slice(t)))}}elser.push(a)}replace(t,r,o){if(!(oinstanceofe))returnsuper.replace(t,r,o);[t,r]=h(this,t,r);leta=n(this.text,n(o.text,s(this.text,0,t)),r),l=this.length+o.length-(r-t);returna.length<=32?newe(a,l):i.from(e.split(a,[]),l)}sliceString(t,e=this.length,i="\n"){[t,e]=h(this,t,e);letn="";for(lets=0,r=0;s<=e&&r<this.text.length;r++){leto=this.text[r],a=s+o.length;s>t&&r&&(n+=i),t<a&&e>s&&(n+=o.slice(Math.max(0,t-s),e-s)),s=a+1}returnn}flatten(t){for(leteofthis.text)t.push(e)}scanIdentical(){return0}staticsplit(t,i){letn=[],s=-1;for(letroft)n.push(r),s+=r.length+1,32==n.length&&(i.push(newe(n,s)),n=[],s=-1);returns>-1&&i.push(newe(n,s)),i}}classiextendst{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(leteoft)this.lines+=e.lines}lineInner(t,e,i,n){for(lets=0;;s++){letr=this.children[s],o=n+r.length,a=i+r.lines-1;if((e?a:o)>=t)returnr.lineInner(t,e,i,n);n=o+1,i=a+1}}decompose(t,e,i,n){for(lets=0,r=0;r<=e&&s<this.children.length;s++){leto=this.children[s],a=r+o.length;if(t<=a&&e>=r){lets=n&((r<=t?1:0)|(a>=e?2:0));r>=t&&a<=e&&!s?i.push(o):o.decompose(t-r,e-r,i,s)}r=a+1}}replace(t,e,n){if([t,e]=h(this,t,e),n.lines<this.lines)for(lets=0,r=0;s<this.children.length;s++){leto=this.children[s],a=r+o.length;if(t>=r&&e<=a){letl=o.replace(t-r,e-r,n),h=this.lines-o.lines+l.lines;if(l.lines<h>>4&&l.lines>h>>6){letr=this.children.slice();returnr[s]=l,newi(r,this.length-(e-t)+n.length)}returnsuper.replace(r,a,l)}r=a+1}returnsuper.replace(t,e,n)}sliceString(t,e=this.length,i="\n"){[t,e]=h(this,t,e);letn="";for(lets=0,r=0;s<this.children.length&&r<=e;s++){leto=this.children[s],a=r+o.length;r>t&&s&&(n+=i),t<a&&e>r&&(n+=o.sliceString(t-r,e-r,i)),r=a+1}returnn}flatten(t){for(leteofthis.children)e.flatten(t)}scanIdentical(t,e){if(!(tinstanceofi))return0;letn=0,[s,r,o,a]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,r+=e){if(s==o||r==