diff --git a/packages/css-tokenizer/CHANGELOG.md b/packages/css-tokenizer/CHANGELOG.md index eef9fb0f5..55d2b0ab9 100644 --- a/packages/css-tokenizer/CHANGELOG.md +++ b/packages/css-tokenizer/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes to CSS Tokenizer +### Unreleased (minor) + +- Add `tokenizeGridTemplateAreas` for `grid-template-areas` strings. + ### 3.0.3 _October 25, 2024_ diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index c5feaaf78..6ab58be2c 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1 @@ -"use strict";class ParseError extends Error{sourceStart;sourceEnd;parserState;constructor(e,n,o,t){super(e),this.name="ParseError",this.sourceStart=n,this.sourceEnd=o,this.parserState=t}}class ParseErrorWithToken extends ParseError{token;constructor(e,n,o,t,r){super(e,n,o,t),this.token=r}}const e={UnexpectedNewLineInString:"Unexpected newline while consuming a string token.",UnexpectedEOFInString:"Unexpected EOF while consuming a string token.",UnexpectedEOFInComment:"Unexpected EOF while consuming a comment.",UnexpectedEOFInURL:"Unexpected EOF while consuming a url token.",UnexpectedEOFInEscapedCodePoint:"Unexpected EOF while consuming an escaped code point.",UnexpectedCharacterInURL:"Unexpected character while consuming a url token.",InvalidEscapeSequenceInURL:"Invalid escape sequence while consuming a url token.",InvalidEscapeSequenceAfterBackslash:'Invalid escape sequence after "\\"'},n="undefined"!=typeof globalThis&&"structuredClone"in globalThis;const o=13,t=45,r=10,s=43,i=65533;function checkIfFourCodePointsWouldStartCDO(e){return 60===e.source.codePointAt(e.cursor)&&33===e.source.codePointAt(e.cursor+1)&&e.source.codePointAt(e.cursor+2)===t&&e.source.codePointAt(e.cursor+3)===t}function isDigitCodePoint(e){return e>=48&&e<=57}function isUppercaseLetterCodePoint(e){return e>=65&&e<=90}function isLowercaseLetterCodePoint(e){return e>=97&&e<=122}function isHexDigitCodePoint(e){return e>=48&&e<=57||e>=97&&e<=102||e>=65&&e<=70}function isLetterCodePoint(e){return isLowercaseLetterCodePoint(e)||isUppercaseLetterCodePoint(e)}function isIdentStartCodePoint(e){return isLetterCodePoint(e)||isNonASCII_IdentCodePoint(e)||95===e}function isIdentCodePoint(e){return isIdentStartCodePoint(e)||isDigitCodePoint(e)||e===t}function isNonASCII_IdentCodePoint(e){return 183===e||8204===e||8205===e||8255===e||8256===e||8204===e||(192<=e&&e<=214||216<=e&&e<=246||248<=e&&e<=893||895<=e&&e<=8191||8304<=e&&e<=8591||11264<=e&&e<=12271||12289<=e&&e<=55295||63744<=e&&e<=64975||65008<=e&&e<=65533||(0===e||(!!isSurrogate(e)||e>=65536)))}function isNewLine(e){return e===r||e===o||12===e}function isWhitespace(e){return 32===e||e===r||9===e||e===o||12===e}function isSurrogate(e){return e>=55296&&e<=57343}function checkIfTwoCodePointsAreAValidEscape(e){return 92===e.source.codePointAt(e.cursor)&&!isNewLine(e.source.codePointAt(e.cursor+1)??-1)}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,n){return n.source.codePointAt(n.cursor)===t?n.source.codePointAt(n.cursor+1)===t||(!!isIdentStartCodePoint(n.source.codePointAt(n.cursor+1)??-1)||92===n.source.codePointAt(n.cursor+1)&&!isNewLine(n.source.codePointAt(n.cursor+2)??-1)):!!isIdentStartCodePoint(n.source.codePointAt(n.cursor)??-1)||checkIfTwoCodePointsAreAValidEscape(n)}function checkIfThreeCodePointsWouldStartANumber(e){return e.source.codePointAt(e.cursor)===s||e.source.codePointAt(e.cursor)===t?!!isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1)||46===e.source.codePointAt(e.cursor+1)&&isDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1):46===e.source.codePointAt(e.cursor)?isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1):isDigitCodePoint(e.source.codePointAt(e.cursor)??-1)}function checkIfTwoCodePointsStartAComment(e){return 47===e.source.codePointAt(e.cursor)&&42===e.source.codePointAt(e.cursor+1)}function checkIfThreeCodePointsWouldStartCDC(e){return e.source.codePointAt(e.cursor)===t&&e.source.codePointAt(e.cursor+1)===t&&62===e.source.codePointAt(e.cursor+2)}var c,a,u;function consumeComment(n,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(void 0===t){const t=[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInComment,o.representationStart,o.representationEnd,["4.3.2. Consume comments","Unexpected EOF"],t)),t}if(42===t&&(void 0!==o.source.codePointAt(o.cursor)&&47===o.source.codePointAt(o.cursor))){o.advanceCodePoint();break}}return[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(n,t){const s=t.readCodePoint();if(void 0===s)return n.onParseError(new ParseError(e.UnexpectedEOFInEscapedCodePoint,t.representationStart,t.representationEnd,["4.3.7. Consume an escaped code point","Unexpected EOF"])),i;if(isHexDigitCodePoint(s)){const e=[s];let n;for(;void 0!==(n=t.source.codePointAt(t.cursor))&&isHexDigitCodePoint(n)&&e.length<6;)e.push(n),t.advanceCodePoint();isWhitespace(t.source.codePointAt(t.cursor)??-1)&&(t.source.codePointAt(t.cursor)===o&&t.source.codePointAt(t.cursor+1)===r&&t.advanceCodePoint(),t.advanceCodePoint());const c=parseInt(String.fromCodePoint(...e),16);return 0===c||isSurrogate(c)||c>1114111?i:c}return 0===s||isSurrogate(s)?i:s}function consumeIdentSequence(e,n){const o=[];for(;;){const t=n.source.codePointAt(n.cursor)??-1;if(0===t||isSurrogate(t))o.push(i),n.advanceCodePoint(+(t>65535)+1);else if(isIdentCodePoint(t))o.push(t),n.advanceCodePoint(+(t>65535)+1);else{if(!checkIfTwoCodePointsAreAValidEscape(n))return o;n.advanceCodePoint(),o.push(consumeEscapedCodePoint(e,n))}}}function consumeHashToken(e,n){n.advanceCodePoint();const o=n.source.codePointAt(n.cursor);if(void 0!==o&&(isIdentCodePoint(o)||checkIfTwoCodePointsAreAValidEscape(n))){let o=exports.HashType.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)&&(o=exports.HashType.ID);const t=consumeIdentSequence(e,n);return[exports.TokenType.Hash,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...t),type:o}]}return[exports.TokenType.Delim,"#",n.representationStart,n.representationEnd,{value:"#"}]}function consumeNumber(e,n){let o=exports.NumberType.Integer;for(n.source.codePointAt(n.cursor)!==s&&n.source.codePointAt(n.cursor)!==t||n.advanceCodePoint();isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();if(46===n.source.codePointAt(n.cursor)&&isDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))for(n.advanceCodePoint(2),o=exports.NumberType.Number;isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();if(101===n.source.codePointAt(n.cursor)||69===n.source.codePointAt(n.cursor)){if(isDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))n.advanceCodePoint(2);else{if(n.source.codePointAt(n.cursor+1)!==t&&n.source.codePointAt(n.cursor+1)!==s||!isDigitCodePoint(n.source.codePointAt(n.cursor+2)??-1))return o;n.advanceCodePoint(3)}for(o=exports.NumberType.Number;isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint()}return o}function consumeNumericToken(e,n){let o;{const e=n.source.codePointAt(n.cursor);e===t?o="-":e===s&&(o="+")}const r=consumeNumber(0,n),i=parseFloat(n.source.slice(n.representationStart,n.representationEnd+1));if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const t=consumeIdentSequence(e,n);return[exports.TokenType.Dimension,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:i,signCharacter:o,type:r,unit:String.fromCodePoint(...t)}]}return 37===n.source.codePointAt(n.cursor)?(n.advanceCodePoint(),[exports.TokenType.Percentage,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:i,signCharacter:o}]):[exports.TokenType.Number,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:i,signCharacter:o,type:r}]}function consumeWhiteSpace(e){for(;isWhitespace(e.source.codePointAt(e.cursor)??-1);)e.advanceCodePoint();return[exports.TokenType.Whitespace,e.source.slice(e.representationStart,e.representationEnd+1),e.representationStart,e.representationEnd,void 0]}exports.TokenType=void 0,(c=exports.TokenType||(exports.TokenType={})).Comment="comment",c.AtKeyword="at-keyword-token",c.BadString="bad-string-token",c.BadURL="bad-url-token",c.CDC="CDC-token",c.CDO="CDO-token",c.Colon="colon-token",c.Comma="comma-token",c.Delim="delim-token",c.Dimension="dimension-token",c.EOF="EOF-token",c.Function="function-token",c.Hash="hash-token",c.Ident="ident-token",c.Number="number-token",c.Percentage="percentage-token",c.Semicolon="semicolon-token",c.String="string-token",c.URL="url-token",c.Whitespace="whitespace-token",c.OpenParen="(-token",c.CloseParen=")-token",c.OpenSquare="[-token",c.CloseSquare="]-token",c.OpenCurly="{-token",c.CloseCurly="}-token",c.UnicodeRange="unicode-range-token",exports.NumberType=void 0,(a=exports.NumberType||(exports.NumberType={})).Integer="integer",a.Number="number",exports.HashType=void 0,(u=exports.HashType||(exports.HashType={})).Unrestricted="unrestricted",u.ID="id";class Reader{cursor=0;source="";representationStart=0;representationEnd=-1;constructor(e){this.source=e}advanceCodePoint(e=1){this.cursor=this.cursor+e,this.representationEnd=this.cursor-1}readCodePoint(){const e=this.source.codePointAt(this.cursor);if(void 0!==e)return this.cursor=this.cursor+1,this.representationEnd=this.cursor-1,e}unreadCodePoint(e=1){this.cursor=this.cursor-e,this.representationEnd=this.cursor-1}resetRepresentation(){this.representationStart=this.cursor,this.representationEnd=-1}}function consumeStringToken(n,t){let s="";const c=t.readCodePoint();for(;;){const a=t.readCodePoint();if(void 0===a){const o=[exports.TokenType.String,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:s}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInString,t.representationStart,t.representationEnd,["4.3.5. Consume a string token","Unexpected EOF"],o)),o}if(isNewLine(a)){t.unreadCodePoint();const s=[exports.TokenType.BadString,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedNewLineInString,t.representationStart,t.source.codePointAt(t.cursor)===o&&t.source.codePointAt(t.cursor+1)===r?t.representationEnd+2:t.representationEnd+1,["4.3.5. Consume a string token","Unexpected newline"],s)),s}if(a===c)return[exports.TokenType.String,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:s}];if(92!==a)0===a||isSurrogate(a)?s+=String.fromCodePoint(i):s+=String.fromCodePoint(a);else{if(void 0===t.source.codePointAt(t.cursor))continue;if(isNewLine(t.source.codePointAt(t.cursor)??-1)){t.source.codePointAt(t.cursor)===o&&t.source.codePointAt(t.cursor+1)===r&&t.advanceCodePoint(),t.advanceCodePoint();continue}s+=String.fromCodePoint(consumeEscapedCodePoint(n,t))}}}function checkIfCodePointsMatchURLIdent(e){return!(3!==e.length||117!==e[0]&&85!==e[0]||114!==e[1]&&82!==e[1]||108!==e[2]&&76!==e[2])}function consumeBadURL(e,n){for(;;){const o=n.source.codePointAt(n.cursor);if(void 0===o)return;if(41===o)return void n.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(n)?(n.advanceCodePoint(),consumeEscapedCodePoint(e,n)):n.advanceCodePoint()}}function consumeUrlToken(n,o){for(;isWhitespace(o.source.codePointAt(o.cursor)??-1);)o.advanceCodePoint();let t="";for(;;){if(void 0===o.source.codePointAt(o.cursor)){const r=[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,o.representationStart,o.representationEnd,["4.3.6. Consume a url token","Unexpected EOF"],r)),r}if(41===o.source.codePointAt(o.cursor))return o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isWhitespace(o.source.codePointAt(o.cursor)??-1)){for(o.advanceCodePoint();isWhitespace(o.source.codePointAt(o.cursor)??-1);)o.advanceCodePoint();if(void 0===o.source.codePointAt(o.cursor)){const r=[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,o.representationStart,o.representationEnd,["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"],r)),r}return 41===o.source.codePointAt(o.cursor)?(o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):(consumeBadURL(n,o),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0])}const s=o.source.codePointAt(o.cursor);if(34===s||39===s||40===s||(11===(r=s??-1)||127===r||0<=r&&r<=8||14<=r&&r<=31)){consumeBadURL(n,o);const t=[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedCharacterInURL,o.representationStart,o.representationEnd,["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"],t)),t}if(92===s){if(checkIfTwoCodePointsAreAValidEscape(o)){o.advanceCodePoint(),t+=String.fromCodePoint(consumeEscapedCodePoint(n,o));continue}consumeBadURL(n,o);const r=[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceInURL,o.representationStart,o.representationEnd,["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],r)),r}0===o.source.codePointAt(o.cursor)||isSurrogate(o.source.codePointAt(o.cursor)??-1)?(t+=String.fromCodePoint(i),o.advanceCodePoint()):(t+=o.source[o.cursor],o.advanceCodePoint())}var r}function consumeIdentLikeToken(e,n){const o=consumeIdentSequence(e,n);if(40!==n.source.codePointAt(n.cursor))return[exports.TokenType.Ident,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...o)}];if(checkIfCodePointsMatchURLIdent(o)){n.advanceCodePoint();let t=0;for(;;){const e=isWhitespace(n.source.codePointAt(n.cursor)??-1),r=isWhitespace(n.source.codePointAt(n.cursor+1)??-1);if(e&&r){t+=1,n.advanceCodePoint(1);continue}const s=e?n.source.codePointAt(n.cursor+1):n.source.codePointAt(n.cursor);if(34===s||39===s)return t>0&&n.unreadCodePoint(t),[exports.TokenType.Function,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...o)}];break}return consumeUrlToken(e,n)}return n.advanceCodePoint(),[exports.TokenType.Function,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...o)}]}function checkIfThreeCodePointsWouldStartAUnicodeRange(e){return!(117!==e.source.codePointAt(e.cursor)&&85!==e.source.codePointAt(e.cursor)||e.source.codePointAt(e.cursor+1)!==s||63!==e.source.codePointAt(e.cursor+2)&&!isHexDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1))}function consumeUnicodeRangeToken(e,n){n.advanceCodePoint(2);const o=[],r=[];let s;for(;void 0!==(s=n.source.codePointAt(n.cursor))&&o.length<6&&isHexDigitCodePoint(s);)o.push(s),n.advanceCodePoint();for(;void 0!==(s=n.source.codePointAt(n.cursor))&&o.length<6&&63===s;)0===r.length&&r.push(...o),o.push(48),r.push(70),n.advanceCodePoint();if(!r.length&&n.source.codePointAt(n.cursor)===t&&isHexDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))for(n.advanceCodePoint();void 0!==(s=n.source.codePointAt(n.cursor))&&r.length<6&&isHexDigitCodePoint(s);)r.push(s),n.advanceCodePoint();if(!r.length){const e=parseInt(String.fromCodePoint(...o),16);return[exports.TokenType.UnicodeRange,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{startOfRange:e,endOfRange:e}]}const i=parseInt(String.fromCodePoint(...o),16),c=parseInt(String.fromCodePoint(...r),16);return[exports.TokenType.UnicodeRange,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{startOfRange:i,endOfRange:c}]}function tokenizer(n,i){const c=n.css.valueOf(),a=n.unicodeRangesAllowed??!1,u=new Reader(c),d={onParseError:i?.onParseError??noop};return{nextToken:function nextToken(){u.resetRepresentation();const n=u.source.codePointAt(u.cursor);if(void 0===n)return[exports.TokenType.EOF,"",-1,-1,void 0];if(47===n&&checkIfTwoCodePointsStartAComment(u))return consumeComment(d,u);if(a&&(117===n||85===n)&&checkIfThreeCodePointsWouldStartAUnicodeRange(u))return consumeUnicodeRangeToken(0,u);if(isIdentStartCodePoint(n))return consumeIdentLikeToken(d,u);if(isDigitCodePoint(n))return consumeNumericToken(d,u);switch(n){case 44:return u.advanceCodePoint(),[exports.TokenType.Comma,",",u.representationStart,u.representationEnd,void 0];case 58:return u.advanceCodePoint(),[exports.TokenType.Colon,":",u.representationStart,u.representationEnd,void 0];case 59:return u.advanceCodePoint(),[exports.TokenType.Semicolon,";",u.representationStart,u.representationEnd,void 0];case 40:return u.advanceCodePoint(),[exports.TokenType.OpenParen,"(",u.representationStart,u.representationEnd,void 0];case 41:return u.advanceCodePoint(),[exports.TokenType.CloseParen,")",u.representationStart,u.representationEnd,void 0];case 91:return u.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",u.representationStart,u.representationEnd,void 0];case 93:return u.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",u.representationStart,u.representationEnd,void 0];case 123:return u.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",u.representationStart,u.representationEnd,void 0];case 125:return u.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",u.representationStart,u.representationEnd,void 0];case 39:case 34:return consumeStringToken(d,u);case 35:return consumeHashToken(d,u);case s:case 46:return checkIfThreeCodePointsWouldStartANumber(u)?consumeNumericToken(d,u):(u.advanceCodePoint(),[exports.TokenType.Delim,u.source[u.representationStart],u.representationStart,u.representationEnd,{value:u.source[u.representationStart]}]);case r:case o:case 12:case 9:case 32:return consumeWhiteSpace(u);case t:return checkIfThreeCodePointsWouldStartANumber(u)?consumeNumericToken(d,u):checkIfThreeCodePointsWouldStartCDC(u)?(u.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",u.representationStart,u.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,u)?consumeIdentLikeToken(d,u):(u.advanceCodePoint(),[exports.TokenType.Delim,"-",u.representationStart,u.representationEnd,{value:"-"}]);case 60:return checkIfFourCodePointsWouldStartCDO(u)?(u.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",u.representationStart,u.representationEnd,void 0]):(u.advanceCodePoint(),[exports.TokenType.Delim,"<",u.representationStart,u.representationEnd,{value:"<"}]);case 64:if(u.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,u)){const e=consumeIdentSequence(d,u);return[exports.TokenType.AtKeyword,u.source.slice(u.representationStart,u.representationEnd+1),u.representationStart,u.representationEnd,{value:String.fromCodePoint(...e)}]}return[exports.TokenType.Delim,"@",u.representationStart,u.representationEnd,{value:"@"}];case 92:{if(checkIfTwoCodePointsAreAValidEscape(u))return consumeIdentLikeToken(d,u);u.advanceCodePoint();const n=[exports.TokenType.Delim,"\\",u.representationStart,u.representationEnd,{value:"\\"}];return d.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceAfterBackslash,u.representationStart,u.representationEnd,["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],n)),n}}return u.advanceCodePoint(),[exports.TokenType.Delim,u.source[u.representationStart],u.representationStart,u.representationEnd,{value:u.source[u.representationStart]}]},endOfFile:function endOfFile(){return void 0===u.source.codePointAt(u.cursor)}}}function noop(){}function ensureThatValueRoundTripsAsIdent(e){let n=0;e[0]===t&&e[1]===t?n=2:e[0]===t&&e[1]?(n=2,isIdentStartCodePoint(e[1])||(n+=insertEscapedCodePoint(e,1,e[1]))):isIdentStartCodePoint(e[0])?n=1:(n=1,n+=insertEscapedCodePoint(e,0,e[0]));for(let o=n;o=48&&e<=57}function isUppercaseLetterCodePoint(e){return e>=65&&e<=90}function isLowercaseLetterCodePoint(e){return e>=97&&e<=122}function isHexDigitCodePoint(e){return e>=48&&e<=57||e>=97&&e<=102||e>=65&&e<=70}function isLetterCodePoint(e){return isLowercaseLetterCodePoint(e)||isUppercaseLetterCodePoint(e)}function isIdentStartCodePoint(e){return isLetterCodePoint(e)||isNonASCII_IdentCodePoint(e)||95===e}function isIdentCodePoint(e){return isIdentStartCodePoint(e)||isDigitCodePoint(e)||e===r}function isNonASCII_IdentCodePoint(e){return 183===e||8204===e||8205===e||8255===e||8256===e||8204===e||(192<=e&&e<=214||216<=e&&e<=246||248<=e&&e<=893||895<=e&&e<=8191||8304<=e&&e<=8591||11264<=e&&e<=12271||12289<=e&&e<=55295||63744<=e&&e<=64975||65008<=e&&e<=65533||(0===e||(!!isSurrogate(e)||e>=65536)))}function isNewLine(e){return e===s||e===n||12===e}function isWhitespace(e){return 32===e||e===s||9===e||e===n||12===e}function isSurrogate(e){return e>=55296&&e<=57343}function checkIfTwoCodePointsAreAValidEscape(e){return 92===e.source.codePointAt(e.cursor)&&!isNewLine(e.source.codePointAt(e.cursor+1)??-1)}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.source.codePointAt(o.cursor)===r?o.source.codePointAt(o.cursor+1)===r||(!!isIdentStartCodePoint(o.source.codePointAt(o.cursor+1)??-1)||92===o.source.codePointAt(o.cursor+1)&&!isNewLine(o.source.codePointAt(o.cursor+2)??-1)):!!isIdentStartCodePoint(o.source.codePointAt(o.cursor)??-1)||checkIfTwoCodePointsAreAValidEscape(o)}function checkIfThreeCodePointsWouldStartANumber(e){return e.source.codePointAt(e.cursor)===i||e.source.codePointAt(e.cursor)===r?!!isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1)||e.source.codePointAt(e.cursor+1)===t&&isDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1):e.source.codePointAt(e.cursor)===t?isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1):isDigitCodePoint(e.source.codePointAt(e.cursor)??-1)}function checkIfTwoCodePointsStartAComment(e){return 47===e.source.codePointAt(e.cursor)&&42===e.source.codePointAt(e.cursor+1)}function checkIfThreeCodePointsWouldStartCDC(e){return e.source.codePointAt(e.cursor)===r&&e.source.codePointAt(e.cursor+1)===r&&62===e.source.codePointAt(e.cursor+2)}var a,u,d;function consumeComment(o,n){for(n.advanceCodePoint(2);;){const t=n.readCodePoint();if(void 0===t){const t=[exports.TokenType.Comment,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,void 0];return o.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInComment,n.representationStart,n.representationEnd,["4.3.2. Consume comments","Unexpected EOF"],t)),t}if(42===t&&(void 0!==n.source.codePointAt(n.cursor)&&47===n.source.codePointAt(n.cursor))){n.advanceCodePoint();break}}return[exports.TokenType.Comment,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,void 0]}function consumeEscapedCodePoint(o,t){const r=t.readCodePoint();if(void 0===r)return o.onParseError(new ParseError(e.UnexpectedEOFInEscapedCodePoint,t.representationStart,t.representationEnd,["4.3.7. Consume an escaped code point","Unexpected EOF"])),c;if(isHexDigitCodePoint(r)){const e=[r];let o;for(;void 0!==(o=t.source.codePointAt(t.cursor))&&isHexDigitCodePoint(o)&&e.length<6;)e.push(o),t.advanceCodePoint();isWhitespace(t.source.codePointAt(t.cursor)??-1)&&(t.source.codePointAt(t.cursor)===n&&t.source.codePointAt(t.cursor+1)===s&&t.advanceCodePoint(),t.advanceCodePoint());const i=parseInt(String.fromCodePoint(...e),16);return 0===i||isSurrogate(i)||i>1114111?c:i}return 0===r||isSurrogate(r)?c:r}function consumeIdentSequence(e,o){const n=[];for(;;){const t=o.source.codePointAt(o.cursor)??-1;if(0===t||isSurrogate(t))n.push(c),o.advanceCodePoint(+(t>65535)+1);else if(isIdentCodePoint(t))n.push(t),o.advanceCodePoint(+(t>65535)+1);else{if(!checkIfTwoCodePointsAreAValidEscape(o))return n;o.advanceCodePoint(),n.push(consumeEscapedCodePoint(e,o))}}}function consumeHashToken(e,o){o.advanceCodePoint();const n=o.source.codePointAt(o.cursor);if(void 0!==n&&(isIdentCodePoint(n)||checkIfTwoCodePointsAreAValidEscape(o))){let n=exports.HashType.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(n=exports.HashType.ID);const t=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCodePoint(...t),type:n}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let n=exports.NumberType.Integer;for(o.source.codePointAt(o.cursor)!==i&&o.source.codePointAt(o.cursor)!==r||o.advanceCodePoint();isDigitCodePoint(o.source.codePointAt(o.cursor)??-1);)o.advanceCodePoint();if(o.source.codePointAt(o.cursor)===t&&isDigitCodePoint(o.source.codePointAt(o.cursor+1)??-1))for(o.advanceCodePoint(2),n=exports.NumberType.Number;isDigitCodePoint(o.source.codePointAt(o.cursor)??-1);)o.advanceCodePoint();if(101===o.source.codePointAt(o.cursor)||69===o.source.codePointAt(o.cursor)){if(isDigitCodePoint(o.source.codePointAt(o.cursor+1)??-1))o.advanceCodePoint(2);else{if(o.source.codePointAt(o.cursor+1)!==r&&o.source.codePointAt(o.cursor+1)!==i||!isDigitCodePoint(o.source.codePointAt(o.cursor+2)??-1))return n;o.advanceCodePoint(3)}for(n=exports.NumberType.Number;isDigitCodePoint(o.source.codePointAt(o.cursor)??-1);)o.advanceCodePoint()}return n}function consumeNumericToken(e,o){let n;{const e=o.source.codePointAt(o.cursor);e===r?n="-":e===i&&(n="+")}const t=consumeNumber(0,o),s=parseFloat(o.source.slice(o.representationStart,o.representationEnd+1));if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const r=consumeIdentSequence(e,o);return[exports.TokenType.Dimension,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:s,signCharacter:n,type:t,unit:String.fromCodePoint(...r)}]}return 37===o.source.codePointAt(o.cursor)?(o.advanceCodePoint(),[exports.TokenType.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:s,signCharacter:n}]):[exports.TokenType.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:s,signCharacter:n,type:t}]}function consumeWhiteSpace$1(e){for(;isWhitespace(e.source.codePointAt(e.cursor)??-1);)e.advanceCodePoint();return[exports.TokenType.Whitespace,e.source.slice(e.representationStart,e.representationEnd+1),e.representationStart,e.representationEnd,void 0]}exports.TokenType=void 0,(a=exports.TokenType||(exports.TokenType={})).Comment="comment",a.AtKeyword="at-keyword-token",a.BadString="bad-string-token",a.BadURL="bad-url-token",a.CDC="CDC-token",a.CDO="CDO-token",a.Colon="colon-token",a.Comma="comma-token",a.Delim="delim-token",a.Dimension="dimension-token",a.EOF="EOF-token",a.Function="function-token",a.Hash="hash-token",a.Ident="ident-token",a.Number="number-token",a.Percentage="percentage-token",a.Semicolon="semicolon-token",a.String="string-token",a.URL="url-token",a.Whitespace="whitespace-token",a.OpenParen="(-token",a.CloseParen=")-token",a.OpenSquare="[-token",a.CloseSquare="]-token",a.OpenCurly="{-token",a.CloseCurly="}-token",a.UnicodeRange="unicode-range-token",exports.NumberType=void 0,(u=exports.NumberType||(exports.NumberType={})).Integer="integer",u.Number="number",exports.HashType=void 0,(d=exports.HashType||(exports.HashType={})).Unrestricted="unrestricted",d.ID="id";class Reader{cursor=0;source="";representationStart=0;representationEnd=-1;constructor(e){this.source=e}advanceCodePoint(e=1){this.cursor=this.cursor+e,this.representationEnd=this.cursor-1}readCodePoint(){const e=this.source.codePointAt(this.cursor);if(void 0!==e)return this.cursor=this.cursor+1,this.representationEnd=this.cursor-1,e}unreadCodePoint(e=1){this.cursor=this.cursor-e,this.representationEnd=this.cursor-1}resetRepresentation(){this.representationStart=this.cursor,this.representationEnd=-1}}function consumeStringToken(o,t){let r="";const i=t.readCodePoint();for(;;){const a=t.readCodePoint();if(void 0===a){const n=[exports.TokenType.String,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:r}];return o.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInString,t.representationStart,t.representationEnd,["4.3.5. Consume a string token","Unexpected EOF"],n)),n}if(isNewLine(a)){t.unreadCodePoint();const r=[exports.TokenType.BadString,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return o.onParseError(new ParseErrorWithToken(e.UnexpectedNewLineInString,t.representationStart,t.source.codePointAt(t.cursor)===n&&t.source.codePointAt(t.cursor+1)===s?t.representationEnd+2:t.representationEnd+1,["4.3.5. Consume a string token","Unexpected newline"],r)),r}if(a===i)return[exports.TokenType.String,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:r}];if(92!==a)0===a||isSurrogate(a)?r+=String.fromCodePoint(c):r+=String.fromCodePoint(a);else{if(void 0===t.source.codePointAt(t.cursor))continue;if(isNewLine(t.source.codePointAt(t.cursor)??-1)){t.source.codePointAt(t.cursor)===n&&t.source.codePointAt(t.cursor+1)===s&&t.advanceCodePoint(),t.advanceCodePoint();continue}r+=String.fromCodePoint(consumeEscapedCodePoint(o,t))}}}function checkIfCodePointsMatchURLIdent(e){return!(3!==e.length||117!==e[0]&&85!==e[0]||114!==e[1]&&82!==e[1]||108!==e[2]&&76!==e[2])}function consumeBadURL(e,o){for(;;){const n=o.source.codePointAt(o.cursor);if(void 0===n)return;if(41===n)return void o.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(o)?(o.advanceCodePoint(),consumeEscapedCodePoint(e,o)):o.advanceCodePoint()}}function consumeUrlToken(o,n){for(;isWhitespace(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();let t="";for(;;){if(void 0===n.source.codePointAt(n.cursor)){const r=[exports.TokenType.URL,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:t}];return o.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,n.representationStart,n.representationEnd,["4.3.6. Consume a url token","Unexpected EOF"],r)),r}if(41===n.source.codePointAt(n.cursor))return n.advanceCodePoint(),[exports.TokenType.URL,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:t}];if(isWhitespace(n.source.codePointAt(n.cursor)??-1)){for(n.advanceCodePoint();isWhitespace(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();if(void 0===n.source.codePointAt(n.cursor)){const r=[exports.TokenType.URL,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:t}];return o.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,n.representationStart,n.representationEnd,["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"],r)),r}return 41===n.source.codePointAt(n.cursor)?(n.advanceCodePoint(),[exports.TokenType.URL,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:t}]):(consumeBadURL(o,n),[exports.TokenType.BadURL,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,void 0])}const s=n.source.codePointAt(n.cursor);if(34===s||39===s||40===s||(11===(r=s??-1)||127===r||0<=r&&r<=8||14<=r&&r<=31)){consumeBadURL(o,n);const t=[exports.TokenType.BadURL,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,void 0];return o.onParseError(new ParseErrorWithToken(e.UnexpectedCharacterInURL,n.representationStart,n.representationEnd,["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"],t)),t}if(92===s){if(checkIfTwoCodePointsAreAValidEscape(n)){n.advanceCodePoint(),t+=String.fromCodePoint(consumeEscapedCodePoint(o,n));continue}consumeBadURL(o,n);const r=[exports.TokenType.BadURL,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,void 0];return o.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceInURL,n.representationStart,n.representationEnd,["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],r)),r}0===n.source.codePointAt(n.cursor)||isSurrogate(n.source.codePointAt(n.cursor)??-1)?(t+=String.fromCodePoint(c),n.advanceCodePoint()):(t+=n.source[n.cursor],n.advanceCodePoint())}var r}function consumeIdentLikeToken(e,o){const n=consumeIdentSequence(e,o);if(40!==o.source.codePointAt(o.cursor))return[exports.TokenType.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCodePoint(...n)}];if(checkIfCodePointsMatchURLIdent(n)){o.advanceCodePoint();let t=0;for(;;){const e=isWhitespace(o.source.codePointAt(o.cursor)??-1),r=isWhitespace(o.source.codePointAt(o.cursor+1)??-1);if(e&&r){t+=1,o.advanceCodePoint(1);continue}const s=e?o.source.codePointAt(o.cursor+1):o.source.codePointAt(o.cursor);if(34===s||39===s)return t>0&&o.unreadCodePoint(t),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCodePoint(...n)}];break}return consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCodePoint(...n)}]}function checkIfThreeCodePointsWouldStartAUnicodeRange(e){return!(117!==e.source.codePointAt(e.cursor)&&85!==e.source.codePointAt(e.cursor)||e.source.codePointAt(e.cursor+1)!==i||63!==e.source.codePointAt(e.cursor+2)&&!isHexDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1))}function consumeUnicodeRangeToken(e,o){o.advanceCodePoint(2);const n=[],t=[];let s;for(;void 0!==(s=o.source.codePointAt(o.cursor))&&n.length<6&&isHexDigitCodePoint(s);)n.push(s),o.advanceCodePoint();for(;void 0!==(s=o.source.codePointAt(o.cursor))&&n.length<6&&63===s;)0===t.length&&t.push(...n),n.push(48),t.push(70),o.advanceCodePoint();if(!t.length&&o.source.codePointAt(o.cursor)===r&&isHexDigitCodePoint(o.source.codePointAt(o.cursor+1)??-1))for(o.advanceCodePoint();void 0!==(s=o.source.codePointAt(o.cursor))&&t.length<6&&isHexDigitCodePoint(s);)t.push(s),o.advanceCodePoint();if(!t.length){const e=parseInt(String.fromCodePoint(...n),16);return[exports.TokenType.UnicodeRange,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{startOfRange:e,endOfRange:e}]}const i=parseInt(String.fromCodePoint(...n),16),c=parseInt(String.fromCodePoint(...t),16);return[exports.TokenType.UnicodeRange,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{startOfRange:i,endOfRange:c}]}function tokenizer(o,c){const a=o.css.valueOf(),u=o.unicodeRangesAllowed??!1,d=new Reader(a),p={onParseError:c?.onParseError??noop};return{nextToken:function nextToken(){d.resetRepresentation();const o=d.source.codePointAt(d.cursor);if(void 0===o)return[exports.TokenType.EOF,"",-1,-1,void 0];if(47===o&&checkIfTwoCodePointsStartAComment(d))return consumeComment(p,d);if(u&&(117===o||85===o)&&checkIfThreeCodePointsWouldStartAUnicodeRange(d))return consumeUnicodeRangeToken(0,d);if(isIdentStartCodePoint(o))return consumeIdentLikeToken(p,d);if(isDigitCodePoint(o))return consumeNumericToken(p,d);switch(o){case 44:return d.advanceCodePoint(),[exports.TokenType.Comma,",",d.representationStart,d.representationEnd,void 0];case 58:return d.advanceCodePoint(),[exports.TokenType.Colon,":",d.representationStart,d.representationEnd,void 0];case 59:return d.advanceCodePoint(),[exports.TokenType.Semicolon,";",d.representationStart,d.representationEnd,void 0];case 40:return d.advanceCodePoint(),[exports.TokenType.OpenParen,"(",d.representationStart,d.representationEnd,void 0];case 41:return d.advanceCodePoint(),[exports.TokenType.CloseParen,")",d.representationStart,d.representationEnd,void 0];case 91:return d.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",d.representationStart,d.representationEnd,void 0];case 93:return d.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",d.representationStart,d.representationEnd,void 0];case 123:return d.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",d.representationStart,d.representationEnd,void 0];case 125:return d.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",d.representationStart,d.representationEnd,void 0];case 39:case 34:return consumeStringToken(p,d);case 35:return consumeHashToken(p,d);case i:case t:return checkIfThreeCodePointsWouldStartANumber(d)?consumeNumericToken(p,d):(d.advanceCodePoint(),[exports.TokenType.Delim,d.source[d.representationStart],d.representationStart,d.representationEnd,{value:d.source[d.representationStart]}]);case s:case n:case 12:case 9:case 32:return consumeWhiteSpace$1(d);case r:return checkIfThreeCodePointsWouldStartANumber(d)?consumeNumericToken(p,d):checkIfThreeCodePointsWouldStartCDC(d)?(d.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",d.representationStart,d.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,d)?consumeIdentLikeToken(p,d):(d.advanceCodePoint(),[exports.TokenType.Delim,"-",d.representationStart,d.representationEnd,{value:"-"}]);case 60:return checkIfFourCodePointsWouldStartCDO(d)?(d.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",d.representationStart,d.representationEnd,void 0]):(d.advanceCodePoint(),[exports.TokenType.Delim,"<",d.representationStart,d.representationEnd,{value:"<"}]);case 64:if(d.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,d)){const e=consumeIdentSequence(p,d);return[exports.TokenType.AtKeyword,d.source.slice(d.representationStart,d.representationEnd+1),d.representationStart,d.representationEnd,{value:String.fromCodePoint(...e)}]}return[exports.TokenType.Delim,"@",d.representationStart,d.representationEnd,{value:"@"}];case 92:{if(checkIfTwoCodePointsAreAValidEscape(d))return consumeIdentLikeToken(p,d);d.advanceCodePoint();const o=[exports.TokenType.Delim,"\\",d.representationStart,d.representationEnd,{value:"\\"}];return p.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceAfterBackslash,d.representationStart,d.representationEnd,["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],o)),o}}return d.advanceCodePoint(),[exports.TokenType.Delim,d.source[d.representationStart],d.representationStart,d.representationEnd,{value:d.source[d.representationStart]}]},endOfFile:function endOfFile(){return void 0===d.source.codePointAt(d.cursor)}}}function noop(){}function ensureThatValueRoundTripsAsIdent(e){let o=0;e[0]===r&&e[1]===r?o=2:e[0]===r&&e[1]?(o=2,isIdentStartCodePoint(e[1])||(o+=insertEscapedCodePoint(e,1,e[1]))):isIdentStartCodePoint(e[0])?o=1:(o=1,o+=insertEscapedCodePoint(e,0,e[0]));for(let n=o;n65535)+1);else{if(!isIdentCodePoint(n))break;o.push(n),e.advanceCodePoint(+(n>65535)+1)}}return{type:exports.TokenTypeGridTemplateAreas.NamedCell,value:String.fromCodePoint(...o)}}function consumeNullCell(e){for(;e.source.codePointAt(e.cursor)===t;)e.advanceCodePoint();return{type:exports.TokenTypeGridTemplateAreas.NullCell,value:e.source.slice(e.representationStart,e.representationEnd+1)}}function consumeWhiteSpace(e){for(;isWhitespace(e.source.codePointAt(e.cursor)??-1);)e.advanceCodePoint()}function consumeTrash(e){e.advanceCodePoint();e:for(;;){const o=e.source.codePointAt(e.cursor);if(void 0===o)break e;switch(o){case s:case n:case 12:case 9:case 32:case t:case 0:break e;default:if(isSurrogate(o)||isIdentCodePoint(o))break e;e.advanceCodePoint();continue e}}return{type:exports.TokenTypeGridTemplateAreas.Trash,value:e.source.slice(e.representationStart,e.representationEnd+1)}}exports.TokenTypeGridTemplateAreas=void 0,(T=exports.TokenTypeGridTemplateAreas||(exports.TokenTypeGridTemplateAreas={})).NamedCell="named-cell-token",T.NullCell="null-cell-token",T.Trash="trash-token",exports.ParseError=ParseError,exports.ParseErrorMessage=e,exports.ParseErrorWithToken=ParseErrorWithToken,exports.cloneTokens=function cloneTokens(e){return o?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(!!p.includes(e[0])&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},exports.isTokenAtKeyword=function isTokenAtKeyword(e){return!!e&&e[0]===exports.TokenType.AtKeyword},exports.isTokenBadString=function isTokenBadString(e){return!!e&&e[0]===exports.TokenType.BadString},exports.isTokenBadURL=function isTokenBadURL(e){return!!e&&e[0]===exports.TokenType.BadURL},exports.isTokenCDC=function isTokenCDC(e){return!!e&&e[0]===exports.TokenType.CDC},exports.isTokenCDO=function isTokenCDO(e){return!!e&&e[0]===exports.TokenType.CDO},exports.isTokenCloseCurly=function isTokenCloseCurly(e){return!!e&&e[0]===exports.TokenType.CloseCurly},exports.isTokenCloseParen=function isTokenCloseParen(e){return!!e&&e[0]===exports.TokenType.CloseParen},exports.isTokenCloseSquare=function isTokenCloseSquare(e){return!!e&&e[0]===exports.TokenType.CloseSquare},exports.isTokenColon=function isTokenColon(e){return!!e&&e[0]===exports.TokenType.Colon},exports.isTokenComma=function isTokenComma(e){return!!e&&e[0]===exports.TokenType.Comma},exports.isTokenComment=function isTokenComment(e){return!!e&&e[0]===exports.TokenType.Comment},exports.isTokenDelim=function isTokenDelim(e){return!!e&&e[0]===exports.TokenType.Delim},exports.isTokenDimension=function isTokenDimension(e){return!!e&&e[0]===exports.TokenType.Dimension},exports.isTokenEOF=function isTokenEOF(e){return!!e&&e[0]===exports.TokenType.EOF},exports.isTokenFunction=function isTokenFunction(e){return!!e&&e[0]===exports.TokenType.Function},exports.isTokenHash=function isTokenHash(e){return!!e&&e[0]===exports.TokenType.Hash},exports.isTokenIdent=function isTokenIdent(e){return!!e&&e[0]===exports.TokenType.Ident},exports.isTokenNumber=function isTokenNumber(e){return!!e&&e[0]===exports.TokenType.Number},exports.isTokenNumeric=function isTokenNumeric(e){if(!e)return!1;switch(e[0]){case exports.TokenType.Dimension:case exports.TokenType.Number:case exports.TokenType.Percentage:return!0;default:return!1}},exports.isTokenOpenCurly=function isTokenOpenCurly(e){return!!e&&e[0]===exports.TokenType.OpenCurly},exports.isTokenOpenParen=function isTokenOpenParen(e){return!!e&&e[0]===exports.TokenType.OpenParen},exports.isTokenOpenSquare=function isTokenOpenSquare(e){return!!e&&e[0]===exports.TokenType.OpenSquare},exports.isTokenPercentage=function isTokenPercentage(e){return!!e&&e[0]===exports.TokenType.Percentage},exports.isTokenSemicolon=function isTokenSemicolon(e){return!!e&&e[0]===exports.TokenType.Semicolon},exports.isTokenString=function isTokenString(e){return!!e&&e[0]===exports.TokenType.String},exports.isTokenURL=function isTokenURL(e){return!!e&&e[0]===exports.TokenType.URL},exports.isTokenUnicodeRange=function isTokenUnicodeRange(e){return!!e&&e[0]===exports.TokenType.UnicodeRange},exports.isTokenWhiteSpaceOrComment=function isTokenWhiteSpaceOrComment(e){if(!e)return!1;switch(e[0]){case exports.TokenType.Whitespace:case exports.TokenType.Comment:return!0;default:return!1}},exports.isTokenWhitespace=function isTokenWhitespace(e){return!!e&&e[0]===exports.TokenType.Whitespace},exports.mirrorVariant=function mirrorVariant(e){switch(e[0]){case exports.TokenType.OpenParen:return[exports.TokenType.CloseParen,")",-1,-1,void 0];case exports.TokenType.CloseParen:return[exports.TokenType.OpenParen,"(",-1,-1,void 0];case exports.TokenType.OpenCurly:return[exports.TokenType.CloseCurly,"}",-1,-1,void 0];case exports.TokenType.CloseCurly:return[exports.TokenType.OpenCurly,"{",-1,-1,void 0];case exports.TokenType.OpenSquare:return[exports.TokenType.CloseSquare,"]",-1,-1,void 0];case exports.TokenType.CloseSquare:return[exports.TokenType.OpenSquare,"[",-1,-1,void 0];default:return null}},exports.mirrorVariantType=function mirrorVariantType(e){switch(e){case exports.TokenType.OpenParen:return exports.TokenType.CloseParen;case exports.TokenType.CloseParen:return exports.TokenType.OpenParen;case exports.TokenType.OpenCurly:return exports.TokenType.CloseCurly;case exports.TokenType.CloseCurly:return exports.TokenType.OpenCurly;case exports.TokenType.OpenSquare:return exports.TokenType.CloseSquare;case exports.TokenType.CloseSquare:return exports.TokenType.OpenSquare;default:return null}},exports.mutateIdent=function mutateIdent(e,o){const n=[];for(const e of o)n.push(e.codePointAt(0));const t=String.fromCodePoint(...ensureThatValueRoundTripsAsIdent(n));e[1]=t,e[4].value=o},exports.mutateUnit=function mutateUnit(e,o){const n=[];for(const e of o)n.push(e.codePointAt(0));const t=ensureThatValueRoundTripsAsIdent(n);101===t[0]&&insertEscapedCodePoint(t,0,t[0]);const r=String.fromCodePoint(...t),s="+"===e[4].signCharacter?e[4].signCharacter:"",i=e[4].value.toString();e[1]=`${s}${i}${r}`,e[4].unit=o},exports.stringify=function stringify(...e){let o="";for(let n=0;n): Array; */ export declare type CSSToken = TokenAtKeyword | TokenBadString | TokenBadURL | TokenCDC | TokenCDO | TokenColon | TokenComma | TokenComment | TokenDelim | TokenDimension | TokenEOF | TokenFunction | TokenHash | TokenIdent | TokenNumber | TokenPercentage | TokenSemicolon | TokenString | TokenURL | TokenWhitespace | TokenOpenParen | TokenCloseParen | TokenOpenSquare | TokenCloseSquare | TokenOpenCurly | TokenCloseCurly | TokenUnicodeRange; +export declare interface GridTemplateAreasTokenNamedCell { + type: TokenTypeGridTemplateAreas.NamedCell; + /** + * The name of the cell + */ + value: string; +} + +export declare interface GridTemplateAreasTokenNullCell { + type: TokenTypeGridTemplateAreas.NullCell; + /** + * The dots representing the null cell + */ + value: string; +} + +export declare interface GridTemplateAreasTokenTrash { + type: TokenTypeGridTemplateAreas.Trash; + /** + * The incorrect cell value + */ + value: string; +} + /** * The type of hash token */ @@ -380,6 +404,13 @@ export declare function tokenize(input: { onParseError?: (error: ParseError) => void; }): Array; +/** + * Tokenize a CSS string describing grid template areas into a list of tokens. + */ +export declare function tokenizeGridTemplateAreas(input: { + valueOf(): string; +}): Array; + /** * Create a tokenizer for a CSS string. */ @@ -573,6 +604,17 @@ export declare enum TokenType { UnicodeRange = "unicode-range-token" } +/** + * All possible CSS token types for grid template areas + * + * @see {@link https://drafts.csswg.org/css-grid/#valdef-grid-template-areas-string} + */ +export declare enum TokenTypeGridTemplateAreas { + NamedCell = "named-cell-token", + NullCell = "null-cell-token", + Trash = "trash-token" +} + export declare interface TokenUnicodeRange extends Token=48&&e<=57}function isUppercaseLetterCodePoint(e){return e>=65&&e<=90}function isLowercaseLetterCodePoint(e){return e>=97&&e<=122}function isHexDigitCodePoint(e){return e>=48&&e<=57||e>=97&&e<=102||e>=65&&e<=70}function isLetterCodePoint(e){return isLowercaseLetterCodePoint(e)||isUppercaseLetterCodePoint(e)}function isIdentStartCodePoint(e){return isLetterCodePoint(e)||isNonASCII_IdentCodePoint(e)||95===e}function isIdentCodePoint(e){return isIdentStartCodePoint(e)||isDigitCodePoint(e)||e===o}function isNonASCII_IdentCodePoint(e){return 183===e||8204===e||8205===e||8255===e||8256===e||8204===e||(192<=e&&e<=214||216<=e&&e<=246||248<=e&&e<=893||895<=e&&e<=8191||8304<=e&&e<=8591||11264<=e&&e<=12271||12289<=e&&e<=55295||63744<=e&&e<=64975||65008<=e&&e<=65533||(0===e||(!!isSurrogate(e)||e>=65536)))}function isNewLine(e){return e===r||e===t||12===e}function isWhitespace(e){return 32===e||e===r||9===e||e===t||12===e}function isSurrogate(e){return e>=55296&&e<=57343}function checkIfTwoCodePointsAreAValidEscape(e){return 92===e.source.codePointAt(e.cursor)&&!isNewLine(e.source.codePointAt(e.cursor+1)??-1)}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,n){return n.source.codePointAt(n.cursor)===o?n.source.codePointAt(n.cursor+1)===o||(!!isIdentStartCodePoint(n.source.codePointAt(n.cursor+1)??-1)||92===n.source.codePointAt(n.cursor+1)&&!isNewLine(n.source.codePointAt(n.cursor+2)??-1)):!!isIdentStartCodePoint(n.source.codePointAt(n.cursor)??-1)||checkIfTwoCodePointsAreAValidEscape(n)}function checkIfThreeCodePointsWouldStartANumber(e){return e.source.codePointAt(e.cursor)===i||e.source.codePointAt(e.cursor)===o?!!isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1)||46===e.source.codePointAt(e.cursor+1)&&isDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1):46===e.source.codePointAt(e.cursor)?isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1):isDigitCodePoint(e.source.codePointAt(e.cursor)??-1)}function checkIfTwoCodePointsStartAComment(e){return 47===e.source.codePointAt(e.cursor)&&42===e.source.codePointAt(e.cursor+1)}function checkIfThreeCodePointsWouldStartCDC(e){return e.source.codePointAt(e.cursor)===o&&e.source.codePointAt(e.cursor+1)===o&&62===e.source.codePointAt(e.cursor+2)}var c,a,u;function mirrorVariantType(e){switch(e){case c.OpenParen:return c.CloseParen;case c.CloseParen:return c.OpenParen;case c.OpenCurly:return c.CloseCurly;case c.CloseCurly:return c.OpenCurly;case c.OpenSquare:return c.CloseSquare;case c.CloseSquare:return c.OpenSquare;default:return null}}function mirrorVariant(e){switch(e[0]){case c.OpenParen:return[c.CloseParen,")",-1,-1,void 0];case c.CloseParen:return[c.OpenParen,"(",-1,-1,void 0];case c.OpenCurly:return[c.CloseCurly,"}",-1,-1,void 0];case c.CloseCurly:return[c.OpenCurly,"{",-1,-1,void 0];case c.OpenSquare:return[c.CloseSquare,"]",-1,-1,void 0];case c.CloseSquare:return[c.OpenSquare,"[",-1,-1,void 0];default:return null}}function consumeComment(n,t){for(t.advanceCodePoint(2);;){const o=t.readCodePoint();if(void 0===o){const o=[c.Comment,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInComment,t.representationStart,t.representationEnd,["4.3.2. Consume comments","Unexpected EOF"],o)),o}if(42===o&&(void 0!==t.source.codePointAt(t.cursor)&&47===t.source.codePointAt(t.cursor))){t.advanceCodePoint();break}}return[c.Comment,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0]}function consumeEscapedCodePoint(n,o){const i=o.readCodePoint();if(void 0===i)return n.onParseError(new ParseError(e.UnexpectedEOFInEscapedCodePoint,o.representationStart,o.representationEnd,["4.3.7. Consume an escaped code point","Unexpected EOF"])),s;if(isHexDigitCodePoint(i)){const e=[i];let n;for(;void 0!==(n=o.source.codePointAt(o.cursor))&&isHexDigitCodePoint(n)&&e.length<6;)e.push(n),o.advanceCodePoint();isWhitespace(o.source.codePointAt(o.cursor)??-1)&&(o.source.codePointAt(o.cursor)===t&&o.source.codePointAt(o.cursor+1)===r&&o.advanceCodePoint(),o.advanceCodePoint());const c=parseInt(String.fromCodePoint(...e),16);return 0===c||isSurrogate(c)||c>1114111?s:c}return 0===i||isSurrogate(i)?s:i}function consumeIdentSequence(e,n){const t=[];for(;;){const o=n.source.codePointAt(n.cursor)??-1;if(0===o||isSurrogate(o))t.push(s),n.advanceCodePoint(+(o>65535)+1);else if(isIdentCodePoint(o))t.push(o),n.advanceCodePoint(+(o>65535)+1);else{if(!checkIfTwoCodePointsAreAValidEscape(n))return t;n.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,n))}}}function consumeHashToken(e,n){n.advanceCodePoint();const t=n.source.codePointAt(n.cursor);if(void 0!==t&&(isIdentCodePoint(t)||checkIfTwoCodePointsAreAValidEscape(n))){let t=u.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)&&(t=u.ID);const o=consumeIdentSequence(e,n);return[c.Hash,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...o),type:t}]}return[c.Delim,"#",n.representationStart,n.representationEnd,{value:"#"}]}function consumeNumber(e,n){let t=a.Integer;for(n.source.codePointAt(n.cursor)!==i&&n.source.codePointAt(n.cursor)!==o||n.advanceCodePoint();isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();if(46===n.source.codePointAt(n.cursor)&&isDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))for(n.advanceCodePoint(2),t=a.Number;isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();if(101===n.source.codePointAt(n.cursor)||69===n.source.codePointAt(n.cursor)){if(isDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))n.advanceCodePoint(2);else{if(n.source.codePointAt(n.cursor+1)!==o&&n.source.codePointAt(n.cursor+1)!==i||!isDigitCodePoint(n.source.codePointAt(n.cursor+2)??-1))return t;n.advanceCodePoint(3)}for(t=a.Number;isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint()}return t}function consumeNumericToken(e,n){let t;{const e=n.source.codePointAt(n.cursor);e===o?t="-":e===i&&(t="+")}const r=consumeNumber(0,n),s=parseFloat(n.source.slice(n.representationStart,n.representationEnd+1));if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const o=consumeIdentSequence(e,n);return[c.Dimension,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:s,signCharacter:t,type:r,unit:String.fromCodePoint(...o)}]}return 37===n.source.codePointAt(n.cursor)?(n.advanceCodePoint(),[c.Percentage,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:s,signCharacter:t}]):[c.Number,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:s,signCharacter:t,type:r}]}function consumeWhiteSpace(e){for(;isWhitespace(e.source.codePointAt(e.cursor)??-1);)e.advanceCodePoint();return[c.Whitespace,e.source.slice(e.representationStart,e.representationEnd+1),e.representationStart,e.representationEnd,void 0]}!function(e){e.Comment="comment",e.AtKeyword="at-keyword-token",e.BadString="bad-string-token",e.BadURL="bad-url-token",e.CDC="CDC-token",e.CDO="CDO-token",e.Colon="colon-token",e.Comma="comma-token",e.Delim="delim-token",e.Dimension="dimension-token",e.EOF="EOF-token",e.Function="function-token",e.Hash="hash-token",e.Ident="ident-token",e.Number="number-token",e.Percentage="percentage-token",e.Semicolon="semicolon-token",e.String="string-token",e.URL="url-token",e.Whitespace="whitespace-token",e.OpenParen="(-token",e.CloseParen=")-token",e.OpenSquare="[-token",e.CloseSquare="]-token",e.OpenCurly="{-token",e.CloseCurly="}-token",e.UnicodeRange="unicode-range-token"}(c||(c={})),function(e){e.Integer="integer",e.Number="number"}(a||(a={})),function(e){e.Unrestricted="unrestricted",e.ID="id"}(u||(u={}));class Reader{cursor=0;source="";representationStart=0;representationEnd=-1;constructor(e){this.source=e}advanceCodePoint(e=1){this.cursor=this.cursor+e,this.representationEnd=this.cursor-1}readCodePoint(){const e=this.source.codePointAt(this.cursor);if(void 0!==e)return this.cursor=this.cursor+1,this.representationEnd=this.cursor-1,e}unreadCodePoint(e=1){this.cursor=this.cursor-e,this.representationEnd=this.cursor-1}resetRepresentation(){this.representationStart=this.cursor,this.representationEnd=-1}}function consumeStringToken(n,o){let i="";const a=o.readCodePoint();for(;;){const u=o.readCodePoint();if(void 0===u){const t=[c.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:i}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInString,o.representationStart,o.representationEnd,["4.3.5. Consume a string token","Unexpected EOF"],t)),t}if(isNewLine(u)){o.unreadCodePoint();const i=[c.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedNewLineInString,o.representationStart,o.source.codePointAt(o.cursor)===t&&o.source.codePointAt(o.cursor+1)===r?o.representationEnd+2:o.representationEnd+1,["4.3.5. Consume a string token","Unexpected newline"],i)),i}if(u===a)return[c.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:i}];if(92!==u)0===u||isSurrogate(u)?i+=String.fromCodePoint(s):i+=String.fromCodePoint(u);else{if(void 0===o.source.codePointAt(o.cursor))continue;if(isNewLine(o.source.codePointAt(o.cursor)??-1)){o.source.codePointAt(o.cursor)===t&&o.source.codePointAt(o.cursor+1)===r&&o.advanceCodePoint(),o.advanceCodePoint();continue}i+=String.fromCodePoint(consumeEscapedCodePoint(n,o))}}}function checkIfCodePointsMatchURLIdent(e){return!(3!==e.length||117!==e[0]&&85!==e[0]||114!==e[1]&&82!==e[1]||108!==e[2]&&76!==e[2])}function consumeBadURL(e,n){for(;;){const t=n.source.codePointAt(n.cursor);if(void 0===t)return;if(41===t)return void n.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(n)?(n.advanceCodePoint(),consumeEscapedCodePoint(e,n)):n.advanceCodePoint()}}function consumeUrlToken(n,t){for(;isWhitespace(t.source.codePointAt(t.cursor)??-1);)t.advanceCodePoint();let o="";for(;;){if(void 0===t.source.codePointAt(t.cursor)){const r=[c.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","Unexpected EOF"],r)),r}if(41===t.source.codePointAt(t.cursor))return t.advanceCodePoint(),[c.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];if(isWhitespace(t.source.codePointAt(t.cursor)??-1)){for(t.advanceCodePoint();isWhitespace(t.source.codePointAt(t.cursor)??-1);)t.advanceCodePoint();if(void 0===t.source.codePointAt(t.cursor)){const r=[c.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"],r)),r}return 41===t.source.codePointAt(t.cursor)?(t.advanceCodePoint(),[c.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}]):(consumeBadURL(n,t),[c.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0])}const i=t.source.codePointAt(t.cursor);if(34===i||39===i||40===i||(11===(r=i??-1)||127===r||0<=r&&r<=8||14<=r&&r<=31)){consumeBadURL(n,t);const o=[c.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedCharacterInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"],o)),o}if(92===i){if(checkIfTwoCodePointsAreAValidEscape(t)){t.advanceCodePoint(),o+=String.fromCodePoint(consumeEscapedCodePoint(n,t));continue}consumeBadURL(n,t);const r=[c.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],r)),r}0===t.source.codePointAt(t.cursor)||isSurrogate(t.source.codePointAt(t.cursor)??-1)?(o+=String.fromCodePoint(s),t.advanceCodePoint()):(o+=t.source[t.cursor],t.advanceCodePoint())}var r}function consumeIdentLikeToken(e,n){const t=consumeIdentSequence(e,n);if(40!==n.source.codePointAt(n.cursor))return[c.Ident,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...t)}];if(checkIfCodePointsMatchURLIdent(t)){n.advanceCodePoint();let o=0;for(;;){const e=isWhitespace(n.source.codePointAt(n.cursor)??-1),r=isWhitespace(n.source.codePointAt(n.cursor+1)??-1);if(e&&r){o+=1,n.advanceCodePoint(1);continue}const i=e?n.source.codePointAt(n.cursor+1):n.source.codePointAt(n.cursor);if(34===i||39===i)return o>0&&n.unreadCodePoint(o),[c.Function,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...t)}];break}return consumeUrlToken(e,n)}return n.advanceCodePoint(),[c.Function,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...t)}]}function checkIfThreeCodePointsWouldStartAUnicodeRange(e){return!(117!==e.source.codePointAt(e.cursor)&&85!==e.source.codePointAt(e.cursor)||e.source.codePointAt(e.cursor+1)!==i||63!==e.source.codePointAt(e.cursor+2)&&!isHexDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1))}function consumeUnicodeRangeToken(e,n){n.advanceCodePoint(2);const t=[],r=[];let i;for(;void 0!==(i=n.source.codePointAt(n.cursor))&&t.length<6&&isHexDigitCodePoint(i);)t.push(i),n.advanceCodePoint();for(;void 0!==(i=n.source.codePointAt(n.cursor))&&t.length<6&&63===i;)0===r.length&&r.push(...t),t.push(48),r.push(70),n.advanceCodePoint();if(!r.length&&n.source.codePointAt(n.cursor)===o&&isHexDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))for(n.advanceCodePoint();void 0!==(i=n.source.codePointAt(n.cursor))&&r.length<6&&isHexDigitCodePoint(i);)r.push(i),n.advanceCodePoint();if(!r.length){const e=parseInt(String.fromCodePoint(...t),16);return[c.UnicodeRange,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{startOfRange:e,endOfRange:e}]}const s=parseInt(String.fromCodePoint(...t),16),a=parseInt(String.fromCodePoint(...r),16);return[c.UnicodeRange,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{startOfRange:s,endOfRange:a}]}function tokenize(e,n){const t=tokenizer(e,n),o=[];for(;!t.endOfFile();)o.push(t.nextToken());return o.push(t.nextToken()),o}function tokenizer(n,s){const a=n.css.valueOf(),u=n.unicodeRangesAllowed??!1,d=new Reader(a),p={onParseError:s?.onParseError??noop};return{nextToken:function nextToken(){d.resetRepresentation();const n=d.source.codePointAt(d.cursor);if(void 0===n)return[c.EOF,"",-1,-1,void 0];if(47===n&&checkIfTwoCodePointsStartAComment(d))return consumeComment(p,d);if(u&&(117===n||85===n)&&checkIfThreeCodePointsWouldStartAUnicodeRange(d))return consumeUnicodeRangeToken(0,d);if(isIdentStartCodePoint(n))return consumeIdentLikeToken(p,d);if(isDigitCodePoint(n))return consumeNumericToken(p,d);switch(n){case 44:return d.advanceCodePoint(),[c.Comma,",",d.representationStart,d.representationEnd,void 0];case 58:return d.advanceCodePoint(),[c.Colon,":",d.representationStart,d.representationEnd,void 0];case 59:return d.advanceCodePoint(),[c.Semicolon,";",d.representationStart,d.representationEnd,void 0];case 40:return d.advanceCodePoint(),[c.OpenParen,"(",d.representationStart,d.representationEnd,void 0];case 41:return d.advanceCodePoint(),[c.CloseParen,")",d.representationStart,d.representationEnd,void 0];case 91:return d.advanceCodePoint(),[c.OpenSquare,"[",d.representationStart,d.representationEnd,void 0];case 93:return d.advanceCodePoint(),[c.CloseSquare,"]",d.representationStart,d.representationEnd,void 0];case 123:return d.advanceCodePoint(),[c.OpenCurly,"{",d.representationStart,d.representationEnd,void 0];case 125:return d.advanceCodePoint(),[c.CloseCurly,"}",d.representationStart,d.representationEnd,void 0];case 39:case 34:return consumeStringToken(p,d);case 35:return consumeHashToken(p,d);case i:case 46:return checkIfThreeCodePointsWouldStartANumber(d)?consumeNumericToken(p,d):(d.advanceCodePoint(),[c.Delim,d.source[d.representationStart],d.representationStart,d.representationEnd,{value:d.source[d.representationStart]}]);case r:case t:case 12:case 9:case 32:return consumeWhiteSpace(d);case o:return checkIfThreeCodePointsWouldStartANumber(d)?consumeNumericToken(p,d):checkIfThreeCodePointsWouldStartCDC(d)?(d.advanceCodePoint(3),[c.CDC,"--\x3e",d.representationStart,d.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,d)?consumeIdentLikeToken(p,d):(d.advanceCodePoint(),[c.Delim,"-",d.representationStart,d.representationEnd,{value:"-"}]);case 60:return checkIfFourCodePointsWouldStartCDO(d)?(d.advanceCodePoint(4),[c.CDO,"\x3c!--",d.representationStart,d.representationEnd,void 0]):(d.advanceCodePoint(),[c.Delim,"<",d.representationStart,d.representationEnd,{value:"<"}]);case 64:if(d.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,d)){const e=consumeIdentSequence(p,d);return[c.AtKeyword,d.source.slice(d.representationStart,d.representationEnd+1),d.representationStart,d.representationEnd,{value:String.fromCodePoint(...e)}]}return[c.Delim,"@",d.representationStart,d.representationEnd,{value:"@"}];case 92:{if(checkIfTwoCodePointsAreAValidEscape(d))return consumeIdentLikeToken(p,d);d.advanceCodePoint();const n=[c.Delim,"\\",d.representationStart,d.representationEnd,{value:"\\"}];return p.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceAfterBackslash,d.representationStart,d.representationEnd,["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],n)),n}}return d.advanceCodePoint(),[c.Delim,d.source[d.representationStart],d.representationStart,d.representationEnd,{value:d.source[d.representationStart]}]},endOfFile:function endOfFile(){return void 0===d.source.codePointAt(d.cursor)}}}function noop(){}function mutateIdent(e,n){const t=[];for(const e of n)t.push(e.codePointAt(0));const o=String.fromCodePoint(...ensureThatValueRoundTripsAsIdent(t));e[1]=o,e[4].value=n}function mutateUnit(e,n){const t=[];for(const e of n)t.push(e.codePointAt(0));const o=ensureThatValueRoundTripsAsIdent(t);101===o[0]&&insertEscapedCodePoint(o,0,o[0]);const r=String.fromCodePoint(...o),i="+"===e[4].signCharacter?e[4].signCharacter:"",s=e[4].value.toString();e[1]=`${i}${s}${r}`,e[4].unit=n}function ensureThatValueRoundTripsAsIdent(e){let n=0;e[0]===o&&e[1]===o?n=2:e[0]===o&&e[1]?(n=2,isIdentStartCodePoint(e[1])||(n+=insertEscapedCodePoint(e,1,e[1]))):isIdentStartCodePoint(e[0])?n=1:(n=1,n+=insertEscapedCodePoint(e,0,e[0]));for(let t=n;t=48&&e<=57}function isUppercaseLetterCodePoint(e){return e>=65&&e<=90}function isLowercaseLetterCodePoint(e){return e>=97&&e<=122}function isHexDigitCodePoint(e){return e>=48&&e<=57||e>=97&&e<=102||e>=65&&e<=70}function isLetterCodePoint(e){return isLowercaseLetterCodePoint(e)||isUppercaseLetterCodePoint(e)}function isIdentStartCodePoint(e){return isLetterCodePoint(e)||isNonASCII_IdentCodePoint(e)||95===e}function isIdentCodePoint(e){return isIdentStartCodePoint(e)||isDigitCodePoint(e)||e===r}function isNonASCII_IdentCodePoint(e){return 183===e||8204===e||8205===e||8255===e||8256===e||8204===e||(192<=e&&e<=214||216<=e&&e<=246||248<=e&&e<=893||895<=e&&e<=8191||8304<=e&&e<=8591||11264<=e&&e<=12271||12289<=e&&e<=55295||63744<=e&&e<=64975||65008<=e&&e<=65533||(0===e||(!!isSurrogate(e)||e>=65536)))}function isNewLine(e){return e===i||e===t||12===e}function isWhitespace(e){return 32===e||e===i||9===e||e===t||12===e}function isSurrogate(e){return e>=55296&&e<=57343}function checkIfTwoCodePointsAreAValidEscape(e){return 92===e.source.codePointAt(e.cursor)&&!isNewLine(e.source.codePointAt(e.cursor+1)??-1)}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,n){return n.source.codePointAt(n.cursor)===r?n.source.codePointAt(n.cursor+1)===r||(!!isIdentStartCodePoint(n.source.codePointAt(n.cursor+1)??-1)||92===n.source.codePointAt(n.cursor+1)&&!isNewLine(n.source.codePointAt(n.cursor+2)??-1)):!!isIdentStartCodePoint(n.source.codePointAt(n.cursor)??-1)||checkIfTwoCodePointsAreAValidEscape(n)}function checkIfThreeCodePointsWouldStartANumber(e){return e.source.codePointAt(e.cursor)===s||e.source.codePointAt(e.cursor)===r?!!isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1)||e.source.codePointAt(e.cursor+1)===o&&isDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1):e.source.codePointAt(e.cursor)===o?isDigitCodePoint(e.source.codePointAt(e.cursor+1)??-1):isDigitCodePoint(e.source.codePointAt(e.cursor)??-1)}function checkIfTwoCodePointsStartAComment(e){return 47===e.source.codePointAt(e.cursor)&&42===e.source.codePointAt(e.cursor+1)}function checkIfThreeCodePointsWouldStartCDC(e){return e.source.codePointAt(e.cursor)===r&&e.source.codePointAt(e.cursor+1)===r&&62===e.source.codePointAt(e.cursor+2)}var a,u,d;function mirrorVariantType(e){switch(e){case a.OpenParen:return a.CloseParen;case a.CloseParen:return a.OpenParen;case a.OpenCurly:return a.CloseCurly;case a.CloseCurly:return a.OpenCurly;case a.OpenSquare:return a.CloseSquare;case a.CloseSquare:return a.OpenSquare;default:return null}}function mirrorVariant(e){switch(e[0]){case a.OpenParen:return[a.CloseParen,")",-1,-1,void 0];case a.CloseParen:return[a.OpenParen,"(",-1,-1,void 0];case a.OpenCurly:return[a.CloseCurly,"}",-1,-1,void 0];case a.CloseCurly:return[a.OpenCurly,"{",-1,-1,void 0];case a.OpenSquare:return[a.CloseSquare,"]",-1,-1,void 0];case a.CloseSquare:return[a.OpenSquare,"[",-1,-1,void 0];default:return null}}function consumeComment(n,t){for(t.advanceCodePoint(2);;){const o=t.readCodePoint();if(void 0===o){const o=[a.Comment,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInComment,t.representationStart,t.representationEnd,["4.3.2. Consume comments","Unexpected EOF"],o)),o}if(42===o&&(void 0!==t.source.codePointAt(t.cursor)&&47===t.source.codePointAt(t.cursor))){t.advanceCodePoint();break}}return[a.Comment,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0]}function consumeEscapedCodePoint(n,o){const r=o.readCodePoint();if(void 0===r)return n.onParseError(new ParseError(e.UnexpectedEOFInEscapedCodePoint,o.representationStart,o.representationEnd,["4.3.7. Consume an escaped code point","Unexpected EOF"])),c;if(isHexDigitCodePoint(r)){const e=[r];let n;for(;void 0!==(n=o.source.codePointAt(o.cursor))&&isHexDigitCodePoint(n)&&e.length<6;)e.push(n),o.advanceCodePoint();isWhitespace(o.source.codePointAt(o.cursor)??-1)&&(o.source.codePointAt(o.cursor)===t&&o.source.codePointAt(o.cursor+1)===i&&o.advanceCodePoint(),o.advanceCodePoint());const s=parseInt(String.fromCodePoint(...e),16);return 0===s||isSurrogate(s)||s>1114111?c:s}return 0===r||isSurrogate(r)?c:r}function consumeIdentSequence(e,n){const t=[];for(;;){const o=n.source.codePointAt(n.cursor)??-1;if(0===o||isSurrogate(o))t.push(c),n.advanceCodePoint(+(o>65535)+1);else if(isIdentCodePoint(o))t.push(o),n.advanceCodePoint(+(o>65535)+1);else{if(!checkIfTwoCodePointsAreAValidEscape(n))return t;n.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,n))}}}function consumeHashToken(e,n){n.advanceCodePoint();const t=n.source.codePointAt(n.cursor);if(void 0!==t&&(isIdentCodePoint(t)||checkIfTwoCodePointsAreAValidEscape(n))){let t=d.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)&&(t=d.ID);const o=consumeIdentSequence(e,n);return[a.Hash,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...o),type:t}]}return[a.Delim,"#",n.representationStart,n.representationEnd,{value:"#"}]}function consumeNumber(e,n){let t=u.Integer;for(n.source.codePointAt(n.cursor)!==s&&n.source.codePointAt(n.cursor)!==r||n.advanceCodePoint();isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();if(n.source.codePointAt(n.cursor)===o&&isDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))for(n.advanceCodePoint(2),t=u.Number;isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint();if(101===n.source.codePointAt(n.cursor)||69===n.source.codePointAt(n.cursor)){if(isDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))n.advanceCodePoint(2);else{if(n.source.codePointAt(n.cursor+1)!==r&&n.source.codePointAt(n.cursor+1)!==s||!isDigitCodePoint(n.source.codePointAt(n.cursor+2)??-1))return t;n.advanceCodePoint(3)}for(t=u.Number;isDigitCodePoint(n.source.codePointAt(n.cursor)??-1);)n.advanceCodePoint()}return t}function consumeNumericToken(e,n){let t;{const e=n.source.codePointAt(n.cursor);e===r?t="-":e===s&&(t="+")}const o=consumeNumber(0,n),i=parseFloat(n.source.slice(n.representationStart,n.representationEnd+1));if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const r=consumeIdentSequence(e,n);return[a.Dimension,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:i,signCharacter:t,type:o,unit:String.fromCodePoint(...r)}]}return 37===n.source.codePointAt(n.cursor)?(n.advanceCodePoint(),[a.Percentage,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:i,signCharacter:t}]):[a.Number,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:i,signCharacter:t,type:o}]}function consumeWhiteSpace$1(e){for(;isWhitespace(e.source.codePointAt(e.cursor)??-1);)e.advanceCodePoint();return[a.Whitespace,e.source.slice(e.representationStart,e.representationEnd+1),e.representationStart,e.representationEnd,void 0]}!function(e){e.Comment="comment",e.AtKeyword="at-keyword-token",e.BadString="bad-string-token",e.BadURL="bad-url-token",e.CDC="CDC-token",e.CDO="CDO-token",e.Colon="colon-token",e.Comma="comma-token",e.Delim="delim-token",e.Dimension="dimension-token",e.EOF="EOF-token",e.Function="function-token",e.Hash="hash-token",e.Ident="ident-token",e.Number="number-token",e.Percentage="percentage-token",e.Semicolon="semicolon-token",e.String="string-token",e.URL="url-token",e.Whitespace="whitespace-token",e.OpenParen="(-token",e.CloseParen=")-token",e.OpenSquare="[-token",e.CloseSquare="]-token",e.OpenCurly="{-token",e.CloseCurly="}-token",e.UnicodeRange="unicode-range-token"}(a||(a={})),function(e){e.Integer="integer",e.Number="number"}(u||(u={})),function(e){e.Unrestricted="unrestricted",e.ID="id"}(d||(d={}));class Reader{cursor=0;source="";representationStart=0;representationEnd=-1;constructor(e){this.source=e}advanceCodePoint(e=1){this.cursor=this.cursor+e,this.representationEnd=this.cursor-1}readCodePoint(){const e=this.source.codePointAt(this.cursor);if(void 0!==e)return this.cursor=this.cursor+1,this.representationEnd=this.cursor-1,e}unreadCodePoint(e=1){this.cursor=this.cursor-e,this.representationEnd=this.cursor-1}resetRepresentation(){this.representationStart=this.cursor,this.representationEnd=-1}}function consumeStringToken(n,o){let r="";const s=o.readCodePoint();for(;;){const u=o.readCodePoint();if(void 0===u){const t=[a.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInString,o.representationStart,o.representationEnd,["4.3.5. Consume a string token","Unexpected EOF"],t)),t}if(isNewLine(u)){o.unreadCodePoint();const r=[a.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedNewLineInString,o.representationStart,o.source.codePointAt(o.cursor)===t&&o.source.codePointAt(o.cursor+1)===i?o.representationEnd+2:o.representationEnd+1,["4.3.5. Consume a string token","Unexpected newline"],r)),r}if(u===s)return[a.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(92!==u)0===u||isSurrogate(u)?r+=String.fromCodePoint(c):r+=String.fromCodePoint(u);else{if(void 0===o.source.codePointAt(o.cursor))continue;if(isNewLine(o.source.codePointAt(o.cursor)??-1)){o.source.codePointAt(o.cursor)===t&&o.source.codePointAt(o.cursor+1)===i&&o.advanceCodePoint(),o.advanceCodePoint();continue}r+=String.fromCodePoint(consumeEscapedCodePoint(n,o))}}}function checkIfCodePointsMatchURLIdent(e){return!(3!==e.length||117!==e[0]&&85!==e[0]||114!==e[1]&&82!==e[1]||108!==e[2]&&76!==e[2])}function consumeBadURL(e,n){for(;;){const t=n.source.codePointAt(n.cursor);if(void 0===t)return;if(41===t)return void n.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(n)?(n.advanceCodePoint(),consumeEscapedCodePoint(e,n)):n.advanceCodePoint()}}function consumeUrlToken(n,t){for(;isWhitespace(t.source.codePointAt(t.cursor)??-1);)t.advanceCodePoint();let o="";for(;;){if(void 0===t.source.codePointAt(t.cursor)){const r=[a.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","Unexpected EOF"],r)),r}if(41===t.source.codePointAt(t.cursor))return t.advanceCodePoint(),[a.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];if(isWhitespace(t.source.codePointAt(t.cursor)??-1)){for(t.advanceCodePoint();isWhitespace(t.source.codePointAt(t.cursor)??-1);)t.advanceCodePoint();if(void 0===t.source.codePointAt(t.cursor)){const r=[a.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];return n.onParseError(new ParseErrorWithToken(e.UnexpectedEOFInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"],r)),r}return 41===t.source.codePointAt(t.cursor)?(t.advanceCodePoint(),[a.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}]):(consumeBadURL(n,t),[a.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0])}const i=t.source.codePointAt(t.cursor);if(34===i||39===i||40===i||(11===(r=i??-1)||127===r||0<=r&&r<=8||14<=r&&r<=31)){consumeBadURL(n,t);const o=[a.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.UnexpectedCharacterInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"],o)),o}if(92===i){if(checkIfTwoCodePointsAreAValidEscape(t)){t.advanceCodePoint(),o+=String.fromCodePoint(consumeEscapedCodePoint(n,t));continue}consumeBadURL(n,t);const r=[a.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];return n.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceInURL,t.representationStart,t.representationEnd,["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],r)),r}0===t.source.codePointAt(t.cursor)||isSurrogate(t.source.codePointAt(t.cursor)??-1)?(o+=String.fromCodePoint(c),t.advanceCodePoint()):(o+=t.source[t.cursor],t.advanceCodePoint())}var r}function consumeIdentLikeToken(e,n){const t=consumeIdentSequence(e,n);if(40!==n.source.codePointAt(n.cursor))return[a.Ident,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...t)}];if(checkIfCodePointsMatchURLIdent(t)){n.advanceCodePoint();let o=0;for(;;){const e=isWhitespace(n.source.codePointAt(n.cursor)??-1),r=isWhitespace(n.source.codePointAt(n.cursor+1)??-1);if(e&&r){o+=1,n.advanceCodePoint(1);continue}const i=e?n.source.codePointAt(n.cursor+1):n.source.codePointAt(n.cursor);if(34===i||39===i)return o>0&&n.unreadCodePoint(o),[a.Function,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...t)}];break}return consumeUrlToken(e,n)}return n.advanceCodePoint(),[a.Function,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCodePoint(...t)}]}function checkIfThreeCodePointsWouldStartAUnicodeRange(e){return!(117!==e.source.codePointAt(e.cursor)&&85!==e.source.codePointAt(e.cursor)||e.source.codePointAt(e.cursor+1)!==s||63!==e.source.codePointAt(e.cursor+2)&&!isHexDigitCodePoint(e.source.codePointAt(e.cursor+2)??-1))}function consumeUnicodeRangeToken(e,n){n.advanceCodePoint(2);const t=[],o=[];let i;for(;void 0!==(i=n.source.codePointAt(n.cursor))&&t.length<6&&isHexDigitCodePoint(i);)t.push(i),n.advanceCodePoint();for(;void 0!==(i=n.source.codePointAt(n.cursor))&&t.length<6&&63===i;)0===o.length&&o.push(...t),t.push(48),o.push(70),n.advanceCodePoint();if(!o.length&&n.source.codePointAt(n.cursor)===r&&isHexDigitCodePoint(n.source.codePointAt(n.cursor+1)??-1))for(n.advanceCodePoint();void 0!==(i=n.source.codePointAt(n.cursor))&&o.length<6&&isHexDigitCodePoint(i);)o.push(i),n.advanceCodePoint();if(!o.length){const e=parseInt(String.fromCodePoint(...t),16);return[a.UnicodeRange,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{startOfRange:e,endOfRange:e}]}const s=parseInt(String.fromCodePoint(...t),16),c=parseInt(String.fromCodePoint(...o),16);return[a.UnicodeRange,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{startOfRange:s,endOfRange:c}]}function tokenize(e,n){const t=tokenizer(e,n),o=[];for(;!t.endOfFile();)o.push(t.nextToken());return o.push(t.nextToken()),o}function tokenizer(n,c){const u=n.css.valueOf(),d=n.unicodeRangesAllowed??!1,p=new Reader(u),P={onParseError:c?.onParseError??noop};return{nextToken:function nextToken(){p.resetRepresentation();const n=p.source.codePointAt(p.cursor);if(void 0===n)return[a.EOF,"",-1,-1,void 0];if(47===n&&checkIfTwoCodePointsStartAComment(p))return consumeComment(P,p);if(d&&(117===n||85===n)&&checkIfThreeCodePointsWouldStartAUnicodeRange(p))return consumeUnicodeRangeToken(0,p);if(isIdentStartCodePoint(n))return consumeIdentLikeToken(P,p);if(isDigitCodePoint(n))return consumeNumericToken(P,p);switch(n){case 44:return p.advanceCodePoint(),[a.Comma,",",p.representationStart,p.representationEnd,void 0];case 58:return p.advanceCodePoint(),[a.Colon,":",p.representationStart,p.representationEnd,void 0];case 59:return p.advanceCodePoint(),[a.Semicolon,";",p.representationStart,p.representationEnd,void 0];case 40:return p.advanceCodePoint(),[a.OpenParen,"(",p.representationStart,p.representationEnd,void 0];case 41:return p.advanceCodePoint(),[a.CloseParen,")",p.representationStart,p.representationEnd,void 0];case 91:return p.advanceCodePoint(),[a.OpenSquare,"[",p.representationStart,p.representationEnd,void 0];case 93:return p.advanceCodePoint(),[a.CloseSquare,"]",p.representationStart,p.representationEnd,void 0];case 123:return p.advanceCodePoint(),[a.OpenCurly,"{",p.representationStart,p.representationEnd,void 0];case 125:return p.advanceCodePoint(),[a.CloseCurly,"}",p.representationStart,p.representationEnd,void 0];case 39:case 34:return consumeStringToken(P,p);case 35:return consumeHashToken(P,p);case s:case o:return checkIfThreeCodePointsWouldStartANumber(p)?consumeNumericToken(P,p):(p.advanceCodePoint(),[a.Delim,p.source[p.representationStart],p.representationStart,p.representationEnd,{value:p.source[p.representationStart]}]);case i:case t:case 12:case 9:case 32:return consumeWhiteSpace$1(p);case r:return checkIfThreeCodePointsWouldStartANumber(p)?consumeNumericToken(P,p):checkIfThreeCodePointsWouldStartCDC(p)?(p.advanceCodePoint(3),[a.CDC,"--\x3e",p.representationStart,p.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,p)?consumeIdentLikeToken(P,p):(p.advanceCodePoint(),[a.Delim,"-",p.representationStart,p.representationEnd,{value:"-"}]);case 60:return checkIfFourCodePointsWouldStartCDO(p)?(p.advanceCodePoint(4),[a.CDO,"\x3c!--",p.representationStart,p.representationEnd,void 0]):(p.advanceCodePoint(),[a.Delim,"<",p.representationStart,p.representationEnd,{value:"<"}]);case 64:if(p.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,p)){const e=consumeIdentSequence(P,p);return[a.AtKeyword,p.source.slice(p.representationStart,p.representationEnd+1),p.representationStart,p.representationEnd,{value:String.fromCodePoint(...e)}]}return[a.Delim,"@",p.representationStart,p.representationEnd,{value:"@"}];case 92:{if(checkIfTwoCodePointsAreAValidEscape(p))return consumeIdentLikeToken(P,p);p.advanceCodePoint();const n=[a.Delim,"\\",p.representationStart,p.representationEnd,{value:"\\"}];return P.onParseError(new ParseErrorWithToken(e.InvalidEscapeSequenceAfterBackslash,p.representationStart,p.representationEnd,["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"],n)),n}}return p.advanceCodePoint(),[a.Delim,p.source[p.representationStart],p.representationStart,p.representationEnd,{value:p.source[p.representationStart]}]},endOfFile:function endOfFile(){return void 0===p.source.codePointAt(p.cursor)}}}function noop(){}function mutateIdent(e,n){const t=[];for(const e of n)t.push(e.codePointAt(0));const o=String.fromCodePoint(...ensureThatValueRoundTripsAsIdent(t));e[1]=o,e[4].value=n}function mutateUnit(e,n){const t=[];for(const e of n)t.push(e.codePointAt(0));const o=ensureThatValueRoundTripsAsIdent(t);101===o[0]&&insertEscapedCodePoint(o,0,o[0]);const r=String.fromCodePoint(...o),i="+"===e[4].signCharacter?e[4].signCharacter:"",s=e[4].value.toString();e[1]=`${i}${s}${r}`,e[4].unit=n}function ensureThatValueRoundTripsAsIdent(e){let n=0;e[0]===r&&e[1]===r?n=2:e[0]===r&&e[1]?(n=2,isIdentStartCodePoint(e[1])||(n+=insertEscapedCodePoint(e,1,e[1]))):isIdentStartCodePoint(e[0])?n=1:(n=1,n+=insertEscapedCodePoint(e,0,e[0]));for(let t=n;t65535)+1);else{if(!isIdentCodePoint(t))break;n.push(t),e.advanceCodePoint(+(t>65535)+1)}}return{type:P.NamedCell,value:String.fromCodePoint(...n)}}function consumeNullCell(e){for(;e.source.codePointAt(e.cursor)===o;)e.advanceCodePoint();return{type:P.NullCell,value:e.source.slice(e.representationStart,e.representationEnd+1)}}function consumeWhiteSpace(e){for(;isWhitespace(e.source.codePointAt(e.cursor)??-1);)e.advanceCodePoint()}function consumeTrash(e){e.advanceCodePoint();e:for(;;){const n=e.source.codePointAt(e.cursor);if(void 0===n)break e;switch(n){case i:case t:case 12:case 9:case 32:case o:case 0:break e;default:if(isSurrogate(n)||isIdentCodePoint(n))break e;e.advanceCodePoint();continue e}}return{type:P.Trash,value:e.source.slice(e.representationStart,e.representationEnd+1)}}!function(e){e.NamedCell="named-cell-token",e.NullCell="null-cell-token",e.Trash="trash-token"}(P||(P={}));export{d as HashType,u as NumberType,ParseError,e as ParseErrorMessage,ParseErrorWithToken,a as TokenType,P as TokenTypeGridTemplateAreas,cloneTokens,isToken,isTokenAtKeyword,isTokenBadString,isTokenBadURL,isTokenCDC,isTokenCDO,isTokenCloseCurly,isTokenCloseParen,isTokenCloseSquare,isTokenColon,isTokenComma,isTokenComment,isTokenDelim,isTokenDimension,isTokenEOF,isTokenFunction,isTokenHash,isTokenIdent,isTokenNumber,isTokenNumeric,isTokenOpenCurly,isTokenOpenParen,isTokenOpenSquare,isTokenPercentage,isTokenSemicolon,isTokenString,isTokenURL,isTokenUnicodeRange,isTokenWhiteSpaceOrComment,isTokenWhitespace,mirrorVariant,mirrorVariantType,mutateIdent,mutateUnit,stringify,tokenize,tokenizeGridTemplateAreas,tokenizer}; diff --git a/packages/css-tokenizer/docs/css-tokenizer.api.json b/packages/css-tokenizer/docs/css-tokenizer.api.json index 4ef60eb90..3573527a2 100644 --- a/packages/css-tokenizer/docs/css-tokenizer.api.json +++ b/packages/css-tokenizer/docs/css-tokenizer.api.json @@ -505,6 +505,225 @@ "endIndex": 54 } }, + { + "kind": "Interface", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNamedCell:interface", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface GridTemplateAreasTokenNamedCell " + } + ], + "fileUrlPath": "dist/_types/interfaces/token-grid-template-areas.d.ts", + "releaseTag": "Public", + "name": "GridTemplateAreasTokenNamedCell", + "preserveMemberOrder": false, + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNamedCell#type:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "type: " + }, + { + "kind": "Reference", + "text": "TokenTypeGridTemplateAreas.NamedCell", + "canonicalReference": "@csstools/css-tokenizer!TokenTypeGridTemplateAreas.NamedCell:member" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "type", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNamedCell#value:member", + "docComment": "/**\n * The name of the cell\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "value: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "value", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNullCell:interface", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface GridTemplateAreasTokenNullCell " + } + ], + "fileUrlPath": "dist/_types/interfaces/token-grid-template-areas.d.ts", + "releaseTag": "Public", + "name": "GridTemplateAreasTokenNullCell", + "preserveMemberOrder": false, + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNullCell#type:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "type: " + }, + { + "kind": "Reference", + "text": "TokenTypeGridTemplateAreas.NullCell", + "canonicalReference": "@csstools/css-tokenizer!TokenTypeGridTemplateAreas.NullCell:member" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "type", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNullCell#value:member", + "docComment": "/**\n * The dots representing the null cell\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "value: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "value", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenTrash:interface", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface GridTemplateAreasTokenTrash " + } + ], + "fileUrlPath": "dist/_types/interfaces/token-grid-template-areas.d.ts", + "releaseTag": "Public", + "name": "GridTemplateAreasTokenTrash", + "preserveMemberOrder": false, + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenTrash#type:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "type: " + }, + { + "kind": "Reference", + "text": "TokenTypeGridTemplateAreas.Trash", + "canonicalReference": "@csstools/css-tokenizer!TokenTypeGridTemplateAreas.Trash:member" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "type", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenTrash#value:member", + "docComment": "/**\n * The incorrect cell value\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "value: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "value", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + }, { "kind": "Enum", "canonicalReference": "@csstools/css-tokenizer!HashType:enum", @@ -4489,6 +4708,83 @@ ], "name": "tokenize" }, + { + "kind": "Function", + "canonicalReference": "@csstools/css-tokenizer!tokenizeGridTemplateAreas:function(1)", + "docComment": "/**\n * Tokenize a CSS string describing grid template areas into a list of tokens.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare function tokenizeGridTemplateAreas(input: " + }, + { + "kind": "Content", + "text": "{\n valueOf(): string;\n}" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Reference", + "text": "Array", + "canonicalReference": "!Array:interface" + }, + { + "kind": "Content", + "text": "<" + }, + { + "kind": "Reference", + "text": "GridTemplateAreasTokenNamedCell", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNamedCell:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "GridTemplateAreasTokenNullCell", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenNullCell:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "GridTemplateAreasTokenTrash", + "canonicalReference": "@csstools/css-tokenizer!GridTemplateAreasTokenTrash:interface" + }, + { + "kind": "Content", + "text": ">" + }, + { + "kind": "Content", + "text": ";" + } + ], + "fileUrlPath": "dist/_types/tokenize-grid-template-areas.d.ts", + "returnTypeTokenRange": { + "startIndex": 3, + "endIndex": 11 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "input", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "isOptional": false + } + ], + "name": "tokenizeGridTemplateAreas" + }, { "kind": "Function", "canonicalReference": "@csstools/css-tokenizer!tokenizer:function(1)", @@ -5635,6 +5931,86 @@ } ] }, + { + "kind": "Enum", + "canonicalReference": "@csstools/css-tokenizer!TokenTypeGridTemplateAreas:enum", + "docComment": "/**\n * All possible CSS token types for grid template areas\n *\n * @see\n *\n * {@link https://drafts.csswg.org/css-grid/#valdef-grid-template-areas-string}\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare enum TokenTypeGridTemplateAreas " + } + ], + "fileUrlPath": "dist/_types/interfaces/token-grid-template-areas.d.ts", + "releaseTag": "Public", + "name": "TokenTypeGridTemplateAreas", + "preserveMemberOrder": false, + "members": [ + { + "kind": "EnumMember", + "canonicalReference": "@csstools/css-tokenizer!TokenTypeGridTemplateAreas.NamedCell:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "NamedCell = " + }, + { + "kind": "Content", + "text": "\"named-cell-token\"" + } + ], + "initializerTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "releaseTag": "Public", + "name": "NamedCell" + }, + { + "kind": "EnumMember", + "canonicalReference": "@csstools/css-tokenizer!TokenTypeGridTemplateAreas.NullCell:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "NullCell = " + }, + { + "kind": "Content", + "text": "\"null-cell-token\"" + } + ], + "initializerTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "releaseTag": "Public", + "name": "NullCell" + }, + { + "kind": "EnumMember", + "canonicalReference": "@csstools/css-tokenizer!TokenTypeGridTemplateAreas.Trash:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "Trash = " + }, + { + "kind": "Content", + "text": "\"trash-token\"" + } + ], + "initializerTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "releaseTag": "Public", + "name": "Trash" + } + ] + }, { "kind": "Interface", "canonicalReference": "@csstools/css-tokenizer!TokenUnicodeRange:interface", diff --git a/packages/css-tokenizer/src/index.ts b/packages/css-tokenizer/src/index.ts index c28cc7fd9..96940e135 100644 --- a/packages/css-tokenizer/src/index.ts +++ b/packages/css-tokenizer/src/index.ts @@ -112,3 +112,16 @@ export { isTokenWhitespace, isTokenWhiteSpaceOrComment, } from './util/type-predicates'; + +// Grid template areas +export { tokenizeGridTemplateAreas } from './tokenize-grid-template-areas'; + +export { + TokenTypeGridTemplateAreas, +} from './interfaces/token-grid-template-areas'; + +export type { + GridTemplateAreasTokenNamedCell, + GridTemplateAreasTokenNullCell, + GridTemplateAreasTokenTrash +} from './interfaces/token-grid-template-areas'; diff --git a/packages/css-tokenizer/src/interfaces/token-grid-template-areas.ts b/packages/css-tokenizer/src/interfaces/token-grid-template-areas.ts new file mode 100644 index 000000000..30c95e791 --- /dev/null +++ b/packages/css-tokenizer/src/interfaces/token-grid-template-areas.ts @@ -0,0 +1,34 @@ +/** + * All possible CSS token types for grid template areas + * + * @see {@link https://drafts.csswg.org/css-grid/#valdef-grid-template-areas-string} + */ +export enum TokenTypeGridTemplateAreas { + NamedCell = 'named-cell-token', + NullCell = 'null-cell-token', + Trash = 'trash-token', +} + +export interface GridTemplateAreasTokenNamedCell { + type: TokenTypeGridTemplateAreas.NamedCell + /** + * The name of the cell + */ + value: string +} + +export interface GridTemplateAreasTokenNullCell { + type: TokenTypeGridTemplateAreas.NullCell + /** + * The dots representing the null cell + */ + value: string +} + +export interface GridTemplateAreasTokenTrash { + type: TokenTypeGridTemplateAreas.Trash + /** + * The incorrect cell value + */ + value: string +} diff --git a/packages/css-tokenizer/src/tokenize-grid-template-areas.ts b/packages/css-tokenizer/src/tokenize-grid-template-areas.ts new file mode 100644 index 000000000..a337c7253 --- /dev/null +++ b/packages/css-tokenizer/src/tokenize-grid-template-areas.ts @@ -0,0 +1,127 @@ +import { CARRIAGE_RETURN, CHARACTER_TABULATION, FORM_FEED, FULL_STOP, LINE_FEED, NULL, REPLACEMENT_CHARACTER, SPACE } from "./code-points/code-points"; +import { isIdentCodePoint, isSurrogate, isWhitespace } from "./code-points/ranges"; +import type { CodePointReader } from "./interfaces/code-point-reader"; +import type { GridTemplateAreasTokenNamedCell, GridTemplateAreasTokenNullCell, GridTemplateAreasTokenTrash } from "./interfaces/token-grid-template-areas"; +import { TokenTypeGridTemplateAreas } from "./interfaces/token-grid-template-areas"; +import { Reader } from "./reader"; + +/** + * Tokenize a CSS string describing grid template areas into a list of tokens. + */ +export function tokenizeGridTemplateAreas(input: { valueOf(): string }): Array { + const tokens: Array = []; + const reader = new Reader(input.valueOf()); + + TOKENIZER_LOOP: + while (true) { + reader.resetRepresentation(); + + const peeked = reader.source.codePointAt(reader.cursor); + if (typeof peeked === "undefined") { + break; + } + + switch (peeked) { + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + case CHARACTER_TABULATION: + case SPACE: + consumeWhiteSpace(reader); + continue TOKENIZER_LOOP; + + case FULL_STOP: + tokens.push(consumeNullCell(reader)); + continue TOKENIZER_LOOP; + + default: + if (peeked === NULL || isSurrogate(peeked) || isIdentCodePoint(peeked)) { + tokens.push(consumeNamedCell(reader)); + continue TOKENIZER_LOOP; + } + + tokens.push(consumeTrash(reader)); + continue TOKENIZER_LOOP; + } + } + + return tokens; +} + +export function consumeNamedCell(reader: CodePointReader): GridTemplateAreasTokenNamedCell { + const codePoints: Array = []; + + while (true) { + const codePoint = reader.source.codePointAt(reader.cursor) ?? -1; + if (codePoint === NULL || isSurrogate(codePoint)) { + codePoints.push(REPLACEMENT_CHARACTER); + reader.advanceCodePoint(1 + +(codePoint > 0xffff)); + continue; + } + + if (isIdentCodePoint(codePoint)) { + codePoints.push(codePoint); + reader.advanceCodePoint(1 + +(codePoint > 0xffff)); + continue; + } + + break; + } + + return { + type: TokenTypeGridTemplateAreas.NamedCell, + value: String.fromCodePoint(...codePoints), + } +} + +function consumeNullCell(reader: CodePointReader): GridTemplateAreasTokenNullCell { + while (reader.source.codePointAt(reader.cursor) === FULL_STOP) { + reader.advanceCodePoint(); + } + + return { + type: TokenTypeGridTemplateAreas.NullCell, + value: reader.source.slice(reader.representationStart, reader.representationEnd + 1), + }; +} + +function consumeWhiteSpace(reader: CodePointReader): void { + while (isWhitespace(reader.source.codePointAt(reader.cursor) ?? -1)) { + reader.advanceCodePoint(); + } +} + +export function consumeTrash(reader: CodePointReader): GridTemplateAreasTokenTrash { + reader.advanceCodePoint(); + + TOKENIZER_LOOP: + while (true) { + const peeked = reader.source.codePointAt(reader.cursor); + if (typeof peeked === "undefined") { + break TOKENIZER_LOOP; + } + + switch (peeked) { + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + case CHARACTER_TABULATION: + case SPACE: + case FULL_STOP: + case NULL: + break TOKENIZER_LOOP; + default: + if (isSurrogate(peeked) || isIdentCodePoint(peeked)) { + break TOKENIZER_LOOP; + } + + reader.advanceCodePoint(); + continue TOKENIZER_LOOP; + } + } + + return { + type: TokenTypeGridTemplateAreas.Trash, + value: reader.source.slice(reader.representationStart, reader.representationEnd + 1), + }; +} diff --git a/packages/css-tokenizer/test/test.mjs b/packages/css-tokenizer/test/test.mjs index 9c5dafb72..15b2359c8 100644 --- a/packages/css-tokenizer/test/test.mjs +++ b/packages/css-tokenizer/test/test.mjs @@ -43,3 +43,6 @@ import './mutations/dimension.mjs'; // Keep this as the last test, // it is only intended to increase test coverage by double checking more obscure cases. import './css-tokenizer-tests/test.mjs'; + +// Tokens Grid Template Areas +import './token-grid-template-areas/basic.mjs'; diff --git a/packages/css-tokenizer/test/token-grid-template-areas/basic.mjs b/packages/css-tokenizer/test/token-grid-template-areas/basic.mjs new file mode 100644 index 000000000..1c565027c --- /dev/null +++ b/packages/css-tokenizer/test/token-grid-template-areas/basic.mjs @@ -0,0 +1,108 @@ +import { tokenizeGridTemplateAreas, tokenize, isTokenString } from '@csstools/css-tokenizer'; +import assert from 'node:assert'; + +function tokenizeFromSource(source) { + const t = tokenize({ css: source }); + const firstString = t.find(isTokenString); + if (!firstString) { + return []; + } + + return tokenizeGridTemplateAreas(firstString[4].value); +} + +{ + assert.deepEqual( + tokenizeFromSource('"a a"'), + [ + { type: 'named-cell-token', value: 'a' }, + { type: 'named-cell-token', value: 'a' }, + ], + ); +} + +{ + assert.deepEqual( + tokenizeFromSource('"a"'), + [{ type: 'named-cell-token', value: 'a' }], + ); +} + +{ + assert.deepEqual( + tokenizeFromSource('"."'), + [{ type: 'null-cell-token', value: '.' }], + ); +} + +{ + assert.deepEqual( + tokenizeFromSource('"..."'), + [{ type: 'null-cell-token', value: '...' }], + ); +} + +{ + assert.deepEqual( + tokenizeFromSource('"@ a"'), + [ + { type: 'trash-token', value: '@' }, + { type: 'named-cell-token', value: 'a' }, + ], + ); +} + +{ + assert.deepEqual( + // Unescaped, so bad string + tokenizeFromSource('"a\nb"'), + [], + ); +} + +{ + assert.deepEqual( + // Escaped, so regular string + tokenizeFromSource('"a\\\nb"'), + [{ type: 'named-cell-token', value: 'ab' }], + ); +} + +{ + assert.deepEqual( + // Escaped, so regular string + tokenizeFromSource('"a\\\n b"'), + [ + { type: 'named-cell-token', value: 'a' }, + { type: 'named-cell-token', value: 'b' }, + ], + ); +} + +{ + assert.deepEqual( + tokenizeFromSource('"a\\\\"'), + [ + { type: 'named-cell-token', value: 'a' }, + { type: 'trash-token', value: '\\' }, + ], + ); +} + +{ + assert.deepEqual( + tokenizeFromSource('"tu\\0U"'), + [{ type: 'named-cell-token', value: 'tu�U' }], + ); +} + +{ + assert.deepEqual( + tokenizeFromSource('"tu\\\\0U"'), + [ + { type: 'named-cell-token', value: 'tu' }, + { type: 'trash-token', value: '\\' }, + { type: 'named-cell-token', value: '0U' }, + ], + ); +}