Files

2 lines
6.9 KiB
JavaScript
Raw Permalink Normal View History

import{N as F}from"./vendor-lezer-common-tVQBIsvN.js";let z=0;class g{constructor(t,a,n,i){this.name=t,this.set=a,this.base=n,this.modified=i,this.id=z++}toString(){let{name:t}=this;for(let a of this.modified)a.name&&(t=`${a.name}(${t})`);return t}static define(t,a){let n=typeof t=="string"?t:"?";if(t instanceof g&&(a=t),a?.base)throw new Error("Can not derive from a modified tag");let i=new g(n,[],null,[]);if(i.set.push(i),a)for(let s of a.set)i.set.push(s);return i}static defineModifier(t){let a=new q(t);return n=>n.modified.indexOf(a)>-1?n:q.get(n.base||n,n.modified.concat(a).sort((i,s)=>i.id-s.id))}}let G=0;class q{constructor(t){this.name=t,this.instances=[],this.id=G++}static get(t,a){if(!a.length)return t;let n=a[0].instances.find(r=>r.base==t&&L(a,r.modified));if(n)return n;let i=[],s=new g(t.name,i,t,a);for(let r of a)r.instances.push(s);let c=P(a);for(let r of t.set)if(!r.modified.length)for(let m of c)i.push(q.get(r,m));return s}}function L(o,t){return o.length==t.length&&o.every((a,n)=>a==t[n])}function P(o){let t=[[]];for(let a=0;a<o.length;a++)for(let n=0,i=t.length;n<i;n++)t.push(t[n].concat(o[a]));return t.sort((a,n)=>n.length-a.length)}function Z(o){let t=Object.create(null);for(let a in o){let n=o[a];Array.isArray(n)||(n=[n]);for(let i of a.split(" "))if(i){let s=[],c=2,r=i;for(let d=0;;){if(r=="..."&&d>0&&d+3==i.length){c=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!f)throw new RangeError("Invalid path: "+i);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),d+=f[0].length,d==i.length)break;let b=i[d++];if(d==i.length&&b=="!"){c=0;break}if(b!="/")throw new RangeError("Invalid path: "+i);r=i.slice(d)}let m=s.length-1,h=s[m];if(!h)throw new RangeError("Invalid path: "+i);let v=new R(n,c,m>0?s.slice(0,m):null);t[h]=v.sort(t[h])}}return J.add(t)}const J=new F({combine(o,t){let a,n,i;for(;o||t;){if(!o||t&&o.depth>=t.depth?(i=t,t=t.next):(i=o,o=o.next),a&&a.mode==i.mode&&!i.context&&!a.context)continue;let s=new R(i.tags,i.mode,i.context);a?a.next=s:n=s,a=s}return n}});class R{constructor(t,a,n,i){this.tags=t,this.mode=a,this.context=n,this.next=i}get opaque(){return this.mode==0}get inherit(){return this.mode==1}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}}R.empty=new R([],2,null);function Q(o,t){let a=Object.create(null);for(let s of o)if(!Array.isArray(s.tag))a[s.tag.id]=s.class;else for(let c of s.tag)a[c.id]=s.class;let{scope:n,all:i=null}=t||{};return{style:s=>{let c=i;for(let r of s)for(let m of r.set){let h=a[m.id];if(h){c=c?c+" "+h:h;break}}return c},scope:n}}function U(o,t){let a=null;for(let n of o){let i=n.style(t);i&&(a=a?a+" "+i:i)}return a}function _(o,t,a,n=0,i=o.length){let s=new W(n,Array.isArray(t)?t:[t],a);s.highlightRange(o.cursor(),n,i,"",s.highlighters),s.flush(i)}class W{constructor(t,a,n){this.at=t,this.highlighters=a,this.span=n,this.class=""}startSpan(t,a){a!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=a)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,a,n,i,s){let{type:c,from:r,to:m}=t;if(r>=n||m<=a)return;c.isTop&&(s=this.highlighters.filter(b=>!b.scope||b.scope(c)));let h=i,v=X(t)||R.empty,d=U(s,v.tags);if(d&&(h&&(h+=" "),h+=d,v.mode==1&&(i+=(i?" ":"")+d)),this.startSpan(Math.max(a,r),h),v.opaque)return;let f=t.tree&&t.tree.prop(F.mounted);if(f&&f.overlay){let b=t.node.enter(f.overlay[0].from+r,1),V=this.highlighters.filter(w=>!w.scope||w.scope(f.tree.type)),B=t.firstChild();for(let w=0,M=r;;w++){let S=w<f.overlay.length?f.overlay[w]:null,E=S?S.from+r:m,H=Math.max(a,M),A=Math.min(n,E);if(H<A&&B)for(;t.from<A&&(this.highlightRange(t,H,A,i,s),this.startSpan(Math.min(A,t.to),h),!(t.to>=E||!t.nextSibling())););if(!S||E>n)break;M=S.to+r,M>a&&(this.highlightRange(b.cursor(),Math.max(a,S.from+r),Math.min(n,M),"",V),this.startSpan(Math.min(n,M),h))}B&&t.parent()}else if(t.firstChild()){f&&(i="");do if(!(t.to<=a)){if(t.from>=n)break;this.highlightRange(t,a,n,i,s),this.startSpan(Math.min(n,t.to),h)}while(t.nextSibling());t.par