tildefriends/deps/codemirror/cm6.js

2 lines
563 KiB
JavaScript
Raw Normal View History

class t{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,s){[t,e]=h(this,t,e);let n=[];return this.decompose(0,t,n,2),s.length&&s.decompose(0,s.length,n,3),this.decompose(e,this.length,n,1),i.from(n,this.length-(e-t)+s.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=h(this,t,e);let s=[];return this.decompose(t,e,s,0),i.from(s,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new r(this),n=new r(t);for(let t=e,r=e;;){if(s.next(t),n.next(t),t=0,s.lineBreak!=n.lineBreak||s.done!=n.done||s.value!=n.value)return!1;if(r+=s.value.length,s.done||r>=i)return!0}}iter(t=1){return new r(this,t)}iterRange(t,e=this.length){return new o(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new a(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(s){if(0==s.length)throw new RangeError("A document must have at least one line");return 1!=s.length||s[0]?s.length<=32?new e(s):i.from(e.split(s,[])):t.empty}}class e extends t{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let n=0;;n++){let r=this.text[n],o=s+r.length;if((e?i:o)>=t)return new l(s,o,i,r);s=o+1,i++}}decompose(t,i,r,o){let a=t<=0&&i>=this.length?this:new e(n(this.text,t,i),Math.min(i,this.length)-Math.max(0,t));if(1&o){let t=r.pop(),i=s(a.text,t.text.slice(),0,a.length);if(i.length<=32)r.push(new e(i,t.length+a.length));else{let t=i.length>>1;r.push(new e(i.slice(0,t)),new e(i.slice(t)))}}else r.push(a)}replace(t,r,o){if(!(o instanceof e))return super.replace(t,r,o);[t,r]=h(this,t,r);let a=s(this.text,s(o.text,n(this.text,0,t)),r),l=this.length+o.length-(r-t);return a.length<=32?new e(a,l):i.from(e.split(a,[]),l)}sliceString(t,e=this.length,i="\n"){[t,e]=h(this,t,e);let s="";for(let n=0,r=0;n<=e&&r<this.text.length;r++){let o=this.text[r],a=n+o.length;n>t&&r&&(s+=i),t<a&&e>n&&(s+=o.slice(Math.max(0,t-n),e-n)),n=a+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,i){let s=[],n=-1;for(let r of t)s.push(r),n+=r.length+1,32==s.length&&(i.push(new e(s,n)),s=[],n=-1);return n>-1&&i.push(new e(s,n)),i}}class i extends t{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,s){for(let n=0;;n++){let r=this.children[n],o=s+r.length,a=i+r.lines-1;if((e?a:o)>=t)return r.lineInner(t,e,i,s);s=o+1,i=a+1}}decompose(t,e,i,s){for(let n=0,r=0;r<=e&&n<this.children.length;n++){let o=this.children[n],a=r+o.length;if(t<=a&&e>=r){let n=s&((r<=t?1:0)|(a>=e?2:0));r>=t&&a<=e&&!n?i.push(o):o.decompose(t-r,e-r,i,n)}r=a+1}}replace(t,e,s){if([t,e]=h(this,t,e),s.lines<this.lines)for(let n=0,r=0;n<this.children.length;n++){let o=this.children[n],a=r+o.length;if(t>=r&&e<=a){let l=o.replace(t-r,e-r,s),h=this.lines-o.lines+l.lines;if(l.lines<h>>4&&l.lines>h>>6){let r=this.children.slice();return r[n]=l,new i(r,this.length-(e-t)+s.length)}return super.replace(r,a,l)}r=a+1}return super.replace(t,e,s)}sliceString(t,e=this.length,i="\n"){[t,e]=h(this,t,e);let s="";for(let n=0,r=0;n<this.children.length&&r<=e;n++){let o=this.children[n],a=r+o.length;r>t&&n&&(s+=i),t<a&&e>r&&(s+=o.sliceString(t-r,e-r,i)),r=a+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof i))return 0;let s=0,[n,r,o,a]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,r+=e){if(n==o||r==