import{TokenTypease,isTokenasn,stringifyast,ParseErroraso,mirrorVariantass,mirrorVariantTypeasi}from"@csstools/css-tokenizer";varr;functionconsumeComponentValue(n,t){consto=t[0];if(o[0]===e.OpenParen||o[0]===e.OpenCurly||o[0]===e.OpenSquare){conste=consumeSimpleBlock(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Function){conste=consumeFunction(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Whitespace){conste=consumeWhitespace(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Comment){conste=consumeComment(n,t);return{advance:e.advance,node:e.node}}return{advance:1,node:newTokenNode(o)}}!function(e){e.Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token"}(r||(r={}));classFunctionNode{type=r.Function;name;endToken;value;constructor(e,n,t){this.name=e,this.endToken=n,this.value=t}getName(){returnthis.name[4].value}normalize(){this.endToken[0]===e.EOF&&(this.endToken=[e.CloseParen,")",-1,-1,void0])}tokens(){returnthis.endToken[0]===e.EOF?[this.name,...this.value.flatMap((e=>e.tokens()))]:[this.name,...this.value.flatMap((e=>e.tokens())),this.endToken]}toString(){conste=this.value.map((e=>n(e)?t(e):e.toString())).join("");returnt(this.name)+e+t(this.endToken)}indexOf(e){returnthis.value.indexOf(e)}at(e){if("number"==typeofe)returne<0&&(e=this.value.length+e),this.value[e]}walk(e,n){lett=!1;if(this.value.forEach(((o,s)=>{if(t)return;leti;n&&(i={...n}),!1!==e({node:o,parent:this,state:i},s)?"walk"ino&&!1===o.walk(e,i)&&(t=!0):t=!0})),t)return!1}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){returnFunctionNode.isFunctionNode(this)}staticisFunctionNode(e){return!!e&&(einstanceofFunctionNode&&e.type===r.Function)}}functionconsumeFunction(n,t){consts=[];leti=1;for(;;){constr=t[i];if(!r||r[0]===e.EOF)returnn.onParseError(newo("Unexpected EOF while consuming a function.",t[0][2],t[t.length-1][3],["5.4.9. Consume a function","Unexpected EOF"])),{advance:t.length,node:newFunctionNode(t[0],r,s)};if(r[0]===e.CloseParen)return{advance:i+1,node:newFunctionNode(t[0],r,s)};if(r[0]===e.Comment||r[0]===e.Whitespace){conste=consumeAllCommentsAndWhitespace(n,t.slice(i));i+=e.advance,s.push(...e.nodes);continue}consta=consumeComponentValue(n,t.slice(i));i+=a.advance,s.push(a.node)}}classSimpleBlockNode{type=r.SimpleBlock;startToken;endToken;value;constructor(e,n,t){this.startToken=e,this.endToken=n,this.value=t}normalize(){if(this.endToken[0]===e.EOF){conste=s(this.startToken);e&&(this.endToken=e)}}tokens(){returnthis.endToken[0]===e.EOF?[this.startToken,...this.value.flatMap((e=>e.tokens()))]:[this.startToken,...this.value.flatMap((e=>e.tokens())),this.endToken]}toString(){conste=this.value.map((e=>n(e)?t(e):e.toString())).join("");returnt(this.startToken)+e+t(this.endToken)}indexOf(e){returnthis.value.indexOf(e)}at(e){if("number"==typeofe)returne<0&&(e=this.value.length+e),this.value[e]}walk(e,n){lett=!1;if(this.value.forEach(((o,s)=>{if(t)return;leti;n&&(i={...n}),!1!==e({node:o,parent:this,state:i},s)?"walk"ino&&!1===o.walk(e,i)&&(t=!0):t=!0})),t)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){returnSimpleBlockNode.isSimpleBlockNode(this)}staticisSimpleBlockNode(e){return!!e&&(einstanceofSimpleBlockNode&&e.type===r.SimpleBlock)}}functionconsumeSimpleBlock(n,t){consts=i(t[0][0]);if(!s)thrownewError("Failed to parse, a mirror variant must exist for all block open tokens.");constr=[];leta=1;for(;;){consti=t[a];if(!i||i[0]===e.EOF)returnn.onParseError(newo("Unexpected EOF while consuming a simple block.",t[0][2],t[t.length-1][3],["5.4.8. Consume a simple block","Unexpected EOF"])),{advance:t.length,node:newSimpleBlockNode(t[0],i,r)};if(i[0]===s)return{advance:a+1,node:newSimpleBlockNode(t[0],i,r)};if(i[0]===e.Comment||i[0]===e.Whitespace){conste=consumeAllCommentsAndWhitespace(n,t.slice(a));a+=e.advance,r.push(...e.nod