codsen-tokenizer
Version:
HTML and CSS lexer aimed at code with fatal errors, accepts mixed coding languages
14 lines (12 loc) • 39.6 kB
JavaScript
/**
* @name codsen-tokenizer
* @fileoverview HTML and CSS lexer aimed at code with fatal errors, accepts mixed coding languages
* @version 7.0.25
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/codsen-tokenizer/}
*/
import{matchLeft as Je,matchRight as ge,matchLeftIncl as _e,matchRightIncl as pe}from"string-match-left-right";import ze from"rfdc";import{left as R,right as I}from"string-left-right";import{isAttrClosing as oe}from"is-html-attribute-closing";import{allHtmlAttribs as ce}from"html-all-known-attributes";import{isAttrNameChar as Re}from"is-char-suitable-for-html-attr-name";import{voidTags as Xe,isPlainObject as j,isLatinLetter as U,inlineTags as Ze,backtick as et}from"codsen-utils";import{leftDoubleQuote as $e,rightDoubleQuote as ie}from"codsen-utils";var Ie=new Set(["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","content","data","datalist","dd","del","details","dfn","dialog","dir","div","dl","dt","element","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","image","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","menuitem","meta","meter","multicol","nav","nextid","nobr","noembed","noframes","noscript","object","ol","optgroup","option","output","p","param","picture","plaintext","pre","progress","q","rb","rp","rt","rtc","ruby","s","samp","script","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"]),v="{}%-$_()*|#",Z="{}|#",re="%()$_*#",fe="({",Ve="})",he=[")|(","|(",")(","()","}{","{}","%)","*)","||","--"],Se=".,;!?";function Te(t){return/[.\-_a-z0-9\u00B7\u00C0-\uFFFD]/i.test(t)}function M(t){let u="";for(let m=0,i=t.length;m<i;m++)t[m]==="["?u=`]${u}`:t[m]==="]"?u=`[${u}`:t[m]==="{"?u=`}${u}`:t[m]==="}"?u=`{${u}`:t[m]==="("?u=`)${u}`:t[m]===")"?u=`(${u}`:t[m]==="<"?u=`>${u}`:t[m]===">"?u=`<${u}`:t[m]===$e?u=`${ie}${u}`:t[m]===ie?u=`${$e}${u}`:u=`${t[m]}${u}`;return u}function ee(t){return Ie.has(t.toLowerCase())||["doctype","cdata","xml"].includes(t.toLowerCase())}function te(t,u,m,i){for(let S=u,C=t.length;S<C;S++){if(t.startsWith(m,S))return!0;if(t.startsWith(i,S))return!1}return!1}var se=["{","}",","],F=`'"${$e}${ie}`,G=/[\w-]/;function He(t){if(t?.length){for(let u=t.length;u--;)if(t[u].type==="esp")return u}}var ne=He;function We(t,u,m){let i=t[u],S=t.length,C=m[ne(m)];for(let c=u+1;c<S&&!(fe.includes(t[c])&&Ve.includes(t[c-1])||i.length>1&&(i.includes("<")||i.includes("{")||i.includes("[")||i.includes("("))&&t[c]==="(");c++)if(v.includes(t[c])||C&&C.guessedClosingLump.includes(t[c])||t[u]==="<"&&t[c]==="/"||t[c]===">"&&i==="--"&&Array.isArray(m)&&m.length&&m[m.length-1].type==="esp"&&m[m.length-1].openingLump[0]==="<"&&m[m.length-1].openingLump[2]==="-"&&m[m.length-1].openingLump[3]==="-"||!C&&c>u&&"!=@".includes(t[c]))i+=t[c];else break;if(i&&Array.isArray(m)&&m.length&&m[m.length-1].type==="esp"&&m[m.length-1].guessedClosingLump&&i.length>m[m.length-1].guessedClosingLump.length){if(i.endsWith(m[m.length-1].openingLump))return i.slice(0,i.length-m[m.length-1].openingLump.length);let c=new Set(m[m.length-1].guessedClosingLump),_=0;for(let s=0,H=i.length;s<H;s++){if(!c.has(i[s])&&_>1)return i.slice(0,s);c.has(i[s])&&(_+=1,c=new Set([...c].filter(N=>N!==i[s])))}}return i}var De=We;import{matchLeft as Fe,matchRight as ke,matchRightIncl as Ne}from"string-match-left-right";function Me(t,u,m,i){return!!(t[u]==="<"&&(ke(t,u,["!--"],{maxMismatches:1,firstMustMatch:!0,trimBeforeMatching:!0})||Ne(t,u,["<![endif]"],{i:!0,maxMismatches:2,trimBeforeMatching:!0}))&&!ke(t,u,["![cdata","<"],{i:!0,maxMismatches:1,trimBeforeMatching:!0})&&(m.type!=="comment"||m.kind!=="not")||t[u]==="-"&&Ne(t,u,["-->"],{trimBeforeMatching:!0})&&(m.type!=="comment"||!m.closing&&m.kind!=="not")&&!Fe(t,u,"<",{trimBeforeMatching:!0,trimCharsBeforeMatching:["-","!"]})&&(!Array.isArray(i)||!i.length||i[i.length-1].type!=="esp"||!(i[i.length-1].openingLump[0]==="<"&&i[i.length-1].openingLump[2]==="-"&&i[i.length-1].openingLump[3]==="-")))}var Ae=Me;function Be(t,u,m,i,S){return S&&(t[u]==="/"&&t[u+1]==="*"||t[u]==="*"&&t[u+1]==="/")}var Oe=Be;function Ue(t,u,m=!1){if(!u.length)return;let i=m?u[0]:u[u.length-1];if(i.type==="esp"&&(t.includes(i.guessedClosingLump)||Array.from(t).every(S=>i.guessedClosingLump.includes(S))||i.guessedClosingLump&&i.guessedClosingLump.length>2&&i.guessedClosingLump[i.guessedClosingLump.length-1]===t[t.length-1]&&i.guessedClosingLump[i.guessedClosingLump.length-2]===t[t.length-2]))return t.length}var le=Ue;import{isOpening as be}from"is-html-tag-opening";import{matchRight as Qe}from"string-match-left-right";import{backslash as qe,isLatinLetter as me}from"codsen-utils";function Ye(t,u,m,i,S,C,c){return!!(t[u]?.trim().length&&(!i.length||m.type==="text")&&(!m.kind||!["doctype","xml"].includes(m.kind))&&(!S||t[u]==="<")&&(t[u]==="<"&&(be(t,u,{allowCustomTagNames:!0})||t[c]===">"||Qe(t,u,["doctype","xml","cdata"],{i:!0,trimBeforeMatching:!0,trimCharsBeforeMatching:["?","!","["," ","-"]}))||t[u]==="/"&&me(t[u+1])&&t[C]!=="<"&&be(t,u,{allowCustomTagNames:!0,skipOpeningBracket:!0})||me(t[u])&&(!t[u-1]||!me(t[u-1])&&!["<","/","!",qe].includes(t[C]))&&be(t,u,{allowCustomTagNames:!1,skipOpeningBracket:!0}))&&(m.type!=="esp"||m?.tail?.includes(t[u])))}var Ce=Ye;import{right as Ke}from"string-left-right";function Ge(t,u,m,i,S){return!!(v.includes(t[u])&&t[u+1]&&v.includes(t[u+1])&&!(re.includes(t[u])&&re.includes(t[u+1]))&&(t[u]!==t[u+1]||Z.includes(t[u]))&&m.type!=="rule"&&m.type!=="at"&&!(t[u]==="-"&&"-{(".includes(t[u+1]))&&!("})".includes(t[u])&&"-".includes(t[u+1]))&&!(t[u]==="%"&&t[u+1]==="%"&&"0123456789".includes(t[u-1])&&(!t[u+2]||Se.includes(t[u+2])||!t[u+2].trim().length))&&!(S&&("{}".includes(t[u])||"{}".includes(t[Ke(t,u)])))||t[u]==="<"&&(t[u+1]==="/"&&v.includes(t[u+2])||v.includes(t[u+1])&&!["-"].includes(t[u+1]))||t[u]==="<"&&(t[u+1]==="%"||t.startsWith("jsp:",u+1)||t.startsWith("cms:",u+1)||t.startsWith("c:",u+1))||t.startsWith("${jspProp",u)||">})".includes(t[u])&&Array.isArray(i)&&i.length&&i[i.length-1].type==="esp"&&i[i.length-1].openingLump.includes(M(t[u]))&&(t[u]!==">"||!te(t,u+1,">","<"))||t[u]==="-"&&t[u+1]==="-"&&t[u+2]===">"&&Array.isArray(i)&&i.length&&i[i.length-1].type==="esp"&&i[i.length-1].openingLump[0]==="<"&&i[i.length-1].openingLump[2]==="-"&&i[i.length-1].openingLump[3]==="-")}var ve=Ge;var Le="7.0.25";var y=ze(),rn=Le,tt=/^\s*!?\s*[a-zA-Z0-9]+(?:[\s;}<>'"]|$)/gm,nt={tagCb:null,tagCbLookahead:0,charCb:null,charCbLookahead:0,reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100};function sn(t,u){let m=Date.now();if(typeof t!="string")throw t===void 0?new Error("codsen-tokenizer: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`codsen-tokenizer: [THROW_ID_02] the first input argument must be string! It was given as "${typeof t}", equal to:
${JSON.stringify(t,null,4)}`);if(u&&!j(u))throw new Error(`codsen-tokenizer: [THROW_ID_03] the second input argument, an options object, should be a plain object but it was given as type ${typeof u}, equal to ${JSON.stringify(u,null,4)}`);if(u&&j(u)&&u.tagCb&&typeof u.tagCb!="function")throw new Error(`codsen-tokenizer: [THROW_ID_04] the opts.tagCb, callback function, should be a function but it was given as type ${typeof u.tagCb}, equal to ${JSON.stringify(u.tagCb,null,4)}`);if(u&&j(u)&&u.charCb&&typeof u.charCb!="function")throw new Error(`codsen-tokenizer: [THROW_ID_05] the opts.charCb, callback function, should be a function but it was given as type ${typeof u.charCb}, equal to ${JSON.stringify(u.charCb,null,4)}`);if(u&&j(u)&&u.reportProgressFunc&&typeof u.reportProgressFunc!="function")throw new Error(`codsen-tokenizer: [THROW_ID_06] the opts.reportProgressFunc, callback function, should be a function but it was given as type ${typeof u.reportProgressFunc}, equal to ${JSON.stringify(u.reportProgressFunc,null,4)}`);let i={...nt,...u},S=0,C=0,c=t.length,_=Math.floor(c/2),s=0,H=!1,N=!1,ue=!1,Q=[],q=[],n={};function L(){n={type:null,start:null,end:null,value:null},V()}let Ee={attribName:"",attribNameRecognised:!1,attribNameStartsAt:null,attribNameEndsAt:null,attribOpeningQuoteAt:null,attribClosingQuoteAt:null,attribValueRaw:null,attribValue:[],attribValueStartsAt:null,attribValueEndsAt:null,attribStarts:null,attribEnds:null,attribLeft:null},l={...Ee};function V(){l=y(Ee)}function de(e){l.attribValue.length&&l.attribValue[~-l.attribValue.length].start&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].end=e.start,l.attribValue[~-l.attribValue.length].value=t.slice(l.attribValue[~-l.attribValue.length].start,e.start)),l.attribValue.push(e)}let ae={start:null,end:null,property:null,propertyStarts:null,propertyEnds:null,value:null,valueStarts:null,valueEnds:null,important:null,importantStarts:null,importantEnds:null,colon:null,semi:null},o={...ae};function T(){o={...ae}}function D(e){l?.attribName==="style"?l.attribValue.push({...e}):n&&Array.isArray(n.properties)&&n.properties.push({...e})}L();let Y,h,g,A=null,$=[];function k(e){return!!(Array.isArray($)&&$.length&&$[~-$.length].type===e)}function ye(e){let p=(I(t,e)||e)+1;de({type:"comment",start:e,end:p,value:t.slice(e,p),closing:!0,kind:"block",language:"css"}),s=p,k("block")&&$.pop()}function z(e,p,r){let f=e.shift(),W=[];for(let w=0;w<r&&e[w];w++)W.push(y(e[w]));typeof p=="function"&&p(f,W)}function Pe(e){i.charCb&&(q.push(e),q.length>i.charCbLookahead&&z(q,i.charCb,i.charCbLookahead))}function P(e){i.tagCb&&(Q.push(e),Q.length>i.tagCbLookahead&&z(Q,i.tagCb,i.tagCbLookahead))}function x(e,p){if(!["text","esp"].includes(e.type)&&e.start!==null&&e.start<p&&(t[~-p]&&!t[~-p].trim()||t[p]==="<"))if(R(t,p)!==null?e.end=R(t,p)+1:e.end=p,e.value=t.slice(e.start,e.end),e.type==="tag"&&!"/>".includes(t[~-e.end])){let r=e.tagNameEndsAt||p;if(Array.isArray(e.attribs)&&e.attribs.length)for(let f=0,W=e.attribs.length;f<W;f++)if(e.attribs[f].attribNameRecognised&&e.attribs[f].attribEnds)r=e.attribs[f].attribEnds,t[r+1]&&!t[r].trim()&&t[r+1].trim()&&(r+=1);else{f===0?e.attribs=[]:e.attribs=e.attribs.splice(0,f);break}e.end=r,e.value=t.slice(e.start,e.end),e.tagNameEndsAt||(e.tagNameEndsAt=r),e.tagNameStartsAt&&e.tagNameEndsAt&&!e.tagName&&(e.tagName=t.slice(e.tagNameStartsAt,r),e.recognised=ee(e.tagName)),P(e),J("text",r),V()}else P(e),L(),t[~-p]&&!t[~-p].trim()&&(J("text",R(t,p)+1),V());n.start!==null&&(n.end===null&&n.start!==p&&(n.end=p,n.value=t.slice(n.start,n.end)),n.start!==null&&n.end&&(k("at")?$[~-$.length].token.rules.push(n):P(n)),L())}function xe(){return k("at")&&j($[~-$.length].token)&&!!$[~-$.length].token.openingCurlyAt&&!$[~-$.length].token.closingCurlyAt}function X(e,p=null){return e==="tag"?{type:e,start:p,end:null,value:null,tagNameStartsAt:null,tagNameEndsAt:null,tagName:null,recognised:null,closing:!1,void:!1,pureHTML:!0,kind:null,attribs:[]}:e==="comment"?{type:e,start:p,end:null,value:null,closing:!1,kind:"simple",language:"html"}:e==="rule"?{type:e,start:p,end:null,value:null,left:null,nested:!1,openingCurlyAt:null,closingCurlyAt:null,selectorsStart:null,selectorsEnd:null,selectors:[],properties:[]}:e==="at"?{type:e,start:p,end:null,value:null,left:null,nested:!1,openingCurlyAt:null,closingCurlyAt:null,identifier:null,identifierStartsAt:null,identifierEndsAt:null,query:null,queryStartsAt:null,queryEndsAt:null,rules:[]}:e==="esp"?{type:e,start:p,end:null,value:null,head:null,headStartsAt:null,headEndsAt:null,tail:null,tailStartsAt:null,tailEndsAt:null}:{type:"text",start:p,end:null,value:null}}function J(e,p){n=X(e,p)}function B(e){T(),typeof e=="number"?(o.propertyStarts=e,o.start=e):o={...ae,...e}}function K(e){return!`'"`.includes(t[e])||!(l.attribOpeningQuoteAt||l.attribValueStartsAt)||oe(t,l.attribOpeningQuoteAt||l.attribValueStartsAt,e)}function we(e,p){return";}/".includes(t[e])&&(!l?.attribName||l.attribName!=="style")||`/;'"><`.includes(t[e])&&l&&l.attribName==="style"&&(p||K(e))}for(let e=0;e<=c;e++){!s&&t[e]&&i.reportProgressFunc&&(c>1e3&&c<2e3?e===_&&i.reportProgressFunc(Math.floor((i.reportProgressFuncTo-i.reportProgressFuncFrom)/2)):c>=2e3&&(S=i.reportProgressFuncFrom+Math.floor(e/c*(i.reportProgressFuncTo-i.reportProgressFuncFrom)),S!==C&&(C=S,i.reportProgressFunc(S))));let p=R(t,e),r=I(t,e);if(N&&n.type&&!["rule","at","text","comment"].includes(n.type)&&(N=!1),s&&e>=s&&(s=0),U(t[e])&&U(t[~-e])&&U(t[e+1])){o?.valueStarts&&!o.valueEnds&&!o.importantStarts&&t.startsWith("important",e)&&(o.valueEnds=e,o.value=t.slice(o.valueStarts,e),o.importantStarts=e);continue}if(` \r
`.includes(t[e])&&t[e]===t[~-e]&&t[e]===t[e+1])continue;if(!s&&xe())if(t[e]==="}"){if(!n.type||n.type==="text"||n.type==="rule"&&n.openingCurlyAt===null){n.type==="rule"&&(n.end=p+1,n.value=t.slice(n.start,n.end),P(n),k("at")&&$[~-$.length].token.rules.push(n),L(),p!==null&&p<~-e&&(J("text",p+1),V())),x(n,e);let a=$.pop();n=y(a.token),n.closingCurlyAt=e,n.end=e+1,n.value=t.slice(n.start,n.end),P(n),k("at")&&$[~-$.length].token.rules.push(n),L(),s=e+1}}else n.type==="text"&&t[e]?.trim()&&(n.end=e,n.value=t.slice(n.start,n.end),k("at")?$[~-$.length].token.rules.push(n):P(n),L());if(n.end&&n.end===e&&(n.tagName==="style"&&!n.closing&&(N=!0),g?(l=g,l.attribValue.push(n),n=y(h),g=void 0,h=void 0):(x(n,e),$.length=0)),s||(["tag","at"].includes(n.type)&&n.kind!=="cdata"?t[e]&&(F.includes(t[e])||"()".includes(t[e]))&&!(F.includes(t[p])&&t[p]===t[r])&&K(e)&&(k("simple")&&$[~-$.length].value===M(t[e])?$.pop():$.push({type:"simple",value:t[e],position:e})):n.type==="comment"&&["only","not"].includes(n.kind)?["[","]"].includes(t[e])&&(k("simple")&&$[~-$.length].value===M(t[e])?$.pop():$.push({type:"simple",value:t[e],position:e})):n.type==="esp"&&`'"${et}()`.includes(t[e])&&!(['"',"'","`"].includes(t[p])&&t[p]===t[r])&&(k("simple")&&$[~-$.length].value===M(t[e])?($.pop(),s=e+1):"]})>".includes(t[e])||$.push({type:"simple",value:t[e],position:e}))),!s&&n.type==="at"&&n.start!=null&&e>=n.start&&!n.identifierStartsAt&&t[e]?.trim()&&t[e]!=="@"&&(n.identifierStartsAt=e),!s&&n.type==="at"&&n.queryStartsAt&&!n.queryEndsAt&&"{;".includes(t[e])&&(t[e]==="{"?t[~-e]?.trim()?n.queryEndsAt=e:n.queryEndsAt=p!==null?p+1:e:n.queryEndsAt=R(t,e+1)||0,n.queryStartsAt&&n.queryEndsAt&&(n.query=t.slice(n.queryStartsAt,n.queryEndsAt)),n.end=t[e]===";"?e+1:e,n.value=t.slice(n.start,n.end),t[e]===";"?P(n):(n.openingCurlyAt=e,$.push({type:"at",token:n})),L(),s=e+1),!s&&n.type==="at"&&n.identifier&&t[e]?.trim()&&!n.queryStartsAt&&(n.queryStartsAt=e),!s&&n&&n.type==="at"&&n.identifierStartsAt&&e>=n.start&&t[e]&&(!t[e].trim()||"()".includes(t[e]))&&!n.identifierEndsAt&&(n.identifierEndsAt=e,n.identifier=t.slice(n.identifierStartsAt,e)),n.type==="rule"){if(Y&&(se.includes(t[e])||t[e]&&r&&!t[e].trim()&&se.includes(t[r])))n.selectors.push({value:t.slice(Y,e),selectorStarts:Y,selectorEnds:e}),Y=void 0,n.selectorsEnd=e;else if(t[e]==="{"&&t[e-1]!=="{"&&t[e+1]!=="{"&&n.openingCurlyAt&&!n.closingCurlyAt){for(let a=e;a--;)if(!t[a].trim()||`{}"';`.includes(t[a])){o?.start&&!o.end&&(o.end=a+1,o.property=t.slice(o.start,o.end),D(o),T(),n.end=a+1,n.value=t.slice(n.start,n.end),P(n),J(t[a+1]==="@"?"at":"rule",a+1),V(),n.left=R(t,a+1),n.selectorsStart=a+1,e=a+1);break}}}let f=ne($);if(!s&&t[e])if(Ce(t,e,n,$,N,p,r)){n.type&&n.start!==null&&(n.type==="rule"&&o?.start&&(o.importantStarts&&!o.importantEnds&&(o.importantEnds=e,o.important=t.slice(o.importantStarts,e)),o.propertyStarts&&!o.propertyEnds&&(o.propertyEnds=e,o.property||(o.property=t.slice(o.propertyStarts,e))),o.end||(o.end=e),o.valueStarts&&!o.valueEnds&&(o.valueEnds=e,o.value||(o.value=t.slice(o.valueStarts,e))),D(o),T()),x(n,e),L()),J("tag",e),V(),N&&(N=!1);let a="?![-/",b="",d=!1;if(r)for(let E=r;E<c&&(!d&&t[E]?.trim()&&t[E].toUpperCase()!==t[E].toLowerCase()&&(d=!0),!(d&&t[E]&&(!t[E].trim()||!/\w/.test(t[E])&&!a.includes(t[E])||t[E]==="[")));E++)a.includes(t[E])||(b+=t[E].trim().toLowerCase());b==="doctype"?n.kind="doctype":b==="cdata"?n.kind="cdata":b==="xml"?n.kind="xml":Ze.has(b)&&(n.kind="inline",b&&(s=e))}else if(!H&&Ae(t,e,n,$))n.start!=null&&x(n,e),J("comment",e),V(),t[e]==="-"?n.closing=!0:pe(t,e,["<![endif]-->"],{i:!0,trimBeforeMatching:!0,maxMismatches:2})&&(n.closing=!0,n.kind="only"),N&&(N=!1);else if(!H&&Oe(t,e,n,$,N))n.start!=null&&x(n,e),J("comment",e),V(),n.language="css",n.kind=t[e]==="/"&&t[e+1]==="/"?"line":"block",n.value=t.slice(e,e+2),n.end=e+2,n.closing=t[e]==="*"&&t[e+1]==="/",ue=!0,n.closing&&(ue=!1),s=e+2;else if(!H&&(typeof f=="number"&&$[f]&&$[f].type==="esp"&&$[f].openingLump&&$[f].guessedClosingLump&&$[f].guessedClosingLump.length>1&&$[f].guessedClosingLump.includes(t[e])&&$[f].guessedClosingLump.includes(t[e+1])&&!($[f+1]&&`'"`.includes($[f+1].value)&&t.indexOf($[f+1].value,e)>0&&$[f].guessedClosingLump.includes(t[I(t,t.indexOf($[f+1].value,e))]))||ve(t,e,n,$,N)&&(!k("simple")||!["'",'"'].includes($[~-$.length].value)||l?.attribStarts&&!l.attribEnds))){l?.attribValue.length&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].end=e,l.attribValue[~-l.attribValue.length].value=t.slice(l.attribValue[~-l.attribValue.length].start,e));let a=De(t,e,$);if(!he.includes(a)){let b,d={char:"",idx:0};if($.length&&(b=le(a,$))){if(n.type==="esp"){if(n.end||(n.end=e+b,n.value=t.slice(n.start,n.end),n.tail=t.slice(e,e+b),n.tailStartsAt=e,n.tailEndsAt=n.end,t[e]===">"&&t[p]==="/"&&(n.tailStartsAt=p,n.tail=t.slice(n.tailStartsAt,e+1))),s=n.tailEndsAt,h){Array.isArray(h.attribs)||(h.attribs=[]),o?.start?(Array.isArray(o.value)||(o.value=[]),o.value.push({...n})):g?(l=g,l.attribValue.push({...n})):l?.attribStarts&&Array.isArray(l.attribValue)?l.attribValue.push({...n}):h.attribs.push({...n}),n=y(h),h=void 0,g=void 0,$.pop();continue}else x(n,e);L()}$.pop()}else if($.length&&(b=le(a,$,!0)))n.type==="esp"&&(n.end||(n.end=e+(b||0),n.value=t.slice(n.start,n.end)),n.tailStartsAt||(n.tailStartsAt=e),!n.tailEndsAt&&b&&(n.tailEndsAt=n.tailStartsAt+b,n.tail=t.slice(e,e+b)),x(n,e),L()),$.length=0;else if(l?.attribValue?.length&&l.attribValue[~-l.attribValue.length].start&&Array.from(t.slice(l.attribValue[~-l.attribValue.length].start,e)).some((E,O)=>a.includes(M(E))&&(Z.includes(E)||!O)&&(d={char:E,idx:O}))&&n.type==="tag"&&l?.attribValueStartsAt&&!l.attribValueEndsAt&&l.attribValue[~-l.attribValue.length]&&l.attribValue[~-l.attribValue.length].type==="text"){n.pureHTML=!1;let E=l.attribValue[~-l.attribValue.length],O=X("esp",E.start);d.idx||(O.head=d.char,O.headStartsAt=E.start,O.headEndsAt=O.headStartsAt+1,O.tailStartsAt=e,O.tailEndsAt=e+a.length,O.tail=a,l.attribValue[~-l.attribValue.length]=O)}else{if(k("esp")&&$.pop(),g&&(Array.isArray(g.attribValue)||(g.attribValue=[]),g.attribValue.push(n)),$.push({type:"esp",openingLump:a,guessedClosingLump:M(a),position:e}),n.start!==null)if(n.type==="tag"){if(l&&l.attribName==="style"){if(o.start&&!o.end&&o.propertyEnds&&!o.valueStarts)o.valueStarts=e;else if(o.start&&!Array.isArray(o.value)&&(o.propertyStarts&&!o.propertyEnds?(o.propertyEnds=p+1,o.property=t.slice(o.propertyStarts,e)):o.valueStarts&&!o.valueEnds&&(o.valueEnds=p+1,o.value=t.slice(o.valueStarts,o.valueEnds)),o.start&&!o.end&&(o.end=p+1),l&&Array.isArray(l.attribValue))){if(l.attribValue.push(y(o)),o.end!==e){let E=X("text",p+1);E.end=e,E.value=t.slice(p+1,e),l.attribValue.push(y(E))}T()}}else n.tagNameStartsAt&&(!n.tagName||!n.tagNameEndsAt)&&(n.tagNameEndsAt=e,n.tagName=t.slice(n.tagNameStartsAt,e),n.recognised=ee(n.tagName)),l.attribStarts&&!l.attribEnds&&(g=y(l));h=y(n)}else n.type==="text"?(n.end=e,n.value=t.slice(n.start,e),Array.isArray(o.value)?o.value.push(n):x(n,e)):g?g&&Array.isArray(g.attribValue)&&g.attribValue.length&&g.attribValue[~-g.attribValue.length].type==="esp"&&!g.attribValue[~-g.attribValue.length].end&&(g.attribValue[~-g.attribValue.length].end=e,g.attribValue[~-g.attribValue.length].value=t.slice(g.attribValue[~-g.attribValue.length].start,e)):x(n,e);J("esp",e),n.head=a,n.headStartsAt=e,n.headEndsAt=e+a.length,h?.pureHTML&&(h.pureHTML=!1),g&&Array.isArray(g.attribValue)&&g.attribValue.length&&(g.attribValue[~-g.attribValue.length].start===n.start?g.attribValue.pop():g.attribValue[~-g.attribValue.length].type==="text"&&!g.attribValue[~-g.attribValue.length].end&&(g.attribValue[~-g.attribValue.length].end=e,g.attribValue[~-g.attribValue.length].value=t.slice(g.attribValue[~-g.attribValue.length].start,e)))}s=e+(b||a.length)}}else!H&&N&&!ue&&t[e]?.trim()&&!"{}".includes(t[e])&&(!n.type||["text"].includes(n.type))?(n.type&&x(n,e),J(t[e]==="@"?"at":"rule",e),V(),n.left=A,n.nested=$.some(a=>a.type==="at")):n.type||(J("text",e),V(),H&&t.indexOf("</script>",e)?s=t.indexOf("</script>",e):s=e);let W,w;if(!s&&t[e]&&(o.start||t[e]==="!")&&(!$.length||$[~-$.length].type!=="esp")&&(n.type!=="text"||Array.isArray(o.value))){let a=I(t,e-1);W=";<>".includes(t[a])||`'"`.includes(t[a])&&(!$?.length||!$[~-$.length]||!$[~-$.length].value||$[~-$.length].value===t[a]),w=pe(t,e,["!important"],{i:!0,trimBeforeMatching:!0,maxMismatches:2})}if(!s&&o&&(o.semi&&o.semi<e&&o.semi<e||(o.valueStarts&&!o.valueEnds&&t[r]!=="!"&&(!r||W)||o.importantStarts&&!o.importantEnds)&&(!o.valueEnds||t[r]!==";")&&(!t[e]?.trim()||!o.valueEnds&&t[e]===";"||we(e,Array.isArray(o.value)&&o.value[~-o.value.length].type==="esp")))){o.importantStarts&&!o.importantEnds&&(o.importantEnds=R(t,e)+1,o.important=t.slice(o.importantStarts,o.importantEnds)),o.valueStarts&&!o.valueEnds&&(o.valueEnds=R(t,e)+1,Array.isArray(o.value)||(o.value=t.slice(o.valueStarts,o.valueEnds))),t[e]===";"?(o.semi=e,o.end=e+1):t[r]===";"&&(o.semi=r,o.end=o.semi+1,s=o.end),o.end||(o.end=R(t,e)+1),n.type==="text"&&n.start&&!n.end&&(n.end=e,n.value=t.slice(n.start,e),Array.isArray(o.value)&&o.value.push(n),h&&(n=y(h)));let a;o.valueEnds!==e&&!o.important&&!t[e-1].trim()&&(a=X("text",o.valueEnds),a.end=e,a.value=t.slice(o.valueEnds,e)),D(o),T(),a&&D(a),!s&&(!t[e]||t[e].trim())&&t[e]===";"&&(s=e)}if(!s&&o?.start&&o.valueStarts&&!o.valueEnds)if(!t[e]||W||w||t[I(t,e-1)]==="!"||";}".includes(t[e])&&(!l?.attribName||l.attribName!=="style")||`;'"`.includes(t[e])&&l&&l.attribName==="style"&&K(e)||r&&!t[e].trim()&&(t.slice(e,r).includes(`
`)||t.slice(e,r).includes("\r")))A&&(!`'"`.includes(t[e])||!r||!`'";`.includes(t[r]))&&(o.valueEnds=A+1,n.type==="text"&&(n.end=e,n.value=t.slice(n.start,e),Array.isArray(o.value)&&o.value.push(n),n=y(h)),Array.isArray(o.value)||(o.value=t.slice(o.valueStarts,A+1))),t[e]===";"?o.semi=e:t[e]&&!t[e].trim()&&t[r]===";"&&(o.semi=r),o.semi&&(o.end=o.semi+1),!o.semi&&!W&&!w&&t[I(t,e-1)]!=="!"&&!o.end&&(o.end=e),o.end&&(o.end>e&&(s=o.end),D(o),T());else if(t[e]===":"&&o?.colon&&o.colon<e&&A&&o.colon+1<A){let a=[];if(I(t,o.colon)&&(a=t.slice(I(t,o.colon),A+1).split(/\s+/)),a.length===2){o.valueEnds=o.valueStarts+a[0].length,o.value=t.slice(o.valueStarts,o.valueEnds),o.end=o.valueEnds,D(o);let b=o.end,d=A+1-a[1].length;T(),D({type:"text",start:b,end:d,value:t.slice(b,d)}),o.start=d,o.propertyStarts=d}}else t[e]==="/"&&t[r]==="*"&&(o.valueStarts&&!o.valueEnds&&(o.valueEnds=e,o.value=t.slice(o.valueStarts,e)),o.end||(o.end=e),D(o),T());if(!s&&o?.start&&!o.end&&t[e]===";"&&(o.semi=e,o.end=e+1,o.propertyEnds||(o.propertyEnds=e),o.propertyStarts&&o.propertyEnds&&!o.property&&(o.property=t.slice(o.propertyStarts,o.propertyEnds)),D(o),T(),s=e),o?.importantStarts&&!o.importantEnds&&t[e]&&!t[e].trim()&&(o.importantEnds=e,o.important=t.slice(o.importantStarts,e)),!s&&o?.valueEnds&&!o.importantStarts&&(t[e]==="!"||U(t[e])&&t.slice(e).match(tt))&&(o.importantStarts=e,(t[e-1]?.trim()&&t[e-2]&&!t[e-2].trim()||t[e-1]==="1"&&t[e-2]&&!/\d/.test(t[e-2]))&&(o.valueEnds=R(t,e-1)+1,o.value=t.slice(o.valueStarts,o.valueEnds),o.importantStarts--,o.important=`${t[e-1]}${o.important}`)),!s&&o?.colon&&!o.valueStarts&&(!$.length||$[~-$.length].type!=="esp")&&t[e]?.trim())if(`;}'"`.includes(t[e])&&K(e)){t[e]===";"&&(o.semi=e);let a;o.end||(o.end=o.semi?o.semi+1:R(t,e)+1,a=o.end),D(o),T(),a&&a<e&&D({type:"text",start:a,end:e,value:t.slice(a,e)})}else t[e]==="!"?o.importantStarts=e:o.valueStarts=e;if(!s&&t[e]==="{"&&t[e+1]==="{"&&o?.valueStarts&&!o.valueEnds&&t.indexOf("}}",e)>0&&(s=t.indexOf("}}")+2),!s&&n.type==="rule"&&t[e]?.trim()&&!"{}".includes(t[e])&&!Y&&!n.openingCurlyAt&&(",".includes(t[e])?n.selectorsEnd=e+1:(Y=e,n.selectorsStart===null&&(n.selectorsStart=e))),!s&&o?.propertyStarts&&o.propertyStarts<e&&!o.propertyEnds&&(!t[e]?.trim()||!G.test(t[e])&&(t[e]===":"||!r||!":/}".includes(t[r])||t[e]==="}"&&t[r]==="}")||t[e]==="!")&&(t[e]!=="/"||t[e-1]!=="/")&&(o.propertyEnds=e,o.property=t.slice(o.propertyStarts,e),o.valueStarts&&(o.end=e),("};".includes(t[e])||t[e]&&!t[e].trim()&&t[r]!==":")&&(t[e]===";"&&(o.semi=e),o.end||(o.end=o.semi?o.semi+1:e),D(o),T()),t[e]?.trim()&&G.test(t[o.propertyStarts])&&!G.test(t[e])&&!`:'"`.includes(t[e]))){let a=t.indexOf(";",e),b=t.indexOf(":",e);(b===-1&&a!==-1||!(b!==-1&&a!==-1&&b<a))&&!"{}".includes(t[e])&&r&&(!"!".includes(t[e])||U(t[r]))?(o.colon=e,o.valueStarts=r):b!==-1&&a!==-1&&b<a?o.propertyEnds=null:t[e]==="!"&&(o.importantStarts=e)}if(!s&&o?.propertyEnds&&!o.valueStarts&&t[e]===":"&&(o.colon=e,r||(o.end=e+1,t[e+1]&&(D(o),T(),n.properties&&(n.properties.push({type:"text",start:e+1,end:null,value:null}),s=e+1))),o.propertyEnds&&A&&o.propertyEnds!==A+1&&!G.test(t[o.propertyEnds])&&(o.propertyEnds=A+1,o.property=t.slice(o.propertyStarts,o.propertyEnds))),!s&&n.type==="rule"&&t[e]?.trim()&&!"{}".includes(t[e])&&n.selectorsEnd&&n.openingCurlyAt&&!o.propertyStarts&&!o.importantStarts&&(Array.isArray(n.properties)&&n.properties.length&&n.properties[~-n.properties.length].start&&!n.properties[~-n.properties.length].end&&(n.properties[~-n.properties.length].end=e,n.properties[~-n.properties.length].value=t.slice(n.properties[~-n.properties.length].start,e)),t[e]===";"?(B({start:e,end:e+1,semi:e}),D(o),T()):t[e]==="!"?B({start:e,importantStarts:e}):B(e),s=e),!s&&(!n||n.type!=="esp")&&l&&l.attribName==="style"&&l.attribOpeningQuoteAt&&!l.attribClosingQuoteAt&&!o.start&&t[e]?.trim()&&!`'"`.includes(t[e])&&!k("block")&&(t[e]==="/"&&t[r]==="*"?(de({type:"comment",start:e,end:r+1,value:t.slice(e,r+1),closing:!1,kind:"block",language:"css"}),$.push({type:"block",value:t.slice(e,r+1),position:e}),s=r+1):t[e]==="*"&&t[r]==="/"?ye(e):(Array.isArray(l.attribValue)&&l.attribValue.length&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].end=e,l.attribValue[~-l.attribValue.length].value=t.slice(l.attribValue[~-l.attribValue.length].start,e)),t[e]===";"?(B({start:e,end:e+1,semi:e}),s=e):B(w?{start:e,importantStarts:e}:e))),n.type==="comment"&&["only","not"].includes(n.kind)&&t[e],!s){if(n.type==="tag"&&!$.length&&t[e]===">")n.end=e+1,n.value=t.slice(n.start,n.end);else if(n.type==="comment"&&n.language==="html"&&!$.length&&n.kind==="simple"&&(t[n.start]==="<"&&t[e]==="-"&&(Je(t,e,"!-",{trimBeforeMatching:!0})||_e(t,e,"!-",{trimBeforeMatching:!0})&&t[e+1]!=="-")||t[n.start]==="-"&&t[e]===">"&&Je(t,e,"--",{trimBeforeMatching:!0,maxMismatches:1})))t[e]==="-"&&(ge(t,e,["[if","(if","{if"],{i:!0,trimBeforeMatching:!0})||ge(t,e,["if"],{i:!0,trimBeforeMatching:!0})&&(te(t,e,"]",">")||t.includes("mso",e)&&!t.slice(e,t.indexOf("mso")).includes("<")&&!t.slice(e,t.indexOf("mso")).includes(">")))?n.kind="only":t[n.start]!=="-"&&pe(t,e,["-<![endif"],{i:!0,trimBeforeMatching:!0,maxMismatches:2})?(n.kind="not",n.closing=!0):n.kind==="simple"&&n.language==="html"&&!n.closing&&t[r]===">"?(n.end=r+1,n.kind="simplet",n.closing=null):n.language==="html"&&(n.end=e+1,t[p]==="!"&&t[r]==="-"&&(n.end=r+1),n.value=t.slice(n.start,n.end));else if(n.type==="comment"&&n.language==="html"&&t[e]===">"&&(!$.length||t[r]==="<"))Array.isArray($)&&$.length&&$[~-$.length].value==="["&&$.pop(),!["simplet","not"].includes(n.kind)&&ge(t,e,["<!-->","<!---->"],{trimBeforeMatching:!0,maxMismatches:1,lastMustMatch:!0})?n.kind="not":(n.end=e+1,n.value=t.slice(n.start,n.end));else if(n.type==="comment"&&n.language==="css"&&t[e]==="*"&&t[e+1]==="/")n.end=e+1,n.value=t.slice(n.start,n.end);else if(n.type==="esp"&&n.end===null&&typeof n.head=="string"&&typeof n.tail=="string"&&n.tail.includes(t[e])){let a="";for(let b=e;b<c&&v.includes(t[b]);b++)a+=t[b];if(a.length>n.head.length){let b=n.head[0];if(a.endsWith(n.head))n.end=e+a.length-n.head.length,n.value=t.slice(n.start,n.end),s=n.end;else if(a.startsWith(n.tail))n.end=e+n.tail.length,n.value=t.slice(n.start,n.end),s=n.end;else if(!n.tail.includes(b)&&a.includes(b)||a.endsWith(n.head)||a.startsWith(n.tail)){let d=a.slice(0,a.indexOf(b)),E=a.slice(a.indexOf(b));d.length&&E.length&&n.tail.split("").every(O=>d.includes(O))&&(n.end=e+d.length,n.value=t.slice(n.start,n.end),s=n.end)}else n.end=e+a.length,n.value=t.slice(n.start,n.end),s=n.end}else n.end=e+a.length,n.value=t.slice(n.start,n.end),k("esp")&&$.pop(),s=n.end}}if(!s&&n.type==="tag"&&n.tagNameStartsAt&&!n.tagNameEndsAt&&(!t[e]||!Te(t[e]))&&(n.tagNameEndsAt=e,n.tagName=t.slice(n.tagNameStartsAt,e).toLowerCase(),n.tagName&&n.tagName.toLowerCase()==="script"&&(H=!H),n.tagName==="xml"&&n.closing&&!n.kind&&(n.kind="xml"),Xe.includes(n.tagName)&&(n.void=!0),n.recognised=ee(n.tagName),s=e),!s&&n.type==="tag"&&!n.tagNameStartsAt&&n.start!=null&&(n.start<e||t[n.start]!=="<")&&(t[e]==="/"?(n.closing=!0,s=e):U(t[e])&&(n.tagNameStartsAt=e,n.closing||(n.closing=!1,s=e))),!s&&n.type==="tag"&&n.kind!=="cdata"&&l.attribNameStartsAt&&e>l.attribNameStartsAt&&l.attribNameEndsAt===null&&!Re(t[e])&&(l.attribNameEndsAt=e,l.attribName=t.slice(l.attribNameStartsAt,e),l.attribNameRecognised=ce.has(l.attribName),l.attribName.startsWith("mc:")&&(n.pureHTML=!1),t[e]&&!t[e].trim()&&t[r]==="="||(t[e]&&!t[e].trim()||t[e]===">"||t[e]==="/"&&t[r]===">")&&(`'"`.includes(t[r])||(l.attribEnds=e,n.attribs.push(y(l)),V()))),!s&&t[e]&&n.type==="tag"&&n.kind!=="cdata"&&n.tagNameEndsAt&&e>n.tagNameEndsAt&&l.attribStarts===null&&Re(t[e])&&(l.attribStarts=e,l.attribLeft=A,l.attribNameStartsAt=e),!s&&n.type==="rule"&&(t[e]==="{"&&t[e+1]!=="{"&&t[e-1]!=="{"&&!n.openingCurlyAt?n.openingCurlyAt=e:t[e]==="}"&&n.openingCurlyAt&&!n.closingCurlyAt&&(n.closingCurlyAt=e,n.end=e+1,n.value=t.slice(n.start,n.end),Array.isArray(n.properties)&&n.properties.length&&n.properties[~-n.properties.length].start&&!n.properties[~-n.properties.length].end&&(n.properties[~-n.properties.length].end=e,n.properties[~-n.properties.length].value=t.slice(n.properties[~-n.properties.length].start,e)),o.start&&(n.properties.push(o),T()),P(n),k("at")&&$[~-$.length].token.rules.push(n),L())),!s&&l.attribName&&Array.isArray(l.attribValue)&&l.attribValue.length&&!l.attribValue[~-l.attribValue.length].end&&t[e]==="*"&&t[r]==="/"&&ye(e),(!s&&l?.attribValueStartsAt&&!l.attribValueEndsAt&&!o.propertyStarts&&n.type!=="esp"&&e>=l.attribValueStartsAt&&Array.isArray(l.attribValue)&&(!l.attribValue.length||l.attribValue[~-l.attribValue.length].end&&l.attribValue[~-l.attribValue.length].end<=e)||!s&&n.type==="rule"&&n.openingCurlyAt&&!n.closingCurlyAt&&!o.propertyStarts)&&(t[e]===";"&&(l&&Array.isArray(l.attribValue)&&l.attribValue.length&&l.attribValue[~-l.attribValue.length].semi&&l.attribValue[~-l.attribValue.length].semi<e||n&&n.type==="rule"&&Array.isArray(n.properties)&&n.properties.length&&n.properties[~-n.properties.length].semi&&n.properties[~-n.properties.length].semi<e)?(B({start:e,semi:e}),s=e+1):(t[e]&&!t[e].trim()||k("block"))&&(l.attribName?l.attribValue.push({type:"text",start:e,end:null,value:null}):n.type==="rule"&&(!Array.isArray(n.properties)||!n.properties.length||n.properties[~-n.properties.length].end)&&n.properties.push({type:"text",start:e,end:null,value:null}))),!s&&n.type==="tag"&&l.attribValueStartsAt&&e>=l.attribValueStartsAt&&l.attribValueEndsAt===null)if(F.includes(t[e]))!$.some(a=>a.type==="esp")&&(!t[e]||!t.includes(">",e)||oe(t,l.attribOpeningQuoteAt||l.attribValueStartsAt,e))?(l.attribClosingQuoteAt=e,l.attribValueEndsAt=e,l.attribValueStartsAt&&(l.attribValueRaw=t.slice(l.attribValueStartsAt,e)),l.attribEnds=e+1,o.propertyStarts&&(l.attribValue.push(y(o)),T()),Array.isArray(l.attribValue)&&l.attribValue.length&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].property||(l.attribValue[~-l.attribValue.length].end=e,l.attribValue[~-l.attribValue.length].property===null?(l.attribValue[~-l.attribValue.length].property=t.slice(l.attribValue[~-l.attribValue.length].start,e),l.attribValue[~-l.attribValue.length].propertyEnds=e):l.attribValue[~-l.attribValue.length].value=t.slice(l.attribValue[~-l.attribValue.length].start,e))),t[l.attribOpeningQuoteAt]!==t[e]&&($.pop(),$.pop()),l.attribValue[~-l.attribValue.length]&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].end=e),n.attribs.push(y(l)),V()):(!Array.isArray(l.attribValue)||!l.attribValue.length||l.attribValue[~-l.attribValue.length].type!=="text")&&!o.propertyStarts&&l.attribValue.push({type:"text",start:e,end:null,value:null});else if(l.attribOpeningQuoteAt===null&&(t[e]&&!t[e].trim()||["/",">"].includes(t[e])||v.includes(t[e])&&v.includes(t[e+1])))l.attribValueEndsAt=e,l.attribValueRaw=t.slice(l.attribValueStartsAt,e),Array.isArray(l.attribValue)&&l.attribValue.length&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].end=e,l.attribValue[~-l.attribValue.length].value=t.slice(l.attribValue[~-l.attribValue.length].start,l.attribValue[~-l.attribValue.length].end)),l.attribEnds=e,n.attribs.push(y(l)),V(),$.pop(),t[e]===">"&&(n.end=e+1,n.value=t.slice(n.start,n.end));else if(t[e]==="="&&p!==null&&r&&(`'"`.includes(t[r])||t[~-e]&&U(t[~-e]))&&!(l?.attribOpeningQuoteAt&&(/\//.test(t.slice(l.attribOpeningQuoteAt+1,e))||/mailto:/.test(t.slice(l.attribOpeningQuoteAt+1,e))||/\w\?\w/.test(t.slice(l.attribOpeningQuoteAt+1,e))))){let a,b;for(let d=p;d>=l.attribValueStartsAt;d--){if(!a&&t[d]&&!t[d].trim()&&(a=!0,b)){let E=t.slice(d,b)}a&&t[d]?.trim()&&(a=!1,b||(b=d+1))}if(b){l.attribValueEndsAt=b,l.attribValueStartsAt&&(l.attribValueRaw=t.slice(l.attribValueStartsAt,b),Array.isArray(l.attribValue)&&l.attribValue.length&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].end=l.attribValueEndsAt,l.attribValue[~-l.attribValue.length].value=t.slice(l.attribValue[~-l.attribValue.length].start,l.attribValueEndsAt))),l.attribEnds=b,t[l.attribOpeningQuoteAt]!==t[e]&&$.pop(),n.attribs.push(y(l)),V(),e=~-b;continue}else if(l.attribOpeningQuoteAt&&(`'"`.includes(t[r])||ce.has(t.slice(l.attribOpeningQuoteAt+1,e).trim()))){e=l.attribOpeningQuoteAt,l.attribEnds=l.attribOpeningQuoteAt+1,l.attribValueStartsAt=null,l.attribValue.pop(),$.pop(),n.attribs.push(y(l)),V();continue}}else t[e]==="/"&&t[r]===">"?(l.attribValueStartsAt&&(l.attribValueStartsAt=null),l.attribEnds||(l.attribEnds=e)):l&&l.attribName!=="style"&&l.attribStarts&&!l.attribEnds&&!o.propertyStarts&&(!Array.isArray(l.attribValue)||!l.attribValue.length||l.attribValue[~-l.attribValue.length].end&&l.attribValue[~-l.attribValue.length].end<=e)?l.attribValue.push({type:"text",start:e,end:null,value:null}):o&&!o.importantStarts&&Array.isArray(o.value)&&t[e]&&(t[e].trim()||!w)&&(h=y(n),J("text",e));else n.type==="esp"&&g&&h&&g.attribOpeningQuoteAt&&g.attribValueStartsAt&&`'"`.includes(t[e])&&t[g.attribOpeningQuoteAt]===t[e]&&oe(t,g.attribOpeningQuoteAt,e)&&(n.end=e,n.value=t.slice(n.start,e),g&&!Array.isArray(g.attribValue)&&(g.attribValue=[]),g.attribValue.push(n),g.attribValueEndsAt=e,g.attribValueRaw=t.slice(g.attribValueStartsAt,e),g.attribClosingQuoteAt=e,g.attribEnds=e+1,n=y(h),n.attribs.push(g),g=void 0,h=void 0,V(),$.pop(),$.pop(),$.pop());if(!s&&n.type==="tag"&&!l.attribValueStartsAt&&l.attribNameEndsAt&&l.attribNameEndsAt<=e&&t[e]?.trim()){if(t[e]==="="&&!F.includes(t[r])&&!"=".includes(t[r])&&!v.includes(t[r])){let a=F.split("").map(b=>t.indexOf(b,r)).filter(b=>b>0).length?Math.min(...F.split("").map(b=>t.indexOf(b,r)).filter(b=>b>0)):void 0;r&&t.slice(r).includes("=")&&ce.has(t.slice(r,r+t.slice(r).indexOf("=")).trim().toLowerCase())?(l.attribEnds=e+1,n.attribs.push({...l}),V()):(!a||t.slice(r,a).includes("=")||!t.includes(t[a],a+1)||Array.from(t.slice(a+1,t.indexOf(t[a],a+1))).some(b=>"<>=".includes(b)))&&(l.attribValueStartsAt=r,$.push({type:"simple",value:null,position:l.attribValueStartsAt}))}else if(F.includes(t[e])){let a=r;a&&F.includes(t[a])&&t[e]!==t[a]&&t.length>a+2&&t.slice(a+1).includes(t[a])&&(!t.indexOf(t[a],a+1)||!I(t,t.indexOf(t[a],a+1))||t[e]!==t[I(t,t.indexOf(t[a],a+1))])&&!Array.from(t.slice(a+1,t.indexOf(t[a]))).some(b=>`<>=${t[e]}`.includes(b))?$.pop():l.attribOpeningQuoteAt?(oe(t,l.attribOpeningQuoteAt,e)&&(l.attribClosingQuoteAt=e),l.attribOpeningQuoteAt&&l.attribClosingQuoteAt&&(l.attribOpeningQuoteAt<~-l.attribClosingQuoteAt?l.attribValueRaw=t.slice(l.attribOpeningQuoteAt+1,l.attribClosingQuoteAt):l.attribValueRaw="",l.attribEnds=e+1,n.attribs.push(y(l)),V())):(l.attribOpeningQuoteAt=e,t[e+1]&&(t[e+1]!==t[e]||!K(e+1))&&(l.attribValueStartsAt=e+1))}}if(!s&&t[e]===">"&&t[e-1]!=="%"&&n.type==="tag"&&l.attribStarts&&!l.attribEnds){let a=!1;if(t[e+1])for(let b=e+1;b<c;b++)if(l.attribOpeningQuoteAt&&t[b]===t[l.attribOpeningQuoteAt]){b!==e+1&&t[~-b]!=="="&&(a=!0);break}else{if(t[b]===">")break;if(t[b]==="<"){a=!0,$.pop();break}else if(!t[b+1]){a=!0;break}}else a=!0;if(a){for(n.end=e+1,n.value=t.slice(n.start,n.end),l.attribValueStartsAt&&e&&l.attribValueStartsAt<e&&t.slice(l.attribValueStartsAt,e).trim()?(l.attribValueEndsAt=e,l.attribValueRaw=t.slice(l.attribValueStartsAt,e),Array.isArray(l.attribValue)&&l.attribValue.length&&!l.attribValue[~-l.attribValue.length].end&&(l.attribValue[~-l.attribValue.length].end=e,l.attribValue[~-l.attribValue.length].value=t.slice(l.attribValue[~-l.attribValue.length].start,e))):l.attribValueStartsAt=null,l.attribEnds===null&&(l.attribEnds=e);l.attribValue?.length&&l.attribValue[~-l.attribValue.length].end===null;)l.attribValue.pop();l&&(n.attribs.push(y(l)),V())}}t[e]&&i.charCb&&Pe({type:n.type,chr:t[e],i:e}),!t[e]&&n.start!==null&&(n.end=e,n.value=t.slice(n.start,n.end),n.type!=="tag"?(n.type==="esp"&&h&&(l&&Array.isArray(l.attribValue)&&l.attribValue.length&&Array.isArray(l.attribValue[~-l.attribValue.length].value)&&(l.attribValue[~-l.attribValue.length].value.push(y(n)),l.attribValueEndsAt||(l.attribValueEndsAt=n.end)),n=y(h),g=void 0,h=void 0,n.attribs.push(y(l)),V()),V()):l?.attribName&&(l.attribEnds||(l.attribEnds=e),n.attribs.push({...l}),V()),n&&Array.isArray(n.properties)&&n.properties.length&&!n.properties[~-n.properties.length].end&&(n.properties[~-n.properties.length].end=e,n.properties[~-n.properties.length].start&&!n.properties[~-n.properties.length].value&&(n.properties[~-n.properties.length].value=t.slice(n.properties[~-n.properties.length].start,e))),o?.propertyStarts&&(o.end||(o.end=e),D(o),T()),P(n)),t[e]?.trim()&&(A=e)}if(q.length)for(let e=0,p=q.length;e<p;e++)z(q,i.charCb,i.charCbLookahead);if(Q.length)for(let e=0,p=Q.length;e<p;e++)z(Q,i.tagCb,i.tagCbLookahead);return{timeTakenInMilliseconds:Date.now()-m}}var bn={matchLayerLast:le};export{nt as defaults,sn as tokenizer,bn as util,rn as version};