codemirror 6.0.2.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +23 -0
- data/LICENSE +28 -0
- data/README.md +210 -0
- data/app/assets/javascripts/codemirror/autocomplete.js +1 -0
- data/app/assets/javascripts/codemirror/commands.js +1 -0
- data/app/assets/javascripts/codemirror/index.js +1 -0
- data/app/assets/javascripts/codemirror/lang-angular.js +1 -0
- data/app/assets/javascripts/codemirror/lang-cpp.js +1 -0
- data/app/assets/javascripts/codemirror/lang-css.js +1 -0
- data/app/assets/javascripts/codemirror/lang-go.js +1 -0
- data/app/assets/javascripts/codemirror/lang-html.js +1 -0
- data/app/assets/javascripts/codemirror/lang-java.js +1 -0
- data/app/assets/javascripts/codemirror/lang-javascript.js +1 -0
- data/app/assets/javascripts/codemirror/lang-json.js +1 -0
- data/app/assets/javascripts/codemirror/lang-less.js +1 -0
- data/app/assets/javascripts/codemirror/lang-liquid.js +1 -0
- data/app/assets/javascripts/codemirror/lang-markdown.js +1 -0
- data/app/assets/javascripts/codemirror/lang-php.js +1 -0
- data/app/assets/javascripts/codemirror/lang-python.js +1 -0
- data/app/assets/javascripts/codemirror/lang-rust.js +1 -0
- data/app/assets/javascripts/codemirror/lang-sass.js +1 -0
- data/app/assets/javascripts/codemirror/lang-sql.js +1 -0
- data/app/assets/javascripts/codemirror/lang-vue.js +1 -0
- data/app/assets/javascripts/codemirror/lang-wast.js +1 -0
- data/app/assets/javascripts/codemirror/lang-xml.js +1 -0
- data/app/assets/javascripts/codemirror/lang-yaml.js +1 -0
- data/app/assets/javascripts/codemirror/language.js +1 -0
- data/app/assets/javascripts/codemirror/lezer-common.js +1 -0
- data/app/assets/javascripts/codemirror/lezer-highlight.js +1 -0
- data/app/assets/javascripts/codemirror/lezer-lr.js +1 -0
- data/app/assets/javascripts/codemirror/lint.js +1 -0
- data/app/assets/javascripts/codemirror/search.js +1 -0
- data/app/assets/javascripts/codemirror/state.js +1 -0
- data/app/assets/javascripts/codemirror/theme-one-dark.js +1 -0
- data/app/assets/javascripts/codemirror/view.js +1 -0
- data/config/importmap.rb +46 -0
- data/lib/codemirror/engine.rb +24 -0
- data/lib/codemirror/version.rb +18 -0
- data/lib/codemirror.rb +7 -0
- metadata +100 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=1024;let t=0;class r{constructor(e,t){this.from=e,this.to=t}}class n{constructor(e={}){this.id=t++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof e&&(e=o.match(e)),t=>{let r=e(t);return void 0===r?null:[this,r]}}}n.closedBy=new n({deserialize:e=>e.split(" ")}),n.openedBy=new n({deserialize:e=>e.split(" ")}),n.group=new n({deserialize:e=>e.split(" ")}),n.isolate=new n({deserialize:e=>{if(e&&"rtl"!=e&&"ltr"!=e&&"auto"!=e)throw new RangeError("Invalid value for isolate: "+e);return e||"auto"}}),n.contextHash=new n({perNode:!0}),n.lookAhead=new n({perNode:!0}),n.mounted=new n({perNode:!0});class i{constructor(e,t,r,n=!1){this.tree=e,this.overlay=t,this.parser=r,this.bracketed=n}static get(e){return e&&e.props&&e.props[n.mounted.id]}}const s=Object.create(null);class o{constructor(e,t,r,n=0){this.name=e,this.props=t,this.id=r,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):s,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(null==e.name?8:0),n=new o(e.name||"",t,e.id,r);if(e.props)for(let r of e.props)if(Array.isArray(r)||(r=r(n)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}return n}prop(e){return this.props[e.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(e){if("string"==typeof e){if(this.name==e)return!0;let t=this.prop(n.group);return!!t&&t.indexOf(e)>-1}return this.id==e}static match(e){let t=Object.create(null);for(let r in e)for(let n of r.split(" "))t[n]=e[r];return e=>{for(let r=e.prop(n.group),i=-1;i<(r?r.length:0);i++){let n=t[i<0?e.name:r[i]];if(n)return n}}}}o.none=new o("",Object.create(null),0,8);class h{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let r of this.types){let n=null;for(let t of e){let e=t(r);if(e){n||(n=Object.assign({},r.props));let t=e[1],i=e[0];i.combine&&i.id in n&&(t=i.combine(n[i.id],t)),n[i.id]=t}}t.push(n?new o(r.name,n,r.id,r.flags):r)}return new h(t)}}const l=new WeakMap,f=new WeakMap;var u;!function(e){e[e.ExcludeBuffers=1]="ExcludeBuffers",e[e.IncludeAnonymous=2]="IncludeAnonymous",e[e.IgnoreMounts=4]="IgnoreMounts",e[e.IgnoreOverlays=8]="IgnoreOverlays",e[e.EnterBracketed=16]="EnterBracketed"}(u||(u={}));class a{constructor(e,t,r,n,i){if(this.type=e,this.children=t,this.positions=r,this.length=n,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)this.props["number"==typeof e?e:e.id]=t}}toString(){let e=i.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let e of this.children){let r=e.toString();r&&(t&&(t+=","),t+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new A(this.topNode,e)}cursorAt(e,t=0,r=0){let n=l.get(this)||this.topNode,i=new A(n);return i.moveTo(e,t),l.set(this,i._tree),i}get topNode(){return new b(this,0,0,null)}resolve(e,t=0){let r=g(l.get(this)||this.topNode,e,t,!1);return l.set(this,r),r}resolveInner(e,t=0){let r=g(f.get(this)||this.topNode,e,t,!0);return f.set(this,r),r}resolveStack(e,t=0){return function(e,t,r){let n=e.resolveInner(t,r),s=null;for(let e=n instanceof b?n:n.context.parent;e;e=e.parent)if(e.index<0){let i=e.parent;(s||(s=[n])).push(i.resolve(t,r)),e=i}else{let o=i.get(e.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let i=new b(o.tree,o.overlay[0].from+e.from,-1,e);(s||(s=[n])).push(g(i,t,r,!1))}}return s?k(s):n}(this,e,t)}iterate(e){let{enter:t,leave:r,from:n=0,to:i=this.length}=e,s=e.mode||0,o=(s&u.IncludeAnonymous)>0;for(let e=this.cursor(s|u.IncludeAnonymous);;){let s=!1;if(e.from<=i&&e.to>=n&&(!o&&e.type.isAnonymous||!1!==t(e))){if(e.firstChild())continue;s=!0}for(;s&&r&&(o||!e.type.isAnonymous)&&r(e),!e.nextSibling();){if(!e.parent())return;s=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:N(o.none,this.children,this.positions,0,this.children.length,0,this.length,(e,t,r)=>new a(this.type,e,t,r,this.propValues),e.makeTree||((e,t,r)=>new a(o.none,e,t,r)))}static build(t){return function(t){var r;let{buffer:i,nodeSet:s,maxBufferLength:o=e,reused:h=[],minRepeatType:l=s.types.length}=t,f=Array.isArray(i)?new p(i,i.length):i,u=s.types,c=0,g=0;function m(e,t,r,n,i,a){let{id:p,start:_,end:A,size:C}=f,S=g,I=c;if(C<0){if(f.next(),-1==C){let t=h[p];return r.push(t),void n.push(_-e)}if(-3==C)return void(c=p);if(-4==C)return void(g=p);throw new RangeError(`Unrecognized record size: ${C}`)}let B,E,z=u[p],M=_-e;if(A-_<=o&&(E=v(f.pos-t,i))){let t=new Uint16Array(E.size-E.skip),r=f.pos-E.size,n=t.length;for(;f.pos>r;)n=k(E.start,t,n);B=new d(t,A-E.start,s),M=E.start-e}else{let e=f.pos-C;f.next();let t=[],r=[],n=p>=l?p:-1,i=0,s=A;for(;f.pos>e;)n>=0&&f.id==n&&f.size>=0?(f.end<=s-o&&(y(t,r,_,i,f.end,s,n,S,I),i=t.length,s=f.end),f.next()):a>2500?b(_,e,t,r):m(_,e,t,r,n,a+1);if(n>=0&&i>0&&i<t.length&&y(t,r,_,i,_,s,n,S,I),t.reverse(),r.reverse(),n>-1&&i>0){let e=x(z,I);B=N(z,t,r,0,t.length,0,A-_,e,e)}else B=w(z,t,r,A-_,S-A,I)}r.push(B),n.push(M)}function b(e,t,r,n){let i=[],h=0,l=-1;for(;f.pos>t;){let{id:e,start:t,end:r,size:n}=f;if(n>4)f.next();else{if(l>-1&&t<l)break;l<0&&(l=r-o),i.push(e,t,r),h++,f.next()}}if(h){let t=new Uint16Array(4*h),o=i[i.length-2];for(let e=i.length-3,r=0;e>=0;e-=3)t[r++]=i[e],t[r++]=i[e+1]-o,t[r++]=i[e+2]-o,t[r++]=r;r.push(new d(t,i[2]-o,s)),n.push(o-e)}}function x(e,t){return(r,i,s)=>{let o,h,l=0,f=r.length-1;if(f>=0&&(o=r[f])instanceof a){if(!f&&o.type==e&&o.length==s)return o;(h=o.prop(n.lookAhead))&&(l=i[f]+o.length+h)}return w(e,r,i,s,l,t)}}function y(e,t,r,n,i,o,h,l,f){let u=[],a=[];for(;e.length>n;)u.push(e.pop()),a.push(t.pop()+r-i);e.push(w(s.types[h],u,a,o-i,l-o,f)),t.push(i-r)}function w(e,t,r,i,s,o,h){if(o){let e=[n.contextHash,o];h=h?[e].concat(h):[e]}if(s>25){let e=[n.lookAhead,s];h=h?[e].concat(h):[e]}return new a(e,t,r,i,h)}function v(e,t){let r=f.fork(),n=0,i=0,s=0,h=r.end-o,u={size:0,start:0,skip:0};e:for(let o=r.pos-e;r.pos>o;){let e=r.size;if(r.id==t&&e>=0){u.size=n,u.start=i,u.skip=s,s+=4,n+=4,r.next();continue}let f=r.pos-e;if(e<0||f<o||r.start<h)break;let a=r.id>=l?4:0,p=r.start;for(r.next();r.pos>f;){if(r.size<0){if(-3!=r.size&&-4!=r.size)break e;a+=4}else r.id>=l&&(a+=4);r.next()}i=p,n+=e,s+=a}return(t<0||n==e)&&(u.size=n,u.start=i,u.skip=s),u.size>4?u:void 0}function k(e,t,r){let{id:n,start:i,end:s,size:o}=f;if(f.next(),o>=0&&n<l){let h=r;if(o>4){let n=f.pos-(o-4);for(;f.pos>n;)r=k(e,t,r)}t[--r]=h,t[--r]=s-e,t[--r]=i-e,t[--r]=n}else-3==o?c=n:-4==o&&(g=n);return r}let _=[],A=[];for(;f.pos>0;)m(t.start||0,t.bufferStart||0,_,A,-1,0);let C=null!==(r=t.length)&&void 0!==r?r:_.length?A[0]+_[0].length:0;return new a(u[t.topID],_.reverse(),A.reverse(),C)}(t)}}a.empty=new a(o.none,[],[],0);class p{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new p(this.buffer,this.index)}}class d{constructor(e,t,r){this.buffer=e,this.length=t,this.set=r}get type(){return o.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],r=this.buffer[e+3],n=this.set.types[t],i=n.name;if(/\W/.test(i)&&!n.isError&&(i=JSON.stringify(i)),r==(e+=4))return i;let s=[];for(;e<r;)s.push(this.childString(e)),e=this.buffer[e+3];return i+"("+s.join(",")+")"}findChild(e,t,r,n,i){let{buffer:s}=this,o=-1;for(let h=e;h!=t&&!(c(i,n,s[h+1],s[h+2])&&(o=h,r>0));h=s[h+3]);return o}slice(e,t,r){let n=this.buffer,i=new Uint16Array(t-e),s=0;for(let o=e,h=0;o<t;){i[h++]=n[o++],i[h++]=n[o++]-r;let t=i[h++]=n[o++]-r;i[h++]=n[o++]-e,s=Math.max(s,t)}return new d(i,s,this.set)}}function c(e,t,r,n){switch(e){case-2:return r<t;case-1:return n>=t&&r<t;case 0:return r<t&&n>t;case 1:return r<=t&&n>t;case 2:return n>t;case 4:return!0}}function g(e,t,r,n){for(var i;e.from==e.to||(r<1?e.from>=t:e.from>t)||(r>-1?e.to<=t:e.to<t);){let t=!n&&e instanceof b&&e.index<0?null:e.parent;if(!t)return e;e=t}let s=n?0:u.IgnoreOverlays;if(n)for(let n=e,o=n.parent;o;n=o,o=n.parent)n instanceof b&&n.index<0&&(null===(i=o.enter(t,r,s))||void 0===i?void 0:i.from)!=n.from&&(e=o);for(;;){let n=e.enter(t,r,s);if(!n)return e;e=n}}class m{cursor(e=0){return new A(this,e)}getChild(e,t=null,r=null){let n=x(this,e,t,r);return n.length?n[0]:null}getChildren(e,t=null,r=null){return x(this,e,t,r)}resolve(e,t=0){return g(this,e,t,!1)}resolveInner(e,t=0){return g(this,e,t,!0)}matchContext(e){return y(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),r=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(r=t,t=e.prevSibling):t=e}return r}get node(){return this}get next(){return this.parent}}class b extends m{constructor(e,t,r,n){super(),this._tree=e,this.from=t,this.index=r,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,r,n,s=0){for(let o=this;;){for(let{children:h,positions:l}=o._tree,f=t>0?h.length:-1;e!=f;e+=t){let f,p=h[e],g=l[e]+o.from;if(s&u.EnterBracketed&&p instanceof a&&(f=i.get(p))&&!f.overlay&&f.bracketed&&r>=g&&r<=g+p.length||c(n,r,g,g+p.length))if(p instanceof d){if(s&u.ExcludeBuffers)continue;let i=p.findChild(0,p.buffer.length,t,r-g,n);if(i>-1)return new v(new w(o,p,e,g),null,i)}else if(s&u.IncludeAnonymous||!p.type.isAnonymous||C(p)){let h;if(!(s&u.IgnoreMounts)&&(h=i.get(p))&&!h.overlay)return new b(h.tree,g,e,o);let l=new b(p,g,e,o);return s&u.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(t<0?p.children.length-1:0,t,r,n,s)}}if(s&u.IncludeAnonymous||!o.type.isAnonymous)return null;if(e=o.index>=0?o.index+t:t<0?-1:o._parent._tree.children.length,o=o._parent,!o)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,r=0){let n;if(!(r&u.IgnoreOverlays)&&(n=i.get(this._tree))&&n.overlay){let i=e-this.from,s=r&u.EnterBracketed&&n.bracketed;for(let{from:e,to:r}of n.overlay)if((t>0||s?e<=i:e<i)&&(t<0||s?r>=i:r>i))return new b(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function x(e,t,r,n){let i=e.cursor(),s=[];if(!i.firstChild())return s;if(null!=r)for(let e=!1;!e;)if(e=i.type.is(r),!i.nextSibling())return s;for(;;){if(null!=n&&i.type.is(n))return s;if(i.type.is(t)&&s.push(i.node),!i.nextSibling())return null==n?s:[]}}function y(e,t,r=t.length-1){for(let n=e;r>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(t[r]&&t[r]!=n.name)return!1;r--}}return!0}class w{constructor(e,t,r,n){this.parent=e,this.buffer=t,this.index=r,this.start=n}}class v extends m{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,r){super(),this.context=e,this._parent=t,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,t,r){let{buffer:n}=this.context,i=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,r);return i<0?null:new v(this.context,this,i)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,r=0){if(r&u.ExcludeBuffers)return null;let{buffer:n}=this.context,i=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return i<0?null:new v(this.context,this,i)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new v(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new v(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:r}=this.context,n=this.index+4,i=r.buffer[this.index+3];if(i>n){let s=r.buffer[this.index+1];e.push(r.slice(n,i,s)),t.push(0)}return new a(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function k(e){if(!e.length)return null;let t=0,r=e[0];for(let n=1;n<e.length;n++){let i=e[n];(i.from>r.from||i.to<r.to)&&(r=i,t=n)}let n=r instanceof b&&r.index<0?null:r.parent,i=e.slice();return n?i[t]=n:i.splice(t,1),new _(i,r)}class _{constructor(e,t){this.heads=e,this.node=t}get next(){return k(this.heads)}}class A{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~u.EnterBracketed,e instanceof b)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return!!e&&(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0)}yieldBuf(e,t){this.index=e;let{start:r,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=r+n.buffer[e+1],this.to=r+n.buffer[e+2],!0}yield(e){return!!e&&(e instanceof b?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,r,this.mode));let{buffer:n}=this.buffer,i=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,r);return!(i<0)&&(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,r=this.mode){return this.buffer?!(r&u.ExcludeBuffers)&&this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&u.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&u.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode));let{buffer:t}=this.buffer,r=this.stack.length-1;if(e<0){let e=r<0?0:this.stack[r]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(r<0?t.buffer.length:t.buffer[this.stack[r]+3]))return this.yieldBuf(e)}return r<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,r,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(n.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:r}=n)}else({index:t,_parent:r}=this._tree);for(;r;({index:t,_parent:r}=r))if(t>-1)for(let n=t+e,i=e<0?-1:r._tree.children.length;n!=i;n+=e){let e=r._tree.children[n];if(this.mode&u.IncludeAnonymous||e instanceof d||!e.type.isAnonymous||C(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,r=0;if(e&&e.context==this.buffer)e:for(let n=this.index,i=this.stack.length;i>=0;){for(let s=e;s;s=s._parent)if(s.index==n){if(n==this.index)return s;t=s,r=i+1;break e}n=this.stack[--i]}for(let e=r;e<this.stack.length;e++)t=new v(this.buffer,t,this.stack[e]);return this.bufferNode=new v(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let r=0;;){let n=!1;if(this.type.isAnonymous||!1!==e(this)){if(this.firstChild()){r++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,n=!0}}}matchContext(e){if(!this.buffer)return y(this.node.parent,e);let{buffer:t}=this.buffer,{types:r}=t.set;for(let n=e.length-1,i=this.stack.length-1;n>=0;i--){if(i<0)return y(this._tree,e,n);let s=r[t.buffer[this.stack[i]]];if(!s.isAnonymous){if(e[n]&&e[n]!=s.name)return!1;n--}}return!0}}function C(e){return e.children.some(e=>e instanceof d||!e.type.isAnonymous||C(e))}const S=new WeakMap;function I(e,t){if(!e.isAnonymous||t instanceof d||t.type!=e)return 1;let r=S.get(t);if(null==r){r=1;for(let n of t.children){if(n.type!=e||!(n instanceof a)){r=1;break}r+=I(e,n)}S.set(t,r)}return r}function N(e,t,r,n,i,s,o,h,l){let f=0;for(let r=n;r<i;r++)f+=I(e,t[r]);let u=Math.ceil(1.5*f/8),a=[],p=[];return function t(r,n,i,o,h){for(let f=i;f<o;){let i=f,d=n[f],c=I(e,r[f]);for(f++;f<o;f++){let t=I(e,r[f]);if(c+t>=u)break;c+=t}if(f==i+1){if(c>u){let e=r[i];t(e.children,e.positions,0,e.children.length,n[i]+h);continue}a.push(r[i])}else{let t=n[f-1]+r[f-1].length-d;a.push(N(e,r,n,i,f,d,t,null,l))}p.push(d+h-s)}}(t,r,n,i,0),(h||l)(a,p,o)}class B{constructor(){this.map=new WeakMap}setBuffer(e,t,r){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,r)}getBuffer(e,t){let r=this.map.get(e);return r&&r.get(t)}set(e,t){e instanceof v?this.setBuffer(e.context.buffer,e.index,t):e instanceof b&&this.map.set(e.tree,t)}get(e){return e instanceof v?this.getBuffer(e.context.buffer,e.index):e instanceof b?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class E{constructor(e,t,r,n,i=!1,s=!1){this.from=e,this.to=t,this.tree=r,this.offset=n,this.open=(i?1:0)|(s?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(e,t=[],r=!1){let n=[new E(0,e.length,e,0,!1,r)];for(let r of t)r.to>e.length&&n.push(r);return n}static applyChanges(e,t,r=128){if(!t.length)return e;let n=[],i=1,s=e.length?e[0]:null;for(let o=0,h=0,l=0;;o++){let f=o<t.length?t[o]:null,u=f?f.fromA:1e9;if(u-h>=r)for(;s&&s.from<u;){let t=s;if(h>=t.from||u<=t.to||l){let e=Math.max(t.from,h)-l,r=Math.min(t.to,u)-l;t=e>=r?null:new E(e,r,t.tree,t.offset+l,o>0,!!f)}if(t&&n.push(t),s.to>u)break;s=i<e.length?e[i++]:null}if(!f)break;h=f.toA,l=f.toA-f.toB}return n}}class z{startParse(e,t,n){return"string"==typeof e&&(e=new M(e)),n=n?n.length?n.map(e=>new r(e.from,e.to)):[new r(0,0)]:[new r(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,r){let n=this.startParse(e,t,r);for(;;){let e=n.advance();if(e)return e}}}class M{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function T(e){return(t,r,n,i)=>new D(t,e,r,n,i)}class P{constructor(e,t,r,n,i,s){this.parser=e,this.parse=t,this.overlay=r,this.bracketed=n,this.target=i,this.from=s}}function O(e){if(!e.length||e.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(e))}class j{constructor(e,t,r,n,i,s,o,h){this.parser=e,this.predicate=t,this.mounts=r,this.index=n,this.start=i,this.bracketed=s,this.target=o,this.prev=h,this.depth=0,this.ranges=[]}}const F=new n({perNode:!0});class D{constructor(e,t,r,n,i){this.nest=t,this.input=r,this.fragments=n,this.ranges=i,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let e=this.baseParse.advance();if(!e)return null;if(this.baseParse=null,this.baseTree=e,this.startInner(),null!=this.stoppedAt)for(let e of this.inner)e.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let e=this.baseTree;return null!=this.stoppedAt&&(e=new a(e.type,e.children,e.positions,e.length,e.propValues.concat([[F,this.stoppedAt]]))),e}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let r=Object.assign(Object.create(null),e.target.props);r[n.mounted.id]=new i(t,e.overlay,e.parser,e.bracketed),e.target.props=r}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new L(this.fragments),t=null,n=null,i=new A(new b(this.baseTree,this.ranges[0].from,0,null),u.IncludeAnonymous|u.IgnoreMounts);e:for(let s,o;;){let h,l=!0;if(null!=this.stoppedAt&&i.from>=this.stoppedAt)l=!1;else if(e.hasNode(i)){if(t){let e=t.mounts.find(e=>e.frag.from<=i.from&&e.frag.to>=i.to&&e.mount.overlay);if(e)for(let r of e.mount.overlay){let n=r.from+e.pos,s=r.to+e.pos;n>=i.from&&s<=i.to&&!t.ranges.some(e=>e.from<s&&e.to>n)&&t.ranges.push({from:n,to:s})}}l=!1}else if(n&&(o=R(n.ranges,i.from,i.to)))l=2!=o;else if(!i.type.isAnonymous&&(s=this.nest(i,this.input))&&(i.from<i.to||!s.overlay)){i.tree||(U(i),t&&t.depth++,n&&n.depth++);let o=e.findMounts(i.from,s.parser);if("function"==typeof s.overlay)t=new j(s.parser,s.overlay,o,this.inner.length,i.from,!!s.bracketed,i.tree,t);else{let e=V(this.ranges,s.overlay||(i.from<i.to?[new r(i.from,i.to)]:[]));e.length&&O(e),!e.length&&s.overlay||this.inner.push(new P(s.parser,e.length?s.parser.startParse(this.input,G(o,e),e):s.parser.startParse(""),s.overlay?s.overlay.map(e=>new r(e.from-i.from,e.to-i.from)):null,!!s.bracketed,i.tree,e.length?e[0].from:i.from)),s.overlay?e.length&&(n={ranges:e,depth:0,prev:n}):l=!1}}else if(t&&(h=t.predicate(i))&&(!0===h&&(h=new r(i.from,i.to)),h.from<h.to)){let e=t.ranges.length-1;e>=0&&t.ranges[e].to==h.from?t.ranges[e]={from:t.ranges[e].from,to:h.to}:t.ranges.push(h)}if(l&&i.firstChild())t&&t.depth++,n&&n.depth++;else for(;!i.nextSibling();){if(!i.parent())break e;if(t&&! --t.depth){let e=V(this.ranges,t.ranges);e.length&&(O(e),this.inner.splice(t.index,0,new P(t.parser,t.parser.startParse(this.input,G(t.mounts,e),e),t.ranges.map(e=>new r(e.from-t.start,e.to-t.start)),t.bracketed,t.target,e[0].from))),t=t.prev}n&&! --n.depth&&(n=n.prev)}}}}function R(e,t,r){for(let n of e){if(n.from>=r)break;if(n.to>t)return n.from<=t&&n.to>=r?2:1}return 0}function W(e,t,r,n,i,s){if(t<r){let o=e.buffer[t+1];n.push(e.slice(t,r,o)),i.push(o-s)}}function U(e){let{node:t}=e,r=[],n=t.context.buffer;do{r.push(e.index),e.parent()}while(!e.tree);let i=e.tree,s=i.children.indexOf(n),h=i.children[s],l=h.buffer,f=[s];i.children[s]=function e(n,i,s,o,u,p){let d=r[p],c=[],g=[];W(h,n,d,c,g,o);let m=l[d+1],b=l[d+2];f.push(c.length);let x=p?e(d+4,l[d+3],h.set.types[l[d]],m,b-m,p-1):t.toTree();return c.push(x),g.push(m-o),W(h,l[d+3],i,c,g,o),new a(s,c,g,u)}(0,l.length,o.none,0,h.length,r.length-1);for(let t of f){let r=e.tree.children[t],n=e.tree.positions[t];e.yield(new b(r,n+e.from,t,e._tree))}}class J{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(u.IncludeAnonymous|u.IgnoreMounts)}moveTo(e){let{cursor:t}=this,r=e-this.offset;for(;!this.done&&t.from<r;)if(t.to>=e&&t.enter(r,1,u.IgnoreOverlays|u.ExcludeBuffers));else{if(!(t.to<=e))break;t.next(!1)||(this.done=!0)}}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(!(t.children.length&&0==t.positions[0]&&t.children[0]instanceof a))break;t=t.children[0]}return!1}}class L{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let r=this.curFrag=e[0];this.curTo=null!==(t=r.tree.prop(F))&&void 0!==t?t:r.to,this.inner=new J(r.tree,-r.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=null!==(e=t.tree.prop(F))&&void 0!==e?e:t.to,this.inner=new J(t.tree,-t.offset)}}findMounts(e,t){var r;let i=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let e=this.inner.cursor.node;e;e=e.parent){let s=null===(r=e.tree)||void 0===r?void 0:r.prop(n.mounted);if(s&&s.parser==t)for(let t=this.fragI;t<this.fragments.length;t++){let r=this.fragments[t];if(r.from>=e.to)break;r.tree==this.curFrag.tree&&i.push({frag:r,pos:e.from-r.offset,mount:s})}}}return i}}function V(e,t){let n=null,i=t;for(let s=1,o=0;s<e.length;s++){let h=e[s-1].to,l=e[s].from;for(;o<i.length;o++){let e=i[o];if(e.from>=l)break;e.to<=h||(n||(i=n=t.slice()),e.from<h?(n[o]=new r(e.from,h),e.to>l&&n.splice(o+1,0,new r(l,e.to))):e.to>l?n[o--]=new r(l,e.to):n.splice(o--,1))}}return i}function H(e,t,n,i){let s=0,o=0,h=!1,l=!1,f=-1e9,u=[];for(;;){let a=s==e.length?1e9:h?e[s].to:e[s].from,p=o==t.length?1e9:l?t[o].to:t[o].from;if(h!=l){let e=Math.max(f,n),t=Math.min(a,p,i);e<t&&u.push(new r(e,t))}if(f=Math.min(a,p),1e9==f)break;a==f&&(h?(h=!1,s++):h=!0),p==f&&(l?(l=!1,o++):l=!0)}return u}function G(e,t){let n=[];for(let{pos:i,mount:s,frag:o}of e){let e=i+(s.overlay?s.overlay[0].from:0),h=e+s.tree.length,l=Math.max(o.from,e),f=Math.min(o.to,h);if(s.overlay){let h=H(t,s.overlay.map(e=>new r(e.from+i,e.to+i)),l,f);for(let t=0,r=l;;t++){let i=t==h.length,l=i?f:h[t].from;if(l>r&&n.push(new E(r,l,s.tree,-e,o.from>=r||o.openStart,o.to<=l||o.openEnd)),i)break;r=h[t].to}}else n.push(new E(l,f,s.tree,-e,o.from>=e||o.openStart,o.to<=h||o.openEnd))}return n}export{e as DefaultBufferLength,u as IterMode,i as MountedTree,n as NodeProp,h as NodeSet,o as NodeType,B as NodeWeakMap,z as Parser,a as Tree,d as TreeBuffer,A as TreeCursor,E as TreeFragment,T as parseMixed};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{NodeProp as t}from"@lezer/common";let e=0;class a{constructor(t,a,i,o){this.name=t,this.set=a,this.base=i,this.modified=o,this.id=e++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i="string"==typeof t?t:"?";if(t instanceof a&&(e=t),null==e?void 0:e.base)throw new Error("Can not derive from a modified tag");let o=new a(i,[],null,[]);if(o.set.push(o),e)for(let t of e.set)o.set.push(t);return o}static defineModifier(t){let e=new o(t);return t=>t.modified.indexOf(e)>-1?t:o.get(t.base||t,t.modified.concat(e).sort((t,e)=>t.id-e.id))}}let i=0;class o{constructor(t){this.name=t,this.instances=[],this.id=i++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(a=>{return a.base==t&&(i=e,o=a.modified,i.length==o.length&&i.every((t,e)=>t==o[e]));var i,o});if(i)return i;let r=[],n=new a(t.name,r,t,e);for(let t of e)t.instances.push(n);let s=function(t){let e=[[]];for(let a=0;a<t.length;a++)for(let i=0,o=e.length;i<o;i++)e.push(e[i].concat(t[a]));return e.sort((t,e)=>e.length-t.length)}(e);for(let e of t.set)if(!e.modified.length)for(let t of s)r.push(o.get(e,t));return n}}function r(t){let e=Object.create(null);for(let a in t){let i=t[a];Array.isArray(i)||(i=[i]);for(let t of a.split(" "))if(t){let a=[],o=2,r=t;for(let e=0;;){if("..."==r&&e>0&&e+3==t.length){o=1;break}let i=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!i)throw new RangeError("Invalid path: "+t);if(a.push("*"==i[0]?"":'"'==i[0][0]?JSON.parse(i[0]):i[0]),e+=i[0].length,e==t.length)break;let n=t[e++];if(e==t.length&&"!"==n){o=0;break}if("/"!=n)throw new RangeError("Invalid path: "+t);r=t.slice(e)}let n=a.length-1,l=a[n];if(!l)throw new RangeError("Invalid path: "+t);let c=new s(i,o,n>0?a.slice(0,n):null);e[l]=c.sort(e[l])}}return n.add(e)}const n=new t({combine(t,e){let a,i,o;for(;t||e;){if(!t||e&&t.depth>=e.depth?(o=e,e=e.next):(o=t,t=t.next),a&&a.mode==o.mode&&!o.context&&!a.context)continue;let r=new s(o.tags,o.mode,o.context);a?a.next=r:i=r,a=r}return i}});class s{constructor(t,e,a,i){this.tags=t,this.mode=e,this.context=a,this.next=i}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}function l(t,e){let a=Object.create(null);for(let e of t)if(Array.isArray(e.tag))for(let t of e.tag)a[t.id]=e.class;else a[e.tag.id]=e.class;let{scope:i,all:o=null}=e||{};return{style:t=>{let e=o;for(let i of t)for(let t of i.set){let i=a[t.id];if(i){e=e?e+" "+i:i;break}}return e},scope:i}}function c(t,e,a,i=0,o=t.length){let r=new f(i,Array.isArray(e)?e:[e],a);r.highlightRange(t.cursor(),i,o,"",r.highlighters),r.flush(o)}function h(t,e,a,i,o,r=0,n=t.length){let s=r;function l(e,a){if(!(e<=s)){for(let r=t.slice(s,e),n=0;;){let t=r.indexOf("\n",n),e=t<0?r.length:t;if(e>n&&i(r.slice(n,e),a),t<0)break;o(),n=t+1}s=e}}c(e,a,(t,e,a)=>{l(t,""),l(e,a)},r,n),l(n,"")}s.empty=new s([],2,null);class f{constructor(t,e,a){this.at=t,this.highlighters=e,this.span=a,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(e,a,i,o,r){let{type:n,from:l,to:c}=e;if(l>=i||c<=a)return;n.isTop&&(r=this.highlighters.filter(t=>!t.scope||t.scope(n)));let h=o,f=g(e)||s.empty,d=function(t,e){let a=null;for(let i of t){let t=i.style(e);t&&(a=a?a+" "+t:t)}return a}(r,f.tags);if(d&&(h&&(h+=" "),h+=d,1==f.mode&&(o+=(o?" ":"")+d)),this.startSpan(Math.max(a,l),h),f.opaque)return;let m=e.tree&&e.tree.prop(t.mounted);if(m&&m.overlay){let t=e.node.enter(m.overlay[0].from+l,1),n=this.highlighters.filter(t=>!t.scope||t.scope(m.tree.type)),s=e.firstChild();for(let f=0,g=l;;f++){let d=f<m.overlay.length?m.overlay[f]:null,p=d?d.from+l:c,u=Math.max(a,g),k=Math.min(i,p);if(u<k&&s)for(;e.from<k&&(this.highlightRange(e,u,k,o,r),this.startSpan(Math.min(k,e.to),h),!(e.to>=p)&&e.nextSibling()););if(!d||p>i)break;g=d.to+l,g>a&&(this.highlightRange(t.cursor(),Math.max(a,d.from+l),Math.min(i,g),"",n),this.startSpan(Math.min(i,g),h))}s&&e.parent()}else if(e.firstChild()){m&&(o="");do{if(!(e.to<=a)){if(e.from>=i)break;this.highlightRange(e,a,i,o,r),this.startSpan(Math.min(i,e.to),h)}}while(e.nextSibling());e.parent()}}}function g(t){let e=t.type.prop(n);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}const d=a.define,m=d(),p=d(),u=d(p),k=d(p),b=d(),y=d(b),N=d(b),x=d(),w=d(x),v=d(),M=d(),O=d(),S=d(O),R=d(),C={comment:m,lineComment:d(m),blockComment:d(m),docComment:d(m),name:p,variableName:d(p),typeName:u,tagName:d(u),propertyName:k,attributeName:d(k),className:d(p),labelName:d(p),namespace:d(p),macroName:d(p),literal:b,string:y,docString:d(y),character:d(y),attributeValue:d(y),number:N,integer:d(N),float:d(N),bool:d(b),regexp:d(b),escape:d(b),color:d(b),url:d(b),keyword:v,self:d(v),null:d(v),atom:d(v),unit:d(v),modifier:d(v),operatorKeyword:d(v),controlKeyword:d(v),definitionKeyword:d(v),moduleKeyword:d(v),operator:M,derefOperator:d(M),arithmeticOperator:d(M),logicOperator:d(M),bitwiseOperator:d(M),compareOperator:d(M),updateOperator:d(M),definitionOperator:d(M),typeOperator:d(M),controlOperator:d(M),punctuation:O,separator:d(O),bracket:S,angleBracket:d(S),squareBracket:d(S),paren:d(S),brace:d(S),content:x,heading:w,heading1:d(w),heading2:d(w),heading3:d(w),heading4:d(w),heading5:d(w),heading6:d(w),contentSeparator:d(x),list:d(x),quote:d(x),emphasis:d(x),strong:d(x),link:d(x),monospace:d(x),strikethrough:d(x),inserted:d(),deleted:d(),changed:d(),invalid:d(),meta:R,documentMeta:d(R),annotation:d(R),processingInstruction:d(R),definition:a.defineModifier("definition"),constant:a.defineModifier("constant"),function:a.defineModifier("function"),standard:a.defineModifier("standard"),local:a.defineModifier("local"),special:a.defineModifier("special")};for(let t in C){let e=C[t];e instanceof a&&(e.name=t)}const A=l([{tag:C.link,class:"tok-link"},{tag:C.heading,class:"tok-heading"},{tag:C.emphasis,class:"tok-emphasis"},{tag:C.strong,class:"tok-strong"},{tag:C.keyword,class:"tok-keyword"},{tag:C.atom,class:"tok-atom"},{tag:C.bool,class:"tok-bool"},{tag:C.url,class:"tok-url"},{tag:C.labelName,class:"tok-labelName"},{tag:C.inserted,class:"tok-inserted"},{tag:C.deleted,class:"tok-deleted"},{tag:C.literal,class:"tok-literal"},{tag:C.string,class:"tok-string"},{tag:C.number,class:"tok-number"},{tag:[C.regexp,C.escape,C.special(C.string)],class:"tok-string2"},{tag:C.variableName,class:"tok-variableName"},{tag:C.local(C.variableName),class:"tok-variableName tok-local"},{tag:C.definition(C.variableName),class:"tok-variableName tok-definition"},{tag:C.special(C.variableName),class:"tok-variableName2"},{tag:C.definition(C.propertyName),class:"tok-propertyName tok-definition"},{tag:C.typeName,class:"tok-typeName"},{tag:C.namespace,class:"tok-namespace"},{tag:C.className,class:"tok-className"},{tag:C.macroName,class:"tok-macroName"},{tag:C.propertyName,class:"tok-propertyName"},{tag:C.operator,class:"tok-operator"},{tag:C.comment,class:"tok-comment"},{tag:C.meta,class:"tok-meta"},{tag:C.invalid,class:"tok-invalid"},{tag:C.punctuation,class:"tok-punctuation"}]);export{a as Tag,A as classHighlighter,g as getStyleTags,h as highlightCode,c as highlightTree,r as styleTags,l as tagHighlighter,C as tags};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Parser as t,NodeProp as e,NodeSet as s,NodeType as i,DefaultBufferLength as r,Tree as h,IterMode as n}from"@lezer/common";class o{constructor(t,e,s,i,r,h,n,o,a,l=0,c){this.p=t,this.stack=e,this.state=s,this.reducePos=i,this.pos=r,this.score=h,this.buffer=n,this.bufferBase=o,this.curContext=a,this.lookAhead=l,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,s=0){let i=t.parser.context;return new o(t,[],e,s,s,0,[],0,i?new a(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let s=t>>19,i=65535&t,{parser:r}=this.p,h=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),n=r.dynamicPrecedence(i);if(n&&(this.score+=n),0==s)return i<r.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(r.getGoto(this.state,i,!0),this.reducePos),i<r.minRepeatTerm&&this.storeNode(i,this.reducePos,this.reducePos,h?8:4,!0),void this.reduceContext(i,this.reducePos);let o=this.stack.length-3*(s-1)-(262144&t?6:0),a=o?this.stack[o-2]:this.p.ranges[0].from;i<r.minRepeatTerm&&a==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let l=this.reducePos-a;l>=2e3&&!(null===(e=this.p.parser.nodeSet.types[i])||void 0===e?void 0:e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=l):this.p.lastBigReductionSize<l&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=l));let c=o?this.stack[o-1]:0,u=this.bufferBase+this.buffer.length-c;if(i<r.minRepeatTerm||131072&t){let t=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(i,a,t,u+4,!0)}if(262144&t)this.state=this.stack[o];else{let t=this.stack[o-3];this.state=r.getGoto(t,i,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(i,a)}storeNode(t,e,s,i=4,r=!1){if(0==t&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let t=this.buffer.length;if(t>0&&0==this.buffer[t-4]&&this.buffer[t-1]>-1){if(e==s)return;if(this.buffer[t-2]>=e)return void(this.buffer[t-2]=s)}}if(r&&this.pos!=s){let r=this.buffer.length;if(r>0&&(0!=this.buffer[r-4]||this.buffer[r-1]<0)){let t=!1;for(let e=r;e>0&&this.buffer[e-2]>s;e-=4)if(this.buffer[e-1]>=0){t=!0;break}if(t)for(;r>0&&this.buffer[r-2]>s;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,i>4&&(i-=4)}this.buffer[r]=t,this.buffer[r+1]=e,this.buffer[r+2]=s,this.buffer[r+3]=i}else this.buffer.push(t,e,s,i)}shift(t,e,s,i){if(131072&t)this.pushState(65535&t,this.pos);else if(262144&t)this.pos=i,this.shiftContext(e,s),e<=this.p.parser.maxNode&&this.buffer.push(e,s,i,4);else{let r=t,{parser:h}=this.p;this.pos=i;let n=h.stateFlag(r,1);!n&&(i>s||e<=h.maxNode)&&(this.reducePos=i),this.pushState(r,n?s:Math.min(s,this.reducePos)),this.shiftContext(e,s),e<=h.maxNode&&this.buffer.push(e,s,i,4)}}apply(t,e,s,i){65536&t?this.reduce(t):this.shift(t,e,s,i)}useNode(t,e){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=t)&&(this.p.reused.push(t),s++);let i=this.pos;this.reducePos=this.pos=i+t.length,this.pushState(e,i),this.buffer.push(s,i,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&0==t.buffer[e-4]&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let s=t.buffer.slice(e),i=t.bufferBase+e;for(;t&&i==t.bufferBase;)t=t.parent;return new o(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,i,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let s=t<=this.p.parser.maxNode;s&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,s?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new l(this);;){let s=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(0==s)return!1;if(!(65536&s))return!0;e.reduce(s)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let s=[];for(let i,r=0;r<e.length;r+=2)(i=e[r+1])!=this.state&&this.p.parser.hasAction(i,t)&&s.push(e[r],i);if(this.stack.length<120)for(let t=0;s.length<8&&t<e.length;t+=2){let i=e[t+1];s.some((t,e)=>1&e&&t==i)||s.push(e[t],i)}e=s}let s=[];for(let t=0;t<e.length&&s.length<4;t+=2){let i=e[t+1];if(i==this.state)continue;let r=this.split();r.pushState(i,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(e[t],this.pos),r.reducePos=this.pos,r.score-=200,s.push(r)}return s}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if(!(65536&e))return!1;if(!t.validAction(this.state,e)){let s=e>>19,i=65535&e,r=this.stack.length-3*s;if(r<0||t.getGoto(this.stack[r],i,!1)<0){let t=this.findForcedReduction();if(null==t)return!1;e=t}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],s=(i,r)=>{if(!e.includes(i))return e.push(i),t.allActions(i,e=>{if(393216&e);else if(65536&e){let s=(e>>19)-r;if(s>1){let i=65535&e,r=this.stack.length-3*s;if(r>=0&&t.getGoto(this.stack[r],i,!1)>=0)return s<<19|65536|i}}else{let t=s(e,r+1);if(null!=t)return t}})};return s(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(3!=this.stack.length)return!1;let{parser:t}=this.p;return 65535==t.data[t.stateSlot(this.state,1)]&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||-3!=this.buffer[t])&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||-4!=this.buffer[t])&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new a(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return!(t<=this.lookAhead)&&(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class a{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class l{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=65535&t,s=t>>19;0==s?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(s-1);let i=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=i}}class c{constructor(t,e,s){this.stack=t,this.pos=e,this.index=s,this.buffer=t.buffer,0==this.index&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new c(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;null!=t&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,0==this.index&&this.maybeNext()}fork(){return new c(this.stack,this.pos,this.index)}}function u(t,e=Uint16Array){if("string"!=typeof t)return t;let s=null;for(let i=0,r=0;i<t.length;){let h=0;for(;;){let e=t.charCodeAt(i++),s=!1;if(126==e){h=65535;break}e>=92&&e--,e>=34&&e--;let r=e-32;if(r>=46&&(r-=46,s=!0),h+=r,s)break;h*=46}s?s[r++]=h:s=new e(h)}return s}class f{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const p=new f;class d{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=p,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let s=this.range,i=this.rangeIndex,r=this.pos+t;for(;r<s.from;){if(!i)return null;let t=this.ranges[--i];r-=s.from-t.to,s=t}for(;e<0?r>s.to:r>=s.to;){if(i==this.ranges.length-1)return null;let t=this.ranges[++i];r+=t.from-s.to,s=t}return r}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e,s,i=this.chunkOff+t;if(i>=0&&i<this.chunk.length)e=this.pos+t,s=this.chunk.charCodeAt(i);else{let i=this.resolveOffset(t,1);if(null==i)return-1;if(e=i,e>=this.chunk2Pos&&e<this.chunk2Pos+this.chunk2.length)s=this.chunk2.charCodeAt(e-this.chunk2Pos);else{let t=this.rangeIndex,i=this.range;for(;i.to<=e;)i=this.ranges[++t];this.chunk2=this.input.chunk(this.chunk2Pos=e),e+this.chunk2.length>i.to&&(this.chunk2=this.chunk2.slice(0,i.to-e)),s=this.chunk2.charCodeAt(0)}}return e>=this.token.lookAhead&&(this.token.lookAhead=e+1),s}acceptToken(t,e=0){let s=e?this.resolveOffset(e,-1):this.pos;if(null==s||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=s}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=p,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let s="";for(let i of this.ranges){if(i.from>=e)break;i.to>t&&(s+=this.input.read(Math.max(i.from,t),Math.min(i.to,e)))}return s}}class k{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;x(this.data,t,e,this.id,s.data,s.tokenPrecTable)}}k.prototype.contextual=k.prototype.fallback=k.prototype.extend=!1;class g{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data="string"==typeof t?u(t):t}token(t,e){let s=t.pos,i=0;for(;;){let s=t.next<0,r=t.resolveOffset(1,1);if(x(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(null==this.elseToken)return;if(s||i++,null==r)break;t.reset(r,t.token)}i&&(t.reset(s,t.token),t.acceptToken(this.elseToken,i))}}g.prototype.contextual=k.prototype.fallback=k.prototype.extend=!1;class m{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function x(t,e,s,i,r,h){let n=0,o=1<<i,{dialect:a}=s.p.parser;t:for(;0!=(o&t[n]);){let s=t[n+1];for(let i=n+3;i<s;i+=2)if((t[i+1]&o)>0){let s=t[i];if(a.allows(s)&&(-1==e.token.value||e.token.value==s||S(s,e.token.value,r,h))){e.acceptToken(s);break}}let i=e.next,l=0,c=t[n+2];if(!(e.next<0&&c>l&&65535==t[s+3*c-3])){for(;l<c;){let r=l+c>>1,h=s+r+(r<<1),o=t[h],a=t[h+1]||65536;if(i<o)c=r;else{if(!(i>=a)){n=t[h+2],e.advance();continue t}l=r+1}}break}n=t[s+3*c-1]}}function b(t,e,s){for(let i,r=e;65535!=(i=t[r]);r++)if(i==s)return r-e;return-1}function S(t,e,s,i){let r=b(s,i,e);return r<0||b(s,i,t)<r}const v="undefined"!=typeof process&&process.env&&/\bparse\b/.test(process.env.LOG);let P=null;function A(t,e,s){let i=t.cursor(n.IncludeAnonymous);for(i.moveTo(e);;)if(!(s<0?i.childBefore(e):i.childAfter(e)))for(;;){if((s<0?i.to<e:i.from>e)&&!i.type.isError)return s<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(t.length,Math.max(i.from+1,e+25));if(s<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return s<0?0:t.length}}class C{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?A(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?A(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let s=this.trees.length-1;if(s<0)return this.nextFragment(),null;let i=this.trees[s],r=this.index[s];if(r==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=i.children[r],o=this.start[s]+i.positions[r];if(o>t)return this.nextStart=o,null;if(n instanceof h){if(o==t){if(o<this.safeFrom)return null;let t=o+n.length;if(t<=this.safeTo){let s=n.prop(e.lookAhead);if(!s||t+s<this.fragment.to)return n}}this.index[s]++,o+n.length>=Math.max(this.safeFrom,t)&&(this.trees.push(n),this.start.push(o),this.index.push(0))}else this.index[s]++,this.nextStart=o+n.length}}}class y{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(t=>new f)}getActions(t){let e=0,s=null,{parser:i}=t.p,{tokenizers:r}=i,h=i.stateSlot(t.state,3),n=t.curContext?t.curContext.hash:0,o=0;for(let i=0;i<r.length;i++){if(!(1<<i&h))continue;let a=r[i],l=this.tokens[i];if((!s||a.fallback)&&((a.contextual||l.start!=t.pos||l.mask!=h||l.context!=n)&&(this.updateCachedToken(l,a,t),l.mask=h,l.context=n),l.lookAhead>l.end+25&&(o=Math.max(l.lookAhead,o)),0!=l.value)){let i=e;if(l.extended>-1&&(e=this.addActions(t,l.extended,l.end,e)),e=this.addActions(t,l.value,l.end,e),!a.extend&&(s=l,e>i))break}}for(;this.actions.length>e;)this.actions.pop();return o&&t.setLookAhead(o),s||t.pos!=this.stream.end||(s=new f,s.value=t.p.parser.eofTerm,s.start=s.end=t.pos,e=this.addActions(t,s.value,s.end,e)),this.mainToken=s,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new f,{pos:s,p:i}=t;return e.start=s,e.end=Math.min(s+1,i.stream.end),e.value=s==i.stream.end?i.parser.eofTerm:0,e}updateCachedToken(t,e,s){let i=this.stream.clipPos(s.pos);if(e.token(this.stream.reset(i,t),s),t.value>-1){let{parser:e}=s.p;for(let i=0;i<e.specialized.length;i++)if(e.specialized[i]==t.value){let r=e.specializers[i](this.stream.read(t.start,t.end),s);if(r>=0&&s.p.parser.dialect.allows(r>>1)){1&r?t.extended=r>>1:t.value=r>>1;break}}}else t.value=0,t.end=this.stream.clipPos(i+1)}putAction(t,e,s,i){for(let e=0;e<i;e+=3)if(this.actions[e]==t)return i;return this.actions[i++]=t,this.actions[i++]=e,this.actions[i++]=s,i}addActions(t,e,s,i){let{state:r}=t,{parser:h}=t.p,{data:n}=h;for(let t=0;t<2;t++)for(let o=h.stateSlot(r,t?2:1);;o+=3){if(65535==n[o]){if(1!=n[o+1]){0==i&&2==n[o+1]&&(i=this.putAction(D(n,o+2),e,s,i));break}o=D(n,o+2)}n[o]==e&&(i=this.putAction(D(n,o+1),e,s,i))}return i}}class T{constructor(t,e,s,i){this.parser=t,this.input=e,this.ranges=i,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new d(e,i),this.tokens=new y(t,this.stream),this.topTerm=t.top[1];let{from:r}=i[0];this.stacks=[o.start(this,t.top[0],r)],this.fragments=s.length&&this.stream.end-r>4*t.bufferLength?new C(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t,e,s=this.stacks,i=this.minStackPos,r=this.stacks=[];if(this.bigReductionCount>300&&1==s.length){let[t]=s;for(;t.forceReduce()&&t.stack.length&&t.stack[t.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let h=0;h<s.length;h++){let n=s[h];for(;;){if(this.tokens.mainToken=null,n.pos>i)r.push(n);else{if(this.advanceStack(n,r,s))continue;{t||(t=[],e=[]),t.push(n);let s=this.tokens.getMainToken(n);e.push(s.value,s.end)}}break}}if(!r.length){let e=t&&function(t){let e=null;for(let s of t){let t=s.p.stoppedAt;(s.pos==s.p.stream.end||null!=t&&s.pos>t)&&s.p.parser.stateFlag(s.state,2)&&(!e||e.score<s.score)&&(e=s)}return e}(t);if(e)return v&&console.log("Finish with "+this.stackID(e)),this.stackToTree(e);if(this.parser.strict)throw v&&t&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+i);this.recovering||(this.recovering=5)}if(this.recovering&&t){let s=null!=this.stoppedAt&&t[0].pos>this.stoppedAt?t[0]:this.runRecovery(t,e,r);if(s)return v&&console.log("Force-finish "+this.stackID(s)),this.stackToTree(s.forceAll())}if(this.recovering){let t=1==this.recovering?1:3*this.recovering;if(r.length>t)for(r.sort((t,e)=>e.score-t.score);r.length>t;)r.pop();r.some(t=>t.reducePos>i)&&this.recovering--}else if(r.length>1){t:for(let t=0;t<r.length-1;t++){let e=r[t];for(let s=t+1;s<r.length;s++){let i=r[s];if(e.sameState(i)||e.buffer.length>500&&i.buffer.length>500){if(!((e.score-i.score||e.buffer.length-i.buffer.length)>0)){r.splice(t--,1);continue t}r.splice(s--,1)}}}r.length>12&&(r.sort((t,e)=>e.score-t.score),r.splice(12,r.length-12))}this.minStackPos=r[0].pos;for(let t=1;t<r.length;t++)r[t].pos<this.minStackPos&&(this.minStackPos=r[t].pos);return null}stopAt(t){if(null!=this.stoppedAt&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,s,i){let r=t.pos,{parser:n}=this,o=v?this.stackID(t)+" -> ":"";if(null!=this.stoppedAt&&r>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let s=t.curContext&&t.curContext.tracker.strict,i=s?t.curContext.hash:0;for(let a=this.fragments.nodeAt(r);a;){let r=this.parser.nodeSet.types[a.type.id]==a.type?n.getGoto(t.state,a.type.id):-1;if(r>-1&&a.length&&(!s||(a.prop(e.contextHash)||0)==i))return t.useNode(a,r),v&&console.log(o+this.stackID(t)+` (via reuse of ${n.getName(a.type.id)})`),!0;if(!(a instanceof h)||0==a.children.length||a.positions[0]>0)break;let l=a.children[0];if(!(l instanceof h&&0==a.positions[0]))break;a=l}}let a=n.stateSlot(t.state,4);if(a>0)return t.reduce(a),v&&console.log(o+this.stackID(t)+` (via always-reduce ${n.getName(65535&a)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let l=this.tokens.getActions(t);for(let e=0;e<l.length;){let h=l[e++],a=l[e++],c=l[e++],u=e==l.length||!i,f=u?t:t.split(),p=this.tokens.mainToken;if(f.apply(h,a,p?p.start:f.pos,c),v&&console.log(o+this.stackID(f)+` (via ${65536&h?`reduce of ${n.getName(65535&h)}`:"shift"} for ${n.getName(a)} @ ${r}${f==t?"":", split"})`),u)return!0;f.pos>r?s.push(f):i.push(f)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return w(t,e),!0}}runRecovery(t,e,s){let i=null,r=!1;for(let h=0;h<t.length;h++){let n=t[h],o=e[h<<1],a=e[1+(h<<1)],l=v?this.stackID(n)+" -> ":"";if(n.deadEnd){if(r)continue;if(r=!0,n.restart(),v&&console.log(l+this.stackID(n)+" (restarted)"),this.advanceFully(n,s))continue}let c=n.split(),u=l;for(let t=0;t<10&&c.forceReduce();t++){if(v&&console.log(u+this.stackID(c)+" (via force-reduce)"),this.advanceFully(c,s))break;v&&(u=this.stackID(c)+" -> ")}for(let t of n.recoverByInsert(o))v&&console.log(l+this.stackID(t)+" (via recover-insert)"),this.advanceFully(t,s);this.stream.end>n.pos?(a==n.pos&&(a++,o=0),n.recoverByDelete(o,a),v&&console.log(l+this.stackID(n)+` (via recover-delete ${this.parser.getName(o)})`),w(n,s)):(!i||i.score<c.score)&&(i=c)}return i}stackToTree(t){return t.close(),h.build({buffer:c.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(P||(P=new WeakMap)).get(t);return e||P.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function w(t,e){for(let s=0;s<e.length;s++){let i=e[s];if(i.pos==t.pos&&i.sameState(t))return void(e[s].score<t.score&&(e[s]=t))}e.push(t)}class R{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||0==this.disabled[t]}}const N=t=>t;class z{constructor(t){this.start=t.start,this.shift=t.shift||N,this.reduce=t.reduce||N,this.reuse=t.reuse||N,this.hash=t.hash||(()=>0),this.strict=!1!==t.strict}}class I extends t{constructor(t){if(super(),this.wrappers=[],14!=t.version)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let h=t.nodeNames.split(" ");this.minRepeatTerm=h.length;for(let e=0;e<t.repeatNodeCount;e++)h.push("");let n=Object.keys(t.topRules).map(e=>t.topRules[e][1]),o=[];for(let t=0;t<h.length;t++)o.push([]);function a(t,e,s){o[t].push([e,e.deserialize(String(s))])}if(t.nodeProps)for(let s of t.nodeProps){let t=s[0];"string"==typeof t&&(t=e[t]);for(let e=1;e<s.length;){let i=s[e++];if(i>=0)a(i,t,s[e++]);else{let r=s[e+-i];for(let h=-i;h>0;h--)a(s[e++],t,r);e++}}}this.nodeSet=new s(h.map((e,s)=>i.define({name:s>=this.minRepeatTerm?void 0:e,id:s,props:o[s],top:n.indexOf(s)>-1,error:0==s,skipped:t.skippedNodes&&t.skippedNodes.indexOf(s)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=r;let l=u(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let t=0;t<this.specializerSpecs.length;t++)this.specialized[t]=this.specializerSpecs[t].term;this.specializers=this.specializerSpecs.map(B),this.states=u(t.states,Uint32Array),this.data=u(t.stateData),this.goto=u(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(t=>"number"==typeof t?new k(l,t):t),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,s){let i=new T(this,t,e,s);for(let r of this.wrappers)i=r(i,t,e,s);return i}getGoto(t,e,s=!1){let i=this.goto;if(e>=i[0])return-1;for(let r=i[e+1];;){let e=i[r++],h=1&e,n=i[r++];if(h&&s)return n;for(let s=r+(e>>1);r<s;r++)if(i[r]==t)return n;if(h)return-1}}hasAction(t,e){let s=this.data;for(let i=0;i<2;i++)for(let r,h=this.stateSlot(t,i?2:1);;h+=3){if(65535==(r=s[h])){if(1!=s[h+1]){if(2==s[h+1])return D(s,h+2);break}r=s[h=D(s,h+2)]}if(r==e||0==r)return D(s,h+1)}return 0}stateSlot(t,e){return this.states[6*t+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,t=>t==e||null)}allActions(t,e){let s=this.stateSlot(t,4),i=s?e(s):void 0;for(let s=this.stateSlot(t,1);null==i;s+=3){if(65535==this.data[s]){if(1!=this.data[s+1])break;s=D(this.data,s+2)}i=e(D(this.data,s+1))}return i}nextStates(t){let e=[];for(let s=this.stateSlot(t,1);;s+=3){if(65535==this.data[s]){if(1!=this.data[s+1])break;s=D(this.data,s+2)}if(!(1&this.data[s+2])){let t=this.data[s+1];e.some((e,s)=>1&s&&e==t)||e.push(this.data[s],t)}}return e}configure(t){let e=Object.assign(Object.create(I.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let s=this.topRules[t.top];if(!s)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=s}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(e=>{let s=t.tokenizers.find(t=>t.from==e);return s?s.to:e})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,i)=>{let r=t.specializers.find(t=>t.from==s.external);if(!r)return s;let h=Object.assign(Object.assign({},s),{external:r.to});return e.specializers[i]=B(h),h})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),null!=t.strict&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),null!=t.bufferLength&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return null==e?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),s=e.map(()=>!1);if(t)for(let i of t.split(" ")){let t=e.indexOf(i);t>=0&&(s[t]=!0)}let i=null;for(let t=0;t<e.length;t++)if(!s[t])for(let s,r=this.dialects[e[t]];65535!=(s=this.data[r++]);)(i||(i=new Uint8Array(this.maxTerm+1)))[s]=1;return new R(t,s,i)}static deserialize(t){return new I(t)}}function D(t,e){return t[e]|t[e+1]<<16}function B(t){if(t.external){let e=t.extend?1:0;return(s,i)=>t.external(s,i)<<1|e}return t.get}export{z as ContextTracker,m as ExternalTokenizer,d as InputStream,I as LRParser,g as LocalTokenGroup,o as Stack};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getPanel as e,activateHover as t,showPanel as i,EditorView as o,Decoration as n,ViewPlugin as s,gutter as l,showTooltip as r,hoverTooltip as a,GutterMarker as c,WidgetType as d,logException as f}from"@codemirror/view";import{RangeSet as u,StateEffect as m,StateField as h,Facet as g,combineConfig as p,RangeSetBuilder as v}from"@codemirror/state";function w(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var o in i)if(Object.prototype.hasOwnProperty.call(i,o)){var n=i[o];"string"==typeof n?e.setAttribute(o,n):null!=n&&(e[o]=n)}t++}for(;t<arguments.length;t++)b(e,arguments[t]);return e}function b(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var i=0;i<t.length;i++)b(e,t[i])}}class k{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class x{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let o=i.facet(H).markerFilter;o&&(e=o(e,i));let s=e.slice().sort((e,t)=>e.from-t.from||e.to-t.to),l=new v,r=[],a=0,c=i.doc.iter(),d=0,f=i.doc.length;for(let e=0;;){let t,i,o=e==s.length?null:s[e];if(!o&&!r.length)break;if(r.length)t=a,i=r.reduce((e,t)=>Math.min(e,t.to),o&&o.from>t?o.from:1e8);else{if(t=o.from,t>f)break;i=o.to,r.push(o),e++}for(;e<s.length;){let o=s[e];if(o.from!=t||!(o.to>o.from||o.to==t)){i=Math.min(o.from,i);break}r.push(o),e++,i=Math.min(o.to,i)}i=Math.min(i,f);let u=!1;if(r.some(e=>e.from==t&&(e.to==i||i==f))&&(u=t==i,!u&&i-t<10)){let e=t-(d+c.value.length);e>0&&(c.next(e),d=t);for(let e=t;;){if(e>=i){u=!0;break}if(!c.lineBreak&&d+c.value.length>e)break;e=d+c.value.length,d+=c.value.length,c.next()}}let m=W(r);if(u)l.add(t,t,n.widget({widget:new Y(m),diagnostics:r.slice()}));else{let e=r.reduce((e,t)=>t.markClass?e+" "+t.markClass:e,"");l.add(t,i,n.mark({class:"cm-lintRange cm-lintRange-"+m+e,diagnostics:r.slice(),inclusiveEnd:r.some(e=>e.to>i)}))}if(a=i,a==f)break;for(let e=0;e<r.length;e++)r[e].to<=a&&r.splice(e--,1)}let u=l.finish();return new x(u,t,y(u))}}function y(e,t=null,i=0){let o=null;return e.between(i,1e9,(e,i,{spec:n})=>{if(!(t&&n.diagnostics.indexOf(t)<0))if(o){if(n.diagnostics.indexOf(o.diagnostic)<0)return!1;o=new k(o.from,i,o.diagnostic)}else o=new k(e,i,t||n.diagnostics[0])}),o}function C(e,t){let i=t.pos,o=t.end||i,n=e.state.facet(H).hideOn(e,i,o);if(null!=n)return n;let s=e.startState.doc.lineAt(t.pos);return!(!e.effects.some(e=>e.is(S))&&!e.changes.touchesRange(s.from,Math.max(s.to,o)))}function T(e,t){return e.field(M,!1)?t:t.concat(m.appendConfig.of(ae))}function R(e,t){return{effects:T(e,[S.of(t)])}}const S=m.define(),A=m.define(),L=m.define(),M=h.define({create:()=>new x(n.none,null,null),update(e,t){if(t.docChanged&&e.diagnostics.size){let i=e.diagnostics.map(t.changes),o=null,n=e.panel;if(e.selected){let n=t.changes.mapPos(e.selected.from,1);o=y(i,e.selected.diagnostic,n)||y(i,null,n)}!i.size&&n&&t.state.facet(H).autoPanel&&(n=null),e=new x(i,n,o)}for(let i of t.effects)if(i.is(S)){let o=t.state.facet(H).autoPanel?i.value.length?_.open:null:e.panel;e=x.init(i.value,o,t.state)}else i.is(A)?e=new x(e.diagnostics,i.value?_.open:null,e.selected):i.is(L)&&(e=new x(e.diagnostics,e.panel,i.value));return e},provide:e=>[i.from(e,e=>e.panel),o.decorations.from(e,e=>e.diagnostics)]});function I(e){let t=e.field(M,!1);return t?t.diagnostics.size:0}const P=n.mark({class:"cm-lintRange cm-lintRange-active"});function O(e,t,i){let o,{diagnostics:n}=e.state.field(M),s=-1,l=-1;n.between(t-(i<0?1:0),t+(i>0?1:0),(e,n,{spec:r})=>{if(t>=e&&t<=n&&(e==n||(t>e||i>0)&&(t<n||i<0)))return o=r.diagnostics,s=e,l=n,!1});let r=e.state.facet(H).tooltipFilter;return o&&r&&(o=r(o,e.state)),o?{pos:s,end:l,above:!0,create:()=>({dom:B(e,o)})}:null}function B(e,t){return w("ul",{class:"cm-tooltip-lint"},t.map(t=>V(e,t,!1)))}const D=t=>{let i=t.state.field(M,!1);i&&i.panel||t.dispatch({effects:T(t.state,[A.of(!0)])});let o=e(t,_.open);return o&&o.dom.querySelector(".cm-panel-lint ul").focus(),!0},F=e=>{let t=e.state.field(M,!1);return!(!t||!t.panel)&&(e.dispatch({effects:A.of(!1)}),!0)},E=e=>{let i=e.state.field(M,!1);if(!i)return!1;let o=e.state.selection.main,n=y(i.diagnostics,null,o.to+1);return!(!n&&(n=y(i.diagnostics,null,0),!n||n.from==o.from&&n.to==o.to))&&(e.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),t(e,n.from,1,{tooltip:re,until:e=>e.docChanged||e.newSelection.main.head<n.from||e.newSelection.main.head>n.to}),!0)},z=e=>{var i;let{state:o}=e,n=o.field(M,!1);if(!n)return!1;let s,l,r,a,c=o.selection.main;if(n.diagnostics.between(0,o.doc.length,(e,t)=>{t<c.to&&(null==s||s<e)&&(s=e,l=t),(null==r||e>r)&&(r=e,a=t)}),null==r||null==s&&r==c.from)return!1;let d=null!=s?s:r,f=null!==(i=null!=l?l:a)&&void 0!==i?i:d;return e.dispatch({selection:{anchor:d,head:f},scrollIntoView:!0}),t(e,d,1,{tooltip:re,until:e=>e.docChanged||e.newSelection.main.head<d||e.newSelection.main.head>f}),!0},$=[{key:"Mod-Shift-m",run:D,preventDefault:!0},{key:"F8",run:E}],j=s.fromClass(class{constructor(e){this.view=e,this.timeout=-1,this.set=!0;let{delay:t}=e.state.facet(H);this.lintTime=Date.now()+t,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let e=Date.now();if(e<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-e);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(H);t.length&&function(e,t,i){let o=[],n=-1;for(let s of e)s.then(i=>{o.push(i),clearTimeout(n),o.length==e.length?t(o):n=setTimeout(()=>t(o),200)},i)}(t.map(e=>Promise.resolve(e(this.view))),t=>{this.view.state.doc==e.doc&&this.view.dispatch(R(this.view.state,t.reduce((e,t)=>e.concat(t))))},e=>{f(this.view.state,e)})}}update(e){let t=e.state.facet(H);(e.docChanged||t!=e.startState.facet(H)||t.needsRefresh&&t.needsRefresh(e))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});const H=g.define({combine:e=>({sources:e.map(e=>e.source).filter(e=>null!=e),...p(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:N,tooltipFilter:N,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,o,n)=>e(i,o,n)||t(i,o,n):e:t,autoPanel:(e,t)=>e||t})})});function N(e,t){return e?t?(i,o)=>t(e(i,o),o):e:t}function q(e,t={}){return[H.of({source:e,config:t}),j,ae]}function K(e){let t=e.plugin(j);t&&t.force()}function U(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let o=i[e];if(/[a-zA-Z]/.test(o)&&!t.some(e=>e.toLowerCase()==o.toLowerCase())){t.push(o);continue e}}t.push("")}return t}function V(e,t,i){var o;let n=i?U(t.actions):[];return w("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},w("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),null===(o=t.actions)||void 0===o?void 0:o.map((i,o)=>{let s=!1,l=o=>{if(o.preventDefault(),s)return;s=!0;let n=y(e.state.field(M).diagnostics,t);n&&i.apply(e,n.from,n.to)},{name:r}=i,a=n[o]?r.indexOf(n[o]):-1,c=a<0?r:[r.slice(0,a),w("u",r.slice(a,a+1)),r.slice(a+1)];return w("button",{type:"button",class:"cm-diagnosticAction"+(i.markClass?" "+i.markClass:""),onclick:l,onmousedown:l,"aria-label":` Action: ${r}${a<0?"":` (access key "${n[o]})"`}.`},c)}),t.source&&w("div",{class:"cm-diagnosticSource"},t.source))}class Y extends d{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return w("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class Z{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=V(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class _{constructor(e){this.view=e,this.items=[];this.list=w("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(27==t.keyCode)F(this.view),this.view.focus();else if(38==t.keyCode||33==t.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==t.keyCode||34==t.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==t.keyCode)this.moveSelection(0);else if(35==t.keyCode)this.moveSelection(this.items.length-1);else if(13==t.keyCode)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],o=U(i.actions);for(let n=0;n<o.length;n++)if(o[n].toUpperCase().charCodeAt(0)==t.keyCode){let t=y(this.view.state.field(M).diagnostics,i);t&&i.actions[n].apply(e,t.from,t.to)}}}t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=w("div",{class:"cm-panel-lint"},this.list,w("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>F(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(M).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(M),i=0,o=!1,n=null,s=new Set;for(e.between(0,this.view.state.doc.length,(e,l,{spec:r})=>{for(let e of r.diagnostics){if(s.has(e))continue;s.add(e);let l,r=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==e){r=t;break}r<0?(l=new Z(this.view,e),this.items.splice(i,0,l),o=!0):(l=this.items[r],r>i&&(this.items.splice(i,r-i),o=!0)),t&&l.diagnostic==t.diagnostic?l.dom.hasAttribute("aria-selected")||(l.dom.setAttribute("aria-selected","true"),n=l):l.dom.hasAttribute("aria-selected")&&l.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)o=!0,this.items.pop();0==this.items.length&&(this.items.push(new Z(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),o=!0),n?(this.list.setAttribute("aria-activedescendant",n.id),this.view.requestMeasure({key:this,read:()=>({sel:n.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let i=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/i:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),o&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=y(this.view.state.field(M).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:L.of(t)})}static open(e){return new _(e)}}function X(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function G(e){return X(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const J=o.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:G("#f11")},".cm-lintRange-warning":{backgroundImage:G("orange")},".cm-lintRange-info":{backgroundImage:G("#999")},".cm-lintRange-hint":{backgroundImage:G("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function Q(e){return"error"==e?4:"warning"==e?3:"info"==e?2:1}function W(e){let t="hint",i=1;for(let o of e){let e=Q(o.severity);e>i&&(i=e,t=o.severity)}return t}class ee extends c{constructor(e){super(),this.diagnostics=e,this.severity=W(e)}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,o=e.state.facet(ce).tooltipFilter;return o&&(i=o(i,e.state)),i.length&&(t.onmouseover=()=>function(e,t,i){function o(){let o=e.elementAtHeight(t.getBoundingClientRect().top+5-e.documentTop);e.coordsAtPos(o.from)&&e.dispatch({effects:ne.of({pos:o.from,above:!1,clip:!1,create:()=>({dom:B(e,i),getCoords:()=>t.getBoundingClientRect()})})}),t.onmouseout=t.onmousemove=null,function(e,t){let i=o=>{let n=t.getBoundingClientRect();if(!(o.clientX>n.left-10&&o.clientX<n.right+10&&o.clientY>n.top-10&&o.clientY<n.bottom+10)){for(let e=o.target;e;e=e.parentNode)if(1==e.nodeType&&e.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",i),e.state.field(se)&&e.dispatch({effects:ne.of(null)})}};window.addEventListener("mousemove",i)}(e,t)}let{hoverTime:n}=e.state.facet(ce),s=setTimeout(o,n);t.onmouseout=()=>{clearTimeout(s),t.onmouseout=t.onmousemove=null},t.onmousemove=()=>{clearTimeout(s),s=setTimeout(o,n)}}(e,t,i)),t}}function te(e,t){let i=Object.create(null);for(let o of t){let t=e.lineAt(o.from);(i[t.from]||(i[t.from]=[])).push(o)}let o=[];for(let e in i)o.push(new ee(i[e]).range(+e));return u.of(o,!0)}const ie=l({class:"cm-gutter-lint",markers:e=>e.state.field(oe),widgetMarker:(e,t,i)=>{let o=[];return e.state.field(oe).between(i.from,i.to,(e,t,n)=>{e>i.from&&e<i.to&&o.push(...n.diagnostics)}),o.length?new ee(o):null}}),oe=h.define({create:()=>u.empty,update(e,t){e=e.map(t.changes);let i=t.state.facet(ce).markerFilter;for(let o of t.effects)if(o.is(S)){let n=o.value;i&&(n=i(n||[],t.state)),e=te(t.state.doc,n.slice(0))}return e}}),ne=m.define(),se=h.define({create:()=>null,update:(e,t)=>(e&&t.docChanged&&(e=C(t,e)?null:{...e,pos:t.changes.mapPos(e.pos)}),t.effects.reduce((e,t)=>t.is(ne)?t.value:e,e)),provide:e=>r.from(e)}),le=o.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:X('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:X('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:X('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),re=a(O,{hideOn:C}),ae=[M,o.decorations.compute([M],e=>{let{selected:t,panel:i}=e.field(M);return t&&i&&t.from!=t.to?n.set([P.range(t.from,t.to)]):n.none}),re,J],ce=g.define({combine:e=>p(e,{hoverTime:300,markerFilter:null,tooltipFilter:null})});function de(e={}){return[ce.of(e),oe,ie,le,se]}function fe(e,t){let i=e.field(M,!1);if(i&&i.diagnostics.size){let e=[],o=[],n=-1;for(let s=u.iter([i.diagnostics]);;s.next()){for(let i=0;i<e.length;i++)(!s.value||s.value.spec.diagnostics.indexOf(e[i])<0)&&(t(e[i],o[i],n),e.splice(i,1),o.splice(i--,1));if(!s.value)break;for(let t of s.value.spec.diagnostics)e.indexOf(t)<0&&(e.push(t),o.push(s.from));n=s.to}}}export{F as closeLintPanel,I as diagnosticCount,fe as forEachDiagnostic,K as forceLinting,de as lintGutter,$ as lintKeymap,q as linter,E as nextDiagnostic,D as openLintPanel,z as previousDiagnostic,R as setDiagnostics,S as setDiagnosticsEffect};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getPanel as e,showDialog as t,EditorView as r,showPanel as i,ViewPlugin as n,Decoration as s,runScopeHandlers as o}from"@codemirror/view";import{codePointAt as l,fromCodePoint as c,codePointSize as a,EditorState as h,EditorSelection as u,StateEffect as f,StateField as d,Facet as m,combineConfig as p,Prec as g,CharCategory as v,RangeSetBuilder as x,findClusterBreak as y}from"@codemirror/state";function b(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,r=arguments[1];if(r&&"object"==typeof r&&null==r.nodeType&&!Array.isArray(r)){for(var i in r)if(Object.prototype.hasOwnProperty.call(r,i)){var n=r[i];"string"==typeof n?e.setAttribute(i,n):null!=n&&(e[i]=n)}t++}for(;t<arguments.length;t++)w(e,arguments[t]);return e}function w(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var r=0;r<t.length;r++)w(e,t[r])}}const M="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class k{constructor(e,t,r=0,i=e.length,n,s){this.test=s,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(r,i),this.bufferStart=r,this.normalize=n?e=>n(M(e)):M,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return l(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=c(e),r=this.bufferStart+this.bufferPos;this.bufferPos+=a(e);let i=this.normalize(t);if(i.length)for(let e=0,n=r,s=!0;;e++){let r=i.charCodeAt(e),o=this.match(r,n,s,this.bufferPos+this.bufferStart,e==i.length-1);if(o)return this.value=o,this;if(e==i.length-1)break;s&&e<t.length&&t.charCodeAt(e)==r?n++:s=!1}}}match(e,t,r,i,n){let s=null;for(let t=0;t<this.matches.length;){let r=this.matches[t],o=!1;this.query.charCodeAt(r.index)==e&&(r.index==this.query.length-1?s={from:r.from,to:i,precise:n&&r.precise}:(r.index++,o=!0)),o?t++:this.matches.splice(t,1)}return this.query.charCodeAt(0)==e&&(1==this.query.length?s={from:t,to:i,precise:r&&n}:this.matches.push({from:t,index:1,precise:r})),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}"undefined"!=typeof Symbol&&(k.prototype[Symbol.iterator]=function(){return this});const S={from:-1,to:-1,match:/.*/.exec(""),precise:!0},q="gm"+(null==/x/.unicode?"":"u");class C{constructor(e,t,r,i=0,n=e.length){if(this.text=e,this.to=n,this.curLine="",this.done=!1,this.value=S,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new A(e,t,r,i,n);this.re=new RegExp(t,q+((null==r?void 0:r.ignoreCase)?"i":"")),this.test=null==r?void 0:r.test,this.iter=e.iter();let s=e.lineAt(i);this.curLineStart=s.from,this.matchPos=F(e,i),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let r=this.curLineStart+t.index,i=r+t[0].length;if(this.matchPos=F(this.text,i+(r==i?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<i||r>this.value.to)&&(!this.test||this.test(r,i,t)))return this.value={from:r,to:i,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),e=0}}}}const L=new WeakMap;class W{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,r){let i=L.get(e);if(!i||i.from>=r||i.to<=t){let i=new W(t,e.sliceString(t,r));return L.set(e,i),i}if(i.from==t&&i.to==r)return i;let{text:n,from:s}=i;return s>t&&(n=e.sliceString(t,s)+n,s=t),i.to<r&&(n+=e.sliceString(i.to,r)),L.set(e,new W(s,n)),new W(t,n.slice(t-s,r-s))}}class A{constructor(e,t,r,i,n){this.text=e,this.to=n,this.done=!1,this.value=S,this.matchPos=F(e,i),this.re=new RegExp(t,q+((null==r?void 0:r.ignoreCase)?"i":"")),this.test=null==r?void 0:r.test,this.flat=W.get(e,i,this.chunkEnd(i+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,r=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,r,t)))return this.value={from:e,to:r,precise:!0,match:t},this.matchPos=F(this.text,r+(e==r?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=W.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function F(e,t){if(t>=e.length)return t;let r,i=e.lineAt(t);for(;t<i.to&&(r=i.text.charCodeAt(t-i.from))>=56320&&r<57344;)t++;return t}"undefined"!=typeof Symbol&&(C.prototype[Symbol.iterator]=A.prototype[Symbol.iterator]=function(){return this});const D=e=>{let{state:i}=e,n=String(i.doc.lineAt(e.state.selection.main.head).number),{close:s,result:o}=t(e,{label:i.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:i.phrase("go")});return o.then(t=>{let n=t&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.elements.line.value);if(!n)return void e.dispatch({effects:s});let o=i.doc.lineAt(i.selection.main.head),[,l,c,a,h]=n,f=a?+a.slice(1):0,d=c?+c:o.number;if(c&&h){let e=d/100;l&&(e=e*("-"==l?-1:1)+o.number/i.doc.lines),d=Math.round(i.doc.lines*e)}else c&&l&&(d=d*("-"==l?-1:1)+o.number);let m=i.doc.line(Math.max(1,Math.min(i.doc.lines,d))),p=u.cursor(m.from+Math.max(0,Math.min(f,m.length)));e.dispatch({effects:[s,r.scrollIntoView(p.from,{y:"center"})],selection:p})}),!0},R={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},E=m.define({combine:e=>p(e,R,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});function P(e){let t=[T,O];return e&&t.push(E.of(e)),t}const I=s.mark({class:"cm-selectionMatch"}),$=s.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function z(e,t,r,i){return!(0!=r&&e(t.sliceDoc(r-1,r))==v.Word||i!=t.doc.length&&e(t.sliceDoc(i,i+1))==v.Word)}const O=n.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(E),{state:r}=e,i=r.selection;if(i.ranges.length>1)return s.none;let n,o=i.main,l=null;if(o.empty){if(!t.highlightWordAroundCursor)return s.none;let e=r.wordAt(o.head);if(!e)return s.none;l=r.charCategorizer(o.head),n=r.sliceDoc(e.from,e.to)}else{let e=o.to-o.from;if(e<t.minSelectionLength||e>200)return s.none;if(t.wholeWords){if(n=r.sliceDoc(o.from,o.to),l=r.charCategorizer(o.head),!z(l,r,o.from,o.to)||!function(e,t,r,i){return e(t.sliceDoc(r,r+1))==v.Word&&e(t.sliceDoc(i-1,i))==v.Word}(l,r,o.from,o.to))return s.none}else if(n=r.sliceDoc(o.from,o.to),!n)return s.none}let c=[];for(let i of e.visibleRanges){let e=new k(r.doc,n,i.from,i.to);for(;!e.next().done;){let{from:i,to:n}=e.value;if((!l||z(l,r,i,n))&&(o.empty&&i<=o.from&&n>=o.to?c.push($.range(i,n)):(i>=o.to||n<=o.from)&&c.push(I.range(i,n)),c.length>t.maxMatches))return s.none}}return s.set(c)}},{decorations:e=>e.decorations}),T=r.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const V=({state:e,dispatch:t})=>{let{ranges:i}=e.selection;if(i.some(e=>e.from===e.to))return(({state:e,dispatch:t})=>{let{selection:r}=e,i=u.create(r.ranges.map(t=>e.wordAt(t.head)||u.cursor(t.head)),r.mainIndex);return!i.eq(r)&&(t(e.update({selection:i})),!0)})({state:e,dispatch:t});let n=e.sliceDoc(i[0].from,i[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=n))return!1;let s=function(e,t){let{main:r,ranges:i}=e.selection,n=e.wordAt(r.head),s=n&&n.from==r.from&&n.to==r.to;for(let r=!1,n=new k(e.doc,t,i[i.length-1].to);;){if(n.next(),!n.done){if(r&&i.some(e=>e.from==n.value.from))continue;if(s){let t=e.wordAt(n.value.from);if(!t||t.from!=n.value.from||t.to!=n.value.to)continue}return n.value}if(r)return null;n=new k(e.doc,t,0,Math.max(0,i[i.length-1].from-1)),r=!0}}(e,n);return!!s&&(t(e.update({selection:e.selection.addRange(u.range(s.from,s.to),!1),effects:r.scrollIntoView(s.to)})),!0)},j=m.define({combine:e=>p(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new be(e),scrollToMatch:e=>r.scrollIntoView(e)})});function K(e){return e?[j.of(e),Ce]:Ce}class N{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||function(e){try{return new RegExp(e,q),!0}catch(e){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>"n"==t?"\n":"r"==t?"\r":"t"==t?"\t":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new X(this):new G(this)}getCursor(e,t=0,r){let i=e.doc?e:h.create({doc:e});return null==r&&(r=i.doc.length),this.regexp?U(this,i,t,r):B(this,i,t,r)}}class Q{constructor(e){this.spec=e}}function B(e,t,r,i){let n;var s,o;return e.wholeWord&&(s=t.doc,o=t.charCategorizer(t.selection.main.head),n=(e,t,r,i)=>((i>e||i+r.length<t)&&(i=Math.max(0,e-2),r=s.sliceString(i,Math.min(s.length,t+2))),!(o(H(r,e-i))==v.Word&&o(J(r,e-i))==v.Word||o(J(r,t-i))==v.Word&&o(H(r,t-i))==v.Word))),e.test&&(n=function(e,t,r){return(i,n,s,o)=>{if(r&&!r(i,n,s,o))return!1;let l=i>=o&&n<=o+s.length?s.slice(i-o,n-o):t.doc.sliceString(i,n);return e(l,t,i,n)}}(e.test,t,n)),new k(t.doc,e.unquoted,r,i,e.caseSensitive?void 0:e=>e.toLowerCase(),n)}class G extends Q{constructor(e){super(e)}nextMatch(e,t,r){let i=B(this.spec,e,r,e.doc.length).nextOverlapping();if(i.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);i=B(this.spec,e,0,r).nextOverlapping()}return i.done||i.value.from==t&&i.value.to==r?null:i.value}prevMatchInRange(e,t,r){for(let i=r;;){let r=Math.max(t,i-1e4-this.spec.unquoted.length),n=B(this.spec,e,r,i),s=null;for(;!n.nextOverlapping().done;)s=n.value;if(s)return s;if(r==t)return null;i-=1e4}}prevMatch(e,t,r){let i=this.prevMatchInRange(e,0,t);return i||(i=this.prevMatchInRange(e,Math.max(0,r-this.spec.unquoted.length),e.doc.length)),!i||i.from==t&&i.to==r?null:i}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let r=B(this.spec,e,0,e.doc.length),i=[];for(;!r.next().done;){if(i.length>=t)return null;i.push(r.value)}return i}highlight(e,t,r,i){let n=B(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,e.doc.length));for(;!n.next().done;)i(n.value.from,n.value.to)}}function U(e,t,r,i){let n;var s;return e.wholeWord&&(s=t.charCategorizer(t.selection.main.head),n=(e,t,r)=>!r[0].length||(s(H(r.input,r.index))!=v.Word||s(J(r.input,r.index))!=v.Word)&&(s(J(r.input,r.index+r[0].length))!=v.Word||s(H(r.input,r.index+r[0].length))!=v.Word)),e.test&&(n=function(e,t,r){return(i,n,s)=>(!r||r(i,n,s))&&e(s[0],t,i,n)}(e.test,t,n)),new C(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:n},r,i)}function H(e,t){return e.slice(y(e,t,!1),t)}function J(e,t){return e.slice(t,y(e,t))}class X extends Q{nextMatch(e,t,r){let i=U(this.spec,e,r,e.doc.length).next();return i.done&&(i=U(this.spec,e,0,t).next()),i.done?null:i.value}prevMatchInRange(e,t,r){for(let i=1;;i++){let n=Math.max(t,r-1e4*i),s=U(this.spec,e,n,r),o=null;for(;!s.next().done;)o=s.value;if(o&&(n==t||o.from>n+10))return o;if(n==t)return null}}prevMatch(e,t,r){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,r,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,r)=>{if("&"==r)return e.match[0];if("$"==r)return"$";for(let t=r.length;t>0;t--){let i=+r.slice(0,t);if(i>0&&i<e.match.length)return e.match[i]+r.slice(t)}return t})}matchAll(e,t){let r=U(this.spec,e,0,e.doc.length),i=[];for(;!r.next().done;){if(i.length>=t)return null;i.push(r.value)}return i}highlight(e,t,r,i){let n=U(this.spec,e,Math.max(0,t-250),Math.min(r+250,e.doc.length));for(;!n.next().done;)i(n.value.from,n.value.to)}}const Y=f.define(),Z=f.define(),_=d.define({create:e=>new re(me(e).create(),null),update(e,t){for(let r of t.effects)r.is(Y)?e=new re(r.value.create(),e.panel):r.is(Z)&&(e=new re(e.query,r.value?de:null));return e},provide:e=>i.from(e,e=>e.panel)});function ee(e){let t=e.field(_,!1);return t?t.query.spec:me(e)}function te(e){var t;return null!=(null===(t=e.field(_,!1))||void 0===t?void 0:t.panel)}class re{constructor(e,t){this.query=e,this.panel=t}}const ie=s.mark({class:"cm-searchMatch"}),ne=s.mark({class:"cm-searchMatch cm-searchMatch-selected"}),se=n.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(_))}update(e){let t=e.state.field(_);(t!=e.startState.field(_)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return s.none;let{view:r}=this,i=new x;for(let t=0,n=r.visibleRanges,s=n.length;t<s;t++){let{from:o,to:l}=n[t];for(;t<s-1&&l>n[t+1].from-500;)l=n[++t].to;e.highlight(r.state,o,l,(e,t)=>{let n=r.state.selection.ranges.some(r=>r.from==e&&r.to==t);i.add(e,t,n?ne:ie)})}return i.finish()}},{decorations:e=>e.decorations});function oe(e){return t=>{let r=t.state.field(_,!1);return r&&r.query.spec.valid?e(t,r):ve(t)}}const le=oe((e,{query:t})=>{let{to:r}=e.state.selection.main,i=t.nextMatch(e.state,r,r);if(!i)return!1;let n=u.single(i.from,i.to),s=e.state.facet(j);return e.dispatch({selection:n,effects:[Se(e,i),s.scrollToMatch(n.main,e)],userEvent:"select.search"}),ge(e),!0}),ce=oe((e,{query:t})=>{let{state:r}=e,{from:i}=r.selection.main,n=t.prevMatch(r,i,i);if(!n)return!1;let s=u.single(n.from,n.to),o=e.state.facet(j);return e.dispatch({selection:s,effects:[Se(e,n),o.scrollToMatch(s.main,e)],userEvent:"select.search"}),ge(e),!0}),ae=oe((e,{query:t})=>{let r=t.matchAll(e.state,1e3);return!(!r||!r.length)&&(e.dispatch({selection:u.create(r.map(e=>u.range(e.from,e.to))),userEvent:"select.search.matches"}),!0)}),he=({state:e,dispatch:t})=>{let r=e.selection;if(r.ranges.length>1||r.main.empty)return!1;let{from:i,to:n}=r.main,s=[],o=0;for(let t=new k(e.doc,e.sliceDoc(i,n));!t.next().done;){if(s.length>1e3)return!1;t.value.from==i&&(o=s.length),s.push(u.range(t.value.from,t.value.to))}return t(e.update({selection:u.create(s,o),userEvent:"select.search.matches"})),!0},ue=oe((e,{query:t})=>{let{state:i}=e,{from:n,to:s}=i.selection.main;if(i.readOnly)return!1;let o=t.nextMatch(i,n,n);if(!o)return!1;let l,c,a=o,h=[],f=[];a.precise?a.from==n&&a.to==s&&(c=i.toText(t.getReplacement(a)),h.push({from:a.from,to:a.to,insert:c}),a=t.nextMatch(i,a.from,a.to),f.push(r.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+"."))):a=t.nextMatch(i,a.from,a.to);let d=e.state.changes(h);return a&&(l=u.single(a.from,a.to).map(d),f.push(Se(e,a)),f.push(i.facet(j).scrollToMatch(l.main,e))),e.dispatch({changes:d,selection:l,effects:f,userEvent:"input.replace"}),!0}),fe=oe((e,{query:t})=>{if(e.state.readOnly)return!1;let i=[];for(let r of t.matchAll(e.state,1e9)){let{from:e,to:n,precise:s}=r;s&&i.push({from:e,to:n,insert:t.getReplacement(r)})}if(!i.length)return!1;let n=e.state.phrase("replaced $ matches",i.length)+".";return e.dispatch({changes:i,effects:r.announce.of(n),userEvent:"input.replace.all"}),!0});function de(e){return e.state.facet(j).createPanel(e)}function me(e,t){var r,i,n,s,o;let l=e.selection.main,c=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!c)return t;let a=e.facet(j);return new N({search:(null!==(r=null==t?void 0:t.literal)&&void 0!==r?r:a.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:null!==(i=null==t?void 0:t.caseSensitive)&&void 0!==i?i:a.caseSensitive,literal:null!==(n=null==t?void 0:t.literal)&&void 0!==n?n:a.literal,regexp:null!==(s=null==t?void 0:t.regexp)&&void 0!==s?s:a.regexp,wholeWord:null!==(o=null==t?void 0:t.wholeWord)&&void 0!==o?o:a.wholeWord})}function pe(t){let r=e(t,de);return r&&r.dom.querySelector("[main-field]")}function ge(e){let t=pe(e);t&&t==e.root.activeElement&&t.select()}const ve=e=>{let t=e.state.field(_,!1);if(t&&t.panel){let r=pe(e);if(r&&r!=e.root.activeElement){let i=me(e.state,t.query.spec);i.valid&&e.dispatch({effects:Y.of(i)}),r.focus(),r.select()}}else e.dispatch({effects:[Z.of(!0),t?Y.of(me(e.state,t.query.spec)):f.appendConfig.of(Ce)]});return!0},xe=t=>{let r=t.state.field(_,!1);if(!r||!r.panel)return!1;let i=e(t,de);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Z.of(!1)}),!0},ye=[{key:"Mod-f",run:ve,scope:"editor search-panel"},{key:"F3",run:le,shift:ce,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:le,shift:ce,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:xe,scope:"editor search-panel"},{key:"Mod-Shift-l",run:he},{key:"Mod-Alt-g",run:D},{key:"Mod-d",run:V,preventDefault:!0}];class be{constructor(e){this.view=e;let t=this.query=e.state.field(_).query.spec;function r(e,t,r){return b("button",{class:"cm-button",name:e,onclick:t,type:"button"},r)}this.commit=this.commit.bind(this),this.searchField=b("input",{value:t.search,placeholder:we(e,"Find"),"aria-label":we(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=b("input",{value:t.replace,placeholder:we(e,"Replace"),"aria-label":we(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=b("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=b("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=b("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=b("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,r("next",()=>le(e),[we(e,"next")]),r("prev",()=>ce(e),[we(e,"previous")]),r("select",()=>ae(e),[we(e,"all")]),b("label",null,[this.caseField,we(e,"match case")]),b("label",null,[this.reField,we(e,"regexp")]),b("label",null,[this.wordField,we(e,"by word")]),...e.state.readOnly?[]:[b("br"),this.replaceField,r("replace",()=>ue(e),[we(e,"replace")]),r("replaceAll",()=>fe(e),[we(e,"replace all")])],b("button",{name:"close",onclick:()=>xe(e),"aria-label":we(e,"close"),type:"button"},["×"])])}commit(){let e=new N({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Y.of(e)}))}keydown(e){o(this.view,e,"search-panel")?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?ce:le)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),ue(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(Y)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(j).top}}function we(e,t){return e.state.phrase(t)}const Me=30,ke=/[\s\.,:;?!]/;function Se(e,{from:t,to:i}){let n=e.state.doc.lineAt(t),s=e.state.doc.lineAt(i).to,o=Math.max(n.from,t-Me),l=Math.min(s,i+Me),c=e.state.sliceDoc(o,l);if(o!=n.from)for(let e=0;e<Me;e++)if(!ke.test(c[e+1])&&ke.test(c[e])){c=c.slice(e);break}if(l!=s)for(let e=c.length-1;e>c.length-Me;e--)if(!ke.test(c[e-1])&&ke.test(c[e])){c=c.slice(0,e);break}return r.announce.of(`${e.state.phrase("current match")}. ${c} ${e.state.phrase("on line")} ${n.number}.`)}const qe=r.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Ce=[_,g.low(se),qe];export{C as RegExpCursor,k as SearchCursor,N as SearchQuery,xe as closeSearchPanel,le as findNext,ce as findPrevious,ee as getSearchQuery,D as gotoLine,P as highlightSelectionMatches,ve as openSearchPanel,fe as replaceAll,ue as replaceNext,K as search,ye as searchKeymap,te as searchPanelOpen,ae as selectMatches,V as selectNextOccurrence,he as selectSelectionMatches,Y as setSearchQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let t=[],e=[];function n(n){if(n<768)return!1;for(let i=0,s=t.length;;){let r=i+s>>1;if(n<t[r])s=r;else{if(!(n>=e[r]))return!0;i=r+1}if(i==s)return!1}}function i(t){return t>=127462&&t<=127487}(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let i=0,s=0;i<n.length;i++)(i%2?e:t).push(s+=n[i])})();function s(t,e,n=!0,i=!0){return(n?r:h)(t,e,i)}function r(t,e,s){if(e==t.length)return e;e&&l(t.charCodeAt(e))&&a(t.charCodeAt(e-1))&&e--;let r=o(t,e);for(e+=c(r);e<t.length;){let h=o(t,e);if(8205==r||8205==h||s&&n(h))e+=c(h),r=h;else{if(!i(h))break;{let n=0,s=e-2;for(;s>=0&&i(o(t,s));)n++,s-=2;if(n%2==0)break;e+=2}}}return e}function h(t,e,n){for(;e>1;){let i=r(t,e-2,n);if(i<e)return i;e--}return 0}function o(t,e){let n=t.charCodeAt(e);if(!a(n)||e+1==t.length)return n;let i=t.charCodeAt(e+1);return l(i)?i-56320+(n-55296<<10)+65536:n}function l(t){return t>=56320&&t<57344}function a(t){return t>=55296&&t<56320}function c(t){return t<65536?1:2}class f{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,n){[t,e]=k(this,t,e);let i=[];return this.decompose(0,t,i,2),n.length&&n.decompose(0,n.length,i,3),this.decompose(e,this.length,i,1),g.from(i,this.length-(e-t)+n.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=k(this,t,e);let n=[];return this.decompose(t,e,n,0),g.from(n,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 m(this),s=new m(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 m(this,t)}iterRange(t,e=this.length){return new v(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 x(n)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(0==t.length)throw new RangeError("A document must have at least one line");return 1!=t.length||t[0]?t.length<=32?new u(t):g.from(u.split(t,[])):f.empty}}class u extends f{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 w(i,h,n,r);i=h+1,n++}}decompose(t,e,n,i){let s=t<=0&&e>=this.length?this:new u(p(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&i){let t=n.pop(),e=d(s.text,t.text.slice(),0,s.length);if(e.length<=32)n.push(new u(e,t.length+s.length));else{let t=e.length>>1;n.push(new u(e.slice(0,t)),new u(e.slice(t)))}}else n.push(s)}replace(t,e,n){if(!(n instanceof u))return super.replace(t,e,n);[t,e]=k(this,t,e);let i=d(this.text,d(n.text,p(this.text,0,t)),e),s=this.length+n.length-(e-t);return i.length<=32?new u(i,s):g.from(u.split(i,[]),s)}sliceString(t,e=this.length,n="\n"){[t,e]=k(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,e){let n=[],i=-1;for(let s of t)n.push(s),i+=s.length+1,32==n.length&&(e.push(new u(n,i)),n=[],i=-1);return i>-1&&e.push(new u(n,i)),e}}class g extends f{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,n){if([t,e]=k(this,t,e),n.lines<this.lines)for(let i=0,s=0;i<this.children.length;i++){let r=this.children[i],h=s+r.length;if(t>=s&&e<=h){let o=r.replace(t-s,e-s,n),l=this.lines-r.lines+o.lines;if(o.lines<l>>4&&o.lines>l>>6){let s=this.children.slice();return s[i]=o,new g(s,this.length-(e-t)+n.length)}return super.replace(s,h,o)}s=h+1}return super.replace(t,e,n)}sliceString(t,e=this.length,n="\n"){[t,e]=k(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 g))return 0;let n=0,[i,s,r,h]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=e,s+=e){if(i==r||s==h)return n;let o=this.children[i],l=t.children[s];if(o!=l)return n+o.scanIdentical(l,e);n+=o.length+1}}static from(t,e=t.reduce((t,e)=>t+e.length+1,-1)){let n=0;for(let e of t)n+=e.lines;if(n<32){let n=[];for(let e of t)e.flatten(n);return new u(n,e)}let i=Math.max(32,n>>5),s=i<<1,r=i>>1,h=[],o=0,l=-1,a=[];function c(t){let e;if(t.lines>s&&t instanceof g)for(let e of t.children)c(e);else t.lines>r&&(o>r||!o)?(f(),h.push(t)):t instanceof u&&o&&(e=a[a.length-1])instanceof u&&t.lines+e.lines<=32?(o+=t.lines,l+=t.length+1,a[a.length-1]=new u(e.text.concat(t.text),e.length+1+t.length)):(o+t.lines>i&&f(),o+=t.lines,l+=t.length+1,a.push(t))}function f(){0!=o&&(h.push(1==a.length?a[0]:g.from(a,l)),l=-1,o=a.length=0)}for(let e of t)c(e);return f(),1==h.length?h[0]:new g(h,e)}}function d(t,e,n=0,i=1e9){for(let s=0,r=0,h=!0;r<t.length&&s<=i;r++){let o=t[r],l=s+o.length;l>=n&&(l>i&&(o=o.slice(0,i-s)),s<n&&(o=o.slice(n-s)),h?(e[e.length-1]+=o,h=!1):e.push(o)),s=l+1}return e}function p(t,e,n){return d(t,[""],e,n)}f.empty=new u([""],0);class m{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof u?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,i=this.nodes[n],s=this.offsets[n],r=s>>1,h=i instanceof u?i.text.length:i.children.length;if(r==(e>0?h:0)){if(0==n)return this.done=!0,this.value="",this;e>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&s)==(e>0?0:1)){if(this.offsets[n]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(i instanceof u){let s=i.text[r+(e<0?-1:0)];if(this.offsets[n]+=e,s.length>Math.max(0,t))return this.value=0==t?s:e>0?s.slice(t):s.slice(0,s.length-t),this;t-=s.length}else{let s=i.children[r+(e<0?-1:0)];t>s.length?(t-=s.length,this.offsets[n]+=e):(e<0&&this.offsets[n]--,this.nodes.push(s),this.offsets.push(e>0?1:(s instanceof u?s.text.length:s.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class v{constructor(t,e,n){this.value="",this.done=!1,this.cursor=new m(t,e>n?-1:1),this.pos=e>n?t.length:0,this.from=Math.min(e,n),this.to=Math.max(e,n)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let n=e<0?this.pos-this.from:this.to-this.pos;t>n&&(t=n),n-=t;let{value:i}=this.cursor.next(t);return this.pos+=(i.length+t)*e,this.value=i.length<=n?i:e<0?i.slice(i.length-n):i.slice(0,n),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class x{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:n,value:i}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):n?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=i,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(f.prototype[Symbol.iterator]=function(){return this.iter()},m.prototype[Symbol.iterator]=v.prototype[Symbol.iterator]=x.prototype[Symbol.iterator]=function(){return this});class w{constructor(t,e,n,i){this.from=t,this.to=e,this.number=n,this.text=i}get length(){return this.to-this.from}}function k(t,e,n){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,n))]}function y(t,e,n=!0,i=!0){return s(t,e,n,i)}function S(t,e){let n=t.charCodeAt(e);if(!(i=n,i>=55296&&i<56320&&e+1!=t.length))return n;var i;let s=t.charCodeAt(e+1);return function(t){return t>=56320&&t<57344}(s)?s-56320+(n-55296<<10)+65536:n}function I(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function b(t){return t<65536?1:2}const P=/\r\n?|\n/;var E=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(E||(E={}));class M{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let n=this.sections[e+1];t+=n<0?this.sections[e]:n}return t}get empty(){return 0==this.sections.length||2==this.sections.length&&this.sections[1]<0}iterGaps(t){for(let e=0,n=0,i=0;e<this.sections.length;){let s=this.sections[e++],r=this.sections[e++];r<0?(t(n,i,s),i+=s):i+=r,n+=s}}iterChangedRanges(t,e=!1){C(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],i=this.sections[e++];i<0?t.push(n,i):t.push(i,n)}return new M(t)}composeDesc(t){return this.empty?t:t.empty?this:N(this,t)}mapDesc(t,e=!1){return t.empty?this:T(this,t,e)}mapPos(t,e=-1,n=E.Simple){let i=0,s=0;for(let r=0;r<this.sections.length;){let h=this.sections[r++],o=this.sections[r++],l=i+h;if(o<0){if(l>t)return s+(t-i);s+=h}else{if(n!=E.Simple&&l>=t&&(n==E.TrackDel&&i<t&&l>t||n==E.TrackBefore&&i<t||n==E.TrackAfter&&l>t))return null;if(l>t||l==t&&e<0&&!h)return t==i||e<0?s:s+o;s+=o}i=l}if(t>i)throw new RangeError(`Position ${t} is out of range for changeset of length ${i}`);return s}touchesRange(t,e=t){for(let n=0,i=0;n<this.sections.length&&i<=e;){let s=i+this.sections[n++];if(this.sections[n++]>=0&&i<=e&&s>=t)return!(i<t&&s>e)||"cover";i=s}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let n=this.sections[e++],i=this.sections[e++];t+=(t?" ":"")+n+(i>=0?":"+i:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(t=>"number"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeDesc");return new M(t)}static create(t){return new M(t)}}class A extends M{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return C(this,(e,n,i,s,r)=>t=t.replace(i,i+(n-e),r),!1),t}mapDesc(t,e=!1){return T(this,t,e,!0)}invert(t){let e=this.sections.slice(),n=[];for(let i=0,s=0;i<e.length;i+=2){let r=e[i],h=e[i+1];if(h>=0){e[i]=h,e[i+1]=r;let o=i>>1;for(;n.length<o;)n.push(f.empty);n.push(r?t.slice(s,s+r):f.empty)}s+=r}return new A(e,n)}compose(t){return this.empty?t:t.empty?this:N(this,t,!0)}map(t,e=!1){return t.empty?this:T(this,t,e,!0)}iterChanges(t,e=!1){C(this,t,e)}get desc(){return M.create(this.sections)}filter(t){let e=[],n=[],i=[],s=new F(this);t:for(let r=0,h=0;;){let o=r==t.length?1e9:t[r++];for(;h<o||h==o&&0==s.len;){if(s.done)break t;let t=Math.min(s.len,o-h);O(i,t,-1);let r=-1==s.ins?-1:0==s.off?s.ins:0;O(e,t,r),r>0&&R(n,e,s.text),s.forward(t),h+=t}let l=t[r++];for(;h<l;){if(s.done)break t;let t=Math.min(s.len,l-h);O(e,t,-1),O(i,t,-1==s.ins?-1:0==s.off?s.ins:0),s.forward(t),h+=t}}return{changes:new A(e,n),filtered:M.create(i)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let n=this.sections[e],i=this.sections[e+1];i<0?t.push(n):0==i?t.push([n]):t.push([n].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,n){let i=[],s=[],r=0,h=null;function o(t=!1){if(!t&&!i.length)return;r<e&&O(i,e-r,-1);let n=new A(i,s);h=h?h.compose(n.map(h)):n,i=[],s=[],r=0}return function t(l){if(Array.isArray(l))for(let e of l)t(e);else if(l instanceof A){if(l.length!=e)throw new RangeError(`Mismatched change set length (got ${l.length}, expected ${e})`);o(),h=h?h.compose(l.map(h)):l}else{let{from:t,to:h=t,insert:a}=l;if(t>h||t<0||h>e)throw new RangeError(`Invalid change range ${t} to ${h} (in doc of length ${e})`);let c=a?"string"==typeof a?f.of(a.split(n||P)):a:f.empty,u=c.length;if(t==h&&0==u)return;t<r&&o(),t>r&&O(i,t-r,-1),O(i,h-t,u),R(s,i,c),r=h}}(t),o(!h),h}static empty(t){return new A(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],n=[];for(let i=0;i<t.length;i++){let s=t[i];if("number"==typeof s)e.push(s,-1);else{if(!Array.isArray(s)||"number"!=typeof s[0]||s.some((t,e)=>e&&"string"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==s.length)e.push(s[0],0);else{for(;n.length<i;)n.push(f.empty);n[i]=f.of(s.slice(1)),e.push(s[0],n[i].length)}}}return new A(e,n)}static createSet(t,e){return new A(t,e)}}function O(t,e,n,i=!1){if(0==e&&n<=0)return;let s=t.length-2;s>=0&&n<=0&&n==t[s+1]?t[s]+=e:s>=0&&0==e&&0==t[s]?t[s+1]+=n:i?(t[s]+=e,t[s+1]+=n):t.push(e,n)}function R(t,e,n){if(0==n.length)return;let i=e.length-2>>1;if(i<t.length)t[t.length-1]=t[t.length-1].append(n);else{for(;t.length<i;)t.push(f.empty);t.push(n)}}function C(t,e,n){let i=t.inserted;for(let s=0,r=0,h=0;h<t.sections.length;){let o=t.sections[h++],l=t.sections[h++];if(l<0)s+=o,r+=o;else{let a=s,c=r,u=f.empty;for(;a+=o,c+=l,l&&i&&(u=u.append(i[h-2>>1])),!(n||h==t.sections.length||t.sections[h+1]<0);)o=t.sections[h++],l=t.sections[h++];e(s,a,r,c,u),s=a,r=c}}}function T(t,e,n,i=!1){let s=[],r=i?[]:null,h=new F(t),o=new F(e);for(let t=-1;;){if(h.done&&o.len||o.done&&h.len)throw new Error("Mismatched change set lengths");if(-1==h.ins&&-1==o.ins){let t=Math.min(h.len,o.len);O(s,t,-1),h.forward(t),o.forward(t)}else if(o.ins>=0&&(h.ins<0||t==h.i||0==h.off&&(o.len<h.len||o.len==h.len&&!n))){let e=o.len;for(O(s,o.ins,-1);e;){let n=Math.min(h.len,e);h.ins>=0&&t<h.i&&h.len<=n&&(O(s,0,h.ins),r&&R(r,s,h.text),t=h.i),h.forward(n),e-=n}o.next()}else{if(!(h.ins>=0)){if(h.done&&o.done)return r?A.createSet(s,r):M.create(s);throw new Error("Mismatched change set lengths")}{let e=0,n=h.len;for(;n;)if(-1==o.ins){let t=Math.min(n,o.len);e+=t,n-=t,o.forward(t)}else{if(!(0==o.ins&&o.len<n))break;n-=o.len,o.next()}O(s,e,t<h.i?h.ins:0),r&&t<h.i&&R(r,s,h.text),t=h.i,h.forward(h.len-n)}}}}function N(t,e,n=!1){let i=[],s=n?[]:null,r=new F(t),h=new F(e);for(let t=!1;;){if(r.done&&h.done)return s?A.createSet(i,s):M.create(i);if(0==r.ins)O(i,r.len,0,t),r.next();else if(0!=h.len||h.done){if(r.done||h.done)throw new Error("Mismatched change set lengths");{let e=Math.min(r.len2,h.len),n=i.length;if(-1==r.ins){let n=-1==h.ins?-1:h.off?0:h.ins;O(i,e,n,t),s&&n&&R(s,i,h.text)}else-1==h.ins?(O(i,r.off?0:r.len,e,t),s&&R(s,i,r.textBit(e))):(O(i,r.off?0:r.len,h.off?0:h.ins,t),s&&!h.off&&R(s,i,h.text));t=(r.ins>e||h.ins>=0&&h.len>e)&&(t||i.length>n),r.forward2(e),h.forward(e)}}else O(i,0,h.ins,t),s&&R(s,i,h.text),h.next()}}class F{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return-2==this.ins}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,e=this.i-2>>1;return e>=t.length?f.empty:t[e]}textBit(t){let{inserted:e}=this.set,n=this.i-2>>1;return n>=e.length&&!t?f.empty:e[n].slice(this.off,null==t?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class B{constructor(t,e,n,i){this.from=t,this.to=e,this.flags=n,this.goalColumn=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get undirectional(){return(64&this.flags)>0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}map(t,e=-1){let n,i;return this.empty?n=i=t.mapPos(this.from,e):(n=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),n==this.from&&i==this.to?this:new B(n,i,this.flags,this.goalColumn)}extend(t,e=t,n=0){if(t<=this.anchor&&e>=this.anchor)return J.range(t,e,void 0,void 0,n);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return J.range(this.anchor,i,void 0,void 0,n)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||this.goalColumn!=t.goalColumn||e&&this.empty&&this.assoc!=t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return J.range(t.anchor,t.head)}static create(t,e,n,i){return new B(t,e,n,i)}}class J{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:J.create(this.ranges.map(n=>n.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(t.ranges[n],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return 1==this.ranges.length?this:new J([this.main],0)}addRange(t,e=!0){return J.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let n=this.ranges.slice();return n[e]=t,J.create(n,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new J(t.ranges.map(t=>B.fromJSON(t)),t.main)}static single(t,e=t){return new J([J.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let n=0,i=0;i<t.length;i++){let s=t[i];if(s.empty?s.from<=n:s.from<n)return J.normalized(t.slice(),e);n=s.to}return new J(t,e)}static cursor(t,e=0,n,i){return B.create(t,t,(0==e?0:e<0?8:16)|(null==n?7:Math.min(6,n)),i)}static range(t,e,n,i,s){let r=null==i?7:Math.min(6,i);return s||t==e||(s=e<t?1:-1),s&&(r|=s<0?8:16),e<t?B.create(e,t,32|r,n):B.create(t,e,r,n)}static undirectionalRange(t,e){return B.create(t,e,64,void 0)}static normalized(t,e=0){let n=t[e];t.sort((t,e)=>t.from-e.from),e=t.indexOf(n);for(let n=1;n<t.length;n++){let i=t[n],s=t[n-1];if(i.empty?i.from<=s.to:i.from<s.to){let r=s.from,h=Math.max(i.to,s.to);n<=e&&e--,t.splice(--n,2,i.anchor>i.head?J.range(h,r):J.range(r,h))}}return new J(t,e)}}function D(t,e){for(let n of t.ranges)if(n.to>e)throw new RangeError("Selection points outside of document")}let L=0;class j{constructor(t,e,n,i,s){this.combine=t,this.compareInput=e,this.compare=n,this.isStatic=i,this.id=L++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}get reader(){return this}static define(t={}){return new j(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:$),!!t.static,t.enables)}of(t){return new q([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new q(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new q(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],n=>e(n.field(t)))}}function $(t,e){return t==e||t.length==e.length&&t.every((t,n)=>t===e[n])}class q{constructor(t,e,n,i){this.dependencies=t,this.facet=e,this.type=n,this.value=i,this.id=L++}dynamicSlot(t){var e;let n=this.value,i=this.facet.compareInput,s=this.id,r=t[s]>>1,h=2==this.type,o=!1,l=!1,a=[];for(let n of this.dependencies)"doc"==n?o=!0:"selection"==n?l=!0:1&(null!==(e=t[n.id])&&void 0!==e?e:1)||a.push(t[n.id]);return{create:t=>(t.values[r]=n(t),1),update(t,e){if(o&&e.docChanged||l&&(e.docChanged||e.selection)||V(t,a)){let e=n(t);if(h?!z(e,t.values[r],i):!i(e,t.values[r]))return t.values[r]=e,1}return 0},reconfigure:(t,e)=>{let o,l=e.config.address[s];if(null!=l){let s=st(e,l);if(this.dependencies.every(n=>n instanceof j?e.facet(n)===t.facet(n):!(n instanceof U)||e.field(n,!1)==t.field(n,!1))||(h?z(o=n(t),s,i):i(o=n(t),s)))return t.values[r]=s,0}else o=n(t);return t.values[r]=o,1}}}}function z(t,e,n){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!n(t[i],e[i]))return!1;return!0}function V(t,e){let n=!1;for(let i of e)1&it(t,i)&&(n=!0);return n}function _(t,e,n){let i=n.map(e=>t[e.id]),s=n.map(t=>t.type),r=i.filter(t=>!(1&t)),h=t[e.id]>>1;function o(t){let n=[];for(let e=0;e<i.length;e++){let r=st(t,i[e]);if(2==s[e])for(let t of r)n.push(t);else n.push(r)}return e.combine(n)}return{create(t){for(let e of i)it(t,e);return t.values[h]=o(t),1},update(t,n){if(!V(t,r))return 0;let i=o(t);return e.compare(i,t.values[h])?0:(t.values[h]=i,1)},reconfigure(t,s){let r=V(t,i),l=s.config.facets[e.id],a=s.facet(e);if(l&&!r&&$(n,l))return t.values[h]=a,0;let c=o(t);return e.compare(c,a)?(t.values[h]=a,0):(t.values[h]=c,1)}}}const W=j.define({static:!0});class U{constructor(t,e,n,i,s){this.id=t,this.createF=e,this.updateF=n,this.compareF=i,this.spec=s,this.provides=void 0}static define(t){let e=new U(L++,t.create,t.update,t.compare||((t,e)=>t===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(W).find(t=>t.field==this);return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,n)=>{let i=t.values[e],s=this.updateF(i,n);return this.compareF(i,s)?0:(t.values[e]=s,1)},reconfigure:(t,n)=>{let i,s=t.facet(W),r=n.facet(W);return(i=s.find(t=>t.field==this))&&i!=r.find(t=>t.field==this)?(t.values[e]=i.create(t),1):null!=n.config.address[this.id]?(t.values[e]=n.field(this),0):(t.values[e]=this.create(t),1)}}}init(t){return[this,W.of({field:this,create:t})]}get extension(){return this}}const G=4,H=3,K=2,Q=1;function X(t){return e=>new Z(e,t)}const Y={highest:X(0),high:X(Q),default:X(K),low:X(H),lowest:X(G)};class Z{constructor(t,e){this.inner=t,this.prec=e}}class tt{of(t){return new et(this,t)}reconfigure(t){return tt.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class et{constructor(t,e){this.compartment=t,this.inner=e}}class nt{constructor(t,e,n,i,s,r){for(this.base=t,this.compartments=e,this.dynamicSlots=n,this.address=i,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return null==e?t.default:this.staticValues[e>>1]}static resolve(t,e,n){let i=[],s=Object.create(null),r=new Map;for(let n of function(t,e,n){let i=[[],[],[],[],[]],s=new Map;function r(t,h){let o=s.get(t);if(null!=o){if(o<=h)return;let e=i[o].indexOf(t);e>-1&&i[o].splice(e,1),t instanceof et&&n.delete(t.compartment)}if(s.set(t,h),Array.isArray(t))for(let e of t)r(e,h);else if(t instanceof et){if(n.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let i=e.get(t.compartment)||t.inner;n.set(t.compartment,i),r(i,h)}else if(t instanceof Z)r(t.inner,t.prec);else if(t instanceof U)i[h].push(t),t.provides&&r(t.provides,h);else if(t instanceof q)i[h].push(t),t.facet.extensions&&r(t.facet.extensions,K);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(e,h)}}return r(t,K),i.reduce((t,e)=>t.concat(e))}(t,e,r))n instanceof U?i.push(n):(s[n.facet.id]||(s[n.facet.id]=[])).push(n);let h=Object.create(null),o=[],l=[];for(let t of i)h[t.id]=l.length<<1,l.push(e=>t.slot(e));let a=null==n?void 0:n.config.facets;for(let t in s){let e=s[t],i=e[0].facet,r=a&&a[t]||[];if(e.every(t=>0==t.type))if(h[i.id]=o.length<<1|1,$(r,e))o.push(n.facet(i));else{let t=i.combine(e.map(t=>t.value));o.push(n&&i.compare(t,n.facet(i))?n.facet(i):t)}else{for(let t of e)0==t.type?(h[t.id]=o.length<<1|1,o.push(t.value)):(h[t.id]=l.length<<1,l.push(e=>t.dynamicSlot(e)));h[i.id]=l.length<<1,l.push(t=>_(t,i,e))}}let c=l.map(t=>t(h));return new nt(t,r,c,h,o,s)}}function it(t,e){if(1&e)return 2;let n=e>>1,i=t.status[n];if(4==i)throw new Error("Cyclic dependency between fields and/or facets");if(2&i)return i;t.status[n]=4;let s=t.computeSlot(t,t.config.dynamicSlots[n]);return t.status[n]=2|s}function st(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const rt=j.define(),ht=j.define({combine:t=>t.some(t=>t),static:!0}),ot=j.define({combine:t=>t.length?t[0]:void 0,static:!0}),lt=j.define(),at=j.define(),ct=j.define(),ft=j.define({combine:t=>!!t.length&&t[0]});class ut{constructor(t,e){this.type=t,this.value=e}static define(){return new gt}}class gt{of(t){return new ut(this,t)}}class dt{constructor(t){this.map=t}of(t){return new pt(this,t)}}class pt{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new pt(this.type,e)}is(t){return this.type==t}static define(t={}){return new dt(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let n=[];for(let i of t){let t=i.map(e);t&&n.push(t)}return n}}pt.reconfigure=pt.define(),pt.appendConfig=pt.define();class mt{constructor(t,e,n,i,s,r){this.startState=t,this.changes=e,this.selection=n,this.effects=i,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,n&&D(n,e.newLength),s.some(t=>t.type==mt.time)||(this.annotations=s.concat(mt.time.of(Date.now())))}static create(t,e,n,i,s,r){return new mt(t,e,n,i,s,r)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(mt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function vt(t,e){let n=[];for(let i=0,s=0;;){let r,h;if(i<t.length&&(s==e.length||e[s]>=t[i]))r=t[i++],h=t[i++];else{if(!(s<e.length))return n;r=e[s++],h=e[s++]}!n.length||n[n.length-1]<r?n.push(r,h):n[n.length-1]<h&&(n[n.length-1]=h)}}function xt(t,e,n){var i;let s,r,h;return n?(s=e.changes,r=A.empty(e.changes.length),h=t.changes.compose(e.changes)):(s=e.changes.map(t.changes),r=t.changes.mapDesc(e.changes,!0),h=t.changes.compose(s)),{changes:h,selection:e.selection?e.selection.map(r):null===(i=t.selection)||void 0===i?void 0:i.map(s),effects:pt.mapEffects(t.effects,s).concat(pt.mapEffects(e.effects,r)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function wt(t,e,n){let i=e.selection,s=St(e.annotations);return e.userEvent&&(s=s.concat(mt.userEvent.of(e.userEvent))),{changes:e.changes instanceof A?e.changes:A.of(e.changes||[],n,t.facet(ot)),selection:i&&(i instanceof J?i:J.single(i.anchor,i.head)),effects:St(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function kt(t,e,n){let i=wt(t,e.length?e[0]:{},t.doc.length);e.length&&!1===e[0].filter&&(n=!1);for(let s=1;s<e.length;s++){!1===e[s].filter&&(n=!1);let r=!!e[s].sequential;i=xt(i,wt(t,e[s],r?i.changes.newLength:t.doc.length),r)}let s=mt.create(t,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return function(t){let e=t.startState,n=e.facet(ct),i=t;for(let s=n.length-1;s>=0;s--){let r=n[s](t);r&&Object.keys(r).length&&(i=xt(i,wt(e,r,t.changes.newLength),!0))}return i==t?t:mt.create(e,t.changes,t.selection,i.effects,i.annotations,i.scrollIntoView)}(n?function(t){let e=t.startState,n=!0;for(let i of e.facet(lt)){let e=i(t);if(!1===e){n=!1;break}Array.isArray(e)&&(n=!0===n?e:vt(n,e))}if(!0!==n){let i,s;if(!1===n)s=t.changes.invertedDesc,i=A.empty(e.doc.length);else{let e=t.changes.filter(n);i=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=mt.create(e,i,t.selection&&t.selection.map(s),pt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let i=e.facet(at);for(let n=i.length-1;n>=0;n--){let s=i[n](t);t=s instanceof mt?s:Array.isArray(s)&&1==s.length&&s[0]instanceof mt?s[0]:kt(e,St(s),!1)}return t}(s):s)}mt.time=ut.define(),mt.userEvent=ut.define(),mt.addToHistory=ut.define(),mt.remote=ut.define();const yt=[];function St(t){return null==t?yt:Array.isArray(t)?t:[t]}var It=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(It||(It={}));const bt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Pt;try{Pt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function Et(t){return e=>{if(!/\S/.test(e))return It.Space;if(function(t){if(Pt)return Pt.test(t);for(let e=0;e<t.length;e++){let n=t[e];if(/\w/.test(n)||n>""&&(n.toUpperCase()!=n.toLowerCase()||bt.test(n)))return!0}return!1}(e))return It.Word;for(let n=0;n<t.length;n++)if(e.indexOf(t[n])>-1)return It.Word;return It.Other}}class Mt{constructor(t,e,n,i,s,r){this.config=t,this.doc=e,this.selection=n,this.values=i,this.status=t.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let t=0;t<this.config.dynamicSlots.length;t++)it(this,t<<1);this.computeSlot=null}field(t,e=!0){let n=this.config.address[t.id];if(null!=n)return it(this,n),st(this,n);if(e)throw new RangeError("Field is not present in this state")}update(...t){return kt(this,t,!0)}applyTransaction(t){let e,n=this.config,{base:i,compartments:s}=n;for(let e of t.effects)e.is(tt.reconfigure)?(n&&(s=new Map,n.compartments.forEach((t,e)=>s.set(e,t)),n=null),s.set(e.value.compartment,e.value.extension)):e.is(pt.reconfigure)?(n=null,i=e.value):e.is(pt.appendConfig)&&(n=null,i=St(i).concat(e.value));if(n)e=t.startState.values.slice();else{n=nt.resolve(i,s,this),e=new Mt(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(t,e)=>e.reconfigure(t,this),null).values}let r=t.startState.facet(ht)?t.newSelection:t.newSelection.asSingle();new Mt(n,t.newDoc,r,e,(e,n)=>n.update(e,t),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:J.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,n=t(e.ranges[0]),i=this.changes(n.changes),s=[n.range],r=St(n.effects);for(let n=1;n<e.ranges.length;n++){let h=t(e.ranges[n]),o=this.changes(h.changes),l=o.map(i);for(let t=0;t<n;t++)s[t]=s[t].map(l);let a=i.mapDesc(o,!0);s.push(h.range.map(a)),i=i.compose(l),r=pt.mapEffects(r,l).concat(pt.mapEffects(St(h.effects),a))}return{changes:i,selection:J.create(s,e.mainIndex),effects:r}}changes(t=[]){return t instanceof A?t:A.of(t,this.doc.length,this.facet(Mt.lineSeparator))}toText(t){return f.of(t.split(this.facet(Mt.lineSeparator)||P))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return null==e?t.default:(it(this,e),st(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let n in t){let i=t[n];i instanceof U&&null!=this.config.address[i.id]&&(e[n]=i.spec.toJSON(this.field(t[n]),this))}return e}static fromJSON(t,e={},n){if(!t||"string"!=typeof t.doc)throw new RangeError("Invalid JSON representation for EditorState");let i=[];if(n)for(let e in n)if(Object.prototype.hasOwnProperty.call(t,e)){let s=n[e],r=t[e];i.push(s.init(t=>s.spec.fromJSON(r,t)))}return Mt.create({doc:t.doc,selection:J.fromJSON(t.selection),extensions:e.extensions?i.concat([e.extensions]):i})}static create(t={}){let e=nt.resolve(t.extensions||[],new Map),n=t.doc instanceof f?t.doc:f.of((t.doc||"").split(e.staticFacet(Mt.lineSeparator)||P)),i=t.selection?t.selection instanceof J?t.selection:J.single(t.selection.anchor,t.selection.head):J.single(0);return D(i,n.length),e.staticFacet(ht)||(i=i.asSingle()),new Mt(e,n,i,e.dynamicSlots.map(()=>null),(t,e)=>e.create(t),null)}get tabSize(){return this.facet(Mt.tabSize)}get lineBreak(){return this.facet(Mt.lineSeparator)||"\n"}get readOnly(){return this.facet(ft)}phrase(t,...e){for(let e of this.facet(Mt.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(t,n)=>{if("$"==n)return"$";let i=+(n||1);return!i||i>e.length?t:e[i-1]})),t}languageDataAt(t,e,n=-1){let i=[];for(let s of this.facet(rt))for(let r of s(this,e,n))Object.prototype.hasOwnProperty.call(r,t)&&i.push(r[t]);return i}charCategorizer(t){let e=this.languageDataAt("wordChars",t);return Et(e.length?e[0]:"")}wordAt(t){let{text:e,from:n,length:i}=this.doc.lineAt(t),s=this.charCategorizer(t),r=t-n,h=t-n;for(;r>0;){let t=y(e,r,!1);if(s(e.slice(t,r))!=It.Word)break;r=t}for(;h<i;){let t=y(e,h);if(s(e.slice(h,t))!=It.Word)break;h=t}return r==h?null:J.range(r+n,h+n)}}function At(t,e,n={}){let i={};for(let e of t)for(let t of Object.keys(e)){let s=e[t],r=i[t];if(void 0===r)i[t]=s;else if(r===s||void 0===s);else{if(!Object.hasOwnProperty.call(n,t))throw new Error("Config merge conflict for field "+t);i[t]=n[t](r,s)}}for(let t in e)void 0===i[t]&&(i[t]=e[t]);return i}Mt.allowMultipleSelections=ht,Mt.tabSize=j.define({combine:t=>t.length?t[0]:4}),Mt.lineSeparator=ot,Mt.readOnly=ft,Mt.phrases=j.define({compare(t,e){let n=Object.keys(t),i=Object.keys(e);return n.length==i.length&&n.every(n=>t[n]==e[n])}}),Mt.languageData=rt,Mt.changeFilter=lt,Mt.transactionFilter=at,Mt.transactionExtender=ct,tt.reconfigure=pt.define();class Ot{eq(t){return this==t}range(t,e=t){return Ct.create(t,e,this)}}function Rt(t,e){return t==e||t.constructor==e.constructor&&t.eq(e)}Ot.prototype.startSide=Ot.prototype.endSide=0,Ot.prototype.point=!1,Ot.prototype.mapMode=E.TrackDel;class Ct{constructor(t,e,n){this.from=t,this.to=e,this.value=n}static create(t,e,n){return new Ct(t,e,n)}}function Tt(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Nt{constructor(t,e,n,i){this.from=t,this.to=e,this.value=n,this.maxPoint=i}get length(){return this.to[this.to.length-1]}findIndex(t,e,n,i=0){let s=n?this.to:this.from;for(let r=i,h=s.length;;){if(r==h)return r;let i=r+h>>1,o=s[i]-t||(n?this.value[i].endSide:this.value[i].startSide)-e;if(i==r)return o>=0?r:h;o>=0?h=i:r=i+1}}between(t,e,n,i){for(let s=this.findIndex(e,-1e9,!0),r=this.findIndex(n,1e9,!1,s);s<r;s++)if(!1===i(this.from[s]+t,this.to[s]+t,this.value[s]))return!1}map(t,e){let n=[],i=[],s=[],r=-1,h=-1;for(let o=0;o<this.value.length;o++){let l,a,c=this.value[o],f=this.from[o]+t,u=this.to[o]+t;if(f==u){let t=e.mapPos(f,c.startSide,c.mapMode);if(null==t)continue;if(l=a=t,c.startSide!=c.endSide&&(a=e.mapPos(f,c.endSide),a<l))continue}else if(l=e.mapPos(f,c.startSide),a=e.mapPos(u,c.endSide),l>a||l==a&&c.startSide>0&&c.endSide<=0)continue;(a-l||c.endSide-c.startSide)<0||(r<0&&(r=l),c.point&&(h=Math.max(h,a-l)),n.push(c),i.push(l-r),s.push(a-r))}return{mapped:n.length?new Nt(i,s,n,h):null,pos:r}}}class Ft{constructor(t,e,n,i){this.chunkPos=t,this.chunk=e,this.nextLayer=n,this.maxPoint=i}static create(t,e,n,i){return new Ft(t,e,n,i)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:n=!1,filterFrom:i=0,filterTo:s=this.length}=t,r=t.filter;if(0==e.length&&!r)return this;if(n&&(e=e.slice().sort(Tt)),this.isEmpty)return e.length?Ft.of(e):this;let h=new Dt(this,null,-1).goto(0),o=0,l=[],a=new Bt;for(;h.value||o<e.length;)if(o<e.length&&(h.from-e[o].from||h.startSide-e[o].value.startSide)>=0){let t=e[o++];a.addInner(t.from,t.to,t.value)||l.push(t)}else 1==h.rangeIndex&&h.chunkIndex<this.chunk.length&&(o==e.length||this.chunkEnd(h.chunkIndex)<e[o].from)&&(!r||i>this.chunkEnd(h.chunkIndex)||s<this.chunkPos[h.chunkIndex])&&a.addChunk(this.chunkPos[h.chunkIndex],this.chunk[h.chunkIndex])?h.nextChunk():((!r||i>h.to||s<h.from||r(h.from,h.to,h.value))&&(a.addInner(h.from,h.to,h.value)||l.push(Ct.create(h.from,h.to,h.value))),h.next());return a.finishInner(this.nextLayer.isEmpty&&!l.length?Ft.empty:this.nextLayer.update({add:l,filter:r,filterFrom:i,filterTo:s}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],n=[],i=-1;for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],h=this.chunk[s],o=t.touchesRange(r,r+h.length);if(!1===o)i=Math.max(i,h.maxPoint),e.push(h),n.push(t.mapPos(r));else if(!0===o){let{mapped:s,pos:o}=h.map(r,t);s&&(i=Math.max(i,s.maxPoint),e.push(s),n.push(o))}}let s=this.nextLayer.map(t);return 0==e.length?s:new Ft(n,e,s||Ft.empty,i)}between(t,e,n){if(!this.isEmpty){for(let i=0;i<this.chunk.length;i++){let s=this.chunkPos[i],r=this.chunk[i];if(e>=s&&t<=s+r.length&&!1===r.between(s,t-s,e-s,n))return}this.nextLayer.between(t,e,n)}}iter(t=0){return Lt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Lt.from(t).goto(e)}static compare(t,e,n,i,s=-1){let r=t.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),h=e.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),o=Jt(r,h,n),l=new $t(r,o,s),a=new $t(h,o,s);n.iterGaps((t,e,n)=>qt(l,t,a,e,n,i)),n.empty&&0==n.length&&qt(l,0,a,0,0,i)}static eq(t,e,n=0,i){null==i&&(i=999999999);let s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0),r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let h=Jt(s,r),o=new $t(s,h,0).goto(n),l=new $t(r,h,0).goto(n);for(;;){if(o.to!=l.to||!zt(o.active,l.active)||o.point&&(!l.point||!Rt(o.point,l.point)))return!1;if(o.to>i)return!0;o.next(),l.next()}}static spans(t,e,n,i,s=-1){let r=new $t(t,null,s).goto(e),h=e,o=r.openStart;for(;;){let t=Math.min(r.to,n);if(r.point){let n=r.activeForPoint(r.to),s=r.pointFrom<e?n.length+1:r.point.startSide<0?n.length:Math.min(n.length,o);i.point(h,t,r.point,n,s,r.pointRank),o=Math.min(r.openEnd(t),n.length)}else t>h&&(i.span(h,t,r.active,o),o=r.openEnd(t));if(r.to>n)return o+(r.point&&r.to>n?1:0);h=r.to,r.next()}}static of(t,e=!1){let n=new Bt;for(let i of t instanceof Ct?[t]:e?function(t){if(t.length>1)for(let e=t[0],n=1;n<t.length;n++){let i=t[n];if(Tt(e,i)>0)return t.slice().sort(Tt);e=i}return t}(t):t)n.add(i.from,i.to,i.value);return n.finish()}static join(t){if(!t.length)return Ft.empty;let e=t[t.length-1];for(let n=t.length-2;n>=0;n--)for(let i=t[n];i!=Ft.empty;i=i.nextLayer)e=new Ft(i.chunkPos,i.chunk,e,Math.max(i.maxPoint,e.maxPoint));return e}}Ft.empty=new Ft([],[],null,-1),Ft.empty.nextLayer=Ft.empty;class Bt{finishChunk(t){this.chunks.push(new Nt(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,n){this.addInner(t,e,n)||(this.nextLayer||(this.nextLayer=new Bt)).add(t,e,n)}addInner(t,e,n){let i=t-this.lastTo||n.startSide-this.last.endSide;if(i<=0&&(t-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(i<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=n,this.lastFrom=t,this.lastTo=e,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let n=e.value.length-1;return this.last=e.value[n],this.lastFrom=e.from[n]+t,this.lastTo=e.to[n]+t,!0}finish(){return this.finishInner(Ft.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=Ft.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Jt(t,e,n){let i=new Map;for(let e of t)for(let t=0;t<e.chunk.length;t++)e.chunk[t].maxPoint<=0&&i.set(e.chunk[t],e.chunkPos[t]);let s=new Set;for(let t of e)for(let e=0;e<t.chunk.length;e++){let r=i.get(t.chunk[e]);null==r||(n?n.mapPos(r):r)!=t.chunkPos[e]||(null==n?void 0:n.touchesRange(r,r+t.chunk[e].length))||s.add(t.chunk[e])}return s}class Dt{constructor(t,e,n,i=0){this.layer=t,this.skip=e,this.minPoint=n,this.rank=i}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,n){for(;this.chunkIndex<this.layer.chunk.length;){let e=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(e)||this.layer.chunkEnd(this.chunkIndex)<t||e.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let i=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!n||this.rangeIndex<i)&&this.setRangeIndex(i)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;){if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],n=t+e.from[this.rangeIndex];if(this.from=n,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}}class Lt{constructor(t){this.heap=t}static from(t,e=null,n=-1){let i=[];for(let s=0;s<t.length;s++)for(let r=t[s];!r.isEmpty;r=r.nextLayer)r.maxPoint>=n&&i.push(new Dt(r,e,n,s));return 1==i.length?i[0]:new Lt(i)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let n of this.heap)n.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)jt(this.heap,t);return this.next(),this}forward(t,e){for(let n of this.heap)n.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)jt(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),jt(this.heap,0)}}}function jt(t,e){for(let n=t[e];;){let i=1+(e<<1);if(i>=t.length)break;let s=t[i];if(i+1<t.length&&s.compare(t[i+1])>=0&&(s=t[i+1],i++),n.compare(s)<0)break;t[i]=n,t[e]=s,e=i}}class $t{constructor(t,e,n){this.minPoint=n,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Lt.from(t,e,n)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Vt(this.active,t),Vt(this.activeTo,t),Vt(this.activeRank,t),this.minActive=Wt(this.active,this.activeTo)}addActive(t){let e=0,{value:n,to:i,rank:s}=this.cursor;for(;e<this.activeRank.length&&(s-this.activeRank[e]||i-this.activeTo[e])>0;)e++;_t(this.active,e,n),_t(this.activeTo,e,i),_t(this.activeRank,e,s),t&&_t(t,e,this.cursor.from),this.minActive=Wt(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let i=this.minActive;if(i>-1&&(this.activeTo[i]-this.cursor.from||this.active[i].endSide-this.cursor.startSide)<0){if(this.activeTo[i]>t){this.to=this.activeTo[i],this.endSide=this.active[i].endSide;break}this.removeActive(i),n&&Vt(n,i)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)){this.point=t,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=t.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}this.cursor.next()}else this.addActive(n),this.cursor.next()}}}if(n){this.openStart=0;for(let e=n.length-1;e>=0&&n[e]<t;e--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let n=this.active.length-1;n>=0&&!(this.activeRank[n]<this.pointRank);n--)(this.activeTo[n]>t||this.activeTo[n]==t&&this.active[n].endSide>=this.point.endSide)&&e.push(this.active[n]);return e.reverse()}openEnd(t){let e=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>t;n--)e++;return e}}function qt(t,e,n,i,s,r){t.goto(e),n.goto(i);let h=i+s,o=i,l=i-e,a=!!r.boundChange;for(let e=!1;;){let i=t.to+l-n.to,s=i||t.endSide-n.endSide,c=s<0?t.to+l:n.to,f=Math.min(c,h);if(t.point||n.point?(t.point&&n.point&&Rt(t.point,n.point)&&zt(t.activeForPoint(t.to),n.activeForPoint(n.to))||r.comparePoint(o,f,t.point,n.point),e=!1):(e&&r.boundChange(o),f>o&&!zt(t.active,n.active)&&r.compareRange(o,f,t.active,n.active),a&&f<h&&(i||t.openEnd(c)!=n.openEnd(c))&&(e=!0)),c>h)break;o=c,s<=0&&t.next(),s>=0&&n.next()}}function zt(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!=e[n]&&!Rt(t[n],e[n]))return!1;return!0}function Vt(t,e){for(let n=e,i=t.length-1;n<i;n++)t[n]=t[n+1];t.pop()}function _t(t,e,n){for(let n=t.length-1;n>=e;n--)t[n+1]=t[n];t[e]=n}function Wt(t,e){let n=-1,i=1e9;for(let s=0;s<e.length;s++)(e[s]-i||t[s].endSide-t[n].endSide)<0&&(n=s,i=e[s]);return n}function Ut(t,e,n=t.length){let i=0;for(let s=0;s<n&&s<t.length;)9==t.charCodeAt(s)?(i+=e-i%e,s++):(i++,s=y(t,s));return i}function Gt(t,e,n,i){for(let i=0,s=0;;){if(s>=e)return i;if(i==t.length)break;s+=9==t.charCodeAt(i)?n-s%n:1,i=y(t,i)}return!0===i?-1:t.length}export{ut as Annotation,gt as AnnotationType,M as ChangeDesc,A as ChangeSet,It as CharCategory,tt as Compartment,J as EditorSelection,Mt as EditorState,j as Facet,w as Line,E as MapMode,Y as Prec,Ct as Range,Ft as RangeSet,Bt as RangeSetBuilder,Ot as RangeValue,B as SelectionRange,pt as StateEffect,dt as StateEffectType,U as StateField,f as Text,mt as Transaction,S as codePointAt,b as codePointSize,At as combineConfig,Ut as countColumn,y as findClusterBreak,Gt as findColumn,I as fromCodePoint};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EditorView as o}from"@codemirror/view";import{HighlightStyle as r,syntaxHighlighting as e}from"@codemirror/language";import{tags as c}from"@lezer/highlight";const a="#e5c07b",t="#e06c75",l="#56b6c2",n="#ffffff",i="#abb2bf",d="#7d8799",m="#61afef",g="#98c379",s="#d19a66",b="#c678dd",p="#21252b",f="#2c313a",u="#282c34",k="#353a42",h="#3E4451",C="#528bff",y={chalky:a,coral:t,cyan:l,invalid:n,ivory:i,stone:d,malibu:m,sage:g,whiskey:s,violet:b,darkBackground:p,highlightBackground:f,background:u,tooltipBackground:k,selection:h,cursor:C},B=o.theme({"&":{color:i,backgroundColor:u},".cm-content":{caretColor:C},".cm-cursor, .cm-dropCursor":{borderLeftColor:C},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:h},".cm-panels":{backgroundColor:p,color:i},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:u,color:d,border:"none"},".cm-activeLineGutter":{backgroundColor:f},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:k},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:k,borderBottomColor:k},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:f,color:i}}},{dark:!0}),v=r.define([{tag:c.keyword,color:b},{tag:[c.name,c.deleted,c.character,c.propertyName,c.macroName],color:t},{tag:[c.function(c.variableName),c.labelName],color:m},{tag:[c.color,c.constant(c.name),c.standard(c.name)],color:s},{tag:[c.definition(c.name),c.separator],color:i},{tag:[c.typeName,c.className,c.number,c.changed,c.annotation,c.modifier,c.self,c.namespace],color:a},{tag:[c.operator,c.operatorKeyword,c.url,c.escape,c.regexp,c.link,c.special(c.string)],color:l},{tag:[c.meta,c.comment],color:d},{tag:c.strong,fontWeight:"bold"},{tag:c.emphasis,fontStyle:"italic"},{tag:c.strikethrough,textDecoration:"line-through"},{tag:c.link,color:d,textDecoration:"underline"},{tag:c.heading,fontWeight:"bold",color:t},{tag:[c.atom,c.bool,c.special(c.variableName)],color:s},{tag:[c.processingInstruction,c.string,c.inserted],color:g},{tag:c.invalid,color:n}]),x=[B,e(v)];export{y as color,x as oneDark,v as oneDarkHighlightStyle,B as oneDarkTheme};
|