UNPKG

@gdquest/gd-exercise

Version:

Core package that handles logic for the GDExercise project.

3 lines (2 loc) 23.1 kB
var Me=0,ee=class{constructor(e,t){this.from=e,this.to=t}},m=class{constructor(e={}){this.id=Me++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=M.match(e)),t=>{let r=e(t);return r===void 0?null:[this,r]}}};m.closedBy=new m({deserialize:s=>s.split(" ")});m.openedBy=new m({deserialize:s=>s.split(" ")});m.group=new m({deserialize:s=>s.split(" ")});m.contextHash=new m({perNode:!0});m.lookAhead=new m({perNode:!0});m.mounted=new m({perNode:!0});var ze=Object.create(null),M=class s{constructor(e,t,r,i=0){this.name=e,this.props=t,this.id=r,this.flags=i}static define(e){let t=e.props&&e.props.length?Object.create(null):ze,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),i=new s(e.name||"",t,e.id,r);if(e.props){for(let n of e.props)if(Array.isArray(n)||(n=n(i)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[n[0].id]=n[1]}}return i}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(m.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let r in e)for(let i of r.split(" "))t[i]=e[r];return r=>{for(let i=r.prop(m.group),n=-1;n<(i?i.length:0);n++){let l=t[n<0?r.name:i[n]];if(l)return l}}}};M.none=new M("",Object.create(null),0,8);var Ae=class s{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 i=null;for(let n of e){let l=n(r);l&&(i||(i=Object.assign({},r.props)),i[l[0].id]=l[1])}t.push(i?new M(r.name,i,r.id,r.flags):r)}return new s(t)}},le=new WeakMap,Ne=new WeakMap,N;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays"})(N||(N={}));var F=class s{constructor(e,t,r,i,n){if(this.type=e,this.children=t,this.positions=r,this.length=i,this.props=null,n&&n.length){this.props=Object.create(null);for(let[l,h]of n)this.props[typeof l=="number"?l:l.id]=h}}toString(){let e=this.prop(m.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let r of this.children){let i=r.toString();i&&(t&&(t+=","),t+=i)}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 Z(this.topNode,e)}cursorAt(e,t=0,r=0){let i=le.get(this)||this.topNode,n=new Z(i);return n.moveTo(e,t),le.set(this,n._tree),n}get topNode(){return new K(this,0,0,null)}resolve(e,t=0){let r=Y(le.get(this)||this.topNode,e,t,!1);return le.set(this,r),r}resolveInner(e,t=0){let r=Y(Ne.get(this)||this.topNode,e,t,!0);return Ne.set(this,r),r}iterate(e){let{enter:t,leave:r,from:i=0,to:n=this.length}=e,l=e.mode||0,h=(l&N.IncludeAnonymous)>0;for(let a=this.cursor(l|N.IncludeAnonymous);;){let y=!1;if(a.from<=n&&a.to>=i&&(!h&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;y=!0}for(;y&&r&&(h||!a.type.isAnonymous)&&r(a),!a.nextSibling();){if(!a.parent())return;y=!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:be(M.none,this.children,this.positions,0,this.children.length,0,this.length,(t,r,i)=>new s(this.type,t,r,i,this.propValues),e.makeTree||((t,r,i)=>new s(M.none,t,r,i)))}static build(e){return Oe(e)}};F.empty=new F(M.none,[],[],0);var de=class s{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 s(this.buffer,this.index)}},J=class s{constructor(e,t,r){this.buffer=e,this.length=t,this.set=r}get type(){return M.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],i=this.set.types[t],n=i.name;if(/\W/.test(n)&&!i.isError&&(n=JSON.stringify(n)),e+=4,r==e)return n;let l=[];for(;e<r;)l.push(this.childString(e)),e=this.buffer[e+3];return n+"("+l.join(",")+")"}findChild(e,t,r,i,n){let{buffer:l}=this,h=-1;for(let a=e;a!=t&&!(_e(n,i,l[a+1],l[a+2])&&(h=a,r>0));a=l[a+3]);return h}slice(e,t,r){let i=this.buffer,n=new Uint16Array(t-e),l=0;for(let h=e,a=0;h<t;){n[a++]=i[h++],n[a++]=i[h++]-r;let y=n[a++]=i[h++]-r;n[a++]=i[h++]-e,l=Math.max(l,y)}return new s(n,l,this.set)}};function _e(s,e,t,r){switch(s){case-2:return t<e;case-1:return r>=e&&t<e;case 0:return t<e&&r>e;case 1:return t<=e&&r>e;case 2:return r>e;case 4:return!0}}function Be(s,e){let t=s.childBefore(e);for(;t;){let r=t.lastChild;if(!r||r.to!=t.to)break;r.type.isError&&r.from==r.to?(s=t,t=r.prevSibling):t=r}return s}function Y(s,e,t,r){for(var i;s.from==s.to||(t<1?s.from>=e:s.from>e)||(t>-1?s.to<=e:s.to<e);){let l=!r&&s instanceof K&&s.index<0?null:s.parent;if(!l)return s;s=l}let n=r?0:N.IgnoreOverlays;if(r)for(let l=s,h=l.parent;h;l=h,h=l.parent)l instanceof K&&l.index<0&&((i=h.enter(e,t,n))===null||i===void 0?void 0:i.from)!=l.from&&(s=h);for(;;){let l=s.enter(e,t,n);if(!l)return s;s=l}}var K=class s{constructor(e,t,r,i){this._tree=e,this.from=t,this.index=r,this._parent=i}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,i,n=0){for(let l=this;;){for(let{children:h,positions:a}=l._tree,y=t>0?h.length:-1;e!=y;e+=t){let k=h[e],w=a[e]+l.from;if(_e(i,r,w,w+k.length)){if(k instanceof J){if(n&N.ExcludeBuffers)continue;let v=k.findChild(0,k.buffer.length,t,r-w,i);if(v>-1)return new te(new ge(l,k,e,w),null,v)}else if(n&N.IncludeAnonymous||!k.type.isAnonymous||ye(k)){let v;if(!(n&N.IgnoreMounts)&&k.props&&(v=k.prop(m.mounted))&&!v.overlay)return new s(v.tree,w,e,l);let B=new s(k,w,e,l);return n&N.IncludeAnonymous||!B.type.isAnonymous?B:B.nextChild(t<0?k.children.length-1:0,t,r,i)}}}if(n&N.IncludeAnonymous||!l.type.isAnonymous||(l.index>=0?e=l.index+t:e=t<0?-1:l._parent._tree.children.length,l=l._parent,!l))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)}enter(e,t,r=0){let i;if(!(r&N.IgnoreOverlays)&&(i=this._tree.prop(m.mounted))&&i.overlay){let n=e-this.from;for(let{from:l,to:h}of i.overlay)if((t>0?l<=n:l<n)&&(t<0?h>=n:h>n))return new s(i.tree,i.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}cursor(e=0){return new Z(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return Y(this,e,t,!1)}resolveInner(e,t=0){return Y(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Be(this,e)}getChild(e,t=null,r=null){let i=he(this,e,t,r);return i.length?i[0]:null}getChildren(e,t=null,r=null){return he(this,e,t,r)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return fe(this,e)}};function he(s,e,t,r){let i=s.cursor(),n=[];if(!i.firstChild())return n;if(t!=null){for(;!i.type.is(t);)if(!i.nextSibling())return n}for(;;){if(r!=null&&i.type.is(r))return n;if(i.type.is(e)&&n.push(i.node),!i.nextSibling())return r==null?n:[]}}function fe(s,e,t=e.length-1){for(let r=s.parent;t>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[t]&&e[t]!=r.name)return!1;t--}}return!0}var ge=class{constructor(e,t,r,i){this.parent=e,this.buffer=t,this.index=r,this.start=i}},te=class s{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){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:i}=this.context,n=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.context.start,r);return n<0?null:new s(this.context,this,n)}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)}enter(e,t,r=0){if(r&N.ExcludeBuffers)return null;let{buffer:i}=this.context,n=i.findChild(this.index+4,i.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return n<0?null:new s(this.context,this,n)}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 s(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 s(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new Z(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:r}=this.context,i=this.index+4,n=r.buffer[this.index+3];if(n>i){let l=r.buffer[this.index+1];e.push(r.slice(i,n,l)),t.push(0)}return new F(this.type,e,t,this.to-this.from)}resolve(e,t=0){return Y(this,e,t,!1)}resolveInner(e,t=0){return Y(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Be(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,r=null){let i=he(this,e,t,r);return i.length?i[0]:null}getChildren(e,t=null,r=null){return he(this,e,t,r)}get node(){return this}matchContext(e){return fe(this,e)}},Z=class{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof K)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.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):!1}yieldBuf(e,t){this.index=e;let{start:r,buffer:i}=this.buffer;return this.type=t||i.set.types[i.buffer[e]],this.from=r+i.buffer[e+1],this.to=r+i.buffer[e+2],!0}yield(e){return e?e instanceof K?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}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:i}=this.buffer,n=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.buffer.start,r);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}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&N.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&N.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&N.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)):!1;let{buffer:t}=this.buffer,r=this.stack.length-1;if(e<0){let i=r<0?0:this.stack[r]+4;if(this.index!=i)return this.yieldBuf(t.findChild(i,this.index,-1,0,4))}else{let i=t.buffer[this.index+3];if(i<(r<0?t.buffer.length:t.buffer[this.stack[r]+3]))return this.yieldBuf(i)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,r,{buffer:i}=this;if(i){if(e>0){if(this.index<i.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(i.buffer.buffer[n+3]<this.index)return!1;({index:t,parent:r}=i)}else({index:t,_parent:r}=this._tree);for(;r;{index:t,_parent:r}=r)if(t>-1)for(let n=t+e,l=e<0?-1:r._tree.children.length;n!=l;n+=e){let h=r._tree.children[n];if(this.mode&N.IncludeAnonymous||h instanceof J||!h.type.isAnonymous||ye(h))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 i=this.index,n=this.stack.length;n>=0;){for(let l=e;l;l=l._parent)if(l.index==i){if(i==this.index)return l;t=l,r=n+1;break e}i=this.stack[--n]}for(let i=r;i<this.stack.length;i++)t=new te(this.buffer,t,this.stack[i]);return this.bufferNode=new te(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let r=0;;){let i=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(i=!0)}for(;i&&t&&t(this),i=this.type.isAnonymous,!this.nextSibling();){if(!r)return;this.parent(),r--,i=!0}}}matchContext(e){if(!this.buffer)return fe(this.node,e);let{buffer:t}=this.buffer,{types:r}=t.set;for(let i=e.length-1,n=this.stack.length-1;i>=0;n--){if(n<0)return fe(this.node,e,i);let l=r[t.buffer[this.stack[n]]];if(!l.isAnonymous){if(e[i]&&e[i]!=l.name)return!1;i--}}return!0}};function ye(s){return s.children.some(e=>e instanceof J||!e.type.isAnonymous||ye(e))}function Oe(s){var e;let{buffer:t,nodeSet:r,maxBufferLength:i=1024,reused:n=[],minRepeatType:l=r.types.length}=s,h=Array.isArray(t)?new de(t,t.length):t,a=r.types,y=0,k=0;function w(g,b,f,c,A){let{id:d,start:p,end:x,size:_}=h,I=k;for(;_<0;)if(h.next(),_==-1){let L=n[d];f.push(L),c.push(p-g);return}else if(_==-3){y=d;return}else if(_==-4){k=d;return}else throw new RangeError(`Unrecognized record size: ${_}`);let Q=a[d],D,j,ke=p-g;if(x-p<=i&&(j=G(h.pos-b,A))){let L=new Uint16Array(j.size-j.skip),P=h.pos-j.size,R=L.length;for(;h.pos>P;)R=ne(j.start,L,R);D=new J(L,x-j.start,r),ke=j.start-g}else{let L=h.pos-_;h.next();let P=[],R=[],q=d>=l?d:-1,X=0,se=x;for(;h.pos>L;)q>=0&&h.id==q&&h.size>=0?(h.end<=se-i&&(B(P,R,p,X,h.end,se,q,I),X=P.length,se=h.end),h.next()):w(p,L,P,R,q);if(q>=0&&X>0&&X<P.length&&B(P,R,p,X,p,se,q,I),P.reverse(),R.reverse(),q>-1&&X>0){let ve=v(Q);D=be(Q,P,R,0,P.length,0,x-p,ve,ve)}else D=C(Q,P,R,x-p,I-x)}f.push(D),c.push(ke)}function v(g){return(b,f,c)=>{let A=0,d=b.length-1,p,x;if(d>=0&&(p=b[d])instanceof F){if(!d&&p.type==g&&p.length==c)return p;(x=p.prop(m.lookAhead))&&(A=f[d]+p.length+x)}return C(g,b,f,c,A)}}function B(g,b,f,c,A,d,p,x){let _=[],I=[];for(;g.length>c;)_.push(g.pop()),I.push(b.pop()+f-A);g.push(C(r.types[p],_,I,d-A,x-d)),b.push(A-f)}function C(g,b,f,c,A=0,d){if(y){let p=[m.contextHash,y];d=d?[p].concat(d):[p]}if(A>25){let p=[m.lookAhead,A];d=d?[p].concat(d):[p]}return new F(g,b,f,c,d)}function G(g,b){let f=h.fork(),c=0,A=0,d=0,p=f.end-i,x={size:0,start:0,skip:0};e:for(let _=f.pos-g;f.pos>_;){let I=f.size;if(f.id==b&&I>=0){x.size=c,x.start=A,x.skip=d,d+=4,c+=4,f.next();continue}let Q=f.pos-I;if(I<0||Q<_||f.start<p)break;let D=f.id>=l?4:0,j=f.start;for(f.next();f.pos>Q;){if(f.size<0)if(f.size==-3)D+=4;else break e;else f.id>=l&&(D+=4);f.next()}A=j,c+=I,d+=D}return(b<0||c==g)&&(x.size=c,x.start=A,x.skip=d),x.size>4?x:void 0}function ne(g,b,f){let{id:c,start:A,end:d,size:p}=h;if(h.next(),p>=0&&c<l){let x=f;if(p>4){let _=h.pos-(p-4);for(;h.pos>_;)f=ne(g,b,f)}b[--f]=x,b[--f]=d-g,b[--f]=A-g,b[--f]=c}else p==-3?y=c:p==-4&&(k=c);return f}let W=[],$=[];for(;h.pos>0;)w(s.start||0,s.bufferStart||0,W,$,-1);let S=(e=s.length)!==null&&e!==void 0?e:W.length?$[0]+W[0].length:0;return new F(a[s.topID],W.reverse(),$.reverse(),S)}var Ce=new WeakMap;function oe(s,e){if(!s.isAnonymous||e instanceof J||e.type!=s)return 1;let t=Ce.get(e);if(t==null){t=1;for(let r of e.children){if(r.type!=s||!(r instanceof F)){t=1;break}t+=oe(s,r)}Ce.set(e,t)}return t}function be(s,e,t,r,i,n,l,h,a){let y=0;for(let C=r;C<i;C++)y+=oe(s,e[C]);let k=Math.ceil(y*1.5/8),w=[],v=[];function B(C,G,ne,W,$){for(let S=ne;S<W;){let g=S,b=G[S],f=oe(s,C[S]);for(S++;S<W;S++){let c=oe(s,C[S]);if(f+c>=k)break;f+=c}if(S==g+1){if(f>k){let c=C[g];B(c.children,c.positions,0,c.children.length,G[g]+$);continue}w.push(C[g])}else{let c=G[S-1]+C[S-1].length-b;w.push(be(s,C,G,g,S,b,c,null,a))}v.push(b+$-n)}}return B(e,t,r,i,0),(h||a)(w,v,l)}var Se=class{startParse(e,t,r){return typeof e=="string"&&(e=new me(e)),r=r?r.length?r.map(i=>new ee(i.from,i.to)):[new ee(0,0)]:[new ee(0,e.length)],this.createParse(e,t||[],r)}parse(e,t,r){let i=this.startParse(e,t,r);for(;;){let n=i.advance();if(n)return n}}},me=class{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)}};var Le=new m({perNode:!0});var Ee=0,T=class s{constructor(e,t,r){this.set=e,this.base=t,this.modified=r,this.id=Ee++}static define(e){if(e?.base)throw new Error("Can not derive from a modified tag");let t=new s([],null,[]);if(t.set.push(t),e)for(let r of e.set)t.set.push(r);return t}static defineModifier(){let e=new ce;return t=>t.modified.indexOf(e)>-1?t:ce.get(t.base||t,t.modified.concat(e).sort((r,i)=>r.id-i.id))}},Te=0,ce=class s{constructor(){this.instances=[],this.id=Te++}static get(e,t){if(!t.length)return e;let r=t[0].instances.find(h=>h.base==e&&je(t,h.modified));if(r)return r;let i=[],n=new T(i,e,t);for(let h of t)h.instances.push(n);let l=Re(t);for(let h of e.set)if(!h.modified.length)for(let a of l)i.push(s.get(h,a));return n}};function je(s,e){return s.length==e.length&&s.every((t,r)=>t==e[r])}function Re(s){let e=[[]];for(let t=0;t<s.length;t++)for(let r=0,i=e.length;r<i;r++)e.push(e[r].concat(s[t]));return e.sort((t,r)=>r.length-t.length)}function We(s){let e=Object.create(null);for(let t in s){let r=s[t];Array.isArray(r)||(r=[r]);for(let i of t.split(" "))if(i){let n=[],l=2,h=i;for(let w=0;;){if(h=="..."&&w>0&&w+3==i.length){l=1;break}let v=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(h);if(!v)throw new RangeError("Invalid path: "+i);if(n.push(v[0]=="*"?"":v[0][0]=='"'?JSON.parse(v[0]):v[0]),w+=v[0].length,w==i.length)break;let B=i[w++];if(w==i.length&&B=="!"){l=0;break}if(B!="/")throw new RangeError("Invalid path: "+i);h=i.slice(w)}let a=n.length-1,y=n[a];if(!y)throw new RangeError("Invalid path: "+i);let k=new ie(r,l,a>0?n.slice(0,a):null);e[y]=k.sort(e[y])}}return Fe.add(e)}var Fe=new m,ie=class{constructor(e,t,r,i){this.tags=e,this.mode=t,this.context=r,this.next=i}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};ie.empty=new ie([],2,null);function De(s,e){let t=Object.create(null);for(let n of s)if(!Array.isArray(n.tag))t[n.tag.id]=n.class;else for(let l of n.tag)t[l.id]=n.class;let{scope:r,all:i=null}=e||{};return{style:n=>{let l=i;for(let h of n)for(let a of h.set){let y=t[a.id];if(y){l=l?l+" "+y:y;break}}return l},scope:r}}var o=T.define,ae=o(),U=o(),Ie=o(U),Pe=o(U),H=o(),ue=o(H),xe=o(H),E=o(),V=o(E),z=o(),O=o(),we=o(),re=o(we),pe=o(),u={comment:ae,lineComment:o(ae),blockComment:o(ae),docComment:o(ae),name:U,variableName:o(U),typeName:Ie,tagName:o(Ie),propertyName:Pe,attributeName:o(Pe),className:o(U),labelName:o(U),namespace:o(U),macroName:o(U),literal:H,string:ue,docString:o(ue),character:o(ue),attributeValue:o(ue),number:xe,integer:o(xe),float:o(xe),bool:o(H),regexp:o(H),escape:o(H),color:o(H),url:o(H),keyword:z,self:o(z),null:o(z),atom:o(z),unit:o(z),modifier:o(z),operatorKeyword:o(z),controlKeyword:o(z),definitionKeyword:o(z),moduleKeyword:o(z),operator:O,derefOperator:o(O),arithmeticOperator:o(O),logicOperator:o(O),bitwiseOperator:o(O),compareOperator:o(O),updateOperator:o(O),definitionOperator:o(O),typeOperator:o(O),controlOperator:o(O),punctuation:we,separator:o(we),bracket:re,angleBracket:o(re),squareBracket:o(re),paren:o(re),brace:o(re),content:E,heading:V,heading1:o(V),heading2:o(V),heading3:o(V),heading4:o(V),heading5:o(V),heading6:o(V),contentSeparator:o(E),list:o(E),quote:o(E),emphasis:o(E),strong:o(E),link:o(E),monospace:o(E),strikethrough:o(E),inserted:o(),deleted:o(),changed:o(),invalid:o(),meta:pe,documentMeta:o(pe),annotation:o(pe),processingInstruction:o(pe),definition:T.defineModifier(),constant:T.defineModifier(),function:T.defineModifier(),standard:T.defineModifier(),local:T.defineModifier(),special:T.defineModifier()},qe=De([{tag:u.link,class:"tok-link"},{tag:u.heading,class:"tok-heading"},{tag:u.emphasis,class:"tok-emphasis"},{tag:u.strong,class:"tok-strong"},{tag:u.keyword,class:"tok-keyword"},{tag:u.atom,class:"tok-atom"},{tag:u.bool,class:"tok-bool"},{tag:u.url,class:"tok-url"},{tag:u.labelName,class:"tok-labelName"},{tag:u.inserted,class:"tok-inserted"},{tag:u.deleted,class:"tok-deleted"},{tag:u.literal,class:"tok-literal"},{tag:u.string,class:"tok-string"},{tag:u.number,class:"tok-number"},{tag:[u.regexp,u.escape,u.special(u.string)],class:"tok-string2"},{tag:u.variableName,class:"tok-variableName"},{tag:u.local(u.variableName),class:"tok-variableName tok-local"},{tag:u.definition(u.variableName),class:"tok-variableName tok-definition"},{tag:u.special(u.variableName),class:"tok-variableName2"},{tag:u.definition(u.propertyName),class:"tok-propertyName tok-definition"},{tag:u.typeName,class:"tok-typeName"},{tag:u.namespace,class:"tok-namespace"},{tag:u.className,class:"tok-className"},{tag:u.macroName,class:"tok-macroName"},{tag:u.propertyName,class:"tok-propertyName"},{tag:u.operator,class:"tok-operator"},{tag:u.comment,class:"tok-comment"},{tag:u.meta,class:"tok-meta"},{tag:u.invalid,class:"tok-invalid"},{tag:u.punctuation,class:"tok-punctuation"}]);export{m as a,M as b,Ae as c,N as d,F as e,Se as f,We as g,u as h}; //# sourceMappingURL=chunk-FKEIQKC6.min.mjs.map