mirror of
https://github.com/open-webui/open-webui
synced 2024-11-29 07:21:01 +00:00
3 lines
47 KiB
JavaScript
3 lines
47 KiB
JavaScript
|
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,i){[t,e]=a(this,t,e);let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(e,this.length,s,1),n.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=a(this,t,e);let i=[];return this.decompose(t,e,i,0),n.from(i,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),n=this.length-this.scanIdentical(t,-1),i=new r(this),s=new r(t);for(let t=e,r=e;;){if(i.next(t),s.next(t),t=0,i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return!1;if(r+=i.value.length,i.done||r>=n)return!0}}iter(t=1){return new r(this,t)}iterRange(t,e=this.length){return new h(this,t,e)}iterLines(t,e){let n;if(null==t)n=this.iter();else{null==e&&(e=this.lines+1);let i=this.line(t).from;n=this.iterRange(i,Math.max(i,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new o(n)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(i){if(0==i.length)throw new RangeError("A document must have at least one line");return 1!=i.length||i[0]?i.length<=32?new e(i):n.from(e.split(i,[])):t.empty}}class e extends t{constructor(t,e=function(t){let e=-1;for(let n of t)e+=n.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,n,i){for(let s=0;;s++){let r=this.text[s],h=i+r.length;if((e?n:h)>=t)return new l(i,h,n,r);i=h+1,n++}}decompose(t,n,r,h){let o=t<=0&&n>=this.length?this:new e(s(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(1&h){let t=r.pop(),n=i(o.text,t.text.slice(),0,o.length);if(n.length<=32)r.push(new e(n,t.length+o.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(o)}replace(t,r,h){if(!(h instanceof e))return super.replace(t,r,h);[t,r]=a(this,t,r);let o=i(this.text,i(h.text,s(this.text,0,t)),r),l=this.length+h.length-(r-t);return o.length<=32?new e(o,l):n.from(e.split(o,[]),l)}sliceString(t,e=this.length,n="\n"){[t,e]=a(this,t,e);let i="";for(let s=0,r=0;s<=e&&r<this.text.length;r++){let h=this.text[r],o=s+h.length;s>t&&r&&(i+=n),t<o&&e>s&&(i+=h.slice(Math.max(0,t-s),e-s)),s=o+1}return i}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,n){let i=[],s=-1;for(let r of t)i.push(r),s+=r.length+1,32==i.length&&(n.push(new e(i,s)),i=[],s=-1);return s>-1&&n.push(new e(i,s)),n}}class n 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,n,i){for(let s=0;;s++){let r=this.children[s],h=i+r.length,o=n+r.lines-1;if((e?o:h)>=t)return r.lineInner(t,e,n,i);i=h+1,n=o+1}}decompose(t,e,n,i){for(let s=0,r=0;r<=e&&s<this.children.length;s++){let h=this.children[s],o=r+h.length;if(t<=o&&e>=r){let s=i&((r<=t?1:0)|(o>=e?2:0));r>=t&&o<=e&&!s?n.push(h):h.decompose(t-r,e-r,n,s)}r=o+1}}replace(t,e,i){if([t,e]=a(this,t,e),i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let h=this.children[s],o=r+h.length;if(t>=r&&e<=o){let l=h.replace(t-r,e-r,i),a=this.lines-h.lines+l.lines;if(l.lines<a>>4&&l.lines>a>>6){let r=this.children.slice();return r[s]=l,new n(r,this.length-(e-t)+i.length)}return super.replace(r,o,l)}r=o+1}return super.replace(t,e,i)}sliceString(t,e=this.length,n="\n"){[t,e]=a(this,t,e);let i="";for(let s=0,r=0;s<this.children.length&&r<=e;s++){let h=this.children[s],o=r+h.length;r>t&&s&&(i+=n),t<o&&e>r&&(i+=h.sliceString(t-r,e-r,n)),r=o+1}return i}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof n))return 0;let i=0,[s,r,h,o]=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==h||r==
|
||
|
//# sourceMappingURL=codemirror_state-BKbyfKsm.js.map
|