import{NodeProp as D}from"@lezer/common";let Q=0;class m{constructor(t,a,i){this.set=t,this.base=a,this.modified=i,this.id=Q++}static define(t){if(t?.base)throw new Error("Can not derive from a modified tag");let a=new m([],null,[]);if(a.set.push(a),t)for(let i of t.set)a.set.push(i);return a}static defineModifier(){let t=new B;return a=>a.modified.indexOf(t)>-1?a:B.get(a.base||a,a.modified.concat(t).sort((i,l)=>i.id-l.id))}}let U=0;class B{constructor(){this.instances=[],this.id=U++}static get(t,a){if(!a.length)return t;let i=a[0].instances.find(r=>r.base==t&&W(a,r.modified));if(i)return i;let l=[],s=new m(l,t,a);for(let r of a)r.instances.push(s);let c=X(a);for(let r of t.set)if(!r.modified.length)for(let d of c)l.push(B.get(r,d));return s}}function W(o,t){return o.length==t.length&&o.every((a,i)=>a==t[i])}function X(o){let t=[[]];for(let a=0;a<o.length;a++)for(let i=0,l=t.length;i<l;i++)t.push(t[i].concat(o[a]));return t.sort((a,i)=>i.length-a.length)}function Y(o){let t=Object.create(null);for(let a in o){let i=o[a];Array.isArray(i)||(i=[i]);for(let l of a.split(" "))if(l){let s=[],c=2,r=l;for(let f=0;;){if(r=="..."&&f>0&&f+3==l.length){c=1;break}let h=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!h)throw new RangeError("Invalid path: "+l);if(s.push(h[0]=="*"?"":h[0][0]=='"'?JSON.parse(h[0]):h[0]),f+=h[0].length,f==l.length)break;let p=l[f++];if(f==l.length&&p=="!"){c=0;break}if(p!="/")throw new RangeError("Invalid path: "+l);r=l.slice(f)}let d=s.length-1,g=s[d];if(!g)throw new RangeError("Invalid path: "+l);let b=new A(i,c,d>0?s.slice(0,d):null);t[g]=b.sort(t[g])}}return F.add(t)}const F=new D;class A{constructor(t,a,i,l){this.tags=t,this.mode=a,this.context=i,this.next=l}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}}A.empty=new A([],2,null);function J(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:i,all:l=null}=t||{};return{style:s=>{let c=l;for(let r of s)for(let d of r.set){let g=a[d.id];if(g){c=c?c+" "+g:g;break}}return c},scope:i}}function Z(o,t){let a=null;for(let i of o){let l=i.style(t);l&&(a=a?a+" "+l:l)}return a}function V(o,t,a,i=0,l=o.length){let s=new _(i,Array.isArray(t)?t:[t],a);s.highlightRange(o.cursor(),i,l,"",s.highlighters),s.flush(l)}function $(o,t,a,i,l,s=0,c=o.length){let r=s;function d(g,b){if(!(g<=r)){for(let f=o.slice(r,g),h=0;;){let p=f.indexOf(`
`,h),R=p<0?f.length:p;if(R>h&&i(f.slice(h,R),b),p<0)break;l(),h=p+1}r=g}}V(t,a,(g,b,f)=>{d(g,""),d(b,f)},s,c),d(c,"")}class _{constructor(t,a,i){this.at=t,this.highlighters=a,this.span=i,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,i,l,s){let{type:c,from:r,to:d}=t;if(r>=i||d<=a)return;c.isTop&&(s=this.highlighters.filter(p=>!p.scope||p.scope(c)));let g=l,b=z(t)||A.empty,f=Z(s,b.tags);if(f&&(g&&(g+=" "),g+=f,b.mode==1&&(l+=(l?" ":"")+f)),this.startSpan(Math.max(a,r),g),b.opaque)return;let h=t.tree&&t.tree.prop(D.mounted);if(h&&h.overlay){let p=t.node.enter(h.overlay[0].from+r,1),R=this.highlighters.filter(v=>!v.scope||v.scope(h.tree.type)),j=t.firstChild();for(let v=0,M=r;;v++){let O=v<h.overlay.length?h.overlay[v]:null,E=O?O.from+r:d,P=Math.max(a,M),T=Math.min(i,E);if(P<T&&j)for(;t.from<T&&(this.highlightRange(t,P,T,l,s),this.startSpan(Math.min(T,t.to),g),!(t.to>=E||!t.nextSibling())););if(!O||E>i)break;M=O.to+r,M>a&&(this.highlightRange(p.cursor(),Math.max(a,O.from+r),Math.min(i,M),"",R),this.startSpan(Math.min(i,M),g))}j&&t.parent()}else if(t.firstChild()){h&&(l="");do if(!(t.to<=a)){if(t.from>=i)break;this.highlightRange(t,a,i,l,s),this.startSpan(Math.min(i,t.to),g)}while(t.nextSibling());t.parent()}}}function z(o){let t=o.type.prop(F);for(;t&&t.context&&!o.matchContext(t.context);)t=t.next;return t||null}const e=m.define,C=e(),N=e(),G=e(N),L=e(N),x=e(),I=e(x),H=e(x),u=e(),w=e(u),k=e(),y=e(),K=e(),S=e(K),q=e(),n={comment:C,lineComment:e(C),blockComment:e(C),docComment:e(C),name:N,variableName:e(N),typeName:G,tagName:e(G),propertyName:L,attributeName:e(L),className:e(N),labelName:e(N),namespace:e(N),macroName:e(N),literal:x,string:I,docString:e(I),character:e(I),attributeValue:e(I),number:H,integer:e(H),float:e(H),bool:e(x),regexp:e(x),escape:e(x),color:e(x),url:e(x),keyword:k,self:e(k),null:e(k),atom:e(k),unit:e(k),modifier:e(k),operatorKeyword:e(k),controlKeyword:e(k),definitionKeyword:e(k),moduleKeyword:e(k),operator:y,derefOperator:e(y),arithmeticOperator:e(y),logicOperator:e(y),bitwiseOperator:e(y),compareOperator:e(y),updateOperator:e(y),definitionOperator:e(y),typeOperator:e(y),controlOperator:e(y),punctuation:K,separator:e(K),bracket:S,angleBracket:e(S),squareBracket:e(S),paren:e(S),brace:e(S),content:u,heading:w,heading1:e(w),heading2:e(w),heading3:e(w),heading4:e(w),heading5:e(w),heading6:e(w),contentSeparator:e(u),list:e(u),quote:e(u),emphasis:e(u),strong:e(u),link:e(u),monospace:e(u),strikethrough:e(u),inserted:e(),deleted:e(),changed:e(),invalid:e(),meta:q,documentMeta:e(q),annotation:e(q),processingInstruction:e(q),definition:m.defineModifier(),constant:m.defineModifier(),function:m.defineModifier(),standard:m.defineModifier(),local:m.defineModifier(),special:m.defineModifier()},tt=J([{tag:n.link,class:"tok-link"},{tag:n.heading,class:"tok-heading"},{tag:n.emphasis,class:"tok-emphasis"},{tag:n.strong,class:"tok-strong"},{tag:n.keyword,class:"tok-keyword"},{tag:n.atom,class:"tok-atom"},{tag:n.bool,class:"tok-bool"},{tag:n.url,class:"tok-url"},{tag:n.labelName,class:"tok-labelName"},{tag:n.inserted,class:"tok-inserted"},{tag:n.deleted,class:"tok-deleted"},{tag:n.literal,class:"tok-literal"},{tag:n.string,class:"tok-string"},{tag:n.number,class:"tok-number"},{tag:[n.regexp,n.escape,n.special(n.string)],class:"tok-string2"},{tag:n.variableName,class:"tok-variableName"},{tag:n.local(n.variableName),class:"tok-variableName tok-local"},{tag:n.definition(n.variableName),class:"tok-variableName tok-definition"},{tag:n.special(n.variableName),class:"tok-variableName2"},{tag:n.definition(n.propertyName),class:"tok-propertyName tok-definition"},{tag:n.typeName,class:"tok-typeName"},{tag:n.namespace,class:"tok-namespace"},{tag:n.className,class:"tok-className"},{tag:n.macroName,class:"tok-macroName"},{tag:n.propertyName,class:"tok-propertyName"},{tag:n.operator,class:"tok-operator"},{tag:n.comment,class:"tok-comment"},{tag:n.meta,class:"tok-meta"},{tag:n.invalid,class:"tok-invalid"},{tag:n.punctuation,class:"tok-punctuation"}]);export{m as Tag,tt as classHighlighter,z as getStyleTags,$ as highlightCode,V as highlightTree,Y as styleTags,J as tagHighlighter,n as tags};
