import{ContextTracker,ExternalTokenizer,LRParser}from"@lezer/lr";import{styleTags,tags}from"@lezer/highlight";import{parseMixed}from"@lezer/common";const scriptText=53,StartCloseScriptTag=1,styleText=54,StartCloseStyleTag=2,textareaText=55,StartCloseTextareaTag=3,StartTag=4,StartScriptTag=5,StartStyleTag=6,StartTextareaTag=7,StartSelfClosingTag=8,StartCloseTag=9,NoMatchStartCloseTag=10,MismatchedStartCloseTag=11,missingCloseTag=56,IncompleteCloseTag=12,commentContent$1=57,Element=18,ScriptText=27,StyleText=30,TextareaText=33,OpenTag=35,Dialect_noMatch=0;const selfClosers={area:true,base:true,br:true,col:true,command:true,embed:true,frame:true,hr:true,img:true,input:true,keygen:true,link:true,meta:true,param:true,source:true,track:true,wbr:true,menuitem:true};const implicitlyClosed={dd:true,li:true,optgroup:true,option:true,p:true,rp:true,rt:true,tbody:true,td:true,tfoot:true,th:true,tr:true};const closeOnOpen={dd:{dd:true,dt:true},dt:{dd:true,dt:true},li:{li:true},option:{option:true,optgroup:true},optgroup:{optgroup:true},p:{address:true,article:true,aside:true,blockquote:true,dir:true,div:true,dl:true,fieldset:true,footer:true,form:true,h1:true,h2:true,h3:true,h4:true,h5:true,h6:true,header:true,hgroup:true,hr:true,menu:true,nav:true,ol:true,p:true,pre:true,section:true,table:true,ul:true},rp:{rp:true,rt:true},rt:{rp:true,rt:true},tbody:{tbody:true,tfoot:true},td:{td:true,th:true},tfoot:{tbody:true},th:{td:true,th:true},thead:{tbody:true,tfoot:true},tr:{tr:true}};function nameChar(ch){return ch==45||ch==46||ch==58||ch>=65&&ch<=90||ch==95||ch>=97&&ch<=122||ch>=161}function isSpace(ch){return ch==9||ch==10||ch==13||ch==32}let cachedName=null,cachedInput=null,cachedPos=0;function tagNameAfter(input,offset){let pos=input.pos+offset;if(cachedPos==pos&&cachedInput==input)return cachedName;let next=input.peek(offset);while(isSpace(next))next=input.peek(++offset);let name="";for(;;){if(!nameChar(next))break;name+=String.fromCharCode(next);next=input.peek(++offset)}cachedInput=input;cachedPos=pos;return cachedName=name?name.toLowerCase():next==question||next==bang?undefined:null}const lessThan=60,greaterThan=62,slash=47,question=63,bang=33,dash=45;function ElementContext(name,parent){this.name=name;this.parent=parent;this.hash=parent?parent.hash:0;for(let i=0;i-1?new ElementContext(tagNameAfter(input,1)||"",context):context},reduce(context,term){return term==Element&&context?context.parent:context},reuse(context,node,stack,input){let type=node.type.id;return type==StartTag||type==OpenTag?new ElementContext(tagNameAfter(input,1)||"",context):context},hash(context){return context?context.hash:0},strict:false});const tagStart=new ExternalTokenizer((input,stack)=>{if(input.next!=lessThan){if(input.next<0&&stack.context)input.acceptToken(missingCloseTag);return}input.advance();let close=input.next==slash;if(close)input.advance();let name=tagNameAfter(input,0);if(name===undefined)return;if(!name)return input.acceptToken(close?IncompleteCloseTag:StartTag);let parent=stack.context?stack.context.name:null;if(close){if(name==parent)return input.acceptToken(StartCloseTag);if(parent&&implicitlyClosed[parent])return input.acceptToken(missingCloseTag,-2);if(stack.dialectEnabled(Dialect_noMatch))return input.acceptToken(NoMatchStartCloseTag);for(let cx=stack.context;cx;cx=cx.parent)if(cx.name==name)return;input.acceptToken(MismatchedStartCloseTag)}else{if(name=="script")return input.acceptToken(StartScriptTag);if(name=="style")return input.acceptToken(StartStyleTag);if(name=="textarea")return input.acceptToken(StartTextareaTag);if(selfClosers.hasOwnProperty(name))return input.acceptToken(StartSelfClosingTag);if(parent&&closeOnOpen[parent]&&closeOnOpen[parent][name])input.acceptToken(missingCloseTag,-1);else input.acceptToken(StartTag)}},{contextual:true});const commentContent=new ExternalTokenizer(input=>{for(let dashes=0,i=0;;i++){if(input.next<0){if(i)input.acceptToken(commentContent$1);break}if(input.next==dash){dashes++}else if(input.next==greaterThan&&dashes>=2){if(i>3)input.acceptToken(commentContent$1,-2);break}else{dashes=0}input.advance()}});function contentTokenizer(tag,textToken,endToken){let lastState=2+tag.length;return new ExternalTokenizer(input=>{for(let state=0,matchedLen=0,i=0;;i++){if(input.next<0){if(i)input.acceptToken(textToken);break}if(state==0&&input.next==lessThan||state==1&&input.next==slash||state>=2&&statematchedLen)input.acceptToken(textToken,-matchedLen);else input.acceptToken(endToken,-(matchedLen-2));break}else if((input.next==10||input.next==13)&&i){input.acceptToken(textToken,1);break}else{state=matchedLen=0}input.advance()}})}const scriptTokens=contentTokenizer("script",scriptText,StartCloseScriptTag);const styleTokens=contentTokenizer("style",styleText,StartCloseStyleTag);const textareaTokens=contentTokenizer("textarea",textareaText,StartCloseTextareaTag);const htmlHighlighting=styleTags({"Text RawText":tags.content,"StartTag StartCloseTag SelfCloserEndTag EndTag SelfCloseEndTag":tags.angleBracket,TagName:tags.tagName,"MismatchedCloseTag/TagName":[tags.tagName,tags.invalid],AttributeName:tags.attributeName,"AttributeValue UnquotedAttributeValue":tags.attributeValue,Is:tags.definitionOperator,"EntityReference CharacterReference":tags.character,Comment:tags.blockComment,ProcessingInst:tags.processingInstruction,DoctypeDecl:tags.documentMeta});const parser=LRParser.deserialize({version:14,states:",xOVOxOOO!WQ!bO'#CoO!]Q!bO'#CyO!bQ!bO'#C|O!gQ!bO'#DPO!lQ!bO'#DRO!qOXO'#CnO!|OYO'#CnO#XO[O'#CnO$eOxO'#CnOOOW'#Cn'#CnO$lO!rO'#DSO$tQ!bO'#DUO$yQ!bO'#DVOOOW'#Dj'#DjOOOW'#DX'#DXQVOxOOO%OQ#tO,59ZO%WQ#tO,59eO%`Q#tO,59hO%hQ#tO,59kO%pQ#tO,59mOOOX'#D]'#D]O%xOXO'#CwO&TOXO,59YOOOY'#D^'#D^O&]OYO'#CzO&hOYO,59YOOO['#D_'#D_O&pO[O'#C}O&{O[O,59YOOOW'#D`'#D`O'TOxO,59YO'[Q!bO'#DQOOOW,59Y,59YOOO`'#Da'#DaO'aO!rO,59nOOOW,59n,59nO'iQ!bO,59pO'nQ!bO,59qOOOW-E7V-E7VO'sQ#tO'#CqOOQO'#DY'#DYO(OQ#tO1G.uOOOX1G.u1G.uO(WQ#tO1G/POOOY1G/P1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!uO!_!wO!`!uO~O_!xO`!xOa!xO!a!wO!b!xO~O_!uO`!uOa!uO!_!{O!`!uO~O_!xO`!xOa!xO!a!{O!b!xO~O`_a!cwz!c~",goto:"%o!_PPPPPPPPPPPPPPPPPP!`!fP!lPP!xPP!{#O#R#X#[#_#e#h#k#q#w!`P!`!`P#}$T$k$q$w$}%T%Z%aPPPPPPPP%gX^OX`pXUOX`pezabcde{}!P!R!TR!q!dRhUR!XhXVOX`pRkVR!XkXWOX`pRnWR!XnXXOX`pQrXR!XpXYOX`pQ`ORx`Q{aQ}bQ!PcQ!RdQ!TeZ!e{}!P!R!TQ!v!oR!z!vQ!y!pR!|!yQgUR!VgQjVR!YjQmWR![mQpXR!^pQtZR!`tS_O`ToXp",nodeNames:"⚠ StartCloseTag StartCloseTag StartCloseTag StartTag StartTag StartTag StartTag StartTag StartCloseTag StartCloseTag StartCloseTag IncompleteCloseTag Document Text EntityReference CharacterReference InvalidEntity Element OpenTag TagName Attribute AttributeName Is AttributeValue UnquotedAttributeValue EndTag ScriptText CloseTag OpenTag StyleText CloseTag OpenTag TextareaText CloseTag OpenTag CloseTag SelfClosingTag Comment ProcessingInst MismatchedCloseTag CloseTag DoctypeDecl",maxTerm:66,context:elementContext,nodeProps:[["closedBy",-11,1,2,3,4,5,6,7,8,9,10,11,"EndTag",-4,19,29,32,35,"CloseTag"],["group",-9,12,15,16,17,18,38,39,40,41,"Entity",14,"Entity TextContent",-3,27,30,33,"TextContent Entity"],["openedBy",26,"StartTag StartCloseTag",-4,28,31,34,36,"OpenTag"]],propSources:[htmlHighlighting],skippedNodes:[0],repeatNodeCount:9,tokenData:"!#b!aR!WOX$kXY)sYZ)sZ]$k]^)s^p$kpq)sqr$krs*zsv$kvw+dwx2yx}$k}!O3f!O!P$k!P!Q7_!Q![$k![!]8u!]!^$k!^!_>b!_!`!!p!`!a8T!a!c$k!c!}8u!}#R$k#R#S8u#S#T$k#T#o8u#o$f$k$f$g&R$g%W$k%W%o8u%o%p$k%p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vKjvwLowxNPx!aKj!a!b! g!b~KjqL`T!bpOvLZvxLox!aLZ!a!bM^!b~LZPLrRO!aLo!a!bL{!b~LoPMORO!`Lo!`!aMX!a~LoPM^OwPqMcT!bpOvLZvxLox!`LZ!`!aMr!a~LZqMyQ!bpwPOv'gx~'gaNUV!``OrNPrsLosvNPvwLow!aNP!a!bNk!b~NPaNpV!``OrNPrsLosvNPvwLow!`NP!`!a! V!a~NPa! ^R!``wPOr(]sv(]w~(]!R! nW!``!bpOrKjrsLZsvKjvwLowxNPx!`Kj!`!a!!W!a~Kj!R!!aT!``!bpwPOr(krs'gsv(kwx(]x~(k!V!!{VgS^P!``!bpOr&Rrs&qsv&Rwx'rx!^&R!^!_(k!_~&R",tokenizers:[scriptTokens,styleTokens,textareaTokens,tagStart,commentContent,0,1,2,3,4,5],topRules:{Document:[0,13]},dialects:{noMatch:0},tokenPrec:476});function getAttrs(element,input){let attrs=Object.create(null);for(let att of element.firstChild.getChildren("Attribute")){let name=att.getChild("AttributeName"),value=att.getChild("AttributeValue")||att.getChild("UnquotedAttributeValue");if(name)attrs[input.read(name.from,name.to)]=!value?"":value.name=="AttributeValue"?input.read(value.from+1,value.to-1):input.read(value.from,value.to)}return attrs}function maybeNest(node,input,tags){let attrs;for(let tag of tags){if(!tag.attrs||tag.attrs(attrs||(attrs=getAttrs(node.node.parent,input))))return{parser:tag.parser}}return null}function configureNesting(tags){let script=[],style=[],textarea=[];for(let tag of tags){let array=tag.tag=="script"?script:tag.tag=="style"?style:tag.tag=="textarea"?textarea:null;if(!array)throw new RangeError("Only script, style, and textarea tags can host nested parsers");array.push(tag)}return parseMixed((node,input)=>{let id=node.type.id;if(id==ScriptText)return maybeNest(node,input,script);if(id==StyleText)return maybeNest(node,input,style);if(id==TextareaText)return maybeNest(node,input,textarea);return null})}export{configureNesting,parser};