From 4190bfd2e87ee1e85f09fc7285baf8021482b9ce Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 24 Dec 2022 11:44:56 +0100 Subject: [PATCH 01/24] css-parser-algorithms : fix unclosed blocks and functions --- packages/css-parser-algorithms/CHANGELOG.md | 1 + .../consume-component-block-function.d.ts | 19 +-- packages/css-parser-algorithms/dist/index.cjs | 2 +- .../css-parser-algorithms/dist/index.d.ts | 2 +- packages/css-parser-algorithms/dist/index.mjs | 2 +- .../dist/util/type-predicates.d.ts | 4 +- .../consume-component-block-function.ts | 77 +++++------ packages/css-parser-algorithms/src/index.ts | 2 - .../src/util/type-predicates.ts | 10 +- .../cases/wpt/0001.list-comma.expect.json | 48 +++++++ .../cases/wpt/0001.list-space.expect.json | 46 +++++++ .../test/cases/wpt/0001.mjs | 15 +++ packages/css-parser-algorithms/test/test.mjs | 2 + .../test/util/run-test.mjs | 6 +- packages/css-tokenizer/dist/index.cjs | 2 +- packages/css-tokenizer/dist/index.mjs | 2 +- packages/css-tokenizer/src/reader.ts | 3 +- .../css-tokenizer/test/test-stringify.mjs | 8 ++ packages/css-tokenizer/test/test.mjs | 13 ++ packages/css-tokenizer/test/token/url.mjs | 46 +++++++ .../test/wpt/cdc-vs-ident-tokens.mjs | 28 ++++ .../test/wpt/decimal-points-in-numbers.mjs | 102 +++++++++++++++ .../test/wpt/ident-three-code-points.mjs | 121 ++++++++++++++++++ .../test/wpt/inclusive-ranges.mjs | 97 ++++++++++++++ .../test/api/options.mjs | 38 +++++- 25 files changed, 611 insertions(+), 85 deletions(-) create mode 100644 packages/css-parser-algorithms/test/cases/wpt/0001.list-comma.expect.json create mode 100644 packages/css-parser-algorithms/test/cases/wpt/0001.list-space.expect.json create mode 100644 packages/css-parser-algorithms/test/cases/wpt/0001.mjs create mode 100644 packages/css-tokenizer/test/test-stringify.mjs create mode 100644 packages/css-tokenizer/test/wpt/cdc-vs-ident-tokens.mjs create mode 100644 packages/css-tokenizer/test/wpt/decimal-points-in-numbers.mjs create mode 100644 packages/css-tokenizer/test/wpt/ident-three-code-points.mjs create mode 100644 packages/css-tokenizer/test/wpt/inclusive-ranges.mjs diff --git a/packages/css-parser-algorithms/CHANGELOG.md b/packages/css-parser-algorithms/CHANGELOG.md index 6e25f75aa..46cbcc0cb 100644 --- a/packages/css-parser-algorithms/CHANGELOG.md +++ b/packages/css-parser-algorithms/CHANGELOG.md @@ -1,5 +1,6 @@ ### Unreleased +- Fix: Removes `UnclosedFunctionNode` and `UnclosedSimpleBlockNode`. (breaking) - Fix: Do not discard empty items in comma separated lists. ### 1.0.0 (November 14, 2022) diff --git a/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts b/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts index 24e87f789..7c8c9b67c 100644 --- a/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts +++ b/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts @@ -2,7 +2,7 @@ import { CSSToken, TokenFunction } from '@csstools/css-tokenizer'; import { Context } from '../interfaces/context'; import { ComponentValueType } from '../util/component-value-type'; export type ContainerNode = FunctionNode | SimpleBlockNode; -export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode | UnclosedSimpleBlockNode | UnclosedFunctionNode; +export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode | UnclosedFunctionNode; export declare function consumeComponentValue(ctx: Context, tokens: Array): { advance: number; node: ComponentValue; @@ -28,7 +28,7 @@ export declare class FunctionNode { } export declare function consumeFunction(ctx: Context, tokens: Array): { advance: number; - node: FunctionNode | UnclosedFunctionNode; + node: FunctionNode; }; export declare class SimpleBlockNode { type: ComponentValueType; @@ -51,7 +51,7 @@ export declare class SimpleBlockNode { /** https://www.w3.org/TR/css-syntax-3/#consume-simple-block */ export declare function consumeSimpleBlock(ctx: Context, tokens: Array): { advance: number; - node: SimpleBlockNode | UnclosedSimpleBlockNode; + node: SimpleBlockNode; }; export declare class WhitespaceNode { type: ComponentValueType; @@ -117,16 +117,3 @@ export declare class UnclosedFunctionNode { isUnclosedFunctionNode(): this is UnclosedFunctionNode; static isUnclosedFunctionNode(x: unknown): x is UnclosedFunctionNode; } -export declare class UnclosedSimpleBlockNode { - type: ComponentValueType; - value: Array; - constructor(value: Array); - tokens(): Array; - toString(): string; - toJSON(): { - type: ComponentValueType; - tokens: CSSToken[]; - }; - isUnclosedSimpleBlockNode(): this is UnclosedSimpleBlockNode; - static isUnclosedSimpleBlockNode(x: unknown): x is UnclosedSimpleBlockNode; -} diff --git a/packages/css-parser-algorithms/dist/index.cjs b/packages/css-parser-algorithms/dist/index.cjs index 2ad9b2515..7feba34ea 100644 --- a/packages/css-parser-algorithms/dist/index.cjs +++ b/packages/css-parser-algorithms/dist/index.cjs @@ -1 +1 @@ -"use strict";var e,n=require("@csstools/css-tokenizer");function consumeComponentValue(e,o){const t=o[0];if(t[0]===n.TokenType.OpenParen||t[0]===n.TokenType.OpenCurly||t[0]===n.TokenType.OpenSquare){const n=consumeSimpleBlock(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Function){const n=consumeFunction(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Whitespace){const n=consumeWhitespace(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Comment){const n=consumeComment(e,o);return{advance:n.advance,node:n.node}}return{advance:1,node:new TokenNode(t)}}exports.ComponentValueType=void 0,(e=exports.ComponentValueType||(exports.ComponentValueType={})).Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token",e.UnclosedFunction="unclosed-function",e.UnclosedSimpleBlock="unclosed-simple-block";class FunctionNode{type=exports.ComponentValueType.Function;name;endToken;value;constructor(e,n,o){this.name=e,this.endToken=n,this.value=o}nameTokenValue(){return this.name[4].value}tokens(){return[this.name,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.name)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===exports.ComponentValueType.Function)}}function consumeFunction(e,o){const t=[];let s=1;for(;;){const i=o[s];if(!i||i[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a function.",start:o[0][2],end:o[o.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:o.length,node:new UnclosedFunctionNode(o)};if(i[0]===n.TokenType.CloseParen)return{advance:s+1,node:new FunctionNode(o[0],i,t)};if(i[0]===n.TokenType.Comment||i[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(s));s+=n.advance,t.push(...n.nodes);continue}const c=consumeComponentValue(e,o.slice(s));s+=c.advance,t.push(c.node)}}class SimpleBlockNode{type=exports.ComponentValueType.SimpleBlock;startToken;endToken;value;constructor(e,n,o){this.startToken=e,this.endToken=n,this.value=o}tokens(){return[this.startToken,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.startToken)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===exports.ComponentValueType.SimpleBlock)}}function consumeSimpleBlock(e,o){const t=n.mirrorVariantType(o[0][0]);if(!t)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const s=[];let i=1;for(;;){const c=o[i];if(!c||c[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a simple block.",start:o[0][2],end:o[o.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:o.length,node:new UnclosedSimpleBlockNode(o)};if(c[0]===t)return{advance:i+1,node:new SimpleBlockNode(o[0],c,s)};if(c[0]===n.TokenType.Comment||c[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(i));i+=n.advance,s.push(...n.nodes);continue}const r=consumeComponentValue(e,o.slice(i));i+=r.advance,s.push(r.node)}}class WhitespaceNode{type=exports.ComponentValueType.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===exports.ComponentValueType.Whitespace)}}function consumeWhitespace(e,o){let t=0;for(;;){if(o[t][0]!==n.TokenType.Whitespace)return{advance:t,node:new WhitespaceNode(o.slice(0,t))};t++}}class CommentNode{type=exports.ComponentValueType.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===exports.ComponentValueType.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(e,o){const t=[];let s=0;for(;;)if(o[s][0]!==n.TokenType.Whitespace){if(o[s][0]!==n.TokenType.Comment)return{advance:s,nodes:t};t.push(new CommentNode(o[s])),s++}else{const e=consumeWhitespace(0,o.slice(s));s+=e.advance,t.push(e.node)}}class TokenNode{type=exports.ComponentValueType.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===exports.ComponentValueType.Token)}}class UnclosedFunctionNode{type=exports.ComponentValueType.UnclosedFunction;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedFunctionNode(){return UnclosedFunctionNode.isUnclosedFunctionNode(this)}static isUnclosedFunctionNode(e){return!!e&&(e instanceof UnclosedFunctionNode&&e.type===exports.ComponentValueType.UnclosedFunction)}}class UnclosedSimpleBlockNode{type=exports.ComponentValueType.UnclosedSimpleBlock;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedSimpleBlockNode(){return UnclosedSimpleBlockNode.isUnclosedSimpleBlockNode(this)}static isUnclosedSimpleBlockNode(e){return!!e&&(e instanceof UnclosedSimpleBlockNode&&e.type===exports.ComponentValueType.UnclosedSimpleBlock)}}exports.CommentNode=CommentNode,exports.FunctionNode=FunctionNode,exports.SimpleBlockNode=SimpleBlockNode,exports.TokenNode=TokenNode,exports.UnclosedFunctionNode=UnclosedFunctionNode,exports.UnclosedSimpleBlockNode=UnclosedSimpleBlockNode,exports.WhitespaceNode=WhitespaceNode,exports.consumeAllCommentsAndWhitespace=consumeAllCommentsAndWhitespace,exports.consumeComment=consumeComment,exports.consumeComponentValue=consumeComponentValue,exports.consumeFunction=consumeFunction,exports.consumeSimpleBlock=consumeSimpleBlock,exports.consumeWhitespace=consumeWhitespace,exports.gatherNodeAncestry=function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((o=>{n.set(o,e.parent)})):n.set(e.node,e.parent)})),n},exports.isCommentNode=function isCommentNode(e){return CommentNode.isCommentNode(e)},exports.isFunctionNode=function isFunctionNode(e){return FunctionNode.isFunctionNode(e)},exports.isSimpleBlockNode=function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)},exports.isTokenNode=function isTokenNode(e){return TokenNode.isTokenNode(e)},exports.isUnclosedFunctionNode=function isUnclosedFunctionNode(e){return UnclosedFunctionNode.isUnclosedFunctionNode(e)},exports.isUnclosedSimpleBlockNode=function isUnclosedSimpleBlockNode(e){return UnclosedSimpleBlockNode.isUnclosedSimpleBlockNode(e)},exports.isWhitespaceNode=function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)},exports.parseCommaSeparatedListOfComponentValues=function parseCommaSeparatedListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];if(0===e.length)return[];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let c=[],r=0;for(;;){if(!s[r]||s[r][0]===n.TokenType.EOF)return c.length&&i.push(c),i;if(s[r][0]===n.TokenType.Comma){i.push(c),c=[],r++;continue}const o=consumeComponentValue(t,e.slice(r));c.push(o.node),r+=o.advance}},exports.parseComponentValue=function parseComponentValue(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(t,s);if(s[Math.min(i.advance,s.length-1)][0]===n.TokenType.EOF)return i.node;t.onParseError({message:"Expected EOF after parsing a component value.",start:e[0][2],end:e[e.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})},exports.parseListOfComponentValues=function parseListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let c=0;for(;;){if(!s[c]||s[c][0]===n.TokenType.EOF)return i;const e=consumeComponentValue(t,s.slice(c));i.push(e.node),c+=e.advance}}; +"use strict";var e,n=require("@csstools/css-tokenizer");function consumeComponentValue(e,o){const t=o[0];if(t[0]===n.TokenType.OpenParen||t[0]===n.TokenType.OpenCurly||t[0]===n.TokenType.OpenSquare){const n=consumeSimpleBlock(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Function){const n=consumeFunction(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Whitespace){const n=consumeWhitespace(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Comment){const n=consumeComment(e,o);return{advance:n.advance,node:n.node}}return{advance:1,node:new TokenNode(t)}}exports.ComponentValueType=void 0,(e=exports.ComponentValueType||(exports.ComponentValueType={})).Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token",e.UnclosedFunction="unclosed-function",e.UnclosedSimpleBlock="unclosed-simple-block";class FunctionNode{type=exports.ComponentValueType.Function;name;endToken;value;constructor(e,n,o){this.name=e,this.endToken=n,this.value=o}nameTokenValue(){return this.name[4].value}tokens(){return this.endToken[0]===n.TokenType.EOF?[this.name,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens()))]:[this.name,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.name)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===exports.ComponentValueType.Function)}}function consumeFunction(e,o){const t=[];let s=1;for(;;){const i=o[s];if(!i||i[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a function.",start:o[0][2],end:o[o.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:o.length,node:new FunctionNode(o[0],i,t)};if(i[0]===n.TokenType.CloseParen)return{advance:s+1,node:new FunctionNode(o[0],i,t)};if(i[0]===n.TokenType.Comment||i[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(s));s+=n.advance,t.push(...n.nodes);continue}const r=consumeComponentValue(e,o.slice(s));s+=r.advance,t.push(r.node)}}class SimpleBlockNode{type=exports.ComponentValueType.SimpleBlock;startToken;endToken;value;constructor(e,n,o){this.startToken=e,this.endToken=n,this.value=o}tokens(){return this.endToken[0]===n.TokenType.EOF?[this.startToken,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens()))]:[this.startToken,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.startToken)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===exports.ComponentValueType.SimpleBlock)}}function consumeSimpleBlock(e,o){const t=n.mirrorVariantType(o[0][0]);if(!t)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const s=[];let i=1;for(;;){const r=o[i];if(!r||r[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a simple block.",start:o[0][2],end:o[o.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:o.length,node:new SimpleBlockNode(o[0],r,s)};if(r[0]===t)return{advance:i+1,node:new SimpleBlockNode(o[0],r,s)};if(r[0]===n.TokenType.Comment||r[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(i));i+=n.advance,s.push(...n.nodes);continue}const a=consumeComponentValue(e,o.slice(i));i+=a.advance,s.push(a.node)}}class WhitespaceNode{type=exports.ComponentValueType.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===exports.ComponentValueType.Whitespace)}}function consumeWhitespace(e,o){let t=0;for(;;){if(o[t][0]!==n.TokenType.Whitespace)return{advance:t,node:new WhitespaceNode(o.slice(0,t))};t++}}class CommentNode{type=exports.ComponentValueType.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===exports.ComponentValueType.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(e,o){const t=[];let s=0;for(;;)if(o[s][0]!==n.TokenType.Whitespace){if(o[s][0]!==n.TokenType.Comment)return{advance:s,nodes:t};t.push(new CommentNode(o[s])),s++}else{const e=consumeWhitespace(0,o.slice(s));s+=e.advance,t.push(e.node)}}class TokenNode{type=exports.ComponentValueType.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===exports.ComponentValueType.Token)}}class UnclosedFunctionNode{type=exports.ComponentValueType.UnclosedFunction;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedFunctionNode(){return UnclosedFunctionNode.isUnclosedFunctionNode(this)}static isUnclosedFunctionNode(e){return!!e&&(e instanceof UnclosedFunctionNode&&e.type===exports.ComponentValueType.UnclosedFunction)}}exports.CommentNode=CommentNode,exports.FunctionNode=FunctionNode,exports.SimpleBlockNode=SimpleBlockNode,exports.TokenNode=TokenNode,exports.UnclosedFunctionNode=UnclosedFunctionNode,exports.WhitespaceNode=WhitespaceNode,exports.consumeAllCommentsAndWhitespace=consumeAllCommentsAndWhitespace,exports.consumeComment=consumeComment,exports.consumeComponentValue=consumeComponentValue,exports.consumeFunction=consumeFunction,exports.consumeSimpleBlock=consumeSimpleBlock,exports.consumeWhitespace=consumeWhitespace,exports.gatherNodeAncestry=function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((o=>{n.set(o,e.parent)})):n.set(e.node,e.parent)})),n},exports.isCommentNode=function isCommentNode(e){return CommentNode.isCommentNode(e)},exports.isFunctionNode=function isFunctionNode(e){return FunctionNode.isFunctionNode(e)},exports.isSimpleBlockNode=function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)},exports.isTokenNode=function isTokenNode(e){return TokenNode.isTokenNode(e)},exports.isWhitespaceNode=function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)},exports.parseCommaSeparatedListOfComponentValues=function parseCommaSeparatedListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];if(0===e.length)return[];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let r=[],a=0;for(;;){if(!s[a]||s[a][0]===n.TokenType.EOF)return r.length&&i.push(r),i;if(s[a][0]===n.TokenType.Comma){i.push(r),r=[],a++;continue}const o=consumeComponentValue(t,e.slice(a));r.push(o.node),a+=o.advance}},exports.parseComponentValue=function parseComponentValue(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(t,s);if(s[Math.min(i.advance,s.length-1)][0]===n.TokenType.EOF)return i.node;t.onParseError({message:"Expected EOF after parsing a component value.",start:e[0][2],end:e[e.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})},exports.parseListOfComponentValues=function parseListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let r=0;for(;;){if(!s[r]||s[r][0]===n.TokenType.EOF)return i;const e=consumeComponentValue(t,s.slice(r));i.push(e.node),r+=e.advance}}; diff --git a/packages/css-parser-algorithms/dist/index.d.ts b/packages/css-parser-algorithms/dist/index.d.ts index 5b32227e3..105855acd 100644 --- a/packages/css-parser-algorithms/dist/index.d.ts +++ b/packages/css-parser-algorithms/dist/index.d.ts @@ -5,4 +5,4 @@ export { parseCommaSeparatedListOfComponentValues } from './parse/parse-comma-se export { gatherNodeAncestry } from './util/node-ancestry'; export { ParserError } from './interfaces/error'; export { ComponentValueType } from './util/component-value-type'; -export { isCommentNode, isFunctionNode, isSimpleBlockNode, isTokenNode, isUnclosedFunctionNode, isUnclosedSimpleBlockNode, isWhitespaceNode, } from './util/type-predicates'; +export { isCommentNode, isFunctionNode, isSimpleBlockNode, isTokenNode, isWhitespaceNode, } from './util/type-predicates'; diff --git a/packages/css-parser-algorithms/dist/index.mjs b/packages/css-parser-algorithms/dist/index.mjs index cb6b5c249..c627eee41 100644 --- a/packages/css-parser-algorithms/dist/index.mjs +++ b/packages/css-parser-algorithms/dist/index.mjs @@ -1 +1 @@ -import{TokenType as e,isToken as n,stringify as o,mirrorVariantType as t}from"@csstools/css-tokenizer";var s;function consumeComponentValue(n,o){const t=o[0];if(t[0]===e.OpenParen||t[0]===e.OpenCurly||t[0]===e.OpenSquare){const e=consumeSimpleBlock(n,o);return{advance:e.advance,node:e.node}}if(t[0]===e.Function){const e=consumeFunction(n,o);return{advance:e.advance,node:e.node}}if(t[0]===e.Whitespace){const e=consumeWhitespace(n,o);return{advance:e.advance,node:e.node}}if(t[0]===e.Comment){const e=consumeComment(n,o);return{advance:e.advance,node:e.node}}return{advance:1,node:new TokenNode(t)}}!function(e){e.Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token",e.UnclosedFunction="unclosed-function",e.UnclosedSimpleBlock="unclosed-simple-block"}(s||(s={}));class FunctionNode{type=s.Function;name;endToken;value;constructor(e,n,o){this.name=e,this.endToken=n,this.value=o}nameTokenValue(){return this.name[4].value}tokens(){return[this.name,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?o(e):e.toString())).join("");return o(this.name)+e+o(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===s.Function)}}function consumeFunction(n,o){const t=[];let s=1;for(;;){const i=o[s];if(!i||i[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a function.",start:o[0][2],end:o[o.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:o.length,node:new UnclosedFunctionNode(o)};if(i[0]===e.CloseParen)return{advance:s+1,node:new FunctionNode(o[0],i,t)};if(i[0]===e.Comment||i[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,o.slice(s));s+=e.advance,t.push(...e.nodes);continue}const c=consumeComponentValue(n,o.slice(s));s+=c.advance,t.push(c.node)}}class SimpleBlockNode{type=s.SimpleBlock;startToken;endToken;value;constructor(e,n,o){this.startToken=e,this.endToken=n,this.value=o}tokens(){return[this.startToken,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?o(e):e.toString())).join("");return o(this.startToken)+e+o(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===s.SimpleBlock)}}function consumeSimpleBlock(n,o){const s=t(o[0][0]);if(!s)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const i=[];let c=1;for(;;){const t=o[c];if(!t||t[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a simple block.",start:o[0][2],end:o[o.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:o.length,node:new UnclosedSimpleBlockNode(o)};if(t[0]===s)return{advance:c+1,node:new SimpleBlockNode(o[0],t,i)};if(t[0]===e.Comment||t[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,o.slice(c));c+=e.advance,i.push(...e.nodes);continue}const r=consumeComponentValue(n,o.slice(c));c+=r.advance,i.push(r.node)}}class WhitespaceNode{type=s.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return o(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===s.Whitespace)}}function consumeWhitespace(n,o){let t=0;for(;;){if(o[t][0]!==e.Whitespace)return{advance:t,node:new WhitespaceNode(o.slice(0,t))};t++}}class CommentNode{type=s.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return o(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===s.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(n,o){const t=[];let s=0;for(;;)if(o[s][0]!==e.Whitespace){if(o[s][0]!==e.Comment)return{advance:s,nodes:t};t.push(new CommentNode(o[s])),s++}else{const e=consumeWhitespace(0,o.slice(s));s+=e.advance,t.push(e.node)}}class TokenNode{type=s.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return o(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===s.Token)}}class UnclosedFunctionNode{type=s.UnclosedFunction;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return o(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedFunctionNode(){return UnclosedFunctionNode.isUnclosedFunctionNode(this)}static isUnclosedFunctionNode(e){return!!e&&(e instanceof UnclosedFunctionNode&&e.type===s.UnclosedFunction)}}class UnclosedSimpleBlockNode{type=s.UnclosedSimpleBlock;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return o(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedSimpleBlockNode(){return UnclosedSimpleBlockNode.isUnclosedSimpleBlockNode(this)}static isUnclosedSimpleBlockNode(e){return!!e&&(e instanceof UnclosedSimpleBlockNode&&e.type===s.UnclosedSimpleBlock)}}function parseComponentValue(n,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(t,s);if(s[Math.min(i.advance,s.length-1)][0]===e.EOF)return i.node;t.onParseError({message:"Expected EOF after parsing a component value.",start:n[0][2],end:n[n.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})}function parseListOfComponentValues(n,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let c=0;for(;;){if(!s[c]||s[c][0]===e.EOF)return i;const n=consumeComponentValue(t,s.slice(c));i.push(n.node),c+=n.advance}}function parseCommaSeparatedListOfComponentValues(n,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...n];if(0===n.length)return[];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let c=[],r=0;for(;;){if(!s[r]||s[r][0]===e.EOF)return c.length&&i.push(c),i;if(s[r][0]===e.Comma){i.push(c),c=[],r++;continue}const o=consumeComponentValue(t,n.slice(r));c.push(o.node),r+=o.advance}}function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((o=>{n.set(o,e.parent)})):n.set(e.node,e.parent)})),n}function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)}function isFunctionNode(e){return FunctionNode.isFunctionNode(e)}function isUnclosedSimpleBlockNode(e){return UnclosedSimpleBlockNode.isUnclosedSimpleBlockNode(e)}function isUnclosedFunctionNode(e){return UnclosedFunctionNode.isUnclosedFunctionNode(e)}function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)}function isCommentNode(e){return CommentNode.isCommentNode(e)}function isTokenNode(e){return TokenNode.isTokenNode(e)}export{CommentNode,s as ComponentValueType,FunctionNode,SimpleBlockNode,TokenNode,UnclosedFunctionNode,UnclosedSimpleBlockNode,WhitespaceNode,consumeAllCommentsAndWhitespace,consumeComment,consumeComponentValue,consumeFunction,consumeSimpleBlock,consumeWhitespace,gatherNodeAncestry,isCommentNode,isFunctionNode,isSimpleBlockNode,isTokenNode,isUnclosedFunctionNode,isUnclosedSimpleBlockNode,isWhitespaceNode,parseCommaSeparatedListOfComponentValues,parseComponentValue,parseListOfComponentValues}; +import{TokenType as e,isToken as n,stringify as t,mirrorVariantType as o}from"@csstools/css-tokenizer";var s;function consumeComponentValue(n,t){const o=t[0];if(o[0]===e.OpenParen||o[0]===e.OpenCurly||o[0]===e.OpenSquare){const e=consumeSimpleBlock(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Function){const e=consumeFunction(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Whitespace){const e=consumeWhitespace(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Comment){const e=consumeComment(n,t);return{advance:e.advance,node:e.node}}return{advance:1,node:new TokenNode(o)}}!function(e){e.Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token",e.UnclosedFunction="unclosed-function",e.UnclosedSimpleBlock="unclosed-simple-block"}(s||(s={}));class FunctionNode{type=s.Function;name;endToken;value;constructor(e,n,t){this.name=e,this.endToken=n,this.value=t}nameTokenValue(){return this.name[4].value}tokens(){return this.endToken[0]===e.EOF?[this.name,...this.value.flatMap((e=>n(e)?e:e.tokens()))]:[this.name,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?t(e):e.toString())).join("");return t(this.name)+e+t(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((t,o)=>{n||(!1!==e({node:t,parent:this},o)?"walk"in t&&!1===t.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===s.Function)}}function consumeFunction(n,t){const o=[];let s=1;for(;;){const i=t[s];if(!i||i[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a function.",start:t[0][2],end:t[t.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:t.length,node:new FunctionNode(t[0],i,o)};if(i[0]===e.CloseParen)return{advance:s+1,node:new FunctionNode(t[0],i,o)};if(i[0]===e.Comment||i[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,t.slice(s));s+=e.advance,o.push(...e.nodes);continue}const a=consumeComponentValue(n,t.slice(s));s+=a.advance,o.push(a.node)}}class SimpleBlockNode{type=s.SimpleBlock;startToken;endToken;value;constructor(e,n,t){this.startToken=e,this.endToken=n,this.value=t}tokens(){return this.endToken[0]===e.EOF?[this.startToken,...this.value.flatMap((e=>n(e)?e:e.tokens()))]:[this.startToken,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?t(e):e.toString())).join("");return t(this.startToken)+e+t(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((t,o)=>{n||(!1!==e({node:t,parent:this},o)?"walk"in t&&!1===t.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===s.SimpleBlock)}}function consumeSimpleBlock(n,t){const s=o(t[0][0]);if(!s)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const i=[];let a=1;for(;;){const o=t[a];if(!o||o[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a simple block.",start:t[0][2],end:t[t.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:t.length,node:new SimpleBlockNode(t[0],o,i)};if(o[0]===s)return{advance:a+1,node:new SimpleBlockNode(t[0],o,i)};if(o[0]===e.Comment||o[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,t.slice(a));a+=e.advance,i.push(...e.nodes);continue}const c=consumeComponentValue(n,t.slice(a));a+=c.advance,i.push(c.node)}}class WhitespaceNode{type=s.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return t(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===s.Whitespace)}}function consumeWhitespace(n,t){let o=0;for(;;){if(t[o][0]!==e.Whitespace)return{advance:o,node:new WhitespaceNode(t.slice(0,o))};o++}}class CommentNode{type=s.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return t(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===s.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(n,t){const o=[];let s=0;for(;;)if(t[s][0]!==e.Whitespace){if(t[s][0]!==e.Comment)return{advance:s,nodes:o};o.push(new CommentNode(t[s])),s++}else{const e=consumeWhitespace(0,t.slice(s));s+=e.advance,o.push(e.node)}}class TokenNode{type=s.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return t(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===s.Token)}}class UnclosedFunctionNode{type=s.UnclosedFunction;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return t(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedFunctionNode(){return UnclosedFunctionNode.isUnclosedFunctionNode(this)}static isUnclosedFunctionNode(e){return!!e&&(e instanceof UnclosedFunctionNode&&e.type===s.UnclosedFunction)}}function parseComponentValue(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(o,s);if(s[Math.min(i.advance,s.length-1)][0]===e.EOF)return i.node;o.onParseError({message:"Expected EOF after parsing a component value.",start:n[0][2],end:n[n.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})}function parseListOfComponentValues(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let a=0;for(;;){if(!s[a]||s[a][0]===e.EOF)return i;const n=consumeComponentValue(o,s.slice(a));i.push(n.node),a+=n.advance}}function parseCommaSeparatedListOfComponentValues(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];if(0===n.length)return[];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let a=[],c=0;for(;;){if(!s[c]||s[c][0]===e.EOF)return a.length&&i.push(a),i;if(s[c][0]===e.Comma){i.push(a),a=[],c++;continue}const t=consumeComponentValue(o,n.slice(c));a.push(t.node),c+=t.advance}}function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((t=>{n.set(t,e.parent)})):n.set(e.node,e.parent)})),n}function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)}function isFunctionNode(e){return FunctionNode.isFunctionNode(e)}function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)}function isCommentNode(e){return CommentNode.isCommentNode(e)}function isTokenNode(e){return TokenNode.isTokenNode(e)}export{CommentNode,s as ComponentValueType,FunctionNode,SimpleBlockNode,TokenNode,UnclosedFunctionNode,WhitespaceNode,consumeAllCommentsAndWhitespace,consumeComment,consumeComponentValue,consumeFunction,consumeSimpleBlock,consumeWhitespace,gatherNodeAncestry,isCommentNode,isFunctionNode,isSimpleBlockNode,isTokenNode,isWhitespaceNode,parseCommaSeparatedListOfComponentValues,parseComponentValue,parseListOfComponentValues}; diff --git a/packages/css-parser-algorithms/dist/util/type-predicates.d.ts b/packages/css-parser-algorithms/dist/util/type-predicates.d.ts index 1cbf896d4..896d3036b 100644 --- a/packages/css-parser-algorithms/dist/util/type-predicates.d.ts +++ b/packages/css-parser-algorithms/dist/util/type-predicates.d.ts @@ -1,8 +1,6 @@ -import { CommentNode, FunctionNode, SimpleBlockNode, TokenNode, UnclosedFunctionNode, UnclosedSimpleBlockNode, WhitespaceNode } from '../consume/consume-component-block-function'; +import { CommentNode, FunctionNode, SimpleBlockNode, TokenNode, WhitespaceNode } from '../consume/consume-component-block-function'; export declare function isSimpleBlockNode(x: unknown): x is SimpleBlockNode; export declare function isFunctionNode(x: unknown): x is FunctionNode; -export declare function isUnclosedSimpleBlockNode(x: unknown): x is UnclosedSimpleBlockNode; -export declare function isUnclosedFunctionNode(x: unknown): x is UnclosedFunctionNode; export declare function isWhitespaceNode(x: unknown): x is WhitespaceNode; export declare function isCommentNode(x: unknown): x is CommentNode; export declare function isTokenNode(x: unknown): x is TokenNode; diff --git a/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts b/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts index 726b51843..62a91496e 100644 --- a/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts +++ b/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts @@ -4,7 +4,7 @@ import { ComponentValueType } from '../util/component-value-type'; export type ContainerNode = FunctionNode | SimpleBlockNode; -export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode | UnclosedSimpleBlockNode | UnclosedFunctionNode; +export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode | UnclosedFunctionNode; // https://www.w3.org/TR/css-syntax-3/#consume-a-component-value export function consumeComponentValue(ctx: Context, tokens: Array): { advance: number, node: ComponentValue } { @@ -69,6 +69,19 @@ export class FunctionNode { } tokens(): Array { + if (this.endToken[0] === TokenType.EOF) { + return [ + this.name, + ...this.value.flatMap((x) => { + if (isToken(x)) { + return x; + } + + return x.tokens(); + }), + ]; + } + return [ this.name, ...this.value.flatMap((x) => { @@ -160,7 +173,7 @@ export class FunctionNode { } // https://www.w3.org/TR/css-syntax-3/#consume-function -export function consumeFunction(ctx: Context, tokens: Array): { advance: number, node: FunctionNode | UnclosedFunctionNode } { +export function consumeFunction(ctx: Context, tokens: Array): { advance: number, node: FunctionNode } { const value: Array = []; let i = 1; @@ -181,7 +194,7 @@ export function consumeFunction(ctx: Context, tokens: Array): { advanc return { advance: tokens.length, - node: new UnclosedFunctionNode(tokens), + node: new FunctionNode(tokens[0] as TokenFunction, token, value), }; } @@ -219,6 +232,19 @@ export class SimpleBlockNode { } tokens(): Array { + if (this.endToken[0] === TokenType.EOF) { + return [ + this.startToken, + ...this.value.flatMap((x) => { + if (isToken(x)) { + return x; + } + + return x.tokens(); + }), + ]; + } + return [ this.startToken, ...this.value.flatMap((x) => { @@ -310,7 +336,7 @@ export class SimpleBlockNode { } /** https://www.w3.org/TR/css-syntax-3/#consume-simple-block */ -export function consumeSimpleBlock(ctx: Context, tokens: Array): { advance: number, node: SimpleBlockNode | UnclosedSimpleBlockNode } { +export function consumeSimpleBlock(ctx: Context, tokens: Array): { advance: number, node: SimpleBlockNode } { const endingTokenType = mirrorVariantType(tokens[0][0]); if (!endingTokenType) { throw new Error('Failed to parse, a mirror variant must exist for all block open tokens.'); @@ -336,7 +362,7 @@ export function consumeSimpleBlock(ctx: Context, tokens: Array): { adv return { advance: tokens.length, - node: new UnclosedSimpleBlockNode(tokens), + node: new SimpleBlockNode(tokens[0], token, value), }; } @@ -578,44 +604,3 @@ export class UnclosedFunctionNode { return x.type === ComponentValueType.UnclosedFunction; } } - -export class UnclosedSimpleBlockNode { - type: ComponentValueType = ComponentValueType.UnclosedSimpleBlock; - - value: Array; - - constructor(value: Array) { - this.value = value; - } - - tokens(): Array { - return this.value; - } - - toString(): string { - return stringify(...this.value); - } - - toJSON() { - return { - type: this.type, - tokens: this.tokens(), - }; - } - - isUnclosedSimpleBlockNode(): this is UnclosedSimpleBlockNode { - return UnclosedSimpleBlockNode.isUnclosedSimpleBlockNode(this); - } - - static isUnclosedSimpleBlockNode(x: unknown): x is UnclosedSimpleBlockNode { - if (!x) { - return false; - } - - if (!(x instanceof UnclosedSimpleBlockNode)) { - return false; - } - - return x.type === ComponentValueType.UnclosedSimpleBlock; - } -} diff --git a/packages/css-parser-algorithms/src/index.ts b/packages/css-parser-algorithms/src/index.ts index 5bb92c097..bcd257b39 100644 --- a/packages/css-parser-algorithms/src/index.ts +++ b/packages/css-parser-algorithms/src/index.ts @@ -10,7 +10,5 @@ export { isFunctionNode, isSimpleBlockNode, isTokenNode, - isUnclosedFunctionNode, - isUnclosedSimpleBlockNode, isWhitespaceNode, } from './util/type-predicates'; diff --git a/packages/css-parser-algorithms/src/util/type-predicates.ts b/packages/css-parser-algorithms/src/util/type-predicates.ts index a5cb96eda..79ec240e5 100644 --- a/packages/css-parser-algorithms/src/util/type-predicates.ts +++ b/packages/css-parser-algorithms/src/util/type-predicates.ts @@ -1,4 +1,4 @@ -import { CommentNode, FunctionNode, SimpleBlockNode, TokenNode, UnclosedFunctionNode, UnclosedSimpleBlockNode, WhitespaceNode } from '../consume/consume-component-block-function'; +import { CommentNode, FunctionNode, SimpleBlockNode, TokenNode, WhitespaceNode } from '../consume/consume-component-block-function'; export function isSimpleBlockNode(x: unknown): x is SimpleBlockNode { return SimpleBlockNode.isSimpleBlockNode(x); @@ -8,14 +8,6 @@ export function isFunctionNode(x: unknown): x is FunctionNode { return FunctionNode.isFunctionNode(x); } -export function isUnclosedSimpleBlockNode(x: unknown): x is UnclosedSimpleBlockNode { - return UnclosedSimpleBlockNode.isUnclosedSimpleBlockNode(x); -} - -export function isUnclosedFunctionNode(x: unknown): x is UnclosedFunctionNode { - return UnclosedFunctionNode.isUnclosedFunctionNode(x); -} - export function isWhitespaceNode(x: unknown): x is WhitespaceNode { return WhitespaceNode.isWhitespaceNode(x); } diff --git a/packages/css-parser-algorithms/test/cases/wpt/0001.list-comma.expect.json b/packages/css-parser-algorithms/test/cases/wpt/0001.list-comma.expect.json new file mode 100644 index 000000000..88632bb58 --- /dev/null +++ b/packages/css-parser-algorithms/test/cases/wpt/0001.list-comma.expect.json @@ -0,0 +1,48 @@ +[ + [ + { + "type": "simple-block", + "startToken": [ + "[-token", + "[", + 0, + 0, + null + ], + "tokens": [ + [ + "[-token", + "[", + 0, + 0, + null + ], + [ + "ident-token", + "foo", + 1, + 3, + { + "value": "foo" + } + ] + ], + "value": [ + { + "type": "token", + "tokens": [ + [ + "ident-token", + "foo", + 1, + 3, + { + "value": "foo" + } + ] + ] + } + ] + } + ] +] \ No newline at end of file diff --git a/packages/css-parser-algorithms/test/cases/wpt/0001.list-space.expect.json b/packages/css-parser-algorithms/test/cases/wpt/0001.list-space.expect.json new file mode 100644 index 000000000..1c8119cee --- /dev/null +++ b/packages/css-parser-algorithms/test/cases/wpt/0001.list-space.expect.json @@ -0,0 +1,46 @@ +[ + { + "type": "simple-block", + "startToken": [ + "[-token", + "[", + 0, + 0, + null + ], + "tokens": [ + [ + "[-token", + "[", + 0, + 0, + null + ], + [ + "ident-token", + "foo", + 1, + 3, + { + "value": "foo" + } + ] + ], + "value": [ + { + "type": "token", + "tokens": [ + [ + "ident-token", + "foo", + 1, + 3, + { + "value": "foo" + } + ] + ] + } + ] + } +] \ No newline at end of file diff --git a/packages/css-parser-algorithms/test/cases/wpt/0001.mjs b/packages/css-parser-algorithms/test/cases/wpt/0001.mjs new file mode 100644 index 000000000..a68369f07 --- /dev/null +++ b/packages/css-parser-algorithms/test/cases/wpt/0001.mjs @@ -0,0 +1,15 @@ +import assert from 'assert'; +import { runTest } from '../../util/run-test.mjs'; + +// css/css-syntax/unclosed-constructs.html +runTest( + '[foo', + 'wpt/0001', + (actual, expected) => { + assert.deepStrictEqual( + actual, + expected, + ); + }, + true, +); diff --git a/packages/css-parser-algorithms/test/test.mjs b/packages/css-parser-algorithms/test/test.mjs index 2eef7a9a5..1d28110d3 100644 --- a/packages/css-parser-algorithms/test/test.mjs +++ b/packages/css-parser-algorithms/test/test.mjs @@ -36,3 +36,5 @@ import './cases/various/0017.mjs'; import './cases/various/0018.mjs'; import './cases/various/0019.mjs'; import './cases/various/0020.mjs'; + +import './cases/wpt/0001.mjs'; diff --git a/packages/css-parser-algorithms/test/util/run-test.mjs b/packages/css-parser-algorithms/test/util/run-test.mjs index 5d58211c9..525580a41 100644 --- a/packages/css-parser-algorithms/test/util/run-test.mjs +++ b/packages/css-parser-algorithms/test/util/run-test.mjs @@ -3,8 +3,12 @@ import path from 'path'; import { parseCommaSeparatedListOfComponentValues, parseListOfComponentValues } from '@csstools/css-parser-algorithms'; import { tokenizer } from '@csstools/css-tokenizer'; -export function runTest(source, testPath, assertEqual) { +export function runTest(source, testPath, assertEqual, expectParseError = false) { const onParseError = (err) => { + if (expectParseError) { + return; + } + console.warn(err); throw new Error(`Unable to parse "${source}"`); }; diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index 0b87d2cd1..3d74b8b55 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1 @@ -"use strict";class Reader{#e;#t="";#n=[];#o=0;#r=0;#i=-1;constructor(e){this.#e=0,this.#t=e,this.#o=e.length;for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===v)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===k)}function isNewLine(e){switch(e){case y:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case y:case s:case h:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){const n=t.peekTwoCodePoints();return n[0]===L&&n[1]!==y}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===k?r===k||(!!isIdentStartCodePoint(r)||r===L&&i!==y):!!isIdentStartCodePoint(o)||o===L&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===U||o===k?!!isDigitCodePoint(r)||r===P&&isDigitCodePoint(i):o===P?isDigitCodePoint(r):!!isDigitCodePoint(o)}function checkIfTwoCodePointsStartAComment(e,t){const n=t.peekTwoCodePoints();return n[0]===B&&n[1]===r}function checkIfThreeCodePointsWouldStartCDC(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===k&&r===k&&i===T}function consumeComment(e,t){for(t.readCodePoint(),t.readCodePoint();;){const n=t.readCodePoint();if(!1===n){const n=t.representation();e.onParseError({message:"Unexpected EOF while consuming a comment.",start:n[0],end:n[1],state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(n!==r)continue;const o=t.peekOneCodePoint();if(!1!==o&&o===B){t.readCodePoint();break}}const n=t.representation();return[exports.TokenType.Comment,t.representationString(),n[0],n[1],void 0]}function codePointsToString(e){let t="";for(let n=0;nO?b:i}var o;return n}function consumeIdentSequence(e,t){const n=[];for(;;){const o=t.peekOneCodePoint();if(!1===o)return n;if(isIdentCodePoint(o))t.readCodePoint(),n.push(o);else{if(o!==L||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(e,t){t.readCodePoint();const o=t.peekOneCodePoint();if(!1!==o&&isIdentCodePoint(o)||checkIfTwoCodePointsAreAValidEscape(0,t)){let o=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,t)&&(o=n.ID);const r=consumeIdentSequence(e,t),i=t.representation();return[exports.TokenType.Hash,t.representationString(),i[0],i[1],{value:codePointsToString(r),type:o}]}const r=t.representation();return[exports.TokenType.Delim,t.representationString(),r[0],r[1],{value:"#"}]}function consumeNumber(e,t){let n=exports.NumberType.Integer;const o=[];{const e=t.peekOneCodePoint();e!==U&&e!==k||(t.readCodePoint(),o.push(e));const n=consumeDigits(t);for(let e=0;e{})};return{nextToken:function nextToken(){if(r.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,r)){if(null!=t&&t.commentsAreTokens)return consumeComment(i,r);consumeComment(i,r)}r.resetRepresentation();const e=r.peekOneCodePoint();if(!1===e)return[exports.TokenType.EOF,"",-1,-1,void 0];switch(e){case d:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Comma,r.representationString(),e[0],e[1],void 0]}case a:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Colon,r.representationString(),e[0],e[1],void 0]}case q:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Semicolon,r.representationString(),e[0],e[1],void 0]}case S:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenParen,r.representationString(),e[0],e[1],void 0]}case W:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseParen,r.representationString(),e[0],e[1],void 0]}case A:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenSquare,r.representationString(),e[0],e[1],void 0]}case F:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseSquare,r.representationString(),e[0],e[1],void 0]}case g:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenCurly,r.representationString(),e[0],e[1],void 0]}case R:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseCurly,r.representationString(),e[0],e[1],void 0]}}switch(e){case o:case N:return consumeStringToken(i,r);case w:return consumeHashToken(i,r);case U:case P:{if(checkIfThreeCodePointsWouldStartANumber(0,r))return consumeNumericToken(i,r);r.readCodePoint();const t=r.representation();return[exports.TokenType.Delim,r.representationString(),t[0],t[1],{value:String.fromCharCode(e)}]}case k:{if(checkIfThreeCodePointsWouldStartANumber(0,r))return consumeNumericToken(i,r);if(checkIfThreeCodePointsWouldStartCDC(0,r)){r.readCodePoint(),r.readCodePoint(),r.readCodePoint();const e=r.representation();return[exports.TokenType.CDC,r.representationString(),e[0],e[1],void 0]}if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,r))return consumeIdentLikeToken(i,r);r.readCodePoint();const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"-"}]}case x:{if(checkIfFourCodePointsWouldStartCDO(0,r)){r.readCodePoint(),r.readCodePoint(),r.readCodePoint(),r.readCodePoint();const e=r.representation();return[exports.TokenType.CDO,r.representationString(),e[0],e[1],void 0]}r.readCodePoint();const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"<"}]}case u:{if(r.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)){const e=consumeIdentSequence(i,r),t=r.representation();return[exports.TokenType.AtKeyword,r.representationString(),t[0],t[1],{value:codePointsToString(e)}]}const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"@"}]}case L:{if(checkIfTwoCodePointsAreAValidEscape(0,r))return consumeIdentLikeToken(i,r);r.readCodePoint();const e=r.representation();return i.onParseError({message:'Invalid escape sequence after "\\"',start:e[0],end:e[1],state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"\\"}]}}if(isWhitespace(e))return consumeWhiteSpace(0,r);if(isDigitCodePoint(e))return consumeNumericToken(i,r);if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,r);r.readCodePoint();const n=r.representation();return[exports.TokenType.Delim,r.representationString(),n[0],n[1],{value:String.fromCharCode(e)}]},endOfFile:function endOfFile(){return!1===r.peekOneCodePoint()}}}; +"use strict";class Reader{#e;#t="";#n=[];#o=0;#r=0;#i=-1;constructor(e){this.#e=0,this.#t=e,this.#o=e.length,this.#n=new Array(this.#o);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===v)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===k)}function isNewLine(e){switch(e){case y:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case y:case s:case h:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){const n=t.peekTwoCodePoints();return n[0]===L&&n[1]!==y}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===k?r===k||(!!isIdentStartCodePoint(r)||r===L&&i!==y):!!isIdentStartCodePoint(o)||o===L&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===U||o===k?!!isDigitCodePoint(r)||r===P&&isDigitCodePoint(i):o===P?isDigitCodePoint(r):!!isDigitCodePoint(o)}function checkIfTwoCodePointsStartAComment(e,t){const n=t.peekTwoCodePoints();return n[0]===B&&n[1]===r}function checkIfThreeCodePointsWouldStartCDC(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===k&&r===k&&i===T}function consumeComment(e,t){for(t.readCodePoint(),t.readCodePoint();;){const n=t.readCodePoint();if(!1===n){const n=t.representation();e.onParseError({message:"Unexpected EOF while consuming a comment.",start:n[0],end:n[1],state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(n!==r)continue;const o=t.peekOneCodePoint();if(!1!==o&&o===B){t.readCodePoint();break}}const n=t.representation();return[exports.TokenType.Comment,t.representationString(),n[0],n[1],void 0]}function codePointsToString(e){let t="";for(let n=0;nO?b:i}var o;return n}function consumeIdentSequence(e,t){const n=[];for(;;){const o=t.peekOneCodePoint();if(!1===o)return n;if(isIdentCodePoint(o))t.readCodePoint(),n.push(o);else{if(o!==L||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(e,t){t.readCodePoint();const o=t.peekOneCodePoint();if(!1!==o&&isIdentCodePoint(o)||checkIfTwoCodePointsAreAValidEscape(0,t)){let o=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,t)&&(o=n.ID);const r=consumeIdentSequence(e,t),i=t.representation();return[exports.TokenType.Hash,t.representationString(),i[0],i[1],{value:codePointsToString(r),type:o}]}const r=t.representation();return[exports.TokenType.Delim,t.representationString(),r[0],r[1],{value:"#"}]}function consumeNumber(e,t){let n=exports.NumberType.Integer;const o=[];{const e=t.peekOneCodePoint();e!==U&&e!==k||(t.readCodePoint(),o.push(e));const n=consumeDigits(t);for(let e=0;e{})};return{nextToken:function nextToken(){if(r.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,r)){if(null!=t&&t.commentsAreTokens)return consumeComment(i,r);consumeComment(i,r)}r.resetRepresentation();const e=r.peekOneCodePoint();if(!1===e)return[exports.TokenType.EOF,"",-1,-1,void 0];switch(e){case d:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Comma,r.representationString(),e[0],e[1],void 0]}case a:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Colon,r.representationString(),e[0],e[1],void 0]}case q:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Semicolon,r.representationString(),e[0],e[1],void 0]}case S:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenParen,r.representationString(),e[0],e[1],void 0]}case W:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseParen,r.representationString(),e[0],e[1],void 0]}case A:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenSquare,r.representationString(),e[0],e[1],void 0]}case F:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseSquare,r.representationString(),e[0],e[1],void 0]}case g:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenCurly,r.representationString(),e[0],e[1],void 0]}case R:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseCurly,r.representationString(),e[0],e[1],void 0]}}switch(e){case o:case N:return consumeStringToken(i,r);case w:return consumeHashToken(i,r);case U:case P:{if(checkIfThreeCodePointsWouldStartANumber(0,r))return consumeNumericToken(i,r);r.readCodePoint();const t=r.representation();return[exports.TokenType.Delim,r.representationString(),t[0],t[1],{value:String.fromCharCode(e)}]}case k:{if(checkIfThreeCodePointsWouldStartANumber(0,r))return consumeNumericToken(i,r);if(checkIfThreeCodePointsWouldStartCDC(0,r)){r.readCodePoint(),r.readCodePoint(),r.readCodePoint();const e=r.representation();return[exports.TokenType.CDC,r.representationString(),e[0],e[1],void 0]}if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,r))return consumeIdentLikeToken(i,r);r.readCodePoint();const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"-"}]}case x:{if(checkIfFourCodePointsWouldStartCDO(0,r)){r.readCodePoint(),r.readCodePoint(),r.readCodePoint(),r.readCodePoint();const e=r.representation();return[exports.TokenType.CDO,r.representationString(),e[0],e[1],void 0]}r.readCodePoint();const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"<"}]}case u:{if(r.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)){const e=consumeIdentSequence(i,r),t=r.representation();return[exports.TokenType.AtKeyword,r.representationString(),t[0],t[1],{value:codePointsToString(e)}]}const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"@"}]}case L:{if(checkIfTwoCodePointsAreAValidEscape(0,r))return consumeIdentLikeToken(i,r);r.readCodePoint();const e=r.representation();return i.onParseError({message:'Invalid escape sequence after "\\"',start:e[0],end:e[1],state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"\\"}]}}if(isWhitespace(e))return consumeWhiteSpace(0,r);if(isDigitCodePoint(e))return consumeNumericToken(i,r);if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,r);r.readCodePoint();const n=r.representation();return[exports.TokenType.Delim,r.representationString(),n[0],n[1],{value:String.fromCharCode(e)}]},endOfFile:function endOfFile(){return!1===r.peekOneCodePoint()}}}; diff --git a/packages/css-tokenizer/dist/index.mjs b/packages/css-tokenizer/dist/index.mjs index a9c73e6e9..d8a660184 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1 +1 @@ -class Reader{#e;#t="";#n=[];#o=0;#r=0;#i=-1;constructor(e){this.#e=0,this.#t=e,this.#o=e.length;for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===E)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case v:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case v:case s:case h:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){const n=t.peekTwoCodePoints();return n[0]===W&&n[1]!==v}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===l?r===l||(!!isIdentStartCodePoint(r)||r===W&&i!==v):!!isIdentStartCodePoint(o)||o===W&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===N||o===l?!!isDigitCodePoint(r)||r===P&&isDigitCodePoint(i):o===P?isDigitCodePoint(r):!!isDigitCodePoint(o)}function checkIfTwoCodePointsStartAComment(e,t){const n=t.peekTwoCodePoints();return n[0]===B&&n[1]===r}function checkIfThreeCodePointsWouldStartCDC(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===l&&r===l&&i===f}function consumeComment(t,n){for(n.readCodePoint(),n.readCodePoint();;){const e=n.readCodePoint();if(!1===e){const e=n.representation();t.onParseError({message:"Unexpected EOF while consuming a comment.",start:e[0],end:e[1],state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e!==r)continue;const o=n.peekOneCodePoint();if(!1!==o&&o===B){n.readCodePoint();break}}const o=n.representation();return[e.Comment,n.representationString(),o[0],o[1],void 0]}function codePointsToString(e){let t="";for(let n=0;nw?R:i}var o;return n}function consumeIdentSequence(e,t){const n=[];for(;;){const o=t.peekOneCodePoint();if(!1===o)return n;if(isIdentCodePoint(o))t.readCodePoint(),n.push(o);else{if(o!==W||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(t,o){o.readCodePoint();const r=o.peekOneCodePoint();if(!1!==r&&isIdentCodePoint(r)||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=n.ID);const i=consumeIdentSequence(t,o),s=o.representation();return[e.Hash,o.representationString(),s[0],s[1],{value:codePointsToString(i),type:r}]}const i=o.representation();return[e.Delim,o.representationString(),i[0],i[1],{value:"#"}]}function consumeNumber(e,n){let o=t.Integer;const r=[];{const e=n.peekOneCodePoint();e!==N&&e!==l||(n.readCodePoint(),r.push(e));const t=consumeDigits(n);for(let e=0;e{})};return{nextToken:function nextToken(){if(i.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,i)){if(null!=n&&n.commentsAreTokens)return consumeComment(s,i);consumeComment(s,i)}i.resetRepresentation();const t=i.peekOneCodePoint();if(!1===t)return[e.EOF,"",-1,-1,void 0];switch(t){case d:{i.readCodePoint();const t=i.representation();return[e.Comma,i.representationString(),t[0],t[1],void 0]}case a:{i.readCodePoint();const t=i.representation();return[e.Colon,i.representationString(),t[0],t[1],void 0]}case x:{i.readCodePoint();const t=i.representation();return[e.Semicolon,i.representationString(),t[0],t[1],void 0]}case A:{i.readCodePoint();const t=i.representation();return[e.OpenParen,i.representationString(),t[0],t[1],void 0]}case F:{i.readCodePoint();const t=i.representation();return[e.CloseParen,i.representationString(),t[0],t[1],void 0]}case T:{i.readCodePoint();const t=i.representation();return[e.OpenSquare,i.representationString(),t[0],t[1],void 0]}case q:{i.readCodePoint();const t=i.representation();return[e.CloseSquare,i.representationString(),t[0],t[1],void 0]}case k:{i.readCodePoint();const t=i.representation();return[e.OpenCurly,i.representationString(),t[0],t[1],void 0]}case y:{i.readCodePoint();const t=i.representation();return[e.CloseCurly,i.representationString(),t[0],t[1],void 0]}}switch(t){case o:case b:return consumeStringToken(s,i);case U:return consumeHashToken(s,i);case N:case P:{if(checkIfThreeCodePointsWouldStartANumber(0,i))return consumeNumericToken(s,i);i.readCodePoint();const n=i.representation();return[e.Delim,i.representationString(),n[0],n[1],{value:String.fromCharCode(t)}]}case l:{if(checkIfThreeCodePointsWouldStartANumber(0,i))return consumeNumericToken(s,i);if(checkIfThreeCodePointsWouldStartCDC(0,i)){i.readCodePoint(),i.readCodePoint(),i.readCodePoint();const t=i.representation();return[e.CDC,i.representationString(),t[0],t[1],void 0]}if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,i))return consumeIdentLikeToken(s,i);i.readCodePoint();const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"-"}]}case I:{if(checkIfFourCodePointsWouldStartCDO(0,i)){i.readCodePoint(),i.readCodePoint(),i.readCodePoint(),i.readCodePoint();const t=i.representation();return[e.CDO,i.representationString(),t[0],t[1],void 0]}i.readCodePoint();const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"<"}]}case u:{if(i.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(s,i),n=i.representation();return[e.AtKeyword,i.representationString(),n[0],n[1],{value:codePointsToString(t)}]}const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"@"}]}case W:{if(checkIfTwoCodePointsAreAValidEscape(0,i))return consumeIdentLikeToken(s,i);i.readCodePoint();const t=i.representation();return s.onParseError({message:'Invalid escape sequence after "\\"',start:t[0],end:t[1],state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,i.representationString(),t[0],t[1],{value:"\\"}]}}if(isWhitespace(t))return consumeWhiteSpace(0,i);if(isDigitCodePoint(t))return consumeNumericToken(s,i);if(isIdentStartCodePoint(t))return consumeIdentLikeToken(s,i);i.readCodePoint();const r=i.representation();return[e.Delim,i.representationString(),r[0],r[1],{value:String.fromCharCode(t)}]},endOfFile:function endOfFile(){return!1===i.peekOneCodePoint()}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; +class Reader{#e;#t="";#n=[];#o=0;#r=0;#i=-1;constructor(e){this.#e=0,this.#t=e,this.#o=e.length,this.#n=new Array(this.#o);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===E)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case v:case s:case p:return!0;default:return!1}}function isWhitespace(e){switch(e){case v:case s:case p:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){const n=t.peekTwoCodePoints();return n[0]===W&&n[1]!==v}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===l?r===l||(!!isIdentStartCodePoint(r)||r===W&&i!==v):!!isIdentStartCodePoint(o)||o===W&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===N||o===l?!!isDigitCodePoint(r)||r===P&&isDigitCodePoint(i):o===P?isDigitCodePoint(r):!!isDigitCodePoint(o)}function checkIfTwoCodePointsStartAComment(e,t){const n=t.peekTwoCodePoints();return n[0]===B&&n[1]===r}function checkIfThreeCodePointsWouldStartCDC(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===l&&r===l&&i===f}function consumeComment(t,n){for(n.readCodePoint(),n.readCodePoint();;){const e=n.readCodePoint();if(!1===e){const e=n.representation();t.onParseError({message:"Unexpected EOF while consuming a comment.",start:e[0],end:e[1],state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e!==r)continue;const o=n.peekOneCodePoint();if(!1!==o&&o===B){n.readCodePoint();break}}const o=n.representation();return[e.Comment,n.representationString(),o[0],o[1],void 0]}function codePointsToString(e){let t="";for(let n=0;nw?R:i}var o;return n}function consumeIdentSequence(e,t){const n=[];for(;;){const o=t.peekOneCodePoint();if(!1===o)return n;if(isIdentCodePoint(o))t.readCodePoint(),n.push(o);else{if(o!==W||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(t,o){o.readCodePoint();const r=o.peekOneCodePoint();if(!1!==r&&isIdentCodePoint(r)||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=n.ID);const i=consumeIdentSequence(t,o),s=o.representation();return[e.Hash,o.representationString(),s[0],s[1],{value:codePointsToString(i),type:r}]}const i=o.representation();return[e.Delim,o.representationString(),i[0],i[1],{value:"#"}]}function consumeNumber(e,n){let o=t.Integer;const r=[];{const e=n.peekOneCodePoint();e!==N&&e!==l||(n.readCodePoint(),r.push(e));const t=consumeDigits(n);for(let e=0;e{})};return{nextToken:function nextToken(){if(i.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,i)){if(null!=n&&n.commentsAreTokens)return consumeComment(s,i);consumeComment(s,i)}i.resetRepresentation();const t=i.peekOneCodePoint();if(!1===t)return[e.EOF,"",-1,-1,void 0];switch(t){case d:{i.readCodePoint();const t=i.representation();return[e.Comma,i.representationString(),t[0],t[1],void 0]}case a:{i.readCodePoint();const t=i.representation();return[e.Colon,i.representationString(),t[0],t[1],void 0]}case x:{i.readCodePoint();const t=i.representation();return[e.Semicolon,i.representationString(),t[0],t[1],void 0]}case A:{i.readCodePoint();const t=i.representation();return[e.OpenParen,i.representationString(),t[0],t[1],void 0]}case F:{i.readCodePoint();const t=i.representation();return[e.CloseParen,i.representationString(),t[0],t[1],void 0]}case T:{i.readCodePoint();const t=i.representation();return[e.OpenSquare,i.representationString(),t[0],t[1],void 0]}case q:{i.readCodePoint();const t=i.representation();return[e.CloseSquare,i.representationString(),t[0],t[1],void 0]}case k:{i.readCodePoint();const t=i.representation();return[e.OpenCurly,i.representationString(),t[0],t[1],void 0]}case y:{i.readCodePoint();const t=i.representation();return[e.CloseCurly,i.representationString(),t[0],t[1],void 0]}}switch(t){case o:case b:return consumeStringToken(s,i);case U:return consumeHashToken(s,i);case N:case P:{if(checkIfThreeCodePointsWouldStartANumber(0,i))return consumeNumericToken(s,i);i.readCodePoint();const n=i.representation();return[e.Delim,i.representationString(),n[0],n[1],{value:String.fromCharCode(t)}]}case l:{if(checkIfThreeCodePointsWouldStartANumber(0,i))return consumeNumericToken(s,i);if(checkIfThreeCodePointsWouldStartCDC(0,i)){i.readCodePoint(),i.readCodePoint(),i.readCodePoint();const t=i.representation();return[e.CDC,i.representationString(),t[0],t[1],void 0]}if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,i))return consumeIdentLikeToken(s,i);i.readCodePoint();const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"-"}]}case I:{if(checkIfFourCodePointsWouldStartCDO(0,i)){i.readCodePoint(),i.readCodePoint(),i.readCodePoint(),i.readCodePoint();const t=i.representation();return[e.CDO,i.representationString(),t[0],t[1],void 0]}i.readCodePoint();const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"<"}]}case u:{if(i.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(s,i),n=i.representation();return[e.AtKeyword,i.representationString(),n[0],n[1],{value:codePointsToString(t)}]}const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"@"}]}case W:{if(checkIfTwoCodePointsAreAValidEscape(0,i))return consumeIdentLikeToken(s,i);i.readCodePoint();const t=i.representation();return s.onParseError({message:'Invalid escape sequence after "\\"',start:t[0],end:t[1],state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,i.representationString(),t[0],t[1],{value:"\\"}]}}if(isWhitespace(t))return consumeWhiteSpace(0,i);if(isDigitCodePoint(t))return consumeNumericToken(s,i);if(isIdentStartCodePoint(t))return consumeIdentLikeToken(s,i);i.readCodePoint();const r=i.representation();return[e.Delim,i.representationString(),r[0],r[1],{value:String.fromCharCode(t)}]},endOfFile:function endOfFile(){return!1===i.peekOneCodePoint()}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; diff --git a/packages/css-tokenizer/src/reader.ts b/packages/css-tokenizer/src/reader.ts index 287b5627d..bc55dface 100644 --- a/packages/css-tokenizer/src/reader.ts +++ b/packages/css-tokenizer/src/reader.ts @@ -14,8 +14,9 @@ export class Reader implements CodePointReader { this.#stringSource = source; this.#length = source.length; + this.#codePointSource = new Array(this.#length); for (let i = 0; i < this.#length; i++) { - this.#codePointSource.push(this.#stringSource.charCodeAt(i)); + this.#codePointSource[i] = this.#stringSource.charCodeAt(i); } } diff --git a/packages/css-tokenizer/test/test-stringify.mjs b/packages/css-tokenizer/test/test-stringify.mjs new file mode 100644 index 000000000..d0b0362c1 --- /dev/null +++ b/packages/css-tokenizer/test/test-stringify.mjs @@ -0,0 +1,8 @@ +import assert from 'assert'; +import { stringify } from 'querystring'; + +{ + assert.equal(stringify(null), ''); + assert.equal(stringify(undefined), ''); + assert.equal(stringify(), ''); +} diff --git a/packages/css-tokenizer/test/test.mjs b/packages/css-tokenizer/test/test.mjs index 8299c98ce..13afe8a8b 100644 --- a/packages/css-tokenizer/test/test.mjs +++ b/packages/css-tokenizer/test/test.mjs @@ -1,16 +1,29 @@ // Reader import './test-reader.mjs'; + // Code points import './code-points/code-points.mjs'; import './code-points/ranges.mjs'; + // Tokens import './token/basic.mjs'; import './token/comment.mjs'; import './token/numeric.mjs'; import './token/url.mjs'; + // Complex import './complex/at-media-params.mjs'; import './complex/parse-error.mjs'; + // Community import './community/bootstrap.mjs'; import './community/postcss-parser-tests.mjs'; + +// Stringify +import './test-stringify.mjs'; + +// WPT +import './wpt/cdc-vs-ident-tokens.mjs'; +import './wpt/decimal-points-in-numbers.mjs'; +import './wpt/ident-three-code-points.mjs'; +import './wpt/inclusive-ranges.mjs'; diff --git a/packages/css-tokenizer/test/token/url.mjs b/packages/css-tokenizer/test/token/url.mjs index eeada65c4..018bb23d2 100644 --- a/packages/css-tokenizer/test/token/url.mjs +++ b/packages/css-tokenizer/test/token/url.mjs @@ -259,3 +259,49 @@ url( 'mix-quoted" ' )\ ], ); } + +{ + const t1 = tokenizer({ + css: 'background-image:url(foo)', + }); + + const t2 = tokenizer({ + css: 'background-image:url(foo', + }); + + assert.deepEqual( + collectTokens(t1).map((x) => { + x[1] = ''; + x[3] = 0; + return x; + }), + collectTokens(t2).map((x) => { + x[1] = ''; + x[3] = 0; + return x; + }), + ); +} + +{ + const t1 = tokenizer({ + css: 'background-image:url()', + }); + + const t2 = tokenizer({ + css: 'background-image:url(', + }); + + assert.deepEqual( + collectTokens(t1).map((x) => { + x[1] = ''; + x[3] = 0; + return x; + }), + collectTokens(t2).map((x) => { + x[1] = ''; + x[3] = 0; + return x; + }), + ); +} diff --git a/packages/css-tokenizer/test/wpt/cdc-vs-ident-tokens.mjs b/packages/css-tokenizer/test/wpt/cdc-vs-ident-tokens.mjs new file mode 100644 index 000000000..4564ec19a --- /dev/null +++ b/packages/css-tokenizer/test/wpt/cdc-vs-ident-tokens.mjs @@ -0,0 +1,28 @@ +import { tokenizer } from '@csstools/css-tokenizer'; +import assert from 'assert'; +import { collectTokens } from '../util/collect-tokens.mjs'; + +{ + const t = tokenizer({ + css: '-->--foo { color: blue; }', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['CDC-token', '-->', 0, 2, undefined], + ['ident-token', '--foo', 3, 7, { value: '--foo' }], + ['whitespace-token', ' ', 8, 8, undefined], + ['{-token', '{', 9, 9, undefined], + ['whitespace-token', ' ', 10, 10, undefined], + ['ident-token', 'color', 11, 15, { value: 'color' }], + ['colon-token', ':', 16, 16, undefined], + ['whitespace-token', ' ', 17, 17, undefined], + ['ident-token', 'blue', 18, 21, { value: 'blue' }], + ['semicolon-token', ';', 22, 22, undefined], + ['whitespace-token', ' ', 23, 23, undefined], + ['}-token', '}', 24, 24, undefined], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} diff --git a/packages/css-tokenizer/test/wpt/decimal-points-in-numbers.mjs b/packages/css-tokenizer/test/wpt/decimal-points-in-numbers.mjs new file mode 100644 index 000000000..2092a9d10 --- /dev/null +++ b/packages/css-tokenizer/test/wpt/decimal-points-in-numbers.mjs @@ -0,0 +1,102 @@ +import { tokenizer } from '@csstools/css-tokenizer'; +import assert from 'assert'; +import { collectTokens } from '../util/collect-tokens.mjs'; + +{ + const t = tokenizer({ + css: '1.0', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['number-token', '1.0', 0, 2, { value: 1, type: 'number' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '.1', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['number-token', '.1', 0, 1, { value: 0.1, type: 'number' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '1.', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['number-token', '1', 0, 0, { value: 1, type: 'integer' }], + ['delim-token', '.', 1, 1, { value: '.' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '1.0px', + }); + + assert.deepEqual( + collectTokens(t), + [ + [ + 'dimension-token', + '1.0px', + 0, + 4, + { value: 1, type: 'number', unit: 'px' }, + ], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '.1px', + }); + + assert.deepEqual( + collectTokens(t), + [ + [ + 'dimension-token', + '.1px', + 0, + 3, + { value: 0.1, type: 'number', unit: 'px' }, + ], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '1.px', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['number-token', '1', 0, 0, { value: 1, type: 'integer' }], + ['delim-token', '.', 1, 1, { value: '.' }], + ['ident-token', 'px', 2, 3, { value: 'px' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} diff --git a/packages/css-tokenizer/test/wpt/ident-three-code-points.mjs b/packages/css-tokenizer/test/wpt/ident-three-code-points.mjs new file mode 100644 index 000000000..278632c25 --- /dev/null +++ b/packages/css-tokenizer/test/wpt/ident-three-code-points.mjs @@ -0,0 +1,121 @@ +import { tokenizer } from '@csstools/css-tokenizer'; +import assert from 'assert'; +import { collectTokens } from '../util/collect-tokens.mjs'; + +{ + const t = tokenizer({ + css: '#1', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['hash-token', '#1', 0, 1, { value: '1', type: 'unrestricted' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '#-2', + }); + + assert.deepEqual( + collectTokens(t), + [ + [ + 'hash-token', + '#-2', + 0, + 2, + { value: '-2', type: 'unrestricted' }, + ], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '#--3', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['hash-token', '#--3', 0, 3, { value: '--3', type: 'id' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '#---4', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['hash-token', '#---4', 0, 4, { value: '---4', type: 'id' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '#a', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['hash-token', '#a', 0, 1, { value: 'a', type: 'id' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '#-b', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['hash-token', '#-b', 0, 2, { value: '-b', type: 'id' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '#--c', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['hash-token', '#--c', 0, 3, { value: '--c', type: 'id' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: '#---d', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['hash-token', '#---d', 0, 4, { value: '---d', type: 'id' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} diff --git a/packages/css-tokenizer/test/wpt/inclusive-ranges.mjs b/packages/css-tokenizer/test/wpt/inclusive-ranges.mjs new file mode 100644 index 000000000..671805f75 --- /dev/null +++ b/packages/css-tokenizer/test/wpt/inclusive-ranges.mjs @@ -0,0 +1,97 @@ +import { tokenizer } from '@csstools/css-tokenizer'; +import assert from 'assert'; +import { collectTokens } from '../util/collect-tokens.mjs'; + +{ + for (let i = 0; i < 9; i++) { + const t = tokenizer({ + css: i.toString(), + }); + + assert.deepEqual( + collectTokens(t), + [ + ['number-token', i.toString(), 0, 0, { value: i, type: 'integer' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); + } + + for (let i = 10; i < 21; i++) { + const t = tokenizer({ + css: i.toString(), + }); + + assert.deepEqual( + collectTokens(t), + [ + ['number-token', i.toString(), 0, 1, { value: i, type: 'integer' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); + } +} + +{ + for (let i = 1; i <= 8; i++) { + const t = tokenizer({ + css: 'foo' + String.fromCodePoint(i), + }); + + assert.deepEqual( + collectTokens(t), + [ + ['ident-token', 'foo', 0, 2, { value: 'foo' }], + ['delim-token', String.fromCodePoint(i), 3, 3, { value: String.fromCodePoint(i) }], + ['EOF-token', '', -1, -1, undefined], + ], + ); + } +} + +{ + for (let i = 0xe; i <= 0x1f; i++) { + const t = tokenizer({ + css: 'foo' + String.fromCodePoint(i), + }); + + assert.deepEqual( + collectTokens(t), + [ + ['ident-token', 'foo', 0, 2, { value: 'foo' }], + ['delim-token', String.fromCodePoint(i), 3, 3, { value: String.fromCodePoint(i) }], + ['EOF-token', '', -1, -1, undefined], + ], + ); + } +} + +{ + const t = tokenizer({ + css: 'foo' + String.fromCodePoint(0xb), + }); + + assert.deepEqual( + collectTokens(t), + [ + ['ident-token', 'foo', 0, 2, { value: 'foo' }], + ['delim-token', String.fromCodePoint(0xb), 3, 3, { value: String.fromCodePoint(0xb) }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: 'foo' + String.fromCodePoint(0x7f), + }); + + assert.deepEqual( + collectTokens(t), + [ + ['ident-token', 'foo', 0, 2, { value: 'foo' }], + ['delim-token', String.fromCodePoint(0x7f), 3, 3, { value: String.fromCodePoint(0x7f) }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} diff --git a/packages/media-query-list-parser/test/api/options.mjs b/packages/media-query-list-parser/test/api/options.mjs index 9268779f4..37d2327d8 100644 --- a/packages/media-query-list-parser/test/api/options.mjs +++ b/packages/media-query-list-parser/test/api/options.mjs @@ -42,7 +42,41 @@ import { parse } from '@csstools/media-query-list-parser'; assert.equal( resultAST.length, - 0, + 1, + ); +} + +{ + let error; + const resultAST = parse('(foo', { + onParseError: (err) => { + error = err; + }, + }); + + assert.equal( + resultAST.length, + 1, + ); + + assert.deepEqual( + error, + { + message: 'Unexpected EOF while consuming a simple block.', + start: 0, + end: -1, + state: ['5.4.8. Consume a simple block', 'Unexpected EOF'], + }, + ); +} + + +{ + const resultAST = parse('(foo'); + + assert.equal( + resultAST.length, + 1, ); } @@ -56,7 +90,7 @@ import { parse } from '@csstools/media-query-list-parser'; assert.equal( resultAST.length, - 0, + 1, ); assert.deepEqual( From 0dea408fa8f39bda71f9ac6b83f8ec686bb0a795 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 24 Dec 2022 12:42:02 +0100 Subject: [PATCH 02/24] add more tests --- .../test/community/open-props.css | 693 ++++++++++++++++++ .../test/community/open-props.mjs | 26 + .../test/community/token-types.mjs | 166 +++++ packages/css-tokenizer/test/test.mjs | 2 + 4 files changed, 887 insertions(+) create mode 100644 packages/css-tokenizer/test/community/open-props.css create mode 100644 packages/css-tokenizer/test/community/open-props.mjs create mode 100644 packages/css-tokenizer/test/community/token-types.mjs diff --git a/packages/css-tokenizer/test/community/open-props.css b/packages/css-tokenizer/test/community/open-props.css new file mode 100644 index 000000000..ebc039155 --- /dev/null +++ b/packages/css-tokenizer/test/community/open-props.css @@ -0,0 +1,693 @@ +:where(html) { + --font-sans: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif; + --font-serif: ui-serif, serif; + --font-mono: Dank Mono, Operator Mono, Inconsolata, Fira Mono, ui-monospace, SF Mono, Monaco, Droid Sans Mono, Source Code Pro, monospace; + --font-weight-1: 100; + --font-weight-2: 200; + --font-weight-3: 300; + --font-weight-4: 400; + --font-weight-5: 500; + --font-weight-6: 600; + --font-weight-7: 700; + --font-weight-8: 800; + --font-weight-9: 900; + --font-lineheight-00: .95; + --font-lineheight-0: 1.1; + --font-lineheight-1: 1.25; + --font-lineheight-2: 1.375; + --font-lineheight-3: 1.5; + --font-lineheight-4: 1.75; + --font-lineheight-5: 2; + --font-letterspacing-0: -.05em; + --font-letterspacing-1: .025em; + --font-letterspacing-2: .050em; + --font-letterspacing-3: .075em; + --font-letterspacing-4: .150em; + --font-letterspacing-5: .500em; + --font-letterspacing-6: .750em; + --font-letterspacing-7: 1em; + --font-size-00: .5rem; + --font-size-0: .75rem; + --font-size-1: 1rem; + --font-size-2: 1.1rem; + --font-size-3: 1.25rem; + --font-size-4: 1.5rem; + --font-size-5: 2rem; + --font-size-6: 2.5rem; + --font-size-7: 3rem; + --font-size-8: 3.5rem; + --font-size-fluid-0: clamp(.75rem, 2vw, 1rem); + --font-size-fluid-1: clamp(1rem, 4vw, 1.5rem); + --font-size-fluid-2: clamp(1.5rem, 6vw, 2.5rem); + --font-size-fluid-3: clamp(2rem, 9vw, 3.5rem); + --size-000: -.5rem; + --size-00: -.25rem; + --size-1: .25rem; + --size-2: .5rem; + --size-3: 1rem; + --size-4: 1.25rem; + --size-5: 1.5rem; + --size-6: 1.75rem; + --size-7: 2rem; + --size-8: 3rem; + --size-9: 4rem; + --size-10: 5rem; + --size-11: 7.5rem; + --size-12: 10rem; + --size-13: 15rem; + --size-14: 20rem; + --size-15: 30rem; + --size-fluid-1: clamp(.5rem, 1vw, 1rem); + --size-fluid-2: clamp(1rem, 2vw, 1.5rem); + --size-fluid-3: clamp(1.5rem, 3vw, 2rem); + --size-fluid-4: clamp(2rem, 4vw, 3rem); + --size-fluid-5: clamp(4rem, 5vw, 5rem); + --size-fluid-6: clamp(5rem, 7vw, 7.5rem); + --size-fluid-7: clamp(7.5rem, 10vw, 10rem); + --size-fluid-8: clamp(10rem, 20vw, 15rem); + --size-fluid-9: clamp(15rem, 30vw, 20rem); + --size-fluid-10: clamp(20rem, 40vw, 30rem); + --size-content-1: 20ch; + --size-content-2: 45ch; + --size-content-3: 60ch; + --size-header-1: 20ch; + --size-header-2: 25ch; + --size-header-3: 35ch; + --size-xxs: 240px; + --size-xs: 360px; + --size-sm: 480px; + --size-md: 768px; + --size-lg: 1024px; + --size-xl: 1440px; + --size-xxl: 1920px; + --ease-1: cubic-bezier(.25, 0, .5, 1); + --ease-2: cubic-bezier(.25, 0, .4, 1); + --ease-3: cubic-bezier(.25, 0, .3, 1); + --ease-4: cubic-bezier(.25, 0, .2, 1); + --ease-5: cubic-bezier(.25, 0, .1, 1); + --ease-in-1: cubic-bezier(.25, 0, 1, 1); + --ease-in-2: cubic-bezier(.50, 0, 1, 1); + --ease-in-3: cubic-bezier(.70, 0, 1, 1); + --ease-in-4: cubic-bezier(.90, 0, 1, 1); + --ease-in-5: cubic-bezier(1, 0, 1, 1); + --ease-out-1: cubic-bezier(0, 0, .75, 1); + --ease-out-2: cubic-bezier(0, 0, .50, 1); + --ease-out-3: cubic-bezier(0, 0, .3, 1); + --ease-out-4: cubic-bezier(0, 0, .1, 1); + --ease-out-5: cubic-bezier(0, 0, 0, 1); + --ease-in-out-1: cubic-bezier(.1, 0, .9, 1); + --ease-in-out-2: cubic-bezier(.3, 0, .7, 1); + --ease-in-out-3: cubic-bezier(.5, 0, .5, 1); + --ease-in-out-4: cubic-bezier(.7, 0, .3, 1); + --ease-in-out-5: cubic-bezier(.9, 0, .1, 1); + --ease-elastic-1: cubic-bezier(.5, .75, .75, 1.25); + --ease-elastic-2: cubic-bezier(.5, 1, .75, 1.25); + --ease-elastic-3: cubic-bezier(.5, 1.25, .75, 1.25); + --ease-elastic-4: cubic-bezier(.5, 1.5, .75, 1.25); + --ease-elastic-5: cubic-bezier(.5, 1.75, .75, 1.25); + --ease-squish-1: cubic-bezier(.5, -.1, .1, 1.5); + --ease-squish-2: cubic-bezier(.5, -.3, .1, 1.5); + --ease-squish-3: cubic-bezier(.5, -.5, .1, 1.5); + --ease-squish-4: cubic-bezier(.5, -.7, .1, 1.5); + --ease-squish-5: cubic-bezier(.5, -.9, .1, 1.5); + --ease-step-1: steps(2); + --ease-step-2: steps(3); + --ease-step-3: steps(4); + --ease-step-4: steps(7); + --ease-step-5: steps(10); + --layer-1: 1; + --layer-2: 2; + --layer-3: 3; + --layer-4: 4; + --layer-5: 5; + --layer-important: 2147483647; + --shadow-color: 220 3% 15%; + --shadow-strength: 1%; + --shadow-1: 0 1px 2px -1px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 9%)); + --shadow-2: 0 3px 5px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 3%)), 0 7px 14px -5px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 5%)); + --shadow-3: 0 -1px 3px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 2%)), 0 1px 2px -5px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 2%)), 0 2px 5px -5px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 4%)), 0 4px 12px -5px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 5%)), 0 12px 15px -5px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 7%)); + --shadow-4: 0 -2px 5px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 2%)), 0 1px 1px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 3%)), 0 2px 2px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 3%)), 0 5px 5px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 4%)), 0 9px 9px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 5%)), 0 16px 16px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 6%)); + --shadow-5: 0 -1px 2px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 2%)), 0 2px 1px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 3%)), 0 5px 5px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 3%)), 0 10px 10px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 4%)), 0 20px 20px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 5%)), 0 40px 40px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 7%)); + --shadow-6: 0 -1px 2px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 2%)), 0 3px 2px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 3%)), 0 7px 5px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 3%)), 0 12px 10px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 4%)), 0 22px 18px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 5%)), 0 41px 33px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 6%)), 0 100px 80px -2px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 7%)); + --inner-shadow-0: inset 0 0 0 1px hsl(var(--shadow-color)/calc(var(--shadow-strength) + 9%)); + --inner-shadow-1: inset 0 1px 2px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 9%)); + --inner-shadow-2: inset 0 1px 4px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 9%)); + --inner-shadow-3: inset 0 2px 8px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 9%)); + --inner-shadow-4: inset 0 2px 14px 0 hsl(var(--shadow-color)/calc(var(--shadow-strength) + 9%)); + --ratio-square: 1; + --ratio-landscape: 4/3; + --ratio-portrait: 3/4; + --ratio-widescreen: 16/9; + --ratio-ultrawide: 18/5; + --ratio-golden: 1.6180/1; + --gray-0: #f8f9fa; + --gray-1: #f1f3f5; + --gray-2: #e9ecef; + --gray-3: #dee2e6; + --gray-4: #ced4da; + --gray-5: #adb5bd; + --gray-6: #868e96; + --gray-7: #495057; + --gray-8: #343a40; + --gray-9: #212529; + --gray-10: #16191d; + --gray-11: #0d0f12; + --gray-12: #030507; + --stone-0: #f8fafb; + --stone-1: #f2f4f6; + --stone-2: #ebedef; + --stone-3: #e0e4e5; + --stone-4: #d1d6d8; + --stone-5: #b1b6b9; + --stone-6: #979b9d; + --stone-7: #7e8282; + --stone-8: #666968; + --stone-9: #50514f; + --stone-10: #3a3a37; + --stone-11: #252521; + --stone-12: #121210; + --red-0: #fff5f5; + --red-1: #ffe3e3; + --red-2: #ffc9c9; + --red-3: #ffa8a8; + --red-4: #ff8787; + --red-5: #ff6b6b; + --red-6: #fa5252; + --red-7: #f03e3e; + --red-8: #e03131; + --red-9: #c92a2a; + --red-10: #b02525; + --red-11: #962020; + --red-12: #7d1a1a; + --pink-0: #fff0f6; + --pink-1: #ffdeeb; + --pink-2: #fcc2d7; + --pink-3: #faa2c1; + --pink-4: #f783ac; + --pink-5: #f06595; + --pink-6: #e64980; + --pink-7: #d6336c; + --pink-8: #c2255c; + --pink-9: #a61e4d; + --pink-10: #8c1941; + --pink-11: #731536; + --pink-12: #59102a; + --purple-0: #f8f0fc; + --purple-1: #f3d9fa; + --purple-2: #eebefa; + --purple-3: #e599f7; + --purple-4: #da77f2; + --purple-5: #cc5de8; + --purple-6: #be4bdb; + --purple-7: #ae3ec9; + --purple-8: #9c36b5; + --purple-9: #862e9c; + --purple-10: #702682; + --purple-11: #5a1e69; + --purple-12: #44174f; + --violet-0: #f3f0ff; + --violet-1: #e5dbff; + --violet-2: #d0bfff; + --violet-3: #b197fc; + --violet-4: #9775fa; + --violet-5: #845ef7; + --violet-6: #7950f2; + --violet-7: #7048e8; + --violet-8: #6741d9; + --violet-9: #5f3dc4; + --violet-10: #5235ab; + --violet-11: #462d91; + --violet-12: #3a2578; + --indigo-0: #edf2ff; + --indigo-1: #dbe4ff; + --indigo-2: #bac8ff; + --indigo-3: #91a7ff; + --indigo-4: #748ffc; + --indigo-5: #5c7cfa; + --indigo-6: #4c6ef5; + --indigo-7: #4263eb; + --indigo-8: #3b5bdb; + --indigo-9: #364fc7; + --indigo-10: #2f44ad; + --indigo-11: #283a94; + --indigo-12: #21307a; + --blue-0: #e7f5ff; + --blue-1: #d0ebff; + --blue-2: #a5d8ff; + --blue-3: #74c0fc; + --blue-4: #4dabf7; + --blue-5: #339af0; + --blue-6: #228be6; + --blue-7: #1c7ed6; + --blue-8: #1971c2; + --blue-9: #1864ab; + --blue-10: #145591; + --blue-11: #114678; + --blue-12: #0d375e; + --cyan-0: #e3fafc; + --cyan-1: #c5f6fa; + --cyan-2: #99e9f2; + --cyan-3: #66d9e8; + --cyan-4: #3bc9db; + --cyan-5: #22b8cf; + --cyan-6: #15aabf; + --cyan-7: #1098ad; + --cyan-8: #0c8599; + --cyan-9: #0b7285; + --cyan-10: #095c6b; + --cyan-11: #074652; + --cyan-12: #053038; + --teal-0: #e6fcf5; + --teal-1: #c3fae8; + --teal-2: #96f2d7; + --teal-3: #63e6be; + --teal-4: #38d9a9; + --teal-5: #20c997; + --teal-6: #12b886; + --teal-7: #0ca678; + --teal-8: #099268; + --teal-9: #087f5b; + --teal-10: #066649; + --teal-11: #054d37; + --teal-12: #033325; + --green-0: #ebfbee; + --green-1: #d3f9d8; + --green-2: #b2f2bb; + --green-3: #8ce99a; + --green-4: #69db7c; + --green-5: #51cf66; + --green-6: #40c057; + --green-7: #37b24d; + --green-8: #2f9e44; + --green-9: #2b8a3e; + --green-10: #237032; + --green-11: #1b5727; + --green-12: #133d1b; + --lime-0: #f4fce3; + --lime-1: #e9fac8; + --lime-2: #d8f5a2; + --lime-3: #c0eb75; + --lime-4: #a9e34b; + --lime-5: #94d82d; + --lime-6: #82c91e; + --lime-7: #74b816; + --lime-8: #66a80f; + --lime-9: #5c940d; + --lime-10: #4c7a0b; + --lime-11: #3c6109; + --lime-12: #2c4706; + --yellow-0: #fff9db; + --yellow-1: #fff3bf; + --yellow-2: #ffec99; + --yellow-3: #ffe066; + --yellow-4: #ffd43b; + --yellow-5: #fcc419; + --yellow-6: #fab005; + --yellow-7: #f59f00; + --yellow-8: #f08c00; + --yellow-9: #e67700; + --yellow-10: #b35c00; + --yellow-11: #804200; + --yellow-12: #663500; + --orange-0: #fff4e6; + --orange-1: #ffe8cc; + --orange-2: #ffd8a8; + --orange-3: #ffc078; + --orange-4: #ffa94d; + --orange-5: #ff922b; + --orange-6: #fd7e14; + --orange-7: #f76707; + --orange-8: #e8590c; + --orange-9: #d9480f; + --orange-10: #bf400d; + --orange-11: #99330b; + --orange-12: #802b09; + --choco-0: #fff8dc; + --choco-1: #fce1bc; + --choco-2: #f7ca9e; + --choco-3: #f1b280; + --choco-4: #e99b62; + --choco-5: #df8545; + --choco-6: #d46e25; + --choco-7: #bd5f1b; + --choco-8: #a45117; + --choco-9: #8a4513; + --choco-10: #703a13; + --choco-11: #572f12; + --choco-12: #3d210d; + --brown-0: #faf4eb; + --brown-1: #ede0d1; + --brown-2: #e0cab7; + --brown-3: #d3b79e; + --brown-4: #c5a285; + --brown-5: #b78f6d; + --brown-6: #a87c56; + --brown-7: #956b47; + --brown-8: #825b3a; + --brown-9: #6f4b2d; + --brown-10: #5e3a21; + --brown-11: #4e2b15; + --brown-12: #422412; + --sand-0: #f8fafb; + --sand-1: #e6e4dc; + --sand-2: #d5cfbd; + --sand-3: #c2b9a0; + --sand-4: #aea58c; + --sand-5: #9a9178; + --sand-6: #867c65; + --sand-7: #736a53; + --sand-8: #5f5746; + --sand-9: #4b4639; + --sand-10: #38352d; + --sand-11: #252521; + --sand-12: #121210; + --camo-0: #f9fbe7; + --camo-1: #e8ed9c; + --camo-2: #d2df4e; + --camo-3: #c2ce34; + --camo-4: #b5bb2e; + --camo-5: #a7a827; + --camo-6: #999621; + --camo-7: #8c851c; + --camo-8: #7e7416; + --camo-9: #6d6414; + --camo-10: #5d5411; + --camo-11: #4d460e; + --camo-12: #36300a; + --jungle-0: #ecfeb0; + --jungle-1: #def39a; + --jungle-2: #d0e884; + --jungle-3: #c2dd6e; + --jungle-4: #b5d15b; + --jungle-5: #a8c648; + --jungle-6: #9bbb36; + --jungle-7: #8fb024; + --jungle-8: #84a513; + --jungle-9: #7a9908; + --jungle-10: #658006; + --jungle-11: #516605; + --jungle-12: #3d4d04; + --gradient-1: linear-gradient(to bottom right, #1f005c, #5b0060, #870160, #ac255e, #ca485c, #e16b5c, #f39060, #ffb56b); + --gradient-2: linear-gradient(to bottom right, #48005c, #8300e2, #a269ff); + --gradient-3: radial-gradient(circle at top right, #0ff, rgba(0, 255, 255, 0)), radial-gradient(circle at bottom left, #ff1492, rgba(255, 20, 146, 0)); + --gradient-4: linear-gradient(to bottom right, #00f5a0, #00d9f5); + --gradient-5: conic-gradient(from -270deg at 75% 110%, #f0f, #fffaf0); + --gradient-6: conic-gradient(from -90deg at top left, #000, #fff); + --gradient-7: linear-gradient(to bottom right, #72c6ef, #004e8f); + --gradient-8: conic-gradient(from 90deg at 50% 0%, #111, 50%, #222, #111); + --gradient-9: conic-gradient(from .5turn at bottom center, #add8e6, #fff); + --gradient-10: conic-gradient(from 90deg at 40% -25%, gold, #f79d03, #ee6907, #e6390a, #de0d0d, #d61039, #cf1261, #c71585, #cf1261, #d61039, #de0d0d, #ee6907, #f79d03, gold, gold, gold); + --gradient-11: conic-gradient(at bottom left, #ff1493, cyan); + --gradient-12: conic-gradient(from 90deg at 25% -10%, #ff4500, #d3f340, #7bee85, #afeeee, #7bee85); + --gradient-13: radial-gradient(circle at 50% 200%, #000142, #3b0083, #b300c3, #ff059f, #ff4661, #ffad86, #fff3c7); + --gradient-14: conic-gradient(at top right, lime, cyan); + --gradient-15: linear-gradient(to bottom right, #c7d2fe, #fecaca, #fef3c7); + --gradient-16: radial-gradient(circle at 50% -250%, #374151, #111827, #000); + --gradient-17: conic-gradient(from -90deg at 50% -25%, blue, #8a2be2); + --gradient-18: linear-gradient(0deg, rgba(255, 0, 0, .8), rgba(255, 0, 0, 0) 75%), linear-gradient(60deg, rgba(255, 255, 0, .8), rgba(255, 255, 0, 0) 75%), linear-gradient(120deg, rgba(0, 255, 0, .8), rgba(0, 255, 0, 0) 75%), linear-gradient(180deg, rgba(0, 255, 255, .8), rgba(0, 255, 255, 0) 75%), linear-gradient(240deg, rgba(0, 0, 255, .8), rgba(0, 0, 255, 0) 75%), linear-gradient(300deg, rgba(255, 0, 255, .8), rgba(255, 0, 255, 0) 75%); + --gradient-19: linear-gradient(to bottom right, #ffe259, #ffa751); + --gradient-20: conic-gradient(from -135deg at -10% center, orange, #ff7715, #ff522a, #ff3f47, #ff5482, #ff69b4); + --gradient-21: conic-gradient(from -90deg at 25% 115%, red, #f06, #f0c, #c0f, #60f, #00f, #00f, #00f, #00f); + --gradient-22: linear-gradient(to bottom right, #acb6e5, #86fde8); + --gradient-23: linear-gradient(to bottom right, #536976, #292e49); + --gradient-24: conic-gradient(from .5turn at 0% 0%, #00c476, 10%, #82b0ff, 90%, #00c476); + --gradient-25: conic-gradient(at 125% 50%, #b78cf7, #ff7c94, #ffcf0d, #ff7c94, #b78cf7); + --gradient-26: linear-gradient(to bottom right, #9796f0, #fbc7d4); + --gradient-27: conic-gradient(from .5turn at bottom left, #ff1493, #639); + --gradient-28: conic-gradient(from -90deg at 50% 105%, #fff, orchid); + --gradient-29: radial-gradient(circle at top right, #bfb3ff, rgba(191, 179, 255, 0)), radial-gradient(circle at bottom left, #86acf9, rgba(134, 172, 249, 0)); + --gradient-30: radial-gradient(circle at top right, #00ff80, rgba(0, 255, 128, 0)), radial-gradient(circle at bottom left, #adffd6, rgba(173, 255, 214, 0)); + --noise-1: url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.005' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23a)'/%3E%3C/svg%3E"); + --noise-2: url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 300 300' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.05' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23a)'/%3E%3C/svg%3E"); + --noise-3: url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.25' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23a)'/%3E%3C/svg%3E"); + --noise-4: url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 2056 2056' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23a)'/%3E%3C/svg%3E"); + --noise-5: url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 2056 2056' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23a)'/%3E%3C/svg%3E"); + --noise-filter-1: contrast(300%) brightness(100%); + --noise-filter-2: contrast(200%) brightness(150%); + --noise-filter-3: contrast(200%) brightness(250%); + --noise-filter-4: contrast(200%) brightness(500%); + --noise-filter-5: contrast(200%) brightness(1000%); + --animation-fade-in: fade-in .5s var(--ease-3); + --animation-fade-in-bloom: fade-in-bloom 2s var(--ease-3); + --animation-fade-out: fade-out .5s var(--ease-3); + --animation-fade-out-bloom: fade-out-bloom 2s var(--ease-3); + --animation-scale-up: scale-up .5s var(--ease-3); + --animation-scale-down: scale-down .5s var(--ease-3); + --animation-slide-out-up: slide-out-up .5s var(--ease-3); + --animation-slide-out-down: slide-out-down .5s var(--ease-3); + --animation-slide-out-right: slide-out-right .5s var(--ease-3); + --animation-slide-out-left: slide-out-left .5s var(--ease-3); + --animation-slide-in-up: slide-in-up .5s var(--ease-3); + --animation-slide-in-down: slide-in-down .5s var(--ease-3); + --animation-slide-in-right: slide-in-right .5s var(--ease-3); + --animation-slide-in-left: slide-in-left .5s var(--ease-3); + --animation-shake-x: shake-x .75s var(--ease-out-5); + --animation-shake-y: shake-y .75s var(--ease-out-5); + --animation-spin: spin 2s linear infinite; + --animation-ping: ping 5s var(--ease-out-3) infinite; + --animation-blink: blink 1s var(--ease-out-3) infinite; + --animation-float: float 3s var(--ease-in-out-3) infinite; + --animation-bounce: bounce 2s var(--ease-squish-2) infinite; + --animation-pulse: pulse 2s var(--ease-out-3) infinite; + --border-size-1: 1px; + --border-size-2: 2px; + --border-size-3: 5px; + --border-size-4: 10px; + --border-size-5: 25px; + --radius-1: 2px; + --radius-2: 5px; + --radius-3: 1rem; + --radius-4: 2rem; + --radius-5: 4rem; + --radius-6: 8rem; + --radius-round: 1e5px; + --radius-blob-1: 30% 70% 70% 30%/53% 30% 70% 47%; + --radius-blob-2: 53% 47% 34% 66%/63% 46% 54% 37%; + --radius-blob-3: 37% 63% 56% 44%/49% 56% 44% 51%; + --radius-blob-4: 63% 37% 37% 63%/43% 37% 63% 57%; + --radius-blob-5: 49% 51% 48% 52%/57% 44% 56% 43%; + --radius-conditional-1: clamp(0px, calc(100vw - 100%) * 1e5, var(--radius-1)); + --radius-conditional-2: clamp(0px, calc(100vw - 100%) * 1e5, var(--radius-2)); + --radius-conditional-3: clamp(0px, calc(100vw - 100%) * 1e5, var(--radius-3)); + --radius-conditional-4: clamp(0px, calc(100vw - 100%) * 1e5, var(--radius-4)); + --radius-conditional-5: clamp(0px, calc(100vw - 100%) * 1e5, var(--radius-5)); + --radius-conditional-6: clamp(0px, calc(100vw - 100%) * 1e5, var(--radius-6)) +} + +@media (prefers-color-scheme:dark) { + :where(html) { + --shadow-color: 220 40% 2%; + --shadow-strength: 25% + } +} + +@keyframes fade-in { + to { + opacity: 1 + } +} + +@keyframes fade-in-bloom { + 0% { + filter: brightness(1) blur(20px); + opacity: 0 + } + + 10% { + filter: brightness(2) blur(10px); + filter: brightness(.5) blur(10px); + opacity: 1 + } + + to { + filter: brightness(1) blur(0); + opacity: 1 + } +} + +@keyframes fade-out { + to { + opacity: 0 + } +} + +@keyframes fade-out-bloom { + to { + filter: brightness(1) blur(20px); + opacity: 0 + } + + 10% { + filter: brightness(2) blur(10px); + filter: brightness(.5) blur(10px); + opacity: 1 + } + + 0% { + filter: brightness(1) blur(0); + opacity: 1 + } +} + +@keyframes scale-up { + to { + transform: scale(1.25) + } +} + +@keyframes scale-down { + to { + transform: scale(.75) + } +} + +@keyframes slide-out-up { + to { + transform: translateY(-100%) + } +} + +@keyframes slide-out-down { + to { + transform: translateY(100%) + } +} + +@keyframes slide-out-right { + to { + transform: translateX(100%) + } +} + +@keyframes slide-out-left { + to { + transform: translateX(-100%) + } +} + +@keyframes slide-in-up { + 0% { + transform: translateY(100%) + } +} + +@keyframes slide-in-down { + 0% { + transform: translateY(-100%) + } +} + +@keyframes slide-in-right { + 0% { + transform: translateX(-100%) + } +} + +@keyframes slide-in-left { + 0% { + transform: translateX(100%) + } +} + +@keyframes shake-x { + + 0%, + to { + transform: translateX(0) + } + + 20% { + transform: translateX(-5%) + } + + 40% { + transform: translateX(5%) + } + + 60% { + transform: translateX(-5%) + } + + 80% { + transform: translateX(5%) + } +} + +@keyframes shake-y { + + 0%, + to { + transform: translateY(0) + } + + 20% { + transform: translateY(-5%) + } + + 40% { + transform: translateY(5%) + } + + 60% { + transform: translateY(-5%) + } + + 80% { + transform: translateY(5%) + } +} + +@keyframes spin { + to { + transform: rotate(1turn) + } +} + +@keyframes ping { + + 90%, + to { + opacity: 0; + transform: scale(2) + } +} + +@keyframes blink { + + 0%, + to { + opacity: 1 + } + + 50% { + opacity: .5 + } +} + +@keyframes float { + 50% { + transform: translateY(-25%) + } +} + +@keyframes bounce { + 25% { + transform: translateY(-20%) + } + + 40% { + transform: translateY(-3%) + } + + 0%, + 60%, + to { + transform: translateY(0) + } +} + +@keyframes pulse { + 50% { + transform: scale(.9) + } +} diff --git a/packages/css-tokenizer/test/community/open-props.mjs b/packages/css-tokenizer/test/community/open-props.mjs new file mode 100644 index 000000000..83ec89d9c --- /dev/null +++ b/packages/css-tokenizer/test/community/open-props.mjs @@ -0,0 +1,26 @@ +import { tokenizer, TokenType } from '@csstools/css-tokenizer'; +import fs from 'fs'; + +{ + const source = fs.readFileSync('./test/community/open-props.css').toString(); + + const t = tokenizer( + { + css: source, + }, + { + onParseError: (err) => { + // We only expect something like open props to tokenize without parser errors. + throw new Error(JSON.stringify(err)); + }, + }, + ); + + // eslint-disable-next-line no-constant-condition + while (true) { + const token = t.nextToken(); + if (token[0] === TokenType.EOF) { + break; + } + } +} diff --git a/packages/css-tokenizer/test/community/token-types.mjs b/packages/css-tokenizer/test/community/token-types.mjs new file mode 100644 index 000000000..97b1fcb8f --- /dev/null +++ b/packages/css-tokenizer/test/community/token-types.mjs @@ -0,0 +1,166 @@ +import { tokenizer, TokenType } from '@csstools/css-tokenizer'; +import postcssTokenizer from 'postcss/lib/tokenize'; +import assert from 'assert'; +import fs from 'fs'; + +const bootstrapSource = fs.readFileSync('./test/community/bootstrap.css').toString(); +const openPropsSource = fs.readFileSync('./test/community/open-props.css').toString(); + +const source = ` +/* a comment */ + + +--> +/* more comments */ + +.foo { + image: url(https://example.com/foo.jpg); + image: url("https://example.com/foo.jpg"); +} + +.foo { + image: url((); +} + +.foo { + content: "foo +bar"; +} + +#1 {} + +#foo {} + +.foo { + margin: 0; + margin: 1px; + line-height: 1%; + line-height: 1.2; +} + +${bootstrapSource} +${openPropsSource} +`; + +{ + const t = tokenizer( + { + css: source, + }, + { + commentsAreTokens: true, + onParseError: () => { + // noop + }, + }, + ); + + let tokens = []; + + // eslint-disable-next-line no-constant-condition + while (true) { + const token = t.nextToken(); + tokens.push(token); + + if (token[0] === TokenType.EOF) { + break; + } + } + + const tokenTypes = Array.from(new Set(tokens.map(x => csstoolsTokenToTypeWithSubIdentifiers(x)))); + tokenTypes.sort((a, b) => a.localeCompare(b)); + + assert.deepEqual( + tokenTypes, + [ + '(-token', + ')-token', + '[-token', + ']-token', + '{-token', + '}-token', + 'at-keyword-token', + 'bad-string-token', + 'bad-url-token', + 'CDC-token', + 'CDO-token', + 'colon-token', + 'comma-token', + 'comment', + 'delim-token', + 'dimension-token - integer', + 'dimension-token - number', + 'EOF-token', + 'function-token', + 'hash-token - id', + 'hash-token - unrestricted', + 'ident-token', + 'number-token - integer', + 'number-token - number', + 'percentage-token', + 'semicolon-token', + 'string-token', + 'url-token', + 'whitespace-token', + ], + ); +} + +function csstoolsTokenToTypeWithSubIdentifiers(token) { + if (token[0] === TokenType.Number) { + return `${token[0]} - ${token[4].type}`; + } + + if (token[0] === TokenType.Dimension) { + return `${token[0]} - ${token[4].type}`; + } + + if (token[0] === TokenType.Hash) { + return `${token[0]} - ${token[4].type}`; + } + + return token[0]; +} + +{ + const t = postcssTokenizer( + { + css: source, + }, + ); + + let tokens = []; + + // eslint-disable-next-line no-constant-condition + while (true) { + const token = t.nextToken(); + if (!token) { + break; + } + + tokens.push(token); + } + + const tokenTypes = Array.from(new Set(tokens.map(x => x[0]))); + tokenTypes.sort((a, b) => a.localeCompare(b)); + + assert.deepEqual( + tokenTypes, + [ + ';', + ':', + '(', + ')', + '[', + ']', + '{', + '}', + 'at-word', + 'brackets', + 'comment', + 'space', + 'string', + 'word', + ], + ); +} diff --git a/packages/css-tokenizer/test/test.mjs b/packages/css-tokenizer/test/test.mjs index 13afe8a8b..54ccdaadc 100644 --- a/packages/css-tokenizer/test/test.mjs +++ b/packages/css-tokenizer/test/test.mjs @@ -17,7 +17,9 @@ import './complex/parse-error.mjs'; // Community import './community/bootstrap.mjs'; +import './community/open-props.mjs'; import './community/postcss-parser-tests.mjs'; +import './community/token-types.mjs'; // Stringify import './test-stringify.mjs'; From 902fb4042549e3d635be6f0bef6f4e6a108ad3d9 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 24 Dec 2022 13:09:47 +0100 Subject: [PATCH 03/24] one more test --- packages/css-tokenizer/test/token/url.mjs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/css-tokenizer/test/token/url.mjs b/packages/css-tokenizer/test/token/url.mjs index 018bb23d2..cff68fabd 100644 --- a/packages/css-tokenizer/test/token/url.mjs +++ b/packages/css-tokenizer/test/token/url.mjs @@ -305,3 +305,18 @@ url( 'mix-quoted" ' )\ }), ); } + +{ + const t = tokenizer({ + css: 'url(foo())', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['bad-url-token', 'url(foo()', 0, 8, undefined], + [')-token', ')', 9, 9, undefined], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} From 0551173a377049d63afc3e6c65e2e404ddd381e5 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 24 Dec 2022 19:39:48 +0100 Subject: [PATCH 04/24] performance improvements --- .../code-points/code-points-to-string.d.ts | 1 - packages/css-tokenizer/dist/index.cjs | 2 +- packages/css-tokenizer/dist/index.mjs | 2 +- .../dist/interfaces/code-point-reader.d.ts | 13 +- packages/css-tokenizer/dist/reader.d.ts | 18 ++- .../four-code-points-would-start-cdo.ts | 5 +- .../css-tokenizer/src/checks/next-is-eof.ts | 3 +- .../three-code-points-would-start-cdc.ts | 5 +- ...-code-points-would-start-ident-sequence.ts | 15 +- .../three-code-points-would-start-number.ts | 17 +-- .../two-code-points-are-valid-escape.ts | 5 +- .../checks/two-code-points-start-comment.ts | 5 +- .../src/code-points/code-points-to-string.ts | 9 -- packages/css-tokenizer/src/consume/bad-url.ts | 5 +- packages/css-tokenizer/src/consume/comment.ts | 18 +-- .../src/consume/escaped-code-point.ts | 16 +- .../css-tokenizer/src/consume/hash-token.ts | 18 +-- .../src/consume/ident-like-token.ts | 35 ++--- .../src/consume/ident-sequence.ts | 9 +- packages/css-tokenizer/src/consume/number.ts | 65 ++++---- .../src/consume/numeric-token.ts | 21 +-- .../css-tokenizer/src/consume/string-token.ts | 22 ++- .../css-tokenizer/src/consume/url-token.ts | 69 ++++----- .../src/consume/whitespace-token.ts | 20 +-- .../src/interfaces/code-point-reader.ts | 16 +- packages/css-tokenizer/src/reader.ts | 144 ++++++------------ packages/css-tokenizer/src/tokenizer.ts | 80 ++++------ .../test/community/bootstrap-benchmark.mjs | 76 +++++++-- packages/css-tokenizer/test/inspect.mjs | 61 ++++++++ packages/css-tokenizer/test/test-reader.mjs | 45 ++++-- 30 files changed, 399 insertions(+), 421 deletions(-) delete mode 100644 packages/css-tokenizer/dist/code-points/code-points-to-string.d.ts delete mode 100644 packages/css-tokenizer/src/code-points/code-points-to-string.ts create mode 100644 packages/css-tokenizer/test/inspect.mjs diff --git a/packages/css-tokenizer/dist/code-points/code-points-to-string.d.ts b/packages/css-tokenizer/dist/code-points/code-points-to-string.d.ts deleted file mode 100644 index bb5e034c7..000000000 --- a/packages/css-tokenizer/dist/code-points/code-points-to-string.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function codePointsToString(codePoints: Array): string; diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index 3d74b8b55..cf0f9610b 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1 @@ -"use strict";class Reader{#e;#t="";#n=[];#o=0;#r=0;#i=-1;constructor(e){this.#e=0,this.#t=e,this.#o=e.length,this.#n=new Array(this.#o);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===v)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===k)}function isNewLine(e){switch(e){case y:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case y:case s:case h:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){const n=t.peekTwoCodePoints();return n[0]===L&&n[1]!==y}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===k?r===k||(!!isIdentStartCodePoint(r)||r===L&&i!==y):!!isIdentStartCodePoint(o)||o===L&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===U||o===k?!!isDigitCodePoint(r)||r===P&&isDigitCodePoint(i):o===P?isDigitCodePoint(r):!!isDigitCodePoint(o)}function checkIfTwoCodePointsStartAComment(e,t){const n=t.peekTwoCodePoints();return n[0]===B&&n[1]===r}function checkIfThreeCodePointsWouldStartCDC(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===k&&r===k&&i===T}function consumeComment(e,t){for(t.readCodePoint(),t.readCodePoint();;){const n=t.readCodePoint();if(!1===n){const n=t.representation();e.onParseError({message:"Unexpected EOF while consuming a comment.",start:n[0],end:n[1],state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(n!==r)continue;const o=t.peekOneCodePoint();if(!1!==o&&o===B){t.readCodePoint();break}}const n=t.representation();return[exports.TokenType.Comment,t.representationString(),n[0],n[1],void 0]}function codePointsToString(e){let t="";for(let n=0;nO?b:i}var o;return n}function consumeIdentSequence(e,t){const n=[];for(;;){const o=t.peekOneCodePoint();if(!1===o)return n;if(isIdentCodePoint(o))t.readCodePoint(),n.push(o);else{if(o!==L||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(e,t){t.readCodePoint();const o=t.peekOneCodePoint();if(!1!==o&&isIdentCodePoint(o)||checkIfTwoCodePointsAreAValidEscape(0,t)){let o=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,t)&&(o=n.ID);const r=consumeIdentSequence(e,t),i=t.representation();return[exports.TokenType.Hash,t.representationString(),i[0],i[1],{value:codePointsToString(r),type:o}]}const r=t.representation();return[exports.TokenType.Delim,t.representationString(),r[0],r[1],{value:"#"}]}function consumeNumber(e,t){let n=exports.NumberType.Integer;const o=[];{const e=t.peekOneCodePoint();e!==U&&e!==k||(t.readCodePoint(),o.push(e));const n=consumeDigits(t);for(let e=0;e{})};return{nextToken:function nextToken(){if(r.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,r)){if(null!=t&&t.commentsAreTokens)return consumeComment(i,r);consumeComment(i,r)}r.resetRepresentation();const e=r.peekOneCodePoint();if(!1===e)return[exports.TokenType.EOF,"",-1,-1,void 0];switch(e){case d:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Comma,r.representationString(),e[0],e[1],void 0]}case a:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Colon,r.representationString(),e[0],e[1],void 0]}case q:{r.readCodePoint();const e=r.representation();return[exports.TokenType.Semicolon,r.representationString(),e[0],e[1],void 0]}case S:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenParen,r.representationString(),e[0],e[1],void 0]}case W:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseParen,r.representationString(),e[0],e[1],void 0]}case A:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenSquare,r.representationString(),e[0],e[1],void 0]}case F:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseSquare,r.representationString(),e[0],e[1],void 0]}case g:{r.readCodePoint();const e=r.representation();return[exports.TokenType.OpenCurly,r.representationString(),e[0],e[1],void 0]}case R:{r.readCodePoint();const e=r.representation();return[exports.TokenType.CloseCurly,r.representationString(),e[0],e[1],void 0]}}switch(e){case o:case N:return consumeStringToken(i,r);case w:return consumeHashToken(i,r);case U:case P:{if(checkIfThreeCodePointsWouldStartANumber(0,r))return consumeNumericToken(i,r);r.readCodePoint();const t=r.representation();return[exports.TokenType.Delim,r.representationString(),t[0],t[1],{value:String.fromCharCode(e)}]}case k:{if(checkIfThreeCodePointsWouldStartANumber(0,r))return consumeNumericToken(i,r);if(checkIfThreeCodePointsWouldStartCDC(0,r)){r.readCodePoint(),r.readCodePoint(),r.readCodePoint();const e=r.representation();return[exports.TokenType.CDC,r.representationString(),e[0],e[1],void 0]}if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,r))return consumeIdentLikeToken(i,r);r.readCodePoint();const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"-"}]}case x:{if(checkIfFourCodePointsWouldStartCDO(0,r)){r.readCodePoint(),r.readCodePoint(),r.readCodePoint(),r.readCodePoint();const e=r.representation();return[exports.TokenType.CDO,r.representationString(),e[0],e[1],void 0]}r.readCodePoint();const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"<"}]}case u:{if(r.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)){const e=consumeIdentSequence(i,r),t=r.representation();return[exports.TokenType.AtKeyword,r.representationString(),t[0],t[1],{value:codePointsToString(e)}]}const e=r.representation();return[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"@"}]}case L:{if(checkIfTwoCodePointsAreAValidEscape(0,r))return consumeIdentLikeToken(i,r);r.readCodePoint();const e=r.representation();return i.onParseError({message:'Invalid escape sequence after "\\"',start:e[0],end:e[1],state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,r.representationString(),e[0],e[1],{value:"\\"}]}}if(isWhitespace(e))return consumeWhiteSpace(0,r);if(isDigitCodePoint(e))return consumeNumericToken(i,r);if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,r);r.readCodePoint();const n=r.representation();return[exports.TokenType.Delim,r.representationString(),n[0],n[1],{value:String.fromCharCode(e)}]},endOfFile:function endOfFile(){return!1===r.peekOneCodePoint()}}}; +"use strict";class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;peekedOne;peekedTwo;peekedThree;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===y)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===S)}function isNewLine(e){switch(e){case A:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case A:case s:case h:case a:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.peekedOne===L&&t.peekedTwo!==A}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.peekedOne===S?t.peekedTwo===S||(!!isIdentStartCodePoint(t.peekedTwo)||t.peekedTwo===L&&t.peekedThree!==A):!!isIdentStartCodePoint(t.peekedOne)||t.peekedOne===L&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.peekedOne===U||t.peekedOne===S?!!isDigitCodePoint(t.peekedTwo)||t.peekedTwo===k&&isDigitCodePoint(t.peekedThree):t.peekedOne===k?isDigitCodePoint(t.peekedTwo):!!isDigitCodePoint(t.peekedOne)}function checkIfTwoCodePointsStartAComment(e,t){return t.peekedOne===B&&t.peekedTwo===o}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.peekedOne===S&&t.peekedTwo===S&&t.peekedThree===T}function consumeComment(e,t){for(t.readCodePoint(2);;){const n=t.readCodePoint();if(!1===n){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:t.representationStart,end:t.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(n===o&&(void 0!==t.peekedOne&&t.peekedOne===B)){t.readCodePoint();break}}return[exports.TokenType.Comment,t.representationString(),t.representationStart,t.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const n=t.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(n)){const e=[n];for(;void 0!==t.peekedOne&&isHexDigitCodePoint(t.peekedOne)&&e.length<6;)e.push(t.peekedOne),t.readCodePoint();isWhitespace(t.peekedOne)&&t.readCodePoint();const o=parseInt(String.fromCharCode(...e),16);return 0===o?b:G<=(r=o)&&r<=X||o>v?b:o}var r;return n}function consumeIdentSequence(e,t){const n=[];for(;;){if(void 0===t.peekedOne)return n;if(isIdentCodePoint(t.peekedOne))n.push(t.peekedOne),t.readCodePoint();else{if(t.peekedOne!==L||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(e,t){if(t.readCodePoint(),void 0!==t.peekedOne&&isIdentCodePoint(t.peekedOne)||checkIfTwoCodePointsAreAValidEscape(0,t)){let r=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,t)&&(r=n.ID);const o=consumeIdentSequence(e,t);return[exports.TokenType.Hash,t.representationString(),t.representationStart,t.representationEnd,{value:String.fromCharCode(...o),type:r}]}return[exports.TokenType.Delim,t.representationString(),t.representationStart,t.representationEnd,{value:"#"}]}function consumeNumber(e,t){let n=exports.NumberType.Integer;const r=[];{t.peekedOne!==U&&t.peekedOne!==S||(r.push(t.peekedOne),t.readCodePoint());const e=consumeDigits(t);for(let t=0;t{})};return{nextToken:function nextToken(){if(o.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,o)){if(null!=t&&t.commentsAreTokens)return consumeComment(i,o);consumeComment(i,o)}o.resetRepresentation();const e=o.peekedOne;if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];switch(e){case p:return o.readCodePoint(),[exports.TokenType.Comma,o.representationString(),o.representationStart,o.representationEnd,void 0];case d:return o.readCodePoint(),[exports.TokenType.Colon,o.representationString(),o.representationStart,o.representationEnd,void 0];case q:return o.readCodePoint(),[exports.TokenType.Semicolon,o.representationString(),o.representationStart,o.representationEnd,void 0];case g:return o.readCodePoint(),[exports.TokenType.OpenParen,o.representationString(),o.representationStart,o.representationEnd,void 0];case F:return o.readCodePoint(),[exports.TokenType.CloseParen,o.representationString(),o.representationStart,o.representationEnd,void 0];case O:return o.readCodePoint(),[exports.TokenType.OpenSquare,o.representationString(),o.representationStart,o.representationEnd,void 0];case W:return o.readCodePoint(),[exports.TokenType.CloseSquare,o.representationString(),o.representationStart,o.representationEnd,void 0];case P:return o.readCodePoint(),[exports.TokenType.OpenCurly,o.representationString(),o.representationStart,o.representationEnd,void 0];case R:return o.readCodePoint(),[exports.TokenType.CloseCurly,o.representationString(),o.representationStart,o.representationEnd,void 0];case r:case N:return consumeStringToken(i,o);case w:return consumeHashToken(i,o);case U:case k:return checkIfThreeCodePointsWouldStartANumber(0,o)?consumeNumericToken(i,o):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(e)}]);case S:return checkIfThreeCodePointsWouldStartANumber(0,o)?consumeNumericToken(i,o):checkIfThreeCodePointsWouldStartCDC(0,o)?(o.readCodePoint(3),[exports.TokenType.CDC,o.representationString(),o.representationStart,o.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)?consumeIdentLikeToken(i,o):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"-"}]);case E:return checkIfFourCodePointsWouldStartCDO(0,o)?(o.readCodePoint(4),[exports.TokenType.CDO,o.representationString(),o.representationStart,o.representationEnd,void 0]):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"<"}]);case c:if(o.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const e=consumeIdentSequence(i,o);return[exports.TokenType.AtKeyword,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"@"}];case L:return checkIfTwoCodePointsAreAValidEscape(0,o)?consumeIdentLikeToken(i,o):(o.readCodePoint(),i.onParseError({message:'Invalid escape sequence after "\\"',start:o.representationStart,end:o.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"\\"}])}return isWhitespace(e)?consumeWhiteSpace(0,o):isDigitCodePoint(e)?consumeNumericToken(i,o):isIdentStartCodePoint(e)?consumeIdentLikeToken(i,o):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(e)}])},endOfFile:function endOfFile(){return void 0===o.peekedOne}}}; diff --git a/packages/css-tokenizer/dist/index.mjs b/packages/css-tokenizer/dist/index.mjs index d8a660184..19f61bb11 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1 +1 @@ -class Reader{#e;#t="";#n=[];#o=0;#r=0;#i=-1;constructor(e){this.#e=0,this.#t=e,this.#o=e.length,this.#n=new Array(this.#o);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===E)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case v:case s:case p:return!0;default:return!1}}function isWhitespace(e){switch(e){case v:case s:case p:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){const n=t.peekTwoCodePoints();return n[0]===W&&n[1]!==v}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===l?r===l||(!!isIdentStartCodePoint(r)||r===W&&i!==v):!!isIdentStartCodePoint(o)||o===W&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===N||o===l?!!isDigitCodePoint(r)||r===P&&isDigitCodePoint(i):o===P?isDigitCodePoint(r):!!isDigitCodePoint(o)}function checkIfTwoCodePointsStartAComment(e,t){const n=t.peekTwoCodePoints();return n[0]===B&&n[1]===r}function checkIfThreeCodePointsWouldStartCDC(e,t){const n=t.peekThreeCodePoints(),[o,r,i]=n;return o===l&&r===l&&i===f}function consumeComment(t,n){for(n.readCodePoint(),n.readCodePoint();;){const e=n.readCodePoint();if(!1===e){const e=n.representation();t.onParseError({message:"Unexpected EOF while consuming a comment.",start:e[0],end:e[1],state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e!==r)continue;const o=n.peekOneCodePoint();if(!1!==o&&o===B){n.readCodePoint();break}}const o=n.representation();return[e.Comment,n.representationString(),o[0],o[1],void 0]}function codePointsToString(e){let t="";for(let n=0;nw?R:i}var o;return n}function consumeIdentSequence(e,t){const n=[];for(;;){const o=t.peekOneCodePoint();if(!1===o)return n;if(isIdentCodePoint(o))t.readCodePoint(),n.push(o);else{if(o!==W||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(t,o){o.readCodePoint();const r=o.peekOneCodePoint();if(!1!==r&&isIdentCodePoint(r)||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=n.ID);const i=consumeIdentSequence(t,o),s=o.representation();return[e.Hash,o.representationString(),s[0],s[1],{value:codePointsToString(i),type:r}]}const i=o.representation();return[e.Delim,o.representationString(),i[0],i[1],{value:"#"}]}function consumeNumber(e,n){let o=t.Integer;const r=[];{const e=n.peekOneCodePoint();e!==N&&e!==l||(n.readCodePoint(),r.push(e));const t=consumeDigits(n);for(let e=0;e{})};return{nextToken:function nextToken(){if(i.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,i)){if(null!=n&&n.commentsAreTokens)return consumeComment(s,i);consumeComment(s,i)}i.resetRepresentation();const t=i.peekOneCodePoint();if(!1===t)return[e.EOF,"",-1,-1,void 0];switch(t){case d:{i.readCodePoint();const t=i.representation();return[e.Comma,i.representationString(),t[0],t[1],void 0]}case a:{i.readCodePoint();const t=i.representation();return[e.Colon,i.representationString(),t[0],t[1],void 0]}case x:{i.readCodePoint();const t=i.representation();return[e.Semicolon,i.representationString(),t[0],t[1],void 0]}case A:{i.readCodePoint();const t=i.representation();return[e.OpenParen,i.representationString(),t[0],t[1],void 0]}case F:{i.readCodePoint();const t=i.representation();return[e.CloseParen,i.representationString(),t[0],t[1],void 0]}case T:{i.readCodePoint();const t=i.representation();return[e.OpenSquare,i.representationString(),t[0],t[1],void 0]}case q:{i.readCodePoint();const t=i.representation();return[e.CloseSquare,i.representationString(),t[0],t[1],void 0]}case k:{i.readCodePoint();const t=i.representation();return[e.OpenCurly,i.representationString(),t[0],t[1],void 0]}case y:{i.readCodePoint();const t=i.representation();return[e.CloseCurly,i.representationString(),t[0],t[1],void 0]}}switch(t){case o:case b:return consumeStringToken(s,i);case U:return consumeHashToken(s,i);case N:case P:{if(checkIfThreeCodePointsWouldStartANumber(0,i))return consumeNumericToken(s,i);i.readCodePoint();const n=i.representation();return[e.Delim,i.representationString(),n[0],n[1],{value:String.fromCharCode(t)}]}case l:{if(checkIfThreeCodePointsWouldStartANumber(0,i))return consumeNumericToken(s,i);if(checkIfThreeCodePointsWouldStartCDC(0,i)){i.readCodePoint(),i.readCodePoint(),i.readCodePoint();const t=i.representation();return[e.CDC,i.representationString(),t[0],t[1],void 0]}if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,i))return consumeIdentLikeToken(s,i);i.readCodePoint();const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"-"}]}case I:{if(checkIfFourCodePointsWouldStartCDO(0,i)){i.readCodePoint(),i.readCodePoint(),i.readCodePoint(),i.readCodePoint();const t=i.representation();return[e.CDO,i.representationString(),t[0],t[1],void 0]}i.readCodePoint();const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"<"}]}case u:{if(i.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(s,i),n=i.representation();return[e.AtKeyword,i.representationString(),n[0],n[1],{value:codePointsToString(t)}]}const t=i.representation();return[e.Delim,i.representationString(),t[0],t[1],{value:"@"}]}case W:{if(checkIfTwoCodePointsAreAValidEscape(0,i))return consumeIdentLikeToken(s,i);i.readCodePoint();const t=i.representation();return s.onParseError({message:'Invalid escape sequence after "\\"',start:t[0],end:t[1],state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,i.representationString(),t[0],t[1],{value:"\\"}]}}if(isWhitespace(t))return consumeWhiteSpace(0,i);if(isDigitCodePoint(t))return consumeNumericToken(s,i);if(isIdentStartCodePoint(t))return consumeIdentLikeToken(s,i);i.readCodePoint();const r=i.representation();return[e.Delim,i.representationString(),r[0],r[1],{value:String.fromCharCode(t)}]},endOfFile:function endOfFile(){return!1===i.peekOneCodePoint()}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; +class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;peekedOne;peekedTwo;peekedThree;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===v)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case T:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case T:case s:case h:case a:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.peekedOne===F&&t.peekedTwo!==T}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.peekedOne===l?t.peekedTwo===l||(!!isIdentStartCodePoint(t.peekedTwo)||t.peekedTwo===F&&t.peekedThree!==T):!!isIdentStartCodePoint(t.peekedOne)||t.peekedOne===F&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.peekedOne===N||t.peekedOne===l?!!isDigitCodePoint(t.peekedTwo)||t.peekedTwo===k&&isDigitCodePoint(t.peekedThree):t.peekedOne===k?isDigitCodePoint(t.peekedTwo):!!isDigitCodePoint(t.peekedOne)}function checkIfTwoCodePointsStartAComment(e,t){return t.peekedOne===B&&t.peekedTwo===o}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.peekedOne===l&&t.peekedTwo===l&&t.peekedThree===S}function consumeComment(t,n){for(n.readCodePoint(2);;){const e=n.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:n.representationStart,end:n.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===o&&(void 0!==n.peekedOne&&n.peekedOne===B)){n.readCodePoint();break}}return[e.Comment,n.representationString(),n.representationStart,n.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const n=t.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),R;if(isHexDigitCodePoint(n)){const e=[n];for(;void 0!==t.peekedOne&&isHexDigitCodePoint(t.peekedOne)&&e.length<6;)e.push(t.peekedOne),t.readCodePoint();isWhitespace(t.peekedOne)&&t.readCodePoint();const o=parseInt(String.fromCharCode(...e),16);return 0===o?R:G<=(r=o)&&r<=X||o>w?R:o}var r;return n}function consumeIdentSequence(e,t){const n=[];for(;;){if(void 0===t.peekedOne)return n;if(isIdentCodePoint(t.peekedOne))n.push(t.peekedOne),t.readCodePoint();else{if(t.peekedOne!==F||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(t,r){if(r.readCodePoint(),void 0!==r.peekedOne&&isIdentCodePoint(r.peekedOne)||checkIfTwoCodePointsAreAValidEscape(0,r)){let o=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(o=n.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:o}]}return[e.Delim,r.representationString(),r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,n){let r=t.Integer;const o=[];{n.peekedOne!==N&&n.peekedOne!==l||(o.push(n.peekedOne),n.readCodePoint());const e=consumeDigits(n);for(let t=0;t{})};return{nextToken:function nextToken(){if(i.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,i)){if(null!=n&&n.commentsAreTokens)return consumeComment(s,i);consumeComment(s,i)}i.resetRepresentation();const t=i.peekedOne;if(void 0===t)return[e.EOF,"",-1,-1,void 0];switch(t){case c:return i.readCodePoint(),[e.Comma,i.representationString(),i.representationStart,i.representationEnd,void 0];case d:return i.readCodePoint(),[e.Colon,i.representationString(),i.representationStart,i.representationEnd,void 0];case x:return i.readCodePoint(),[e.Semicolon,i.representationString(),i.representationStart,i.representationEnd,void 0];case O:return i.readCodePoint(),[e.OpenParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case y:return i.readCodePoint(),[e.CloseParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case E:return i.readCodePoint(),[e.OpenSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case q:return i.readCodePoint(),[e.CloseSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case g:return i.readCodePoint(),[e.OpenCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case W:return i.readCodePoint(),[e.CloseCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case r:case b:return consumeStringToken(s,i);case U:return consumeHashToken(s,i);case N:case k:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(s,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(t)}]);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(s,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.readCodePoint(3),[e.CDC,i.representationString(),i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(s,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"-"}]);case A:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.readCodePoint(4),[e.CDO,i.representationString(),i.representationStart,i.representationEnd,void 0]):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(s,i);return[e.AtKeyword,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"@"}];case F:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(s,i):(i.readCodePoint(),s.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"\\"}])}return isWhitespace(t)?consumeWhiteSpace(0,i):isDigitCodePoint(t)?consumeNumericToken(s,i):isIdentStartCodePoint(t)?consumeIdentLikeToken(s,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(t)}])},endOfFile:function endOfFile(){return void 0===i.peekedOne}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; diff --git a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts index 05660dc44..fc083f389 100644 --- a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts +++ b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts @@ -1,12 +1,13 @@ export type CodePointReader = { + representationStart: number; + representationEnd: number; + peekedOne: number | undefined; + peekedTwo: number | undefined; + peekedThree: number | undefined; + peekedFour: number | undefined; cursorPositionOfLastReadCodePoint(): number; - peekOneCodePoint(): number | false; - peekTwoCodePoints(): [number, number] | [number] | []; - peekThreeCodePoints(): [number, number, number] | [number, number] | [number] | []; - peekFourCodePoints(): [number, number, number, number] | [number, number, number] | [number, number] | [number] | []; - readCodePoint(): number | false; + readCodePoint(n?: number): number | false; unreadCodePoint(): boolean; - representation(): [number, number]; representationString(): string; resetRepresentation(): any; slice(start: number, end: number): string; diff --git a/packages/css-tokenizer/dist/reader.d.ts b/packages/css-tokenizer/dist/reader.d.ts index 3647d18b4..e4def59f2 100644 --- a/packages/css-tokenizer/dist/reader.d.ts +++ b/packages/css-tokenizer/dist/reader.d.ts @@ -1,15 +1,19 @@ import { CodePointReader } from './interfaces/code-point-reader'; export declare class Reader implements CodePointReader { - #private; + cursor: number; + stringSource: string; + codePointSource: Array; + length: number; + representationStart: number; + representationEnd: number; + peekedOne: number | undefined; + peekedTwo: number | undefined; + peekedThree: number | undefined; constructor(source: string); + peekedFour: number; cursorPositionOfLastReadCodePoint(): number; - peekOneCodePoint(): number | false; - peekTwoCodePoints(): [number, number] | [number] | []; - peekThreeCodePoints(): [number, number, number] | [number, number] | [number] | []; - peekFourCodePoints(): [number, number, number, number] | [number, number, number] | [number, number] | [number] | []; - readCodePoint(): number | false; + readCodePoint(n?: number): number | false; unreadCodePoint(): boolean; - representation(): [number, number]; representationString(): string; resetRepresentation(): void; slice(start: number, end: number): string; diff --git a/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts b/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts index 722a0e6ec..ea9689bda 100644 --- a/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts +++ b/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts @@ -4,8 +4,5 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token export function checkIfFourCodePointsWouldStartCDO(ctx: Context, reader: CodePointReader): boolean { - const peeked = reader.peekFourCodePoints(); - const [first, second, third, fourth] = peeked; - - return first === LESS_THAN_SIGN && second === EXCLAMATION_MARK && third === HYPHEN_MINUS && fourth === HYPHEN_MINUS; + return reader.peekedOne === LESS_THAN_SIGN && reader.peekedTwo === EXCLAMATION_MARK && reader.peekedThree === HYPHEN_MINUS && reader.peekedFour === HYPHEN_MINUS; } diff --git a/packages/css-tokenizer/src/checks/next-is-eof.ts b/packages/css-tokenizer/src/checks/next-is-eof.ts index 18ee497a7..b6e0a3054 100644 --- a/packages/css-tokenizer/src/checks/next-is-eof.ts +++ b/packages/css-tokenizer/src/checks/next-is-eof.ts @@ -2,8 +2,7 @@ import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; export function checkIfNextIsEOF(ctx: Context, reader: CodePointReader): boolean { - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { + if (reader.peekedOne === undefined) { return true; } diff --git a/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts b/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts index 38cdf70dc..dc2667e2a 100644 --- a/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts +++ b/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts @@ -4,8 +4,5 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token export function checkIfThreeCodePointsWouldStartCDC(ctx: Context, reader: CodePointReader): boolean { - const peeked = reader.peekThreeCodePoints(); - const [first, second, third] = peeked; - - return first === HYPHEN_MINUS && second === HYPHEN_MINUS && third === GREATER_THAN_SIGN; + return reader.peekedOne === HYPHEN_MINUS && reader.peekedTwo === HYPHEN_MINUS && reader.peekedThree === GREATER_THAN_SIGN; } diff --git a/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts b/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts index 28ffc8fc6..be477ace1 100644 --- a/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts +++ b/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts @@ -6,23 +6,20 @@ import { checkIfTwoCodePointsAreAValidEscape } from './two-code-points-are-valid // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier export function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, reader: CodePointReader): boolean { - const peeked = reader.peekThreeCodePoints(); - const [first, second, third] = peeked; - // // U+002D HYPHEN-MINUS - if (first === HYPHEN_MINUS) { + if (reader.peekedOne === HYPHEN_MINUS) { // If the second code point is a U+002D HYPHEN-MINUS return true - if (second === HYPHEN_MINUS) { + if (reader.peekedTwo === HYPHEN_MINUS) { return true; } // If the second code point is an ident-start code point return true - if (isIdentStartCodePoint(second)) { + if (isIdentStartCodePoint(reader.peekedTwo)) { return true; } // If the second and third code points are a valid escape return true - if (second === REVERSE_SOLIDUS && third !== LINE_FEED) { + if (reader.peekedTwo === REVERSE_SOLIDUS && reader.peekedThree !== LINE_FEED) { return true; } @@ -31,12 +28,12 @@ export function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, re // ident-start code point // Return true. - if (isIdentStartCodePoint(first)) { + if (isIdentStartCodePoint(reader.peekedOne)) { return true; } // U+005C REVERSE SOLIDUS (\) - if (first === REVERSE_SOLIDUS) { + if (reader.peekedOne === REVERSE_SOLIDUS) { // If the first and second code points are a valid escape, return true. // Otherwise, return false. return checkIfTwoCodePointsAreAValidEscape(ctx, reader); diff --git a/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts b/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts index e4b964e9c..a2322fbfd 100644 --- a/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts +++ b/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts @@ -5,30 +5,27 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number export function checkIfThreeCodePointsWouldStartANumber(ctx: Context, reader: CodePointReader): boolean { - const peeked = reader.peekThreeCodePoints(); - const [first, second, third] = peeked; - - if (first === PLUS_SIGN || first === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) + if (reader.peekedOne === PLUS_SIGN || reader.peekedOne === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) // If the second code point is a digit, return true. - if (isDigitCodePoint(second)) { + if (isDigitCodePoint(reader.peekedTwo)) { return true; } // Otherwise, if the second code point is a U+002E FULL STOP (.) - if (second === FULL_STOP) { + if (reader.peekedTwo === FULL_STOP) { // and the third code point is a digit, return true. - return isDigitCodePoint(third); + return isDigitCodePoint(reader.peekedThree); } // Otherwise, return false. return false; - } else if (first === FULL_STOP) { // U+002E FULL STOP (.) + } else if (reader.peekedOne === FULL_STOP) { // U+002E FULL STOP (.) // If the second code point is a digit, return true. // Otherwise, return false. - return isDigitCodePoint(second); + return isDigitCodePoint(reader.peekedTwo); - } else if (isDigitCodePoint(first)) { // digit + } else if (isDigitCodePoint(reader.peekedOne)) { // digit // Return true. return true; } diff --git a/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts b/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts index 4e30730fb..3f0ec91cd 100644 --- a/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts +++ b/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts @@ -4,14 +4,13 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape export function checkIfTwoCodePointsAreAValidEscape(ctx: Context, reader: CodePointReader): boolean { - const peeked = reader.peekTwoCodePoints(); // If the first code point is not U+005C REVERSE SOLIDUS (\), return false. - if (peeked[0] !== REVERSE_SOLIDUS) { // "\" + if (reader.peekedOne !== REVERSE_SOLIDUS) { // "\" return false; } // Otherwise, if the second code point is a newline, return false. - if (peeked[1] === LINE_FEED) { + if (reader.peekedTwo === LINE_FEED) { return false; } diff --git a/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts b/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts index f24fabf56..aafe2a5dd 100644 --- a/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts +++ b/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts @@ -4,12 +4,11 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments export function checkIfTwoCodePointsStartAComment(ctx: Context, reader: CodePointReader): boolean { - const peeked = reader.peekTwoCodePoints(); - if (peeked[0] !== SOLIDUS) { + if (reader.peekedOne !== SOLIDUS) { return false; } - if (peeked[1] !== ASTERISK) { + if (reader.peekedTwo !== ASTERISK) { return false; } diff --git a/packages/css-tokenizer/src/code-points/code-points-to-string.ts b/packages/css-tokenizer/src/code-points/code-points-to-string.ts deleted file mode 100644 index 33b808d06..000000000 --- a/packages/css-tokenizer/src/code-points/code-points-to-string.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function codePointsToString(codePoints: Array): string { - let result = ''; - - for (let i = 0; i < codePoints.length; i++) { - result += String.fromCharCode(codePoints[i]); - } - - return result; -} diff --git a/packages/css-tokenizer/src/consume/bad-url.ts b/packages/css-tokenizer/src/consume/bad-url.ts index 40a44f9ab..a97d5b2f1 100644 --- a/packages/css-tokenizer/src/consume/bad-url.ts +++ b/packages/css-tokenizer/src/consume/bad-url.ts @@ -8,12 +8,11 @@ import { consumeEscapedCodePoint } from './escaped-code-point'; export function consumeBadURL(ctx: Context, reader: CodePointReader) { // eslint-disable-next-line no-constant-condition while (true) { - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { + if (reader.peekedOne === undefined) { return; } - if (peeked === RIGHT_PARENTHESIS) { + if (reader.peekedOne === RIGHT_PARENTHESIS) { reader.readCodePoint(); return; } diff --git a/packages/css-tokenizer/src/consume/comment.ts b/packages/css-tokenizer/src/consume/comment.ts index c6c6191da..cf79189c1 100644 --- a/packages/css-tokenizer/src/consume/comment.ts +++ b/packages/css-tokenizer/src/consume/comment.ts @@ -5,18 +5,16 @@ import { TokenComment, TokenType } from '../interfaces/token'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment export function consumeComment(ctx: Context, reader: CodePointReader): TokenComment { - reader.readCodePoint(); - reader.readCodePoint(); + reader.readCodePoint(2); // eslint-disable-next-line no-constant-condition while (true) { const codePoint = reader.readCodePoint(); if (codePoint === false) { - const representation = reader.representation(); ctx.onParseError({ message: 'Unexpected EOF while consuming a comment.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.2. Consume comments', 'Unexpected EOF', @@ -30,23 +28,21 @@ export function consumeComment(ctx: Context, reader: CodePointReader): TokenComm continue; } - const close = reader.peekOneCodePoint(); - if (close === false) { + if (reader.peekedOne === undefined) { continue; } - if (close === SOLIDUS) { + if (reader.peekedOne === SOLIDUS) { reader.readCodePoint(); break; } } - const representation = reader.representation(); return [ TokenType.Comment, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, undefined, ]; } diff --git a/packages/css-tokenizer/src/consume/escaped-code-point.ts b/packages/css-tokenizer/src/consume/escaped-code-point.ts index 0f2f6d3a5..557dc4e7d 100644 --- a/packages/css-tokenizer/src/consume/escaped-code-point.ts +++ b/packages/css-tokenizer/src/consume/escaped-code-point.ts @@ -1,5 +1,4 @@ import { MAXIMUM_ALLOWED_CODEPOINT, REPLACEMENT_CHARACTER } from '../code-points/code-points'; -import { codePointsToString } from '../code-points/code-points-to-string'; import { isHexDigitCodePoint, isSurrogate, isWhitespace } from '../code-points/ranges'; import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; @@ -8,11 +7,10 @@ import { Context } from '../interfaces/context'; export function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): number { const codePoint = reader.readCodePoint(); if (codePoint === false) { - const representation = reader.representation(); ctx.onParseError({ message: 'Unexpected EOF while consuming an escaped code point.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.7. Consume an escaped code point', 'Unexpected EOF', @@ -25,18 +23,16 @@ export function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): if (isHexDigitCodePoint(codePoint)) { const hexSequence: Array = [codePoint]; - let peeked = reader.peekOneCodePoint(); - while (peeked !== false && isHexDigitCodePoint(peeked) && hexSequence.length < 6) { + while ((typeof reader.peekedOne !== 'undefined') && isHexDigitCodePoint(reader.peekedOne) && hexSequence.length < 6) { + hexSequence.push(reader.peekedOne); reader.readCodePoint(); - hexSequence.push(peeked); - peeked = reader.peekOneCodePoint(); } - if (peeked !== false && isWhitespace(peeked)) { + if (isWhitespace(reader.peekedOne)) { reader.readCodePoint(); } - const codePointLiteral = parseInt(codePointsToString(hexSequence), 16); + const codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16); if (codePointLiteral === 0) { return REPLACEMENT_CHARACTER; } diff --git a/packages/css-tokenizer/src/consume/hash-token.ts b/packages/css-tokenizer/src/consume/hash-token.ts index 96bb2eb70..b74470a5e 100644 --- a/packages/css-tokenizer/src/consume/hash-token.ts +++ b/packages/css-tokenizer/src/consume/hash-token.ts @@ -1,6 +1,5 @@ import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence'; import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape'; -import { codePointsToString } from '../code-points/code-points-to-string'; import { isIdentCodePoint } from '../code-points/ranges'; import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; @@ -11,10 +10,9 @@ import { consumeIdentSequence } from './ident-sequence'; export function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDelim|TokenHash { reader.readCodePoint(); - const peeked = reader.peekOneCodePoint(); if ( - peeked !== false && - isIdentCodePoint(peeked) || + (typeof reader.peekedOne !== 'undefined') && + isIdentCodePoint(reader.peekedOne) || checkIfTwoCodePointsAreAValidEscape(ctx, reader) ) { let hashType = HashType.Unrestricted; @@ -24,25 +22,23 @@ export function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDe } const identSequence = consumeIdentSequence(ctx, reader); - const representation = reader.representation(); return [ TokenType.Hash, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { - value: codePointsToString(identSequence), + value: String.fromCharCode(...identSequence), type: hashType, }, ]; } - const representation = reader.representation(); return [ TokenType.Delim, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: '#', }, diff --git a/packages/css-tokenizer/src/consume/ident-like-token.ts b/packages/css-tokenizer/src/consume/ident-like-token.ts index bca0d4a30..7c326911d 100644 --- a/packages/css-tokenizer/src/consume/ident-like-token.ts +++ b/packages/css-tokenizer/src/consume/ident-like-token.ts @@ -1,6 +1,5 @@ import { checkIfCodePointsMatchURLIdent } from '../checks/matches-url-ident'; import { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK } from '../code-points/code-points'; -import { codePointsToString } from '../code-points/code-points-to-string'; import { isWhitespace } from '../code-points/ranges'; import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; @@ -11,39 +10,35 @@ import { consumeUrlToken } from './url-token'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): TokenIdent | TokenFunction | TokenURL | TokenBadURL { const codePoints = consumeIdentSequence(ctx, reader); - const peeked = reader.peekOneCodePoint(); - if (peeked === LEFT_PARENTHESIS) { + if (reader.peekedOne === LEFT_PARENTHESIS) { if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { reader.readCodePoint(); let read = 0; // eslint-disable-next-line no-constant-condition while (true) { - const peeked2 = reader.peekTwoCodePoints(); - const firstIsWhitespace = isWhitespace(peeked2[0]); - const secondIsWhitespace = isWhitespace(peeked2[1]); + const firstIsWhitespace = isWhitespace(reader.peekedOne); + const secondIsWhitespace = isWhitespace(reader.peekedTwo); if (firstIsWhitespace && secondIsWhitespace) { read += 2; - reader.readCodePoint(); - reader.readCodePoint(); + reader.readCodePoint(2); continue; } - const firstNonWhitespace = firstIsWhitespace ? peeked2[1] : peeked2[0]; + const firstNonWhitespace = firstIsWhitespace ? reader.peekedTwo : reader.peekedOne; if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { for (let i = 0; i < read; i++) { reader.unreadCodePoint(); } - const representation = reader.representation(); return [ TokenType.Function, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { - value: codePointsToString(codePoints), + value: String.fromCharCode(...codePoints), }, ]; } @@ -59,26 +54,24 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To } reader.readCodePoint(); - const representation = reader.representation(); return [ TokenType.Function, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { - value: codePointsToString(codePoints), + value: String.fromCharCode(...codePoints), }, ]; } - const representation = reader.representation(); return [ TokenType.Ident, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { - value: codePointsToString(codePoints), + value: String.fromCharCode(...codePoints), }, ]; } diff --git a/packages/css-tokenizer/src/consume/ident-sequence.ts b/packages/css-tokenizer/src/consume/ident-sequence.ts index ee4dfc696..3d118bfad 100644 --- a/packages/css-tokenizer/src/consume/ident-sequence.ts +++ b/packages/css-tokenizer/src/consume/ident-sequence.ts @@ -11,18 +11,17 @@ export function consumeIdentSequence(ctx: Context, reader: CodePointReader): Arr // eslint-disable-next-line no-constant-condition while (true) { - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { + if (reader.peekedOne === undefined) { return result; } - if (isIdentCodePoint(peeked)) { + if (isIdentCodePoint(reader.peekedOne)) { + result.push(reader.peekedOne); reader.readCodePoint(); - result.push(peeked); continue; } - if (peeked === REVERSE_SOLIDUS && checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + if (reader.peekedOne === REVERSE_SOLIDUS && checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { reader.readCodePoint(); result.push(consumeEscapedCodePoint(ctx, reader)); continue; diff --git a/packages/css-tokenizer/src/consume/number.ts b/packages/css-tokenizer/src/consume/number.ts index 00bd0659f..442736e5e 100644 --- a/packages/css-tokenizer/src/consume/number.ts +++ b/packages/css-tokenizer/src/consume/number.ts @@ -1,5 +1,4 @@ import { FULL_STOP, HYPHEN_MINUS, LATIN_CAPITAL_LETTER_E, LATIN_SMALL_LETTER_E, PLUS_SIGN } from '../code-points/code-points'; -import { codePointsToString } from '../code-points/code-points-to-string'; import { isDigitCodePoint } from '../code-points/ranges'; import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; @@ -14,10 +13,9 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N { // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr. - const peeked = reader.peekOneCodePoint(); - if (peeked === PLUS_SIGN || peeked === HYPHEN_MINUS) { + if (reader.peekedOne === PLUS_SIGN || reader.peekedOne === HYPHEN_MINUS) { + repr.push(reader.peekedOne); reader.readCodePoint(); - repr.push(peeked); } // 3. While the next input code point is a digit, consume it and append it to repr. @@ -29,15 +27,13 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N { // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then: - const peeked = reader.peekTwoCodePoints(); - if (peeked[0] === FULL_STOP && isDigitCodePoint(peeked[1])) { - // 4.1. Consume them. - reader.readCodePoint(); - reader.readCodePoint(); - + if (reader.peekedOne === FULL_STOP && isDigitCodePoint(reader.peekedTwo)) { // 4.2. Append them to repr. - repr.push(peeked[0]); - repr.push(peeked[1]); + repr.push(reader.peekedOne); + repr.push(reader.peekedTwo); + + // 4.1. Consume them. + reader.readCodePoint(2); // 4.3. Set type to "number". type = NumberType.Number; @@ -54,18 +50,16 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N // 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), // optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+), // followed by a digit, then: - const peeked = reader.peekThreeCodePoints(); if ( - (peeked[0] === LATIN_SMALL_LETTER_E || peeked[0] === LATIN_CAPITAL_LETTER_E) && - isDigitCodePoint(peeked[1]) + (reader.peekedOne === LATIN_SMALL_LETTER_E || reader.peekedOne === LATIN_CAPITAL_LETTER_E) && + isDigitCodePoint(reader.peekedTwo) ) { - // 5.1. Consume them. - reader.readCodePoint(); - reader.readCodePoint(); - // 5.2. Append them to repr. - repr.push(peeked[0]); - repr.push(peeked[1]); + repr.push(reader.peekedOne); + repr.push(reader.peekedTwo); + + // 5.1. Consume them. + reader.readCodePoint(2); // 5.3. Set type to "number". type = NumberType.Number; @@ -78,21 +72,19 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N } if ( - (peeked[0] === LATIN_SMALL_LETTER_E || peeked[0] === LATIN_CAPITAL_LETTER_E) && + (reader.peekedOne === LATIN_SMALL_LETTER_E || reader.peekedOne === LATIN_CAPITAL_LETTER_E) && ( - (peeked[1] === HYPHEN_MINUS || peeked[1] === PLUS_SIGN) && - isDigitCodePoint(peeked[2]) + (reader.peekedTwo === HYPHEN_MINUS || reader.peekedTwo === PLUS_SIGN) && + isDigitCodePoint(reader.peekedThree) ) ) { - // 5.1. Consume them. - reader.readCodePoint(); - reader.readCodePoint(); - reader.readCodePoint(); - // 5.2. Append them to repr. - repr.push(peeked[0]); - repr.push(peeked[1]); - repr.push(peeked[2]); + repr.push(reader.peekedOne); + repr.push(reader.peekedTwo); + repr.push(reader.peekedThree); + + // 5.1. Consume them. + reader.readCodePoint(3); // 5.3. Set type to "number". type = NumberType.Number; @@ -117,13 +109,12 @@ function consumeDigits(reader: CodePointReader): Array { // eslint-disable-next-line no-constant-condition while (true) { - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { + if (reader.peekedOne === undefined) { return value; } - if (isDigitCodePoint(peeked)) { - value.push(peeked); + if (isDigitCodePoint(reader.peekedOne)) { + value.push(reader.peekedOne); reader.readCodePoint(); } else { return value; @@ -221,7 +212,7 @@ function digitCodePointsToInteger(codePoints: Array): number { return 0; } - const stringValue = codePointsToString(codePoints); + const stringValue = String.fromCharCode(...codePoints); const integerValue = Number.parseInt(stringValue, 10); if (Number.isNaN(integerValue)) { diff --git a/packages/css-tokenizer/src/consume/numeric-token.ts b/packages/css-tokenizer/src/consume/numeric-token.ts index f039c1795..9f70ebd44 100644 --- a/packages/css-tokenizer/src/consume/numeric-token.ts +++ b/packages/css-tokenizer/src/consume/numeric-token.ts @@ -1,6 +1,5 @@ import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence'; import { PERCENTAGE_SIGN } from '../code-points/code-points'; -import { codePointsToString } from '../code-points/code-points-to-string'; import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; import { TokenDimension, TokenNumber, TokenPercentage, TokenType } from '../interfaces/token'; @@ -14,31 +13,28 @@ export function consumeNumericToken(ctx: Context, reader: CodePointReader): Toke if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { const unit = consumeIdentSequence(ctx, reader); - const representation = reader.representation(); return [ TokenType.Dimension, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: numberValue[0], type: numberValue[1], - unit: codePointsToString(unit), + unit: String.fromCharCode(...unit), }, ]; } { - const peeked = reader.peekOneCodePoint(); - if (peeked === PERCENTAGE_SIGN) { + if (reader.peekedOne === PERCENTAGE_SIGN) { reader.readCodePoint(); - const representation = reader.representation(); return [ TokenType.Percentage, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: numberValue[0], }, @@ -46,12 +42,11 @@ export function consumeNumericToken(ctx: Context, reader: CodePointReader): Toke } } - const representation = reader.representation(); return [ TokenType.Number, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: numberValue[0], type: numberValue[1], diff --git a/packages/css-tokenizer/src/consume/string-token.ts b/packages/css-tokenizer/src/consume/string-token.ts index fcadd2fc4..82767905d 100644 --- a/packages/css-tokenizer/src/consume/string-token.ts +++ b/packages/css-tokenizer/src/consume/string-token.ts @@ -18,27 +18,25 @@ export function consumeStringToken(ctx: Context, reader: CodePointReader): Token while (true) { const next = reader.readCodePoint(); if (next === false) { - const representation = reader.representation(); ctx.onParseError({ message: 'Unexpected EOF while consuming a string token.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.5. Consume a string token', 'Unexpected EOF', ], }); - return [TokenType.String, reader.representationString(), representation[0], representation[1], { value: result }]; + return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }]; } if (isNewLine(next)) { - const representation = reader.representation(); { ctx.onParseError({ message: 'Unexpected newline while consuming a string token.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.5. Consume a string token', 'Unexpected newline', @@ -47,21 +45,19 @@ export function consumeStringToken(ctx: Context, reader: CodePointReader): Token } reader.unreadCodePoint(); - return [TokenType.BadString, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } if (next === first) { - const representation = reader.representation(); - return [TokenType.String, reader.representationString(), representation[0], representation[1], { value: result }]; + return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }]; } if (next === REVERSE_SOLIDUS) { - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { + if (reader.peekedOne === undefined) { continue; } - if (isNewLine(peeked)) { + if (isNewLine(reader.peekedOne)) { reader.readCodePoint(); continue; } diff --git a/packages/css-tokenizer/src/consume/url-token.ts b/packages/css-tokenizer/src/consume/url-token.ts index 961e3f953..918b83a61 100644 --- a/packages/css-tokenizer/src/consume/url-token.ts +++ b/packages/css-tokenizer/src/consume/url-token.ts @@ -15,13 +15,11 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL // eslint-disable-next-line no-constant-condition while (true) { - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { - const representation = reader.representation(); + if (reader.peekedOne === undefined) { ctx.onParseError({ message: 'Unexpected EOF while consuming a url token.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.6. Consume a url token', 'Unexpected EOF', @@ -31,37 +29,34 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.URL, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: string, }, ]; } - if (peeked === RIGHT_PARENTHESIS) { + if (reader.peekedOne === RIGHT_PARENTHESIS) { reader.readCodePoint(); - const representation = reader.representation(); return [ TokenType.URL, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: string, }, ]; } - if (isWhitespace(peeked)) { + if (isWhitespace(reader.peekedOne)) { consumeWhiteSpace(ctx, reader); - const peeked2 = reader.peekOneCodePoint(); - if (peeked2 === false) { - const representation = reader.representation(); + if (reader.peekedOne === undefined) { ctx.onParseError({ message: 'Unexpected EOF while consuming a url token.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.6. Consume a url token', 'Consume as much whitespace as possible', @@ -72,22 +67,21 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.URL, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: string, }, ]; } - if (peeked2 === RIGHT_PARENTHESIS) { + if (reader.peekedOne === RIGHT_PARENTHESIS) { reader.readCodePoint(); - const representation = reader.representation(); return [ TokenType.URL, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, { value: string, }, @@ -95,24 +89,22 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL } consumeBadURL(ctx, reader); - const representation = reader.representation(); return [ TokenType.BadURL, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, undefined, ]; } - if (peeked === QUOTATION_MARK || peeked === APOSTROPHE || peeked === LEFT_PARENTHESIS || isNonPrintableCodePoint(peeked)) { + if (reader.peekedOne === QUOTATION_MARK || reader.peekedOne === APOSTROPHE || reader.peekedOne === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.peekedOne)) { consumeBadURL(ctx, reader); - const representation = reader.representation(); ctx.onParseError({ message: 'Unexpected character while consuming a url token.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.6. Consume a url token', 'Unexpected U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE (\'), U+0028 LEFT PARENTHESIS (() or non-printable code point', @@ -122,13 +114,13 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.BadURL, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, undefined, ]; } - if (peeked === REVERSE_SOLIDUS) { + if (reader.peekedOne === REVERSE_SOLIDUS) { if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { string += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); continue; @@ -136,11 +128,10 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL consumeBadURL(ctx, reader); - const representation = reader.representation(); ctx.onParseError({ message: 'Invalid escape sequence while consuming a url token.', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.6. Consume a url token', 'U+005C REVERSE SOLIDUS (\\)', @@ -151,13 +142,13 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.BadURL, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, undefined, ]; } + string += String.fromCharCode(reader.peekedOne); reader.readCodePoint(); - string += String.fromCharCode(peeked); } } diff --git a/packages/css-tokenizer/src/consume/whitespace-token.ts b/packages/css-tokenizer/src/consume/whitespace-token.ts index e6febd985..addec8aaf 100644 --- a/packages/css-tokenizer/src/consume/whitespace-token.ts +++ b/packages/css-tokenizer/src/consume/whitespace-token.ts @@ -9,42 +9,38 @@ export function consumeWhiteSpace(ctx: Context, reader: CodePointReader, max = - // eslint-disable-next-line no-constant-condition while (true) { if (max !== -1 && current === max) { - const representation = reader.representation(); return [ TokenType.Whitespace, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, undefined, ]; } current++; - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { - const representation = reader.representation(); + if (reader.peekedOne === undefined) { return [ TokenType.Whitespace, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, undefined, ]; } - if (!isWhitespace(peeked)) { + if (!isWhitespace(reader.peekedOne)) { break; } reader.readCodePoint(); } - const representation = reader.representation(); return [ TokenType.Whitespace, reader.representationString(), - representation[0], - representation[1], + reader.representationStart, + reader.representationEnd, undefined, ]; } diff --git a/packages/css-tokenizer/src/interfaces/code-point-reader.ts b/packages/css-tokenizer/src/interfaces/code-point-reader.ts index 6f1c8b216..95fc4f639 100644 --- a/packages/css-tokenizer/src/interfaces/code-point-reader.ts +++ b/packages/css-tokenizer/src/interfaces/code-point-reader.ts @@ -5,17 +5,19 @@ // A char code in JS is equivalent to a code point from the CSS Specification. export type CodePointReader = { - cursorPositionOfLastReadCodePoint(): number; + representationStart: number; + representationEnd: number; + + peekedOne: number | undefined; + peekedTwo: number | undefined; + peekedThree: number | undefined; + peekedFour: number | undefined; - peekOneCodePoint(): number | false - peekTwoCodePoints(): [number, number] | [number] | [] - peekThreeCodePoints(): [number, number, number] | [number, number] | [number] | [] - peekFourCodePoints(): [number, number, number, number] | [number, number, number] | [number, number] | [number] | [] + cursorPositionOfLastReadCodePoint(): number; - readCodePoint(): number | false + readCodePoint(n?: number): number | false unreadCodePoint(): boolean - representation(): [number, number] representationString(): string resetRepresentation() diff --git a/packages/css-tokenizer/src/reader.ts b/packages/css-tokenizer/src/reader.ts index bc55dface..88eb34946 100644 --- a/packages/css-tokenizer/src/reader.ts +++ b/packages/css-tokenizer/src/reader.ts @@ -1,140 +1,86 @@ import { CodePointReader } from './interfaces/code-point-reader'; export class Reader implements CodePointReader { - #cursor: number; - #stringSource = ''; - #codePointSource: Array = []; - #length = 0; + cursor: number; + stringSource = ''; + codePointSource: Array = []; + length = 0; - #representationStart = 0; - #representationEnd = -1; + representationStart = 0; + representationEnd = -1; - constructor(source: string) { - this.#cursor = 0; - this.#stringSource = source; - this.#length = source.length; - - this.#codePointSource = new Array(this.#length); - for (let i = 0; i < this.#length; i++) { - this.#codePointSource[i] = this.#stringSource.charCodeAt(i); - } - } - - cursorPositionOfLastReadCodePoint(): number { - return this.#cursor - 1; - } - - peekOneCodePoint(): number | false { - const first = this.#codePointSource[this.#cursor]; - if (typeof first === 'undefined') { - return false; - } - - return first; - } - - peekTwoCodePoints(): [number, number] | [number] | [] { - const first = this.#codePointSource[this.#cursor]; - if (typeof first === 'undefined') { - return []; - } - - const second = this.#codePointSource[this.#cursor + 1]; - if (typeof second === 'undefined') { - return [first]; - } - - return [first, second]; - } + peekedOne: number | undefined; + peekedTwo: number | undefined; + peekedThree: number | undefined; - peekThreeCodePoints(): [number, number, number] | [number, number] | [number] | [] { - const first = this.#codePointSource[this.#cursor]; - if (typeof first === 'undefined') { - return []; - } - - const second = this.#codePointSource[this.#cursor + 1]; - if (typeof second === 'undefined') { - return [first]; - } + constructor(source: string) { + this.cursor = 0; + this.stringSource = source; + this.length = source.length; - const third = this.#codePointSource[this.#cursor + 2]; - if (typeof third === 'undefined') { - return [first, second]; + this.codePointSource = new Array(this.length); + for (let i = 0; i < this.length; i++) { + this.codePointSource[i] = this.stringSource.charCodeAt(i); } - return [first, second, third]; + this.peekedOne = this.codePointSource[this.cursor]; + this.peekedTwo = this.codePointSource[this.cursor + 1]; + this.peekedThree = this.codePointSource[this.cursor + 2]; + this.peekedFour = this.codePointSource[this.cursor + 3]; } + peekedFour: number; - peekFourCodePoints(): [number, number, number, number] | [number, number, number] | [number, number] | [number] | [] { - const first = this.#codePointSource[this.#cursor]; - if (typeof first === 'undefined') { - return []; - } - - const second = this.#codePointSource[this.#cursor + 1]; - if (typeof second === 'undefined') { - return [first]; - } - - const third = this.#codePointSource[this.#cursor + 2]; - if (typeof third === 'undefined') { - return [first, second]; - } - - const fourth = this.#codePointSource[this.#cursor + 2]; - if (typeof fourth === 'undefined') { - return [first, second, third]; - } - - return [first, second, third, fourth]; + cursorPositionOfLastReadCodePoint(): number { + return this.cursor - 1; } - readCodePoint(): number | false { - const codePoint = this.#codePointSource[this.#cursor]; + readCodePoint(n = 1): number | false { + const codePoint = this.codePointSource[this.cursor]; if (typeof codePoint === 'undefined') { return false; } - this.#representationEnd = this.#cursor; - this.#cursor += 1; + this.cursor += n; + this.representationEnd = this.cursor - 1; + + this.peekedOne = this.codePointSource[this.cursor]; + this.peekedTwo = this.codePointSource[this.cursor + 1]; + this.peekedThree = this.codePointSource[this.cursor + 2]; + this.peekedFour = this.codePointSource[this.cursor + 3]; return codePoint; } unreadCodePoint(): boolean { - if (this.#cursor === 0) { + if (this.cursor === 0) { return false; } - this.#representationEnd = this.#cursor - 1; - this.#cursor -= 1; + this.representationEnd = this.cursor - 1; + this.cursor -= 1; - return true; - } + this.peekedOne = this.codePointSource[this.cursor]; + this.peekedTwo = this.codePointSource[this.cursor + 1]; + this.peekedThree = this.codePointSource[this.cursor + 2]; + this.peekedFour = this.codePointSource[this.cursor + 3]; - representation(): [number, number] { - return [ - this.#representationStart, - this.#representationEnd, - ]; + return true; } representationString(): string { - const representation = this.representation(); - if (representation[1] === -1) { + if (this.representationEnd === -1) { return ''; } - return this.slice(representation[0], representation[1] + 1); + return this.stringSource.slice(this.representationStart, this.representationEnd + 1); } resetRepresentation() { - this.#representationStart = this.#cursor; - this.#representationEnd = -1; + this.representationStart = this.cursor; + this.representationEnd = -1; } slice(start: number, end: number): string { - return this.#stringSource.slice(start, end); + return this.stringSource.slice(start, end); } } diff --git a/packages/css-tokenizer/src/tokenizer.ts b/packages/css-tokenizer/src/tokenizer.ts index 6a4d9ee7b..7e12d3183 100644 --- a/packages/css-tokenizer/src/tokenizer.ts +++ b/packages/css-tokenizer/src/tokenizer.ts @@ -16,7 +16,6 @@ import { consumeStringToken } from './consume/string-token'; import { consumeIdentLikeToken } from './consume/ident-like-token'; import { checkIfTwoCodePointsAreAValidEscape } from './checks/two-code-points-are-valid-escape'; import { ParserError } from './interfaces/error'; -import { codePointsToString } from './code-points/code-points-to-string'; interface Stringer { valueOf(): string @@ -32,7 +31,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken }; function endOfFile() { - return reader.peekOneCodePoint() === false; + return reader.peekedOne === undefined; } function nextToken(): CSSToken | undefined { @@ -47,9 +46,8 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } reader.resetRepresentation(); - - const peeked = reader.peekOneCodePoint(); - if (peeked === false) { + const peeked = reader.peekedOne; + if (peeked === undefined) { return [TokenType.EOF, '', -1, -1, undefined]; } @@ -57,52 +55,40 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken switch (peeked) { case COMMA: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.Comma, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case COLON: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.Colon, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case SEMICOLON: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.Semicolon, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case LEFT_PARENTHESIS: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.OpenParen, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case RIGHT_PARENTHESIS: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.CloseParen, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case LEFT_SQUARE_BRACKET: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.OpenSquare, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case RIGHT_SQUARE_BRACKET: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.CloseSquare, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case LEFT_CURLY_BRACKET: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.OpenCurly, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case RIGHT_CURLY_BRACKET: { reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.CloseCurly, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } - } - - switch (peeked) { case APOSTROPHE: case QUOTATION_MARK: return consumeStringToken(ctx, reader); @@ -116,8 +102,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.Delim, reader.representationString(), representation[0], representation[1], { + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: String.fromCharCode(peeked), }]; } @@ -128,12 +113,9 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } if (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) { - reader.readCodePoint(); - reader.readCodePoint(); - reader.readCodePoint(); + reader.readCodePoint(3); - const representation = reader.representation(); - return [TokenType.CDC, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { @@ -141,26 +123,20 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.Delim, reader.representationString(), representation[0], representation[1], { + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: '-', }]; } case LESS_THAN_SIGN: { if (checkIfFourCodePointsWouldStartCDO(ctx, reader)) { - reader.readCodePoint(); - reader.readCodePoint(); - reader.readCodePoint(); - reader.readCodePoint(); + reader.readCodePoint(4); - const representation = reader.representation(); - return [TokenType.CDO, reader.representationString(), representation[0], representation[1], undefined]; + return [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.Delim, reader.representationString(), representation[0], representation[1], { + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: '<', }]; } @@ -170,14 +146,12 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { const identSequence = consumeIdentSequence(ctx, reader); - const representation = reader.representation(); - return [TokenType.AtKeyword, reader.representationString(), representation[0], representation[1], { - value: codePointsToString(identSequence), + return [TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...identSequence), }]; } - const representation = reader.representation(); - return [TokenType.Delim, reader.representationString(), representation[0], representation[1], { + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: '@', }]; } @@ -189,11 +163,10 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken reader.readCodePoint(); - const representation = reader.representation(); ctx.onParseError({ message: 'Invalid escape sequence after "\\"', - start: representation[0], - end: representation[1], + start: reader.representationStart, + end: reader.representationEnd, state: [ '4.3.1. Consume a token', 'U+005C REVERSE SOLIDUS (\\)', @@ -201,7 +174,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken ], }); - return [TokenType.Delim, reader.representationString(), representation[0], representation[1], { + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: '\\', }]; } @@ -220,8 +193,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } reader.readCodePoint(); - const representation = reader.representation(); - return [TokenType.Delim, reader.representationString(), representation[0], representation[1], { + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: String.fromCharCode(peeked), }]; } diff --git a/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs b/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs index bfd9d3598..bb595f905 100644 --- a/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs +++ b/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs @@ -2,9 +2,46 @@ import { tokenizer, TokenType } from '@csstools/css-tokenizer'; import postcssTokenizer from 'postcss/lib/tokenize'; import fs from 'fs'; -function csstoolsLargeSource() { - const source = fs.readFileSync('./test/community/bootstrap.css').toString(); +const bootstrapSource = fs.readFileSync('./test/community/bootstrap.css').toString(); +const openPropsSource = fs.readFileSync('./test/community/open-props.css').toString(); + +const largeSource = ` +/* a comment */ + + +--> +/* more comments */ + +.foo { + image: url(https://example.com/foo.jpg); + image: url("https://example.com/foo.jpg"); +} + +.foo { + image: url((); +} + +.foo { + content: "foo +bar"; +} + +#1 {} + +#foo {} + +.foo { + margin: 0; + margin: 1px; + line-height: 1%; + line-height: 1.2; +} +${bootstrapSource} +${openPropsSource} +`; + +function csstoolsLargeSource() { const results = []; let tokenStreamLength = 0; @@ -14,11 +51,11 @@ function csstoolsLargeSource() { { const t = tokenizer( { - css: source, + css: largeSource, }, { - onParseError: (err) => { - throw new Error(JSON.stringify(err)); + onParseError: () => { + // noop }, }, ); @@ -48,10 +85,11 @@ function csstoolsLargeSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); + console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); console.log('-----------------------------------------------'); console.log('95th', results[949]); - console.log('90th', results[899]); console.log('50th', results[499]); + console.log('5th', results[49]); console.log('deviation', results[949] - results[49]); } @@ -124,16 +162,15 @@ function csstoolsSmallSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); + console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); console.log('-----------------------------------------------'); console.log('95th', results[949]); - console.log('90th', results[899]); console.log('50th', results[499]); + console.log('5th', results[49]); console.log('deviation', results[949] - results[49]); } function postcssLargeSource() { - const source = fs.readFileSync('./test/community/bootstrap.css').toString(); - const results = []; let tokenStreamLength = 0; @@ -142,7 +179,7 @@ function postcssLargeSource() { { const t = postcssTokenizer( { - css: source, + css: largeSource, }, ); @@ -171,10 +208,11 @@ function postcssLargeSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('----------------------------------------------'); + console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); + console.log('-----------------------------------------------'); console.log('95th', results[949]); - console.log('90th', results[899]); console.log('50th', results[499]); + console.log('5th', results[49]); console.log('deviation', results[949] - results[49]); } @@ -241,17 +279,23 @@ function postcssSmallSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('----------------------------------------------'); + console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); + console.log('-----------------------------------------------'); console.log('95th', results[949]); - console.log('90th', results[899]); console.log('50th', results[499]); + console.log('5th', results[49]); console.log('deviation', results[949] - results[49]); } -csstoolsLargeSource(); +await new Promise((resolve) => setTimeout(resolve(), 1000)); csstoolsSmallSource(); -postcssLargeSource(); +await new Promise((resolve) => setTimeout(resolve(), 1000)); postcssSmallSource(); +await new Promise((resolve) => setTimeout(resolve(), 1000)); +csstoolsLargeSource(); +await new Promise((resolve) => setTimeout(resolve(), 1000)); +postcssLargeSource(); +await new Promise((resolve) => setTimeout(resolve(), 1000)); // Last result: // -------------- csstools tokenizer ------------- diff --git a/packages/css-tokenizer/test/inspect.mjs b/packages/css-tokenizer/test/inspect.mjs new file mode 100644 index 000000000..6cf401d40 --- /dev/null +++ b/packages/css-tokenizer/test/inspect.mjs @@ -0,0 +1,61 @@ +import { tokenizer, TokenType } from '@csstools/css-tokenizer'; +import fs from 'fs'; + +const bootstrapSource = fs.readFileSync('./test/community/bootstrap.css').toString(); +const openPropsSource = fs.readFileSync('./test/community/open-props.css').toString(); + +const source = ` +/* a comment */ + + +--> +/* more comments */ + +.foo { + image: url(https://example.com/foo.jpg); + image: url("https://example.com/foo.jpg"); +} + +.foo { + image: url((); +} + +.foo { + content: "foo +bar"; +} + +#1 {} + +#foo {} + +.foo { + margin: 0; + margin: 1px; + line-height: 1%; + line-height: 1.2; +} + +${bootstrapSource} +${openPropsSource} +`; + +// eslint-disable-next-line no-constant-condition +while (true) { + const t = tokenizer( + { + css: source, + }, + { + commentsAreTokens: true, + onParseError: () => { + // noop + }, + }, + ); + + // eslint-disable-next-line no-constant-condition + while (t.nextToken()[0] !== TokenType.EOF) { + // noop + } +} diff --git a/packages/css-tokenizer/test/test-reader.mjs b/packages/css-tokenizer/test/test-reader.mjs index 69c59e706..8cf0fcc34 100644 --- a/packages/css-tokenizer/test/test-reader.mjs +++ b/packages/css-tokenizer/test/test-reader.mjs @@ -5,7 +5,7 @@ import { Reader } from '@csstools/css-tokenizer'; const r = new Reader('abc👨‍👨‍👧‍👦d'); { - const peeked = r.peekOneCodePoint(); + const peeked = r.peekedOne; assert.deepEqual( peeked, 97, @@ -17,7 +17,10 @@ import { Reader } from '@csstools/css-tokenizer'; ); assert.deepEqual( - r.representation(), + [ + r.representationStart, + r.representationEnd, + ], [ 0, -1, @@ -26,7 +29,10 @@ import { Reader } from '@csstools/css-tokenizer'; } { - const peeked = r.peekTwoCodePoints(); + const peeked = [ + r.peekedOne, + r.peekedTwo, + ]; assert.deepEqual( peeked, [97, 98], @@ -43,7 +49,10 @@ import { Reader } from '@csstools/css-tokenizer'; ); assert.deepEqual( - r.representation(), + [ + r.representationStart, + r.representationEnd, + ], [ 0, -1, @@ -52,7 +61,11 @@ import { Reader } from '@csstools/css-tokenizer'; } { - const peeked = r.peekThreeCodePoints(); + const peeked = [ + r.peekedOne, + r.peekedTwo, + r.peekedThree, + ]; assert.deepEqual( peeked, [97, 98, 99], @@ -74,7 +87,10 @@ import { Reader } from '@csstools/css-tokenizer'; ); assert.deepEqual( - r.representation(), + [ + r.representationStart, + r.representationEnd, + ], [ 0, -1, @@ -95,7 +111,10 @@ import { Reader } from '@csstools/css-tokenizer'; ); assert.deepEqual( - r.representation(), + [ + r.representationStart, + r.representationEnd, + ], [ 0, 0, @@ -146,7 +165,10 @@ import { Reader } from '@csstools/css-tokenizer'; ); assert.deepEqual( - r.representation(), + [ + r.representationStart, + r.representationEnd, + ], [ 1, 4, @@ -166,7 +188,10 @@ import { Reader } from '@csstools/css-tokenizer'; r.readCodePoint(); assert.deepEqual( - r.representation(), + [ + r.representationStart, + r.representationEnd, + ], [ 1, 14, @@ -174,7 +199,7 @@ import { Reader } from '@csstools/css-tokenizer'; ); assert.deepEqual( - r.slice(r.representation()[0], r.representation()[1] + 1), + r.slice(r.representationStart, r.representationEnd + 1), 'bc👨‍👨‍👧‍👦d', ); From 7664d81f34eb54c0e4647b2c2a2a92c37294e0e3 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sun, 25 Dec 2022 00:03:39 +0100 Subject: [PATCH 05/24] improve performance --- .../dist/code-points/code-points.d.ts | 20 +++++ packages/css-tokenizer/dist/index.cjs | 2 +- packages/css-tokenizer/dist/index.mjs | 2 +- .../dist/interfaces/code-point-reader.d.ts | 8 +- packages/css-tokenizer/dist/reader.d.ts | 6 +- .../four-code-points-would-start-cdo.ts | 2 +- .../css-tokenizer/src/checks/next-is-eof.ts | 2 +- .../three-code-points-would-start-cdc.ts | 2 +- ...-code-points-would-start-ident-sequence.ts | 20 ++--- .../three-code-points-would-start-number.ts | 14 +-- .../two-code-points-are-valid-escape.ts | 4 +- .../checks/two-code-points-start-comment.ts | 4 +- .../src/code-points/code-points.ts | 20 +++++ .../css-tokenizer/src/code-points/ranges.ts | 53 +++--------- packages/css-tokenizer/src/consume/bad-url.ts | 4 +- packages/css-tokenizer/src/consume/comment.ts | 4 +- .../src/consume/escaped-code-point.ts | 6 +- .../css-tokenizer/src/consume/hash-token.ts | 4 +- .../src/consume/ident-like-token.ts | 86 +++++++++---------- .../src/consume/ident-sequence.ts | 9 +- packages/css-tokenizer/src/consume/number.ts | 45 ++++------ .../src/consume/numeric-token.ts | 2 +- .../css-tokenizer/src/consume/string-token.ts | 4 +- .../css-tokenizer/src/consume/url-token.ts | 16 ++-- .../src/consume/whitespace-token.ts | 4 +- .../src/interfaces/code-point-reader.ts | 8 +- packages/css-tokenizer/src/reader.ts | 26 +----- packages/css-tokenizer/src/tokenizer.ts | 44 ++++++---- packages/css-tokenizer/test/test-reader.mjs | 12 +-- 29 files changed, 207 insertions(+), 226 deletions(-) diff --git a/packages/css-tokenizer/dist/code-points/code-points.d.ts b/packages/css-tokenizer/dist/code-points/code-points.d.ts index 66cbce284..60e974351 100644 --- a/packages/css-tokenizer/dist/code-points/code-points.d.ts +++ b/packages/css-tokenizer/dist/code-points/code-points.d.ts @@ -76,3 +76,23 @@ export declare const SHIFT_OUT: number; export declare const SOLIDUS: number; /** \u20 */ export declare const SPACE: number; +/** 0 */ +export declare const DIGIT_0: number; +/** 1 */ +export declare const DIGIT_1: number; +/** 2 */ +export declare const DIGIT_2: number; +/** 3 */ +export declare const DIGIT_3: number; +/** 4 */ +export declare const DIGIT_4: number; +/** 5 */ +export declare const DIGIT_5: number; +/** 6 */ +export declare const DIGIT_6: number; +/** 7 */ +export declare const DIGIT_7: number; +/** 8 */ +export declare const DIGIT_8: number; +/** 9 */ +export declare const DIGIT_9: number; diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index cf0f9610b..106a040b0 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1 @@ -"use strict";class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;peekedOne;peekedTwo;peekedThree;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===y)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===S)}function isNewLine(e){switch(e){case A:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case A:case s:case h:case a:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.peekedOne===L&&t.peekedTwo!==A}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.peekedOne===S?t.peekedTwo===S||(!!isIdentStartCodePoint(t.peekedTwo)||t.peekedTwo===L&&t.peekedThree!==A):!!isIdentStartCodePoint(t.peekedOne)||t.peekedOne===L&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.peekedOne===U||t.peekedOne===S?!!isDigitCodePoint(t.peekedTwo)||t.peekedTwo===k&&isDigitCodePoint(t.peekedThree):t.peekedOne===k?isDigitCodePoint(t.peekedTwo):!!isDigitCodePoint(t.peekedOne)}function checkIfTwoCodePointsStartAComment(e,t){return t.peekedOne===B&&t.peekedTwo===o}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.peekedOne===S&&t.peekedTwo===S&&t.peekedThree===T}function consumeComment(e,t){for(t.readCodePoint(2);;){const n=t.readCodePoint();if(!1===n){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:t.representationStart,end:t.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(n===o&&(void 0!==t.peekedOne&&t.peekedOne===B)){t.readCodePoint();break}}return[exports.TokenType.Comment,t.representationString(),t.representationStart,t.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const n=t.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(n)){const e=[n];for(;void 0!==t.peekedOne&&isHexDigitCodePoint(t.peekedOne)&&e.length<6;)e.push(t.peekedOne),t.readCodePoint();isWhitespace(t.peekedOne)&&t.readCodePoint();const o=parseInt(String.fromCharCode(...e),16);return 0===o?b:G<=(r=o)&&r<=X||o>v?b:o}var r;return n}function consumeIdentSequence(e,t){const n=[];for(;;){if(void 0===t.peekedOne)return n;if(isIdentCodePoint(t.peekedOne))n.push(t.peekedOne),t.readCodePoint();else{if(t.peekedOne!==L||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(e,t){if(t.readCodePoint(),void 0!==t.peekedOne&&isIdentCodePoint(t.peekedOne)||checkIfTwoCodePointsAreAValidEscape(0,t)){let r=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,t)&&(r=n.ID);const o=consumeIdentSequence(e,t);return[exports.TokenType.Hash,t.representationString(),t.representationStart,t.representationEnd,{value:String.fromCharCode(...o),type:r}]}return[exports.TokenType.Delim,t.representationString(),t.representationStart,t.representationEnd,{value:"#"}]}function consumeNumber(e,t){let n=exports.NumberType.Integer;const r=[];{t.peekedOne!==U&&t.peekedOne!==S||(r.push(t.peekedOne),t.readCodePoint());const e=consumeDigits(t);for(let t=0;t{})};return{nextToken:function nextToken(){if(o.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,o)){if(null!=t&&t.commentsAreTokens)return consumeComment(i,o);consumeComment(i,o)}o.resetRepresentation();const e=o.peekedOne;if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];switch(e){case p:return o.readCodePoint(),[exports.TokenType.Comma,o.representationString(),o.representationStart,o.representationEnd,void 0];case d:return o.readCodePoint(),[exports.TokenType.Colon,o.representationString(),o.representationStart,o.representationEnd,void 0];case q:return o.readCodePoint(),[exports.TokenType.Semicolon,o.representationString(),o.representationStart,o.representationEnd,void 0];case g:return o.readCodePoint(),[exports.TokenType.OpenParen,o.representationString(),o.representationStart,o.representationEnd,void 0];case F:return o.readCodePoint(),[exports.TokenType.CloseParen,o.representationString(),o.representationStart,o.representationEnd,void 0];case O:return o.readCodePoint(),[exports.TokenType.OpenSquare,o.representationString(),o.representationStart,o.representationEnd,void 0];case W:return o.readCodePoint(),[exports.TokenType.CloseSquare,o.representationString(),o.representationStart,o.representationEnd,void 0];case P:return o.readCodePoint(),[exports.TokenType.OpenCurly,o.representationString(),o.representationStart,o.representationEnd,void 0];case R:return o.readCodePoint(),[exports.TokenType.CloseCurly,o.representationString(),o.representationStart,o.representationEnd,void 0];case r:case N:return consumeStringToken(i,o);case w:return consumeHashToken(i,o);case U:case k:return checkIfThreeCodePointsWouldStartANumber(0,o)?consumeNumericToken(i,o):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(e)}]);case S:return checkIfThreeCodePointsWouldStartANumber(0,o)?consumeNumericToken(i,o):checkIfThreeCodePointsWouldStartCDC(0,o)?(o.readCodePoint(3),[exports.TokenType.CDC,o.representationString(),o.representationStart,o.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)?consumeIdentLikeToken(i,o):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"-"}]);case E:return checkIfFourCodePointsWouldStartCDO(0,o)?(o.readCodePoint(4),[exports.TokenType.CDO,o.representationString(),o.representationStart,o.representationEnd,void 0]):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"<"}]);case c:if(o.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const e=consumeIdentSequence(i,o);return[exports.TokenType.AtKeyword,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"@"}];case L:return checkIfTwoCodePointsAreAValidEscape(0,o)?consumeIdentLikeToken(i,o):(o.readCodePoint(),i.onParseError({message:'Invalid escape sequence after "\\"',start:o.representationStart,end:o.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"\\"}])}return isWhitespace(e)?consumeWhiteSpace(0,o):isDigitCodePoint(e)?consumeNumericToken(i,o):isIdentStartCodePoint(e)?consumeIdentLikeToken(i,o):(o.readCodePoint(),[exports.TokenType.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(e)}])},endOfFile:function endOfFile(){return void 0===o.peekedOne}}}; +"use strict";class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=se}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===v)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===T)}function isNewLine(e){switch(e){case x:case s:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case x:case s:case S:case c:case H:return!0;default:return!1}}const ce="\ud800".charCodeAt(0),ae="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,r){return r.codePointSource[r.cursor]===N&&r.codePointSource[r.cursor+1]!==x}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,r){return r.codePointSource[r.cursor]===T?r.codePointSource[r.cursor+1]===T||(!!isIdentStartCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===N&&r.codePointSource[r.cursor+2]!==x):!!isIdentStartCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)}function checkIfThreeCodePointsWouldStartANumber(e,r){return r.codePointSource[r.cursor]===w||r.codePointSource[r.cursor]===T?!!isDigitCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===P&&isDigitCodePoint(r.codePointSource[r.cursor+2]):r.codePointSource[r.cursor]===P?isDigitCodePoint(r.codePointSource[r.cursor+1]):!!isDigitCodePoint(r.codePointSource[r.cursor])}function checkIfTwoCodePointsStartAComment(e,r){return r.codePointSource[r.cursor]===B&&r.codePointSource[r.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,r){return r.codePointSource[r.cursor]===T&&r.codePointSource[r.cursor+1]===T&&r.codePointSource[r.cursor+2]===h}function consumeComment(e,r){for(r.readCodePoint(2);;){const o=r.readCodePoint();if(!1===o){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:r.representationStart,end:r.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(o===n&&(void 0!==r.codePointSource[r.cursor]&&r.codePointSource[r.cursor]===B)){r.readCodePoint();break}}return[exports.TokenType.Comment,r.representationString(),r.representationStart,r.representationEnd,void 0]}function consumeEscapedCodePoint(e,r){const o=r.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:r.representationStart,end:r.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),L;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==r.codePointSource[r.cursor]&&isHexDigitCodePoint(r.codePointSource[r.cursor])&&e.length<6;)e.push(r.codePointSource[r.cursor]),r.readCodePoint();isWhitespace(r.codePointSource[r.cursor])&&r.readCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?L:ce<=(t=n)&&t<=ae||n>I?L:n}var t;return o}function consumeIdentSequence(e,r){const o=[];for(;;){if(void 0===r.codePointSource[r.cursor])return o;if(isIdentCodePoint(r.codePointSource[r.cursor]))o.push(r.codePointSource[r.cursor]),r.readCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,r))return o;r.readCodePoint(),o.push(consumeEscapedCodePoint(e,r))}}}function consumeHashToken(e,r){if(r.readCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let t=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(t=o.ID);const n=consumeIdentSequence(e,r);return[exports.TokenType.Hash,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...n),type:t}]}return[exports.TokenType.Delim,r.representationString(),r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,r){let o=exports.NumberType.Integer;const t=[];{r.codePointSource[r.cursor]!==w&&r.codePointSource[r.cursor]!==T||(t.push(r.codePointSource[r.cursor]),r.readCodePoint());const e=consumeDigits(r);for(let r=0;r0&&r.unreadCodePoint(n),[exports.TokenType.Function,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...o)}];break}return n>0&&r.unreadCodePoint(n),consumeUrlToken(e,r)}return r.readCodePoint(),[exports.TokenType.Function,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...o)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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.stringify=function stringify(...e){let r="";for(let o=0;o{})};return{nextToken:function nextToken(){if(n.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,n)){if(null!=r&&r.commentsAreTokens)return consumeComment(i,n);consumeComment(i,n),n.resetRepresentation()}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,n);switch(e){case d:return n.readCodePoint(),[exports.TokenType.Comma,n.representationString(),n.representationStart,n.representationEnd,void 0];case a:return n.readCodePoint(),[exports.TokenType.Colon,n.representationString(),n.representationStart,n.representationEnd,void 0];case q:return n.readCodePoint(),[exports.TokenType.Semicolon,n.representationString(),n.representationStart,n.representationEnd,void 0];case g:return n.readCodePoint(),[exports.TokenType.OpenParen,n.representationString(),n.representationStart,n.representationEnd,void 0];case W:return n.readCodePoint(),[exports.TokenType.CloseParen,n.representationString(),n.representationStart,n.representationEnd,void 0];case A:return n.readCodePoint(),[exports.TokenType.OpenSquare,n.representationString(),n.representationStart,n.representationEnd,void 0];case F:return n.readCodePoint(),[exports.TokenType.CloseSquare,n.representationString(),n.representationStart,n.representationEnd,void 0];case k:return n.readCodePoint(),[exports.TokenType.OpenCurly,n.representationString(),n.representationStart,n.representationEnd,void 0];case R:return n.readCodePoint(),[exports.TokenType.CloseCurly,n.representationString(),n.representationStart,n.representationEnd,void 0];case t:case b:return consumeStringToken(i,n);case U:return consumeHashToken(i,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):(n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:String.fromCharCode(e)}]);case M:case z:case K:case J:case Q:case Z:case _:case j:case G:case X:return consumeNumericToken(i,n);case x:case s:case S:case c:case H:return consumeWhiteSpace(0,n);case T:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.readCodePoint(3),[exports.TokenType.CDC,n.representationString(),n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(i,n):(n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"-"}]);case E:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.readCodePoint(4),[exports.TokenType.CDO,n.representationString(),n.representationStart,n.representationEnd,void 0]):(n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(i,n);return[exports.TokenType.AtKeyword,n.representationString(),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(i,n):(n.readCodePoint(),i.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"\\"}])}return n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:String.fromCharCode(e)}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; diff --git a/packages/css-tokenizer/dist/index.mjs b/packages/css-tokenizer/dist/index.mjs index 19f61bb11..357713e22 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1 +1 @@ -class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;peekedOne;peekedTwo;peekedThree;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===v)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case T:case s:case h:return!0;default:return!1}}function isWhitespace(e){switch(e){case T:case s:case h:case a:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.peekedOne===F&&t.peekedTwo!==T}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.peekedOne===l?t.peekedTwo===l||(!!isIdentStartCodePoint(t.peekedTwo)||t.peekedTwo===F&&t.peekedThree!==T):!!isIdentStartCodePoint(t.peekedOne)||t.peekedOne===F&&checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.peekedOne===N||t.peekedOne===l?!!isDigitCodePoint(t.peekedTwo)||t.peekedTwo===k&&isDigitCodePoint(t.peekedThree):t.peekedOne===k?isDigitCodePoint(t.peekedTwo):!!isDigitCodePoint(t.peekedOne)}function checkIfTwoCodePointsStartAComment(e,t){return t.peekedOne===B&&t.peekedTwo===o}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.peekedOne===l&&t.peekedTwo===l&&t.peekedThree===S}function consumeComment(t,n){for(n.readCodePoint(2);;){const e=n.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:n.representationStart,end:n.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===o&&(void 0!==n.peekedOne&&n.peekedOne===B)){n.readCodePoint();break}}return[e.Comment,n.representationString(),n.representationStart,n.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const n=t.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),R;if(isHexDigitCodePoint(n)){const e=[n];for(;void 0!==t.peekedOne&&isHexDigitCodePoint(t.peekedOne)&&e.length<6;)e.push(t.peekedOne),t.readCodePoint();isWhitespace(t.peekedOne)&&t.readCodePoint();const o=parseInt(String.fromCharCode(...e),16);return 0===o?R:G<=(r=o)&&r<=X||o>w?R:o}var r;return n}function consumeIdentSequence(e,t){const n=[];for(;;){if(void 0===t.peekedOne)return n;if(isIdentCodePoint(t.peekedOne))n.push(t.peekedOne),t.readCodePoint();else{if(t.peekedOne!==F||!checkIfTwoCodePointsAreAValidEscape(0,t))return n;t.readCodePoint(),n.push(consumeEscapedCodePoint(e,t))}}}function consumeHashToken(t,r){if(r.readCodePoint(),void 0!==r.peekedOne&&isIdentCodePoint(r.peekedOne)||checkIfTwoCodePointsAreAValidEscape(0,r)){let o=n.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(o=n.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:o}]}return[e.Delim,r.representationString(),r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,n){let r=t.Integer;const o=[];{n.peekedOne!==N&&n.peekedOne!==l||(o.push(n.peekedOne),n.readCodePoint());const e=consumeDigits(n);for(let t=0;t{})};return{nextToken:function nextToken(){if(i.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,i)){if(null!=n&&n.commentsAreTokens)return consumeComment(s,i);consumeComment(s,i)}i.resetRepresentation();const t=i.peekedOne;if(void 0===t)return[e.EOF,"",-1,-1,void 0];switch(t){case c:return i.readCodePoint(),[e.Comma,i.representationString(),i.representationStart,i.representationEnd,void 0];case d:return i.readCodePoint(),[e.Colon,i.representationString(),i.representationStart,i.representationEnd,void 0];case x:return i.readCodePoint(),[e.Semicolon,i.representationString(),i.representationStart,i.representationEnd,void 0];case O:return i.readCodePoint(),[e.OpenParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case y:return i.readCodePoint(),[e.CloseParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case E:return i.readCodePoint(),[e.OpenSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case q:return i.readCodePoint(),[e.CloseSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case g:return i.readCodePoint(),[e.OpenCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case W:return i.readCodePoint(),[e.CloseCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case r:case b:return consumeStringToken(s,i);case U:return consumeHashToken(s,i);case N:case k:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(s,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(t)}]);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(s,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.readCodePoint(3),[e.CDC,i.representationString(),i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(s,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"-"}]);case A:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.readCodePoint(4),[e.CDO,i.representationString(),i.representationStart,i.representationEnd,void 0]):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(s,i);return[e.AtKeyword,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"@"}];case F:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(s,i):(i.readCodePoint(),s.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"\\"}])}return isWhitespace(t)?consumeWhiteSpace(0,i):isDigitCodePoint(t)?consumeNumericToken(s,i):isIdentStartCodePoint(t)?consumeIdentLikeToken(s,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(t)}])},endOfFile:function endOfFile(){return void 0===i.peekedOne}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; +class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=ce}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===D)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case v:case c:case p:return!0;default:return!1}}function isWhitespace(e){switch(e){case v:case c:case p:case s:case H:return!0;default:return!1}}const se="\ud800".charCodeAt(0),ae="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,r){return r.codePointSource[r.cursor]===y&&r.codePointSource[r.cursor+1]!==v}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,r){return r.codePointSource[r.cursor]===l?r.codePointSource[r.cursor+1]===l||(!!isIdentStartCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===y&&r.codePointSource[r.cursor+2]!==v):!!isIdentStartCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)}function checkIfThreeCodePointsWouldStartANumber(e,r){return r.codePointSource[r.cursor]===R||r.codePointSource[r.cursor]===l?!!isDigitCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===P&&isDigitCodePoint(r.codePointSource[r.cursor+2]):r.codePointSource[r.cursor]===P?isDigitCodePoint(r.codePointSource[r.cursor+1]):!!isDigitCodePoint(r.codePointSource[r.cursor])}function checkIfTwoCodePointsStartAComment(e,r){return r.codePointSource[r.cursor]===B&&r.codePointSource[r.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,r){return r.codePointSource[r.cursor]===l&&r.codePointSource[r.cursor+1]===l&&r.codePointSource[r.cursor+2]===h}function consumeComment(r,t){for(t.readCodePoint(2);;){const e=t.readCodePoint();if(!1===e){r.onParseError({message:"Unexpected EOF while consuming a comment.",start:t.representationStart,end:t.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==t.codePointSource[t.cursor]&&t.codePointSource[t.cursor]===B)){t.readCodePoint();break}}return[e.Comment,t.representationString(),t.representationStart,t.representationEnd,void 0]}function consumeEscapedCodePoint(e,r){const t=r.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:r.representationStart,end:r.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),N;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==r.codePointSource[r.cursor]&&isHexDigitCodePoint(r.codePointSource[r.cursor])&&e.length<6;)e.push(r.codePointSource[r.cursor]),r.readCodePoint();isWhitespace(r.codePointSource[r.cursor])&&r.readCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?N:se<=(o=n)&&o<=ae||n>U?N:n}var o;return t}function consumeIdentSequence(e,r){const t=[];for(;;){if(void 0===r.codePointSource[r.cursor])return t;if(isIdentCodePoint(r.codePointSource[r.cursor]))t.push(r.codePointSource[r.cursor]),r.readCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,r))return t;r.readCodePoint(),t.push(consumeEscapedCodePoint(e,r))}}}function consumeHashToken(r,o){if(o.readCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let n=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(n=t.ID);const i=consumeIdentSequence(r,o);return[e.Hash,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,t){let o=r.Integer;const n=[];{t.codePointSource[t.cursor]!==R&&t.codePointSource[t.cursor]!==l||(n.push(t.codePointSource[t.cursor]),t.readCodePoint());const e=consumeDigits(t);for(let r=0;r0&&t.unreadCodePoint(i),[e.Function,t.representationString(),t.representationStart,t.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&t.unreadCodePoint(i),consumeUrlToken(r,t)}return t.readCodePoint(),[e.Function,t.representationString(),t.representationStart,t.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(r,t){const n=r.css.valueOf(),i=new Reader(n),C={onParseError:(null==t?void 0:t.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,i)){if(null!=t&&t.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.resetRepresentation()}const r=i.codePointSource[i.cursor];if(void 0===r)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(r))return consumeIdentLikeToken(C,i);switch(r){case d:return i.readCodePoint(),[e.Comma,i.representationString(),i.representationStart,i.representationEnd,void 0];case a:return i.readCodePoint(),[e.Colon,i.representationString(),i.representationStart,i.representationEnd,void 0];case x:return i.readCodePoint(),[e.Semicolon,i.representationString(),i.representationStart,i.representationEnd,void 0];case E:return i.readCodePoint(),[e.OpenParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case F:return i.readCodePoint(),[e.CloseParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case k:return i.readCodePoint(),[e.OpenSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case q:return i.readCodePoint(),[e.CloseSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case A:return i.readCodePoint(),[e.OpenCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case W:return i.readCodePoint(),[e.CloseCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case o:case b:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case R:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(r)}]);case M:case z:case K:case J:case Q:case Z:case _:case j:case G:case X:return consumeNumericToken(C,i);case v:case c:case p:case s:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.readCodePoint(3),[e.CDC,i.representationString(),i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"-"}]);case I:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.readCodePoint(4),[e.CDO,i.representationString(),i.representationStart,i.representationEnd,void 0]):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const r=consumeIdentSequence(C,i);return[e.AtKeyword,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(...r)}]}return[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"@"}];case y:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.readCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"\\"}])}return i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(r)}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{r as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; diff --git a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts index fc083f389..1fb887ea0 100644 --- a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts +++ b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts @@ -1,13 +1,11 @@ export type CodePointReader = { representationStart: number; representationEnd: number; - peekedOne: number | undefined; - peekedTwo: number | undefined; - peekedThree: number | undefined; - peekedFour: number | undefined; + cursor: number; + codePointSource: Array; cursorPositionOfLastReadCodePoint(): number; readCodePoint(n?: number): number | false; - unreadCodePoint(): boolean; + unreadCodePoint(n?: number): boolean; representationString(): string; resetRepresentation(): any; slice(start: number, end: number): string; diff --git a/packages/css-tokenizer/dist/reader.d.ts b/packages/css-tokenizer/dist/reader.d.ts index e4def59f2..c93b39b38 100644 --- a/packages/css-tokenizer/dist/reader.d.ts +++ b/packages/css-tokenizer/dist/reader.d.ts @@ -6,14 +6,10 @@ export declare class Reader implements CodePointReader { length: number; representationStart: number; representationEnd: number; - peekedOne: number | undefined; - peekedTwo: number | undefined; - peekedThree: number | undefined; constructor(source: string); - peekedFour: number; cursorPositionOfLastReadCodePoint(): number; readCodePoint(n?: number): number | false; - unreadCodePoint(): boolean; + unreadCodePoint(n?: number): boolean; representationString(): string; resetRepresentation(): void; slice(start: number, end: number): string; diff --git a/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts b/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts index ea9689bda..5391ccf99 100644 --- a/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts +++ b/packages/css-tokenizer/src/checks/four-code-points-would-start-cdo.ts @@ -4,5 +4,5 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token export function checkIfFourCodePointsWouldStartCDO(ctx: Context, reader: CodePointReader): boolean { - return reader.peekedOne === LESS_THAN_SIGN && reader.peekedTwo === EXCLAMATION_MARK && reader.peekedThree === HYPHEN_MINUS && reader.peekedFour === HYPHEN_MINUS; + return reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor+1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+3] === HYPHEN_MINUS; } diff --git a/packages/css-tokenizer/src/checks/next-is-eof.ts b/packages/css-tokenizer/src/checks/next-is-eof.ts index b6e0a3054..cc57009aa 100644 --- a/packages/css-tokenizer/src/checks/next-is-eof.ts +++ b/packages/css-tokenizer/src/checks/next-is-eof.ts @@ -2,7 +2,7 @@ import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; export function checkIfNextIsEOF(ctx: Context, reader: CodePointReader): boolean { - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { return true; } diff --git a/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts b/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts index dc2667e2a..220a78c62 100644 --- a/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts +++ b/packages/css-tokenizer/src/checks/three-code-points-would-start-cdc.ts @@ -4,5 +4,5 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token export function checkIfThreeCodePointsWouldStartCDC(ctx: Context, reader: CodePointReader): boolean { - return reader.peekedOne === HYPHEN_MINUS && reader.peekedTwo === HYPHEN_MINUS && reader.peekedThree === GREATER_THAN_SIGN; + return reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN; } diff --git a/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts b/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts index be477ace1..16c31196f 100644 --- a/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts +++ b/packages/css-tokenizer/src/checks/three-code-points-would-start-ident-sequence.ts @@ -7,19 +7,19 @@ import { checkIfTwoCodePointsAreAValidEscape } from './two-code-points-are-valid // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier export function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, reader: CodePointReader): boolean { // // U+002D HYPHEN-MINUS - if (reader.peekedOne === HYPHEN_MINUS) { + if (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { // If the second code point is a U+002D HYPHEN-MINUS return true - if (reader.peekedTwo === HYPHEN_MINUS) { + if (reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS) { return true; } // If the second code point is an ident-start code point return true - if (isIdentStartCodePoint(reader.peekedTwo)) { + if (isIdentStartCodePoint(reader.codePointSource[reader.cursor+1])) { return true; } // If the second and third code points are a valid escape return true - if (reader.peekedTwo === REVERSE_SOLIDUS && reader.peekedThree !== LINE_FEED) { + if (reader.codePointSource[reader.cursor+1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) { return true; } @@ -28,18 +28,10 @@ export function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, re // ident-start code point // Return true. - if (isIdentStartCodePoint(reader.peekedOne)) { + if (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) { return true; } // U+005C REVERSE SOLIDUS (\) - if (reader.peekedOne === REVERSE_SOLIDUS) { - // If the first and second code points are a valid escape, return true. - // Otherwise, return false. - return checkIfTwoCodePointsAreAValidEscape(ctx, reader); - } - - // anything else - // Return false. - return false; + return checkIfTwoCodePointsAreAValidEscape(ctx, reader); } diff --git a/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts b/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts index a2322fbfd..3b26474c9 100644 --- a/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts +++ b/packages/css-tokenizer/src/checks/three-code-points-would-start-number.ts @@ -5,27 +5,27 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number export function checkIfThreeCodePointsWouldStartANumber(ctx: Context, reader: CodePointReader): boolean { - if (reader.peekedOne === PLUS_SIGN || reader.peekedOne === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) + if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) // If the second code point is a digit, return true. - if (isDigitCodePoint(reader.peekedTwo)) { + if (isDigitCodePoint(reader.codePointSource[reader.cursor+1])) { return true; } // Otherwise, if the second code point is a U+002E FULL STOP (.) - if (reader.peekedTwo === FULL_STOP) { + if (reader.codePointSource[reader.cursor+1] === FULL_STOP) { // and the third code point is a digit, return true. - return isDigitCodePoint(reader.peekedThree); + return isDigitCodePoint(reader.codePointSource[reader.cursor+2]); } // Otherwise, return false. return false; - } else if (reader.peekedOne === FULL_STOP) { // U+002E FULL STOP (.) + } else if (reader.codePointSource[reader.cursor] === FULL_STOP) { // U+002E FULL STOP (.) // If the second code point is a digit, return true. // Otherwise, return false. - return isDigitCodePoint(reader.peekedTwo); + return isDigitCodePoint(reader.codePointSource[reader.cursor+1]); - } else if (isDigitCodePoint(reader.peekedOne)) { // digit + } else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { // digit // Return true. return true; } diff --git a/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts b/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts index 3f0ec91cd..223933ef7 100644 --- a/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts +++ b/packages/css-tokenizer/src/checks/two-code-points-are-valid-escape.ts @@ -5,12 +5,12 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape export function checkIfTwoCodePointsAreAValidEscape(ctx: Context, reader: CodePointReader): boolean { // If the first code point is not U+005C REVERSE SOLIDUS (\), return false. - if (reader.peekedOne !== REVERSE_SOLIDUS) { // "\" + if (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { // "\" return false; } // Otherwise, if the second code point is a newline, return false. - if (reader.peekedTwo === LINE_FEED) { + if (reader.codePointSource[reader.cursor+1] === LINE_FEED) { return false; } diff --git a/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts b/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts index aafe2a5dd..91a1a05aa 100644 --- a/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts +++ b/packages/css-tokenizer/src/checks/two-code-points-start-comment.ts @@ -4,11 +4,11 @@ import { Context } from '../interfaces/context'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments export function checkIfTwoCodePointsStartAComment(ctx: Context, reader: CodePointReader): boolean { - if (reader.peekedOne !== SOLIDUS) { + if (reader.codePointSource[reader.cursor] !== SOLIDUS) { return false; } - if (reader.peekedTwo !== ASTERISK) { + if (reader.codePointSource[reader.cursor+1] !== ASTERISK) { return false; } diff --git a/packages/css-tokenizer/src/code-points/code-points.ts b/packages/css-tokenizer/src/code-points/code-points.ts index fca7ea361..eb765add0 100644 --- a/packages/css-tokenizer/src/code-points/code-points.ts +++ b/packages/css-tokenizer/src/code-points/code-points.ts @@ -76,3 +76,23 @@ export const SHIFT_OUT = '\u{e}'.charCodeAt(0); export const SOLIDUS = '\u{2f}'.charCodeAt(0); /** \u20 */ export const SPACE = '\u{20}'.charCodeAt(0); +/** 0 */ +export const DIGIT_0 = '\u{30}'.charCodeAt(0); +/** 1 */ +export const DIGIT_1 = '\u{31}'.charCodeAt(0); +/** 2 */ +export const DIGIT_2 = '\u{32}'.charCodeAt(0); +/** 3 */ +export const DIGIT_3 = '\u{33}'.charCodeAt(0); +/** 4 */ +export const DIGIT_4 = '\u{34}'.charCodeAt(0); +/** 5 */ +export const DIGIT_5 = '\u{35}'.charCodeAt(0); +/** 6 */ +export const DIGIT_6 = '\u{36}'.charCodeAt(0); +/** 7 */ +export const DIGIT_7 = '\u{37}'.charCodeAt(0); +/** 8 */ +export const DIGIT_8 = '\u{38}'.charCodeAt(0); +/** 9 */ +export const DIGIT_9 = '\u{39}'.charCodeAt(0); diff --git a/packages/css-tokenizer/src/code-points/ranges.ts b/packages/css-tokenizer/src/code-points/ranges.ts index 9aa4628bd..25a0be222 100644 --- a/packages/css-tokenizer/src/code-points/ranges.ts +++ b/packages/css-tokenizer/src/code-points/ranges.ts @@ -6,11 +6,7 @@ const digitsHigh = '\u{39}'.charCodeAt(0); // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit export function isDigitCodePoint(search: number): boolean { - if (digitsLow <= search && search <= digitsHigh) { - return true; - } - - return false; + return digitsLow <= search && search <= digitsHigh; } const letterUppercaseLow = '\u{41}'.charCodeAt(0); @@ -18,11 +14,7 @@ const letterUppercaseHigh = '\u{5a}'.charCodeAt(0); // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter export function isUppercaseLetterCodePoint(search: number): boolean { - if (letterUppercaseLow <= search && search <= letterUppercaseHigh) { - return true; - } - - return false; + return letterUppercaseLow <= search && search <= letterUppercaseHigh; } const letterLowercaseLow = '\u{61}'.charCodeAt(0); @@ -30,11 +22,7 @@ const letterLowercaseHigh = '\u{7a}'.charCodeAt(0); // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter export function isLowercaseLetterCodePoint(search: number): boolean { - if (letterLowercaseLow <= search && search <= letterLowercaseHigh) { - return true; - } - - return false; + return letterLowercaseLow <= search && search <= letterLowercaseHigh; } const afUppercaseHigh = '\u{46}'.charCodeAt(0); @@ -42,15 +30,15 @@ const afLowercaseHigh = '\u{66}'.charCodeAt(0); // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit export function isHexDigitCodePoint(search: number): boolean { - if (isDigitCodePoint(search)) { + if (digitsLow <= search && search <= digitsHigh) { return true; } - if (letterUppercaseLow <= search && search <= afUppercaseHigh) { + if (letterLowercaseLow <= search && search <= afLowercaseHigh) { return true; } - if (letterLowercaseLow <= search && search <= afLowercaseHigh) { + if (letterUppercaseLow <= search && search <= afUppercaseHigh) { return true; } @@ -59,11 +47,7 @@ export function isHexDigitCodePoint(search: number): boolean { // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter export function isLetterCodePoint(search: number): boolean { - if (isUppercaseLetterCodePoint(search) || isLowercaseLetterCodePoint(search)) { - return true; - } - - return false; + return isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search); } const nonASCIILow = '\u{80}'.charCodeAt(0); @@ -113,11 +97,7 @@ export function isNonPrintableCodePoint(search: number): boolean { return true; } - if (SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE) { - return true; - } - - return false; + return SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE; } // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace @@ -138,17 +118,16 @@ export function isNewLine(search: number): boolean { // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace export function isWhitespace(search: number): boolean { + // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing + // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. + // Applying the preprocessing rules would make it impossible to match the input. + // A side effect of this is that our definition of whitespace is broader. + switch (search) { case LINE_FEED: case CARRIAGE_RETURN: case FORM_FEED: - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing - // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. - // Applying the preprocessing rules would make it impossible to match the input. - // A side effect of this is that our definition of whitespace is broader. - return true; case CHARACTER_TABULATION: - return true; case SPACE: return true; @@ -162,9 +141,5 @@ const surrogateHigh = '\u{dfff}'.charCodeAt(0); // https://infra.spec.whatwg.org/#surrogate export function isSurrogate(search: number): boolean { - if (surrogateLow <= search && search <= surrogateHigh) { - return true; - } - - return false; + return surrogateLow <= search && search <= surrogateHigh; } diff --git a/packages/css-tokenizer/src/consume/bad-url.ts b/packages/css-tokenizer/src/consume/bad-url.ts index a97d5b2f1..d669e0a03 100644 --- a/packages/css-tokenizer/src/consume/bad-url.ts +++ b/packages/css-tokenizer/src/consume/bad-url.ts @@ -8,11 +8,11 @@ import { consumeEscapedCodePoint } from './escaped-code-point'; export function consumeBadURL(ctx: Context, reader: CodePointReader) { // eslint-disable-next-line no-constant-condition while (true) { - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { return; } - if (reader.peekedOne === RIGHT_PARENTHESIS) { + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { reader.readCodePoint(); return; } diff --git a/packages/css-tokenizer/src/consume/comment.ts b/packages/css-tokenizer/src/consume/comment.ts index cf79189c1..87f1035fc 100644 --- a/packages/css-tokenizer/src/consume/comment.ts +++ b/packages/css-tokenizer/src/consume/comment.ts @@ -28,11 +28,11 @@ export function consumeComment(ctx: Context, reader: CodePointReader): TokenComm continue; } - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { continue; } - if (reader.peekedOne === SOLIDUS) { + if (reader.codePointSource[reader.cursor] === SOLIDUS) { reader.readCodePoint(); break; } diff --git a/packages/css-tokenizer/src/consume/escaped-code-point.ts b/packages/css-tokenizer/src/consume/escaped-code-point.ts index 557dc4e7d..aa854ae41 100644 --- a/packages/css-tokenizer/src/consume/escaped-code-point.ts +++ b/packages/css-tokenizer/src/consume/escaped-code-point.ts @@ -23,12 +23,12 @@ export function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): if (isHexDigitCodePoint(codePoint)) { const hexSequence: Array = [codePoint]; - while ((typeof reader.peekedOne !== 'undefined') && isHexDigitCodePoint(reader.peekedOne) && hexSequence.length < 6) { - hexSequence.push(reader.peekedOne); + while ((reader.codePointSource[reader.cursor] !== undefined) && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) { + hexSequence.push(reader.codePointSource[reader.cursor]); reader.readCodePoint(); } - if (isWhitespace(reader.peekedOne)) { + if (isWhitespace(reader.codePointSource[reader.cursor])) { reader.readCodePoint(); } diff --git a/packages/css-tokenizer/src/consume/hash-token.ts b/packages/css-tokenizer/src/consume/hash-token.ts index b74470a5e..2a1169994 100644 --- a/packages/css-tokenizer/src/consume/hash-token.ts +++ b/packages/css-tokenizer/src/consume/hash-token.ts @@ -11,8 +11,8 @@ export function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDe reader.readCodePoint(); if ( - (typeof reader.peekedOne !== 'undefined') && - isIdentCodePoint(reader.peekedOne) || + (reader.codePointSource[reader.cursor] !== undefined) && + isIdentCodePoint(reader.codePointSource[reader.cursor]) || checkIfTwoCodePointsAreAValidEscape(ctx, reader) ) { let hashType = HashType.Unrestricted; diff --git a/packages/css-tokenizer/src/consume/ident-like-token.ts b/packages/css-tokenizer/src/consume/ident-like-token.ts index 7c326911d..6b8d9d775 100644 --- a/packages/css-tokenizer/src/consume/ident-like-token.ts +++ b/packages/css-tokenizer/src/consume/ident-like-token.ts @@ -11,62 +11,62 @@ import { consumeUrlToken } from './url-token'; export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): TokenIdent | TokenFunction | TokenURL | TokenBadURL { const codePoints = consumeIdentSequence(ctx, reader); - if (reader.peekedOne === LEFT_PARENTHESIS) { - if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { - reader.readCodePoint(); + if (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) { + return [ + TokenType.Ident, + reader.representationString(), + reader.representationStart, + reader.representationEnd, + { + value: String.fromCharCode(...codePoints), + }, + ]; + } - let read = 0; - // eslint-disable-next-line no-constant-condition - while (true) { - const firstIsWhitespace = isWhitespace(reader.peekedOne); - const secondIsWhitespace = isWhitespace(reader.peekedTwo); - if (firstIsWhitespace && secondIsWhitespace) { - read += 2; - reader.readCodePoint(2); - continue; - } + if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { + reader.readCodePoint(); - const firstNonWhitespace = firstIsWhitespace ? reader.peekedTwo : reader.peekedOne; - if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { - for (let i = 0; i < read; i++) { - reader.unreadCodePoint(); - } + let read = 0; + // eslint-disable-next-line no-constant-condition + while (true) { + const firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]); + const secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor+1]); + if (firstIsWhitespace && secondIsWhitespace) { + read += 2; + reader.readCodePoint(2); + continue; + } - return [ - TokenType.Function, - reader.representationString(), - reader.representationStart, - reader.representationEnd, - { - value: String.fromCharCode(...codePoints), - }, - ]; + const firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor+1] : reader.codePointSource[reader.cursor]; + if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { + if (read > 0) { + reader.unreadCodePoint(read); } - break; + return [ + TokenType.Function, + reader.representationString(), + reader.representationStart, + reader.representationEnd, + { + value: String.fromCharCode(...codePoints), + }, + ]; } - for (let i = 0; i < read; i++) { - reader.unreadCodePoint(); - } + break; + } - return consumeUrlToken(ctx, reader); + if (read > 0) { + reader.unreadCodePoint(read); } - reader.readCodePoint(); - return [ - TokenType.Function, - reader.representationString(), - reader.representationStart, - reader.representationEnd, - { - value: String.fromCharCode(...codePoints), - }, - ]; + return consumeUrlToken(ctx, reader); } + reader.readCodePoint(); return [ - TokenType.Ident, + TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, diff --git a/packages/css-tokenizer/src/consume/ident-sequence.ts b/packages/css-tokenizer/src/consume/ident-sequence.ts index 3d118bfad..e937b1dea 100644 --- a/packages/css-tokenizer/src/consume/ident-sequence.ts +++ b/packages/css-tokenizer/src/consume/ident-sequence.ts @@ -1,5 +1,4 @@ import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape'; -import { REVERSE_SOLIDUS } from '../code-points/code-points'; import { isIdentCodePoint } from '../code-points/ranges'; import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; @@ -11,17 +10,17 @@ export function consumeIdentSequence(ctx: Context, reader: CodePointReader): Arr // eslint-disable-next-line no-constant-condition while (true) { - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { return result; } - if (isIdentCodePoint(reader.peekedOne)) { - result.push(reader.peekedOne); + if (isIdentCodePoint(reader.codePointSource[reader.cursor])) { + result.push(reader.codePointSource[reader.cursor]); reader.readCodePoint(); continue; } - if (reader.peekedOne === REVERSE_SOLIDUS && checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { reader.readCodePoint(); result.push(consumeEscapedCodePoint(ctx, reader)); continue; diff --git a/packages/css-tokenizer/src/consume/number.ts b/packages/css-tokenizer/src/consume/number.ts index 442736e5e..c8c9c1f1b 100644 --- a/packages/css-tokenizer/src/consume/number.ts +++ b/packages/css-tokenizer/src/consume/number.ts @@ -13,8 +13,8 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N { // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr. - if (reader.peekedOne === PLUS_SIGN || reader.peekedOne === HYPHEN_MINUS) { - repr.push(reader.peekedOne); + if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { + repr.push(reader.codePointSource[reader.cursor]); reader.readCodePoint(); } @@ -27,10 +27,10 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N { // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then: - if (reader.peekedOne === FULL_STOP && isDigitCodePoint(reader.peekedTwo)) { + if (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor+1])) { // 4.2. Append them to repr. - repr.push(reader.peekedOne); - repr.push(reader.peekedTwo); + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor+1]); // 4.1. Consume them. reader.readCodePoint(2); @@ -51,12 +51,12 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N // optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+), // followed by a digit, then: if ( - (reader.peekedOne === LATIN_SMALL_LETTER_E || reader.peekedOne === LATIN_CAPITAL_LETTER_E) && - isDigitCodePoint(reader.peekedTwo) + (reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && + isDigitCodePoint(reader.codePointSource[reader.cursor+1]) ) { // 5.2. Append them to repr. - repr.push(reader.peekedOne); - repr.push(reader.peekedTwo); + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor+1]); // 5.1. Consume them. reader.readCodePoint(2); @@ -72,16 +72,16 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N } if ( - (reader.peekedOne === LATIN_SMALL_LETTER_E || reader.peekedOne === LATIN_CAPITAL_LETTER_E) && + (reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && ( - (reader.peekedTwo === HYPHEN_MINUS || reader.peekedTwo === PLUS_SIGN) && - isDigitCodePoint(reader.peekedThree) + (reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor+1] === PLUS_SIGN) && + isDigitCodePoint(reader.codePointSource[reader.cursor+2]) ) ) { // 5.2. Append them to repr. - repr.push(reader.peekedOne); - repr.push(reader.peekedTwo); - repr.push(reader.peekedThree); + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor+1]); + repr.push(reader.codePointSource[reader.cursor+2]); // 5.1. Consume them. reader.readCodePoint(3); @@ -109,12 +109,12 @@ function consumeDigits(reader: CodePointReader): Array { // eslint-disable-next-line no-constant-condition while (true) { - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { return value; } - if (isDigitCodePoint(reader.peekedOne)) { - value.push(reader.peekedOne); + if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { + value.push(reader.codePointSource[reader.cursor]); reader.readCodePoint(); } else { return value; @@ -212,12 +212,5 @@ function digitCodePointsToInteger(codePoints: Array): number { return 0; } - const stringValue = String.fromCharCode(...codePoints); - - const integerValue = Number.parseInt(stringValue, 10); - if (Number.isNaN(integerValue)) { - throw new Error(`Unexpected "NaN" result when parsing a number from digit code points: "${stringValue}"`); - } - - return integerValue; + return Number.parseInt(String.fromCharCode(...codePoints), 10); } diff --git a/packages/css-tokenizer/src/consume/numeric-token.ts b/packages/css-tokenizer/src/consume/numeric-token.ts index 9f70ebd44..8f68601fb 100644 --- a/packages/css-tokenizer/src/consume/numeric-token.ts +++ b/packages/css-tokenizer/src/consume/numeric-token.ts @@ -27,7 +27,7 @@ export function consumeNumericToken(ctx: Context, reader: CodePointReader): Toke } { - if (reader.peekedOne === PERCENTAGE_SIGN) { + if (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) { reader.readCodePoint(); return [ diff --git a/packages/css-tokenizer/src/consume/string-token.ts b/packages/css-tokenizer/src/consume/string-token.ts index 82767905d..c5f5605a1 100644 --- a/packages/css-tokenizer/src/consume/string-token.ts +++ b/packages/css-tokenizer/src/consume/string-token.ts @@ -53,11 +53,11 @@ export function consumeStringToken(ctx: Context, reader: CodePointReader): Token } if (next === REVERSE_SOLIDUS) { - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { continue; } - if (isNewLine(reader.peekedOne)) { + if (isNewLine(reader.codePointSource[reader.cursor])) { reader.readCodePoint(); continue; } diff --git a/packages/css-tokenizer/src/consume/url-token.ts b/packages/css-tokenizer/src/consume/url-token.ts index 918b83a61..79a6424cd 100644 --- a/packages/css-tokenizer/src/consume/url-token.ts +++ b/packages/css-tokenizer/src/consume/url-token.ts @@ -15,7 +15,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL // eslint-disable-next-line no-constant-condition while (true) { - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { ctx.onParseError({ message: 'Unexpected EOF while consuming a url token.', start: reader.representationStart, @@ -37,7 +37,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL ]; } - if (reader.peekedOne === RIGHT_PARENTHESIS) { + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { reader.readCodePoint(); return [ TokenType.URL, @@ -50,9 +50,9 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL ]; } - if (isWhitespace(reader.peekedOne)) { + if (isWhitespace(reader.codePointSource[reader.cursor])) { consumeWhiteSpace(ctx, reader); - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { ctx.onParseError({ message: 'Unexpected EOF while consuming a url token.', start: reader.representationStart, @@ -75,7 +75,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL ]; } - if (reader.peekedOne === RIGHT_PARENTHESIS) { + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { reader.readCodePoint(); return [ TokenType.URL, @@ -98,7 +98,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL ]; } - if (reader.peekedOne === QUOTATION_MARK || reader.peekedOne === APOSTROPHE || reader.peekedOne === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.peekedOne)) { + if (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) { consumeBadURL(ctx, reader); ctx.onParseError({ @@ -120,7 +120,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL ]; } - if (reader.peekedOne === REVERSE_SOLIDUS) { + if (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) { if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { string += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); continue; @@ -148,7 +148,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL ]; } - string += String.fromCharCode(reader.peekedOne); + string += String.fromCharCode(reader.codePointSource[reader.cursor]); reader.readCodePoint(); } } diff --git a/packages/css-tokenizer/src/consume/whitespace-token.ts b/packages/css-tokenizer/src/consume/whitespace-token.ts index addec8aaf..5b1e8a096 100644 --- a/packages/css-tokenizer/src/consume/whitespace-token.ts +++ b/packages/css-tokenizer/src/consume/whitespace-token.ts @@ -19,7 +19,7 @@ export function consumeWhiteSpace(ctx: Context, reader: CodePointReader, max = - } current++; - if (reader.peekedOne === undefined) { + if (reader.codePointSource[reader.cursor] === undefined) { return [ TokenType.Whitespace, reader.representationString(), @@ -29,7 +29,7 @@ export function consumeWhiteSpace(ctx: Context, reader: CodePointReader, max = - ]; } - if (!isWhitespace(reader.peekedOne)) { + if (!isWhitespace(reader.codePointSource[reader.cursor])) { break; } diff --git a/packages/css-tokenizer/src/interfaces/code-point-reader.ts b/packages/css-tokenizer/src/interfaces/code-point-reader.ts index 95fc4f639..460c62e64 100644 --- a/packages/css-tokenizer/src/interfaces/code-point-reader.ts +++ b/packages/css-tokenizer/src/interfaces/code-point-reader.ts @@ -8,15 +8,13 @@ export type CodePointReader = { representationStart: number; representationEnd: number; - peekedOne: number | undefined; - peekedTwo: number | undefined; - peekedThree: number | undefined; - peekedFour: number | undefined; + cursor: number; + codePointSource: Array ; cursorPositionOfLastReadCodePoint(): number; readCodePoint(n?: number): number | false - unreadCodePoint(): boolean + unreadCodePoint(n?: number): boolean representationString(): string resetRepresentation() diff --git a/packages/css-tokenizer/src/reader.ts b/packages/css-tokenizer/src/reader.ts index 88eb34946..14874d40d 100644 --- a/packages/css-tokenizer/src/reader.ts +++ b/packages/css-tokenizer/src/reader.ts @@ -9,10 +9,6 @@ export class Reader implements CodePointReader { representationStart = 0; representationEnd = -1; - peekedOne: number | undefined; - peekedTwo: number | undefined; - peekedThree: number | undefined; - constructor(source: string) { this.cursor = 0; this.stringSource = source; @@ -22,13 +18,7 @@ export class Reader implements CodePointReader { for (let i = 0; i < this.length; i++) { this.codePointSource[i] = this.stringSource.charCodeAt(i); } - - this.peekedOne = this.codePointSource[this.cursor]; - this.peekedTwo = this.codePointSource[this.cursor + 1]; - this.peekedThree = this.codePointSource[this.cursor + 2]; - this.peekedFour = this.codePointSource[this.cursor + 3]; } - peekedFour: number; cursorPositionOfLastReadCodePoint(): number { return this.cursor - 1; @@ -36,33 +26,23 @@ export class Reader implements CodePointReader { readCodePoint(n = 1): number | false { const codePoint = this.codePointSource[this.cursor]; - if (typeof codePoint === 'undefined') { + if (codePoint === undefined) { return false; } this.cursor += n; this.representationEnd = this.cursor - 1; - this.peekedOne = this.codePointSource[this.cursor]; - this.peekedTwo = this.codePointSource[this.cursor + 1]; - this.peekedThree = this.codePointSource[this.cursor + 2]; - this.peekedFour = this.codePointSource[this.cursor + 3]; - return codePoint; } - unreadCodePoint(): boolean { + unreadCodePoint(n = 1): boolean { if (this.cursor === 0) { return false; } + this.cursor -= n; this.representationEnd = this.cursor - 1; - this.cursor -= 1; - - this.peekedOne = this.codePointSource[this.cursor]; - this.peekedTwo = this.codePointSource[this.cursor + 1]; - this.peekedThree = this.codePointSource[this.cursor + 2]; - this.peekedFour = this.codePointSource[this.cursor + 3]; return true; } diff --git a/packages/css-tokenizer/src/tokenizer.ts b/packages/css-tokenizer/src/tokenizer.ts index 7e12d3183..098abda0e 100644 --- a/packages/css-tokenizer/src/tokenizer.ts +++ b/packages/css-tokenizer/src/tokenizer.ts @@ -3,8 +3,8 @@ import { checkIfThreeCodePointsWouldStartAnIdentSequence } from './checks/three- import { checkIfThreeCodePointsWouldStartANumber } from './checks/three-code-points-would-start-number'; import { checkIfTwoCodePointsStartAComment } from './checks/two-code-points-start-comment'; import { checkIfThreeCodePointsWouldStartCDC } from './checks/three-code-points-would-start-cdc'; -import { APOSTROPHE, COLON, COMMA, COMMERCIAL_AT, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON } from './code-points/code-points'; -import { isDigitCodePoint, isIdentStartCodePoint, isWhitespace } from './code-points/ranges'; +import { APOSTROPHE, CARRIAGE_RETURN, CHARACTER_TABULATION, COLON, COMMA, COMMERCIAL_AT, DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9, FORM_FEED, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, LINE_FEED, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON, SPACE } from './code-points/code-points'; +import { isIdentStartCodePoint } from './code-points/ranges'; import { consumeComment } from './consume/comment'; import { consumeHashToken } from './consume/hash-token'; import { consumeIdentSequence } from './consume/ident-sequence'; @@ -31,7 +31,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken }; function endOfFile() { - return reader.peekedOne === undefined; + return reader.codePointSource[reader.cursor] === undefined; } function nextToken(): CSSToken | undefined { @@ -42,15 +42,19 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken return consumeComment(ctx, reader); } else { consumeComment(ctx, reader); + reader.resetRepresentation(); } } - reader.resetRepresentation(); - const peeked = reader.peekedOne; + const peeked = reader.codePointSource[reader.cursor]; if (peeked === undefined) { return [TokenType.EOF, '', -1, -1, undefined]; } + if (isIdentStartCodePoint(peeked)) { + return consumeIdentLikeToken(ctx, reader); + } + // Simple, one character tokens: switch (peeked) { case COMMA: { @@ -106,6 +110,24 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken value: String.fromCharCode(peeked), }]; } + case DIGIT_0: + case DIGIT_1: + case DIGIT_2: + case DIGIT_3: + case DIGIT_4: + case DIGIT_5: + case DIGIT_6: + case DIGIT_7: + case DIGIT_8: + case DIGIT_9: + return consumeNumericToken(ctx, reader); + + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + case CHARACTER_TABULATION: + case SPACE: + return consumeWhiteSpace(ctx, reader); case HYPHEN_MINUS: { if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { @@ -180,18 +202,6 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } } - if (isWhitespace(peeked)) { - return consumeWhiteSpace(ctx, reader); - } - - if (isDigitCodePoint(peeked)) { - return consumeNumericToken(ctx, reader); - } - - if (isIdentStartCodePoint(peeked)) { - return consumeIdentLikeToken(ctx, reader); - } - reader.readCodePoint(); return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: String.fromCharCode(peeked), diff --git a/packages/css-tokenizer/test/test-reader.mjs b/packages/css-tokenizer/test/test-reader.mjs index 8cf0fcc34..2cff13284 100644 --- a/packages/css-tokenizer/test/test-reader.mjs +++ b/packages/css-tokenizer/test/test-reader.mjs @@ -5,7 +5,7 @@ import { Reader } from '@csstools/css-tokenizer'; const r = new Reader('abc👨‍👨‍👧‍👦d'); { - const peeked = r.peekedOne; + const peeked = r.codePointSource[r.cursor]; assert.deepEqual( peeked, 97, @@ -30,8 +30,8 @@ import { Reader } from '@csstools/css-tokenizer'; { const peeked = [ - r.peekedOne, - r.peekedTwo, + r.codePointSource[r.cursor], + r.codePointSource[r.cursor+1], ]; assert.deepEqual( peeked, @@ -62,9 +62,9 @@ import { Reader } from '@csstools/css-tokenizer'; { const peeked = [ - r.peekedOne, - r.peekedTwo, - r.peekedThree, + r.codePointSource[r.cursor], + r.codePointSource[r.cursor+1], + r.codePointSource[r.cursor+2], ]; assert.deepEqual( peeked, From 7ed4701a34ad7c18f2c7970cc944219eca253c47 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sun, 25 Dec 2022 11:54:36 +0100 Subject: [PATCH 06/24] wip --- .../dist/consume/whitespace-token.d.ts | 2 +- packages/css-tokenizer/dist/index.cjs | 1182 ++++++++++++++++- packages/css-tokenizer/dist/index.cjs.map | 1 + packages/css-tokenizer/dist/index.mjs | 1175 +++++++++++++++- packages/css-tokenizer/dist/index.mjs.map | 1 + .../dist/interfaces/code-point-reader.d.ts | 1 + packages/css-tokenizer/dist/reader.d.ts | 3 +- packages/css-tokenizer/src/consume/bad-url.ts | 6 +- packages/css-tokenizer/src/consume/comment.ts | 4 +- .../src/consume/escaped-code-point.ts | 4 +- .../css-tokenizer/src/consume/hash-token.ts | 2 +- .../src/consume/ident-like-token.ts | 10 +- .../src/consume/ident-sequence.ts | 10 +- packages/css-tokenizer/src/consume/number.ts | 10 +- .../src/consume/numeric-token.ts | 2 +- .../css-tokenizer/src/consume/string-token.ts | 2 +- .../css-tokenizer/src/consume/url-token.ts | 6 +- .../src/consume/whitespace-token.ts | 27 +- .../src/interfaces/code-point-reader.ts | 4 +- packages/css-tokenizer/src/reader.ts | 19 +- packages/css-tokenizer/src/tokenizer.ts | 38 +- 21 files changed, 2421 insertions(+), 88 deletions(-) create mode 100644 packages/css-tokenizer/dist/index.cjs.map create mode 100644 packages/css-tokenizer/dist/index.mjs.map diff --git a/packages/css-tokenizer/dist/consume/whitespace-token.d.ts b/packages/css-tokenizer/dist/consume/whitespace-token.d.ts index 76930adea..86585f70d 100644 --- a/packages/css-tokenizer/dist/consume/whitespace-token.d.ts +++ b/packages/css-tokenizer/dist/consume/whitespace-token.d.ts @@ -1,4 +1,4 @@ import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; import { TokenWhitespace } from '../interfaces/token'; -export declare function consumeWhiteSpace(ctx: Context, reader: CodePointReader, max?: number): TokenWhitespace; +export declare function consumeWhiteSpace(ctx: Context, reader: CodePointReader): TokenWhitespace; diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index 106a040b0..13307e4ec 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1,1181 @@ -"use strict";class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=se}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===v)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===T)}function isNewLine(e){switch(e){case x:case s:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case x:case s:case S:case c:case H:return!0;default:return!1}}const ce="\ud800".charCodeAt(0),ae="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,r){return r.codePointSource[r.cursor]===N&&r.codePointSource[r.cursor+1]!==x}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,r){return r.codePointSource[r.cursor]===T?r.codePointSource[r.cursor+1]===T||(!!isIdentStartCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===N&&r.codePointSource[r.cursor+2]!==x):!!isIdentStartCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)}function checkIfThreeCodePointsWouldStartANumber(e,r){return r.codePointSource[r.cursor]===w||r.codePointSource[r.cursor]===T?!!isDigitCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===P&&isDigitCodePoint(r.codePointSource[r.cursor+2]):r.codePointSource[r.cursor]===P?isDigitCodePoint(r.codePointSource[r.cursor+1]):!!isDigitCodePoint(r.codePointSource[r.cursor])}function checkIfTwoCodePointsStartAComment(e,r){return r.codePointSource[r.cursor]===B&&r.codePointSource[r.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,r){return r.codePointSource[r.cursor]===T&&r.codePointSource[r.cursor+1]===T&&r.codePointSource[r.cursor+2]===h}function consumeComment(e,r){for(r.readCodePoint(2);;){const o=r.readCodePoint();if(!1===o){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:r.representationStart,end:r.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(o===n&&(void 0!==r.codePointSource[r.cursor]&&r.codePointSource[r.cursor]===B)){r.readCodePoint();break}}return[exports.TokenType.Comment,r.representationString(),r.representationStart,r.representationEnd,void 0]}function consumeEscapedCodePoint(e,r){const o=r.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:r.representationStart,end:r.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),L;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==r.codePointSource[r.cursor]&&isHexDigitCodePoint(r.codePointSource[r.cursor])&&e.length<6;)e.push(r.codePointSource[r.cursor]),r.readCodePoint();isWhitespace(r.codePointSource[r.cursor])&&r.readCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?L:ce<=(t=n)&&t<=ae||n>I?L:n}var t;return o}function consumeIdentSequence(e,r){const o=[];for(;;){if(void 0===r.codePointSource[r.cursor])return o;if(isIdentCodePoint(r.codePointSource[r.cursor]))o.push(r.codePointSource[r.cursor]),r.readCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,r))return o;r.readCodePoint(),o.push(consumeEscapedCodePoint(e,r))}}}function consumeHashToken(e,r){if(r.readCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let t=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(t=o.ID);const n=consumeIdentSequence(e,r);return[exports.TokenType.Hash,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...n),type:t}]}return[exports.TokenType.Delim,r.representationString(),r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,r){let o=exports.NumberType.Integer;const t=[];{r.codePointSource[r.cursor]!==w&&r.codePointSource[r.cursor]!==T||(t.push(r.codePointSource[r.cursor]),r.readCodePoint());const e=consumeDigits(r);for(let r=0;r0&&r.unreadCodePoint(n),[exports.TokenType.Function,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...o)}];break}return n>0&&r.unreadCodePoint(n),consumeUrlToken(e,r)}return r.readCodePoint(),[exports.TokenType.Function,r.representationString(),r.representationStart,r.representationEnd,{value:String.fromCharCode(...o)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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.stringify=function stringify(...e){let r="";for(let o=0;o{})};return{nextToken:function nextToken(){if(n.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,n)){if(null!=r&&r.commentsAreTokens)return consumeComment(i,n);consumeComment(i,n),n.resetRepresentation()}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,n);switch(e){case d:return n.readCodePoint(),[exports.TokenType.Comma,n.representationString(),n.representationStart,n.representationEnd,void 0];case a:return n.readCodePoint(),[exports.TokenType.Colon,n.representationString(),n.representationStart,n.representationEnd,void 0];case q:return n.readCodePoint(),[exports.TokenType.Semicolon,n.representationString(),n.representationStart,n.representationEnd,void 0];case g:return n.readCodePoint(),[exports.TokenType.OpenParen,n.representationString(),n.representationStart,n.representationEnd,void 0];case W:return n.readCodePoint(),[exports.TokenType.CloseParen,n.representationString(),n.representationStart,n.representationEnd,void 0];case A:return n.readCodePoint(),[exports.TokenType.OpenSquare,n.representationString(),n.representationStart,n.representationEnd,void 0];case F:return n.readCodePoint(),[exports.TokenType.CloseSquare,n.representationString(),n.representationStart,n.representationEnd,void 0];case k:return n.readCodePoint(),[exports.TokenType.OpenCurly,n.representationString(),n.representationStart,n.representationEnd,void 0];case R:return n.readCodePoint(),[exports.TokenType.CloseCurly,n.representationString(),n.representationStart,n.representationEnd,void 0];case t:case b:return consumeStringToken(i,n);case U:return consumeHashToken(i,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):(n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:String.fromCharCode(e)}]);case M:case z:case K:case J:case Q:case Z:case _:case j:case G:case X:return consumeNumericToken(i,n);case x:case s:case S:case c:case H:return consumeWhiteSpace(0,n);case T:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.readCodePoint(3),[exports.TokenType.CDC,n.representationString(),n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(i,n):(n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"-"}]);case E:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.readCodePoint(4),[exports.TokenType.CDO,n.representationString(),n.representationStart,n.representationEnd,void 0]):(n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(i,n);return[exports.TokenType.AtKeyword,n.representationString(),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(i,n):(n.readCodePoint(),i.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:"\\"}])}return n.readCodePoint(),[exports.TokenType.Delim,n.representationString(),n.representationStart,n.representationEnd,{value:String.fromCharCode(e)}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; +'use strict'; + +class Reader { + cursor; + source = ''; + codePointSource = []; + length = 0; + representationStart = 0; + representationEnd = -1; + constructor(source) { + this.cursor = 0; + this.source = source; + this.length = source.length; + this.codePointSource = new Array(this.length); + for (let i = 0; i < this.length; i++) { + this.codePointSource[i] = this.source.charCodeAt(i); + } + } + cursorPositionOfLastReadCodePoint() { + return this.cursor - 1; + } + advanceCodePoint(n = 1) { + this.cursor += n; + this.representationEnd = this.cursor - 1; + } + readCodePoint(n = 1) { + const codePoint = this.codePointSource[this.cursor]; + if (codePoint === undefined) { + return false; + } + this.cursor += n; + this.representationEnd = this.cursor - 1; + return codePoint; + } + unreadCodePoint(n = 1) { + if (this.cursor === 0) { + return false; + } + this.cursor -= n; + this.representationEnd = this.cursor - 1; + return true; + } + representationString() { + return this.source.slice(this.representationStart, this.representationEnd + 1); + } + resetRepresentation() { + this.representationStart = this.cursor; + this.representationEnd = -1; + } + slice(start, end) { + return this.source.slice(start, end); + } +} + +exports.TokenType = void 0; +(function (TokenType) { + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */ + TokenType["Comment"] = "comment"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */ + TokenType["AtKeyword"] = "at-keyword-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */ + TokenType["BadString"] = "bad-string-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */ + TokenType["BadURL"] = "bad-url-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */ + TokenType["CDC"] = "CDC-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */ + TokenType["CDO"] = "CDO-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */ + TokenType["Colon"] = "colon-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */ + TokenType["Comma"] = "comma-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */ + TokenType["Delim"] = "delim-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */ + TokenType["Dimension"] = "dimension-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */ + TokenType["EOF"] = "EOF-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */ + TokenType["Function"] = "function-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */ + TokenType["Hash"] = "hash-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */ + TokenType["Ident"] = "ident-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ + TokenType["Number"] = "number-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ + TokenType["Percentage"] = "percentage-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */ + TokenType["Semicolon"] = "semicolon-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */ + TokenType["String"] = "string-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */ + TokenType["URL"] = "url-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */ + TokenType["Whitespace"] = "whitespace-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */ + TokenType["OpenParen"] = "(-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */ + TokenType["CloseParen"] = ")-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */ + TokenType["OpenSquare"] = "[-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */ + TokenType["CloseSquare"] = "]-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */ + TokenType["OpenCurly"] = "{-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */ + TokenType["CloseCurly"] = "}-token"; +})(exports.TokenType || (exports.TokenType = {})); +exports.NumberType = void 0; +(function (NumberType) { + NumberType["Integer"] = "integer"; + NumberType["Number"] = "number"; +})(exports.NumberType || (exports.NumberType = {})); +var HashType; +(function (HashType) { + HashType["Unrestricted"] = "unrestricted"; + HashType["ID"] = "id"; +})(HashType || (HashType = {})); +function mirrorVariantType(type) { + switch (type) { + 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; + } +} +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function isToken(x) { + if (!Array.isArray(x)) { + return false; + } + if (x.length < 4) { + return false; + } + if (!(x[0] in exports.TokenType)) { + return false; + } + if (typeof x[1] !== 'string') { + return false; + } + if (typeof x[2] !== 'number') { + return false; + } + if (typeof x[3] !== 'number') { + return false; + } + return true; +} + +function stringify(...tokens) { + let buffer = ''; + for (let i = 0; i < tokens.length; i++) { + buffer = buffer + tokens[i][1]; + } + return buffer; +} + +/** ' */ +const APOSTROPHE = '\u{27}'.charCodeAt(0); +/** * */ +const ASTERISK = '\u{2a}'.charCodeAt(0); +/** \b */ +const BACKSPACE = '\u{8}'.charCodeAt(0); +/** \r */ +const CARRIAGE_RETURN = '\u{d}'.charCodeAt(0); +/** \t */ +const CHARACTER_TABULATION = '\u{9}'.charCodeAt(0); +/** : */ +const COLON = '\u{3a}'.charCodeAt(0); +/** , */ +const COMMA = '\u{2c}'.charCodeAt(0); +/** @ */ +const COMMERCIAL_AT = '\u{40}'.charCodeAt(0); +/** \x7F */ +const DELETE = '\u{7f}'.charCodeAt(0); +/** ! */ +const EXCLAMATION_MARK = '\u{21}'.charCodeAt(0); +/** \f */ +const FORM_FEED = '\u{c}'.charCodeAt(0); +/** . */ +const FULL_STOP = '\u{2e}'.charCodeAt(0); +/** > */ +const GREATER_THAN_SIGN = '\u{3e}'.charCodeAt(0); +/** - */ +const HYPHEN_MINUS = '\u{2d}'.charCodeAt(0); +/** \x1F */ +const INFORMATION_SEPARATOR_ONE = '\u{1f}'.charCodeAt(0); +/** E */ +const LATIN_CAPITAL_LETTER_E = '\u{45}'.charCodeAt(0); +/** e */ +const LATIN_SMALL_LETTER_E = '\u{65}'.charCodeAt(0); +/** { */ +const LEFT_CURLY_BRACKET = '\u{7b}'.charCodeAt(0); +/** ( */ +const LEFT_PARENTHESIS = '\u{28}'.charCodeAt(0); +/** [ */ +const LEFT_SQUARE_BRACKET = '\u{5b}'.charCodeAt(0); +/** < */ +const LESS_THAN_SIGN = '\u{3c}'.charCodeAt(0); +/** \n */ +const LINE_FEED = '\u{a}'.charCodeAt(0); +/** \v */ +const LINE_TABULATION = '\u{b}'.charCodeAt(0); +/** _ */ +const LOW_LINE = '\u{5f}'.charCodeAt(0); +/** \x10FFFF */ +const MAXIMUM_ALLOWED_CODEPOINT = '\u{10FFFF}'.charCodeAt(0); +/** \x00 */ +const NULL = '\u{0}'.charCodeAt(0); +/** # */ +const NUMBER_SIGN = '\u{23}'.charCodeAt(0); +/** % */ +const PERCENTAGE_SIGN = '\u{25}'.charCodeAt(0); +/** + */ +const PLUS_SIGN = '\u{2b}'.charCodeAt(0); +/** " */ +const QUOTATION_MARK = '\u{22}'.charCodeAt(0); +/** � */ +const REPLACEMENT_CHARACTER = '\u{0FFFD}'.charCodeAt(0); +/** \ */ +const REVERSE_SOLIDUS = '\u{5c}'.charCodeAt(0); +/** } */ +const RIGHT_CURLY_BRACKET = '\u{7d}'.charCodeAt(0); +/** ) */ +const RIGHT_PARENTHESIS = '\u{29}'.charCodeAt(0); +/** ] */ +const RIGHT_SQUARE_BRACKET = '\u{5d}'.charCodeAt(0); +/** ; */ +const SEMICOLON = '\u{3b}'.charCodeAt(0); +/** \u0E */ +const SHIFT_OUT = '\u{e}'.charCodeAt(0); +/** / */ +const SOLIDUS = '\u{2f}'.charCodeAt(0); +/** \u20 */ +const SPACE = '\u{20}'.charCodeAt(0); +/** 0 */ +const DIGIT_0 = '\u{30}'.charCodeAt(0); +/** 1 */ +const DIGIT_1 = '\u{31}'.charCodeAt(0); +/** 2 */ +const DIGIT_2 = '\u{32}'.charCodeAt(0); +/** 3 */ +const DIGIT_3 = '\u{33}'.charCodeAt(0); +/** 4 */ +const DIGIT_4 = '\u{34}'.charCodeAt(0); +/** 5 */ +const DIGIT_5 = '\u{35}'.charCodeAt(0); +/** 6 */ +const DIGIT_6 = '\u{36}'.charCodeAt(0); +/** 7 */ +const DIGIT_7 = '\u{37}'.charCodeAt(0); +/** 8 */ +const DIGIT_8 = '\u{38}'.charCodeAt(0); +/** 9 */ +const DIGIT_9 = '\u{39}'.charCodeAt(0); + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token +function checkIfFourCodePointsWouldStartCDO(ctx, reader) { + return reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor + 1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 3] === HYPHEN_MINUS; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions +const digitsLow = '\u{30}'.charCodeAt(0); +const digitsHigh = '\u{39}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit +function isDigitCodePoint(search) { + return digitsLow <= search && search <= digitsHigh; +} +const letterUppercaseLow = '\u{41}'.charCodeAt(0); +const letterUppercaseHigh = '\u{5a}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter +function isUppercaseLetterCodePoint(search) { + return letterUppercaseLow <= search && search <= letterUppercaseHigh; +} +const letterLowercaseLow = '\u{61}'.charCodeAt(0); +const letterLowercaseHigh = '\u{7a}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter +function isLowercaseLetterCodePoint(search) { + return letterLowercaseLow <= search && search <= letterLowercaseHigh; +} +const afUppercaseHigh = '\u{46}'.charCodeAt(0); +const afLowercaseHigh = '\u{66}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit +function isHexDigitCodePoint(search) { + if (digitsLow <= search && search <= digitsHigh) { + return true; + } + if (letterLowercaseLow <= search && search <= afLowercaseHigh) { + return true; + } + if (letterUppercaseLow <= search && search <= afUppercaseHigh) { + return true; + } + return false; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter +function isLetterCodePoint(search) { + return isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search); +} +const nonASCIILow = '\u{80}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point +function isNonASCIICodePoint(search) { + return search >= nonASCIILow; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point +function isIdentStartCodePoint(search) { + if (isLetterCodePoint(search)) { + return true; + } + if (isNonASCIICodePoint(search)) { + return true; + } + return search === LOW_LINE; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point +function isIdentCodePoint(search) { + if (isIdentStartCodePoint(search)) { + return true; + } + if (isDigitCodePoint(search)) { + return true; + } + return search === HYPHEN_MINUS; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point +function isNonPrintableCodePoint(search) { + if (search === LINE_TABULATION) { + return true; + } + if (search === DELETE) { + return true; + } + if (NULL <= search && search <= BACKSPACE) { + return true; + } + return SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace +function isNewLine(search) { + switch (search) { + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing + // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. + // Applying the preprocessing rules would make it impossible to match the input. + // A side effect of this is that our definition of whitespace is broader. + return true; + default: + return false; + } +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace +function isWhitespace(search) { + // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing + // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. + // Applying the preprocessing rules would make it impossible to match the input. + // A side effect of this is that our definition of whitespace is broader. + switch (search) { + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + case CHARACTER_TABULATION: + case SPACE: + return true; + default: + return false; + } +} +const surrogateLow = '\u{d800}'.charCodeAt(0); +const surrogateHigh = '\u{dfff}'.charCodeAt(0); +// https://infra.spec.whatwg.org/#surrogate +function isSurrogate(search) { + return surrogateLow <= search && search <= surrogateHigh; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape +function checkIfTwoCodePointsAreAValidEscape(ctx, reader) { + // If the first code point is not U+005C REVERSE SOLIDUS (\), return false. + if (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { + // "\" + return false; + } + // Otherwise, if the second code point is a newline, return false. + if (reader.codePointSource[reader.cursor + 1] === LINE_FEED) { + return false; + } + // Otherwise, return true. + return true; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier +function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader) { + // // U+002D HYPHEN-MINUS + if (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { + // If the second code point is a U+002D HYPHEN-MINUS return true + if (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS) { + return true; + } + // If the second code point is an ident-start code point return true + if (isIdentStartCodePoint(reader.codePointSource[reader.cursor + 1])) { + return true; + } + // If the second and third code points are a valid escape return true + if (reader.codePointSource[reader.cursor + 1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) { + return true; + } + return false; + } + // ident-start code point + // Return true. + if (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) { + return true; + } + // U+005C REVERSE SOLIDUS (\) + return checkIfTwoCodePointsAreAValidEscape(ctx, reader); +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number +function checkIfThreeCodePointsWouldStartANumber(ctx, reader) { + if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { + // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) + // If the second code point is a digit, return true. + if (isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { + return true; + } + // Otherwise, if the second code point is a U+002E FULL STOP (.) + if (reader.codePointSource[reader.cursor + 1] === FULL_STOP) { + // and the third code point is a digit, return true. + return isDigitCodePoint(reader.codePointSource[reader.cursor + 2]); + } + // Otherwise, return false. + return false; + } else if (reader.codePointSource[reader.cursor] === FULL_STOP) { + // U+002E FULL STOP (.) + // If the second code point is a digit, return true. + // Otherwise, return false. + return isDigitCodePoint(reader.codePointSource[reader.cursor + 1]); + } else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { + // digit + // Return true. + return true; + } + // anything else + // Return false. + return false; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments +function checkIfTwoCodePointsStartAComment(ctx, reader) { + if (reader.codePointSource[reader.cursor] !== SOLIDUS) { + return false; + } + if (reader.codePointSource[reader.cursor + 1] !== ASTERISK) { + return false; + } + // Otherwise, return true. + return true; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token +function checkIfThreeCodePointsWouldStartCDC(ctx, reader) { + return reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment +function consumeComment(ctx, reader) { + reader.advanceCodePoint(2); + // eslint-disable-next-line no-constant-condition + while (true) { + const codePoint = reader.readCodePoint(); + if (codePoint === false) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a comment.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.2. Consume comments', 'Unexpected EOF'] + }); + break; + } + if (codePoint !== ASTERISK) { + continue; + } + if (reader.codePointSource[reader.cursor] === undefined) { + continue; + } + if (reader.codePointSource[reader.cursor] === SOLIDUS) { + reader.advanceCodePoint(); + break; + } + } + return [exports.TokenType.Comment, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point +function consumeEscapedCodePoint(ctx, reader) { + const codePoint = reader.readCodePoint(); + if (codePoint === false) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming an escaped code point.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.7. Consume an escaped code point', 'Unexpected EOF'] + }); + return REPLACEMENT_CHARACTER; + } + if (isHexDigitCodePoint(codePoint)) { + const hexSequence = [codePoint]; + while (reader.codePointSource[reader.cursor] !== undefined && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) { + hexSequence.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } + if (isWhitespace(reader.codePointSource[reader.cursor])) { + reader.advanceCodePoint(); + } + const codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16); + if (codePointLiteral === 0) { + return REPLACEMENT_CHARACTER; + } + if (isSurrogate(codePointLiteral)) { + return REPLACEMENT_CHARACTER; + } + if (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) { + return REPLACEMENT_CHARACTER; + } + return codePointLiteral; + } + return codePoint; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name +function consumeIdentSequence(ctx, reader) { + const result = []; + // eslint-disable-next-line no-constant-condition + while (true) { + if (isIdentCodePoint(reader.codePointSource[reader.cursor])) { + result.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + continue; + } + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + reader.advanceCodePoint(); + result.push(consumeEscapedCodePoint(ctx, reader)); + continue; + } + return result; + } +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token +function consumeHashToken(ctx, reader) { + reader.advanceCodePoint(); + if (reader.codePointSource[reader.cursor] !== undefined && isIdentCodePoint(reader.codePointSource[reader.cursor]) || checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + let hashType = HashType.Unrestricted; + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + hashType = HashType.ID; + } + const identSequence = consumeIdentSequence(ctx, reader); + return [exports.TokenType.Hash, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...identSequence), + type: hashType + }]; + } + return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '#' + }]; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number +function consumeNumber(ctx, reader) { + // 1. Initially set type to "integer". + // Let repr be the empty string. + let type = exports.NumberType.Integer; + const repr = []; + { + // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr. + if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { + repr.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } + // 3. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + { + // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then: + if (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { + // 4.2. Append them to repr. + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor + 1]); + // 4.1. Consume them. + reader.advanceCodePoint(2); + // 4.3. Set type to "number". + type = exports.NumberType.Number; + // 4.4. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + } + { + // 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), + // optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+), + // followed by a digit, then: + if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { + // 5.2. Append them to repr. + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor + 1]); + // 5.1. Consume them. + reader.advanceCodePoint(2); + // 5.3. Set type to "number". + type = exports.NumberType.Number; + // 5.4. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor + 1] === PLUS_SIGN) && isDigitCodePoint(reader.codePointSource[reader.cursor + 2])) { + // 5.2. Append them to repr. + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor + 1]); + repr.push(reader.codePointSource[reader.cursor + 2]); + // 5.1. Consume them. + reader.advanceCodePoint(3); + // 5.3. Set type to "number". + type = exports.NumberType.Number; + // 5.4. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + } + // 6. Convert repr to a number, and set the value to the returned value. + const value = convertCodePointsToNumber(repr); + // 7. Return value and type. + return [value, type]; +} +function consumeDigits(reader) { + const value = []; + // eslint-disable-next-line no-constant-condition + while (true) { + if (reader.codePointSource[reader.cursor] === undefined) { + return value; + } + if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { + value.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } else { + return value; + } + } +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number +function convertCodePointsToNumber(codePoints) { + let s = 1; + const iCodePoints = []; + let i = 0; + let d = 0; + const fCodePoints = []; + let f = 0; + let t = 1; + const eCodePoints = []; + let e = 0; + let cursor = 0; + // 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. + // Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-); + // otherwise, let s be the number 1. + if (codePoints[cursor] === HYPHEN_MINUS) { + cursor++; + s = -1; + } else if (codePoints[cursor] === PLUS_SIGN) { + cursor++; + } + // 2. An integer part: zero or more digits. + // If there is at least one digit, + // let i be the number formed by interpreting the digits as a base-10 integer; + // otherwise, let i be the number 0. + while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { + iCodePoints.push(codePoints[cursor]); + cursor++; + } + i = digitCodePointsToInteger(iCodePoints); + // 3. A decimal point: a single U+002E FULL STOP (.), or the empty string. + if (codePoints[cursor] === FULL_STOP) { + cursor++; + } + // 4. A fractional part: zero or more digits. + // If there is at least one digit, + // let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits; + // otherwise, let f and d be the number 0. + while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { + fCodePoints.push(codePoints[cursor]); + cursor++; + } + d = fCodePoints.length; + f = digitCodePointsToInteger(fCodePoints) / Math.pow(10, d); + // 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string. + if (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) { + cursor++; + } + // 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. + // Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-); + // otherwise, let t be the number 1. + if (codePoints[cursor] === HYPHEN_MINUS) { + cursor++; + t = -1; + } else if (codePoints[cursor] === PLUS_SIGN) { + cursor++; + } + // 7. An exponent: zero or more digits. + // If there is at least one digit, + // let e be the number formed by interpreting the digits as a base-10 integer; + // otherwise, let e be the number 0. + while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { + eCodePoints.push(codePoints[cursor]); + cursor++; + } + e = digitCodePointsToInteger(eCodePoints); + // Return the number s·(i + f·10-d)·10te. + return s * (i + f) * Math.pow(10, t * e); +} +function digitCodePointsToInteger(codePoints) { + if (codePoints.length === 0) { + return 0; + } + return Number.parseInt(String.fromCharCode(...codePoints), 10); +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token +function consumeNumericToken(ctx, reader) { + const numberValue = consumeNumber(ctx, reader); + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + const unit = consumeIdentSequence(ctx, reader); + return [exports.TokenType.Dimension, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: numberValue[0], + type: numberValue[1], + unit: String.fromCharCode(...unit) + }]; + } + { + if (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) { + reader.advanceCodePoint(); + return [exports.TokenType.Percentage, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: numberValue[0] + }]; + } + } + return [exports.TokenType.Number, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: numberValue[0], + type: numberValue[1] + }]; +} + +function consumeWhiteSpace(ctx, reader) { + // eslint-disable-next-line no-constant-condition + while (true) { + if (!isWhitespace(reader.codePointSource[reader.cursor])) { + break; + } + reader.advanceCodePoint(); + } + return [exports.TokenType.Whitespace, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token +function consumeStringToken(ctx, reader) { + let result = ''; + const first = reader.readCodePoint(); + if (first === false) { + throw new Error('Unexpected EOF'); + } + // eslint-disable-next-line no-constant-condition + while (true) { + const next = reader.readCodePoint(); + if (next === false) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a string token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.5. Consume a string token', 'Unexpected EOF'] + }); + return [exports.TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: result + }]; + } + if (isNewLine(next)) { + { + ctx.onParseError({ + message: 'Unexpected newline while consuming a string token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.5. Consume a string token', 'Unexpected newline'] + }); + } + reader.unreadCodePoint(); + return [exports.TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (next === first) { + return [exports.TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: result + }]; + } + if (next === REVERSE_SOLIDUS) { + if (reader.codePointSource[reader.cursor] === undefined) { + continue; + } + if (isNewLine(reader.codePointSource[reader.cursor])) { + reader.advanceCodePoint(); + continue; + } + result += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); + continue; + } + result += String.fromCharCode(next); + } +} + +const u = 'u'.charCodeAt(0); +const U = 'U'.charCodeAt(0); +const r = 'r'.charCodeAt(0); +const R = 'R'.charCodeAt(0); +const l = 'l'.charCodeAt(0); +const L = 'L'.charCodeAt(0); +function checkIfCodePointsMatchURLIdent(ctx, codePoints) { + if (codePoints.length !== 3) { + return false; + } + if (codePoints[0] !== u && codePoints[0] !== U) { + return false; + } + if (codePoints[1] !== r && codePoints[1] !== R) { + return false; + } + if (codePoints[2] !== l && codePoints[2] !== L) { + return false; + } + return true; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url +function consumeBadURL(ctx, reader) { + // eslint-disable-next-line no-constant-condition + while (true) { + if (reader.codePointSource[reader.cursor] === undefined) { + return; + } + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { + reader.advanceCodePoint(); + return; + } + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + reader.advanceCodePoint(); + consumeEscapedCodePoint(ctx, reader); + continue; + } + reader.advanceCodePoint(); + continue; + } +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token +function consumeUrlToken(ctx, reader) { + consumeWhiteSpace(ctx, reader); + let string = ''; + // eslint-disable-next-line no-constant-condition + while (true) { + if (reader.codePointSource[reader.cursor] === undefined) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'Unexpected EOF'] + }); + return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { + reader.advanceCodePoint(); + return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + if (isWhitespace(reader.codePointSource[reader.cursor])) { + consumeWhiteSpace(ctx, reader); + if (reader.codePointSource[reader.cursor] === undefined) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'Consume as much whitespace as possible', 'Unexpected EOF'] + }); + return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { + reader.advanceCodePoint(); + return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + consumeBadURL(ctx, reader); + return [exports.TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) { + consumeBadURL(ctx, reader); + ctx.onParseError({ + message: 'Unexpected character while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'Unexpected U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE (\'), U+0028 LEFT PARENTHESIS (() or non-printable code point'] + }); + return [exports.TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) { + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + string += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); + continue; + } + consumeBadURL(ctx, reader); + ctx.onParseError({ + message: 'Invalid escape sequence while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] + }); + return [exports.TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + string += String.fromCharCode(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token +function consumeIdentLikeToken(ctx, reader) { + const codePoints = consumeIdentSequence(ctx, reader); + if (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) { + return [exports.TokenType.Ident, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...codePoints) + }]; + } + if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { + reader.advanceCodePoint(); + let read = 0; + // eslint-disable-next-line no-constant-condition + while (true) { + const firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]); + const secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor + 1]); + if (firstIsWhitespace && secondIsWhitespace) { + read += 2; + reader.advanceCodePoint(2); + continue; + } + const firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor + 1] : reader.codePointSource[reader.cursor]; + if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { + if (read > 0) { + reader.advanceCodePoint(read); + } + return [exports.TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...codePoints) + }]; + } + break; + } + if (read > 0) { + reader.advanceCodePoint(read); + } + return consumeUrlToken(ctx, reader); + } + reader.advanceCodePoint(); + return [exports.TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...codePoints) + }]; +} + +function tokenizer(input, options) { + const css = input.css.valueOf(); + const reader = new Reader(css); + const ctx = { + onParseError: (options == null ? void 0 : options.onParseError) ?? (() => {}) + }; + function endOfFile() { + return reader.codePointSource[reader.cursor] === undefined; + } + function nextToken() { + reader.resetRepresentation(); + if (checkIfTwoCodePointsStartAComment(ctx, reader)) { + if (options != null && options.commentsAreTokens) { + return consumeComment(ctx, reader); + } else { + consumeComment(ctx, reader); + reader.resetRepresentation(); + } + } + const peeked = reader.codePointSource[reader.cursor]; + if (peeked === undefined) { + return [exports.TokenType.EOF, '', -1, -1, undefined]; + } + if (isIdentStartCodePoint(peeked)) { + return consumeIdentLikeToken(ctx, reader); + } + // Simple, one character tokens: + switch (peeked) { + case COMMA: + { + reader.advanceCodePoint(); + return [exports.TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case COLON: + { + reader.advanceCodePoint(); + return [exports.TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case SEMICOLON: + { + reader.advanceCodePoint(); + return [exports.TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case LEFT_PARENTHESIS: + { + reader.advanceCodePoint(); + return [exports.TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case RIGHT_PARENTHESIS: + { + reader.advanceCodePoint(); + return [exports.TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case LEFT_SQUARE_BRACKET: + { + reader.advanceCodePoint(); + return [exports.TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case RIGHT_SQUARE_BRACKET: + { + reader.advanceCodePoint(); + return [exports.TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case LEFT_CURLY_BRACKET: + { + reader.advanceCodePoint(); + return [exports.TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case RIGHT_CURLY_BRACKET: + { + reader.advanceCodePoint(); + return [exports.TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case APOSTROPHE: + case QUOTATION_MARK: + return consumeStringToken(ctx, reader); + case NUMBER_SIGN: + return consumeHashToken(ctx, reader); + case PLUS_SIGN: + case FULL_STOP: + { + if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { + return consumeNumericToken(ctx, reader); + } + reader.advanceCodePoint(); + return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: reader.representationString() + }]; + } + case DIGIT_0: + case DIGIT_1: + case DIGIT_2: + case DIGIT_3: + case DIGIT_4: + case DIGIT_5: + case DIGIT_6: + case DIGIT_7: + case DIGIT_8: + case DIGIT_9: + return consumeNumericToken(ctx, reader); + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + case CHARACTER_TABULATION: + case SPACE: + return consumeWhiteSpace(ctx, reader); + case HYPHEN_MINUS: + { + if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { + return consumeNumericToken(ctx, reader); + } + if (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) { + reader.advanceCodePoint(3); + return [exports.TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + return consumeIdentLikeToken(ctx, reader); + } + reader.advanceCodePoint(); + return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '-' + }]; + } + case LESS_THAN_SIGN: + { + if (checkIfFourCodePointsWouldStartCDO(ctx, reader)) { + reader.advanceCodePoint(4); + return [exports.TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + reader.advanceCodePoint(); + return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '<' + }]; + } + case COMMERCIAL_AT: + { + reader.advanceCodePoint(); + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + const identSequence = consumeIdentSequence(ctx, reader); + return [exports.TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...identSequence) + }]; + } + return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '@' + }]; + } + case REVERSE_SOLIDUS: + { + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + return consumeIdentLikeToken(ctx, reader); + } + reader.advanceCodePoint(); + ctx.onParseError({ + message: 'Invalid escape sequence after "\\"', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.1. Consume a token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] + }); + return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '\\' + }]; + } + } + reader.advanceCodePoint(); + return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: reader.representationString() + }]; + } + return { + nextToken: nextToken, + endOfFile: endOfFile + }; +} + +function cloneTokens(tokens) { + if (typeof globalThis !== 'undefined' && 'structuredClone' in globalThis) { + return structuredClone(tokens); + } + return JSON.parse(JSON.stringify(tokens)); +} + +exports.Reader = Reader; +exports.cloneTokens = cloneTokens; +exports.isToken = isToken; +exports.mirrorVariantType = mirrorVariantType; +exports.stringify = stringify; +exports.tokenizer = tokenizer; +//# sourceMappingURL=index.cjs.map diff --git a/packages/css-tokenizer/dist/index.cjs.map b/packages/css-tokenizer/dist/index.cjs.map new file mode 100644 index 000000000..e79e0743a --- /dev/null +++ b/packages/css-tokenizer/dist/index.cjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.cjs","sources":["../src/reader.ts","../src/interfaces/token.ts","../src/stringify.ts","../src/code-points/code-points.ts","../src/checks/four-code-points-would-start-cdo.ts","../src/code-points/ranges.ts","../src/checks/two-code-points-are-valid-escape.ts","../src/checks/three-code-points-would-start-ident-sequence.ts","../src/checks/three-code-points-would-start-number.ts","../src/checks/two-code-points-start-comment.ts","../src/checks/three-code-points-would-start-cdc.ts","../src/consume/comment.ts","../src/consume/escaped-code-point.ts","../src/consume/ident-sequence.ts","../src/consume/hash-token.ts","../src/consume/number.ts","../src/consume/numeric-token.ts","../src/consume/whitespace-token.ts","../src/consume/string-token.ts","../src/checks/matches-url-ident.ts","../src/consume/bad-url.ts","../src/consume/url-token.ts","../src/consume/ident-like-token.ts","../src/tokenizer.ts","../src/util/clone-tokens.ts"],"sourcesContent":["import { CodePointReader } from './interfaces/code-point-reader';\n\nexport class Reader implements CodePointReader {\n\tcursor: number;\n\tsource = '';\n\tcodePointSource: Array = [];\n\tlength = 0;\n\n\trepresentationStart = 0;\n\trepresentationEnd = -1;\n\n\tconstructor(source: string) {\n\t\tthis.cursor = 0;\n\t\tthis.source = source;\n\t\tthis.length = source.length;\n\n\t\tthis.codePointSource = new Array(this.length);\n\t\tfor (let i = 0; i < this.length; i++) {\n\t\t\tthis.codePointSource[i] = this.source.charCodeAt(i);\n\t\t}\n\t}\n\n\tcursorPositionOfLastReadCodePoint(): number {\n\t\treturn this.cursor - 1;\n\t}\n\n\tadvanceCodePoint(n = 1) {\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\t}\n\n\treadCodePoint(n = 1): number | false {\n\t\tconst codePoint = this.codePointSource[this.cursor];\n\t\tif (codePoint === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn codePoint;\n\t}\n\n\tunreadCodePoint(n = 1): boolean {\n\t\tif (this.cursor === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor -= n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn true;\n\t}\n\n\trepresentationString(): string {\n\t\treturn this.source.slice(this.representationStart, this.representationEnd + 1);\n\t}\n\n\tresetRepresentation() {\n\t\tthis.representationStart = this.cursor;\n\t\tthis.representationEnd = -1;\n\t}\n\n\tslice(start: number, end: number): string {\n\t\treturn this.source.slice(start, end);\n\t}\n}\n","export enum TokenType {\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */\n\tComment = 'comment',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */\n\tAtKeyword = 'at-keyword-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */\n\tBadString = 'bad-string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */\n\tBadURL = 'bad-url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */\n\tCDC = 'CDC-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */\n\tCDO = 'CDO-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */\n\tColon = 'colon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */\n\tComma = 'comma-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */\n\tDelim = 'delim-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */\n\tDimension = 'dimension-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */\n\tEOF = 'EOF-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */\n\tFunction = 'function-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */\n\tHash = 'hash-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */\n\tIdent = 'ident-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tNumber = 'number-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tPercentage = 'percentage-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */\n\tSemicolon = 'semicolon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */\n\tString = 'string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */\n\tURL = 'url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */\n\tWhitespace = 'whitespace-token',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */\n\tOpenParen = '(-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */\n\tCloseParen = ')-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */\n\tOpenSquare = '[-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */\n\tCloseSquare = ']-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */\n\tOpenCurly = '{-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */\n\tCloseCurly = '}-token',\n}\n\nexport enum NumberType {\n\tInteger = 'integer',\n\tNumber = 'number',\n}\n\nexport enum HashType {\n\tUnrestricted = 'unrestricted',\n\tID = 'id',\n}\n\nexport type TokenAtKeyword = Token;\nexport type TokenBadString = Token;\nexport type TokenBadURL = Token;\nexport type TokenCDC = Token;\nexport type TokenCDO = Token;\nexport type TokenColon = Token;\nexport type TokenComma = Token;\nexport type TokenComment = Token;\nexport type TokenDelim = Token;\nexport type TokenDimension = Token;\nexport type TokenEOF = Token;\nexport type TokenFunction = Token;\nexport type TokenHash = Token;\nexport type TokenIdent = Token;\nexport type TokenNumber = Token;\nexport type TokenPercentage = Token;\nexport type TokenSemicolon = Token;\nexport type TokenString = Token;\nexport type TokenURL = Token;\nexport type TokenWhitespace = Token;\n\nexport type TokenOpenParen = Token;\nexport type TokenCloseParen = Token;\nexport type TokenOpenSquare = Token;\nexport type TokenCloseSquare = Token;\nexport type TokenOpenCurly = Token;\nexport type TokenCloseCurly = Token;\n\nexport type CSSToken = TokenAtKeyword |\n\tTokenBadString |\n\tTokenBadURL |\n\tTokenCDC |\n\tTokenCDO |\n\tTokenColon |\n\tTokenComma |\n\tTokenComment |\n\tTokenDelim |\n\tTokenDimension |\n\tTokenEOF |\n\tTokenFunction |\n\tTokenHash |\n\tTokenIdent |\n\tTokenNumber |\n\tTokenPercentage |\n\tTokenSemicolon |\n\tTokenString |\n\tTokenURL |\n\tTokenWhitespace |\n\tTokenOpenParen |\n\tTokenCloseParen |\n\tTokenOpenSquare |\n\tTokenCloseSquare |\n\tTokenOpenCurly |\n\tTokenCloseCurly;\n\nexport type Token = [\n\t/** The type of token */\n\tT,\n\t/** The token representation */\n\tstring,\n\t/** Start position of representation */\n\tnumber,\n\t/** End position of representation */\n\tnumber,\n\t/** Extra data */\n\tU,\n]\n\nexport function mirrorVariantType(type: TokenType): TokenType|null {\n\tswitch (type) {\n\t\tcase TokenType.OpenParen:\n\t\t\treturn TokenType.CloseParen;\n\t\tcase TokenType.CloseParen:\n\t\t\treturn TokenType.OpenParen;\n\n\t\tcase TokenType.OpenCurly:\n\t\t\treturn TokenType.CloseCurly;\n\t\tcase TokenType.CloseCurly:\n\t\t\treturn TokenType.OpenCurly;\n\n\t\tcase TokenType.OpenSquare:\n\t\t\treturn TokenType.CloseSquare;\n\t\tcase TokenType.CloseSquare:\n\t\t\treturn TokenType.OpenSquare;\n\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToken(x: any): x is CSSToken {\n\tif (!Array.isArray(x)) {\n\t\treturn false;\n\t}\n\n\tif (x.length < 4) {\n\t\treturn false;\n\t}\n\n\tif (!(x[0] in TokenType)) {\n\t\treturn false;\n\t}\n\n\tif (typeof x[1] !== 'string') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[2] !== 'number') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[3] !== 'number') {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import type { CSSToken } from './interfaces/token';\n\nexport function stringify(...tokens: Array): string {\n\tlet buffer = '';\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tbuffer = buffer + tokens[i][1];\n\t}\n\n\treturn buffer;\n}\n","/** ' */\nexport const APOSTROPHE = '\\u{27}'.charCodeAt(0);\n/** * */\nexport const ASTERISK = '\\u{2a}'.charCodeAt(0);\n/** \\b */\nexport const BACKSPACE = '\\u{8}'.charCodeAt(0);\n/** \\r */\nexport const CARRIAGE_RETURN = '\\u{d}'.charCodeAt(0);\n/** \\t */\nexport const CHARACTER_TABULATION = '\\u{9}'.charCodeAt(0);\n/** : */\nexport const COLON = '\\u{3a}'.charCodeAt(0);\n/** , */\nexport const COMMA = '\\u{2c}'.charCodeAt(0);\n/** @ */\nexport const COMMERCIAL_AT = '\\u{40}'.charCodeAt(0);\n/** \\x7F */\nexport const DELETE = '\\u{7f}'.charCodeAt(0);\n/** ! */\nexport const EXCLAMATION_MARK = '\\u{21}'.charCodeAt(0);\n/** \\f */\nexport const FORM_FEED = '\\u{c}'.charCodeAt(0);\n/** . */\nexport const FULL_STOP = '\\u{2e}'.charCodeAt(0);\n/** > */\nexport const GREATER_THAN_SIGN = '\\u{3e}'.charCodeAt(0);\n/** - */\nexport const HYPHEN_MINUS = '\\u{2d}'.charCodeAt(0);\n/** \\x1F */\nexport const INFORMATION_SEPARATOR_ONE = '\\u{1f}'.charCodeAt(0);\n/** E */\nexport const LATIN_CAPITAL_LETTER_E = '\\u{45}'.charCodeAt(0);\n/** e */\nexport const LATIN_SMALL_LETTER_E = '\\u{65}'.charCodeAt(0);\n/** { */\nexport const LEFT_CURLY_BRACKET = '\\u{7b}'.charCodeAt(0);\n/** ( */\nexport const LEFT_PARENTHESIS = '\\u{28}'.charCodeAt(0);\n/** [ */\nexport const LEFT_SQUARE_BRACKET = '\\u{5b}'.charCodeAt(0);\n/** < */\nexport const LESS_THAN_SIGN = '\\u{3c}'.charCodeAt(0);\n/** \\n */\nexport const LINE_FEED = '\\u{a}'.charCodeAt(0);\n/** \\v */\nexport const LINE_TABULATION = '\\u{b}'.charCodeAt(0);\n/** _ */\nexport const LOW_LINE = '\\u{5f}'.charCodeAt(0);\n/** \\x10FFFF */\nexport const MAXIMUM_ALLOWED_CODEPOINT = '\\u{10FFFF}'.charCodeAt(0);\n/** \\x00 */\nexport const NULL = '\\u{0}'.charCodeAt(0);\n/** # */\nexport const NUMBER_SIGN = '\\u{23}'.charCodeAt(0);\n/** % */\nexport const PERCENTAGE_SIGN = '\\u{25}'.charCodeAt(0);\n/** + */\nexport const PLUS_SIGN = '\\u{2b}'.charCodeAt(0);\n/** \" */\nexport const QUOTATION_MARK = '\\u{22}'.charCodeAt(0);\n/** � */\nexport const REPLACEMENT_CHARACTER = '\\u{0FFFD}'.charCodeAt(0);\n/** \\ */\nexport const REVERSE_SOLIDUS = '\\u{5c}'.charCodeAt(0);\n/** } */\nexport const RIGHT_CURLY_BRACKET = '\\u{7d}'.charCodeAt(0);\n/** ) */\nexport const RIGHT_PARENTHESIS = '\\u{29}'.charCodeAt(0);\n/** ] */\nexport const RIGHT_SQUARE_BRACKET = '\\u{5d}'.charCodeAt(0);\n/** ; */\nexport const SEMICOLON = '\\u{3b}'.charCodeAt(0);\n/** \\u0E */\nexport const SHIFT_OUT = '\\u{e}'.charCodeAt(0);\n/** / */\nexport const SOLIDUS = '\\u{2f}'.charCodeAt(0);\n/** \\u20 */\nexport const SPACE = '\\u{20}'.charCodeAt(0);\n/** 0 */\nexport const DIGIT_0 = '\\u{30}'.charCodeAt(0);\n/** 1 */\nexport const DIGIT_1 = '\\u{31}'.charCodeAt(0);\n/** 2 */\nexport const DIGIT_2 = '\\u{32}'.charCodeAt(0);\n/** 3 */\nexport const DIGIT_3 = '\\u{33}'.charCodeAt(0);\n/** 4 */\nexport const DIGIT_4 = '\\u{34}'.charCodeAt(0);\n/** 5 */\nexport const DIGIT_5 = '\\u{35}'.charCodeAt(0);\n/** 6 */\nexport const DIGIT_6 = '\\u{36}'.charCodeAt(0);\n/** 7 */\nexport const DIGIT_7 = '\\u{37}'.charCodeAt(0);\n/** 8 */\nexport const DIGIT_8 = '\\u{38}'.charCodeAt(0);\n/** 9 */\nexport const DIGIT_9 = '\\u{39}'.charCodeAt(0);\n","import { EXCLAMATION_MARK, HYPHEN_MINUS, LESS_THAN_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfFourCodePointsWouldStartCDO(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor+1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+3] === HYPHEN_MINUS;\n}\n","import { BACKSPACE, DELETE, INFORMATION_SEPARATOR_ONE, LINE_TABULATION, LOW_LINE, HYPHEN_MINUS, NULL, SHIFT_OUT, LINE_FEED, CARRIAGE_RETURN, FORM_FEED, CHARACTER_TABULATION, SPACE } from './code-points';\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions\n\nconst digitsLow = '\\u{30}'.charCodeAt(0);\nconst digitsHigh = '\\u{39}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit\nexport function isDigitCodePoint(search: number): boolean {\n\treturn digitsLow <= search && search <= digitsHigh;\n}\n\nconst letterUppercaseLow = '\\u{41}'.charCodeAt(0);\nconst letterUppercaseHigh = '\\u{5a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter\nexport function isUppercaseLetterCodePoint(search: number): boolean {\n\treturn letterUppercaseLow <= search && search <= letterUppercaseHigh;\n}\n\nconst letterLowercaseLow = '\\u{61}'.charCodeAt(0);\nconst letterLowercaseHigh = '\\u{7a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter\nexport function isLowercaseLetterCodePoint(search: number): boolean {\n\treturn letterLowercaseLow <= search && search <= letterLowercaseHigh;\n}\n\nconst afUppercaseHigh = '\\u{46}'.charCodeAt(0);\nconst afLowercaseHigh = '\\u{66}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit\nexport function isHexDigitCodePoint(search: number): boolean {\n\tif (digitsLow <= search && search <= digitsHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterLowercaseLow <= search && search <= afLowercaseHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterUppercaseLow <= search && search <= afUppercaseHigh) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter\nexport function isLetterCodePoint(search: number): boolean {\n\treturn isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search);\n}\n\nconst nonASCIILow = '\\u{80}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point\nexport function isNonASCIICodePoint(search: number): boolean {\n\treturn search >= nonASCIILow;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point\nexport function isIdentStartCodePoint(search: number): boolean {\n\tif (isLetterCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isNonASCIICodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === LOW_LINE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point\nexport function isIdentCodePoint(search: number): boolean {\n\tif (isIdentStartCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isDigitCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === HYPHEN_MINUS;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point\nexport function isNonPrintableCodePoint(search: number): boolean {\n\tif (search === LINE_TABULATION) {\n\t\treturn true;\n\t}\n\n\tif (search === DELETE) {\n\t\treturn true;\n\t}\n\n\tif (NULL <= search && search <= BACKSPACE) {\n\t\treturn true;\n\t}\n\n\treturn SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isNewLine(search: number): boolean {\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\t\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t\t\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t\t\t// Applying the preprocessing rules would make it impossible to match the input.\n\t\t\t// A side effect of this is that our definition of whitespace is broader.\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isWhitespace(search: number): boolean {\n\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t// Applying the preprocessing rules would make it impossible to match the input.\n\t// A side effect of this is that our definition of whitespace is broader.\n\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\tcase CHARACTER_TABULATION:\n\t\tcase SPACE:\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nconst surrogateLow = '\\u{d800}'.charCodeAt(0);\nconst surrogateHigh = '\\u{dfff}'.charCodeAt(0);\n\n// https://infra.spec.whatwg.org/#surrogate\nexport function isSurrogate(search: number): boolean {\n\treturn surrogateLow <= search && search <= surrogateHigh;\n}\n","import { LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape\nexport function checkIfTwoCodePointsAreAValidEscape(ctx: Context, reader: CodePointReader): boolean {\n\t// If the first code point is not U+005C REVERSE SOLIDUS (\\), return false.\n\tif (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { // \"\\\"\n\t\treturn false;\n\t}\n\n\t// Otherwise, if the second code point is a newline, return false.\n\tif (reader.codePointSource[reader.cursor+1] === LINE_FEED) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { HYPHEN_MINUS, LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isIdentStartCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { checkIfTwoCodePointsAreAValidEscape } from './two-code-points-are-valid-escape';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier\nexport function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, reader: CodePointReader): boolean {\n\t// // U+002D HYPHEN-MINUS\n\tif (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t// If the second code point is a U+002D HYPHEN-MINUS return true\n\t\tif (reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second code point is an ident-start code point return true\n\t\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second and third code points are a valid escape return true\n\t\tif (reader.codePointSource[reader.cursor+1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t// ident-start code point\n\t// Return true.\n\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) {\n\t\treturn true;\n\t}\n\n\t// U+005C REVERSE SOLIDUS (\\)\n\treturn checkIfTwoCodePointsAreAValidEscape(ctx, reader);\n}\n","import { FULL_STOP, HYPHEN_MINUS, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number\nexport function checkIfThreeCodePointsWouldStartANumber(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-)\n\t\t// If the second code point is a digit, return true.\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Otherwise, if the second code point is a U+002E FULL STOP (.)\n\t\tif (reader.codePointSource[reader.cursor+1] === FULL_STOP) {\n\t\t\t// and the third code point is a digit, return true.\n\t\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+2]);\n\t\t}\n\n\t\t// Otherwise, return false.\n\t\treturn false;\n\n\t} else if (reader.codePointSource[reader.cursor] === FULL_STOP) { // U+002E FULL STOP (.)\n\t\t// If the second code point is a digit, return true.\n\t\t// Otherwise, return false.\n\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+1]);\n\n\t} else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { // digit\n\t\t// Return true.\n\t\treturn true;\n\t}\n\n\t// anything else\n\t// Return false.\n\treturn false;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments\nexport function checkIfTwoCodePointsStartAComment(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] !== SOLIDUS) {\n\t\treturn false;\n\t}\n\n\tif (reader.codePointSource[reader.cursor+1] !== ASTERISK) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { GREATER_THAN_SIGN, HYPHEN_MINUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfThreeCodePointsWouldStartCDC(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenComment, TokenType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment\nexport function consumeComment(ctx: Context, reader: CodePointReader): TokenComment {\n\treader.advanceCodePoint(2);\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst codePoint = reader.readCodePoint();\n\t\tif (codePoint === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a comment.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.2. Consume comments',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (codePoint !== ASTERISK) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === SOLIDUS) {\n\t\t\treader.advanceCodePoint();\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Comment,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { MAXIMUM_ALLOWED_CODEPOINT, REPLACEMENT_CHARACTER } from '../code-points/code-points';\nimport { isHexDigitCodePoint, isSurrogate, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point\nexport function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): number {\n\tconst codePoint = reader.readCodePoint();\n\tif (codePoint === false) {\n\t\tctx.onParseError({\n\t\t\tmessage: 'Unexpected EOF while consuming an escaped code point.',\n\t\t\tstart: reader.representationStart,\n\t\t\tend: reader.representationEnd,\n\t\t\tstate: [\n\t\t\t\t'4.3.7. Consume an escaped code point',\n\t\t\t\t'Unexpected EOF',\n\t\t\t],\n\t\t});\n\n\t\treturn REPLACEMENT_CHARACTER;\n\t}\n\n\tif (isHexDigitCodePoint(codePoint)) {\n\t\tconst hexSequence: Array = [codePoint];\n\n\t\twhile ((reader.codePointSource[reader.cursor] !== undefined) && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) {\n\t\t\thexSequence.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tconst codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16);\n\t\tif (codePointLiteral === 0) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (isSurrogate(codePointLiteral)) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\n\t\treturn codePointLiteral;\n\t}\n\n\treturn codePoint;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name\nexport function consumeIdentSequence(ctx: Context, reader: CodePointReader): Array {\n\tconst result: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (isIdentCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tresult.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tresult.push(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn result;\n\t}\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { HashType, TokenDelim, TokenHash, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDelim|TokenHash {\n\treader.advanceCodePoint();\n\n\tif (\n\t\t(reader.codePointSource[reader.cursor] !== undefined) &&\n\t\tisIdentCodePoint(reader.codePointSource[reader.cursor]) ||\n\t\tcheckIfTwoCodePointsAreAValidEscape(ctx, reader)\n\t) {\n\t\tlet hashType = HashType.Unrestricted;\n\n\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\thashType = HashType.ID;\n\t\t}\n\n\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\t\treturn [\n\t\t\tTokenType.Hash,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\ttype: hashType,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [\n\t\tTokenType.Delim,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: '#',\n\t\t},\n\t];\n}\n","import { FULL_STOP, HYPHEN_MINUS, LATIN_CAPITAL_LETTER_E, LATIN_SMALL_LETTER_E, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { NumberType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number\nexport function consumeNumber(ctx: Context, reader: CodePointReader): [number, NumberType] {\n\t// 1. Initially set type to \"integer\".\n\t// Let repr be the empty string.\n\tlet type = NumberType.Integer;\n\tconst repr: Array = [];\n\n\t{\n\t\t// 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr.\n\t\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\t// 3. While the next input code point is a digit, consume it and append it to repr.\n\t\tconst newPart = consumeDigits(reader);\n\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\trepr.push(newPart[i]);\n\t\t}\n\t}\n\n\t{\n\t\t// 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then:\n\t\tif (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\t// 4.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 4.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 4.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 4.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t{\n\t\t// 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e),\n\t\t// optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+),\n\t\t// followed by a digit, then:\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+1])\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\t(\n\t\t\t\t(reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor+1] === PLUS_SIGN) &&\n\t\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+2])\n\t\t\t)\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+2]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(3);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t// 6. Convert repr to a number, and set the value to the returned value.\n\tconst value = convertCodePointsToNumber(repr);\n\n\t// 7. Return value and type.\n\treturn [value, type];\n}\n\nfunction consumeDigits(reader: CodePointReader): Array {\n\tconst value: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn value;\n\t\t}\n\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tvalue.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number\nfunction convertCodePointsToNumber(codePoints: Array): number {\n\tlet s = 1;\n\tconst iCodePoints: Array = [];\n\tlet i = 0;\n\n\tlet d = 0;\n\tconst fCodePoints: Array = [];\n\tlet f = 0;\n\n\tlet t = 1;\n\n\tconst eCodePoints: Array = [];\n\tlet e = 0;\n\n\tlet cursor = 0;\n\n\t// 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let s be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\ts = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 2. An integer part: zero or more digits.\n\t// If there is at least one digit,\n\t// let i be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let i be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tiCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\ti = digitCodePointsToInteger(iCodePoints);\n\n\t// 3. A decimal point: a single U+002E FULL STOP (.), or the empty string.\n\tif (codePoints[cursor] === FULL_STOP) {\n\t\tcursor++;\n\t}\n\n\t// 4. A fractional part: zero or more digits.\n\t// If there is at least one digit,\n\t// let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits;\n\t// otherwise, let f and d be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tfCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\td = fCodePoints.length;\n\tf = (digitCodePointsToInteger(fCodePoints) / Math.pow(10, d));\n\n\t// 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string.\n\tif (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) {\n\t\tcursor++;\n\t}\n\n\t// 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let t be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\tt = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 7. An exponent: zero or more digits.\n\t// If there is at least one digit,\n\t// let e be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let e be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\teCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\te = digitCodePointsToInteger(eCodePoints);\n\n\t// Return the number s·(i + f·10-d)·10te.\n\treturn s * (i + f) * Math.pow(10, t * e);\n}\n\nfunction digitCodePointsToInteger(codePoints: Array): number {\n\tif (codePoints.length === 0) {\n\t\treturn 0;\n\t}\n\n\treturn Number.parseInt(String.fromCharCode(...codePoints), 10);\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { PERCENTAGE_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenDimension, TokenNumber, TokenPercentage, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeNumber } from './number';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token\nexport function consumeNumericToken(ctx: Context, reader: CodePointReader): TokenPercentage|TokenNumber|TokenDimension {\n\tconst numberValue = consumeNumber(ctx, reader);\n\n\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\tconst unit = consumeIdentSequence(ctx, reader);\n\n\t\treturn [\n\t\t\tTokenType.Dimension,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: numberValue[0],\n\t\t\t\ttype: numberValue[1],\n\t\t\t\tunit: String.fromCharCode(...unit),\n\t\t\t},\n\t\t];\n\t}\n\n\t{\n\t\tif (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) {\n\t\t\treader.advanceCodePoint();\n\n\t\t\treturn [\n\t\t\t\tTokenType.Percentage,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: numberValue[0],\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Number,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: numberValue[0],\n\t\t\ttype: numberValue[1],\n\t\t},\n\t];\n}\n","import { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenType, TokenWhitespace } from '../interfaces/token';\n\nexport function consumeWhiteSpace(ctx: Context, reader: CodePointReader): TokenWhitespace {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (!isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tbreak;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t}\n\n\treturn [\n\t\tTokenType.Whitespace,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isNewLine } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadString, TokenString, TokenType } from '../interfaces/token';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token\nexport function consumeStringToken(ctx: Context, reader: CodePointReader): TokenBadString|TokenString {\n\tlet result = '';\n\n\tconst first = reader.readCodePoint();\n\tif (first === false) {\n\t\tthrow new Error('Unexpected EOF');\n\t}\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst next = reader.readCodePoint();\n\t\tif (next === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a string token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (isNewLine(next)) {\n\t\t\t{\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected newline while consuming a string token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t\t'Unexpected newline',\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treader.unreadCodePoint();\n\t\t\treturn [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t}\n\n\t\tif (next === first) {\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (next === REVERSE_SOLIDUS) {\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isNewLine(reader.codePointSource[reader.cursor])) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tresult += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += String.fromCharCode(next);\n\t}\n}\n","import { Context } from '../interfaces/context';\n\nconst u = 'u'.charCodeAt(0);\nconst U = 'U'.charCodeAt(0);\nconst r = 'r'.charCodeAt(0);\nconst R = 'R'.charCodeAt(0);\nconst l = 'l'.charCodeAt(0);\nconst L = 'L'.charCodeAt(0);\n\nexport function checkIfCodePointsMatchURLIdent(ctx: Context, codePoints: Array): boolean {\n\tif (codePoints.length !== 3) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[0] !== u && codePoints[0] !== U) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[1] !== r && codePoints[1] !== R) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[2] !== l && codePoints[2] !== L) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url\nexport function consumeBadURL(ctx: Context, reader: CodePointReader) {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tconsumeEscapedCodePoint(ctx, reader);\n\t\t\tcontinue;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\tcontinue;\n\t}\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { isNonPrintableCodePoint, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeBadURL } from './bad-url';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\nimport { consumeWhiteSpace } from './whitespace-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token\nexport function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL|TokenBadURL {\n\tconsumeWhiteSpace(ctx, reader);\n\tlet string = '';\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeWhiteSpace(ctx, reader);\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t\t'Consume as much whitespace as possible',\n\t\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected character while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE (\\'), U+0028 LEFT PARENTHESIS (() or non-printable code point',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) {\n\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\tstring += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Invalid escape sequence while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tstring += String.fromCharCode(reader.codePointSource[reader.cursor]);\n\t\treader.advanceCodePoint();\n\t}\n}\n","import { checkIfCodePointsMatchURLIdent } from '../checks/matches-url-ident';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK } from '../code-points/code-points';\nimport { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenFunction, TokenIdent, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeUrlToken } from './url-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token\nexport function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): TokenIdent | TokenFunction | TokenURL | TokenBadURL {\n\tconst codePoints = consumeIdentSequence(ctx, reader);\n\n\tif (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) {\n\t\treturn [\n\t\t\tTokenType.Ident,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t},\n\t\t];\n\t}\n\n\tif (checkIfCodePointsMatchURLIdent(ctx, codePoints)) {\n\t\treader.advanceCodePoint();\n\n\t\tlet read = 0;\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]);\n\t\t\tconst secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor+1]);\n\t\t\tif (firstIsWhitespace && secondIsWhitespace) {\n\t\t\t\tread += 2;\n\t\t\t\treader.advanceCodePoint(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor+1] : reader.codePointSource[reader.cursor];\n\t\t\tif (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) {\n\t\t\t\tif (read > 0) {\n\t\t\t\t\treader.advanceCodePoint(read);\n\t\t\t\t}\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.Function,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (read > 0) {\n\t\t\treader.advanceCodePoint(read);\n\t\t}\n\n\t\treturn consumeUrlToken(ctx, reader);\n\t}\n\n\treader.advanceCodePoint();\n\treturn [\n\t\tTokenType.Function,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t},\n\t];\n}\n","import { checkIfFourCodePointsWouldStartCDO } from './checks/four-code-points-would-start-cdo';\nimport { checkIfThreeCodePointsWouldStartAnIdentSequence } from './checks/three-code-points-would-start-ident-sequence';\nimport { checkIfThreeCodePointsWouldStartANumber } from './checks/three-code-points-would-start-number';\nimport { checkIfTwoCodePointsStartAComment } from './checks/two-code-points-start-comment';\nimport { checkIfThreeCodePointsWouldStartCDC } from './checks/three-code-points-would-start-cdc';\nimport { APOSTROPHE, CARRIAGE_RETURN, CHARACTER_TABULATION, COLON, COMMA, COMMERCIAL_AT, DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9, FORM_FEED, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, LINE_FEED, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON, SPACE } from './code-points/code-points';\nimport { isIdentStartCodePoint } from './code-points/ranges';\nimport { consumeComment } from './consume/comment';\nimport { consumeHashToken } from './consume/hash-token';\nimport { consumeIdentSequence } from './consume/ident-sequence';\nimport { consumeNumericToken } from './consume/numeric-token';\nimport { consumeWhiteSpace } from './consume/whitespace-token';\nimport { CSSToken, TokenType } from './interfaces/token';\nimport { Reader } from './reader';\nimport { consumeStringToken } from './consume/string-token';\nimport { consumeIdentLikeToken } from './consume/ident-like-token';\nimport { checkIfTwoCodePointsAreAValidEscape } from './checks/two-code-points-are-valid-escape';\nimport { ParserError } from './interfaces/error';\n\ninterface Stringer {\n\tvalueOf(): string\n}\n\nexport function tokenizer(input: { css: Stringer }, options?: { commentsAreTokens?: boolean, onParseError?: (error: ParserError) => void }) {\n\tconst css = input.css.valueOf();\n\n\tconst reader = new Reader(css);\n\n\tconst ctx = {\n\t\tonParseError: options?.onParseError ?? (() => { /* noop */ }),\n\t};\n\n\tfunction endOfFile() {\n\t\treturn reader.codePointSource[reader.cursor] === undefined;\n\t}\n\n\tfunction nextToken(): CSSToken | undefined {\n\t\treader.resetRepresentation();\n\n\t\tif (checkIfTwoCodePointsStartAComment(ctx, reader)) {\n\t\t\tif (options?.commentsAreTokens) {\n\t\t\t\treturn consumeComment(ctx, reader);\n\t\t\t} else {\n\t\t\t\tconsumeComment(ctx, reader);\n\t\t\t\treader.resetRepresentation();\n\t\t\t}\n\t\t}\n\n\t\tconst peeked = reader.codePointSource[reader.cursor];\n\t\tif (peeked === undefined) {\n\t\t\treturn [TokenType.EOF, '', -1, -1, undefined];\n\t\t}\n\n\t\tif (isIdentStartCodePoint(peeked)) {\n\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t}\n\n\t\t// Simple, one character tokens:\n\t\tswitch (peeked) {\n\t\t\tcase COMMA: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase COLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase SEMICOLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase APOSTROPHE:\n\t\t\tcase QUOTATION_MARK:\n\t\t\t\treturn consumeStringToken(ctx, reader);\n\t\t\tcase NUMBER_SIGN:\n\t\t\t\treturn consumeHashToken(ctx, reader);\n\n\t\t\tcase PLUS_SIGN:\n\t\t\tcase FULL_STOP: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: reader.representationString(),\n\t\t\t\t}];\n\t\t\t}\n\t\t\tcase DIGIT_0:\n\t\t\tcase DIGIT_1:\n\t\t\tcase DIGIT_2:\n\t\t\tcase DIGIT_3:\n\t\t\tcase DIGIT_4:\n\t\t\tcase DIGIT_5:\n\t\t\tcase DIGIT_6:\n\t\t\tcase DIGIT_7:\n\t\t\tcase DIGIT_8:\n\t\t\tcase DIGIT_9:\n\t\t\t\treturn consumeNumericToken(ctx, reader);\n\n\t\t\tcase LINE_FEED:\n\t\t\tcase CARRIAGE_RETURN:\n\t\t\tcase FORM_FEED:\n\t\t\tcase CHARACTER_TABULATION:\n\t\t\tcase SPACE:\n\t\t\t\treturn consumeWhiteSpace(ctx, reader);\n\n\t\t\tcase HYPHEN_MINUS: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(3);\n\n\t\t\t\t\treturn [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '-',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase LESS_THAN_SIGN: {\n\t\t\t\tif (checkIfFourCodePointsWouldStartCDO(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(4);\n\n\t\t\t\t\treturn [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '<',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase COMMERCIAL_AT: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\n\t\t\t\t\treturn [TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\t\t}];\n\t\t\t\t}\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '@',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase REVERSE_SOLIDUS: {\n\t\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Invalid escape sequence after \"\\\\\"',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.1. Consume a token',\n\t\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '\\\\',\n\t\t\t\t}];\n\t\t\t}\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\tvalue: reader.representationString(),\n\t\t}];\n\t}\n\n\treturn {\n\t\tnextToken: nextToken,\n\t\tendOfFile: endOfFile,\n\t};\n}\n","import { CSSToken } from '../interfaces/token';\n\nexport function cloneTokens(tokens: Array): Array {\n\tif ((typeof globalThis !== 'undefined') && 'structuredClone' in globalThis) {\n\t\treturn structuredClone(tokens);\n\t}\n\n\treturn JSON.parse(JSON.stringify(tokens));\n}\n"],"names":["Reader","cursor","source","codePointSource","length","representationStart","representationEnd","constructor","Array","i","charCodeAt","cursorPositionOfLastReadCodePoint","advanceCodePoint","n","readCodePoint","codePoint","undefined","unreadCodePoint","representationString","slice","resetRepresentation","start","end","TokenType","NumberType","HashType","mirrorVariantType","type","OpenParen","CloseParen","OpenCurly","CloseCurly","OpenSquare","CloseSquare","isToken","x","isArray","stringify","tokens","buffer","APOSTROPHE","ASTERISK","BACKSPACE","CARRIAGE_RETURN","CHARACTER_TABULATION","COLON","COMMA","COMMERCIAL_AT","DELETE","EXCLAMATION_MARK","FORM_FEED","FULL_STOP","GREATER_THAN_SIGN","HYPHEN_MINUS","INFORMATION_SEPARATOR_ONE","LATIN_CAPITAL_LETTER_E","LATIN_SMALL_LETTER_E","LEFT_CURLY_BRACKET","LEFT_PARENTHESIS","LEFT_SQUARE_BRACKET","LESS_THAN_SIGN","LINE_FEED","LINE_TABULATION","LOW_LINE","MAXIMUM_ALLOWED_CODEPOINT","NULL","NUMBER_SIGN","PERCENTAGE_SIGN","PLUS_SIGN","QUOTATION_MARK","REPLACEMENT_CHARACTER","REVERSE_SOLIDUS","RIGHT_CURLY_BRACKET","RIGHT_PARENTHESIS","RIGHT_SQUARE_BRACKET","SEMICOLON","SHIFT_OUT","SOLIDUS","SPACE","DIGIT_0","DIGIT_1","DIGIT_2","DIGIT_3","DIGIT_4","DIGIT_5","DIGIT_6","DIGIT_7","DIGIT_8","DIGIT_9","checkIfFourCodePointsWouldStartCDO","ctx","reader","digitsLow","digitsHigh","isDigitCodePoint","search","letterUppercaseLow","letterUppercaseHigh","isUppercaseLetterCodePoint","letterLowercaseLow","letterLowercaseHigh","isLowercaseLetterCodePoint","afUppercaseHigh","afLowercaseHigh","isHexDigitCodePoint","isLetterCodePoint","nonASCIILow","isNonASCIICodePoint","isIdentStartCodePoint","isIdentCodePoint","isNonPrintableCodePoint","isNewLine","isWhitespace","surrogateLow","surrogateHigh","isSurrogate","checkIfTwoCodePointsAreAValidEscape","checkIfThreeCodePointsWouldStartAnIdentSequence","checkIfThreeCodePointsWouldStartANumber","checkIfTwoCodePointsStartAComment","checkIfThreeCodePointsWouldStartCDC","consumeComment","onParseError","message","state","Comment","consumeEscapedCodePoint","hexSequence","push","codePointLiteral","parseInt","String","fromCharCode","consumeIdentSequence","result","consumeHashToken","hashType","Unrestricted","ID","identSequence","Hash","value","Delim","consumeNumber","Integer","repr","newPart","consumeDigits","Number","convertCodePointsToNumber","codePoints","s","iCodePoints","d","fCodePoints","f","t","eCodePoints","e","digitCodePointsToInteger","Math","pow","consumeNumericToken","numberValue","unit","Dimension","Percentage","consumeWhiteSpace","Whitespace","consumeStringToken","first","Error","next","BadString","u","U","r","R","l","L","checkIfCodePointsMatchURLIdent","consumeBadURL","consumeUrlToken","string","URL","BadURL","consumeIdentLikeToken","Ident","read","firstIsWhitespace","secondIsWhitespace","firstNonWhitespace","Function","tokenizer","input","options","css","valueOf","endOfFile","nextToken","commentsAreTokens","peeked","EOF","Comma","Colon","Semicolon","CDC","CDO","AtKeyword","cloneTokens","globalThis","structuredClone","JSON","parse"],"mappings":";;MAEaA,MAAM,CAAA;EAClBC,MAAM,CAAA;AACNC,EAAAA,MAAM,GAAG,EAAE,CAAA;AACXC,EAAAA,eAAe,GAAkB,EAAE,CAAA;AACnCC,EAAAA,MAAM,GAAG,CAAC,CAAA;A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/packages/css-tokenizer/dist/index.mjs index 357713e22..c447ccb46 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1 +1,1174 @@ -class Reader{cursor;stringSource="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.stringSource=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=ce}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===D)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case v:case c:case p:return!0;default:return!1}}function isWhitespace(e){switch(e){case v:case c:case p:case s:case H:return!0;default:return!1}}const se="\ud800".charCodeAt(0),ae="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,r){return r.codePointSource[r.cursor]===y&&r.codePointSource[r.cursor+1]!==v}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,r){return r.codePointSource[r.cursor]===l?r.codePointSource[r.cursor+1]===l||(!!isIdentStartCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===y&&r.codePointSource[r.cursor+2]!==v):!!isIdentStartCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)}function checkIfThreeCodePointsWouldStartANumber(e,r){return r.codePointSource[r.cursor]===R||r.codePointSource[r.cursor]===l?!!isDigitCodePoint(r.codePointSource[r.cursor+1])||r.codePointSource[r.cursor+1]===P&&isDigitCodePoint(r.codePointSource[r.cursor+2]):r.codePointSource[r.cursor]===P?isDigitCodePoint(r.codePointSource[r.cursor+1]):!!isDigitCodePoint(r.codePointSource[r.cursor])}function checkIfTwoCodePointsStartAComment(e,r){return r.codePointSource[r.cursor]===B&&r.codePointSource[r.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,r){return r.codePointSource[r.cursor]===l&&r.codePointSource[r.cursor+1]===l&&r.codePointSource[r.cursor+2]===h}function consumeComment(r,t){for(t.readCodePoint(2);;){const e=t.readCodePoint();if(!1===e){r.onParseError({message:"Unexpected EOF while consuming a comment.",start:t.representationStart,end:t.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==t.codePointSource[t.cursor]&&t.codePointSource[t.cursor]===B)){t.readCodePoint();break}}return[e.Comment,t.representationString(),t.representationStart,t.representationEnd,void 0]}function consumeEscapedCodePoint(e,r){const t=r.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:r.representationStart,end:r.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),N;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==r.codePointSource[r.cursor]&&isHexDigitCodePoint(r.codePointSource[r.cursor])&&e.length<6;)e.push(r.codePointSource[r.cursor]),r.readCodePoint();isWhitespace(r.codePointSource[r.cursor])&&r.readCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?N:se<=(o=n)&&o<=ae||n>U?N:n}var o;return t}function consumeIdentSequence(e,r){const t=[];for(;;){if(void 0===r.codePointSource[r.cursor])return t;if(isIdentCodePoint(r.codePointSource[r.cursor]))t.push(r.codePointSource[r.cursor]),r.readCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,r))return t;r.readCodePoint(),t.push(consumeEscapedCodePoint(e,r))}}}function consumeHashToken(r,o){if(o.readCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let n=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(n=t.ID);const i=consumeIdentSequence(r,o);return[e.Hash,o.representationString(),o.representationStart,o.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,o.representationString(),o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,t){let o=r.Integer;const n=[];{t.codePointSource[t.cursor]!==R&&t.codePointSource[t.cursor]!==l||(n.push(t.codePointSource[t.cursor]),t.readCodePoint());const e=consumeDigits(t);for(let r=0;r0&&t.unreadCodePoint(i),[e.Function,t.representationString(),t.representationStart,t.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&t.unreadCodePoint(i),consumeUrlToken(r,t)}return t.readCodePoint(),[e.Function,t.representationString(),t.representationStart,t.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(r,t){const n=r.css.valueOf(),i=new Reader(n),C={onParseError:(null==t?void 0:t.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.resetRepresentation(),checkIfTwoCodePointsStartAComment(0,i)){if(null!=t&&t.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.resetRepresentation()}const r=i.codePointSource[i.cursor];if(void 0===r)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(r))return consumeIdentLikeToken(C,i);switch(r){case d:return i.readCodePoint(),[e.Comma,i.representationString(),i.representationStart,i.representationEnd,void 0];case a:return i.readCodePoint(),[e.Colon,i.representationString(),i.representationStart,i.representationEnd,void 0];case x:return i.readCodePoint(),[e.Semicolon,i.representationString(),i.representationStart,i.representationEnd,void 0];case E:return i.readCodePoint(),[e.OpenParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case F:return i.readCodePoint(),[e.CloseParen,i.representationString(),i.representationStart,i.representationEnd,void 0];case k:return i.readCodePoint(),[e.OpenSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case q:return i.readCodePoint(),[e.CloseSquare,i.representationString(),i.representationStart,i.representationEnd,void 0];case A:return i.readCodePoint(),[e.OpenCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case W:return i.readCodePoint(),[e.CloseCurly,i.representationString(),i.representationStart,i.representationEnd,void 0];case o:case b:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case R:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(r)}]);case M:case z:case K:case J:case Q:case Z:case _:case j:case G:case X:return consumeNumericToken(C,i);case v:case c:case p:case s:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.readCodePoint(3),[e.CDC,i.representationString(),i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"-"}]);case I:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.readCodePoint(4),[e.CDO,i.representationString(),i.representationStart,i.representationEnd,void 0]):(i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.readCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const r=consumeIdentSequence(C,i);return[e.AtKeyword,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(...r)}]}return[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"@"}];case y:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.readCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:"\\"}])}return i.readCodePoint(),[e.Delim,i.representationString(),i.representationStart,i.representationEnd,{value:String.fromCharCode(r)}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{r as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; +class Reader { + cursor; + source = ''; + codePointSource = []; + length = 0; + representationStart = 0; + representationEnd = -1; + constructor(source) { + this.cursor = 0; + this.source = source; + this.length = source.length; + this.codePointSource = new Array(this.length); + for (let i = 0; i < this.length; i++) { + this.codePointSource[i] = this.source.charCodeAt(i); + } + } + cursorPositionOfLastReadCodePoint() { + return this.cursor - 1; + } + advanceCodePoint(n = 1) { + this.cursor += n; + this.representationEnd = this.cursor - 1; + } + readCodePoint(n = 1) { + const codePoint = this.codePointSource[this.cursor]; + if (codePoint === undefined) { + return false; + } + this.cursor += n; + this.representationEnd = this.cursor - 1; + return codePoint; + } + unreadCodePoint(n = 1) { + if (this.cursor === 0) { + return false; + } + this.cursor -= n; + this.representationEnd = this.cursor - 1; + return true; + } + representationString() { + return this.source.slice(this.representationStart, this.representationEnd + 1); + } + resetRepresentation() { + this.representationStart = this.cursor; + this.representationEnd = -1; + } + slice(start, end) { + return this.source.slice(start, end); + } +} + +var TokenType; +(function (TokenType) { + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */ + TokenType["Comment"] = "comment"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */ + TokenType["AtKeyword"] = "at-keyword-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */ + TokenType["BadString"] = "bad-string-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */ + TokenType["BadURL"] = "bad-url-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */ + TokenType["CDC"] = "CDC-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */ + TokenType["CDO"] = "CDO-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */ + TokenType["Colon"] = "colon-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */ + TokenType["Comma"] = "comma-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */ + TokenType["Delim"] = "delim-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */ + TokenType["Dimension"] = "dimension-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */ + TokenType["EOF"] = "EOF-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */ + TokenType["Function"] = "function-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */ + TokenType["Hash"] = "hash-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */ + TokenType["Ident"] = "ident-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ + TokenType["Number"] = "number-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ + TokenType["Percentage"] = "percentage-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */ + TokenType["Semicolon"] = "semicolon-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */ + TokenType["String"] = "string-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */ + TokenType["URL"] = "url-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */ + TokenType["Whitespace"] = "whitespace-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */ + TokenType["OpenParen"] = "(-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */ + TokenType["CloseParen"] = ")-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */ + TokenType["OpenSquare"] = "[-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */ + TokenType["CloseSquare"] = "]-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */ + TokenType["OpenCurly"] = "{-token"; + /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */ + TokenType["CloseCurly"] = "}-token"; +})(TokenType || (TokenType = {})); +var NumberType; +(function (NumberType) { + NumberType["Integer"] = "integer"; + NumberType["Number"] = "number"; +})(NumberType || (NumberType = {})); +var HashType; +(function (HashType) { + HashType["Unrestricted"] = "unrestricted"; + HashType["ID"] = "id"; +})(HashType || (HashType = {})); +function mirrorVariantType(type) { + switch (type) { + case TokenType.OpenParen: + return TokenType.CloseParen; + case TokenType.CloseParen: + return TokenType.OpenParen; + case TokenType.OpenCurly: + return TokenType.CloseCurly; + case TokenType.CloseCurly: + return TokenType.OpenCurly; + case TokenType.OpenSquare: + return TokenType.CloseSquare; + case TokenType.CloseSquare: + return TokenType.OpenSquare; + default: + return null; + } +} +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function isToken(x) { + if (!Array.isArray(x)) { + return false; + } + if (x.length < 4) { + return false; + } + if (!(x[0] in TokenType)) { + return false; + } + if (typeof x[1] !== 'string') { + return false; + } + if (typeof x[2] !== 'number') { + return false; + } + if (typeof x[3] !== 'number') { + return false; + } + return true; +} + +function stringify(...tokens) { + let buffer = ''; + for (let i = 0; i < tokens.length; i++) { + buffer = buffer + tokens[i][1]; + } + return buffer; +} + +/** ' */ +const APOSTROPHE = '\u{27}'.charCodeAt(0); +/** * */ +const ASTERISK = '\u{2a}'.charCodeAt(0); +/** \b */ +const BACKSPACE = '\u{8}'.charCodeAt(0); +/** \r */ +const CARRIAGE_RETURN = '\u{d}'.charCodeAt(0); +/** \t */ +const CHARACTER_TABULATION = '\u{9}'.charCodeAt(0); +/** : */ +const COLON = '\u{3a}'.charCodeAt(0); +/** , */ +const COMMA = '\u{2c}'.charCodeAt(0); +/** @ */ +const COMMERCIAL_AT = '\u{40}'.charCodeAt(0); +/** \x7F */ +const DELETE = '\u{7f}'.charCodeAt(0); +/** ! */ +const EXCLAMATION_MARK = '\u{21}'.charCodeAt(0); +/** \f */ +const FORM_FEED = '\u{c}'.charCodeAt(0); +/** . */ +const FULL_STOP = '\u{2e}'.charCodeAt(0); +/** > */ +const GREATER_THAN_SIGN = '\u{3e}'.charCodeAt(0); +/** - */ +const HYPHEN_MINUS = '\u{2d}'.charCodeAt(0); +/** \x1F */ +const INFORMATION_SEPARATOR_ONE = '\u{1f}'.charCodeAt(0); +/** E */ +const LATIN_CAPITAL_LETTER_E = '\u{45}'.charCodeAt(0); +/** e */ +const LATIN_SMALL_LETTER_E = '\u{65}'.charCodeAt(0); +/** { */ +const LEFT_CURLY_BRACKET = '\u{7b}'.charCodeAt(0); +/** ( */ +const LEFT_PARENTHESIS = '\u{28}'.charCodeAt(0); +/** [ */ +const LEFT_SQUARE_BRACKET = '\u{5b}'.charCodeAt(0); +/** < */ +const LESS_THAN_SIGN = '\u{3c}'.charCodeAt(0); +/** \n */ +const LINE_FEED = '\u{a}'.charCodeAt(0); +/** \v */ +const LINE_TABULATION = '\u{b}'.charCodeAt(0); +/** _ */ +const LOW_LINE = '\u{5f}'.charCodeAt(0); +/** \x10FFFF */ +const MAXIMUM_ALLOWED_CODEPOINT = '\u{10FFFF}'.charCodeAt(0); +/** \x00 */ +const NULL = '\u{0}'.charCodeAt(0); +/** # */ +const NUMBER_SIGN = '\u{23}'.charCodeAt(0); +/** % */ +const PERCENTAGE_SIGN = '\u{25}'.charCodeAt(0); +/** + */ +const PLUS_SIGN = '\u{2b}'.charCodeAt(0); +/** " */ +const QUOTATION_MARK = '\u{22}'.charCodeAt(0); +/** � */ +const REPLACEMENT_CHARACTER = '\u{0FFFD}'.charCodeAt(0); +/** \ */ +const REVERSE_SOLIDUS = '\u{5c}'.charCodeAt(0); +/** } */ +const RIGHT_CURLY_BRACKET = '\u{7d}'.charCodeAt(0); +/** ) */ +const RIGHT_PARENTHESIS = '\u{29}'.charCodeAt(0); +/** ] */ +const RIGHT_SQUARE_BRACKET = '\u{5d}'.charCodeAt(0); +/** ; */ +const SEMICOLON = '\u{3b}'.charCodeAt(0); +/** \u0E */ +const SHIFT_OUT = '\u{e}'.charCodeAt(0); +/** / */ +const SOLIDUS = '\u{2f}'.charCodeAt(0); +/** \u20 */ +const SPACE = '\u{20}'.charCodeAt(0); +/** 0 */ +const DIGIT_0 = '\u{30}'.charCodeAt(0); +/** 1 */ +const DIGIT_1 = '\u{31}'.charCodeAt(0); +/** 2 */ +const DIGIT_2 = '\u{32}'.charCodeAt(0); +/** 3 */ +const DIGIT_3 = '\u{33}'.charCodeAt(0); +/** 4 */ +const DIGIT_4 = '\u{34}'.charCodeAt(0); +/** 5 */ +const DIGIT_5 = '\u{35}'.charCodeAt(0); +/** 6 */ +const DIGIT_6 = '\u{36}'.charCodeAt(0); +/** 7 */ +const DIGIT_7 = '\u{37}'.charCodeAt(0); +/** 8 */ +const DIGIT_8 = '\u{38}'.charCodeAt(0); +/** 9 */ +const DIGIT_9 = '\u{39}'.charCodeAt(0); + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token +function checkIfFourCodePointsWouldStartCDO(ctx, reader) { + return reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor + 1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 3] === HYPHEN_MINUS; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions +const digitsLow = '\u{30}'.charCodeAt(0); +const digitsHigh = '\u{39}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit +function isDigitCodePoint(search) { + return digitsLow <= search && search <= digitsHigh; +} +const letterUppercaseLow = '\u{41}'.charCodeAt(0); +const letterUppercaseHigh = '\u{5a}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter +function isUppercaseLetterCodePoint(search) { + return letterUppercaseLow <= search && search <= letterUppercaseHigh; +} +const letterLowercaseLow = '\u{61}'.charCodeAt(0); +const letterLowercaseHigh = '\u{7a}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter +function isLowercaseLetterCodePoint(search) { + return letterLowercaseLow <= search && search <= letterLowercaseHigh; +} +const afUppercaseHigh = '\u{46}'.charCodeAt(0); +const afLowercaseHigh = '\u{66}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit +function isHexDigitCodePoint(search) { + if (digitsLow <= search && search <= digitsHigh) { + return true; + } + if (letterLowercaseLow <= search && search <= afLowercaseHigh) { + return true; + } + if (letterUppercaseLow <= search && search <= afUppercaseHigh) { + return true; + } + return false; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter +function isLetterCodePoint(search) { + return isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search); +} +const nonASCIILow = '\u{80}'.charCodeAt(0); +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point +function isNonASCIICodePoint(search) { + return search >= nonASCIILow; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point +function isIdentStartCodePoint(search) { + if (isLetterCodePoint(search)) { + return true; + } + if (isNonASCIICodePoint(search)) { + return true; + } + return search === LOW_LINE; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point +function isIdentCodePoint(search) { + if (isIdentStartCodePoint(search)) { + return true; + } + if (isDigitCodePoint(search)) { + return true; + } + return search === HYPHEN_MINUS; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point +function isNonPrintableCodePoint(search) { + if (search === LINE_TABULATION) { + return true; + } + if (search === DELETE) { + return true; + } + if (NULL <= search && search <= BACKSPACE) { + return true; + } + return SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE; +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace +function isNewLine(search) { + switch (search) { + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing + // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. + // Applying the preprocessing rules would make it impossible to match the input. + // A side effect of this is that our definition of whitespace is broader. + return true; + default: + return false; + } +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace +function isWhitespace(search) { + // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing + // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. + // Applying the preprocessing rules would make it impossible to match the input. + // A side effect of this is that our definition of whitespace is broader. + switch (search) { + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + case CHARACTER_TABULATION: + case SPACE: + return true; + default: + return false; + } +} +const surrogateLow = '\u{d800}'.charCodeAt(0); +const surrogateHigh = '\u{dfff}'.charCodeAt(0); +// https://infra.spec.whatwg.org/#surrogate +function isSurrogate(search) { + return surrogateLow <= search && search <= surrogateHigh; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape +function checkIfTwoCodePointsAreAValidEscape(ctx, reader) { + // If the first code point is not U+005C REVERSE SOLIDUS (\), return false. + if (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { + // "\" + return false; + } + // Otherwise, if the second code point is a newline, return false. + if (reader.codePointSource[reader.cursor + 1] === LINE_FEED) { + return false; + } + // Otherwise, return true. + return true; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier +function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader) { + // // U+002D HYPHEN-MINUS + if (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { + // If the second code point is a U+002D HYPHEN-MINUS return true + if (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS) { + return true; + } + // If the second code point is an ident-start code point return true + if (isIdentStartCodePoint(reader.codePointSource[reader.cursor + 1])) { + return true; + } + // If the second and third code points are a valid escape return true + if (reader.codePointSource[reader.cursor + 1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) { + return true; + } + return false; + } + // ident-start code point + // Return true. + if (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) { + return true; + } + // U+005C REVERSE SOLIDUS (\) + return checkIfTwoCodePointsAreAValidEscape(ctx, reader); +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number +function checkIfThreeCodePointsWouldStartANumber(ctx, reader) { + if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { + // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) + // If the second code point is a digit, return true. + if (isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { + return true; + } + // Otherwise, if the second code point is a U+002E FULL STOP (.) + if (reader.codePointSource[reader.cursor + 1] === FULL_STOP) { + // and the third code point is a digit, return true. + return isDigitCodePoint(reader.codePointSource[reader.cursor + 2]); + } + // Otherwise, return false. + return false; + } else if (reader.codePointSource[reader.cursor] === FULL_STOP) { + // U+002E FULL STOP (.) + // If the second code point is a digit, return true. + // Otherwise, return false. + return isDigitCodePoint(reader.codePointSource[reader.cursor + 1]); + } else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { + // digit + // Return true. + return true; + } + // anything else + // Return false. + return false; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments +function checkIfTwoCodePointsStartAComment(ctx, reader) { + if (reader.codePointSource[reader.cursor] !== SOLIDUS) { + return false; + } + if (reader.codePointSource[reader.cursor + 1] !== ASTERISK) { + return false; + } + // Otherwise, return true. + return true; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token +function checkIfThreeCodePointsWouldStartCDC(ctx, reader) { + return reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment +function consumeComment(ctx, reader) { + reader.advanceCodePoint(2); + // eslint-disable-next-line no-constant-condition + while (true) { + const codePoint = reader.readCodePoint(); + if (codePoint === false) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a comment.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.2. Consume comments', 'Unexpected EOF'] + }); + break; + } + if (codePoint !== ASTERISK) { + continue; + } + if (reader.codePointSource[reader.cursor] === undefined) { + continue; + } + if (reader.codePointSource[reader.cursor] === SOLIDUS) { + reader.advanceCodePoint(); + break; + } + } + return [TokenType.Comment, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point +function consumeEscapedCodePoint(ctx, reader) { + const codePoint = reader.readCodePoint(); + if (codePoint === false) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming an escaped code point.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.7. Consume an escaped code point', 'Unexpected EOF'] + }); + return REPLACEMENT_CHARACTER; + } + if (isHexDigitCodePoint(codePoint)) { + const hexSequence = [codePoint]; + while (reader.codePointSource[reader.cursor] !== undefined && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) { + hexSequence.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } + if (isWhitespace(reader.codePointSource[reader.cursor])) { + reader.advanceCodePoint(); + } + const codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16); + if (codePointLiteral === 0) { + return REPLACEMENT_CHARACTER; + } + if (isSurrogate(codePointLiteral)) { + return REPLACEMENT_CHARACTER; + } + if (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) { + return REPLACEMENT_CHARACTER; + } + return codePointLiteral; + } + return codePoint; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name +function consumeIdentSequence(ctx, reader) { + const result = []; + // eslint-disable-next-line no-constant-condition + while (true) { + if (isIdentCodePoint(reader.codePointSource[reader.cursor])) { + result.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + continue; + } + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + reader.advanceCodePoint(); + result.push(consumeEscapedCodePoint(ctx, reader)); + continue; + } + return result; + } +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token +function consumeHashToken(ctx, reader) { + reader.advanceCodePoint(); + if (reader.codePointSource[reader.cursor] !== undefined && isIdentCodePoint(reader.codePointSource[reader.cursor]) || checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + let hashType = HashType.Unrestricted; + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + hashType = HashType.ID; + } + const identSequence = consumeIdentSequence(ctx, reader); + return [TokenType.Hash, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...identSequence), + type: hashType + }]; + } + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '#' + }]; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number +function consumeNumber(ctx, reader) { + // 1. Initially set type to "integer". + // Let repr be the empty string. + let type = NumberType.Integer; + const repr = []; + { + // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr. + if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { + repr.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } + // 3. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + { + // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then: + if (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { + // 4.2. Append them to repr. + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor + 1]); + // 4.1. Consume them. + reader.advanceCodePoint(2); + // 4.3. Set type to "number". + type = NumberType.Number; + // 4.4. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + } + { + // 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), + // optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+), + // followed by a digit, then: + if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { + // 5.2. Append them to repr. + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor + 1]); + // 5.1. Consume them. + reader.advanceCodePoint(2); + // 5.3. Set type to "number". + type = NumberType.Number; + // 5.4. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor + 1] === PLUS_SIGN) && isDigitCodePoint(reader.codePointSource[reader.cursor + 2])) { + // 5.2. Append them to repr. + repr.push(reader.codePointSource[reader.cursor]); + repr.push(reader.codePointSource[reader.cursor + 1]); + repr.push(reader.codePointSource[reader.cursor + 2]); + // 5.1. Consume them. + reader.advanceCodePoint(3); + // 5.3. Set type to "number". + type = NumberType.Number; + // 5.4. While the next input code point is a digit, consume it and append it to repr. + const newPart = consumeDigits(reader); + for (let i = 0; i < newPart.length; i++) { + repr.push(newPart[i]); + } + } + } + // 6. Convert repr to a number, and set the value to the returned value. + const value = convertCodePointsToNumber(repr); + // 7. Return value and type. + return [value, type]; +} +function consumeDigits(reader) { + const value = []; + // eslint-disable-next-line no-constant-condition + while (true) { + if (reader.codePointSource[reader.cursor] === undefined) { + return value; + } + if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { + value.push(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } else { + return value; + } + } +} +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number +function convertCodePointsToNumber(codePoints) { + let s = 1; + const iCodePoints = []; + let i = 0; + let d = 0; + const fCodePoints = []; + let f = 0; + let t = 1; + const eCodePoints = []; + let e = 0; + let cursor = 0; + // 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. + // Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-); + // otherwise, let s be the number 1. + if (codePoints[cursor] === HYPHEN_MINUS) { + cursor++; + s = -1; + } else if (codePoints[cursor] === PLUS_SIGN) { + cursor++; + } + // 2. An integer part: zero or more digits. + // If there is at least one digit, + // let i be the number formed by interpreting the digits as a base-10 integer; + // otherwise, let i be the number 0. + while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { + iCodePoints.push(codePoints[cursor]); + cursor++; + } + i = digitCodePointsToInteger(iCodePoints); + // 3. A decimal point: a single U+002E FULL STOP (.), or the empty string. + if (codePoints[cursor] === FULL_STOP) { + cursor++; + } + // 4. A fractional part: zero or more digits. + // If there is at least one digit, + // let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits; + // otherwise, let f and d be the number 0. + while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { + fCodePoints.push(codePoints[cursor]); + cursor++; + } + d = fCodePoints.length; + f = digitCodePointsToInteger(fCodePoints) / Math.pow(10, d); + // 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string. + if (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) { + cursor++; + } + // 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. + // Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-); + // otherwise, let t be the number 1. + if (codePoints[cursor] === HYPHEN_MINUS) { + cursor++; + t = -1; + } else if (codePoints[cursor] === PLUS_SIGN) { + cursor++; + } + // 7. An exponent: zero or more digits. + // If there is at least one digit, + // let e be the number formed by interpreting the digits as a base-10 integer; + // otherwise, let e be the number 0. + while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { + eCodePoints.push(codePoints[cursor]); + cursor++; + } + e = digitCodePointsToInteger(eCodePoints); + // Return the number s·(i + f·10-d)·10te. + return s * (i + f) * Math.pow(10, t * e); +} +function digitCodePointsToInteger(codePoints) { + if (codePoints.length === 0) { + return 0; + } + return Number.parseInt(String.fromCharCode(...codePoints), 10); +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token +function consumeNumericToken(ctx, reader) { + const numberValue = consumeNumber(ctx, reader); + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + const unit = consumeIdentSequence(ctx, reader); + return [TokenType.Dimension, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: numberValue[0], + type: numberValue[1], + unit: String.fromCharCode(...unit) + }]; + } + { + if (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) { + reader.advanceCodePoint(); + return [TokenType.Percentage, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: numberValue[0] + }]; + } + } + return [TokenType.Number, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: numberValue[0], + type: numberValue[1] + }]; +} + +function consumeWhiteSpace(ctx, reader) { + // eslint-disable-next-line no-constant-condition + while (true) { + if (!isWhitespace(reader.codePointSource[reader.cursor])) { + break; + } + reader.advanceCodePoint(); + } + return [TokenType.Whitespace, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token +function consumeStringToken(ctx, reader) { + let result = ''; + const first = reader.readCodePoint(); + if (first === false) { + throw new Error('Unexpected EOF'); + } + // eslint-disable-next-line no-constant-condition + while (true) { + const next = reader.readCodePoint(); + if (next === false) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a string token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.5. Consume a string token', 'Unexpected EOF'] + }); + return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: result + }]; + } + if (isNewLine(next)) { + { + ctx.onParseError({ + message: 'Unexpected newline while consuming a string token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.5. Consume a string token', 'Unexpected newline'] + }); + } + reader.unreadCodePoint(); + return [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (next === first) { + return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: result + }]; + } + if (next === REVERSE_SOLIDUS) { + if (reader.codePointSource[reader.cursor] === undefined) { + continue; + } + if (isNewLine(reader.codePointSource[reader.cursor])) { + reader.advanceCodePoint(); + continue; + } + result += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); + continue; + } + result += String.fromCharCode(next); + } +} + +const u = 'u'.charCodeAt(0); +const U = 'U'.charCodeAt(0); +const r = 'r'.charCodeAt(0); +const R = 'R'.charCodeAt(0); +const l = 'l'.charCodeAt(0); +const L = 'L'.charCodeAt(0); +function checkIfCodePointsMatchURLIdent(ctx, codePoints) { + if (codePoints.length !== 3) { + return false; + } + if (codePoints[0] !== u && codePoints[0] !== U) { + return false; + } + if (codePoints[1] !== r && codePoints[1] !== R) { + return false; + } + if (codePoints[2] !== l && codePoints[2] !== L) { + return false; + } + return true; +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url +function consumeBadURL(ctx, reader) { + // eslint-disable-next-line no-constant-condition + while (true) { + if (reader.codePointSource[reader.cursor] === undefined) { + return; + } + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { + reader.advanceCodePoint(); + return; + } + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + reader.advanceCodePoint(); + consumeEscapedCodePoint(ctx, reader); + continue; + } + reader.advanceCodePoint(); + continue; + } +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token +function consumeUrlToken(ctx, reader) { + consumeWhiteSpace(ctx, reader); + let string = ''; + // eslint-disable-next-line no-constant-condition + while (true) { + if (reader.codePointSource[reader.cursor] === undefined) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'Unexpected EOF'] + }); + return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { + reader.advanceCodePoint(); + return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + if (isWhitespace(reader.codePointSource[reader.cursor])) { + consumeWhiteSpace(ctx, reader); + if (reader.codePointSource[reader.cursor] === undefined) { + ctx.onParseError({ + message: 'Unexpected EOF while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'Consume as much whitespace as possible', 'Unexpected EOF'] + }); + return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { + reader.advanceCodePoint(); + return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: string + }]; + } + consumeBadURL(ctx, reader); + return [TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) { + consumeBadURL(ctx, reader); + ctx.onParseError({ + message: 'Unexpected character while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'Unexpected U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE (\'), U+0028 LEFT PARENTHESIS (() or non-printable code point'] + }); + return [TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) { + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + string += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); + continue; + } + consumeBadURL(ctx, reader); + ctx.onParseError({ + message: 'Invalid escape sequence while consuming a url token.', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.6. Consume a url token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] + }); + return [TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + string += String.fromCharCode(reader.codePointSource[reader.cursor]); + reader.advanceCodePoint(); + } +} + +// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token +function consumeIdentLikeToken(ctx, reader) { + const codePoints = consumeIdentSequence(ctx, reader); + if (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) { + return [TokenType.Ident, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...codePoints) + }]; + } + if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { + reader.advanceCodePoint(); + let read = 0; + // eslint-disable-next-line no-constant-condition + while (true) { + const firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]); + const secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor + 1]); + if (firstIsWhitespace && secondIsWhitespace) { + read += 2; + reader.advanceCodePoint(2); + continue; + } + const firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor + 1] : reader.codePointSource[reader.cursor]; + if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { + if (read > 0) { + reader.advanceCodePoint(read); + } + return [TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...codePoints) + }]; + } + break; + } + if (read > 0) { + reader.advanceCodePoint(read); + } + return consumeUrlToken(ctx, reader); + } + reader.advanceCodePoint(); + return [TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...codePoints) + }]; +} + +function tokenizer(input, options) { + const css = input.css.valueOf(); + const reader = new Reader(css); + const ctx = { + onParseError: (options == null ? void 0 : options.onParseError) ?? (() => {}) + }; + function endOfFile() { + return reader.codePointSource[reader.cursor] === undefined; + } + function nextToken() { + reader.resetRepresentation(); + if (checkIfTwoCodePointsStartAComment(ctx, reader)) { + if (options != null && options.commentsAreTokens) { + return consumeComment(ctx, reader); + } else { + consumeComment(ctx, reader); + reader.resetRepresentation(); + } + } + const peeked = reader.codePointSource[reader.cursor]; + if (peeked === undefined) { + return [TokenType.EOF, '', -1, -1, undefined]; + } + if (isIdentStartCodePoint(peeked)) { + return consumeIdentLikeToken(ctx, reader); + } + // Simple, one character tokens: + switch (peeked) { + case COMMA: + { + reader.advanceCodePoint(); + return [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case COLON: + { + reader.advanceCodePoint(); + return [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case SEMICOLON: + { + reader.advanceCodePoint(); + return [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case LEFT_PARENTHESIS: + { + reader.advanceCodePoint(); + return [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case RIGHT_PARENTHESIS: + { + reader.advanceCodePoint(); + return [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case LEFT_SQUARE_BRACKET: + { + reader.advanceCodePoint(); + return [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case RIGHT_SQUARE_BRACKET: + { + reader.advanceCodePoint(); + return [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case LEFT_CURLY_BRACKET: + { + reader.advanceCodePoint(); + return [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case RIGHT_CURLY_BRACKET: + { + reader.advanceCodePoint(); + return [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + case APOSTROPHE: + case QUOTATION_MARK: + return consumeStringToken(ctx, reader); + case NUMBER_SIGN: + return consumeHashToken(ctx, reader); + case PLUS_SIGN: + case FULL_STOP: + { + if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { + return consumeNumericToken(ctx, reader); + } + reader.advanceCodePoint(); + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: reader.representationString() + }]; + } + case DIGIT_0: + case DIGIT_1: + case DIGIT_2: + case DIGIT_3: + case DIGIT_4: + case DIGIT_5: + case DIGIT_6: + case DIGIT_7: + case DIGIT_8: + case DIGIT_9: + return consumeNumericToken(ctx, reader); + case LINE_FEED: + case CARRIAGE_RETURN: + case FORM_FEED: + case CHARACTER_TABULATION: + case SPACE: + return consumeWhiteSpace(ctx, reader); + case HYPHEN_MINUS: + { + if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { + return consumeNumericToken(ctx, reader); + } + if (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) { + reader.advanceCodePoint(3); + return [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + return consumeIdentLikeToken(ctx, reader); + } + reader.advanceCodePoint(); + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '-' + }]; + } + case LESS_THAN_SIGN: + { + if (checkIfFourCodePointsWouldStartCDO(ctx, reader)) { + reader.advanceCodePoint(4); + return [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + } + reader.advanceCodePoint(); + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '<' + }]; + } + case COMMERCIAL_AT: + { + reader.advanceCodePoint(); + if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { + const identSequence = consumeIdentSequence(ctx, reader); + return [TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: String.fromCharCode(...identSequence) + }]; + } + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '@' + }]; + } + case REVERSE_SOLIDUS: + { + if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { + return consumeIdentLikeToken(ctx, reader); + } + reader.advanceCodePoint(); + ctx.onParseError({ + message: 'Invalid escape sequence after "\\"', + start: reader.representationStart, + end: reader.representationEnd, + state: ['4.3.1. Consume a token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] + }); + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: '\\' + }]; + } + } + reader.advanceCodePoint(); + return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + value: reader.representationString() + }]; + } + return { + nextToken: nextToken, + endOfFile: endOfFile + }; +} + +function cloneTokens(tokens) { + if (typeof globalThis !== 'undefined' && 'structuredClone' in globalThis) { + return structuredClone(tokens); + } + return JSON.parse(JSON.stringify(tokens)); +} + +export { NumberType, Reader, TokenType, cloneTokens, isToken, mirrorVariantType, stringify, tokenizer }; +//# sourceMappingURL=index.mjs.map diff --git a/packages/css-tokenizer/dist/index.mjs.map b/packages/css-tokenizer/dist/index.mjs.map new file mode 100644 index 000000000..06029fdd8 --- /dev/null +++ b/packages/css-tokenizer/dist/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../src/reader.ts","../src/interfaces/token.ts","../src/stringify.ts","../src/code-points/code-points.ts","../src/checks/four-code-points-would-start-cdo.ts","../src/code-points/ranges.ts","../src/checks/two-code-points-are-valid-escape.ts","../src/checks/three-code-points-would-start-ident-sequence.ts","../src/checks/three-code-points-would-start-number.ts","../src/checks/two-code-points-start-comment.ts","../src/checks/three-code-points-would-start-cdc.ts","../src/consume/comment.ts","../src/consume/escaped-code-point.ts","../src/consume/ident-sequence.ts","../src/consume/hash-token.ts","../src/consume/number.ts","../src/consume/numeric-token.ts","../src/consume/whitespace-token.ts","../src/consume/string-token.ts","../src/checks/matches-url-ident.ts","../src/consume/bad-url.ts","../src/consume/url-token.ts","../src/consume/ident-like-token.ts","../src/tokenizer.ts","../src/util/clone-tokens.ts"],"sourcesContent":["import { CodePointReader } from './interfaces/code-point-reader';\n\nexport class Reader implements CodePointReader {\n\tcursor: number;\n\tsource = '';\n\tcodePointSource: Array = [];\n\tlength = 0;\n\n\trepresentationStart = 0;\n\trepresentationEnd = -1;\n\n\tconstructor(source: string) {\n\t\tthis.cursor = 0;\n\t\tthis.source = source;\n\t\tthis.length = source.length;\n\n\t\tthis.codePointSource = new Array(this.length);\n\t\tfor (let i = 0; i < this.length; i++) {\n\t\t\tthis.codePointSource[i] = this.source.charCodeAt(i);\n\t\t}\n\t}\n\n\tcursorPositionOfLastReadCodePoint(): number {\n\t\treturn this.cursor - 1;\n\t}\n\n\tadvanceCodePoint(n = 1) {\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\t}\n\n\treadCodePoint(n = 1): number | false {\n\t\tconst codePoint = this.codePointSource[this.cursor];\n\t\tif (codePoint === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn codePoint;\n\t}\n\n\tunreadCodePoint(n = 1): boolean {\n\t\tif (this.cursor === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor -= n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn true;\n\t}\n\n\trepresentationString(): string {\n\t\treturn this.source.slice(this.representationStart, this.representationEnd + 1);\n\t}\n\n\tresetRepresentation() {\n\t\tthis.representationStart = this.cursor;\n\t\tthis.representationEnd = -1;\n\t}\n\n\tslice(start: number, end: number): string {\n\t\treturn this.source.slice(start, end);\n\t}\n}\n","export enum TokenType {\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */\n\tComment = 'comment',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */\n\tAtKeyword = 'at-keyword-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */\n\tBadString = 'bad-string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */\n\tBadURL = 'bad-url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */\n\tCDC = 'CDC-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */\n\tCDO = 'CDO-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */\n\tColon = 'colon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */\n\tComma = 'comma-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */\n\tDelim = 'delim-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */\n\tDimension = 'dimension-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */\n\tEOF = 'EOF-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */\n\tFunction = 'function-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */\n\tHash = 'hash-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */\n\tIdent = 'ident-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tNumber = 'number-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tPercentage = 'percentage-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */\n\tSemicolon = 'semicolon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */\n\tString = 'string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */\n\tURL = 'url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */\n\tWhitespace = 'whitespace-token',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */\n\tOpenParen = '(-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */\n\tCloseParen = ')-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */\n\tOpenSquare = '[-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */\n\tCloseSquare = ']-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */\n\tOpenCurly = '{-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */\n\tCloseCurly = '}-token',\n}\n\nexport enum NumberType {\n\tInteger = 'integer',\n\tNumber = 'number',\n}\n\nexport enum HashType {\n\tUnrestricted = 'unrestricted',\n\tID = 'id',\n}\n\nexport type TokenAtKeyword = Token;\nexport type TokenBadString = Token;\nexport type TokenBadURL = Token;\nexport type TokenCDC = Token;\nexport type TokenCDO = Token;\nexport type TokenColon = Token;\nexport type TokenComma = Token;\nexport type TokenComment = Token;\nexport type TokenDelim = Token;\nexport type TokenDimension = Token;\nexport type TokenEOF = Token;\nexport type TokenFunction = Token;\nexport type TokenHash = Token;\nexport type TokenIdent = Token;\nexport type TokenNumber = Token;\nexport type TokenPercentage = Token;\nexport type TokenSemicolon = Token;\nexport type TokenString = Token;\nexport type TokenURL = Token;\nexport type TokenWhitespace = Token;\n\nexport type TokenOpenParen = Token;\nexport type TokenCloseParen = Token;\nexport type TokenOpenSquare = Token;\nexport type TokenCloseSquare = Token;\nexport type TokenOpenCurly = Token;\nexport type TokenCloseCurly = Token;\n\nexport type CSSToken = TokenAtKeyword |\n\tTokenBadString |\n\tTokenBadURL |\n\tTokenCDC |\n\tTokenCDO |\n\tTokenColon |\n\tTokenComma |\n\tTokenComment |\n\tTokenDelim |\n\tTokenDimension |\n\tTokenEOF |\n\tTokenFunction |\n\tTokenHash |\n\tTokenIdent |\n\tTokenNumber |\n\tTokenPercentage |\n\tTokenSemicolon |\n\tTokenString |\n\tTokenURL |\n\tTokenWhitespace |\n\tTokenOpenParen |\n\tTokenCloseParen |\n\tTokenOpenSquare |\n\tTokenCloseSquare |\n\tTokenOpenCurly |\n\tTokenCloseCurly;\n\nexport type Token = [\n\t/** The type of token */\n\tT,\n\t/** The token representation */\n\tstring,\n\t/** Start position of representation */\n\tnumber,\n\t/** End position of representation */\n\tnumber,\n\t/** Extra data */\n\tU,\n]\n\nexport function mirrorVariantType(type: TokenType): TokenType|null {\n\tswitch (type) {\n\t\tcase TokenType.OpenParen:\n\t\t\treturn TokenType.CloseParen;\n\t\tcase TokenType.CloseParen:\n\t\t\treturn TokenType.OpenParen;\n\n\t\tcase TokenType.OpenCurly:\n\t\t\treturn TokenType.CloseCurly;\n\t\tcase TokenType.CloseCurly:\n\t\t\treturn TokenType.OpenCurly;\n\n\t\tcase TokenType.OpenSquare:\n\t\t\treturn TokenType.CloseSquare;\n\t\tcase TokenType.CloseSquare:\n\t\t\treturn TokenType.OpenSquare;\n\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToken(x: any): x is CSSToken {\n\tif (!Array.isArray(x)) {\n\t\treturn false;\n\t}\n\n\tif (x.length < 4) {\n\t\treturn false;\n\t}\n\n\tif (!(x[0] in TokenType)) {\n\t\treturn false;\n\t}\n\n\tif (typeof x[1] !== 'string') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[2] !== 'number') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[3] !== 'number') {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import type { CSSToken } from './interfaces/token';\n\nexport function stringify(...tokens: Array): string {\n\tlet buffer = '';\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tbuffer = buffer + tokens[i][1];\n\t}\n\n\treturn buffer;\n}\n","/** ' */\nexport const APOSTROPHE = '\\u{27}'.charCodeAt(0);\n/** * */\nexport const ASTERISK = '\\u{2a}'.charCodeAt(0);\n/** \\b */\nexport const BACKSPACE = '\\u{8}'.charCodeAt(0);\n/** \\r */\nexport const CARRIAGE_RETURN = '\\u{d}'.charCodeAt(0);\n/** \\t */\nexport const CHARACTER_TABULATION = '\\u{9}'.charCodeAt(0);\n/** : */\nexport const COLON = '\\u{3a}'.charCodeAt(0);\n/** , */\nexport const COMMA = '\\u{2c}'.charCodeAt(0);\n/** @ */\nexport const COMMERCIAL_AT = '\\u{40}'.charCodeAt(0);\n/** \\x7F */\nexport const DELETE = '\\u{7f}'.charCodeAt(0);\n/** ! */\nexport const EXCLAMATION_MARK = '\\u{21}'.charCodeAt(0);\n/** \\f */\nexport const FORM_FEED = '\\u{c}'.charCodeAt(0);\n/** . */\nexport const FULL_STOP = '\\u{2e}'.charCodeAt(0);\n/** > */\nexport const GREATER_THAN_SIGN = '\\u{3e}'.charCodeAt(0);\n/** - */\nexport const HYPHEN_MINUS = '\\u{2d}'.charCodeAt(0);\n/** \\x1F */\nexport const INFORMATION_SEPARATOR_ONE = '\\u{1f}'.charCodeAt(0);\n/** E */\nexport const LATIN_CAPITAL_LETTER_E = '\\u{45}'.charCodeAt(0);\n/** e */\nexport const LATIN_SMALL_LETTER_E = '\\u{65}'.charCodeAt(0);\n/** { */\nexport const LEFT_CURLY_BRACKET = '\\u{7b}'.charCodeAt(0);\n/** ( */\nexport const LEFT_PARENTHESIS = '\\u{28}'.charCodeAt(0);\n/** [ */\nexport const LEFT_SQUARE_BRACKET = '\\u{5b}'.charCodeAt(0);\n/** < */\nexport const LESS_THAN_SIGN = '\\u{3c}'.charCodeAt(0);\n/** \\n */\nexport const LINE_FEED = '\\u{a}'.charCodeAt(0);\n/** \\v */\nexport const LINE_TABULATION = '\\u{b}'.charCodeAt(0);\n/** _ */\nexport const LOW_LINE = '\\u{5f}'.charCodeAt(0);\n/** \\x10FFFF */\nexport const MAXIMUM_ALLOWED_CODEPOINT = '\\u{10FFFF}'.charCodeAt(0);\n/** \\x00 */\nexport const NULL = '\\u{0}'.charCodeAt(0);\n/** # */\nexport const NUMBER_SIGN = '\\u{23}'.charCodeAt(0);\n/** % */\nexport const PERCENTAGE_SIGN = '\\u{25}'.charCodeAt(0);\n/** + */\nexport const PLUS_SIGN = '\\u{2b}'.charCodeAt(0);\n/** \" */\nexport const QUOTATION_MARK = '\\u{22}'.charCodeAt(0);\n/** � */\nexport const REPLACEMENT_CHARACTER = '\\u{0FFFD}'.charCodeAt(0);\n/** \\ */\nexport const REVERSE_SOLIDUS = '\\u{5c}'.charCodeAt(0);\n/** } */\nexport const RIGHT_CURLY_BRACKET = '\\u{7d}'.charCodeAt(0);\n/** ) */\nexport const RIGHT_PARENTHESIS = '\\u{29}'.charCodeAt(0);\n/** ] */\nexport const RIGHT_SQUARE_BRACKET = '\\u{5d}'.charCodeAt(0);\n/** ; */\nexport const SEMICOLON = '\\u{3b}'.charCodeAt(0);\n/** \\u0E */\nexport const SHIFT_OUT = '\\u{e}'.charCodeAt(0);\n/** / */\nexport const SOLIDUS = '\\u{2f}'.charCodeAt(0);\n/** \\u20 */\nexport const SPACE = '\\u{20}'.charCodeAt(0);\n/** 0 */\nexport const DIGIT_0 = '\\u{30}'.charCodeAt(0);\n/** 1 */\nexport const DIGIT_1 = '\\u{31}'.charCodeAt(0);\n/** 2 */\nexport const DIGIT_2 = '\\u{32}'.charCodeAt(0);\n/** 3 */\nexport const DIGIT_3 = '\\u{33}'.charCodeAt(0);\n/** 4 */\nexport const DIGIT_4 = '\\u{34}'.charCodeAt(0);\n/** 5 */\nexport const DIGIT_5 = '\\u{35}'.charCodeAt(0);\n/** 6 */\nexport const DIGIT_6 = '\\u{36}'.charCodeAt(0);\n/** 7 */\nexport const DIGIT_7 = '\\u{37}'.charCodeAt(0);\n/** 8 */\nexport const DIGIT_8 = '\\u{38}'.charCodeAt(0);\n/** 9 */\nexport const DIGIT_9 = '\\u{39}'.charCodeAt(0);\n","import { EXCLAMATION_MARK, HYPHEN_MINUS, LESS_THAN_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfFourCodePointsWouldStartCDO(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor+1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+3] === HYPHEN_MINUS;\n}\n","import { BACKSPACE, DELETE, INFORMATION_SEPARATOR_ONE, LINE_TABULATION, LOW_LINE, HYPHEN_MINUS, NULL, SHIFT_OUT, LINE_FEED, CARRIAGE_RETURN, FORM_FEED, CHARACTER_TABULATION, SPACE } from './code-points';\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions\n\nconst digitsLow = '\\u{30}'.charCodeAt(0);\nconst digitsHigh = '\\u{39}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit\nexport function isDigitCodePoint(search: number): boolean {\n\treturn digitsLow <= search && search <= digitsHigh;\n}\n\nconst letterUppercaseLow = '\\u{41}'.charCodeAt(0);\nconst letterUppercaseHigh = '\\u{5a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter\nexport function isUppercaseLetterCodePoint(search: number): boolean {\n\treturn letterUppercaseLow <= search && search <= letterUppercaseHigh;\n}\n\nconst letterLowercaseLow = '\\u{61}'.charCodeAt(0);\nconst letterLowercaseHigh = '\\u{7a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter\nexport function isLowercaseLetterCodePoint(search: number): boolean {\n\treturn letterLowercaseLow <= search && search <= letterLowercaseHigh;\n}\n\nconst afUppercaseHigh = '\\u{46}'.charCodeAt(0);\nconst afLowercaseHigh = '\\u{66}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit\nexport function isHexDigitCodePoint(search: number): boolean {\n\tif (digitsLow <= search && search <= digitsHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterLowercaseLow <= search && search <= afLowercaseHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterUppercaseLow <= search && search <= afUppercaseHigh) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter\nexport function isLetterCodePoint(search: number): boolean {\n\treturn isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search);\n}\n\nconst nonASCIILow = '\\u{80}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point\nexport function isNonASCIICodePoint(search: number): boolean {\n\treturn search >= nonASCIILow;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point\nexport function isIdentStartCodePoint(search: number): boolean {\n\tif (isLetterCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isNonASCIICodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === LOW_LINE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point\nexport function isIdentCodePoint(search: number): boolean {\n\tif (isIdentStartCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isDigitCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === HYPHEN_MINUS;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point\nexport function isNonPrintableCodePoint(search: number): boolean {\n\tif (search === LINE_TABULATION) {\n\t\treturn true;\n\t}\n\n\tif (search === DELETE) {\n\t\treturn true;\n\t}\n\n\tif (NULL <= search && search <= BACKSPACE) {\n\t\treturn true;\n\t}\n\n\treturn SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isNewLine(search: number): boolean {\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\t\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t\t\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t\t\t// Applying the preprocessing rules would make it impossible to match the input.\n\t\t\t// A side effect of this is that our definition of whitespace is broader.\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isWhitespace(search: number): boolean {\n\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t// Applying the preprocessing rules would make it impossible to match the input.\n\t// A side effect of this is that our definition of whitespace is broader.\n\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\tcase CHARACTER_TABULATION:\n\t\tcase SPACE:\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nconst surrogateLow = '\\u{d800}'.charCodeAt(0);\nconst surrogateHigh = '\\u{dfff}'.charCodeAt(0);\n\n// https://infra.spec.whatwg.org/#surrogate\nexport function isSurrogate(search: number): boolean {\n\treturn surrogateLow <= search && search <= surrogateHigh;\n}\n","import { LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape\nexport function checkIfTwoCodePointsAreAValidEscape(ctx: Context, reader: CodePointReader): boolean {\n\t// If the first code point is not U+005C REVERSE SOLIDUS (\\), return false.\n\tif (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { // \"\\\"\n\t\treturn false;\n\t}\n\n\t// Otherwise, if the second code point is a newline, return false.\n\tif (reader.codePointSource[reader.cursor+1] === LINE_FEED) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { HYPHEN_MINUS, LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isIdentStartCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { checkIfTwoCodePointsAreAValidEscape } from './two-code-points-are-valid-escape';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier\nexport function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, reader: CodePointReader): boolean {\n\t// // U+002D HYPHEN-MINUS\n\tif (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t// If the second code point is a U+002D HYPHEN-MINUS return true\n\t\tif (reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second code point is an ident-start code point return true\n\t\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second and third code points are a valid escape return true\n\t\tif (reader.codePointSource[reader.cursor+1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t// ident-start code point\n\t// Return true.\n\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) {\n\t\treturn true;\n\t}\n\n\t// U+005C REVERSE SOLIDUS (\\)\n\treturn checkIfTwoCodePointsAreAValidEscape(ctx, reader);\n}\n","import { FULL_STOP, HYPHEN_MINUS, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number\nexport function checkIfThreeCodePointsWouldStartANumber(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-)\n\t\t// If the second code point is a digit, return true.\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Otherwise, if the second code point is a U+002E FULL STOP (.)\n\t\tif (reader.codePointSource[reader.cursor+1] === FULL_STOP) {\n\t\t\t// and the third code point is a digit, return true.\n\t\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+2]);\n\t\t}\n\n\t\t// Otherwise, return false.\n\t\treturn false;\n\n\t} else if (reader.codePointSource[reader.cursor] === FULL_STOP) { // U+002E FULL STOP (.)\n\t\t// If the second code point is a digit, return true.\n\t\t// Otherwise, return false.\n\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+1]);\n\n\t} else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { // digit\n\t\t// Return true.\n\t\treturn true;\n\t}\n\n\t// anything else\n\t// Return false.\n\treturn false;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments\nexport function checkIfTwoCodePointsStartAComment(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] !== SOLIDUS) {\n\t\treturn false;\n\t}\n\n\tif (reader.codePointSource[reader.cursor+1] !== ASTERISK) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { GREATER_THAN_SIGN, HYPHEN_MINUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfThreeCodePointsWouldStartCDC(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenComment, TokenType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment\nexport function consumeComment(ctx: Context, reader: CodePointReader): TokenComment {\n\treader.advanceCodePoint(2);\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst codePoint = reader.readCodePoint();\n\t\tif (codePoint === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a comment.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.2. Consume comments',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (codePoint !== ASTERISK) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === SOLIDUS) {\n\t\t\treader.advanceCodePoint();\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Comment,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { MAXIMUM_ALLOWED_CODEPOINT, REPLACEMENT_CHARACTER } from '../code-points/code-points';\nimport { isHexDigitCodePoint, isSurrogate, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point\nexport function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): number {\n\tconst codePoint = reader.readCodePoint();\n\tif (codePoint === false) {\n\t\tctx.onParseError({\n\t\t\tmessage: 'Unexpected EOF while consuming an escaped code point.',\n\t\t\tstart: reader.representationStart,\n\t\t\tend: reader.representationEnd,\n\t\t\tstate: [\n\t\t\t\t'4.3.7. Consume an escaped code point',\n\t\t\t\t'Unexpected EOF',\n\t\t\t],\n\t\t});\n\n\t\treturn REPLACEMENT_CHARACTER;\n\t}\n\n\tif (isHexDigitCodePoint(codePoint)) {\n\t\tconst hexSequence: Array = [codePoint];\n\n\t\twhile ((reader.codePointSource[reader.cursor] !== undefined) && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) {\n\t\t\thexSequence.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tconst codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16);\n\t\tif (codePointLiteral === 0) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (isSurrogate(codePointLiteral)) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\n\t\treturn codePointLiteral;\n\t}\n\n\treturn codePoint;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name\nexport function consumeIdentSequence(ctx: Context, reader: CodePointReader): Array {\n\tconst result: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (isIdentCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tresult.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tresult.push(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn result;\n\t}\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { HashType, TokenDelim, TokenHash, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDelim|TokenHash {\n\treader.advanceCodePoint();\n\n\tif (\n\t\t(reader.codePointSource[reader.cursor] !== undefined) &&\n\t\tisIdentCodePoint(reader.codePointSource[reader.cursor]) ||\n\t\tcheckIfTwoCodePointsAreAValidEscape(ctx, reader)\n\t) {\n\t\tlet hashType = HashType.Unrestricted;\n\n\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\thashType = HashType.ID;\n\t\t}\n\n\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\t\treturn [\n\t\t\tTokenType.Hash,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\ttype: hashType,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [\n\t\tTokenType.Delim,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: '#',\n\t\t},\n\t];\n}\n","import { FULL_STOP, HYPHEN_MINUS, LATIN_CAPITAL_LETTER_E, LATIN_SMALL_LETTER_E, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { NumberType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number\nexport function consumeNumber(ctx: Context, reader: CodePointReader): [number, NumberType] {\n\t// 1. Initially set type to \"integer\".\n\t// Let repr be the empty string.\n\tlet type = NumberType.Integer;\n\tconst repr: Array = [];\n\n\t{\n\t\t// 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr.\n\t\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\t// 3. While the next input code point is a digit, consume it and append it to repr.\n\t\tconst newPart = consumeDigits(reader);\n\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\trepr.push(newPart[i]);\n\t\t}\n\t}\n\n\t{\n\t\t// 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then:\n\t\tif (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\t// 4.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 4.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 4.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 4.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t{\n\t\t// 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e),\n\t\t// optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+),\n\t\t// followed by a digit, then:\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+1])\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\t(\n\t\t\t\t(reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor+1] === PLUS_SIGN) &&\n\t\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+2])\n\t\t\t)\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+2]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(3);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t// 6. Convert repr to a number, and set the value to the returned value.\n\tconst value = convertCodePointsToNumber(repr);\n\n\t// 7. Return value and type.\n\treturn [value, type];\n}\n\nfunction consumeDigits(reader: CodePointReader): Array {\n\tconst value: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn value;\n\t\t}\n\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tvalue.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number\nfunction convertCodePointsToNumber(codePoints: Array): number {\n\tlet s = 1;\n\tconst iCodePoints: Array = [];\n\tlet i = 0;\n\n\tlet d = 0;\n\tconst fCodePoints: Array = [];\n\tlet f = 0;\n\n\tlet t = 1;\n\n\tconst eCodePoints: Array = [];\n\tlet e = 0;\n\n\tlet cursor = 0;\n\n\t// 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let s be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\ts = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 2. An integer part: zero or more digits.\n\t// If there is at least one digit,\n\t// let i be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let i be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tiCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\ti = digitCodePointsToInteger(iCodePoints);\n\n\t// 3. A decimal point: a single U+002E FULL STOP (.), or the empty string.\n\tif (codePoints[cursor] === FULL_STOP) {\n\t\tcursor++;\n\t}\n\n\t// 4. A fractional part: zero or more digits.\n\t// If there is at least one digit,\n\t// let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits;\n\t// otherwise, let f and d be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tfCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\td = fCodePoints.length;\n\tf = (digitCodePointsToInteger(fCodePoints) / Math.pow(10, d));\n\n\t// 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string.\n\tif (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) {\n\t\tcursor++;\n\t}\n\n\t// 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let t be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\tt = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 7. An exponent: zero or more digits.\n\t// If there is at least one digit,\n\t// let e be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let e be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\teCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\te = digitCodePointsToInteger(eCodePoints);\n\n\t// Return the number s·(i + f·10-d)·10te.\n\treturn s * (i + f) * Math.pow(10, t * e);\n}\n\nfunction digitCodePointsToInteger(codePoints: Array): number {\n\tif (codePoints.length === 0) {\n\t\treturn 0;\n\t}\n\n\treturn Number.parseInt(String.fromCharCode(...codePoints), 10);\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { PERCENTAGE_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenDimension, TokenNumber, TokenPercentage, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeNumber } from './number';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token\nexport function consumeNumericToken(ctx: Context, reader: CodePointReader): TokenPercentage|TokenNumber|TokenDimension {\n\tconst numberValue = consumeNumber(ctx, reader);\n\n\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\tconst unit = consumeIdentSequence(ctx, reader);\n\n\t\treturn [\n\t\t\tTokenType.Dimension,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: numberValue[0],\n\t\t\t\ttype: numberValue[1],\n\t\t\t\tunit: String.fromCharCode(...unit),\n\t\t\t},\n\t\t];\n\t}\n\n\t{\n\t\tif (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) {\n\t\t\treader.advanceCodePoint();\n\n\t\t\treturn [\n\t\t\t\tTokenType.Percentage,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: numberValue[0],\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Number,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: numberValue[0],\n\t\t\ttype: numberValue[1],\n\t\t},\n\t];\n}\n","import { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenType, TokenWhitespace } from '../interfaces/token';\n\nexport function consumeWhiteSpace(ctx: Context, reader: CodePointReader): TokenWhitespace {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (!isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tbreak;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t}\n\n\treturn [\n\t\tTokenType.Whitespace,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isNewLine } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadString, TokenString, TokenType } from '../interfaces/token';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token\nexport function consumeStringToken(ctx: Context, reader: CodePointReader): TokenBadString|TokenString {\n\tlet result = '';\n\n\tconst first = reader.readCodePoint();\n\tif (first === false) {\n\t\tthrow new Error('Unexpected EOF');\n\t}\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst next = reader.readCodePoint();\n\t\tif (next === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a string token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (isNewLine(next)) {\n\t\t\t{\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected newline while consuming a string token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t\t'Unexpected newline',\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treader.unreadCodePoint();\n\t\t\treturn [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t}\n\n\t\tif (next === first) {\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (next === REVERSE_SOLIDUS) {\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isNewLine(reader.codePointSource[reader.cursor])) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tresult += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += String.fromCharCode(next);\n\t}\n}\n","import { Context } from '../interfaces/context';\n\nconst u = 'u'.charCodeAt(0);\nconst U = 'U'.charCodeAt(0);\nconst r = 'r'.charCodeAt(0);\nconst R = 'R'.charCodeAt(0);\nconst l = 'l'.charCodeAt(0);\nconst L = 'L'.charCodeAt(0);\n\nexport function checkIfCodePointsMatchURLIdent(ctx: Context, codePoints: Array): boolean {\n\tif (codePoints.length !== 3) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[0] !== u && codePoints[0] !== U) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[1] !== r && codePoints[1] !== R) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[2] !== l && codePoints[2] !== L) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url\nexport function consumeBadURL(ctx: Context, reader: CodePointReader) {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tconsumeEscapedCodePoint(ctx, reader);\n\t\t\tcontinue;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\tcontinue;\n\t}\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { isNonPrintableCodePoint, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeBadURL } from './bad-url';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\nimport { consumeWhiteSpace } from './whitespace-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token\nexport function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL|TokenBadURL {\n\tconsumeWhiteSpace(ctx, reader);\n\tlet string = '';\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeWhiteSpace(ctx, reader);\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t\t'Consume as much whitespace as possible',\n\t\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected character while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE (\\'), U+0028 LEFT PARENTHESIS (() or non-printable code point',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) {\n\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\tstring += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Invalid escape sequence while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tstring += String.fromCharCode(reader.codePointSource[reader.cursor]);\n\t\treader.advanceCodePoint();\n\t}\n}\n","import { checkIfCodePointsMatchURLIdent } from '../checks/matches-url-ident';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK } from '../code-points/code-points';\nimport { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenFunction, TokenIdent, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeUrlToken } from './url-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token\nexport function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): TokenIdent | TokenFunction | TokenURL | TokenBadURL {\n\tconst codePoints = consumeIdentSequence(ctx, reader);\n\n\tif (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) {\n\t\treturn [\n\t\t\tTokenType.Ident,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t},\n\t\t];\n\t}\n\n\tif (checkIfCodePointsMatchURLIdent(ctx, codePoints)) {\n\t\treader.advanceCodePoint();\n\n\t\tlet read = 0;\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]);\n\t\t\tconst secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor+1]);\n\t\t\tif (firstIsWhitespace && secondIsWhitespace) {\n\t\t\t\tread += 2;\n\t\t\t\treader.advanceCodePoint(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor+1] : reader.codePointSource[reader.cursor];\n\t\t\tif (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) {\n\t\t\t\tif (read > 0) {\n\t\t\t\t\treader.advanceCodePoint(read);\n\t\t\t\t}\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.Function,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (read > 0) {\n\t\t\treader.advanceCodePoint(read);\n\t\t}\n\n\t\treturn consumeUrlToken(ctx, reader);\n\t}\n\n\treader.advanceCodePoint();\n\treturn [\n\t\tTokenType.Function,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t},\n\t];\n}\n","import { checkIfFourCodePointsWouldStartCDO } from './checks/four-code-points-would-start-cdo';\nimport { checkIfThreeCodePointsWouldStartAnIdentSequence } from './checks/three-code-points-would-start-ident-sequence';\nimport { checkIfThreeCodePointsWouldStartANumber } from './checks/three-code-points-would-start-number';\nimport { checkIfTwoCodePointsStartAComment } from './checks/two-code-points-start-comment';\nimport { checkIfThreeCodePointsWouldStartCDC } from './checks/three-code-points-would-start-cdc';\nimport { APOSTROPHE, CARRIAGE_RETURN, CHARACTER_TABULATION, COLON, COMMA, COMMERCIAL_AT, DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9, FORM_FEED, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, LINE_FEED, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON, SPACE } from './code-points/code-points';\nimport { isIdentStartCodePoint } from './code-points/ranges';\nimport { consumeComment } from './consume/comment';\nimport { consumeHashToken } from './consume/hash-token';\nimport { consumeIdentSequence } from './consume/ident-sequence';\nimport { consumeNumericToken } from './consume/numeric-token';\nimport { consumeWhiteSpace } from './consume/whitespace-token';\nimport { CSSToken, TokenType } from './interfaces/token';\nimport { Reader } from './reader';\nimport { consumeStringToken } from './consume/string-token';\nimport { consumeIdentLikeToken } from './consume/ident-like-token';\nimport { checkIfTwoCodePointsAreAValidEscape } from './checks/two-code-points-are-valid-escape';\nimport { ParserError } from './interfaces/error';\n\ninterface Stringer {\n\tvalueOf(): string\n}\n\nexport function tokenizer(input: { css: Stringer }, options?: { commentsAreTokens?: boolean, onParseError?: (error: ParserError) => void }) {\n\tconst css = input.css.valueOf();\n\n\tconst reader = new Reader(css);\n\n\tconst ctx = {\n\t\tonParseError: options?.onParseError ?? (() => { /* noop */ }),\n\t};\n\n\tfunction endOfFile() {\n\t\treturn reader.codePointSource[reader.cursor] === undefined;\n\t}\n\n\tfunction nextToken(): CSSToken | undefined {\n\t\treader.resetRepresentation();\n\n\t\tif (checkIfTwoCodePointsStartAComment(ctx, reader)) {\n\t\t\tif (options?.commentsAreTokens) {\n\t\t\t\treturn consumeComment(ctx, reader);\n\t\t\t} else {\n\t\t\t\tconsumeComment(ctx, reader);\n\t\t\t\treader.resetRepresentation();\n\t\t\t}\n\t\t}\n\n\t\tconst peeked = reader.codePointSource[reader.cursor];\n\t\tif (peeked === undefined) {\n\t\t\treturn [TokenType.EOF, '', -1, -1, undefined];\n\t\t}\n\n\t\tif (isIdentStartCodePoint(peeked)) {\n\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t}\n\n\t\t// Simple, one character tokens:\n\t\tswitch (peeked) {\n\t\t\tcase COMMA: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase COLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase SEMICOLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase APOSTROPHE:\n\t\t\tcase QUOTATION_MARK:\n\t\t\t\treturn consumeStringToken(ctx, reader);\n\t\t\tcase NUMBER_SIGN:\n\t\t\t\treturn consumeHashToken(ctx, reader);\n\n\t\t\tcase PLUS_SIGN:\n\t\t\tcase FULL_STOP: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: reader.representationString(),\n\t\t\t\t}];\n\t\t\t}\n\t\t\tcase DIGIT_0:\n\t\t\tcase DIGIT_1:\n\t\t\tcase DIGIT_2:\n\t\t\tcase DIGIT_3:\n\t\t\tcase DIGIT_4:\n\t\t\tcase DIGIT_5:\n\t\t\tcase DIGIT_6:\n\t\t\tcase DIGIT_7:\n\t\t\tcase DIGIT_8:\n\t\t\tcase DIGIT_9:\n\t\t\t\treturn consumeNumericToken(ctx, reader);\n\n\t\t\tcase LINE_FEED:\n\t\t\tcase CARRIAGE_RETURN:\n\t\t\tcase FORM_FEED:\n\t\t\tcase CHARACTER_TABULATION:\n\t\t\tcase SPACE:\n\t\t\t\treturn consumeWhiteSpace(ctx, reader);\n\n\t\t\tcase HYPHEN_MINUS: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(3);\n\n\t\t\t\t\treturn [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '-',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase LESS_THAN_SIGN: {\n\t\t\t\tif (checkIfFourCodePointsWouldStartCDO(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(4);\n\n\t\t\t\t\treturn [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '<',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase COMMERCIAL_AT: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\n\t\t\t\t\treturn [TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\t\t}];\n\t\t\t\t}\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '@',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase REVERSE_SOLIDUS: {\n\t\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Invalid escape sequence after \"\\\\\"',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.1. Consume a token',\n\t\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '\\\\',\n\t\t\t\t}];\n\t\t\t}\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\tvalue: reader.representationString(),\n\t\t}];\n\t}\n\n\treturn {\n\t\tnextToken: nextToken,\n\t\tendOfFile: endOfFile,\n\t};\n}\n","import { CSSToken } from '../interfaces/token';\n\nexport function cloneTokens(tokens: Array): Array {\n\tif ((typeof globalThis !== 'undefined') && 'structuredClone' in globalThis) {\n\t\treturn structuredClone(tokens);\n\t}\n\n\treturn JSON.parse(JSON.stringify(tokens));\n}\n"],"names":["Reader","cursor","source","codePointSource","length","representationStart","representationEnd","constructor","Array","i","charCodeAt","cursorPositionOfLastReadCodePoint","advanceCodePoint","n","readCodePoint","codePoint","undefined","unreadCodePoint","representationString","slice","resetRepresentation","start","end","TokenType","NumberType","HashType","mirrorVariantType","type","OpenParen","CloseParen","OpenCurly","CloseCurly","OpenSquare","CloseSquare","isToken","x","isArray","stringify","tokens","buffer","APOSTROPHE","ASTERISK","BACKSPACE","CARRIAGE_RETURN","CHARACTER_TABULATION","COLON","COMMA","COMMERCIAL_AT","DELETE","EXCLAMATION_MARK","FORM_FEED","FULL_STOP","GREATER_THAN_SIGN","HYPHEN_MINUS","INFORMATION_SEPARATOR_ONE","LATIN_CAPITAL_LETTER_E","LATIN_SMALL_LETTER_E","LEFT_CURLY_BRACKET","LEFT_PARENTHESIS","LEFT_SQUARE_BRACKET","LESS_THAN_SIGN","LINE_FEED","LINE_TABULATION","LOW_LINE","MAXIMUM_ALLOWED_CODEPOINT","NULL","NUMBER_SIGN","PERCENTAGE_SIGN","PLUS_SIGN","QUOTATION_MARK","REPLACEMENT_CHARACTER","REVERSE_SOLIDUS","RIGHT_CURLY_BRACKET","RIGHT_PARENTHESIS","RIGHT_SQUARE_BRACKET","SEMICOLON","SHIFT_OUT","SOLIDUS","SPACE","DIGIT_0","DIGIT_1","DIGIT_2","DIGIT_3","DIGIT_4","DIGIT_5","DIGIT_6","DIGIT_7","DIGIT_8","DIGIT_9","checkIfFourCodePointsWouldStartCDO","ctx","reader","digitsLow","digitsHigh","isDigitCodePoint","search","letterUppercaseLow","letterUppercaseHigh","isUppercaseLetterCodePoint","letterLowercaseLow","letterLowercaseHigh","isLowercaseLetterCodePoint","afUppercaseHigh","afLowercaseHigh","isHexDigitCodePoint","isLetterCodePoint","nonASCIILow","isNonASCIICodePoint","isIdentStartCodePoint","isIdentCodePoint","isNonPrintableCodePoint","isNewLine","isWhitespace","surrogateLow","surrogateHigh","isSurrogate","checkIfTwoCodePointsAreAValidEscape","checkIfThreeCodePointsWouldStartAnIdentSequence","checkIfThreeCodePointsWouldStartANumber","checkIfTwoCodePointsStartAComment","checkIfThreeCodePointsWouldStartCDC","consumeComment","onParseError","message","state","Comment","consumeEscapedCodePoint","hexSequence","push","codePointLiteral","parseInt","String","fromCharCode","consumeIdentSequence","result","consumeHashToken","hashType","Unrestricted","ID","identSequence","Hash","value","Delim","consumeNumber","Integer","repr","newPart","consumeDigits","Number","convertCodePointsToNumber","codePoints","s","iCodePoints","d","fCodePoints","f","t","eCodePoints","e","digitCodePointsToInteger","Math","pow","consumeNumericToken","numberValue","unit","Dimension","Percentage","consumeWhiteSpace","Whitespace","consumeStringToken","first","Error","next","BadString","u","U","r","R","l","L","checkIfCodePointsMatchURLIdent","consumeBadURL","consumeUrlToken","string","URL","BadURL","consumeIdentLikeToken","Ident","read","firstIsWhitespace","secondIsWhitespace","firstNonWhitespace","Function","tokenizer","input","options","css","valueOf","endOfFile","nextToken","commentsAreTokens","peeked","EOF","Comma","Colon","Semicolon","CDC","CDO","AtKeyword","cloneTokens","globalThis","structuredClone","JSON","parse"],"mappings":"MAEaA,MAAM,CAAA;EAClBC,MAAM,CAAA;AACNC,EAAAA,MAAM,GAAG,EAAE,CAAA;AACXC,EAAAA,eAAe,GAAkB,EAAE,CAAA;AACnCC,EAAAA,MAAM,GAAG,CAAC,CAAA;AAEVC,EAAAA,mBAAmB,GAAG,CAAC,CAAA;EACvBC,iBAAiB,GAAG,CAAC,CAAC,CAAA;EAEtBC,WAAA,CAAYL,MAAc,EAAA;IACzB,IAAI,CAACD,MAAM,GAAG,CAAC,CAAA;IACf,IAAI,CAACC,MAAM,GAAGA,MAAM,CAAA;AACpB,IAAA,IAAI,CAACE,MAAM,GAAGF,MAAM,CAACE,MAAM,CAAA;IAE3B,IAAI,CAACD,eAAe,GAAG,IAAIK,KAAK,CAAC,IAAI,CAACJ,MAAM,CAAC,CAAA;AAC7C,IAAA,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,IAAI,CAACL,MAAM,EAAEK,CAAC,EAAE,EAAE;AACrC,MAAA,IAAI,CAACN,eAAe,CAACM,CAAC,CAAC,GAAG,IAA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AACzB,IAAA,OAAO,CAACW,SAAS,CAACuH,KAAK,EAAEnD,MAAM,CAACzE,oBAAoB,EAAE,EAAEyE,MAAM,CAACtF,mBAAmB,EAAEsF,MAAM,CAACrF,iBAAiB,EAAE;MAC7GuI,KAAK,EAAElD,MAAM,CAACzE,oBAAoB,EAAA;AAClC,KAAA,CAAC,CAAA;AACH,GAAA;EAEA,OAAO;AACNqL,IAAAA,SAAS,EAAEA,SAAS;AACpBD,IAAAA,SAAS,EAAEA,SAAAA;GACX,CAAA;AACF;;ACpNM,SAAUW,WAAW,CAAC3K,MAAuB,EAAA;EAClD,IAAK,OAAO4K,UAAU,KAAK,WAAW,IAAK,iBAAiB,IAAIA,UAAU,EAAE;IAC3E,OAAOC,eAAe,CAAC7K,MAAM,CAAC,CAAA;AAC9B,GAAA;EAED,OAAO8K,IAAI,CAACC,KAAK,CAACD,IAAI,CAAC/K,SAAS,CAACC,MAAM,CAAC,CAAC,CAAA;AAC1C;;;;"} \ No newline at end of file diff --git a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts index 1fb887ea0..950e3c7b7 100644 --- a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts +++ b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts @@ -4,6 +4,7 @@ export type CodePointReader = { cursor: number; codePointSource: Array; cursorPositionOfLastReadCodePoint(): number; + advanceCodePoint(n?: number): any; readCodePoint(n?: number): number | false; unreadCodePoint(n?: number): boolean; representationString(): string; diff --git a/packages/css-tokenizer/dist/reader.d.ts b/packages/css-tokenizer/dist/reader.d.ts index c93b39b38..ff6969c3b 100644 --- a/packages/css-tokenizer/dist/reader.d.ts +++ b/packages/css-tokenizer/dist/reader.d.ts @@ -1,13 +1,14 @@ import { CodePointReader } from './interfaces/code-point-reader'; export declare class Reader implements CodePointReader { cursor: number; - stringSource: string; + source: string; codePointSource: Array; length: number; representationStart: number; representationEnd: number; constructor(source: string); cursorPositionOfLastReadCodePoint(): number; + advanceCodePoint(n?: number): void; readCodePoint(n?: number): number | false; unreadCodePoint(n?: number): boolean; representationString(): string; diff --git a/packages/css-tokenizer/src/consume/bad-url.ts b/packages/css-tokenizer/src/consume/bad-url.ts index d669e0a03..bdd8eaa73 100644 --- a/packages/css-tokenizer/src/consume/bad-url.ts +++ b/packages/css-tokenizer/src/consume/bad-url.ts @@ -13,17 +13,17 @@ export function consumeBadURL(ctx: Context, reader: CodePointReader) { } if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.readCodePoint(); + reader.advanceCodePoint(); return; } if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - reader.readCodePoint(); + reader.advanceCodePoint(); consumeEscapedCodePoint(ctx, reader); continue; } - reader.readCodePoint(); + reader.advanceCodePoint(); continue; } } diff --git a/packages/css-tokenizer/src/consume/comment.ts b/packages/css-tokenizer/src/consume/comment.ts index 87f1035fc..0b82c0d20 100644 --- a/packages/css-tokenizer/src/consume/comment.ts +++ b/packages/css-tokenizer/src/consume/comment.ts @@ -5,7 +5,7 @@ import { TokenComment, TokenType } from '../interfaces/token'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment export function consumeComment(ctx: Context, reader: CodePointReader): TokenComment { - reader.readCodePoint(2); + reader.advanceCodePoint(2); // eslint-disable-next-line no-constant-condition while (true) { @@ -33,7 +33,7 @@ export function consumeComment(ctx: Context, reader: CodePointReader): TokenComm } if (reader.codePointSource[reader.cursor] === SOLIDUS) { - reader.readCodePoint(); + reader.advanceCodePoint(); break; } } diff --git a/packages/css-tokenizer/src/consume/escaped-code-point.ts b/packages/css-tokenizer/src/consume/escaped-code-point.ts index aa854ae41..5565d1de5 100644 --- a/packages/css-tokenizer/src/consume/escaped-code-point.ts +++ b/packages/css-tokenizer/src/consume/escaped-code-point.ts @@ -25,11 +25,11 @@ export function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): while ((reader.codePointSource[reader.cursor] !== undefined) && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) { hexSequence.push(reader.codePointSource[reader.cursor]); - reader.readCodePoint(); + reader.advanceCodePoint(); } if (isWhitespace(reader.codePointSource[reader.cursor])) { - reader.readCodePoint(); + reader.advanceCodePoint(); } const codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16); diff --git a/packages/css-tokenizer/src/consume/hash-token.ts b/packages/css-tokenizer/src/consume/hash-token.ts index 2a1169994..091da84d2 100644 --- a/packages/css-tokenizer/src/consume/hash-token.ts +++ b/packages/css-tokenizer/src/consume/hash-token.ts @@ -8,7 +8,7 @@ import { consumeIdentSequence } from './ident-sequence'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token export function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDelim|TokenHash { - reader.readCodePoint(); + reader.advanceCodePoint(); if ( (reader.codePointSource[reader.cursor] !== undefined) && diff --git a/packages/css-tokenizer/src/consume/ident-like-token.ts b/packages/css-tokenizer/src/consume/ident-like-token.ts index 6b8d9d775..69adc5a0c 100644 --- a/packages/css-tokenizer/src/consume/ident-like-token.ts +++ b/packages/css-tokenizer/src/consume/ident-like-token.ts @@ -24,7 +24,7 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To } if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { - reader.readCodePoint(); + reader.advanceCodePoint(); let read = 0; // eslint-disable-next-line no-constant-condition @@ -33,14 +33,14 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To const secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor+1]); if (firstIsWhitespace && secondIsWhitespace) { read += 2; - reader.readCodePoint(2); + reader.advanceCodePoint(2); continue; } const firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor+1] : reader.codePointSource[reader.cursor]; if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { if (read > 0) { - reader.unreadCodePoint(read); + reader.advanceCodePoint(read); } return [ @@ -58,13 +58,13 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To } if (read > 0) { - reader.unreadCodePoint(read); + reader.advanceCodePoint(read); } return consumeUrlToken(ctx, reader); } - reader.readCodePoint(); + reader.advanceCodePoint(); return [ TokenType.Function, reader.representationString(), diff --git a/packages/css-tokenizer/src/consume/ident-sequence.ts b/packages/css-tokenizer/src/consume/ident-sequence.ts index e937b1dea..42648f544 100644 --- a/packages/css-tokenizer/src/consume/ident-sequence.ts +++ b/packages/css-tokenizer/src/consume/ident-sequence.ts @@ -6,22 +6,18 @@ import { consumeEscapedCodePoint } from './escaped-code-point'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name export function consumeIdentSequence(ctx: Context, reader: CodePointReader): Array { - const result = []; + const result: Array = []; // eslint-disable-next-line no-constant-condition while (true) { - if (reader.codePointSource[reader.cursor] === undefined) { - return result; - } - if (isIdentCodePoint(reader.codePointSource[reader.cursor])) { result.push(reader.codePointSource[reader.cursor]); - reader.readCodePoint(); + reader.advanceCodePoint(); continue; } if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - reader.readCodePoint(); + reader.advanceCodePoint(); result.push(consumeEscapedCodePoint(ctx, reader)); continue; } diff --git a/packages/css-tokenizer/src/consume/number.ts b/packages/css-tokenizer/src/consume/number.ts index c8c9c1f1b..865b1063a 100644 --- a/packages/css-tokenizer/src/consume/number.ts +++ b/packages/css-tokenizer/src/consume/number.ts @@ -15,7 +15,7 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr. if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { repr.push(reader.codePointSource[reader.cursor]); - reader.readCodePoint(); + reader.advanceCodePoint(); } // 3. While the next input code point is a digit, consume it and append it to repr. @@ -33,7 +33,7 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N repr.push(reader.codePointSource[reader.cursor+1]); // 4.1. Consume them. - reader.readCodePoint(2); + reader.advanceCodePoint(2); // 4.3. Set type to "number". type = NumberType.Number; @@ -59,7 +59,7 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N repr.push(reader.codePointSource[reader.cursor+1]); // 5.1. Consume them. - reader.readCodePoint(2); + reader.advanceCodePoint(2); // 5.3. Set type to "number". type = NumberType.Number; @@ -84,7 +84,7 @@ export function consumeNumber(ctx: Context, reader: CodePointReader): [number, N repr.push(reader.codePointSource[reader.cursor+2]); // 5.1. Consume them. - reader.readCodePoint(3); + reader.advanceCodePoint(3); // 5.3. Set type to "number". type = NumberType.Number; @@ -115,7 +115,7 @@ function consumeDigits(reader: CodePointReader): Array { if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { value.push(reader.codePointSource[reader.cursor]); - reader.readCodePoint(); + reader.advanceCodePoint(); } else { return value; } diff --git a/packages/css-tokenizer/src/consume/numeric-token.ts b/packages/css-tokenizer/src/consume/numeric-token.ts index 8f68601fb..a7935ae82 100644 --- a/packages/css-tokenizer/src/consume/numeric-token.ts +++ b/packages/css-tokenizer/src/consume/numeric-token.ts @@ -28,7 +28,7 @@ export function consumeNumericToken(ctx: Context, reader: CodePointReader): Toke { if (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) { - reader.readCodePoint(); + reader.advanceCodePoint(); return [ TokenType.Percentage, diff --git a/packages/css-tokenizer/src/consume/string-token.ts b/packages/css-tokenizer/src/consume/string-token.ts index c5f5605a1..eeadaabe1 100644 --- a/packages/css-tokenizer/src/consume/string-token.ts +++ b/packages/css-tokenizer/src/consume/string-token.ts @@ -58,7 +58,7 @@ export function consumeStringToken(ctx: Context, reader: CodePointReader): Token } if (isNewLine(reader.codePointSource[reader.cursor])) { - reader.readCodePoint(); + reader.advanceCodePoint(); continue; } diff --git a/packages/css-tokenizer/src/consume/url-token.ts b/packages/css-tokenizer/src/consume/url-token.ts index 79a6424cd..5ac3623ad 100644 --- a/packages/css-tokenizer/src/consume/url-token.ts +++ b/packages/css-tokenizer/src/consume/url-token.ts @@ -38,7 +38,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL } if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.readCodePoint(); + reader.advanceCodePoint(); return [ TokenType.URL, reader.representationString(), @@ -76,7 +76,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL } if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.readCodePoint(); + reader.advanceCodePoint(); return [ TokenType.URL, reader.representationString(), @@ -149,6 +149,6 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL } string += String.fromCharCode(reader.codePointSource[reader.cursor]); - reader.readCodePoint(); + reader.advanceCodePoint(); } } diff --git a/packages/css-tokenizer/src/consume/whitespace-token.ts b/packages/css-tokenizer/src/consume/whitespace-token.ts index 5b1e8a096..690ad01f4 100644 --- a/packages/css-tokenizer/src/consume/whitespace-token.ts +++ b/packages/css-tokenizer/src/consume/whitespace-token.ts @@ -3,37 +3,14 @@ import { CodePointReader } from '../interfaces/code-point-reader'; import { Context } from '../interfaces/context'; import { TokenType, TokenWhitespace } from '../interfaces/token'; -export function consumeWhiteSpace(ctx: Context, reader: CodePointReader, max = -1): TokenWhitespace { - let current = 0; - +export function consumeWhiteSpace(ctx: Context, reader: CodePointReader): TokenWhitespace { // eslint-disable-next-line no-constant-condition while (true) { - if (max !== -1 && current === max) { - return [ - TokenType.Whitespace, - reader.representationString(), - reader.representationStart, - reader.representationEnd, - undefined, - ]; - } - - current++; - if (reader.codePointSource[reader.cursor] === undefined) { - return [ - TokenType.Whitespace, - reader.representationString(), - reader.representationStart, - reader.representationEnd, - undefined, - ]; - } - if (!isWhitespace(reader.codePointSource[reader.cursor])) { break; } - reader.readCodePoint(); + reader.advanceCodePoint(); } return [ diff --git a/packages/css-tokenizer/src/interfaces/code-point-reader.ts b/packages/css-tokenizer/src/interfaces/code-point-reader.ts index 460c62e64..a35950c04 100644 --- a/packages/css-tokenizer/src/interfaces/code-point-reader.ts +++ b/packages/css-tokenizer/src/interfaces/code-point-reader.ts @@ -9,10 +9,12 @@ export type CodePointReader = { representationEnd: number; cursor: number; - codePointSource: Array ; + codePointSource: Array; + source: string; cursorPositionOfLastReadCodePoint(): number; + advanceCodePoint(n?: number) readCodePoint(n?: number): number | false unreadCodePoint(n?: number): boolean diff --git a/packages/css-tokenizer/src/reader.ts b/packages/css-tokenizer/src/reader.ts index 14874d40d..55bde1761 100644 --- a/packages/css-tokenizer/src/reader.ts +++ b/packages/css-tokenizer/src/reader.ts @@ -2,7 +2,7 @@ import { CodePointReader } from './interfaces/code-point-reader'; export class Reader implements CodePointReader { cursor: number; - stringSource = ''; + source = ''; codePointSource: Array = []; length = 0; @@ -11,12 +11,12 @@ export class Reader implements CodePointReader { constructor(source: string) { this.cursor = 0; - this.stringSource = source; + this.source = source; this.length = source.length; this.codePointSource = new Array(this.length); for (let i = 0; i < this.length; i++) { - this.codePointSource[i] = this.stringSource.charCodeAt(i); + this.codePointSource[i] = this.source.charCodeAt(i); } } @@ -24,6 +24,11 @@ export class Reader implements CodePointReader { return this.cursor - 1; } + advanceCodePoint(n = 1) { + this.cursor += n; + this.representationEnd = this.cursor - 1; + } + readCodePoint(n = 1): number | false { const codePoint = this.codePointSource[this.cursor]; if (codePoint === undefined) { @@ -48,11 +53,7 @@ export class Reader implements CodePointReader { } representationString(): string { - if (this.representationEnd === -1) { - return ''; - } - - return this.stringSource.slice(this.representationStart, this.representationEnd + 1); + return this.source.slice(this.representationStart, this.representationEnd + 1); } resetRepresentation() { @@ -61,6 +62,6 @@ export class Reader implements CodePointReader { } slice(start: number, end: number): string { - return this.stringSource.slice(start, end); + return this.source.slice(start, end); } } diff --git a/packages/css-tokenizer/src/tokenizer.ts b/packages/css-tokenizer/src/tokenizer.ts index 098abda0e..40910119f 100644 --- a/packages/css-tokenizer/src/tokenizer.ts +++ b/packages/css-tokenizer/src/tokenizer.ts @@ -58,39 +58,39 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken // Simple, one character tokens: switch (peeked) { case COMMA: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case COLON: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case SEMICOLON: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case LEFT_PARENTHESIS: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case RIGHT_PARENTHESIS: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case LEFT_SQUARE_BRACKET: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case RIGHT_SQUARE_BRACKET: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case LEFT_CURLY_BRACKET: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case RIGHT_CURLY_BRACKET: { - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } case APOSTROPHE: @@ -105,9 +105,9 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken return consumeNumericToken(ctx, reader); } - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(peeked), + value: reader.representationString(), }]; } case DIGIT_0: @@ -135,7 +135,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } if (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) { - reader.readCodePoint(3); + reader.advanceCodePoint(3); return [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } @@ -144,7 +144,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken return consumeIdentLikeToken(ctx, reader); } - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: '-', }]; @@ -152,19 +152,19 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken case LESS_THAN_SIGN: { if (checkIfFourCodePointsWouldStartCDO(ctx, reader)) { - reader.readCodePoint(4); + reader.advanceCodePoint(4); return [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; } - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { value: '<', }]; } case COMMERCIAL_AT: { - reader.readCodePoint(); + reader.advanceCodePoint(); if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { const identSequence = consumeIdentSequence(ctx, reader); @@ -183,7 +183,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken return consumeIdentLikeToken(ctx, reader); } - reader.readCodePoint(); + reader.advanceCodePoint(); ctx.onParseError({ message: 'Invalid escape sequence after "\\"', @@ -202,9 +202,9 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } } - reader.readCodePoint(); + reader.advanceCodePoint(); return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(peeked), + value: reader.representationString(), }]; } From 526d49be175bee7196e7969b2d4ab6ab4ef5dba1 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sun, 25 Dec 2022 12:43:48 +0100 Subject: [PATCH 07/24] wip --- packages/css-tokenizer/dist/index.cjs | 1182 +---------------- packages/css-tokenizer/dist/index.cjs.map | 1 - packages/css-tokenizer/dist/index.mjs | 1175 +--------------- packages/css-tokenizer/dist/index.mjs.map | 1 - .../dist/interfaces/code-point-reader.d.ts | 4 +- packages/css-tokenizer/dist/reader.d.ts | 3 - packages/css-tokenizer/src/consume/comment.ts | 2 +- .../css-tokenizer/src/consume/hash-token.ts | 4 +- .../src/consume/ident-like-token.ts | 6 +- .../src/consume/numeric-token.ts | 6 +- .../css-tokenizer/src/consume/string-token.ts | 9 +- .../css-tokenizer/src/consume/url-token.ts | 14 +- .../src/consume/whitespace-token.ts | 2 +- .../src/interfaces/code-point-reader.ts | 5 - packages/css-tokenizer/src/reader.ts | 19 +- packages/css-tokenizer/src/tokenizer.ts | 117 +- packages/css-tokenizer/test/test-reader.mjs | 12 +- 17 files changed, 84 insertions(+), 2478 deletions(-) delete mode 100644 packages/css-tokenizer/dist/index.cjs.map delete mode 100644 packages/css-tokenizer/dist/index.mjs.map diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index 13307e4ec..5fd78932e 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1,1181 +1 @@ -'use strict'; - -class Reader { - cursor; - source = ''; - codePointSource = []; - length = 0; - representationStart = 0; - representationEnd = -1; - constructor(source) { - this.cursor = 0; - this.source = source; - this.length = source.length; - this.codePointSource = new Array(this.length); - for (let i = 0; i < this.length; i++) { - this.codePointSource[i] = this.source.charCodeAt(i); - } - } - cursorPositionOfLastReadCodePoint() { - return this.cursor - 1; - } - advanceCodePoint(n = 1) { - this.cursor += n; - this.representationEnd = this.cursor - 1; - } - readCodePoint(n = 1) { - const codePoint = this.codePointSource[this.cursor]; - if (codePoint === undefined) { - return false; - } - this.cursor += n; - this.representationEnd = this.cursor - 1; - return codePoint; - } - unreadCodePoint(n = 1) { - if (this.cursor === 0) { - return false; - } - this.cursor -= n; - this.representationEnd = this.cursor - 1; - return true; - } - representationString() { - return this.source.slice(this.representationStart, this.representationEnd + 1); - } - resetRepresentation() { - this.representationStart = this.cursor; - this.representationEnd = -1; - } - slice(start, end) { - return this.source.slice(start, end); - } -} - -exports.TokenType = void 0; -(function (TokenType) { - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */ - TokenType["Comment"] = "comment"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */ - TokenType["AtKeyword"] = "at-keyword-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */ - TokenType["BadString"] = "bad-string-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */ - TokenType["BadURL"] = "bad-url-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */ - TokenType["CDC"] = "CDC-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */ - TokenType["CDO"] = "CDO-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */ - TokenType["Colon"] = "colon-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */ - TokenType["Comma"] = "comma-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */ - TokenType["Delim"] = "delim-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */ - TokenType["Dimension"] = "dimension-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */ - TokenType["EOF"] = "EOF-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */ - TokenType["Function"] = "function-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */ - TokenType["Hash"] = "hash-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */ - TokenType["Ident"] = "ident-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ - TokenType["Number"] = "number-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ - TokenType["Percentage"] = "percentage-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */ - TokenType["Semicolon"] = "semicolon-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */ - TokenType["String"] = "string-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */ - TokenType["URL"] = "url-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */ - TokenType["Whitespace"] = "whitespace-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */ - TokenType["OpenParen"] = "(-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */ - TokenType["CloseParen"] = ")-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */ - TokenType["OpenSquare"] = "[-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */ - TokenType["CloseSquare"] = "]-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */ - TokenType["OpenCurly"] = "{-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */ - TokenType["CloseCurly"] = "}-token"; -})(exports.TokenType || (exports.TokenType = {})); -exports.NumberType = void 0; -(function (NumberType) { - NumberType["Integer"] = "integer"; - NumberType["Number"] = "number"; -})(exports.NumberType || (exports.NumberType = {})); -var HashType; -(function (HashType) { - HashType["Unrestricted"] = "unrestricted"; - HashType["ID"] = "id"; -})(HashType || (HashType = {})); -function mirrorVariantType(type) { - switch (type) { - 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; - } -} -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function isToken(x) { - if (!Array.isArray(x)) { - return false; - } - if (x.length < 4) { - return false; - } - if (!(x[0] in exports.TokenType)) { - return false; - } - if (typeof x[1] !== 'string') { - return false; - } - if (typeof x[2] !== 'number') { - return false; - } - if (typeof x[3] !== 'number') { - return false; - } - return true; -} - -function stringify(...tokens) { - let buffer = ''; - for (let i = 0; i < tokens.length; i++) { - buffer = buffer + tokens[i][1]; - } - return buffer; -} - -/** ' */ -const APOSTROPHE = '\u{27}'.charCodeAt(0); -/** * */ -const ASTERISK = '\u{2a}'.charCodeAt(0); -/** \b */ -const BACKSPACE = '\u{8}'.charCodeAt(0); -/** \r */ -const CARRIAGE_RETURN = '\u{d}'.charCodeAt(0); -/** \t */ -const CHARACTER_TABULATION = '\u{9}'.charCodeAt(0); -/** : */ -const COLON = '\u{3a}'.charCodeAt(0); -/** , */ -const COMMA = '\u{2c}'.charCodeAt(0); -/** @ */ -const COMMERCIAL_AT = '\u{40}'.charCodeAt(0); -/** \x7F */ -const DELETE = '\u{7f}'.charCodeAt(0); -/** ! */ -const EXCLAMATION_MARK = '\u{21}'.charCodeAt(0); -/** \f */ -const FORM_FEED = '\u{c}'.charCodeAt(0); -/** . */ -const FULL_STOP = '\u{2e}'.charCodeAt(0); -/** > */ -const GREATER_THAN_SIGN = '\u{3e}'.charCodeAt(0); -/** - */ -const HYPHEN_MINUS = '\u{2d}'.charCodeAt(0); -/** \x1F */ -const INFORMATION_SEPARATOR_ONE = '\u{1f}'.charCodeAt(0); -/** E */ -const LATIN_CAPITAL_LETTER_E = '\u{45}'.charCodeAt(0); -/** e */ -const LATIN_SMALL_LETTER_E = '\u{65}'.charCodeAt(0); -/** { */ -const LEFT_CURLY_BRACKET = '\u{7b}'.charCodeAt(0); -/** ( */ -const LEFT_PARENTHESIS = '\u{28}'.charCodeAt(0); -/** [ */ -const LEFT_SQUARE_BRACKET = '\u{5b}'.charCodeAt(0); -/** < */ -const LESS_THAN_SIGN = '\u{3c}'.charCodeAt(0); -/** \n */ -const LINE_FEED = '\u{a}'.charCodeAt(0); -/** \v */ -const LINE_TABULATION = '\u{b}'.charCodeAt(0); -/** _ */ -const LOW_LINE = '\u{5f}'.charCodeAt(0); -/** \x10FFFF */ -const MAXIMUM_ALLOWED_CODEPOINT = '\u{10FFFF}'.charCodeAt(0); -/** \x00 */ -const NULL = '\u{0}'.charCodeAt(0); -/** # */ -const NUMBER_SIGN = '\u{23}'.charCodeAt(0); -/** % */ -const PERCENTAGE_SIGN = '\u{25}'.charCodeAt(0); -/** + */ -const PLUS_SIGN = '\u{2b}'.charCodeAt(0); -/** " */ -const QUOTATION_MARK = '\u{22}'.charCodeAt(0); -/** � */ -const REPLACEMENT_CHARACTER = '\u{0FFFD}'.charCodeAt(0); -/** \ */ -const REVERSE_SOLIDUS = '\u{5c}'.charCodeAt(0); -/** } */ -const RIGHT_CURLY_BRACKET = '\u{7d}'.charCodeAt(0); -/** ) */ -const RIGHT_PARENTHESIS = '\u{29}'.charCodeAt(0); -/** ] */ -const RIGHT_SQUARE_BRACKET = '\u{5d}'.charCodeAt(0); -/** ; */ -const SEMICOLON = '\u{3b}'.charCodeAt(0); -/** \u0E */ -const SHIFT_OUT = '\u{e}'.charCodeAt(0); -/** / */ -const SOLIDUS = '\u{2f}'.charCodeAt(0); -/** \u20 */ -const SPACE = '\u{20}'.charCodeAt(0); -/** 0 */ -const DIGIT_0 = '\u{30}'.charCodeAt(0); -/** 1 */ -const DIGIT_1 = '\u{31}'.charCodeAt(0); -/** 2 */ -const DIGIT_2 = '\u{32}'.charCodeAt(0); -/** 3 */ -const DIGIT_3 = '\u{33}'.charCodeAt(0); -/** 4 */ -const DIGIT_4 = '\u{34}'.charCodeAt(0); -/** 5 */ -const DIGIT_5 = '\u{35}'.charCodeAt(0); -/** 6 */ -const DIGIT_6 = '\u{36}'.charCodeAt(0); -/** 7 */ -const DIGIT_7 = '\u{37}'.charCodeAt(0); -/** 8 */ -const DIGIT_8 = '\u{38}'.charCodeAt(0); -/** 9 */ -const DIGIT_9 = '\u{39}'.charCodeAt(0); - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token -function checkIfFourCodePointsWouldStartCDO(ctx, reader) { - return reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor + 1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 3] === HYPHEN_MINUS; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions -const digitsLow = '\u{30}'.charCodeAt(0); -const digitsHigh = '\u{39}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit -function isDigitCodePoint(search) { - return digitsLow <= search && search <= digitsHigh; -} -const letterUppercaseLow = '\u{41}'.charCodeAt(0); -const letterUppercaseHigh = '\u{5a}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter -function isUppercaseLetterCodePoint(search) { - return letterUppercaseLow <= search && search <= letterUppercaseHigh; -} -const letterLowercaseLow = '\u{61}'.charCodeAt(0); -const letterLowercaseHigh = '\u{7a}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter -function isLowercaseLetterCodePoint(search) { - return letterLowercaseLow <= search && search <= letterLowercaseHigh; -} -const afUppercaseHigh = '\u{46}'.charCodeAt(0); -const afLowercaseHigh = '\u{66}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit -function isHexDigitCodePoint(search) { - if (digitsLow <= search && search <= digitsHigh) { - return true; - } - if (letterLowercaseLow <= search && search <= afLowercaseHigh) { - return true; - } - if (letterUppercaseLow <= search && search <= afUppercaseHigh) { - return true; - } - return false; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter -function isLetterCodePoint(search) { - return isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search); -} -const nonASCIILow = '\u{80}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point -function isNonASCIICodePoint(search) { - return search >= nonASCIILow; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point -function isIdentStartCodePoint(search) { - if (isLetterCodePoint(search)) { - return true; - } - if (isNonASCIICodePoint(search)) { - return true; - } - return search === LOW_LINE; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point -function isIdentCodePoint(search) { - if (isIdentStartCodePoint(search)) { - return true; - } - if (isDigitCodePoint(search)) { - return true; - } - return search === HYPHEN_MINUS; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point -function isNonPrintableCodePoint(search) { - if (search === LINE_TABULATION) { - return true; - } - if (search === DELETE) { - return true; - } - if (NULL <= search && search <= BACKSPACE) { - return true; - } - return SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace -function isNewLine(search) { - switch (search) { - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing - // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. - // Applying the preprocessing rules would make it impossible to match the input. - // A side effect of this is that our definition of whitespace is broader. - return true; - default: - return false; - } -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace -function isWhitespace(search) { - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing - // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. - // Applying the preprocessing rules would make it impossible to match the input. - // A side effect of this is that our definition of whitespace is broader. - switch (search) { - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - case CHARACTER_TABULATION: - case SPACE: - return true; - default: - return false; - } -} -const surrogateLow = '\u{d800}'.charCodeAt(0); -const surrogateHigh = '\u{dfff}'.charCodeAt(0); -// https://infra.spec.whatwg.org/#surrogate -function isSurrogate(search) { - return surrogateLow <= search && search <= surrogateHigh; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape -function checkIfTwoCodePointsAreAValidEscape(ctx, reader) { - // If the first code point is not U+005C REVERSE SOLIDUS (\), return false. - if (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { - // "\" - return false; - } - // Otherwise, if the second code point is a newline, return false. - if (reader.codePointSource[reader.cursor + 1] === LINE_FEED) { - return false; - } - // Otherwise, return true. - return true; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier -function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader) { - // // U+002D HYPHEN-MINUS - if (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { - // If the second code point is a U+002D HYPHEN-MINUS return true - if (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS) { - return true; - } - // If the second code point is an ident-start code point return true - if (isIdentStartCodePoint(reader.codePointSource[reader.cursor + 1])) { - return true; - } - // If the second and third code points are a valid escape return true - if (reader.codePointSource[reader.cursor + 1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) { - return true; - } - return false; - } - // ident-start code point - // Return true. - if (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) { - return true; - } - // U+005C REVERSE SOLIDUS (\) - return checkIfTwoCodePointsAreAValidEscape(ctx, reader); -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number -function checkIfThreeCodePointsWouldStartANumber(ctx, reader) { - if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { - // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) - // If the second code point is a digit, return true. - if (isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { - return true; - } - // Otherwise, if the second code point is a U+002E FULL STOP (.) - if (reader.codePointSource[reader.cursor + 1] === FULL_STOP) { - // and the third code point is a digit, return true. - return isDigitCodePoint(reader.codePointSource[reader.cursor + 2]); - } - // Otherwise, return false. - return false; - } else if (reader.codePointSource[reader.cursor] === FULL_STOP) { - // U+002E FULL STOP (.) - // If the second code point is a digit, return true. - // Otherwise, return false. - return isDigitCodePoint(reader.codePointSource[reader.cursor + 1]); - } else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { - // digit - // Return true. - return true; - } - // anything else - // Return false. - return false; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments -function checkIfTwoCodePointsStartAComment(ctx, reader) { - if (reader.codePointSource[reader.cursor] !== SOLIDUS) { - return false; - } - if (reader.codePointSource[reader.cursor + 1] !== ASTERISK) { - return false; - } - // Otherwise, return true. - return true; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token -function checkIfThreeCodePointsWouldStartCDC(ctx, reader) { - return reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment -function consumeComment(ctx, reader) { - reader.advanceCodePoint(2); - // eslint-disable-next-line no-constant-condition - while (true) { - const codePoint = reader.readCodePoint(); - if (codePoint === false) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a comment.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.2. Consume comments', 'Unexpected EOF'] - }); - break; - } - if (codePoint !== ASTERISK) { - continue; - } - if (reader.codePointSource[reader.cursor] === undefined) { - continue; - } - if (reader.codePointSource[reader.cursor] === SOLIDUS) { - reader.advanceCodePoint(); - break; - } - } - return [exports.TokenType.Comment, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point -function consumeEscapedCodePoint(ctx, reader) { - const codePoint = reader.readCodePoint(); - if (codePoint === false) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming an escaped code point.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.7. Consume an escaped code point', 'Unexpected EOF'] - }); - return REPLACEMENT_CHARACTER; - } - if (isHexDigitCodePoint(codePoint)) { - const hexSequence = [codePoint]; - while (reader.codePointSource[reader.cursor] !== undefined && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) { - hexSequence.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } - if (isWhitespace(reader.codePointSource[reader.cursor])) { - reader.advanceCodePoint(); - } - const codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16); - if (codePointLiteral === 0) { - return REPLACEMENT_CHARACTER; - } - if (isSurrogate(codePointLiteral)) { - return REPLACEMENT_CHARACTER; - } - if (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) { - return REPLACEMENT_CHARACTER; - } - return codePointLiteral; - } - return codePoint; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name -function consumeIdentSequence(ctx, reader) { - const result = []; - // eslint-disable-next-line no-constant-condition - while (true) { - if (isIdentCodePoint(reader.codePointSource[reader.cursor])) { - result.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - continue; - } - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - reader.advanceCodePoint(); - result.push(consumeEscapedCodePoint(ctx, reader)); - continue; - } - return result; - } -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token -function consumeHashToken(ctx, reader) { - reader.advanceCodePoint(); - if (reader.codePointSource[reader.cursor] !== undefined && isIdentCodePoint(reader.codePointSource[reader.cursor]) || checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - let hashType = HashType.Unrestricted; - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - hashType = HashType.ID; - } - const identSequence = consumeIdentSequence(ctx, reader); - return [exports.TokenType.Hash, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...identSequence), - type: hashType - }]; - } - return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '#' - }]; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number -function consumeNumber(ctx, reader) { - // 1. Initially set type to "integer". - // Let repr be the empty string. - let type = exports.NumberType.Integer; - const repr = []; - { - // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr. - if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { - repr.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } - // 3. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - { - // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then: - if (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { - // 4.2. Append them to repr. - repr.push(reader.codePointSource[reader.cursor]); - repr.push(reader.codePointSource[reader.cursor + 1]); - // 4.1. Consume them. - reader.advanceCodePoint(2); - // 4.3. Set type to "number". - type = exports.NumberType.Number; - // 4.4. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - } - { - // 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), - // optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+), - // followed by a digit, then: - if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { - // 5.2. Append them to repr. - repr.push(reader.codePointSource[reader.cursor]); - repr.push(reader.codePointSource[reader.cursor + 1]); - // 5.1. Consume them. - reader.advanceCodePoint(2); - // 5.3. Set type to "number". - type = exports.NumberType.Number; - // 5.4. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor + 1] === PLUS_SIGN) && isDigitCodePoint(reader.codePointSource[reader.cursor + 2])) { - // 5.2. Append them to repr. - repr.push(reader.codePointSource[reader.cursor]); - repr.push(reader.codePointSource[reader.cursor + 1]); - repr.push(reader.codePointSource[reader.cursor + 2]); - // 5.1. Consume them. - reader.advanceCodePoint(3); - // 5.3. Set type to "number". - type = exports.NumberType.Number; - // 5.4. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - } - // 6. Convert repr to a number, and set the value to the returned value. - const value = convertCodePointsToNumber(repr); - // 7. Return value and type. - return [value, type]; -} -function consumeDigits(reader) { - const value = []; - // eslint-disable-next-line no-constant-condition - while (true) { - if (reader.codePointSource[reader.cursor] === undefined) { - return value; - } - if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { - value.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } else { - return value; - } - } -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number -function convertCodePointsToNumber(codePoints) { - let s = 1; - const iCodePoints = []; - let i = 0; - let d = 0; - const fCodePoints = []; - let f = 0; - let t = 1; - const eCodePoints = []; - let e = 0; - let cursor = 0; - // 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. - // Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-); - // otherwise, let s be the number 1. - if (codePoints[cursor] === HYPHEN_MINUS) { - cursor++; - s = -1; - } else if (codePoints[cursor] === PLUS_SIGN) { - cursor++; - } - // 2. An integer part: zero or more digits. - // If there is at least one digit, - // let i be the number formed by interpreting the digits as a base-10 integer; - // otherwise, let i be the number 0. - while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { - iCodePoints.push(codePoints[cursor]); - cursor++; - } - i = digitCodePointsToInteger(iCodePoints); - // 3. A decimal point: a single U+002E FULL STOP (.), or the empty string. - if (codePoints[cursor] === FULL_STOP) { - cursor++; - } - // 4. A fractional part: zero or more digits. - // If there is at least one digit, - // let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits; - // otherwise, let f and d be the number 0. - while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { - fCodePoints.push(codePoints[cursor]); - cursor++; - } - d = fCodePoints.length; - f = digitCodePointsToInteger(fCodePoints) / Math.pow(10, d); - // 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string. - if (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) { - cursor++; - } - // 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. - // Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-); - // otherwise, let t be the number 1. - if (codePoints[cursor] === HYPHEN_MINUS) { - cursor++; - t = -1; - } else if (codePoints[cursor] === PLUS_SIGN) { - cursor++; - } - // 7. An exponent: zero or more digits. - // If there is at least one digit, - // let e be the number formed by interpreting the digits as a base-10 integer; - // otherwise, let e be the number 0. - while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { - eCodePoints.push(codePoints[cursor]); - cursor++; - } - e = digitCodePointsToInteger(eCodePoints); - // Return the number s·(i + f·10-d)·10te. - return s * (i + f) * Math.pow(10, t * e); -} -function digitCodePointsToInteger(codePoints) { - if (codePoints.length === 0) { - return 0; - } - return Number.parseInt(String.fromCharCode(...codePoints), 10); -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token -function consumeNumericToken(ctx, reader) { - const numberValue = consumeNumber(ctx, reader); - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - const unit = consumeIdentSequence(ctx, reader); - return [exports.TokenType.Dimension, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: numberValue[0], - type: numberValue[1], - unit: String.fromCharCode(...unit) - }]; - } - { - if (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) { - reader.advanceCodePoint(); - return [exports.TokenType.Percentage, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: numberValue[0] - }]; - } - } - return [exports.TokenType.Number, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: numberValue[0], - type: numberValue[1] - }]; -} - -function consumeWhiteSpace(ctx, reader) { - // eslint-disable-next-line no-constant-condition - while (true) { - if (!isWhitespace(reader.codePointSource[reader.cursor])) { - break; - } - reader.advanceCodePoint(); - } - return [exports.TokenType.Whitespace, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token -function consumeStringToken(ctx, reader) { - let result = ''; - const first = reader.readCodePoint(); - if (first === false) { - throw new Error('Unexpected EOF'); - } - // eslint-disable-next-line no-constant-condition - while (true) { - const next = reader.readCodePoint(); - if (next === false) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a string token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.5. Consume a string token', 'Unexpected EOF'] - }); - return [exports.TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: result - }]; - } - if (isNewLine(next)) { - { - ctx.onParseError({ - message: 'Unexpected newline while consuming a string token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.5. Consume a string token', 'Unexpected newline'] - }); - } - reader.unreadCodePoint(); - return [exports.TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (next === first) { - return [exports.TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: result - }]; - } - if (next === REVERSE_SOLIDUS) { - if (reader.codePointSource[reader.cursor] === undefined) { - continue; - } - if (isNewLine(reader.codePointSource[reader.cursor])) { - reader.advanceCodePoint(); - continue; - } - result += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); - continue; - } - result += String.fromCharCode(next); - } -} - -const u = 'u'.charCodeAt(0); -const U = 'U'.charCodeAt(0); -const r = 'r'.charCodeAt(0); -const R = 'R'.charCodeAt(0); -const l = 'l'.charCodeAt(0); -const L = 'L'.charCodeAt(0); -function checkIfCodePointsMatchURLIdent(ctx, codePoints) { - if (codePoints.length !== 3) { - return false; - } - if (codePoints[0] !== u && codePoints[0] !== U) { - return false; - } - if (codePoints[1] !== r && codePoints[1] !== R) { - return false; - } - if (codePoints[2] !== l && codePoints[2] !== L) { - return false; - } - return true; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url -function consumeBadURL(ctx, reader) { - // eslint-disable-next-line no-constant-condition - while (true) { - if (reader.codePointSource[reader.cursor] === undefined) { - return; - } - if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.advanceCodePoint(); - return; - } - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - reader.advanceCodePoint(); - consumeEscapedCodePoint(ctx, reader); - continue; - } - reader.advanceCodePoint(); - continue; - } -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token -function consumeUrlToken(ctx, reader) { - consumeWhiteSpace(ctx, reader); - let string = ''; - // eslint-disable-next-line no-constant-condition - while (true) { - if (reader.codePointSource[reader.cursor] === undefined) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'Unexpected EOF'] - }); - return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.advanceCodePoint(); - return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - if (isWhitespace(reader.codePointSource[reader.cursor])) { - consumeWhiteSpace(ctx, reader); - if (reader.codePointSource[reader.cursor] === undefined) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'Consume as much whitespace as possible', 'Unexpected EOF'] - }); - return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.advanceCodePoint(); - return [exports.TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - consumeBadURL(ctx, reader); - return [exports.TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) { - consumeBadURL(ctx, reader); - ctx.onParseError({ - message: 'Unexpected character while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'Unexpected U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE (\'), U+0028 LEFT PARENTHESIS (() or non-printable code point'] - }); - return [exports.TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) { - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - string += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); - continue; - } - consumeBadURL(ctx, reader); - ctx.onParseError({ - message: 'Invalid escape sequence while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] - }); - return [exports.TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - string += String.fromCharCode(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token -function consumeIdentLikeToken(ctx, reader) { - const codePoints = consumeIdentSequence(ctx, reader); - if (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) { - return [exports.TokenType.Ident, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...codePoints) - }]; - } - if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { - reader.advanceCodePoint(); - let read = 0; - // eslint-disable-next-line no-constant-condition - while (true) { - const firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]); - const secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor + 1]); - if (firstIsWhitespace && secondIsWhitespace) { - read += 2; - reader.advanceCodePoint(2); - continue; - } - const firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor + 1] : reader.codePointSource[reader.cursor]; - if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { - if (read > 0) { - reader.advanceCodePoint(read); - } - return [exports.TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...codePoints) - }]; - } - break; - } - if (read > 0) { - reader.advanceCodePoint(read); - } - return consumeUrlToken(ctx, reader); - } - reader.advanceCodePoint(); - return [exports.TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...codePoints) - }]; -} - -function tokenizer(input, options) { - const css = input.css.valueOf(); - const reader = new Reader(css); - const ctx = { - onParseError: (options == null ? void 0 : options.onParseError) ?? (() => {}) - }; - function endOfFile() { - return reader.codePointSource[reader.cursor] === undefined; - } - function nextToken() { - reader.resetRepresentation(); - if (checkIfTwoCodePointsStartAComment(ctx, reader)) { - if (options != null && options.commentsAreTokens) { - return consumeComment(ctx, reader); - } else { - consumeComment(ctx, reader); - reader.resetRepresentation(); - } - } - const peeked = reader.codePointSource[reader.cursor]; - if (peeked === undefined) { - return [exports.TokenType.EOF, '', -1, -1, undefined]; - } - if (isIdentStartCodePoint(peeked)) { - return consumeIdentLikeToken(ctx, reader); - } - // Simple, one character tokens: - switch (peeked) { - case COMMA: - { - reader.advanceCodePoint(); - return [exports.TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case COLON: - { - reader.advanceCodePoint(); - return [exports.TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case SEMICOLON: - { - reader.advanceCodePoint(); - return [exports.TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_PARENTHESIS: - { - reader.advanceCodePoint(); - return [exports.TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_PARENTHESIS: - { - reader.advanceCodePoint(); - return [exports.TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_SQUARE_BRACKET: - { - reader.advanceCodePoint(); - return [exports.TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_SQUARE_BRACKET: - { - reader.advanceCodePoint(); - return [exports.TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_CURLY_BRACKET: - { - reader.advanceCodePoint(); - return [exports.TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_CURLY_BRACKET: - { - reader.advanceCodePoint(); - return [exports.TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case APOSTROPHE: - case QUOTATION_MARK: - return consumeStringToken(ctx, reader); - case NUMBER_SIGN: - return consumeHashToken(ctx, reader); - case PLUS_SIGN: - case FULL_STOP: - { - if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { - return consumeNumericToken(ctx, reader); - } - reader.advanceCodePoint(); - return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: reader.representationString() - }]; - } - case DIGIT_0: - case DIGIT_1: - case DIGIT_2: - case DIGIT_3: - case DIGIT_4: - case DIGIT_5: - case DIGIT_6: - case DIGIT_7: - case DIGIT_8: - case DIGIT_9: - return consumeNumericToken(ctx, reader); - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - case CHARACTER_TABULATION: - case SPACE: - return consumeWhiteSpace(ctx, reader); - case HYPHEN_MINUS: - { - if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { - return consumeNumericToken(ctx, reader); - } - if (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) { - reader.advanceCodePoint(3); - return [exports.TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - return consumeIdentLikeToken(ctx, reader); - } - reader.advanceCodePoint(); - return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '-' - }]; - } - case LESS_THAN_SIGN: - { - if (checkIfFourCodePointsWouldStartCDO(ctx, reader)) { - reader.advanceCodePoint(4); - return [exports.TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - reader.advanceCodePoint(); - return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '<' - }]; - } - case COMMERCIAL_AT: - { - reader.advanceCodePoint(); - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - const identSequence = consumeIdentSequence(ctx, reader); - return [exports.TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...identSequence) - }]; - } - return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '@' - }]; - } - case REVERSE_SOLIDUS: - { - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - return consumeIdentLikeToken(ctx, reader); - } - reader.advanceCodePoint(); - ctx.onParseError({ - message: 'Invalid escape sequence after "\\"', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.1. Consume a token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] - }); - return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '\\' - }]; - } - } - reader.advanceCodePoint(); - return [exports.TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: reader.representationString() - }]; - } - return { - nextToken: nextToken, - endOfFile: endOfFile - }; -} - -function cloneTokens(tokens) { - if (typeof globalThis !== 'undefined' && 'structuredClone' in globalThis) { - return structuredClone(tokens); - } - return JSON.parse(JSON.stringify(tokens)); -} - -exports.Reader = Reader; -exports.cloneTokens = cloneTokens; -exports.isToken = isToken; -exports.mirrorVariantType = mirrorVariantType; -exports.stringify = stringify; -exports.tokenizer = tokenizer; -//# sourceMappingURL=index.cjs.map +"use strict";class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=[];for(let o=0;o=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===y)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case A:case i:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case A:case i:case S:case c:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,o){return o.codePointSource[o.cursor]===N&&o.codePointSource[o.cursor+1]!==A}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.codePointSource[o.cursor]===l?o.codePointSource[o.cursor+1]===l||(!!isIdentStartCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===N&&o.codePointSource[o.cursor+2]!==A):!!isIdentStartCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)}function checkIfThreeCodePointsWouldStartANumber(e,o){return o.codePointSource[o.cursor]===w||o.codePointSource[o.cursor]===l?!!isDigitCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===P&&isDigitCodePoint(o.codePointSource[o.cursor+2]):o.codePointSource[o.cursor]===P?isDigitCodePoint(o.codePointSource[o.cursor+1]):!!isDigitCodePoint(o.codePointSource[o.cursor])}function checkIfTwoCodePointsStartAComment(e,o){return o.codePointSource[o.cursor]===B&&o.codePointSource[o.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,o){return o.codePointSource[o.cursor]===l&&o.codePointSource[o.cursor+1]===l&&o.codePointSource[o.cursor+2]===h}function consumeComment(e,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(!1===t){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(t===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,o){const t=o.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:o.representationStart,end:o.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),L;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==o.codePointSource[o.cursor]&&isHexDigitCodePoint(o.codePointSource[o.cursor])&&e.length<6;)e.push(o.codePointSource[o.cursor]),o.advanceCodePoint();isWhitespace(o.codePointSource[o.cursor])&&o.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?L:X<=(r=n)&&r<=Y||n>I?L:n}var r;return t}function consumeIdentSequence(e,o){const t=[];for(;;)if(isIdentCodePoint(o.codePointSource[o.cursor]))t.push(o.codePointSource[o.cursor]),o.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,o))return t;o.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,o))}}function consumeHashToken(e,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=t.ID);const n=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n),type:r}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let t=exports.NumberType.Integer;const r=[];{o.codePointSource[o.cursor]!==w&&o.codePointSource[o.cursor]!==l||(r.push(o.codePointSource[o.cursor]),o.advanceCodePoint());const e=consumeDigits(o);for(let o=0;o0&&o.advanceCodePoint(n),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];break}return n>0&&o.advanceCodePoint(n),consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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.stringify=function stringify(...e){let o="";for(let t=0;t{})};return{nextToken:function nextToken(){if(n.representationStart=n.cursor,n.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,n)){if(null!=o&&o.commentsAreTokens)return consumeComment(s,n);consumeComment(s,n),n.representationStart=n.cursor,n.representationEnd=-1}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(s,n);if(isDigitCodePoint(e))return consumeNumericToken(s,n);switch(e){case d:return n.advanceCodePoint(),[exports.TokenType.Comma,",",n.representationStart,n.representationEnd,void 0];case a:return n.advanceCodePoint(),[exports.TokenType.Colon,":",n.representationStart,n.representationEnd,void 0];case F:return n.advanceCodePoint(),[exports.TokenType.Semicolon,";",n.representationStart,n.representationEnd,void 0];case E:return n.advanceCodePoint(),[exports.TokenType.OpenParen,"(",n.representationStart,n.representationEnd,void 0];case W:return n.advanceCodePoint(),[exports.TokenType.CloseParen,")",n.representationStart,n.representationEnd,void 0];case v:return n.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",n.representationStart,n.representationEnd,void 0];case q:return n.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",n.representationStart,n.representationEnd,void 0];case k:return n.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",n.representationStart,n.representationEnd,void 0];case R:return n.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",n.representationStart,n.representationEnd,void 0];case r:case b:return consumeStringToken(s,n);case U:return consumeHashToken(s,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]);case A:case i:case S:case c:case H:return consumeWhiteSpace(0,n);case l:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,"-",n.representationStart,n.representationEnd,{value:"-"}]);case g:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",n.representationStart,n.representationEnd,void 0]):(n.advanceCodePoint(),[exports.TokenType.Delim,"<",n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(s,n);return[exports.TokenType.AtKeyword,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,"@",n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),s.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,"\\",n.representationStart,n.representationEnd,{value:"\\"}])}return n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; diff --git a/packages/css-tokenizer/dist/index.cjs.map b/packages/css-tokenizer/dist/index.cjs.map deleted file mode 100644 index e79e0743a..000000000 --- a/packages/css-tokenizer/dist/index.cjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.cjs","sources":["../src/reader.ts","../src/interfaces/token.ts","../src/stringify.ts","../src/code-points/code-points.ts","../src/checks/four-code-points-would-start-cdo.ts","../src/code-points/ranges.ts","../src/checks/two-code-points-are-valid-escape.ts","../src/checks/three-code-points-would-start-ident-sequence.ts","../src/checks/three-code-points-would-start-number.ts","../src/checks/two-code-points-start-comment.ts","../src/checks/three-code-points-would-start-cdc.ts","../src/consume/comment.ts","../src/consume/escaped-code-point.ts","../src/consume/ident-sequence.ts","../src/consume/hash-token.ts","../src/consume/number.ts","../src/consume/numeric-token.ts","../src/consume/whitespace-token.ts","../src/consume/string-token.ts","../src/checks/matches-url-ident.ts","../src/consume/bad-url.ts","../src/consume/url-token.ts","../src/consume/ident-like-token.ts","../src/tokenizer.ts","../src/util/clone-tokens.ts"],"sourcesContent":["import { CodePointReader } from './interfaces/code-point-reader';\n\nexport class Reader implements CodePointReader {\n\tcursor: number;\n\tsource = '';\n\tcodePointSource: Array = [];\n\tlength = 0;\n\n\trepresentationStart = 0;\n\trepresentationEnd = -1;\n\n\tconstructor(source: string) {\n\t\tthis.cursor = 0;\n\t\tthis.source = source;\n\t\tthis.length = source.length;\n\n\t\tthis.codePointSource = new Array(this.length);\n\t\tfor (let i = 0; i < this.length; i++) {\n\t\t\tthis.codePointSource[i] = this.source.charCodeAt(i);\n\t\t}\n\t}\n\n\tcursorPositionOfLastReadCodePoint(): number {\n\t\treturn this.cursor - 1;\n\t}\n\n\tadvanceCodePoint(n = 1) {\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\t}\n\n\treadCodePoint(n = 1): number | false {\n\t\tconst codePoint = this.codePointSource[this.cursor];\n\t\tif (codePoint === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn codePoint;\n\t}\n\n\tunreadCodePoint(n = 1): boolean {\n\t\tif (this.cursor === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor -= n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn true;\n\t}\n\n\trepresentationString(): string {\n\t\treturn this.source.slice(this.representationStart, this.representationEnd + 1);\n\t}\n\n\tresetRepresentation() {\n\t\tthis.representationStart = this.cursor;\n\t\tthis.representationEnd = -1;\n\t}\n\n\tslice(start: number, end: number): string {\n\t\treturn this.source.slice(start, end);\n\t}\n}\n","export enum TokenType {\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */\n\tComment = 'comment',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */\n\tAtKeyword = 'at-keyword-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */\n\tBadString = 'bad-string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */\n\tBadURL = 'bad-url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */\n\tCDC = 'CDC-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */\n\tCDO = 'CDO-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */\n\tColon = 'colon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */\n\tComma = 'comma-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */\n\tDelim = 'delim-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */\n\tDimension = 'dimension-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */\n\tEOF = 'EOF-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */\n\tFunction = 'function-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */\n\tHash = 'hash-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */\n\tIdent = 'ident-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tNumber = 'number-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tPercentage = 'percentage-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */\n\tSemicolon = 'semicolon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */\n\tString = 'string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */\n\tURL = 'url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */\n\tWhitespace = 'whitespace-token',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */\n\tOpenParen = '(-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */\n\tCloseParen = ')-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */\n\tOpenSquare = '[-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */\n\tCloseSquare = ']-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */\n\tOpenCurly = '{-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */\n\tCloseCurly = '}-token',\n}\n\nexport enum NumberType {\n\tInteger = 'integer',\n\tNumber = 'number',\n}\n\nexport enum HashType {\n\tUnrestricted = 'unrestricted',\n\tID = 'id',\n}\n\nexport type TokenAtKeyword = Token;\nexport type TokenBadString = Token;\nexport type TokenBadURL = Token;\nexport type TokenCDC = Token;\nexport type TokenCDO = Token;\nexport type TokenColon = Token;\nexport type TokenComma = Token;\nexport type TokenComment = Token;\nexport type TokenDelim = Token;\nexport type TokenDimension = Token;\nexport type TokenEOF = Token;\nexport type TokenFunction = Token;\nexport type TokenHash = Token;\nexport type TokenIdent = Token;\nexport type TokenNumber = Token;\nexport type TokenPercentage = Token;\nexport type TokenSemicolon = Token;\nexport type TokenString = Token;\nexport type TokenURL = Token;\nexport type TokenWhitespace = Token;\n\nexport type TokenOpenParen = Token;\nexport type TokenCloseParen = Token;\nexport type TokenOpenSquare = Token;\nexport type TokenCloseSquare = Token;\nexport type TokenOpenCurly = Token;\nexport type TokenCloseCurly = Token;\n\nexport type CSSToken = TokenAtKeyword |\n\tTokenBadString |\n\tTokenBadURL |\n\tTokenCDC |\n\tTokenCDO |\n\tTokenColon |\n\tTokenComma |\n\tTokenComment |\n\tTokenDelim |\n\tTokenDimension |\n\tTokenEOF |\n\tTokenFunction |\n\tTokenHash |\n\tTokenIdent |\n\tTokenNumber |\n\tTokenPercentage |\n\tTokenSemicolon |\n\tTokenString |\n\tTokenURL |\n\tTokenWhitespace |\n\tTokenOpenParen |\n\tTokenCloseParen |\n\tTokenOpenSquare |\n\tTokenCloseSquare |\n\tTokenOpenCurly |\n\tTokenCloseCurly;\n\nexport type Token = [\n\t/** The type of token */\n\tT,\n\t/** The token representation */\n\tstring,\n\t/** Start position of representation */\n\tnumber,\n\t/** End position of representation */\n\tnumber,\n\t/** Extra data */\n\tU,\n]\n\nexport function mirrorVariantType(type: TokenType): TokenType|null {\n\tswitch (type) {\n\t\tcase TokenType.OpenParen:\n\t\t\treturn TokenType.CloseParen;\n\t\tcase TokenType.CloseParen:\n\t\t\treturn TokenType.OpenParen;\n\n\t\tcase TokenType.OpenCurly:\n\t\t\treturn TokenType.CloseCurly;\n\t\tcase TokenType.CloseCurly:\n\t\t\treturn TokenType.OpenCurly;\n\n\t\tcase TokenType.OpenSquare:\n\t\t\treturn TokenType.CloseSquare;\n\t\tcase TokenType.CloseSquare:\n\t\t\treturn TokenType.OpenSquare;\n\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToken(x: any): x is CSSToken {\n\tif (!Array.isArray(x)) {\n\t\treturn false;\n\t}\n\n\tif (x.length < 4) {\n\t\treturn false;\n\t}\n\n\tif (!(x[0] in TokenType)) {\n\t\treturn false;\n\t}\n\n\tif (typeof x[1] !== 'string') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[2] !== 'number') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[3] !== 'number') {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import type { CSSToken } from './interfaces/token';\n\nexport function stringify(...tokens: Array): string {\n\tlet buffer = '';\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tbuffer = buffer + tokens[i][1];\n\t}\n\n\treturn buffer;\n}\n","/** ' */\nexport const APOSTROPHE = '\\u{27}'.charCodeAt(0);\n/** * */\nexport const ASTERISK = '\\u{2a}'.charCodeAt(0);\n/** \\b */\nexport const BACKSPACE = '\\u{8}'.charCodeAt(0);\n/** \\r */\nexport const CARRIAGE_RETURN = '\\u{d}'.charCodeAt(0);\n/** \\t */\nexport const CHARACTER_TABULATION = '\\u{9}'.charCodeAt(0);\n/** : */\nexport const COLON = '\\u{3a}'.charCodeAt(0);\n/** , */\nexport const COMMA = '\\u{2c}'.charCodeAt(0);\n/** @ */\nexport const COMMERCIAL_AT = '\\u{40}'.charCodeAt(0);\n/** \\x7F */\nexport const DELETE = '\\u{7f}'.charCodeAt(0);\n/** ! */\nexport const EXCLAMATION_MARK = '\\u{21}'.charCodeAt(0);\n/** \\f */\nexport const FORM_FEED = '\\u{c}'.charCodeAt(0);\n/** . */\nexport const FULL_STOP = '\\u{2e}'.charCodeAt(0);\n/** > */\nexport const GREATER_THAN_SIGN = '\\u{3e}'.charCodeAt(0);\n/** - */\nexport const HYPHEN_MINUS = '\\u{2d}'.charCodeAt(0);\n/** \\x1F */\nexport const INFORMATION_SEPARATOR_ONE = '\\u{1f}'.charCodeAt(0);\n/** E */\nexport const LATIN_CAPITAL_LETTER_E = '\\u{45}'.charCodeAt(0);\n/** e */\nexport const LATIN_SMALL_LETTER_E = '\\u{65}'.charCodeAt(0);\n/** { */\nexport const LEFT_CURLY_BRACKET = '\\u{7b}'.charCodeAt(0);\n/** ( */\nexport const LEFT_PARENTHESIS = '\\u{28}'.charCodeAt(0);\n/** [ */\nexport const LEFT_SQUARE_BRACKET = '\\u{5b}'.charCodeAt(0);\n/** < */\nexport const LESS_THAN_SIGN = '\\u{3c}'.charCodeAt(0);\n/** \\n */\nexport const LINE_FEED = '\\u{a}'.charCodeAt(0);\n/** \\v */\nexport const LINE_TABULATION = '\\u{b}'.charCodeAt(0);\n/** _ */\nexport const LOW_LINE = '\\u{5f}'.charCodeAt(0);\n/** \\x10FFFF */\nexport const MAXIMUM_ALLOWED_CODEPOINT = '\\u{10FFFF}'.charCodeAt(0);\n/** \\x00 */\nexport const NULL = '\\u{0}'.charCodeAt(0);\n/** # */\nexport const NUMBER_SIGN = '\\u{23}'.charCodeAt(0);\n/** % */\nexport const PERCENTAGE_SIGN = '\\u{25}'.charCodeAt(0);\n/** + */\nexport const PLUS_SIGN = '\\u{2b}'.charCodeAt(0);\n/** \" */\nexport const QUOTATION_MARK = '\\u{22}'.charCodeAt(0);\n/** � */\nexport const REPLACEMENT_CHARACTER = '\\u{0FFFD}'.charCodeAt(0);\n/** \\ */\nexport const REVERSE_SOLIDUS = '\\u{5c}'.charCodeAt(0);\n/** } */\nexport const RIGHT_CURLY_BRACKET = '\\u{7d}'.charCodeAt(0);\n/** ) */\nexport const RIGHT_PARENTHESIS = '\\u{29}'.charCodeAt(0);\n/** ] */\nexport const RIGHT_SQUARE_BRACKET = '\\u{5d}'.charCodeAt(0);\n/** ; */\nexport const SEMICOLON = '\\u{3b}'.charCodeAt(0);\n/** \\u0E */\nexport const SHIFT_OUT = '\\u{e}'.charCodeAt(0);\n/** / */\nexport const SOLIDUS = '\\u{2f}'.charCodeAt(0);\n/** \\u20 */\nexport const SPACE = '\\u{20}'.charCodeAt(0);\n/** 0 */\nexport const DIGIT_0 = '\\u{30}'.charCodeAt(0);\n/** 1 */\nexport const DIGIT_1 = '\\u{31}'.charCodeAt(0);\n/** 2 */\nexport const DIGIT_2 = '\\u{32}'.charCodeAt(0);\n/** 3 */\nexport const DIGIT_3 = '\\u{33}'.charCodeAt(0);\n/** 4 */\nexport const DIGIT_4 = '\\u{34}'.charCodeAt(0);\n/** 5 */\nexport const DIGIT_5 = '\\u{35}'.charCodeAt(0);\n/** 6 */\nexport const DIGIT_6 = '\\u{36}'.charCodeAt(0);\n/** 7 */\nexport const DIGIT_7 = '\\u{37}'.charCodeAt(0);\n/** 8 */\nexport const DIGIT_8 = '\\u{38}'.charCodeAt(0);\n/** 9 */\nexport const DIGIT_9 = '\\u{39}'.charCodeAt(0);\n","import { EXCLAMATION_MARK, HYPHEN_MINUS, LESS_THAN_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfFourCodePointsWouldStartCDO(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor+1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+3] === HYPHEN_MINUS;\n}\n","import { BACKSPACE, DELETE, INFORMATION_SEPARATOR_ONE, LINE_TABULATION, LOW_LINE, HYPHEN_MINUS, NULL, SHIFT_OUT, LINE_FEED, CARRIAGE_RETURN, FORM_FEED, CHARACTER_TABULATION, SPACE } from './code-points';\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions\n\nconst digitsLow = '\\u{30}'.charCodeAt(0);\nconst digitsHigh = '\\u{39}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit\nexport function isDigitCodePoint(search: number): boolean {\n\treturn digitsLow <= search && search <= digitsHigh;\n}\n\nconst letterUppercaseLow = '\\u{41}'.charCodeAt(0);\nconst letterUppercaseHigh = '\\u{5a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter\nexport function isUppercaseLetterCodePoint(search: number): boolean {\n\treturn letterUppercaseLow <= search && search <= letterUppercaseHigh;\n}\n\nconst letterLowercaseLow = '\\u{61}'.charCodeAt(0);\nconst letterLowercaseHigh = '\\u{7a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter\nexport function isLowercaseLetterCodePoint(search: number): boolean {\n\treturn letterLowercaseLow <= search && search <= letterLowercaseHigh;\n}\n\nconst afUppercaseHigh = '\\u{46}'.charCodeAt(0);\nconst afLowercaseHigh = '\\u{66}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit\nexport function isHexDigitCodePoint(search: number): boolean {\n\tif (digitsLow <= search && search <= digitsHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterLowercaseLow <= search && search <= afLowercaseHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterUppercaseLow <= search && search <= afUppercaseHigh) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter\nexport function isLetterCodePoint(search: number): boolean {\n\treturn isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search);\n}\n\nconst nonASCIILow = '\\u{80}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point\nexport function isNonASCIICodePoint(search: number): boolean {\n\treturn search >= nonASCIILow;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point\nexport function isIdentStartCodePoint(search: number): boolean {\n\tif (isLetterCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isNonASCIICodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === LOW_LINE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point\nexport function isIdentCodePoint(search: number): boolean {\n\tif (isIdentStartCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isDigitCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === HYPHEN_MINUS;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point\nexport function isNonPrintableCodePoint(search: number): boolean {\n\tif (search === LINE_TABULATION) {\n\t\treturn true;\n\t}\n\n\tif (search === DELETE) {\n\t\treturn true;\n\t}\n\n\tif (NULL <= search && search <= BACKSPACE) {\n\t\treturn true;\n\t}\n\n\treturn SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isNewLine(search: number): boolean {\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\t\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t\t\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t\t\t// Applying the preprocessing rules would make it impossible to match the input.\n\t\t\t// A side effect of this is that our definition of whitespace is broader.\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isWhitespace(search: number): boolean {\n\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t// Applying the preprocessing rules would make it impossible to match the input.\n\t// A side effect of this is that our definition of whitespace is broader.\n\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\tcase CHARACTER_TABULATION:\n\t\tcase SPACE:\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nconst surrogateLow = '\\u{d800}'.charCodeAt(0);\nconst surrogateHigh = '\\u{dfff}'.charCodeAt(0);\n\n// https://infra.spec.whatwg.org/#surrogate\nexport function isSurrogate(search: number): boolean {\n\treturn surrogateLow <= search && search <= surrogateHigh;\n}\n","import { LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape\nexport function checkIfTwoCodePointsAreAValidEscape(ctx: Context, reader: CodePointReader): boolean {\n\t// If the first code point is not U+005C REVERSE SOLIDUS (\\), return false.\n\tif (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { // \"\\\"\n\t\treturn false;\n\t}\n\n\t// Otherwise, if the second code point is a newline, return false.\n\tif (reader.codePointSource[reader.cursor+1] === LINE_FEED) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { HYPHEN_MINUS, LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isIdentStartCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { checkIfTwoCodePointsAreAValidEscape } from './two-code-points-are-valid-escape';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier\nexport function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, reader: CodePointReader): boolean {\n\t// // U+002D HYPHEN-MINUS\n\tif (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t// If the second code point is a U+002D HYPHEN-MINUS return true\n\t\tif (reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second code point is an ident-start code point return true\n\t\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second and third code points are a valid escape return true\n\t\tif (reader.codePointSource[reader.cursor+1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t// ident-start code point\n\t// Return true.\n\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) {\n\t\treturn true;\n\t}\n\n\t// U+005C REVERSE SOLIDUS (\\)\n\treturn checkIfTwoCodePointsAreAValidEscape(ctx, reader);\n}\n","import { FULL_STOP, HYPHEN_MINUS, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number\nexport function checkIfThreeCodePointsWouldStartANumber(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-)\n\t\t// If the second code point is a digit, return true.\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Otherwise, if the second code point is a U+002E FULL STOP (.)\n\t\tif (reader.codePointSource[reader.cursor+1] === FULL_STOP) {\n\t\t\t// and the third code point is a digit, return true.\n\t\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+2]);\n\t\t}\n\n\t\t// Otherwise, return false.\n\t\treturn false;\n\n\t} else if (reader.codePointSource[reader.cursor] === FULL_STOP) { // U+002E FULL STOP (.)\n\t\t// If the second code point is a digit, return true.\n\t\t// Otherwise, return false.\n\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+1]);\n\n\t} else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { // digit\n\t\t// Return true.\n\t\treturn true;\n\t}\n\n\t// anything else\n\t// Return false.\n\treturn false;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments\nexport function checkIfTwoCodePointsStartAComment(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] !== SOLIDUS) {\n\t\treturn false;\n\t}\n\n\tif (reader.codePointSource[reader.cursor+1] !== ASTERISK) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { GREATER_THAN_SIGN, HYPHEN_MINUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfThreeCodePointsWouldStartCDC(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenComment, TokenType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment\nexport function consumeComment(ctx: Context, reader: CodePointReader): TokenComment {\n\treader.advanceCodePoint(2);\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst codePoint = reader.readCodePoint();\n\t\tif (codePoint === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a comment.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.2. Consume comments',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (codePoint !== ASTERISK) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === SOLIDUS) {\n\t\t\treader.advanceCodePoint();\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Comment,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { MAXIMUM_ALLOWED_CODEPOINT, REPLACEMENT_CHARACTER } from '../code-points/code-points';\nimport { isHexDigitCodePoint, isSurrogate, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point\nexport function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): number {\n\tconst codePoint = reader.readCodePoint();\n\tif (codePoint === false) {\n\t\tctx.onParseError({\n\t\t\tmessage: 'Unexpected EOF while consuming an escaped code point.',\n\t\t\tstart: reader.representationStart,\n\t\t\tend: reader.representationEnd,\n\t\t\tstate: [\n\t\t\t\t'4.3.7. Consume an escaped code point',\n\t\t\t\t'Unexpected EOF',\n\t\t\t],\n\t\t});\n\n\t\treturn REPLACEMENT_CHARACTER;\n\t}\n\n\tif (isHexDigitCodePoint(codePoint)) {\n\t\tconst hexSequence: Array = [codePoint];\n\n\t\twhile ((reader.codePointSource[reader.cursor] !== undefined) && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) {\n\t\t\thexSequence.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tconst codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16);\n\t\tif (codePointLiteral === 0) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (isSurrogate(codePointLiteral)) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\n\t\treturn codePointLiteral;\n\t}\n\n\treturn codePoint;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name\nexport function consumeIdentSequence(ctx: Context, reader: CodePointReader): Array {\n\tconst result: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (isIdentCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tresult.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tresult.push(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn result;\n\t}\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { HashType, TokenDelim, TokenHash, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDelim|TokenHash {\n\treader.advanceCodePoint();\n\n\tif (\n\t\t(reader.codePointSource[reader.cursor] !== undefined) &&\n\t\tisIdentCodePoint(reader.codePointSource[reader.cursor]) ||\n\t\tcheckIfTwoCodePointsAreAValidEscape(ctx, reader)\n\t) {\n\t\tlet hashType = HashType.Unrestricted;\n\n\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\thashType = HashType.ID;\n\t\t}\n\n\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\t\treturn [\n\t\t\tTokenType.Hash,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\ttype: hashType,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [\n\t\tTokenType.Delim,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: '#',\n\t\t},\n\t];\n}\n","import { FULL_STOP, HYPHEN_MINUS, LATIN_CAPITAL_LETTER_E, LATIN_SMALL_LETTER_E, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { NumberType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number\nexport function consumeNumber(ctx: Context, reader: CodePointReader): [number, NumberType] {\n\t// 1. Initially set type to \"integer\".\n\t// Let repr be the empty string.\n\tlet type = NumberType.Integer;\n\tconst repr: Array = [];\n\n\t{\n\t\t// 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr.\n\t\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\t// 3. While the next input code point is a digit, consume it and append it to repr.\n\t\tconst newPart = consumeDigits(reader);\n\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\trepr.push(newPart[i]);\n\t\t}\n\t}\n\n\t{\n\t\t// 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then:\n\t\tif (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\t// 4.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 4.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 4.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 4.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t{\n\t\t// 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e),\n\t\t// optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+),\n\t\t// followed by a digit, then:\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+1])\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\t(\n\t\t\t\t(reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor+1] === PLUS_SIGN) &&\n\t\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+2])\n\t\t\t)\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+2]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(3);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t// 6. Convert repr to a number, and set the value to the returned value.\n\tconst value = convertCodePointsToNumber(repr);\n\n\t// 7. Return value and type.\n\treturn [value, type];\n}\n\nfunction consumeDigits(reader: CodePointReader): Array {\n\tconst value: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn value;\n\t\t}\n\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tvalue.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number\nfunction convertCodePointsToNumber(codePoints: Array): number {\n\tlet s = 1;\n\tconst iCodePoints: Array = [];\n\tlet i = 0;\n\n\tlet d = 0;\n\tconst fCodePoints: Array = [];\n\tlet f = 0;\n\n\tlet t = 1;\n\n\tconst eCodePoints: Array = [];\n\tlet e = 0;\n\n\tlet cursor = 0;\n\n\t// 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let s be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\ts = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 2. An integer part: zero or more digits.\n\t// If there is at least one digit,\n\t// let i be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let i be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tiCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\ti = digitCodePointsToInteger(iCodePoints);\n\n\t// 3. A decimal point: a single U+002E FULL STOP (.), or the empty string.\n\tif (codePoints[cursor] === FULL_STOP) {\n\t\tcursor++;\n\t}\n\n\t// 4. A fractional part: zero or more digits.\n\t// If there is at least one digit,\n\t// let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits;\n\t// otherwise, let f and d be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tfCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\td = fCodePoints.length;\n\tf = (digitCodePointsToInteger(fCodePoints) / Math.pow(10, d));\n\n\t// 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string.\n\tif (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) {\n\t\tcursor++;\n\t}\n\n\t// 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let t be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\tt = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 7. An exponent: zero or more digits.\n\t// If there is at least one digit,\n\t// let e be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let e be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\teCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\te = digitCodePointsToInteger(eCodePoints);\n\n\t// Return the number s·(i + f·10-d)·10te.\n\treturn s * (i + f) * Math.pow(10, t * e);\n}\n\nfunction digitCodePointsToInteger(codePoints: Array): number {\n\tif (codePoints.length === 0) {\n\t\treturn 0;\n\t}\n\n\treturn Number.parseInt(String.fromCharCode(...codePoints), 10);\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { PERCENTAGE_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenDimension, TokenNumber, TokenPercentage, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeNumber } from './number';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token\nexport function consumeNumericToken(ctx: Context, reader: CodePointReader): TokenPercentage|TokenNumber|TokenDimension {\n\tconst numberValue = consumeNumber(ctx, reader);\n\n\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\tconst unit = consumeIdentSequence(ctx, reader);\n\n\t\treturn [\n\t\t\tTokenType.Dimension,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: numberValue[0],\n\t\t\t\ttype: numberValue[1],\n\t\t\t\tunit: String.fromCharCode(...unit),\n\t\t\t},\n\t\t];\n\t}\n\n\t{\n\t\tif (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) {\n\t\t\treader.advanceCodePoint();\n\n\t\t\treturn [\n\t\t\t\tTokenType.Percentage,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: numberValue[0],\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Number,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: numberValue[0],\n\t\t\ttype: numberValue[1],\n\t\t},\n\t];\n}\n","import { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenType, TokenWhitespace } from '../interfaces/token';\n\nexport function consumeWhiteSpace(ctx: Context, reader: CodePointReader): TokenWhitespace {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (!isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tbreak;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t}\n\n\treturn [\n\t\tTokenType.Whitespace,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isNewLine } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadString, TokenString, TokenType } from '../interfaces/token';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token\nexport function consumeStringToken(ctx: Context, reader: CodePointReader): TokenBadString|TokenString {\n\tlet result = '';\n\n\tconst first = reader.readCodePoint();\n\tif (first === false) {\n\t\tthrow new Error('Unexpected EOF');\n\t}\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst next = reader.readCodePoint();\n\t\tif (next === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a string token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (isNewLine(next)) {\n\t\t\t{\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected newline while consuming a string token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t\t'Unexpected newline',\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treader.unreadCodePoint();\n\t\t\treturn [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t}\n\n\t\tif (next === first) {\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (next === REVERSE_SOLIDUS) {\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isNewLine(reader.codePointSource[reader.cursor])) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tresult += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += String.fromCharCode(next);\n\t}\n}\n","import { Context } from '../interfaces/context';\n\nconst u = 'u'.charCodeAt(0);\nconst U = 'U'.charCodeAt(0);\nconst r = 'r'.charCodeAt(0);\nconst R = 'R'.charCodeAt(0);\nconst l = 'l'.charCodeAt(0);\nconst L = 'L'.charCodeAt(0);\n\nexport function checkIfCodePointsMatchURLIdent(ctx: Context, codePoints: Array): boolean {\n\tif (codePoints.length !== 3) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[0] !== u && codePoints[0] !== U) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[1] !== r && codePoints[1] !== R) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[2] !== l && codePoints[2] !== L) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url\nexport function consumeBadURL(ctx: Context, reader: CodePointReader) {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tconsumeEscapedCodePoint(ctx, reader);\n\t\t\tcontinue;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\tcontinue;\n\t}\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { isNonPrintableCodePoint, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeBadURL } from './bad-url';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\nimport { consumeWhiteSpace } from './whitespace-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token\nexport function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL|TokenBadURL {\n\tconsumeWhiteSpace(ctx, reader);\n\tlet string = '';\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeWhiteSpace(ctx, reader);\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t\t'Consume as much whitespace as possible',\n\t\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected character while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE (\\'), U+0028 LEFT PARENTHESIS (() or non-printable code point',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) {\n\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\tstring += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Invalid escape sequence while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tstring += String.fromCharCode(reader.codePointSource[reader.cursor]);\n\t\treader.advanceCodePoint();\n\t}\n}\n","import { checkIfCodePointsMatchURLIdent } from '../checks/matches-url-ident';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK } from '../code-points/code-points';\nimport { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenFunction, TokenIdent, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeUrlToken } from './url-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token\nexport function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): TokenIdent | TokenFunction | TokenURL | TokenBadURL {\n\tconst codePoints = consumeIdentSequence(ctx, reader);\n\n\tif (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) {\n\t\treturn [\n\t\t\tTokenType.Ident,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t},\n\t\t];\n\t}\n\n\tif (checkIfCodePointsMatchURLIdent(ctx, codePoints)) {\n\t\treader.advanceCodePoint();\n\n\t\tlet read = 0;\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]);\n\t\t\tconst secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor+1]);\n\t\t\tif (firstIsWhitespace && secondIsWhitespace) {\n\t\t\t\tread += 2;\n\t\t\t\treader.advanceCodePoint(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor+1] : reader.codePointSource[reader.cursor];\n\t\t\tif (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) {\n\t\t\t\tif (read > 0) {\n\t\t\t\t\treader.advanceCodePoint(read);\n\t\t\t\t}\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.Function,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (read > 0) {\n\t\t\treader.advanceCodePoint(read);\n\t\t}\n\n\t\treturn consumeUrlToken(ctx, reader);\n\t}\n\n\treader.advanceCodePoint();\n\treturn [\n\t\tTokenType.Function,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t},\n\t];\n}\n","import { checkIfFourCodePointsWouldStartCDO } from './checks/four-code-points-would-start-cdo';\nimport { checkIfThreeCodePointsWouldStartAnIdentSequence } from './checks/three-code-points-would-start-ident-sequence';\nimport { checkIfThreeCodePointsWouldStartANumber } from './checks/three-code-points-would-start-number';\nimport { checkIfTwoCodePointsStartAComment } from './checks/two-code-points-start-comment';\nimport { checkIfThreeCodePointsWouldStartCDC } from './checks/three-code-points-would-start-cdc';\nimport { APOSTROPHE, CARRIAGE_RETURN, CHARACTER_TABULATION, COLON, COMMA, COMMERCIAL_AT, DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9, FORM_FEED, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, LINE_FEED, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON, SPACE } from './code-points/code-points';\nimport { isIdentStartCodePoint } from './code-points/ranges';\nimport { consumeComment } from './consume/comment';\nimport { consumeHashToken } from './consume/hash-token';\nimport { consumeIdentSequence } from './consume/ident-sequence';\nimport { consumeNumericToken } from './consume/numeric-token';\nimport { consumeWhiteSpace } from './consume/whitespace-token';\nimport { CSSToken, TokenType } from './interfaces/token';\nimport { Reader } from './reader';\nimport { consumeStringToken } from './consume/string-token';\nimport { consumeIdentLikeToken } from './consume/ident-like-token';\nimport { checkIfTwoCodePointsAreAValidEscape } from './checks/two-code-points-are-valid-escape';\nimport { ParserError } from './interfaces/error';\n\ninterface Stringer {\n\tvalueOf(): string\n}\n\nexport function tokenizer(input: { css: Stringer }, options?: { commentsAreTokens?: boolean, onParseError?: (error: ParserError) => void }) {\n\tconst css = input.css.valueOf();\n\n\tconst reader = new Reader(css);\n\n\tconst ctx = {\n\t\tonParseError: options?.onParseError ?? (() => { /* noop */ }),\n\t};\n\n\tfunction endOfFile() {\n\t\treturn reader.codePointSource[reader.cursor] === undefined;\n\t}\n\n\tfunction nextToken(): CSSToken | undefined {\n\t\treader.resetRepresentation();\n\n\t\tif (checkIfTwoCodePointsStartAComment(ctx, reader)) {\n\t\t\tif (options?.commentsAreTokens) {\n\t\t\t\treturn consumeComment(ctx, reader);\n\t\t\t} else {\n\t\t\t\tconsumeComment(ctx, reader);\n\t\t\t\treader.resetRepresentation();\n\t\t\t}\n\t\t}\n\n\t\tconst peeked = reader.codePointSource[reader.cursor];\n\t\tif (peeked === undefined) {\n\t\t\treturn [TokenType.EOF, '', -1, -1, undefined];\n\t\t}\n\n\t\tif (isIdentStartCodePoint(peeked)) {\n\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t}\n\n\t\t// Simple, one character tokens:\n\t\tswitch (peeked) {\n\t\t\tcase COMMA: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase COLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase SEMICOLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase APOSTROPHE:\n\t\t\tcase QUOTATION_MARK:\n\t\t\t\treturn consumeStringToken(ctx, reader);\n\t\t\tcase NUMBER_SIGN:\n\t\t\t\treturn consumeHashToken(ctx, reader);\n\n\t\t\tcase PLUS_SIGN:\n\t\t\tcase FULL_STOP: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: reader.representationString(),\n\t\t\t\t}];\n\t\t\t}\n\t\t\tcase DIGIT_0:\n\t\t\tcase DIGIT_1:\n\t\t\tcase DIGIT_2:\n\t\t\tcase DIGIT_3:\n\t\t\tcase DIGIT_4:\n\t\t\tcase DIGIT_5:\n\t\t\tcase DIGIT_6:\n\t\t\tcase DIGIT_7:\n\t\t\tcase DIGIT_8:\n\t\t\tcase DIGIT_9:\n\t\t\t\treturn consumeNumericToken(ctx, reader);\n\n\t\t\tcase LINE_FEED:\n\t\t\tcase CARRIAGE_RETURN:\n\t\t\tcase FORM_FEED:\n\t\t\tcase CHARACTER_TABULATION:\n\t\t\tcase SPACE:\n\t\t\t\treturn consumeWhiteSpace(ctx, reader);\n\n\t\t\tcase HYPHEN_MINUS: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(3);\n\n\t\t\t\t\treturn [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '-',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase LESS_THAN_SIGN: {\n\t\t\t\tif (checkIfFourCodePointsWouldStartCDO(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(4);\n\n\t\t\t\t\treturn [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '<',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase COMMERCIAL_AT: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\n\t\t\t\t\treturn [TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\t\t}];\n\t\t\t\t}\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '@',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase REVERSE_SOLIDUS: {\n\t\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Invalid escape sequence after \"\\\\\"',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.1. Consume a token',\n\t\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '\\\\',\n\t\t\t\t}];\n\t\t\t}\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\tvalue: reader.representationString(),\n\t\t}];\n\t}\n\n\treturn {\n\t\tnextToken: nextToken,\n\t\tendOfFile: endOfFile,\n\t};\n}\n","import { CSSToken } from '../interfaces/token';\n\nexport function cloneTokens(tokens: Array): Array {\n\tif ((typeof globalThis !== 'undefined') && 'structuredClone' in globalThis) {\n\t\treturn structuredClone(tokens);\n\t}\n\n\treturn JSON.parse(JSON.stringify(tokens));\n}\n"],"names":["Reader","cursor","source","codePointSource","length","representationStart","representationEnd","constructor","Array","i","charCodeAt","cursorPositionOfLastReadCodePoint","advanceCodePoint","n","readCodePoint","codePoint","undefined","unreadCodePoint","representationString","slice","resetRepresentation","start","end","TokenType","NumberType","HashType","mirrorVariantType","type","OpenParen","CloseParen","OpenCurly","CloseCurly","OpenSquare","CloseSquare","isToken","x","isArray","stringify","tokens","buffer","APOSTROPHE","ASTERISK","BACKSPACE","CARRIAGE_RETURN","CHARACTER_TABULATION","COLON","COMMA","COMMERCIAL_AT","DELETE","EXCLAMATION_MARK","FORM_FEED","FULL_STOP","GREATER_THAN_SIGN","HYPHEN_MINUS","INFORMATION_SEPARATOR_ONE","LATIN_CAPITAL_LETTER_E","LATIN_SMALL_LETTER_E","LEFT_CURLY_BRACKET","LEFT_PARENTHESIS","LEFT_SQUARE_BRACKET","LESS_THAN_SIGN","LINE_FEED","LINE_TABULATION","LOW_LINE","MAXIMUM_ALLOWED_CODEPOINT","NULL","NUMBER_SIGN","PERCENTAGE_SIGN","PLUS_SIGN","QUOTATION_MARK","REPLACEMENT_CHARACTER","REVERSE_SOLIDUS","RIGHT_CURLY_BRACKET","RIGHT_PARENTHESIS","RIGHT_SQUARE_BRACKET","SEMICOLON","SHIFT_OUT","SOLIDUS","SPACE","DIGIT_0","DIGIT_1","DIGIT_2","DIGIT_3","DIGIT_4","DIGIT_5","DIGIT_6","DIGIT_7","DIGIT_8","DIGIT_9","checkIfFourCodePointsWouldStartCDO","ctx","reader","digitsLow","digitsHigh","isDigitCodePoint","search","letterUppercaseLow","letterUppercaseHigh","isUppercaseLetterCodePoint","letterLowercaseLow","letterLowercaseHigh","isLowercaseLetterCodePoint","afUppercaseHigh","afLowercaseHigh","isHexDigitCodePoint","isLetterCodePoint","nonASCIILow","isNonASCIICodePoint","isIdentStartCodePoint","isIdentCodePoint","isNonPrintableCodePoint","isNewLine","isWhitespace","surrogateLow","surrogateHigh","isSurrogate","checkIfTwoCodePointsAreAValidEscape","checkIfThreeCodePointsWouldStartAnIdentSequence","checkIfThreeCodePointsWouldStartANumber","checkIfTwoCodePointsStartAComment","checkIfThreeCodePointsWouldStartCDC","consumeComment","onParseError","message","state","Comment","consumeEscapedCodePoint","hexSequence","push","codePointLiteral","parseInt","String","fromCharCode","consumeIdentSequence","result","consumeHashToken","hashType","Unrestricted","ID","identSequence","Hash","value","Delim","consumeNumber","Integer","repr","newPart","consumeDigits","Number","convertCodePointsToNumber","codePoints","s","iCodePoints","d","fCodePoints","f","t","eCodePoints","e","digitCodePointsToInteger","Math","pow","consumeNumericToken","numberValue","unit","Dimension","Percentage","consumeWhiteSpace","Whitespace","consumeStringToken","first","Error","next","BadString","u","U","r","R","l","L","checkIfCodePointsMatchURLIdent","consumeBadURL","consumeUrlToken","string","URL","BadURL","consumeIdentLikeToken","Ident","read","firstIsWhitespace","secondIsWhitespace","firstNonWhitespace","Function","tokenizer","input","options","css","valueOf","endOfFile","nextToken","commentsAreTokens","peeked","EOF","Comma","Colon","Semicolon","CDC","CDO","AtKeyword","cloneTokens","globalThis","structuredClone","JSON","parse"],"mappings":";;MAEaA,MAAM,CAAA;EAClBC,MAAM,CAAA;AACNC,EAAAA,MAAM,GAAG,EAAE,CAAA;AACXC,EAAAA,eAAe,GAAkB,EAAE,CAAA;AACnCC,EAAAA,MAAM,GAAG,CAAC,CAAA;AAEVC,EAAAA,mBAAmB,GAAG,CAAC,CAAA;EACvBC,iBAAiB,GAAG,CAAC,CAAC,CAAA;EAEtBC,WAAA,CAAYL,MAAc,EAAA;IACzB,IAAI,CAACD,MAAM,GAAG,CAAC,CAAA;IACf,IAAI,CAACC,MAAM,GAAGA,MAAM,CAAA;AACpB,IAAA,IAAI,CAACE,MAAM,GAAGF,MAAM,CAACE,MAAM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6BAA6B,EAC7B,8DAA8D,CAAA;AAE/D,WAAA,CAAC,CAAA;AAEF,UAAA,OAAO,CAACrG,iBAAS,CAACuH,KAAK,EAAEnD,MAAM,CAACzE,oBAAoB,EAAE,EAAEyE,MAAM,CAACtF,mBAAmB,EAAEsF,MAAM,CAACrF,iBAAiB,EAAE;AAC7GuI,YAAAA,KAAK,EAAE,IAAA;AACP,WAAA,CAAC,CAAA;AACF,SAAA;AAAA,KAAA;IAGFlD,MAAM,CAAC/E,gBAAgB,EAAE,CAAA;AACzB,IAAA,OAAO,CAACW,iBAAS,CAACuH,KAAK,EAAEnD,MAAM,CAACzE,oBAAoB,EAAE,EAAEyE,MAAM,CAACtF,mBAAmB,EAAEsF,MAAM,CAACrF,iBAAiB,EAAE;MAC7GuI,KAAK,EAAElD,MAAM,CAACzE,oBAAoB,EAAA;AAClC,KAAA,CAAC,CAAA;AACH,GAAA;EAEA,OAAO;AACNqL,IAAAA,SAAS,EAAEA,SAAS;AACpBD,IAAAA,SAAS,EAAEA,SAAAA;GACX,CAAA;AACF;;ACpNM,SAAUW,WAAW,CAAC3K,MAAuB,EAAA;EAClD,IAAK,OAAO4K,UAAU,KAAK,WAAW,IAAK,iBAAiB,IAAIA,UAAU,EAAE;IAC3E,OAAOC,eAAe,CAAC7K,MAAM,CAAC,CAAA;AAC9B,GAAA;EAED,OAAO8K,IAAI,CAACC,KAAK,CAACD,IAAI,CAAC/K,SAAS,CAACC,MAAM,CAAC,CAAC,CAAA;AAC1C;;;;;;;;;"} \ No newline at end of file diff --git a/packages/css-tokenizer/dist/index.mjs b/packages/css-tokenizer/dist/index.mjs index c447ccb46..b4d9b4cac 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1,1174 +1 @@ -class Reader { - cursor; - source = ''; - codePointSource = []; - length = 0; - representationStart = 0; - representationEnd = -1; - constructor(source) { - this.cursor = 0; - this.source = source; - this.length = source.length; - this.codePointSource = new Array(this.length); - for (let i = 0; i < this.length; i++) { - this.codePointSource[i] = this.source.charCodeAt(i); - } - } - cursorPositionOfLastReadCodePoint() { - return this.cursor - 1; - } - advanceCodePoint(n = 1) { - this.cursor += n; - this.representationEnd = this.cursor - 1; - } - readCodePoint(n = 1) { - const codePoint = this.codePointSource[this.cursor]; - if (codePoint === undefined) { - return false; - } - this.cursor += n; - this.representationEnd = this.cursor - 1; - return codePoint; - } - unreadCodePoint(n = 1) { - if (this.cursor === 0) { - return false; - } - this.cursor -= n; - this.representationEnd = this.cursor - 1; - return true; - } - representationString() { - return this.source.slice(this.representationStart, this.representationEnd + 1); - } - resetRepresentation() { - this.representationStart = this.cursor; - this.representationEnd = -1; - } - slice(start, end) { - return this.source.slice(start, end); - } -} - -var TokenType; -(function (TokenType) { - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */ - TokenType["Comment"] = "comment"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */ - TokenType["AtKeyword"] = "at-keyword-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */ - TokenType["BadString"] = "bad-string-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */ - TokenType["BadURL"] = "bad-url-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */ - TokenType["CDC"] = "CDC-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */ - TokenType["CDO"] = "CDO-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */ - TokenType["Colon"] = "colon-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */ - TokenType["Comma"] = "comma-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */ - TokenType["Delim"] = "delim-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */ - TokenType["Dimension"] = "dimension-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */ - TokenType["EOF"] = "EOF-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */ - TokenType["Function"] = "function-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */ - TokenType["Hash"] = "hash-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */ - TokenType["Ident"] = "ident-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ - TokenType["Number"] = "number-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ - TokenType["Percentage"] = "percentage-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */ - TokenType["Semicolon"] = "semicolon-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */ - TokenType["String"] = "string-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */ - TokenType["URL"] = "url-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */ - TokenType["Whitespace"] = "whitespace-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */ - TokenType["OpenParen"] = "(-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */ - TokenType["CloseParen"] = ")-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */ - TokenType["OpenSquare"] = "[-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */ - TokenType["CloseSquare"] = "]-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */ - TokenType["OpenCurly"] = "{-token"; - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */ - TokenType["CloseCurly"] = "}-token"; -})(TokenType || (TokenType = {})); -var NumberType; -(function (NumberType) { - NumberType["Integer"] = "integer"; - NumberType["Number"] = "number"; -})(NumberType || (NumberType = {})); -var HashType; -(function (HashType) { - HashType["Unrestricted"] = "unrestricted"; - HashType["ID"] = "id"; -})(HashType || (HashType = {})); -function mirrorVariantType(type) { - switch (type) { - case TokenType.OpenParen: - return TokenType.CloseParen; - case TokenType.CloseParen: - return TokenType.OpenParen; - case TokenType.OpenCurly: - return TokenType.CloseCurly; - case TokenType.CloseCurly: - return TokenType.OpenCurly; - case TokenType.OpenSquare: - return TokenType.CloseSquare; - case TokenType.CloseSquare: - return TokenType.OpenSquare; - default: - return null; - } -} -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function isToken(x) { - if (!Array.isArray(x)) { - return false; - } - if (x.length < 4) { - return false; - } - if (!(x[0] in TokenType)) { - return false; - } - if (typeof x[1] !== 'string') { - return false; - } - if (typeof x[2] !== 'number') { - return false; - } - if (typeof x[3] !== 'number') { - return false; - } - return true; -} - -function stringify(...tokens) { - let buffer = ''; - for (let i = 0; i < tokens.length; i++) { - buffer = buffer + tokens[i][1]; - } - return buffer; -} - -/** ' */ -const APOSTROPHE = '\u{27}'.charCodeAt(0); -/** * */ -const ASTERISK = '\u{2a}'.charCodeAt(0); -/** \b */ -const BACKSPACE = '\u{8}'.charCodeAt(0); -/** \r */ -const CARRIAGE_RETURN = '\u{d}'.charCodeAt(0); -/** \t */ -const CHARACTER_TABULATION = '\u{9}'.charCodeAt(0); -/** : */ -const COLON = '\u{3a}'.charCodeAt(0); -/** , */ -const COMMA = '\u{2c}'.charCodeAt(0); -/** @ */ -const COMMERCIAL_AT = '\u{40}'.charCodeAt(0); -/** \x7F */ -const DELETE = '\u{7f}'.charCodeAt(0); -/** ! */ -const EXCLAMATION_MARK = '\u{21}'.charCodeAt(0); -/** \f */ -const FORM_FEED = '\u{c}'.charCodeAt(0); -/** . */ -const FULL_STOP = '\u{2e}'.charCodeAt(0); -/** > */ -const GREATER_THAN_SIGN = '\u{3e}'.charCodeAt(0); -/** - */ -const HYPHEN_MINUS = '\u{2d}'.charCodeAt(0); -/** \x1F */ -const INFORMATION_SEPARATOR_ONE = '\u{1f}'.charCodeAt(0); -/** E */ -const LATIN_CAPITAL_LETTER_E = '\u{45}'.charCodeAt(0); -/** e */ -const LATIN_SMALL_LETTER_E = '\u{65}'.charCodeAt(0); -/** { */ -const LEFT_CURLY_BRACKET = '\u{7b}'.charCodeAt(0); -/** ( */ -const LEFT_PARENTHESIS = '\u{28}'.charCodeAt(0); -/** [ */ -const LEFT_SQUARE_BRACKET = '\u{5b}'.charCodeAt(0); -/** < */ -const LESS_THAN_SIGN = '\u{3c}'.charCodeAt(0); -/** \n */ -const LINE_FEED = '\u{a}'.charCodeAt(0); -/** \v */ -const LINE_TABULATION = '\u{b}'.charCodeAt(0); -/** _ */ -const LOW_LINE = '\u{5f}'.charCodeAt(0); -/** \x10FFFF */ -const MAXIMUM_ALLOWED_CODEPOINT = '\u{10FFFF}'.charCodeAt(0); -/** \x00 */ -const NULL = '\u{0}'.charCodeAt(0); -/** # */ -const NUMBER_SIGN = '\u{23}'.charCodeAt(0); -/** % */ -const PERCENTAGE_SIGN = '\u{25}'.charCodeAt(0); -/** + */ -const PLUS_SIGN = '\u{2b}'.charCodeAt(0); -/** " */ -const QUOTATION_MARK = '\u{22}'.charCodeAt(0); -/** � */ -const REPLACEMENT_CHARACTER = '\u{0FFFD}'.charCodeAt(0); -/** \ */ -const REVERSE_SOLIDUS = '\u{5c}'.charCodeAt(0); -/** } */ -const RIGHT_CURLY_BRACKET = '\u{7d}'.charCodeAt(0); -/** ) */ -const RIGHT_PARENTHESIS = '\u{29}'.charCodeAt(0); -/** ] */ -const RIGHT_SQUARE_BRACKET = '\u{5d}'.charCodeAt(0); -/** ; */ -const SEMICOLON = '\u{3b}'.charCodeAt(0); -/** \u0E */ -const SHIFT_OUT = '\u{e}'.charCodeAt(0); -/** / */ -const SOLIDUS = '\u{2f}'.charCodeAt(0); -/** \u20 */ -const SPACE = '\u{20}'.charCodeAt(0); -/** 0 */ -const DIGIT_0 = '\u{30}'.charCodeAt(0); -/** 1 */ -const DIGIT_1 = '\u{31}'.charCodeAt(0); -/** 2 */ -const DIGIT_2 = '\u{32}'.charCodeAt(0); -/** 3 */ -const DIGIT_3 = '\u{33}'.charCodeAt(0); -/** 4 */ -const DIGIT_4 = '\u{34}'.charCodeAt(0); -/** 5 */ -const DIGIT_5 = '\u{35}'.charCodeAt(0); -/** 6 */ -const DIGIT_6 = '\u{36}'.charCodeAt(0); -/** 7 */ -const DIGIT_7 = '\u{37}'.charCodeAt(0); -/** 8 */ -const DIGIT_8 = '\u{38}'.charCodeAt(0); -/** 9 */ -const DIGIT_9 = '\u{39}'.charCodeAt(0); - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token -function checkIfFourCodePointsWouldStartCDO(ctx, reader) { - return reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor + 1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 3] === HYPHEN_MINUS; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions -const digitsLow = '\u{30}'.charCodeAt(0); -const digitsHigh = '\u{39}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit -function isDigitCodePoint(search) { - return digitsLow <= search && search <= digitsHigh; -} -const letterUppercaseLow = '\u{41}'.charCodeAt(0); -const letterUppercaseHigh = '\u{5a}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter -function isUppercaseLetterCodePoint(search) { - return letterUppercaseLow <= search && search <= letterUppercaseHigh; -} -const letterLowercaseLow = '\u{61}'.charCodeAt(0); -const letterLowercaseHigh = '\u{7a}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter -function isLowercaseLetterCodePoint(search) { - return letterLowercaseLow <= search && search <= letterLowercaseHigh; -} -const afUppercaseHigh = '\u{46}'.charCodeAt(0); -const afLowercaseHigh = '\u{66}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit -function isHexDigitCodePoint(search) { - if (digitsLow <= search && search <= digitsHigh) { - return true; - } - if (letterLowercaseLow <= search && search <= afLowercaseHigh) { - return true; - } - if (letterUppercaseLow <= search && search <= afUppercaseHigh) { - return true; - } - return false; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter -function isLetterCodePoint(search) { - return isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search); -} -const nonASCIILow = '\u{80}'.charCodeAt(0); -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point -function isNonASCIICodePoint(search) { - return search >= nonASCIILow; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point -function isIdentStartCodePoint(search) { - if (isLetterCodePoint(search)) { - return true; - } - if (isNonASCIICodePoint(search)) { - return true; - } - return search === LOW_LINE; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point -function isIdentCodePoint(search) { - if (isIdentStartCodePoint(search)) { - return true; - } - if (isDigitCodePoint(search)) { - return true; - } - return search === HYPHEN_MINUS; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point -function isNonPrintableCodePoint(search) { - if (search === LINE_TABULATION) { - return true; - } - if (search === DELETE) { - return true; - } - if (NULL <= search && search <= BACKSPACE) { - return true; - } - return SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE; -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace -function isNewLine(search) { - switch (search) { - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing - // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. - // Applying the preprocessing rules would make it impossible to match the input. - // A side effect of this is that our definition of whitespace is broader. - return true; - default: - return false; - } -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace -function isWhitespace(search) { - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing - // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. - // Applying the preprocessing rules would make it impossible to match the input. - // A side effect of this is that our definition of whitespace is broader. - switch (search) { - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - case CHARACTER_TABULATION: - case SPACE: - return true; - default: - return false; - } -} -const surrogateLow = '\u{d800}'.charCodeAt(0); -const surrogateHigh = '\u{dfff}'.charCodeAt(0); -// https://infra.spec.whatwg.org/#surrogate -function isSurrogate(search) { - return surrogateLow <= search && search <= surrogateHigh; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape -function checkIfTwoCodePointsAreAValidEscape(ctx, reader) { - // If the first code point is not U+005C REVERSE SOLIDUS (\), return false. - if (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { - // "\" - return false; - } - // Otherwise, if the second code point is a newline, return false. - if (reader.codePointSource[reader.cursor + 1] === LINE_FEED) { - return false; - } - // Otherwise, return true. - return true; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier -function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader) { - // // U+002D HYPHEN-MINUS - if (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { - // If the second code point is a U+002D HYPHEN-MINUS return true - if (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS) { - return true; - } - // If the second code point is an ident-start code point return true - if (isIdentStartCodePoint(reader.codePointSource[reader.cursor + 1])) { - return true; - } - // If the second and third code points are a valid escape return true - if (reader.codePointSource[reader.cursor + 1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) { - return true; - } - return false; - } - // ident-start code point - // Return true. - if (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) { - return true; - } - // U+005C REVERSE SOLIDUS (\) - return checkIfTwoCodePointsAreAValidEscape(ctx, reader); -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number -function checkIfThreeCodePointsWouldStartANumber(ctx, reader) { - if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { - // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-) - // If the second code point is a digit, return true. - if (isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { - return true; - } - // Otherwise, if the second code point is a U+002E FULL STOP (.) - if (reader.codePointSource[reader.cursor + 1] === FULL_STOP) { - // and the third code point is a digit, return true. - return isDigitCodePoint(reader.codePointSource[reader.cursor + 2]); - } - // Otherwise, return false. - return false; - } else if (reader.codePointSource[reader.cursor] === FULL_STOP) { - // U+002E FULL STOP (.) - // If the second code point is a digit, return true. - // Otherwise, return false. - return isDigitCodePoint(reader.codePointSource[reader.cursor + 1]); - } else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { - // digit - // Return true. - return true; - } - // anything else - // Return false. - return false; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments -function checkIfTwoCodePointsStartAComment(ctx, reader) { - if (reader.codePointSource[reader.cursor] !== SOLIDUS) { - return false; - } - if (reader.codePointSource[reader.cursor + 1] !== ASTERISK) { - return false; - } - // Otherwise, return true. - return true; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token -function checkIfThreeCodePointsWouldStartCDC(ctx, reader) { - return reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment -function consumeComment(ctx, reader) { - reader.advanceCodePoint(2); - // eslint-disable-next-line no-constant-condition - while (true) { - const codePoint = reader.readCodePoint(); - if (codePoint === false) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a comment.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.2. Consume comments', 'Unexpected EOF'] - }); - break; - } - if (codePoint !== ASTERISK) { - continue; - } - if (reader.codePointSource[reader.cursor] === undefined) { - continue; - } - if (reader.codePointSource[reader.cursor] === SOLIDUS) { - reader.advanceCodePoint(); - break; - } - } - return [TokenType.Comment, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point -function consumeEscapedCodePoint(ctx, reader) { - const codePoint = reader.readCodePoint(); - if (codePoint === false) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming an escaped code point.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.7. Consume an escaped code point', 'Unexpected EOF'] - }); - return REPLACEMENT_CHARACTER; - } - if (isHexDigitCodePoint(codePoint)) { - const hexSequence = [codePoint]; - while (reader.codePointSource[reader.cursor] !== undefined && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) { - hexSequence.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } - if (isWhitespace(reader.codePointSource[reader.cursor])) { - reader.advanceCodePoint(); - } - const codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16); - if (codePointLiteral === 0) { - return REPLACEMENT_CHARACTER; - } - if (isSurrogate(codePointLiteral)) { - return REPLACEMENT_CHARACTER; - } - if (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) { - return REPLACEMENT_CHARACTER; - } - return codePointLiteral; - } - return codePoint; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name -function consumeIdentSequence(ctx, reader) { - const result = []; - // eslint-disable-next-line no-constant-condition - while (true) { - if (isIdentCodePoint(reader.codePointSource[reader.cursor])) { - result.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - continue; - } - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - reader.advanceCodePoint(); - result.push(consumeEscapedCodePoint(ctx, reader)); - continue; - } - return result; - } -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token -function consumeHashToken(ctx, reader) { - reader.advanceCodePoint(); - if (reader.codePointSource[reader.cursor] !== undefined && isIdentCodePoint(reader.codePointSource[reader.cursor]) || checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - let hashType = HashType.Unrestricted; - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - hashType = HashType.ID; - } - const identSequence = consumeIdentSequence(ctx, reader); - return [TokenType.Hash, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...identSequence), - type: hashType - }]; - } - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '#' - }]; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number -function consumeNumber(ctx, reader) { - // 1. Initially set type to "integer". - // Let repr be the empty string. - let type = NumberType.Integer; - const repr = []; - { - // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr. - if (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { - repr.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } - // 3. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - { - // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then: - if (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { - // 4.2. Append them to repr. - repr.push(reader.codePointSource[reader.cursor]); - repr.push(reader.codePointSource[reader.cursor + 1]); - // 4.1. Consume them. - reader.advanceCodePoint(2); - // 4.3. Set type to "number". - type = NumberType.Number; - // 4.4. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - } - { - // 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), - // optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+), - // followed by a digit, then: - if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && isDigitCodePoint(reader.codePointSource[reader.cursor + 1])) { - // 5.2. Append them to repr. - repr.push(reader.codePointSource[reader.cursor]); - repr.push(reader.codePointSource[reader.cursor + 1]); - // 5.1. Consume them. - reader.advanceCodePoint(2); - // 5.3. Set type to "number". - type = NumberType.Number; - // 5.4. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - if ((reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) && (reader.codePointSource[reader.cursor + 1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor + 1] === PLUS_SIGN) && isDigitCodePoint(reader.codePointSource[reader.cursor + 2])) { - // 5.2. Append them to repr. - repr.push(reader.codePointSource[reader.cursor]); - repr.push(reader.codePointSource[reader.cursor + 1]); - repr.push(reader.codePointSource[reader.cursor + 2]); - // 5.1. Consume them. - reader.advanceCodePoint(3); - // 5.3. Set type to "number". - type = NumberType.Number; - // 5.4. While the next input code point is a digit, consume it and append it to repr. - const newPart = consumeDigits(reader); - for (let i = 0; i < newPart.length; i++) { - repr.push(newPart[i]); - } - } - } - // 6. Convert repr to a number, and set the value to the returned value. - const value = convertCodePointsToNumber(repr); - // 7. Return value and type. - return [value, type]; -} -function consumeDigits(reader) { - const value = []; - // eslint-disable-next-line no-constant-condition - while (true) { - if (reader.codePointSource[reader.cursor] === undefined) { - return value; - } - if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { - value.push(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } else { - return value; - } - } -} -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number -function convertCodePointsToNumber(codePoints) { - let s = 1; - const iCodePoints = []; - let i = 0; - let d = 0; - const fCodePoints = []; - let f = 0; - let t = 1; - const eCodePoints = []; - let e = 0; - let cursor = 0; - // 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. - // Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-); - // otherwise, let s be the number 1. - if (codePoints[cursor] === HYPHEN_MINUS) { - cursor++; - s = -1; - } else if (codePoints[cursor] === PLUS_SIGN) { - cursor++; - } - // 2. An integer part: zero or more digits. - // If there is at least one digit, - // let i be the number formed by interpreting the digits as a base-10 integer; - // otherwise, let i be the number 0. - while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { - iCodePoints.push(codePoints[cursor]); - cursor++; - } - i = digitCodePointsToInteger(iCodePoints); - // 3. A decimal point: a single U+002E FULL STOP (.), or the empty string. - if (codePoints[cursor] === FULL_STOP) { - cursor++; - } - // 4. A fractional part: zero or more digits. - // If there is at least one digit, - // let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits; - // otherwise, let f and d be the number 0. - while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { - fCodePoints.push(codePoints[cursor]); - cursor++; - } - d = fCodePoints.length; - f = digitCodePointsToInteger(fCodePoints) / Math.pow(10, d); - // 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string. - if (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) { - cursor++; - } - // 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string. - // Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-); - // otherwise, let t be the number 1. - if (codePoints[cursor] === HYPHEN_MINUS) { - cursor++; - t = -1; - } else if (codePoints[cursor] === PLUS_SIGN) { - cursor++; - } - // 7. An exponent: zero or more digits. - // If there is at least one digit, - // let e be the number formed by interpreting the digits as a base-10 integer; - // otherwise, let e be the number 0. - while (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) { - eCodePoints.push(codePoints[cursor]); - cursor++; - } - e = digitCodePointsToInteger(eCodePoints); - // Return the number s·(i + f·10-d)·10te. - return s * (i + f) * Math.pow(10, t * e); -} -function digitCodePointsToInteger(codePoints) { - if (codePoints.length === 0) { - return 0; - } - return Number.parseInt(String.fromCharCode(...codePoints), 10); -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token -function consumeNumericToken(ctx, reader) { - const numberValue = consumeNumber(ctx, reader); - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - const unit = consumeIdentSequence(ctx, reader); - return [TokenType.Dimension, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: numberValue[0], - type: numberValue[1], - unit: String.fromCharCode(...unit) - }]; - } - { - if (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) { - reader.advanceCodePoint(); - return [TokenType.Percentage, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: numberValue[0] - }]; - } - } - return [TokenType.Number, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: numberValue[0], - type: numberValue[1] - }]; -} - -function consumeWhiteSpace(ctx, reader) { - // eslint-disable-next-line no-constant-condition - while (true) { - if (!isWhitespace(reader.codePointSource[reader.cursor])) { - break; - } - reader.advanceCodePoint(); - } - return [TokenType.Whitespace, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token -function consumeStringToken(ctx, reader) { - let result = ''; - const first = reader.readCodePoint(); - if (first === false) { - throw new Error('Unexpected EOF'); - } - // eslint-disable-next-line no-constant-condition - while (true) { - const next = reader.readCodePoint(); - if (next === false) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a string token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.5. Consume a string token', 'Unexpected EOF'] - }); - return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: result - }]; - } - if (isNewLine(next)) { - { - ctx.onParseError({ - message: 'Unexpected newline while consuming a string token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.5. Consume a string token', 'Unexpected newline'] - }); - } - reader.unreadCodePoint(); - return [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (next === first) { - return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: result - }]; - } - if (next === REVERSE_SOLIDUS) { - if (reader.codePointSource[reader.cursor] === undefined) { - continue; - } - if (isNewLine(reader.codePointSource[reader.cursor])) { - reader.advanceCodePoint(); - continue; - } - result += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); - continue; - } - result += String.fromCharCode(next); - } -} - -const u = 'u'.charCodeAt(0); -const U = 'U'.charCodeAt(0); -const r = 'r'.charCodeAt(0); -const R = 'R'.charCodeAt(0); -const l = 'l'.charCodeAt(0); -const L = 'L'.charCodeAt(0); -function checkIfCodePointsMatchURLIdent(ctx, codePoints) { - if (codePoints.length !== 3) { - return false; - } - if (codePoints[0] !== u && codePoints[0] !== U) { - return false; - } - if (codePoints[1] !== r && codePoints[1] !== R) { - return false; - } - if (codePoints[2] !== l && codePoints[2] !== L) { - return false; - } - return true; -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url -function consumeBadURL(ctx, reader) { - // eslint-disable-next-line no-constant-condition - while (true) { - if (reader.codePointSource[reader.cursor] === undefined) { - return; - } - if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.advanceCodePoint(); - return; - } - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - reader.advanceCodePoint(); - consumeEscapedCodePoint(ctx, reader); - continue; - } - reader.advanceCodePoint(); - continue; - } -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token -function consumeUrlToken(ctx, reader) { - consumeWhiteSpace(ctx, reader); - let string = ''; - // eslint-disable-next-line no-constant-condition - while (true) { - if (reader.codePointSource[reader.cursor] === undefined) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'Unexpected EOF'] - }); - return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.advanceCodePoint(); - return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - if (isWhitespace(reader.codePointSource[reader.cursor])) { - consumeWhiteSpace(ctx, reader); - if (reader.codePointSource[reader.cursor] === undefined) { - ctx.onParseError({ - message: 'Unexpected EOF while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'Consume as much whitespace as possible', 'Unexpected EOF'] - }); - return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - if (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) { - reader.advanceCodePoint(); - return [TokenType.URL, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: string - }]; - } - consumeBadURL(ctx, reader); - return [TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) { - consumeBadURL(ctx, reader); - ctx.onParseError({ - message: 'Unexpected character while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'Unexpected U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE (\'), U+0028 LEFT PARENTHESIS (() or non-printable code point'] - }); - return [TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) { - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - string += String.fromCharCode(consumeEscapedCodePoint(ctx, reader)); - continue; - } - consumeBadURL(ctx, reader); - ctx.onParseError({ - message: 'Invalid escape sequence while consuming a url token.', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.6. Consume a url token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] - }); - return [TokenType.BadURL, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - string += String.fromCharCode(reader.codePointSource[reader.cursor]); - reader.advanceCodePoint(); - } -} - -// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token -function consumeIdentLikeToken(ctx, reader) { - const codePoints = consumeIdentSequence(ctx, reader); - if (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) { - return [TokenType.Ident, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...codePoints) - }]; - } - if (checkIfCodePointsMatchURLIdent(ctx, codePoints)) { - reader.advanceCodePoint(); - let read = 0; - // eslint-disable-next-line no-constant-condition - while (true) { - const firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]); - const secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor + 1]); - if (firstIsWhitespace && secondIsWhitespace) { - read += 2; - reader.advanceCodePoint(2); - continue; - } - const firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor + 1] : reader.codePointSource[reader.cursor]; - if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { - if (read > 0) { - reader.advanceCodePoint(read); - } - return [TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...codePoints) - }]; - } - break; - } - if (read > 0) { - reader.advanceCodePoint(read); - } - return consumeUrlToken(ctx, reader); - } - reader.advanceCodePoint(); - return [TokenType.Function, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...codePoints) - }]; -} - -function tokenizer(input, options) { - const css = input.css.valueOf(); - const reader = new Reader(css); - const ctx = { - onParseError: (options == null ? void 0 : options.onParseError) ?? (() => {}) - }; - function endOfFile() { - return reader.codePointSource[reader.cursor] === undefined; - } - function nextToken() { - reader.resetRepresentation(); - if (checkIfTwoCodePointsStartAComment(ctx, reader)) { - if (options != null && options.commentsAreTokens) { - return consumeComment(ctx, reader); - } else { - consumeComment(ctx, reader); - reader.resetRepresentation(); - } - } - const peeked = reader.codePointSource[reader.cursor]; - if (peeked === undefined) { - return [TokenType.EOF, '', -1, -1, undefined]; - } - if (isIdentStartCodePoint(peeked)) { - return consumeIdentLikeToken(ctx, reader); - } - // Simple, one character tokens: - switch (peeked) { - case COMMA: - { - reader.advanceCodePoint(); - return [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case COLON: - { - reader.advanceCodePoint(); - return [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case SEMICOLON: - { - reader.advanceCodePoint(); - return [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_PARENTHESIS: - { - reader.advanceCodePoint(); - return [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_PARENTHESIS: - { - reader.advanceCodePoint(); - return [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_SQUARE_BRACKET: - { - reader.advanceCodePoint(); - return [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_SQUARE_BRACKET: - { - reader.advanceCodePoint(); - return [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_CURLY_BRACKET: - { - reader.advanceCodePoint(); - return [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_CURLY_BRACKET: - { - reader.advanceCodePoint(); - return [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case APOSTROPHE: - case QUOTATION_MARK: - return consumeStringToken(ctx, reader); - case NUMBER_SIGN: - return consumeHashToken(ctx, reader); - case PLUS_SIGN: - case FULL_STOP: - { - if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { - return consumeNumericToken(ctx, reader); - } - reader.advanceCodePoint(); - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: reader.representationString() - }]; - } - case DIGIT_0: - case DIGIT_1: - case DIGIT_2: - case DIGIT_3: - case DIGIT_4: - case DIGIT_5: - case DIGIT_6: - case DIGIT_7: - case DIGIT_8: - case DIGIT_9: - return consumeNumericToken(ctx, reader); - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - case CHARACTER_TABULATION: - case SPACE: - return consumeWhiteSpace(ctx, reader); - case HYPHEN_MINUS: - { - if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { - return consumeNumericToken(ctx, reader); - } - if (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) { - reader.advanceCodePoint(3); - return [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - return consumeIdentLikeToken(ctx, reader); - } - reader.advanceCodePoint(); - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '-' - }]; - } - case LESS_THAN_SIGN: - { - if (checkIfFourCodePointsWouldStartCDO(ctx, reader)) { - reader.advanceCodePoint(4); - return [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - reader.advanceCodePoint(); - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '<' - }]; - } - case COMMERCIAL_AT: - { - reader.advanceCodePoint(); - if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { - const identSequence = consumeIdentSequence(ctx, reader); - return [TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: String.fromCharCode(...identSequence) - }]; - } - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '@' - }]; - } - case REVERSE_SOLIDUS: - { - if (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) { - return consumeIdentLikeToken(ctx, reader); - } - reader.advanceCodePoint(); - ctx.onParseError({ - message: 'Invalid escape sequence after "\\"', - start: reader.representationStart, - end: reader.representationEnd, - state: ['4.3.1. Consume a token', 'U+005C REVERSE SOLIDUS (\\)', 'The input stream does not start with a valid escape sequence'] - }); - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: '\\' - }]; - } - } - reader.advanceCodePoint(); - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: reader.representationString() - }]; - } - return { - nextToken: nextToken, - endOfFile: endOfFile - }; -} - -function cloneTokens(tokens) { - if (typeof globalThis !== 'undefined' && 'structuredClone' in globalThis) { - return structuredClone(tokens); - } - return JSON.parse(JSON.stringify(tokens)); -} - -export { NumberType, Reader, TokenType, cloneTokens, isToken, mirrorVariantType, stringify, tokenizer }; -//# sourceMappingURL=index.mjs.map +class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=[];for(let t=0;t=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===D)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case I:case c:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case I:case c:case S:case s:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.codePointSource[t.cursor]===y&&t.codePointSource[t.cursor+1]!==I}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.codePointSource[t.cursor]===l?t.codePointSource[t.cursor+1]===l||(!!isIdentStartCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===y&&t.codePointSource[t.cursor+2]!==I):!!isIdentStartCodePoint(t.codePointSource[t.cursor])||checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.codePointSource[t.cursor]===b||t.codePointSource[t.cursor]===l?!!isDigitCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===P&&isDigitCodePoint(t.codePointSource[t.cursor+2]):t.codePointSource[t.cursor]===P?isDigitCodePoint(t.codePointSource[t.cursor+1]):!!isDigitCodePoint(t.codePointSource[t.cursor])}function checkIfTwoCodePointsStartAComment(e,t){return t.codePointSource[t.cursor]===B&&t.codePointSource[t.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.codePointSource[t.cursor]===l&&t.codePointSource[t.cursor+1]===l&&t.codePointSource[t.cursor+2]===h}function consumeComment(t,o){for(o.advanceCodePoint(2);;){const e=o.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[e.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const o=t.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),R;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==t.codePointSource[t.cursor]&&isHexDigitCodePoint(t.codePointSource[t.cursor])&&e.length<6;)e.push(t.codePointSource[t.cursor]),t.advanceCodePoint();isWhitespace(t.codePointSource[t.cursor])&&t.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?R:X<=(r=n)&&r<=Y||n>U?R:n}var r;return o}function consumeIdentSequence(e,t){const o=[];for(;;)if(isIdentCodePoint(t.codePointSource[t.cursor]))o.push(t.codePointSource[t.cursor]),t.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,t))return o;t.advanceCodePoint(),o.push(consumeEscapedCodePoint(e,t))}}function consumeHashToken(t,r){if(r.advanceCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let n=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(n=o.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.source.slice(r.representationStart,r.representationEnd+1),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,"#",r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,o){let r=t.Integer;const n=[];{o.codePointSource[o.cursor]!==b&&o.codePointSource[o.cursor]!==l||(n.push(o.codePointSource[o.cursor]),o.advanceCodePoint());const e=consumeDigits(o);for(let t=0;t0&&o.advanceCodePoint(i),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&o.advanceCodePoint(i),consumeUrlToken(t,o)}return o.advanceCodePoint(),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(t,o){const n=t.css.valueOf(),i=new Reader(n),C={onParseError:(null==o?void 0:o.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.representationStart=i.cursor,i.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,i)){if(null!=o&&o.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.representationStart=i.cursor,i.representationEnd=-1}const t=i.codePointSource[i.cursor];if(void 0===t)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(t))return consumeIdentLikeToken(C,i);if(isDigitCodePoint(t))return consumeNumericToken(C,i);switch(t){case d:return i.advanceCodePoint(),[e.Comma,",",i.representationStart,i.representationEnd,void 0];case a:return i.advanceCodePoint(),[e.Colon,":",i.representationStart,i.representationEnd,void 0];case F:return i.advanceCodePoint(),[e.Semicolon,";",i.representationStart,i.representationEnd,void 0];case g:return i.advanceCodePoint(),[e.OpenParen,"(",i.representationStart,i.representationEnd,void 0];case q:return i.advanceCodePoint(),[e.CloseParen,")",i.representationStart,i.representationEnd,void 0];case A:return i.advanceCodePoint(),[e.OpenSquare,"[",i.representationStart,i.representationEnd,void 0];case x:return i.advanceCodePoint(),[e.CloseSquare,"]",i.representationStart,i.representationEnd,void 0];case v:return i.advanceCodePoint(),[e.OpenCurly,"{",i.representationStart,i.representationEnd,void 0];case W:return i.advanceCodePoint(),[e.CloseCurly,"}",i.representationStart,i.representationEnd,void 0];case r:case N:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case b:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]);case I:case c:case S:case s:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.advanceCodePoint(3),[e.CDC,"--\x3e",i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),[e.Delim,"-",i.representationStart,i.representationEnd,{value:"-"}]);case k:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.advanceCodePoint(4),[e.CDO,"\x3c!--",i.representationStart,i.representationEnd,void 0]):(i.advanceCodePoint(),[e.Delim,"<",i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(C,i);return[e.AtKeyword,i.source.slice(i.representationStart,i.representationEnd+1),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,"@",i.representationStart,i.representationEnd,{value:"@"}];case y:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,"\\",i.representationStart,i.representationEnd,{value:"\\"}])}return i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; diff --git a/packages/css-tokenizer/dist/index.mjs.map b/packages/css-tokenizer/dist/index.mjs.map deleted file mode 100644 index 06029fdd8..000000000 --- a/packages/css-tokenizer/dist/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../src/reader.ts","../src/interfaces/token.ts","../src/stringify.ts","../src/code-points/code-points.ts","../src/checks/four-code-points-would-start-cdo.ts","../src/code-points/ranges.ts","../src/checks/two-code-points-are-valid-escape.ts","../src/checks/three-code-points-would-start-ident-sequence.ts","../src/checks/three-code-points-would-start-number.ts","../src/checks/two-code-points-start-comment.ts","../src/checks/three-code-points-would-start-cdc.ts","../src/consume/comment.ts","../src/consume/escaped-code-point.ts","../src/consume/ident-sequence.ts","../src/consume/hash-token.ts","../src/consume/number.ts","../src/consume/numeric-token.ts","../src/consume/whitespace-token.ts","../src/consume/string-token.ts","../src/checks/matches-url-ident.ts","../src/consume/bad-url.ts","../src/consume/url-token.ts","../src/consume/ident-like-token.ts","../src/tokenizer.ts","../src/util/clone-tokens.ts"],"sourcesContent":["import { CodePointReader } from './interfaces/code-point-reader';\n\nexport class Reader implements CodePointReader {\n\tcursor: number;\n\tsource = '';\n\tcodePointSource: Array = [];\n\tlength = 0;\n\n\trepresentationStart = 0;\n\trepresentationEnd = -1;\n\n\tconstructor(source: string) {\n\t\tthis.cursor = 0;\n\t\tthis.source = source;\n\t\tthis.length = source.length;\n\n\t\tthis.codePointSource = new Array(this.length);\n\t\tfor (let i = 0; i < this.length; i++) {\n\t\t\tthis.codePointSource[i] = this.source.charCodeAt(i);\n\t\t}\n\t}\n\n\tcursorPositionOfLastReadCodePoint(): number {\n\t\treturn this.cursor - 1;\n\t}\n\n\tadvanceCodePoint(n = 1) {\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\t}\n\n\treadCodePoint(n = 1): number | false {\n\t\tconst codePoint = this.codePointSource[this.cursor];\n\t\tif (codePoint === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor += n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn codePoint;\n\t}\n\n\tunreadCodePoint(n = 1): boolean {\n\t\tif (this.cursor === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.cursor -= n;\n\t\tthis.representationEnd = this.cursor - 1;\n\n\t\treturn true;\n\t}\n\n\trepresentationString(): string {\n\t\treturn this.source.slice(this.representationStart, this.representationEnd + 1);\n\t}\n\n\tresetRepresentation() {\n\t\tthis.representationStart = this.cursor;\n\t\tthis.representationEnd = -1;\n\t}\n\n\tslice(start: number, end: number): string {\n\t\treturn this.source.slice(start, end);\n\t}\n}\n","export enum TokenType {\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */\n\tComment = 'comment',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */\n\tAtKeyword = 'at-keyword-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */\n\tBadString = 'bad-string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */\n\tBadURL = 'bad-url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */\n\tCDC = 'CDC-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */\n\tCDO = 'CDO-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */\n\tColon = 'colon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */\n\tComma = 'comma-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */\n\tDelim = 'delim-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */\n\tDimension = 'dimension-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */\n\tEOF = 'EOF-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */\n\tFunction = 'function-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */\n\tHash = 'hash-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */\n\tIdent = 'ident-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tNumber = 'number-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */\n\tPercentage = 'percentage-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */\n\tSemicolon = 'semicolon-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */\n\tString = 'string-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */\n\tURL = 'url-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */\n\tWhitespace = 'whitespace-token',\n\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */\n\tOpenParen = '(-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */\n\tCloseParen = ')-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */\n\tOpenSquare = '[-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */\n\tCloseSquare = ']-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */\n\tOpenCurly = '{-token',\n\t/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */\n\tCloseCurly = '}-token',\n}\n\nexport enum NumberType {\n\tInteger = 'integer',\n\tNumber = 'number',\n}\n\nexport enum HashType {\n\tUnrestricted = 'unrestricted',\n\tID = 'id',\n}\n\nexport type TokenAtKeyword = Token;\nexport type TokenBadString = Token;\nexport type TokenBadURL = Token;\nexport type TokenCDC = Token;\nexport type TokenCDO = Token;\nexport type TokenColon = Token;\nexport type TokenComma = Token;\nexport type TokenComment = Token;\nexport type TokenDelim = Token;\nexport type TokenDimension = Token;\nexport type TokenEOF = Token;\nexport type TokenFunction = Token;\nexport type TokenHash = Token;\nexport type TokenIdent = Token;\nexport type TokenNumber = Token;\nexport type TokenPercentage = Token;\nexport type TokenSemicolon = Token;\nexport type TokenString = Token;\nexport type TokenURL = Token;\nexport type TokenWhitespace = Token;\n\nexport type TokenOpenParen = Token;\nexport type TokenCloseParen = Token;\nexport type TokenOpenSquare = Token;\nexport type TokenCloseSquare = Token;\nexport type TokenOpenCurly = Token;\nexport type TokenCloseCurly = Token;\n\nexport type CSSToken = TokenAtKeyword |\n\tTokenBadString |\n\tTokenBadURL |\n\tTokenCDC |\n\tTokenCDO |\n\tTokenColon |\n\tTokenComma |\n\tTokenComment |\n\tTokenDelim |\n\tTokenDimension |\n\tTokenEOF |\n\tTokenFunction |\n\tTokenHash |\n\tTokenIdent |\n\tTokenNumber |\n\tTokenPercentage |\n\tTokenSemicolon |\n\tTokenString |\n\tTokenURL |\n\tTokenWhitespace |\n\tTokenOpenParen |\n\tTokenCloseParen |\n\tTokenOpenSquare |\n\tTokenCloseSquare |\n\tTokenOpenCurly |\n\tTokenCloseCurly;\n\nexport type Token = [\n\t/** The type of token */\n\tT,\n\t/** The token representation */\n\tstring,\n\t/** Start position of representation */\n\tnumber,\n\t/** End position of representation */\n\tnumber,\n\t/** Extra data */\n\tU,\n]\n\nexport function mirrorVariantType(type: TokenType): TokenType|null {\n\tswitch (type) {\n\t\tcase TokenType.OpenParen:\n\t\t\treturn TokenType.CloseParen;\n\t\tcase TokenType.CloseParen:\n\t\t\treturn TokenType.OpenParen;\n\n\t\tcase TokenType.OpenCurly:\n\t\t\treturn TokenType.CloseCurly;\n\t\tcase TokenType.CloseCurly:\n\t\t\treturn TokenType.OpenCurly;\n\n\t\tcase TokenType.OpenSquare:\n\t\t\treturn TokenType.CloseSquare;\n\t\tcase TokenType.CloseSquare:\n\t\t\treturn TokenType.OpenSquare;\n\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToken(x: any): x is CSSToken {\n\tif (!Array.isArray(x)) {\n\t\treturn false;\n\t}\n\n\tif (x.length < 4) {\n\t\treturn false;\n\t}\n\n\tif (!(x[0] in TokenType)) {\n\t\treturn false;\n\t}\n\n\tif (typeof x[1] !== 'string') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[2] !== 'number') {\n\t\treturn false;\n\t}\n\n\tif (typeof x[3] !== 'number') {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import type { CSSToken } from './interfaces/token';\n\nexport function stringify(...tokens: Array): string {\n\tlet buffer = '';\n\tfor (let i = 0; i < tokens.length; i++) {\n\t\tbuffer = buffer + tokens[i][1];\n\t}\n\n\treturn buffer;\n}\n","/** ' */\nexport const APOSTROPHE = '\\u{27}'.charCodeAt(0);\n/** * */\nexport const ASTERISK = '\\u{2a}'.charCodeAt(0);\n/** \\b */\nexport const BACKSPACE = '\\u{8}'.charCodeAt(0);\n/** \\r */\nexport const CARRIAGE_RETURN = '\\u{d}'.charCodeAt(0);\n/** \\t */\nexport const CHARACTER_TABULATION = '\\u{9}'.charCodeAt(0);\n/** : */\nexport const COLON = '\\u{3a}'.charCodeAt(0);\n/** , */\nexport const COMMA = '\\u{2c}'.charCodeAt(0);\n/** @ */\nexport const COMMERCIAL_AT = '\\u{40}'.charCodeAt(0);\n/** \\x7F */\nexport const DELETE = '\\u{7f}'.charCodeAt(0);\n/** ! */\nexport const EXCLAMATION_MARK = '\\u{21}'.charCodeAt(0);\n/** \\f */\nexport const FORM_FEED = '\\u{c}'.charCodeAt(0);\n/** . */\nexport const FULL_STOP = '\\u{2e}'.charCodeAt(0);\n/** > */\nexport const GREATER_THAN_SIGN = '\\u{3e}'.charCodeAt(0);\n/** - */\nexport const HYPHEN_MINUS = '\\u{2d}'.charCodeAt(0);\n/** \\x1F */\nexport const INFORMATION_SEPARATOR_ONE = '\\u{1f}'.charCodeAt(0);\n/** E */\nexport const LATIN_CAPITAL_LETTER_E = '\\u{45}'.charCodeAt(0);\n/** e */\nexport const LATIN_SMALL_LETTER_E = '\\u{65}'.charCodeAt(0);\n/** { */\nexport const LEFT_CURLY_BRACKET = '\\u{7b}'.charCodeAt(0);\n/** ( */\nexport const LEFT_PARENTHESIS = '\\u{28}'.charCodeAt(0);\n/** [ */\nexport const LEFT_SQUARE_BRACKET = '\\u{5b}'.charCodeAt(0);\n/** < */\nexport const LESS_THAN_SIGN = '\\u{3c}'.charCodeAt(0);\n/** \\n */\nexport const LINE_FEED = '\\u{a}'.charCodeAt(0);\n/** \\v */\nexport const LINE_TABULATION = '\\u{b}'.charCodeAt(0);\n/** _ */\nexport const LOW_LINE = '\\u{5f}'.charCodeAt(0);\n/** \\x10FFFF */\nexport const MAXIMUM_ALLOWED_CODEPOINT = '\\u{10FFFF}'.charCodeAt(0);\n/** \\x00 */\nexport const NULL = '\\u{0}'.charCodeAt(0);\n/** # */\nexport const NUMBER_SIGN = '\\u{23}'.charCodeAt(0);\n/** % */\nexport const PERCENTAGE_SIGN = '\\u{25}'.charCodeAt(0);\n/** + */\nexport const PLUS_SIGN = '\\u{2b}'.charCodeAt(0);\n/** \" */\nexport const QUOTATION_MARK = '\\u{22}'.charCodeAt(0);\n/** � */\nexport const REPLACEMENT_CHARACTER = '\\u{0FFFD}'.charCodeAt(0);\n/** \\ */\nexport const REVERSE_SOLIDUS = '\\u{5c}'.charCodeAt(0);\n/** } */\nexport const RIGHT_CURLY_BRACKET = '\\u{7d}'.charCodeAt(0);\n/** ) */\nexport const RIGHT_PARENTHESIS = '\\u{29}'.charCodeAt(0);\n/** ] */\nexport const RIGHT_SQUARE_BRACKET = '\\u{5d}'.charCodeAt(0);\n/** ; */\nexport const SEMICOLON = '\\u{3b}'.charCodeAt(0);\n/** \\u0E */\nexport const SHIFT_OUT = '\\u{e}'.charCodeAt(0);\n/** / */\nexport const SOLIDUS = '\\u{2f}'.charCodeAt(0);\n/** \\u20 */\nexport const SPACE = '\\u{20}'.charCodeAt(0);\n/** 0 */\nexport const DIGIT_0 = '\\u{30}'.charCodeAt(0);\n/** 1 */\nexport const DIGIT_1 = '\\u{31}'.charCodeAt(0);\n/** 2 */\nexport const DIGIT_2 = '\\u{32}'.charCodeAt(0);\n/** 3 */\nexport const DIGIT_3 = '\\u{33}'.charCodeAt(0);\n/** 4 */\nexport const DIGIT_4 = '\\u{34}'.charCodeAt(0);\n/** 5 */\nexport const DIGIT_5 = '\\u{35}'.charCodeAt(0);\n/** 6 */\nexport const DIGIT_6 = '\\u{36}'.charCodeAt(0);\n/** 7 */\nexport const DIGIT_7 = '\\u{37}'.charCodeAt(0);\n/** 8 */\nexport const DIGIT_8 = '\\u{38}'.charCodeAt(0);\n/** 9 */\nexport const DIGIT_9 = '\\u{39}'.charCodeAt(0);\n","import { EXCLAMATION_MARK, HYPHEN_MINUS, LESS_THAN_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfFourCodePointsWouldStartCDO(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === LESS_THAN_SIGN && reader.codePointSource[reader.cursor+1] === EXCLAMATION_MARK && reader.codePointSource[reader.cursor + 2] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+3] === HYPHEN_MINUS;\n}\n","import { BACKSPACE, DELETE, INFORMATION_SEPARATOR_ONE, LINE_TABULATION, LOW_LINE, HYPHEN_MINUS, NULL, SHIFT_OUT, LINE_FEED, CARRIAGE_RETURN, FORM_FEED, CHARACTER_TABULATION, SPACE } from './code-points';\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions\n\nconst digitsLow = '\\u{30}'.charCodeAt(0);\nconst digitsHigh = '\\u{39}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit\nexport function isDigitCodePoint(search: number): boolean {\n\treturn digitsLow <= search && search <= digitsHigh;\n}\n\nconst letterUppercaseLow = '\\u{41}'.charCodeAt(0);\nconst letterUppercaseHigh = '\\u{5a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter\nexport function isUppercaseLetterCodePoint(search: number): boolean {\n\treturn letterUppercaseLow <= search && search <= letterUppercaseHigh;\n}\n\nconst letterLowercaseLow = '\\u{61}'.charCodeAt(0);\nconst letterLowercaseHigh = '\\u{7a}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter\nexport function isLowercaseLetterCodePoint(search: number): boolean {\n\treturn letterLowercaseLow <= search && search <= letterLowercaseHigh;\n}\n\nconst afUppercaseHigh = '\\u{46}'.charCodeAt(0);\nconst afLowercaseHigh = '\\u{66}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit\nexport function isHexDigitCodePoint(search: number): boolean {\n\tif (digitsLow <= search && search <= digitsHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterLowercaseLow <= search && search <= afLowercaseHigh) {\n\t\treturn true;\n\t}\n\n\tif (letterUppercaseLow <= search && search <= afUppercaseHigh) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter\nexport function isLetterCodePoint(search: number): boolean {\n\treturn isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search);\n}\n\nconst nonASCIILow = '\\u{80}'.charCodeAt(0);\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point\nexport function isNonASCIICodePoint(search: number): boolean {\n\treturn search >= nonASCIILow;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point\nexport function isIdentStartCodePoint(search: number): boolean {\n\tif (isLetterCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isNonASCIICodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === LOW_LINE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point\nexport function isIdentCodePoint(search: number): boolean {\n\tif (isIdentStartCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\tif (isDigitCodePoint(search)) {\n\t\treturn true;\n\t}\n\n\treturn search === HYPHEN_MINUS;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point\nexport function isNonPrintableCodePoint(search: number): boolean {\n\tif (search === LINE_TABULATION) {\n\t\treturn true;\n\t}\n\n\tif (search === DELETE) {\n\t\treturn true;\n\t}\n\n\tif (NULL <= search && search <= BACKSPACE) {\n\t\treturn true;\n\t}\n\n\treturn SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE;\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isNewLine(search: number): boolean {\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\t\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t\t\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t\t\t// Applying the preprocessing rules would make it impossible to match the input.\n\t\t\t// A side effect of this is that our definition of whitespace is broader.\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace\nexport function isWhitespace(search: number): boolean {\n\t// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing\n\t// We can not follow the preprocessing rules because our output is text and must be minimally different from the input.\n\t// Applying the preprocessing rules would make it impossible to match the input.\n\t// A side effect of this is that our definition of whitespace is broader.\n\n\tswitch (search) {\n\t\tcase LINE_FEED:\n\t\tcase CARRIAGE_RETURN:\n\t\tcase FORM_FEED:\n\t\tcase CHARACTER_TABULATION:\n\t\tcase SPACE:\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nconst surrogateLow = '\\u{d800}'.charCodeAt(0);\nconst surrogateHigh = '\\u{dfff}'.charCodeAt(0);\n\n// https://infra.spec.whatwg.org/#surrogate\nexport function isSurrogate(search: number): boolean {\n\treturn surrogateLow <= search && search <= surrogateHigh;\n}\n","import { LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-valid-escape\nexport function checkIfTwoCodePointsAreAValidEscape(ctx: Context, reader: CodePointReader): boolean {\n\t// If the first code point is not U+005C REVERSE SOLIDUS (\\), return false.\n\tif (reader.codePointSource[reader.cursor] !== REVERSE_SOLIDUS) { // \"\\\"\n\t\treturn false;\n\t}\n\n\t// Otherwise, if the second code point is a newline, return false.\n\tif (reader.codePointSource[reader.cursor+1] === LINE_FEED) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { HYPHEN_MINUS, LINE_FEED, REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isIdentStartCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { checkIfTwoCodePointsAreAValidEscape } from './two-code-points-are-valid-escape';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#would-start-an-identifier\nexport function checkIfThreeCodePointsWouldStartAnIdentSequence(ctx: Context, reader: CodePointReader): boolean {\n\t// // U+002D HYPHEN-MINUS\n\tif (reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t// If the second code point is a U+002D HYPHEN-MINUS return true\n\t\tif (reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second code point is an ident-start code point return true\n\t\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the second and third code points are a valid escape return true\n\t\tif (reader.codePointSource[reader.cursor+1] === REVERSE_SOLIDUS && reader.codePointSource[reader.cursor + 2] !== LINE_FEED) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t// ident-start code point\n\t// Return true.\n\tif (isIdentStartCodePoint(reader.codePointSource[reader.cursor])) {\n\t\treturn true;\n\t}\n\n\t// U+005C REVERSE SOLIDUS (\\)\n\treturn checkIfTwoCodePointsAreAValidEscape(ctx, reader);\n}\n","import { FULL_STOP, HYPHEN_MINUS, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#starts-with-a-number\nexport function checkIfThreeCodePointsWouldStartANumber(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) { // U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-)\n\t\t// If the second code point is a digit, return true.\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Otherwise, if the second code point is a U+002E FULL STOP (.)\n\t\tif (reader.codePointSource[reader.cursor+1] === FULL_STOP) {\n\t\t\t// and the third code point is a digit, return true.\n\t\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+2]);\n\t\t}\n\n\t\t// Otherwise, return false.\n\t\treturn false;\n\n\t} else if (reader.codePointSource[reader.cursor] === FULL_STOP) { // U+002E FULL STOP (.)\n\t\t// If the second code point is a digit, return true.\n\t\t// Otherwise, return false.\n\t\treturn isDigitCodePoint(reader.codePointSource[reader.cursor+1]);\n\n\t} else if (isDigitCodePoint(reader.codePointSource[reader.cursor])) { // digit\n\t\t// Return true.\n\t\treturn true;\n\t}\n\n\t// anything else\n\t// Return false.\n\treturn false;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comments\nexport function checkIfTwoCodePointsStartAComment(ctx: Context, reader: CodePointReader): boolean {\n\tif (reader.codePointSource[reader.cursor] !== SOLIDUS) {\n\t\treturn false;\n\t}\n\n\tif (reader.codePointSource[reader.cursor+1] !== ASTERISK) {\n\t\treturn false;\n\t}\n\n\t// Otherwise, return true.\n\treturn true;\n}\n","import { GREATER_THAN_SIGN, HYPHEN_MINUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function checkIfThreeCodePointsWouldStartCDC(ctx: Context, reader: CodePointReader): boolean {\n\treturn reader.codePointSource[reader.cursor] === HYPHEN_MINUS && reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS && reader.codePointSource[reader.cursor + 2] === GREATER_THAN_SIGN;\n}\n","import { ASTERISK, SOLIDUS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenComment, TokenType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-comment\nexport function consumeComment(ctx: Context, reader: CodePointReader): TokenComment {\n\treader.advanceCodePoint(2);\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst codePoint = reader.readCodePoint();\n\t\tif (codePoint === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a comment.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.2. Consume comments',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (codePoint !== ASTERISK) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === SOLIDUS) {\n\t\t\treader.advanceCodePoint();\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Comment,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { MAXIMUM_ALLOWED_CODEPOINT, REPLACEMENT_CHARACTER } from '../code-points/code-points';\nimport { isHexDigitCodePoint, isSurrogate, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-escaped-code-point\nexport function consumeEscapedCodePoint(ctx: Context, reader: CodePointReader): number {\n\tconst codePoint = reader.readCodePoint();\n\tif (codePoint === false) {\n\t\tctx.onParseError({\n\t\t\tmessage: 'Unexpected EOF while consuming an escaped code point.',\n\t\t\tstart: reader.representationStart,\n\t\t\tend: reader.representationEnd,\n\t\t\tstate: [\n\t\t\t\t'4.3.7. Consume an escaped code point',\n\t\t\t\t'Unexpected EOF',\n\t\t\t],\n\t\t});\n\n\t\treturn REPLACEMENT_CHARACTER;\n\t}\n\n\tif (isHexDigitCodePoint(codePoint)) {\n\t\tconst hexSequence: Array = [codePoint];\n\n\t\twhile ((reader.codePointSource[reader.cursor] !== undefined) && isHexDigitCodePoint(reader.codePointSource[reader.cursor]) && hexSequence.length < 6) {\n\t\t\thexSequence.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\tconst codePointLiteral = parseInt(String.fromCharCode(...hexSequence), 16);\n\t\tif (codePointLiteral === 0) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (isSurrogate(codePointLiteral)) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\t\tif (codePointLiteral > MAXIMUM_ALLOWED_CODEPOINT) {\n\t\t\treturn REPLACEMENT_CHARACTER;\n\t\t}\n\n\t\treturn codePointLiteral;\n\t}\n\n\treturn codePoint;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-name\nexport function consumeIdentSequence(ctx: Context, reader: CodePointReader): Array {\n\tconst result: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (isIdentCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tresult.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tresult.push(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn result;\n\t}\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { isIdentCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { HashType, TokenDelim, TokenHash, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-token\nexport function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDelim|TokenHash {\n\treader.advanceCodePoint();\n\n\tif (\n\t\t(reader.codePointSource[reader.cursor] !== undefined) &&\n\t\tisIdentCodePoint(reader.codePointSource[reader.cursor]) ||\n\t\tcheckIfTwoCodePointsAreAValidEscape(ctx, reader)\n\t) {\n\t\tlet hashType = HashType.Unrestricted;\n\n\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\thashType = HashType.ID;\n\t\t}\n\n\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\t\treturn [\n\t\t\tTokenType.Hash,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\ttype: hashType,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [\n\t\tTokenType.Delim,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: '#',\n\t\t},\n\t];\n}\n","import { FULL_STOP, HYPHEN_MINUS, LATIN_CAPITAL_LETTER_E, LATIN_SMALL_LETTER_E, PLUS_SIGN } from '../code-points/code-points';\nimport { isDigitCodePoint } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { NumberType } from '../interfaces/token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-number\nexport function consumeNumber(ctx: Context, reader: CodePointReader): [number, NumberType] {\n\t// 1. Initially set type to \"integer\".\n\t// Let repr be the empty string.\n\tlet type = NumberType.Integer;\n\tconst repr: Array = [];\n\n\t{\n\t\t// 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr.\n\t\tif (reader.codePointSource[reader.cursor] === PLUS_SIGN || reader.codePointSource[reader.cursor] === HYPHEN_MINUS) {\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t}\n\n\t\t// 3. While the next input code point is a digit, consume it and append it to repr.\n\t\tconst newPart = consumeDigits(reader);\n\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\trepr.push(newPart[i]);\n\t\t}\n\t}\n\n\t{\n\t\t// 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then:\n\t\tif (reader.codePointSource[reader.cursor] === FULL_STOP && isDigitCodePoint(reader.codePointSource[reader.cursor+1])) {\n\t\t\t// 4.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 4.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 4.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 4.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t{\n\t\t// 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e),\n\t\t// optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+),\n\t\t// followed by a digit, then:\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+1])\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(2);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t(reader.codePointSource[reader.cursor] === LATIN_SMALL_LETTER_E || reader.codePointSource[reader.cursor] === LATIN_CAPITAL_LETTER_E) &&\n\t\t\t(\n\t\t\t\t(reader.codePointSource[reader.cursor+1] === HYPHEN_MINUS || reader.codePointSource[reader.cursor+1] === PLUS_SIGN) &&\n\t\t\t\tisDigitCodePoint(reader.codePointSource[reader.cursor+2])\n\t\t\t)\n\t\t) {\n\t\t\t// 5.2. Append them to repr.\n\t\t\trepr.push(reader.codePointSource[reader.cursor]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+1]);\n\t\t\trepr.push(reader.codePointSource[reader.cursor+2]);\n\n\t\t\t// 5.1. Consume them.\n\t\t\treader.advanceCodePoint(3);\n\n\t\t\t// 5.3. Set type to \"number\".\n\t\t\ttype = NumberType.Number;\n\n\t\t\t// 5.4. While the next input code point is a digit, consume it and append it to repr.\n\t\t\tconst newPart = consumeDigits(reader);\n\t\t\tfor (let i = 0; i < newPart.length; i++) {\n\t\t\t\trepr.push(newPart[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\t// 6. Convert repr to a number, and set the value to the returned value.\n\tconst value = convertCodePointsToNumber(repr);\n\n\t// 7. Return value and type.\n\treturn [value, type];\n}\n\nfunction consumeDigits(reader: CodePointReader): Array {\n\tconst value: Array = [];\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn value;\n\t\t}\n\n\t\tif (isDigitCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tvalue.push(reader.codePointSource[reader.cursor]);\n\t\t\treader.advanceCodePoint();\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t}\n}\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#convert-string-to-number\nfunction convertCodePointsToNumber(codePoints: Array): number {\n\tlet s = 1;\n\tconst iCodePoints: Array = [];\n\tlet i = 0;\n\n\tlet d = 0;\n\tconst fCodePoints: Array = [];\n\tlet f = 0;\n\n\tlet t = 1;\n\n\tconst eCodePoints: Array = [];\n\tlet e = 0;\n\n\tlet cursor = 0;\n\n\t// 1. A sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let s be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let s be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\ts = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 2. An integer part: zero or more digits.\n\t// If there is at least one digit,\n\t// let i be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let i be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tiCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\ti = digitCodePointsToInteger(iCodePoints);\n\n\t// 3. A decimal point: a single U+002E FULL STOP (.), or the empty string.\n\tif (codePoints[cursor] === FULL_STOP) {\n\t\tcursor++;\n\t}\n\n\t// 4. A fractional part: zero or more digits.\n\t// If there is at least one digit,\n\t// let f be the number formed by interpreting the digits as a base-10 integer and d be the number of digits;\n\t// otherwise, let f and d be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\tfCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\td = fCodePoints.length;\n\tf = (digitCodePointsToInteger(fCodePoints) / Math.pow(10, d));\n\n\t// 5. An exponent indicator: a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), or the empty string.\n\tif (codePoints[cursor] === LATIN_SMALL_LETTER_E || codePoints[cursor] === LATIN_CAPITAL_LETTER_E) {\n\t\tcursor++;\n\t}\n\n\t// 6. An exponent sign: a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), or the empty string.\n\t// Let t be the number -1 if the sign is U+002D HYPHEN-MINUS (-);\n\t// otherwise, let t be the number 1.\n\tif (codePoints[cursor] === HYPHEN_MINUS) {\n\t\tcursor++;\n\t\tt = -1;\n\t} else if (codePoints[cursor] === PLUS_SIGN) {\n\t\tcursor++;\n\t}\n\n\t// 7. An exponent: zero or more digits.\n\t// If there is at least one digit,\n\t// let e be the number formed by interpreting the digits as a base-10 integer;\n\t// otherwise, let e be the number 0.\n\twhile (cursor < codePoints.length && isDigitCodePoint(codePoints[cursor])) {\n\t\teCodePoints.push(codePoints[cursor]);\n\t\tcursor++;\n\t}\n\n\te = digitCodePointsToInteger(eCodePoints);\n\n\t// Return the number s·(i + f·10-d)·10te.\n\treturn s * (i + f) * Math.pow(10, t * e);\n}\n\nfunction digitCodePointsToInteger(codePoints: Array): number {\n\tif (codePoints.length === 0) {\n\t\treturn 0;\n\t}\n\n\treturn Number.parseInt(String.fromCharCode(...codePoints), 10);\n}\n","import { checkIfThreeCodePointsWouldStartAnIdentSequence } from '../checks/three-code-points-would-start-ident-sequence';\nimport { PERCENTAGE_SIGN } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenDimension, TokenNumber, TokenPercentage, TokenType } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeNumber } from './number';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-numeric-token\nexport function consumeNumericToken(ctx: Context, reader: CodePointReader): TokenPercentage|TokenNumber|TokenDimension {\n\tconst numberValue = consumeNumber(ctx, reader);\n\n\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\tconst unit = consumeIdentSequence(ctx, reader);\n\n\t\treturn [\n\t\t\tTokenType.Dimension,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: numberValue[0],\n\t\t\t\ttype: numberValue[1],\n\t\t\t\tunit: String.fromCharCode(...unit),\n\t\t\t},\n\t\t];\n\t}\n\n\t{\n\t\tif (reader.codePointSource[reader.cursor] === PERCENTAGE_SIGN) {\n\t\t\treader.advanceCodePoint();\n\n\t\t\treturn [\n\t\t\t\tTokenType.Percentage,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: numberValue[0],\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t}\n\n\treturn [\n\t\tTokenType.Number,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: numberValue[0],\n\t\t\ttype: numberValue[1],\n\t\t},\n\t];\n}\n","import { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenType, TokenWhitespace } from '../interfaces/token';\n\nexport function consumeWhiteSpace(ctx: Context, reader: CodePointReader): TokenWhitespace {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (!isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tbreak;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t}\n\n\treturn [\n\t\tTokenType.Whitespace,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\tundefined,\n\t];\n}\n","import { REVERSE_SOLIDUS } from '../code-points/code-points';\nimport { isNewLine } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadString, TokenString, TokenType } from '../interfaces/token';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-string-token\nexport function consumeStringToken(ctx: Context, reader: CodePointReader): TokenBadString|TokenString {\n\tlet result = '';\n\n\tconst first = reader.readCodePoint();\n\tif (first === false) {\n\t\tthrow new Error('Unexpected EOF');\n\t}\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst next = reader.readCodePoint();\n\t\tif (next === false) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a string token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (isNewLine(next)) {\n\t\t\t{\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected newline while consuming a string token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.5. Consume a string token',\n\t\t\t\t\t\t'Unexpected newline',\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treader.unreadCodePoint();\n\t\t\treturn [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t}\n\n\t\tif (next === first) {\n\t\t\treturn [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }];\n\t\t}\n\n\t\tif (next === REVERSE_SOLIDUS) {\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isNewLine(reader.codePointSource[reader.cursor])) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tresult += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += String.fromCharCode(next);\n\t}\n}\n","import { Context } from '../interfaces/context';\n\nconst u = 'u'.charCodeAt(0);\nconst U = 'U'.charCodeAt(0);\nconst r = 'r'.charCodeAt(0);\nconst R = 'R'.charCodeAt(0);\nconst l = 'l'.charCodeAt(0);\nconst L = 'L'.charCodeAt(0);\n\nexport function checkIfCodePointsMatchURLIdent(ctx: Context, codePoints: Array): boolean {\n\tif (codePoints.length !== 3) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[0] !== u && codePoints[0] !== U) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[1] !== r && codePoints[1] !== R) {\n\t\treturn false;\n\t}\n\n\tif (codePoints[2] !== l && codePoints[2] !== L) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-remnants-of-bad-url\nexport function consumeBadURL(ctx: Context, reader: CodePointReader) {\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn;\n\t\t}\n\n\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\treader.advanceCodePoint();\n\t\t\tconsumeEscapedCodePoint(ctx, reader);\n\t\t\tcontinue;\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\tcontinue;\n\t}\n}\n","import { checkIfTwoCodePointsAreAValidEscape } from '../checks/two-code-points-are-valid-escape';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_PARENTHESIS } from '../code-points/code-points';\nimport { isNonPrintableCodePoint, isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeBadURL } from './bad-url';\nimport { consumeEscapedCodePoint } from './escaped-code-point';\nimport { consumeWhiteSpace } from './whitespace-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-url-token\nexport function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL|TokenBadURL {\n\tconsumeWhiteSpace(ctx, reader);\n\tlet string = '';\n\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\treader.advanceCodePoint();\n\t\t\treturn [\n\t\t\t\tTokenType.URL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\t{\n\t\t\t\t\tvalue: string,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tif (isWhitespace(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeWhiteSpace(ctx, reader);\n\t\t\tif (reader.codePointSource[reader.cursor] === undefined) {\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Unexpected EOF while consuming a url token.',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t\t'Consume as much whitespace as possible',\n\t\t\t\t\t\t'Unexpected EOF',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tif (reader.codePointSource[reader.cursor] === RIGHT_PARENTHESIS) {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.URL,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: string,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === QUOTATION_MARK || reader.codePointSource[reader.cursor] === APOSTROPHE || reader.codePointSource[reader.cursor] === LEFT_PARENTHESIS || isNonPrintableCodePoint(reader.codePointSource[reader.cursor])) {\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Unexpected character while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE (\\'), U+0028 LEFT PARENTHESIS (() or non-printable code point',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tif (reader.codePointSource[reader.cursor] === REVERSE_SOLIDUS) {\n\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\tstring += String.fromCharCode(consumeEscapedCodePoint(ctx, reader));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconsumeBadURL(ctx, reader);\n\n\t\t\tctx.onParseError({\n\t\t\t\tmessage: 'Invalid escape sequence while consuming a url token.',\n\t\t\t\tstart: reader.representationStart,\n\t\t\t\tend: reader.representationEnd,\n\t\t\t\tstate: [\n\t\t\t\t\t'4.3.6. Consume a url token',\n\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t],\n\t\t\t});\n\n\t\t\treturn [\n\t\t\t\tTokenType.BadURL,\n\t\t\t\treader.representationString(),\n\t\t\t\treader.representationStart,\n\t\t\t\treader.representationEnd,\n\t\t\t\tundefined,\n\t\t\t];\n\t\t}\n\n\t\tstring += String.fromCharCode(reader.codePointSource[reader.cursor]);\n\t\treader.advanceCodePoint();\n\t}\n}\n","import { checkIfCodePointsMatchURLIdent } from '../checks/matches-url-ident';\nimport { APOSTROPHE, LEFT_PARENTHESIS, QUOTATION_MARK } from '../code-points/code-points';\nimport { isWhitespace } from '../code-points/ranges';\nimport { CodePointReader } from '../interfaces/code-point-reader';\nimport { Context } from '../interfaces/context';\nimport { TokenBadURL, TokenFunction, TokenIdent, TokenType, TokenURL } from '../interfaces/token';\nimport { consumeIdentSequence } from './ident-sequence';\nimport { consumeUrlToken } from './url-token';\n\n// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-ident-like-token\nexport function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): TokenIdent | TokenFunction | TokenURL | TokenBadURL {\n\tconst codePoints = consumeIdentSequence(ctx, reader);\n\n\tif (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) {\n\t\treturn [\n\t\t\tTokenType.Ident,\n\t\t\treader.representationString(),\n\t\t\treader.representationStart,\n\t\t\treader.representationEnd,\n\t\t\t{\n\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t},\n\t\t];\n\t}\n\n\tif (checkIfCodePointsMatchURLIdent(ctx, codePoints)) {\n\t\treader.advanceCodePoint();\n\n\t\tlet read = 0;\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]);\n\t\t\tconst secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor+1]);\n\t\t\tif (firstIsWhitespace && secondIsWhitespace) {\n\t\t\t\tread += 2;\n\t\t\t\treader.advanceCodePoint(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor+1] : reader.codePointSource[reader.cursor];\n\t\t\tif (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) {\n\t\t\t\tif (read > 0) {\n\t\t\t\t\treader.advanceCodePoint(read);\n\t\t\t\t}\n\n\t\t\t\treturn [\n\t\t\t\t\tTokenType.Function,\n\t\t\t\t\treader.representationString(),\n\t\t\t\t\treader.representationStart,\n\t\t\t\t\treader.representationEnd,\n\t\t\t\t\t{\n\t\t\t\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tif (read > 0) {\n\t\t\treader.advanceCodePoint(read);\n\t\t}\n\n\t\treturn consumeUrlToken(ctx, reader);\n\t}\n\n\treader.advanceCodePoint();\n\treturn [\n\t\tTokenType.Function,\n\t\treader.representationString(),\n\t\treader.representationStart,\n\t\treader.representationEnd,\n\t\t{\n\t\t\tvalue: String.fromCharCode(...codePoints),\n\t\t},\n\t];\n}\n","import { checkIfFourCodePointsWouldStartCDO } from './checks/four-code-points-would-start-cdo';\nimport { checkIfThreeCodePointsWouldStartAnIdentSequence } from './checks/three-code-points-would-start-ident-sequence';\nimport { checkIfThreeCodePointsWouldStartANumber } from './checks/three-code-points-would-start-number';\nimport { checkIfTwoCodePointsStartAComment } from './checks/two-code-points-start-comment';\nimport { checkIfThreeCodePointsWouldStartCDC } from './checks/three-code-points-would-start-cdc';\nimport { APOSTROPHE, CARRIAGE_RETURN, CHARACTER_TABULATION, COLON, COMMA, COMMERCIAL_AT, DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9, FORM_FEED, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, LINE_FEED, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON, SPACE } from './code-points/code-points';\nimport { isIdentStartCodePoint } from './code-points/ranges';\nimport { consumeComment } from './consume/comment';\nimport { consumeHashToken } from './consume/hash-token';\nimport { consumeIdentSequence } from './consume/ident-sequence';\nimport { consumeNumericToken } from './consume/numeric-token';\nimport { consumeWhiteSpace } from './consume/whitespace-token';\nimport { CSSToken, TokenType } from './interfaces/token';\nimport { Reader } from './reader';\nimport { consumeStringToken } from './consume/string-token';\nimport { consumeIdentLikeToken } from './consume/ident-like-token';\nimport { checkIfTwoCodePointsAreAValidEscape } from './checks/two-code-points-are-valid-escape';\nimport { ParserError } from './interfaces/error';\n\ninterface Stringer {\n\tvalueOf(): string\n}\n\nexport function tokenizer(input: { css: Stringer }, options?: { commentsAreTokens?: boolean, onParseError?: (error: ParserError) => void }) {\n\tconst css = input.css.valueOf();\n\n\tconst reader = new Reader(css);\n\n\tconst ctx = {\n\t\tonParseError: options?.onParseError ?? (() => { /* noop */ }),\n\t};\n\n\tfunction endOfFile() {\n\t\treturn reader.codePointSource[reader.cursor] === undefined;\n\t}\n\n\tfunction nextToken(): CSSToken | undefined {\n\t\treader.resetRepresentation();\n\n\t\tif (checkIfTwoCodePointsStartAComment(ctx, reader)) {\n\t\t\tif (options?.commentsAreTokens) {\n\t\t\t\treturn consumeComment(ctx, reader);\n\t\t\t} else {\n\t\t\t\tconsumeComment(ctx, reader);\n\t\t\t\treader.resetRepresentation();\n\t\t\t}\n\t\t}\n\n\t\tconst peeked = reader.codePointSource[reader.cursor];\n\t\tif (peeked === undefined) {\n\t\t\treturn [TokenType.EOF, '', -1, -1, undefined];\n\t\t}\n\n\t\tif (isIdentStartCodePoint(peeked)) {\n\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t}\n\n\t\t// Simple, one character tokens:\n\t\tswitch (peeked) {\n\t\t\tcase COMMA: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase COLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase SEMICOLON: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_PARENTHESIS: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_SQUARE_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase LEFT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase RIGHT_CURLY_BRACKET: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t}\n\t\t\tcase APOSTROPHE:\n\t\t\tcase QUOTATION_MARK:\n\t\t\t\treturn consumeStringToken(ctx, reader);\n\t\t\tcase NUMBER_SIGN:\n\t\t\t\treturn consumeHashToken(ctx, reader);\n\n\t\t\tcase PLUS_SIGN:\n\t\t\tcase FULL_STOP: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: reader.representationString(),\n\t\t\t\t}];\n\t\t\t}\n\t\t\tcase DIGIT_0:\n\t\t\tcase DIGIT_1:\n\t\t\tcase DIGIT_2:\n\t\t\tcase DIGIT_3:\n\t\t\tcase DIGIT_4:\n\t\t\tcase DIGIT_5:\n\t\t\tcase DIGIT_6:\n\t\t\tcase DIGIT_7:\n\t\t\tcase DIGIT_8:\n\t\t\tcase DIGIT_9:\n\t\t\t\treturn consumeNumericToken(ctx, reader);\n\n\t\t\tcase LINE_FEED:\n\t\t\tcase CARRIAGE_RETURN:\n\t\t\tcase FORM_FEED:\n\t\t\tcase CHARACTER_TABULATION:\n\t\t\tcase SPACE:\n\t\t\t\treturn consumeWhiteSpace(ctx, reader);\n\n\t\t\tcase HYPHEN_MINUS: {\n\t\t\t\tif (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) {\n\t\t\t\t\treturn consumeNumericToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(3);\n\n\t\t\t\t\treturn [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '-',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase LESS_THAN_SIGN: {\n\t\t\t\tif (checkIfFourCodePointsWouldStartCDO(ctx, reader)) {\n\t\t\t\t\treader.advanceCodePoint(4);\n\n\t\t\t\t\treturn [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined];\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '<',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase COMMERCIAL_AT: {\n\t\t\t\treader.advanceCodePoint();\n\t\t\t\tif (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) {\n\t\t\t\t\tconst identSequence = consumeIdentSequence(ctx, reader);\n\n\t\t\t\t\treturn [TokenType.AtKeyword, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\t\tvalue: String.fromCharCode(...identSequence),\n\t\t\t\t\t}];\n\t\t\t\t}\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '@',\n\t\t\t\t}];\n\t\t\t}\n\n\t\t\tcase REVERSE_SOLIDUS: {\n\t\t\t\tif (checkIfTwoCodePointsAreAValidEscape(ctx, reader)) {\n\t\t\t\t\treturn consumeIdentLikeToken(ctx, reader);\n\t\t\t\t}\n\n\t\t\t\treader.advanceCodePoint();\n\n\t\t\t\tctx.onParseError({\n\t\t\t\t\tmessage: 'Invalid escape sequence after \"\\\\\"',\n\t\t\t\t\tstart: reader.representationStart,\n\t\t\t\t\tend: reader.representationEnd,\n\t\t\t\t\tstate: [\n\t\t\t\t\t\t'4.3.1. Consume a token',\n\t\t\t\t\t\t'U+005C REVERSE SOLIDUS (\\\\)',\n\t\t\t\t\t\t'The input stream does not start with a valid escape sequence',\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\t\t\tvalue: '\\\\',\n\t\t\t\t}];\n\t\t\t}\n\t\t}\n\n\t\treader.advanceCodePoint();\n\t\treturn [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, {\n\t\t\tvalue: reader.representationString(),\n\t\t}];\n\t}\n\n\treturn {\n\t\tnextToken: nextToken,\n\t\tendOfFile: endOfFile,\n\t};\n}\n","import { CSSToken } from '../interfaces/token';\n\nexport function cloneTokens(tokens: Array): Array {\n\tif ((typeof globalThis !== 'undefined') && 'structuredClone' in globalThis) {\n\t\treturn structuredClone(tokens);\n\t}\n\n\treturn JSON.parse(JSON.stringify(tokens));\n}\n"],"names":["Reader","cursor","source","codePointSource","length","representationStart","representationEnd","constructor","Array","i","charCodeAt","cursorPositionOfLastReadCodePoint","advanceCodePoint","n","readCodePoint","codePoint","undefined","unreadCodePoint","representationString","slice","resetRepresentation","start","end","TokenType","NumberType","HashType","mirrorVariantType","type","OpenParen","CloseParen","OpenCurly","CloseCurly","OpenSquare","CloseSquare","isToken","x","isArray","stringify","tokens","buffer","APOSTROPHE","ASTERISK","BACKSPACE","CARRIAGE_RETURN","CHARACTER_TABULATION","COLON","COMMA","COMMERCIAL_AT","DELETE","EXCLAMATION_MARK","FORM_FEED","FULL_STOP","GREATER_THAN_SIGN","HYPHEN_MINUS","INFORMATION_SEPARATOR_ONE","LATIN_CAPITAL_LETTER_E","LATIN_SMALL_LETTER_E","LEFT_CURLY_BRACKET","LEFT_PARENTHESIS","LEFT_SQUARE_BRACKET","LESS_THAN_SIGN","LINE_FEED","LINE_TABULATION","LOW_LINE","MAXIMUM_ALLOWED_CODEPOINT","NULL","NUMBER_SIGN","PERCENTAGE_SIGN","PLUS_SIGN","QUOTATION_MARK","REPLACEMENT_CHARACTER","REVERSE_SOLIDUS","RIGHT_CURLY_BRACKET","RIGHT_PARENTHESIS","RIGHT_SQUARE_BRACKET","SEMICOLON","SHIFT_OUT","SOLIDUS","SPACE","DIGIT_0","DIGIT_1","DIGIT_2","DIGIT_3","DIGIT_4","DIGIT_5","DIGIT_6","DIGIT_7","DIGIT_8","DIGIT_9","checkIfFourCodePointsWouldStartCDO","ctx","reader","digitsLow","digitsHigh","isDigitCodePoint","search","letterUppercaseLow","letterUppercaseHigh","isUppercaseLetterCodePoint","letterLowercaseLow","letterLowercaseHigh","isLowercaseLetterCodePoint","afUppercaseHigh","afLowercaseHigh","isHexDigitCodePoint","isLetterCodePoint","nonASCIILow","isNonASCIICodePoint","isIdentStartCodePoint","isIdentCodePoint","isNonPrintableCodePoint","isNewLine","isWhitespace","surrogateLow","surrogateHigh","isSurrogate","checkIfTwoCodePointsAreAValidEscape","checkIfThreeCodePointsWouldStartAnIdentSequence","checkIfThreeCodePointsWouldStartANumber","checkIfTwoCodePointsStartAComment","checkIfThreeCodePointsWouldStartCDC","consumeComment","onParseError","message","state","Comment","consumeEscapedCodePoint","hexSequence","push","codePointLiteral","parseInt","String","fromCharCode","consumeIdentSequence","result","consumeHashToken","hashType","Unrestricted","ID","identSequence","Hash","value","Delim","consumeNumber","Integer","repr","newPart","consumeDigits","Number","convertCodePointsToNumber","codePoints","s","iCodePoints","d","fCodePoints","f","t","eCodePoints","e","digitCodePointsToInteger","Math","pow","consumeNumericToken","numberValue","unit","Dimension","Percentage","consumeWhiteSpace","Whitespace","consumeStringToken","first","Error","next","BadString","u","U","r","R","l","L","checkIfCodePointsMatchURLIdent","consumeBadURL","consumeUrlToken","string","URL","BadURL","consumeIdentLikeToken","Ident","read","firstIsWhitespace","secondIsWhitespace","firstNonWhitespace","Function","tokenizer","input","options","css","valueOf","endOfFile","nextToken","commentsAreTokens","peeked","EOF","Comma","Colon","Semicolon","CDC","CDO","AtKeyword","cloneTokens","globalThis","structuredClone","JSON","parse"],"mappings":"MAEaA,MAAM,CAAA;EAClBC,MAAM,CAAA;AACNC,EAAAA,MAAM,GAAG,EAAE,CAAA;AACXC,EAAAA,eAAe,GAAkB,EAAE,CAAA;AACnCC,EAAAA,MAAM,GAAG,CAAC,CAAA;AAEVC,EAAAA,mBAAmB,GAAG,CAAC,CAAA;EACvBC,iBAAiB,GAAG,CAAC,CAAC,CAAA;EAEtBC,WAAA,CAAYL,MAAc,EAAA;IACzB,IAAI,CAACD,MAAM,GAAG,CAAC,CAAA;IACf,IAAI,CAACC,MAAM,GAAGA,MAAM,CAAA;AACpB,IAAA,IAAI,CAACE,MAAM,GAAGF,MAAM,CAACE,MAAM,CAAA;IAE3B,IAAI,CAACD,eAAe,GAAG,IAAIK,KAAK,CAAC,IAAI,CAACJ,MAAM,CAAC,CAAA;AAC7C,IAAA,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,IAAI,CAACL,MAAM,EAAEK,CAAC,EAAE,EAAE;AACrC,MAAA,IAAI,CAACN,eAAe,CAACM,CAAC,CAAC,GAAG,IAAI,CAACP,MAAM,CAACQ,UAAU,CAACD,CAAC,CAAC,CAAA;AACnD,KAAA;AACF,GAAA;AAEAE,EAAAA,iCAAiC,GAAA;AAChC,IAAA,OAAO,IAAI,CAACV,MAAM,GAAG,CAAC,CAAA;AACvB,GAAA;AAEAW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AACzE,oBAAoB,EAAA;AAClC,KAAA,CAAC,CAAA;AACH,GAAA;EAEA,OAAO;AACNqL,IAAAA,SAAS,EAAEA,SAAS;AACpBD,IAAAA,SAAS,EAAEA,SAAAA;GACX,CAAA;AACF;;ACpNM,SAAUW,WAAW,CAAC3K,MAAuB,EAAA;EAClD,IAAK,OAAO4K,UAAU,KAAK,WAAW,IAAK,iBAAiB,IAAIA,UAAU,EAAE;IAC3E,OAAOC,eAAe,CAAC7K,MAAM,CAAC,CAAA;AAC9B,GAAA;EAED,OAAO8K,IAAI,CAACC,KAAK,CAACD,IAAI,CAAC/K,SAAS,CAACC,MAAM,CAAC,CAAC,CAAA;AAC1C;;;;"} \ No newline at end of file diff --git a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts index 950e3c7b7..168bdc580 100644 --- a/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts +++ b/packages/css-tokenizer/dist/interfaces/code-point-reader.d.ts @@ -3,11 +3,9 @@ export type CodePointReader = { representationEnd: number; cursor: number; codePointSource: Array; + source: string; cursorPositionOfLastReadCodePoint(): number; advanceCodePoint(n?: number): any; readCodePoint(n?: number): number | false; unreadCodePoint(n?: number): boolean; - representationString(): string; - resetRepresentation(): any; - slice(start: number, end: number): string; }; diff --git a/packages/css-tokenizer/dist/reader.d.ts b/packages/css-tokenizer/dist/reader.d.ts index ff6969c3b..f92b678fd 100644 --- a/packages/css-tokenizer/dist/reader.d.ts +++ b/packages/css-tokenizer/dist/reader.d.ts @@ -11,7 +11,4 @@ export declare class Reader implements CodePointReader { advanceCodePoint(n?: number): void; readCodePoint(n?: number): number | false; unreadCodePoint(n?: number): boolean; - representationString(): string; - resetRepresentation(): void; - slice(start: number, end: number): string; } diff --git a/packages/css-tokenizer/src/consume/comment.ts b/packages/css-tokenizer/src/consume/comment.ts index 0b82c0d20..ceda8772c 100644 --- a/packages/css-tokenizer/src/consume/comment.ts +++ b/packages/css-tokenizer/src/consume/comment.ts @@ -40,7 +40,7 @@ export function consumeComment(ctx: Context, reader: CodePointReader): TokenComm return [ TokenType.Comment, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, undefined, diff --git a/packages/css-tokenizer/src/consume/hash-token.ts b/packages/css-tokenizer/src/consume/hash-token.ts index 091da84d2..11723e54f 100644 --- a/packages/css-tokenizer/src/consume/hash-token.ts +++ b/packages/css-tokenizer/src/consume/hash-token.ts @@ -24,7 +24,7 @@ export function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDe const identSequence = consumeIdentSequence(ctx, reader); return [ TokenType.Hash, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -36,7 +36,7 @@ export function consumeHashToken(ctx: Context, reader: CodePointReader): TokenDe return [ TokenType.Delim, - reader.representationString(), + '#', reader.representationStart, reader.representationEnd, { diff --git a/packages/css-tokenizer/src/consume/ident-like-token.ts b/packages/css-tokenizer/src/consume/ident-like-token.ts index 69adc5a0c..71f97b352 100644 --- a/packages/css-tokenizer/src/consume/ident-like-token.ts +++ b/packages/css-tokenizer/src/consume/ident-like-token.ts @@ -14,7 +14,7 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To if (reader.codePointSource[reader.cursor] !== LEFT_PARENTHESIS) { return [ TokenType.Ident, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -45,7 +45,7 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To return [ TokenType.Function, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -67,7 +67,7 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To reader.advanceCodePoint(); return [ TokenType.Function, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { diff --git a/packages/css-tokenizer/src/consume/numeric-token.ts b/packages/css-tokenizer/src/consume/numeric-token.ts index a7935ae82..0da13e891 100644 --- a/packages/css-tokenizer/src/consume/numeric-token.ts +++ b/packages/css-tokenizer/src/consume/numeric-token.ts @@ -15,7 +15,7 @@ export function consumeNumericToken(ctx: Context, reader: CodePointReader): Toke return [ TokenType.Dimension, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -32,7 +32,7 @@ export function consumeNumericToken(ctx: Context, reader: CodePointReader): Toke return [ TokenType.Percentage, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -44,7 +44,7 @@ export function consumeNumericToken(ctx: Context, reader: CodePointReader): Toke return [ TokenType.Number, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { diff --git a/packages/css-tokenizer/src/consume/string-token.ts b/packages/css-tokenizer/src/consume/string-token.ts index eeadaabe1..9d618b1cd 100644 --- a/packages/css-tokenizer/src/consume/string-token.ts +++ b/packages/css-tokenizer/src/consume/string-token.ts @@ -10,9 +10,6 @@ export function consumeStringToken(ctx: Context, reader: CodePointReader): Token let result = ''; const first = reader.readCodePoint(); - if (first === false) { - throw new Error('Unexpected EOF'); - } // eslint-disable-next-line no-constant-condition while (true) { @@ -28,7 +25,7 @@ export function consumeStringToken(ctx: Context, reader: CodePointReader): Token ], }); - return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }]; + return [TokenType.String, reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { value: result }]; } if (isNewLine(next)) { @@ -45,11 +42,11 @@ export function consumeStringToken(ctx: Context, reader: CodePointReader): Token } reader.unreadCodePoint(); - return [TokenType.BadString, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + return [TokenType.BadString, reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, undefined]; } if (next === first) { - return [TokenType.String, reader.representationString(), reader.representationStart, reader.representationEnd, { value: result }]; + return [TokenType.String, reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { value: result }]; } if (next === REVERSE_SOLIDUS) { diff --git a/packages/css-tokenizer/src/consume/url-token.ts b/packages/css-tokenizer/src/consume/url-token.ts index 5ac3623ad..172a4e97a 100644 --- a/packages/css-tokenizer/src/consume/url-token.ts +++ b/packages/css-tokenizer/src/consume/url-token.ts @@ -28,7 +28,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.URL, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -41,7 +41,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL reader.advanceCodePoint(); return [ TokenType.URL, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -66,7 +66,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.URL, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -79,7 +79,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL reader.advanceCodePoint(); return [ TokenType.URL, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, { @@ -91,7 +91,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL consumeBadURL(ctx, reader); return [ TokenType.BadURL, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, undefined, @@ -113,7 +113,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.BadURL, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, undefined, @@ -141,7 +141,7 @@ export function consumeUrlToken(ctx: Context, reader: CodePointReader): TokenURL return [ TokenType.BadURL, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, undefined, diff --git a/packages/css-tokenizer/src/consume/whitespace-token.ts b/packages/css-tokenizer/src/consume/whitespace-token.ts index 690ad01f4..e2ac9d6e2 100644 --- a/packages/css-tokenizer/src/consume/whitespace-token.ts +++ b/packages/css-tokenizer/src/consume/whitespace-token.ts @@ -15,7 +15,7 @@ export function consumeWhiteSpace(ctx: Context, reader: CodePointReader): TokenW return [ TokenType.Whitespace, - reader.representationString(), + reader.source.slice(reader.representationStart, reader.representationEnd + 1), reader.representationStart, reader.representationEnd, undefined, diff --git a/packages/css-tokenizer/src/interfaces/code-point-reader.ts b/packages/css-tokenizer/src/interfaces/code-point-reader.ts index a35950c04..91c8392a6 100644 --- a/packages/css-tokenizer/src/interfaces/code-point-reader.ts +++ b/packages/css-tokenizer/src/interfaces/code-point-reader.ts @@ -17,9 +17,4 @@ export type CodePointReader = { advanceCodePoint(n?: number) readCodePoint(n?: number): number | false unreadCodePoint(n?: number): boolean - - representationString(): string - resetRepresentation() - - slice(start: number, end: number): string } diff --git a/packages/css-tokenizer/src/reader.ts b/packages/css-tokenizer/src/reader.ts index 55bde1761..6f8b76667 100644 --- a/packages/css-tokenizer/src/reader.ts +++ b/packages/css-tokenizer/src/reader.ts @@ -14,9 +14,9 @@ export class Reader implements CodePointReader { this.source = source; this.length = source.length; - this.codePointSource = new Array(this.length); - for (let i = 0; i < this.length; i++) { - this.codePointSource[i] = this.source.charCodeAt(i); + this.codePointSource = []; + for (let i = 0; i < source.length; i++) { + this.codePointSource.push(source.charCodeAt(i)); } } @@ -51,17 +51,4 @@ export class Reader implements CodePointReader { return true; } - - representationString(): string { - return this.source.slice(this.representationStart, this.representationEnd + 1); - } - - resetRepresentation() { - this.representationStart = this.cursor; - this.representationEnd = -1; - } - - slice(start: number, end: number): string { - return this.source.slice(start, end); - } } diff --git a/packages/css-tokenizer/src/tokenizer.ts b/packages/css-tokenizer/src/tokenizer.ts index 40910119f..67c3497cf 100644 --- a/packages/css-tokenizer/src/tokenizer.ts +++ b/packages/css-tokenizer/src/tokenizer.ts @@ -3,8 +3,8 @@ import { checkIfThreeCodePointsWouldStartAnIdentSequence } from './checks/three- import { checkIfThreeCodePointsWouldStartANumber } from './checks/three-code-points-would-start-number'; import { checkIfTwoCodePointsStartAComment } from './checks/two-code-points-start-comment'; import { checkIfThreeCodePointsWouldStartCDC } from './checks/three-code-points-would-start-cdc'; -import { APOSTROPHE, CARRIAGE_RETURN, CHARACTER_TABULATION, COLON, COMMA, COMMERCIAL_AT, DIGIT_0, DIGIT_1, DIGIT_2, DIGIT_3, DIGIT_4, DIGIT_5, DIGIT_6, DIGIT_7, DIGIT_8, DIGIT_9, FORM_FEED, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, LINE_FEED, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON, SPACE } from './code-points/code-points'; -import { isIdentStartCodePoint } from './code-points/ranges'; +import { APOSTROPHE, CARRIAGE_RETURN, CHARACTER_TABULATION, COLON, COMMA, COMMERCIAL_AT, FORM_FEED, FULL_STOP, HYPHEN_MINUS, LEFT_CURLY_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LESS_THAN_SIGN, LINE_FEED, NUMBER_SIGN, PLUS_SIGN, QUOTATION_MARK, REVERSE_SOLIDUS, RIGHT_CURLY_BRACKET, RIGHT_PARENTHESIS, RIGHT_SQUARE_BRACKET, SEMICOLON, SPACE } from './code-points/code-points'; +import { isDigitCodePoint, isIdentStartCodePoint } from './code-points/ranges'; import { consumeComment } from './consume/comment'; import { consumeHashToken } from './consume/hash-token'; import { consumeIdentSequence } from './consume/ident-sequence'; @@ -35,14 +35,16 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } function nextToken(): CSSToken | undefined { - reader.resetRepresentation(); + reader.representationStart = reader.cursor; + reader.representationEnd = -1; if (checkIfTwoCodePointsStartAComment(ctx, reader)) { if (options?.commentsAreTokens) { return consumeComment(ctx, reader); } else { consumeComment(ctx, reader); - reader.resetRepresentation(); + reader.representationStart = reader.cursor; + reader.representationEnd = -1; } } @@ -55,72 +57,65 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken return consumeIdentLikeToken(ctx, reader); } + if (isDigitCodePoint(peeked)) { + return consumeNumericToken(ctx, reader); + } + // Simple, one character tokens: switch (peeked) { - case COMMA: { + case COMMA: reader.advanceCodePoint(); - return [TokenType.Comma, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case COLON: { + return [TokenType.Comma, ',', reader.representationStart, reader.representationEnd, undefined]; + + case COLON: reader.advanceCodePoint(); - return [TokenType.Colon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case SEMICOLON: { + return [TokenType.Colon, ':', reader.representationStart, reader.representationEnd, undefined]; + + case SEMICOLON: reader.advanceCodePoint(); - return [TokenType.Semicolon, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_PARENTHESIS: { + return [TokenType.Semicolon, ';', reader.representationStart, reader.representationEnd, undefined]; + + case LEFT_PARENTHESIS: reader.advanceCodePoint(); - return [TokenType.OpenParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_PARENTHESIS: { + return [TokenType.OpenParen, '(', reader.representationStart, reader.representationEnd, undefined]; + + case RIGHT_PARENTHESIS: reader.advanceCodePoint(); - return [TokenType.CloseParen, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_SQUARE_BRACKET: { + return [TokenType.CloseParen, ')', reader.representationStart, reader.representationEnd, undefined]; + + case LEFT_SQUARE_BRACKET: reader.advanceCodePoint(); - return [TokenType.OpenSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_SQUARE_BRACKET: { + return [TokenType.OpenSquare, '[', reader.representationStart, reader.representationEnd, undefined]; + + case RIGHT_SQUARE_BRACKET: reader.advanceCodePoint(); - return [TokenType.CloseSquare, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case LEFT_CURLY_BRACKET: { + return [TokenType.CloseSquare, ']', reader.representationStart, reader.representationEnd, undefined]; + + case LEFT_CURLY_BRACKET: reader.advanceCodePoint(); - return [TokenType.OpenCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } - case RIGHT_CURLY_BRACKET: { + return [TokenType.OpenCurly, '{', reader.representationStart, reader.representationEnd, undefined]; + + case RIGHT_CURLY_BRACKET: reader.advanceCodePoint(); - return [TokenType.CloseCurly, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; - } + return [TokenType.CloseCurly, '}', reader.representationStart, reader.representationEnd, undefined]; + case APOSTROPHE: case QUOTATION_MARK: return consumeStringToken(ctx, reader); + case NUMBER_SIGN: return consumeHashToken(ctx, reader); case PLUS_SIGN: - case FULL_STOP: { + case FULL_STOP: if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { return consumeNumericToken(ctx, reader); } reader.advanceCodePoint(); - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { - value: reader.representationString(), + return [TokenType.Delim, reader.source[reader.representationStart], reader.representationStart, reader.representationEnd, { + value: reader.source[reader.representationStart], }]; - } - case DIGIT_0: - case DIGIT_1: - case DIGIT_2: - case DIGIT_3: - case DIGIT_4: - case DIGIT_5: - case DIGIT_6: - case DIGIT_7: - case DIGIT_8: - case DIGIT_9: - return consumeNumericToken(ctx, reader); case LINE_FEED: case CARRIAGE_RETURN: @@ -129,7 +124,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken case SPACE: return consumeWhiteSpace(ctx, reader); - case HYPHEN_MINUS: { + case HYPHEN_MINUS: if (checkIfThreeCodePointsWouldStartANumber(ctx, reader)) { return consumeNumericToken(ctx, reader); } @@ -137,7 +132,7 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken if (checkIfThreeCodePointsWouldStartCDC(ctx, reader)) { reader.advanceCodePoint(3); - return [TokenType.CDC, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + return [TokenType.CDC, '-->', reader.representationStart, reader.representationEnd, undefined]; } if (checkIfThreeCodePointsWouldStartAnIdentSequence(ctx, reader)) { @@ -145,40 +140,37 @@ export function tokenizer(input: { css: Stringer }, options?: { commentsAreToken } reader.advanceCodePoint(); - return [TokenType.Delim, reader.representationString(), reader.representationStart, reader.representationEnd, { + return [TokenType.Delim, '-', reader.representationStart, reader.representationEnd, { value: '-', }]; - } - case LESS_THAN_SIGN: { + case LESS_THAN_SIGN: if (checkIfFourCodePointsWouldStartCDO(ctx, reader)) { reader.advanceCodePoint(4); - return [TokenType.CDO, reader.representationString(), reader.representationStart, reader.representationEnd, undefined]; + return [TokenType.CDO, ' @@ -28,7 +28,11 @@ bar"; #1 {} -#foo {} +#foo { + width: c\\61 lc(10% * 10px); +} + +.fooz\\{\\} {} .foo { margin: 0; @@ -37,6 +41,34 @@ bar"; line-height: 1.2; } +@media (min-width: 768px) and (max-width: 991px) { + .visible-sm { + display: block !important; + } + + table.visible-sm { + display: table !important; + } + + tr.visible-sm { + display: table-row !important; + } + + th.visible-sm, + td.visible-sm { + display: table-cell !important; + } +} + +@media (min-width: 768px) and (max-width: 991px) { + .visible-sm-block { + display: block !important; + } +} +`; + +const largeSource = ` +${smallSource} ${bootstrapSource} ${openPropsSource} `; @@ -85,40 +117,15 @@ function csstoolsLargeSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); + console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); console.log('-----------------------------------------------'); console.log('95th', results[949]); console.log('50th', results[499]); - console.log('5th', results[49]); + console.log('5th ', results[49]); console.log('deviation', results[949] - results[49]); } function csstoolsSmallSource() { - const source = `@media (min-width: 768px) and (max-width: 991px) { - .visible-sm { - display: block !important; - } - - table.visible-sm { - display: table !important; - } - - tr.visible-sm { - display: table-row !important; - } - - th.visible-sm, - td.visible-sm { - display: table-cell !important; - } -} - -@media (min-width: 768px) and (max-width: 991px) { - .visible-sm-block { - display: block !important; - } -}`; - const results = []; let tokenStreamLength = 0; @@ -128,11 +135,11 @@ function csstoolsSmallSource() { { const t = tokenizer( { - css: source, + css: smallSource, }, { - onParseError: (err) => { - throw new Error(JSON.stringify(err)); + onParseError: () => { + // noop }, }, ); @@ -162,11 +169,11 @@ function csstoolsSmallSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); + console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); console.log('-----------------------------------------------'); console.log('95th', results[949]); console.log('50th', results[499]); - console.log('5th', results[49]); + console.log('5th ', results[49]); console.log('deviation', results[949] - results[49]); } @@ -208,40 +215,15 @@ function postcssLargeSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); + console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); console.log('-----------------------------------------------'); console.log('95th', results[949]); console.log('50th', results[499]); - console.log('5th', results[49]); + console.log('5th ', results[49]); console.log('deviation', results[949] - results[49]); } function postcssSmallSource() { - const source = `@media (min-width: 768px) and (max-width: 991px) { - .visible-sm { - display: block !important; - } - - table.visible-sm { - display: table !important; - } - - tr.visible-sm { - display: table-row !important; - } - - th.visible-sm, - td.visible-sm { - display: table-cell !important; - } -} - -@media (min-width: 768px) and (max-width: 991px) { - .visible-sm-block { - display: block !important; - } -}`; - const results = []; let tokenStreamLength = 0; @@ -250,7 +232,7 @@ function postcssSmallSource() { { const t = postcssTokenizer( { - css: source, + css: smallSource, }, ); @@ -279,15 +261,15 @@ function postcssSmallSource() { console.log('tokens', tokenStreamLength); console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th', (tokenStreamLength / results[49]) / 1000); + console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); console.log('-----------------------------------------------'); console.log('95th', results[949]); console.log('50th', results[499]); - console.log('5th', results[49]); + console.log('5th ', results[49]); console.log('deviation', results[949] - results[49]); } -await new Promise((resolve) => setTimeout(resolve(), 1000)); +await new Promise((resolve) => setTimeout(resolve(), 100)); csstoolsSmallSource(); await new Promise((resolve) => setTimeout(resolve(), 1000)); postcssSmallSource(); @@ -295,24 +277,45 @@ await new Promise((resolve) => setTimeout(resolve(), 1000)); csstoolsLargeSource(); await new Promise((resolve) => setTimeout(resolve(), 1000)); postcssLargeSource(); -await new Promise((resolve) => setTimeout(resolve(), 1000)); // Last result: // -------------- csstools tokenizer ------------- -// tokens 37088 -// tokens/μs @ 95th 10.38213287435934 -// tokens/μs @ 50th 11.020875148827852 +// tokens 252 +// tokens/μs @ 95th 3.3863612154143867 +// tokens/μs @ 50th 17.530760432561532 +// tokens/μs @ 5th 21.52151425313569 // ----------------------------------------------- -// 95th 3.5722910165786743 -// 90th 3.4610829949378967 -// 50th 3.365249991416931 -// deviation 0.24970799684524536 +// 95th 0.0744161605834961 +// 50th 0.014374732971191406 +// 5th 0.011709213256835938 +// deviation 0.06270694732666016 // -------------- postcss tokenizer ------------- -// tokens 27045 -// tokens/μs @ 95th 18.530318414584258 -// tokens/μs @ 50th 26.92161819321654 -// ---------------------------------------------- -// 95th 1.459500014781952 -// 90th 1.2470839619636536 -// 50th 1.0045830011367798 -// deviation 0.4862080216407776 +// tokens 214 +// tokens/μs @ 95th 6.22542000277431 +// tokens/μs @ 50th 7.71170747130387 +// tokens/μs @ 5th 35.41871422934259 +// ----------------------------------------------- +// 95th 0.03437519073486328 +// 50th 0.027750015258789062 +// 5th 0.006042003631591797 +// deviation 0.028333187103271484 +// -------------- csstools tokenizer ------------- +// tokens 87701 +// tokens/μs @ 95th 13.761066815747991 +// tokens/μs @ 50th 18.546012582330164 +// tokens/μs @ 5th 18.881747729614577 +// ----------------------------------------------- +// 95th 6.373125076293945 +// 50th 4.728833198547363 +// 5th 4.644750118255615 +// deviation 1.72837495803833 +// -------------- postcss tokenizer ------------- +// tokens 66238 +// tokens/μs @ 95th 18.133943098715402 +// tokens/μs @ 50th 25.854859639486747 +// tokens/μs @ 5th 26.910528838738287 +// ----------------------------------------------- +// 95th 3.652708053588867 +// 50th 2.5619168281555176 +// 5th 2.4614157676696777 +// deviation 1.1912922859191895 From 12d0481b03f629cca23023ef28cbb25ce6276119 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sun, 25 Dec 2022 16:40:26 +0100 Subject: [PATCH 10/24] improve benchmarks --- .../test/community/bootstrap-benchmark.mjs | 242 ++++++++++++------ 1 file changed, 170 insertions(+), 72 deletions(-) diff --git a/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs b/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs index 37b226cf7..033712229 100644 --- a/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs +++ b/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs @@ -2,9 +2,34 @@ import { tokenizer, TokenType } from '@csstools/css-tokenizer'; import postcssTokenizer from 'postcss/lib/tokenize'; import fs from 'fs'; +function logResults(label, tokenStreamLength, results) { + console.log(`-------------- ${label} -------------`); + console.log('tokens', tokenStreamLength); + console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); + console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); + console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); + console.log('-----------------------------------------------'); + console.log('95th', results[949]); + console.log('50th', results[499]); + console.log('5th ', results[49]); + console.log('deviation', results[949] - results[49]); +} + const bootstrapSource = fs.readFileSync('./test/community/bootstrap.css').toString(); const openPropsSource = fs.readFileSync('./test/community/open-props.css').toString(); +const tinySources = [ + '.foo', + '10px', + '-1276430.01', + '#bar', + '{ color: rgb(0, 0, 0) }', + '@media (min-width: 300px) {}', + 'calc(10 + 2)', + 'var(--foo)', + '--bar', +]; + const smallSource = ` /* a comment */ @@ -81,6 +106,8 @@ function csstoolsLargeSource() { tokenStreamLength = 0; { + const start = performance.now(); + const t = tokenizer( { css: largeSource, @@ -92,8 +119,6 @@ function csstoolsLargeSource() { }, ); - const start = performance.now(); - // eslint-disable-next-line no-constant-condition while (true) { const token = t.nextToken(); @@ -113,16 +138,7 @@ function csstoolsLargeSource() { return a - b; }); - console.log('-------------- csstools tokenizer -------------'); - console.log('tokens', tokenStreamLength); - console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); - console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); - console.log('-----------------------------------------------'); - console.log('95th', results[949]); - console.log('50th', results[499]); - console.log('5th ', results[49]); - console.log('deviation', results[949] - results[49]); + logResults('csstools tokenizer', tokenStreamLength, results); } function csstoolsSmallSource() { @@ -133,6 +149,8 @@ function csstoolsSmallSource() { tokenStreamLength = 0; { + const start = performance.now(); + const t = tokenizer( { css: smallSource, @@ -144,8 +162,51 @@ function csstoolsSmallSource() { }, ); + // eslint-disable-next-line no-constant-condition + while (true) { + const token = t.nextToken(); + if (token[0] === TokenType.EOF) { + break; + } + + tokenStreamLength++; + } + + const end = performance.now(); + results.push(end - start); + } + } + + results.sort((a, b) => { + return a - b; + }); + + logResults('csstools tokenizer', tokenStreamLength, results); +} + +function csstoolsTinySource() { + const results = []; + let tokenStreamLength = 0; + + for (let i = 0; i < 1000; i++) { + tokenStreamLength = 0; + + for (let j = 0; j < tinySources.length; j++) { + const source = tinySources[j]; + const start = performance.now(); + const t = tokenizer( + { + css: source, + }, + { + onParseError: () => { + // noop + }, + }, + ); + // eslint-disable-next-line no-constant-condition while (true) { const token = t.nextToken(); @@ -165,16 +226,7 @@ function csstoolsSmallSource() { return a - b; }); - console.log('-------------- csstools tokenizer -------------'); - console.log('tokens', tokenStreamLength); - console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); - console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); - console.log('-----------------------------------------------'); - console.log('95th', results[949]); - console.log('50th', results[499]); - console.log('5th ', results[49]); - console.log('deviation', results[949] - results[49]); + logResults('csstools tokenizer', tokenStreamLength, results); } function postcssLargeSource() { @@ -184,14 +236,14 @@ function postcssLargeSource() { for (let i = 0; i < 1000; i++) { tokenStreamLength = 0; { + const start = performance.now(); + const t = postcssTokenizer( { css: largeSource, }, ); - const start = performance.now(); - // eslint-disable-next-line no-constant-condition while (true) { const token = t.nextToken(); @@ -211,16 +263,7 @@ function postcssLargeSource() { return a - b; }); - console.log('-------------- postcss tokenizer -------------'); - console.log('tokens', tokenStreamLength); - console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); - console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); - console.log('-----------------------------------------------'); - console.log('95th', results[949]); - console.log('50th', results[499]); - console.log('5th ', results[49]); - console.log('deviation', results[949] - results[49]); + logResults('postcss tokenizer', tokenStreamLength, results); } function postcssSmallSource() { @@ -230,14 +273,54 @@ function postcssSmallSource() { for (let i = 0; i < 1000; i++) { tokenStreamLength = 0; { + const start = performance.now(); + const t = postcssTokenizer( { css: smallSource, }, ); + // eslint-disable-next-line no-constant-condition + while (true) { + const token = t.nextToken(); + if (!token) { + break; + } + + tokenStreamLength++; + } + + const end = performance.now(); + results.push(end - start); + } + } + + results.sort((a, b) => { + return a - b; + }); + + logResults('postcss tokenizer', tokenStreamLength, results); +} + +function postcssTinySource() { + const results = []; + let tokenStreamLength = 0; + + for (let i = 0; i < 1000; i++) { + tokenStreamLength = 0; + + for (let j = 0; j < tinySources.length; j++) { + const source = tinySources[j]; + const start = performance.now(); + const t = postcssTokenizer( + { + css: source, + }, + ); + // eslint-disable-next-line no-constant-condition while (true) { const token = t.nextToken(); @@ -257,19 +340,14 @@ function postcssSmallSource() { return a - b; }); - console.log('-------------- postcss tokenizer -------------'); - console.log('tokens', tokenStreamLength); - console.log('tokens/μs @ 95th', (tokenStreamLength / results[949]) / 1000); - console.log('tokens/μs @ 50th', (tokenStreamLength / results[499]) / 1000); - console.log('tokens/μs @ 5th ', (tokenStreamLength / results[49]) / 1000); - console.log('-----------------------------------------------'); - console.log('95th', results[949]); - console.log('50th', results[499]); - console.log('5th ', results[49]); - console.log('deviation', results[949] - results[49]); + logResults('postcss tokenizer', tokenStreamLength, results); } await new Promise((resolve) => setTimeout(resolve(), 100)); +csstoolsTinySource(); +await new Promise((resolve) => setTimeout(resolve(), 1000)); +postcssTinySource(); +await new Promise((resolve) => setTimeout(resolve(), 1000)); csstoolsSmallSource(); await new Promise((resolve) => setTimeout(resolve(), 1000)); postcssSmallSource(); @@ -280,42 +358,62 @@ postcssLargeSource(); // Last result: // -------------- csstools tokenizer ------------- +// tokens 43 +// tokens/μs @ 95th 147.10854159869496 +// tokens/μs @ 50th 171.76673523809524 +// tokens/μs @ 5th 206.82921100917432 +// ----------------------------------------------- +// 95th 0.0002923011779785156 +// 50th 0.0002503395080566406 +// 5th 0.0002079010009765625 +// deviation 0.00008440017700195312 +// -------------- postcss tokenizer ------------- +// tokens 24 +// tokens/μs @ 95th 191.3750874524715 +// tokens/μs @ 50th 192.10552671755724 +// tokens/μs @ 5th 289.2623448275862 +// ----------------------------------------------- +// 95th 0.00012540817260742188 +// 50th 0.00012493133544921875 +// 5th 0.00008296966552734375 +// deviation 0.000042438507080078125 +// -------------- csstools tokenizer ------------- // tokens 252 -// tokens/μs @ 95th 3.3863612154143867 -// tokens/μs @ 50th 17.530760432561532 -// tokens/μs @ 5th 21.52151425313569 +// tokens/μs @ 95th 2.4858291423249512 +// tokens/μs @ 50th 12.840642029302428 +// tokens/μs @ 5th 15.468529313625055 // ----------------------------------------------- -// 95th 0.0744161605834961 -// 50th 0.014374732971191406 -// 5th 0.011709213256835938 -// deviation 0.06270694732666016 +// 95th 0.10137462615966797 +// 50th 0.019625186920166016 +// 5th 0.016291141510009766 +// deviation 0.0850834846496582 // -------------- postcss tokenizer ------------- // tokens 214 -// tokens/μs @ 95th 6.22542000277431 -// tokens/μs @ 50th 7.71170747130387 -// tokens/μs @ 5th 35.41871422934259 +// tokens/μs @ 95th 3.203975983951225 +// tokens/μs @ 50th 7.9627850463973315 +// tokens/μs @ 5th 25.67745325552123 // ----------------------------------------------- -// 95th 0.03437519073486328 -// 50th 0.027750015258789062 -// 5th 0.006042003631591797 -// deviation 0.028333187103271484 +// 95th 0.06679201126098633 +// 50th 0.026875019073486328 +// 5th 0.008334159851074219 +// deviation 0.05845785140991211 // -------------- csstools tokenizer ------------- // tokens 87701 -// tokens/μs @ 95th 13.761066815747991 -// tokens/μs @ 50th 18.546012582330164 -// tokens/μs @ 5th 18.881747729614577 +// tokens/μs @ 95th 9.514877130822835 +// tokens/μs @ 50th 11.584315742427334 +// tokens/μs @ 5th 11.894349579771065 // ----------------------------------------------- -// 95th 6.373125076293945 -// 50th 4.728833198547363 -// 5th 4.644750118255615 -// deviation 1.72837495803833 +// 95th 9.217249870300293 +// 50th 7.570667266845703 +// 5th 7.373332977294922 +// deviation 1.843916893005371 // -------------- postcss tokenizer ------------- // tokens 66238 -// tokens/μs @ 95th 18.133943098715402 -// tokens/μs @ 50th 25.854859639486747 -// tokens/μs @ 5th 26.910528838738287 +// tokens/μs @ 95th 18.456481036392354 +// tokens/μs @ 50th 25.63886291747939 +// tokens/μs @ 5th 26.946553538250367 // ----------------------------------------------- -// 95th 3.652708053588867 -// 50th 2.5619168281555176 -// 5th 2.4614157676696777 -// deviation 1.1912922859191895 +// 95th 3.5888748168945312 +// 50th 2.5834999084472656 +// 5th 2.458125114440918 +// deviation 1.1307497024536133 From ae18cf9c0def2cb1ea8c7d8f5519582cfdd55165 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Mon, 26 Dec 2022 07:52:04 +0100 Subject: [PATCH 11/24] little bit faster --- packages/css-tokenizer/dist/index.cjs | 2 +- packages/css-tokenizer/dist/index.mjs | 2 +- packages/css-tokenizer/src/reader.ts | 6 +- .../test/community/bootstrap-benchmark.mjs | 76 +++++++++---------- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index bc28eb693..34397314b 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1 @@ -"use strict";class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=[];for(let o=0;o=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===g)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===T)}function isNewLine(e){switch(e){case x:case i:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case x:case i:case S:case c:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,o){return o.codePointSource[o.cursor]===N&&o.codePointSource[o.cursor+1]!==x}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.codePointSource[o.cursor]===T?o.codePointSource[o.cursor+1]===T||(!!isIdentStartCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===N&&o.codePointSource[o.cursor+2]!==x):!!isIdentStartCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)}function checkIfThreeCodePointsWouldStartANumber(e,o){return o.codePointSource[o.cursor]===w||o.codePointSource[o.cursor]===T?!!isDigitCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===P&&isDigitCodePoint(o.codePointSource[o.cursor+2]):o.codePointSource[o.cursor]===P?isDigitCodePoint(o.codePointSource[o.cursor+1]):!!isDigitCodePoint(o.codePointSource[o.cursor])}function checkIfTwoCodePointsStartAComment(e,o){return o.codePointSource[o.cursor]===B&&o.codePointSource[o.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,o){return o.codePointSource[o.cursor]===T&&o.codePointSource[o.cursor+1]===T&&o.codePointSource[o.cursor+2]===h}function consumeComment(e,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(!1===t){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(t===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,o){const t=o.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:o.representationStart,end:o.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==o.codePointSource[o.cursor]&&isHexDigitCodePoint(o.codePointSource[o.cursor])&&e.length<6;)e.push(o.codePointSource[o.cursor]),o.advanceCodePoint();isWhitespace(o.codePointSource[o.cursor])&&o.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:X<=(r=n)&&r<=Y||n>I?b:n}var r;return t}function consumeIdentSequence(e,o){const t=[];for(;;)if(isIdentCodePoint(o.codePointSource[o.cursor]))t.push(o.codePointSource[o.cursor]),o.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,o))return t;o.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,o))}}function consumeHashToken(e,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=t.ID);const n=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n),type:r}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let t=exports.NumberType.Integer;for(o.codePointSource[o.cursor]!==w&&o.codePointSource[o.cursor]!==T||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===T||o.codePointSource[o.cursor+1]===w)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),t]}function consumeNumericToken(e,o){const t=consumeNumber(0,o);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:t[0],type:t[1],unit:String.fromCharCode(...r)}]}return o.codePointSource[o.cursor]===D?(o.advanceCodePoint(),[exports.TokenType.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0]}]):[exports.TokenType.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0],type:t[1]}]}function consumeWhiteSpace(e,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[exports.TokenType.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(e,o){let t="";const r=o.readCodePoint();for(;;){const n=o.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isNewLine(n))return e.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[exports.TokenType.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(n===r)return[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(n!==N)t+=String.fromCharCode(n);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}t+=String.fromCharCode(consumeEscapedCodePoint(e,o))}}}const $="u".charCodeAt(0),ee="U".charCodeAt(0),oe="r".charCodeAt(0),te="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,o){return 3===o.length&&((o[0]===$||o[0]===ee)&&((o[1]===oe||o[1]===te)&&(o[2]===re||o[2]===ne)))}function consumeBadURL(e,o){for(;;){if(void 0===o.codePointSource[o.cursor])return;if(o.codePointSource[o.cursor]===W)return void o.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,o)?(o.advanceCodePoint(),consumeEscapedCodePoint(e,o)):o.advanceCodePoint()}}function consumeUrlToken(e,o){consumeWhiteSpace(0,o);let t="";for(;;){if(void 0===o.codePointSource[o.cursor])return e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(o.codePointSource[o.cursor]===W)return o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):o.codePointSource[o.cursor]===W?(o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):(consumeBadURL(e,o),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===L||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===E||((n=o.codePointSource[o.cursor])===y||n===p||U<=n&&n<=s||V<=n&&n<=l))return consumeBadURL(e,o),e.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){t+=String.fromCharCode(consumeEscapedCodePoint(e,o));continue}return consumeBadURL(e,o),e.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}t+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var n}function consumeIdentLikeToken(e,o){const t=consumeIdentSequence(e,o);if(o.codePointSource[o.cursor]!==E)return[exports.TokenType.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];if(checkIfCodePointsMatchURLIdent(0,t)){o.advanceCodePoint();let n=0;for(;;){const e=isWhitespace(o.codePointSource[o.cursor]),s=isWhitespace(o.codePointSource[o.cursor+1]);if(e&&s){n+=2,o.advanceCodePoint(2);continue}const i=e?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(i===L||i===r)return n>0&&o.advanceCodePoint(n),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];break}return n>0&&o.advanceCodePoint(n),consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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.stringify=function stringify(...e){let o="";for(let t=0;t{})};return{nextToken:function nextToken(){if(n.representationStart=n.cursor,n.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,n)){if(null!=o&&o.commentsAreTokens)return consumeComment(s,n);consumeComment(s,n),n.representationStart=n.cursor,n.representationEnd=-1}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(s,n);if(isDigitCodePoint(e))return consumeNumericToken(s,n);switch(e){case d:return n.advanceCodePoint(),[exports.TokenType.Comma,",",n.representationStart,n.representationEnd,void 0];case a:return n.advanceCodePoint(),[exports.TokenType.Colon,":",n.representationStart,n.representationEnd,void 0];case q:return n.advanceCodePoint(),[exports.TokenType.Semicolon,";",n.representationStart,n.representationEnd,void 0];case E:return n.advanceCodePoint(),[exports.TokenType.OpenParen,"(",n.representationStart,n.representationEnd,void 0];case W:return n.advanceCodePoint(),[exports.TokenType.CloseParen,")",n.representationStart,n.representationEnd,void 0];case v:return n.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",n.representationStart,n.representationEnd,void 0];case F:return n.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",n.representationStart,n.representationEnd,void 0];case f:return n.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",n.representationStart,n.representationEnd,void 0];case R:return n.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",n.representationStart,n.representationEnd,void 0];case r:case L:return consumeStringToken(s,n);case O:return consumeHashToken(s,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]);case x:case i:case S:case c:case H:return consumeWhiteSpace(0,n);case T:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,"-",n.representationStart,n.representationEnd,{value:"-"}]);case A:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",n.representationStart,n.representationEnd,void 0]):(n.advanceCodePoint(),[exports.TokenType.Delim,"<",n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(s,n);return[exports.TokenType.AtKeyword,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,"@",n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),s.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,"\\",n.representationStart,n.representationEnd,{value:"\\"}])}return n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; +"use strict";class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===g)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===T)}function isNewLine(e){switch(e){case x:case i:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case x:case i:case S:case c:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,o){return o.codePointSource[o.cursor]===N&&o.codePointSource[o.cursor+1]!==x}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.codePointSource[o.cursor]===T?o.codePointSource[o.cursor+1]===T||(!!isIdentStartCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===N&&o.codePointSource[o.cursor+2]!==x):!!isIdentStartCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)}function checkIfThreeCodePointsWouldStartANumber(e,o){return o.codePointSource[o.cursor]===w||o.codePointSource[o.cursor]===T?!!isDigitCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===P&&isDigitCodePoint(o.codePointSource[o.cursor+2]):o.codePointSource[o.cursor]===P?isDigitCodePoint(o.codePointSource[o.cursor+1]):!!isDigitCodePoint(o.codePointSource[o.cursor])}function checkIfTwoCodePointsStartAComment(e,o){return o.codePointSource[o.cursor]===B&&o.codePointSource[o.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,o){return o.codePointSource[o.cursor]===T&&o.codePointSource[o.cursor+1]===T&&o.codePointSource[o.cursor+2]===h}function consumeComment(e,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(!1===t){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(t===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,o){const t=o.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:o.representationStart,end:o.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==o.codePointSource[o.cursor]&&isHexDigitCodePoint(o.codePointSource[o.cursor])&&e.length<6;)e.push(o.codePointSource[o.cursor]),o.advanceCodePoint();isWhitespace(o.codePointSource[o.cursor])&&o.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:X<=(r=n)&&r<=Y||n>I?b:n}var r;return t}function consumeIdentSequence(e,o){const t=[];for(;;)if(isIdentCodePoint(o.codePointSource[o.cursor]))t.push(o.codePointSource[o.cursor]),o.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,o))return t;o.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,o))}}function consumeHashToken(e,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=t.ID);const n=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n),type:r}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let t=exports.NumberType.Integer;for(o.codePointSource[o.cursor]!==w&&o.codePointSource[o.cursor]!==T||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===T||o.codePointSource[o.cursor+1]===w)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),t]}function consumeNumericToken(e,o){const t=consumeNumber(0,o);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:t[0],type:t[1],unit:String.fromCharCode(...r)}]}return o.codePointSource[o.cursor]===D?(o.advanceCodePoint(),[exports.TokenType.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0]}]):[exports.TokenType.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0],type:t[1]}]}function consumeWhiteSpace(e,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[exports.TokenType.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(e,o){let t="";const r=o.readCodePoint();for(;;){const n=o.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isNewLine(n))return e.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[exports.TokenType.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(n===r)return[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(n!==N)t+=String.fromCharCode(n);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}t+=String.fromCharCode(consumeEscapedCodePoint(e,o))}}}const $="u".charCodeAt(0),ee="U".charCodeAt(0),oe="r".charCodeAt(0),te="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,o){return 3===o.length&&((o[0]===$||o[0]===ee)&&((o[1]===oe||o[1]===te)&&(o[2]===re||o[2]===ne)))}function consumeBadURL(e,o){for(;;){if(void 0===o.codePointSource[o.cursor])return;if(o.codePointSource[o.cursor]===W)return void o.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,o)?(o.advanceCodePoint(),consumeEscapedCodePoint(e,o)):o.advanceCodePoint()}}function consumeUrlToken(e,o){consumeWhiteSpace(0,o);let t="";for(;;){if(void 0===o.codePointSource[o.cursor])return e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(o.codePointSource[o.cursor]===W)return o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):o.codePointSource[o.cursor]===W?(o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):(consumeBadURL(e,o),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===L||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===E||((n=o.codePointSource[o.cursor])===y||n===p||U<=n&&n<=s||V<=n&&n<=l))return consumeBadURL(e,o),e.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){t+=String.fromCharCode(consumeEscapedCodePoint(e,o));continue}return consumeBadURL(e,o),e.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}t+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var n}function consumeIdentLikeToken(e,o){const t=consumeIdentSequence(e,o);if(o.codePointSource[o.cursor]!==E)return[exports.TokenType.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];if(checkIfCodePointsMatchURLIdent(0,t)){o.advanceCodePoint();let n=0;for(;;){const e=isWhitespace(o.codePointSource[o.cursor]),s=isWhitespace(o.codePointSource[o.cursor+1]);if(e&&s){n+=2,o.advanceCodePoint(2);continue}const i=e?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(i===L||i===r)return n>0&&o.advanceCodePoint(n),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];break}return n>0&&o.advanceCodePoint(n),consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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.stringify=function stringify(...e){let o="";for(let t=0;t{})};return{nextToken:function nextToken(){if(n.representationStart=n.cursor,n.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,n)){if(null!=o&&o.commentsAreTokens)return consumeComment(s,n);consumeComment(s,n),n.representationStart=n.cursor,n.representationEnd=-1}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(s,n);if(isDigitCodePoint(e))return consumeNumericToken(s,n);switch(e){case d:return n.advanceCodePoint(),[exports.TokenType.Comma,",",n.representationStart,n.representationEnd,void 0];case a:return n.advanceCodePoint(),[exports.TokenType.Colon,":",n.representationStart,n.representationEnd,void 0];case q:return n.advanceCodePoint(),[exports.TokenType.Semicolon,";",n.representationStart,n.representationEnd,void 0];case E:return n.advanceCodePoint(),[exports.TokenType.OpenParen,"(",n.representationStart,n.representationEnd,void 0];case W:return n.advanceCodePoint(),[exports.TokenType.CloseParen,")",n.representationStart,n.representationEnd,void 0];case v:return n.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",n.representationStart,n.representationEnd,void 0];case F:return n.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",n.representationStart,n.representationEnd,void 0];case f:return n.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",n.representationStart,n.representationEnd,void 0];case R:return n.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",n.representationStart,n.representationEnd,void 0];case r:case L:return consumeStringToken(s,n);case O:return consumeHashToken(s,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]);case x:case i:case S:case c:case H:return consumeWhiteSpace(0,n);case T:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,"-",n.representationStart,n.representationEnd,{value:"-"}]);case A:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",n.representationStart,n.representationEnd,void 0]):(n.advanceCodePoint(),[exports.TokenType.Delim,"<",n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(s,n);return[exports.TokenType.AtKeyword,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,"@",n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),s.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,"\\",n.representationStart,n.representationEnd,{value:"\\"}])}return n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; diff --git a/packages/css-tokenizer/dist/index.mjs b/packages/css-tokenizer/dist/index.mjs index d9cd5d9ef..9c6f1f850 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1 +1 @@ -class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=[];for(let t=0;t=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===U)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case I:case c:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case I:case c:case S:case a:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.codePointSource[t.cursor]===N&&t.codePointSource[t.cursor+1]!==I}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.codePointSource[t.cursor]===l?t.codePointSource[t.cursor+1]===l||(!!isIdentStartCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===N&&t.codePointSource[t.cursor+2]!==I):!!isIdentStartCodePoint(t.codePointSource[t.cursor])||checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.codePointSource[t.cursor]===R||t.codePointSource[t.cursor]===l?!!isDigitCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===P&&isDigitCodePoint(t.codePointSource[t.cursor+2]):t.codePointSource[t.cursor]===P?isDigitCodePoint(t.codePointSource[t.cursor+1]):!!isDigitCodePoint(t.codePointSource[t.cursor])}function checkIfTwoCodePointsStartAComment(e,t){return t.codePointSource[t.cursor]===B&&t.codePointSource[t.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.codePointSource[t.cursor]===l&&t.codePointSource[t.cursor+1]===l&&t.codePointSource[t.cursor+2]===h}function consumeComment(t,o){for(o.advanceCodePoint(2);;){const e=o.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[e.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const o=t.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),y;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==t.codePointSource[t.cursor]&&isHexDigitCodePoint(t.codePointSource[t.cursor])&&e.length<6;)e.push(t.codePointSource[t.cursor]),t.advanceCodePoint();isWhitespace(t.codePointSource[t.cursor])&&t.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?y:X<=(r=n)&&r<=Y||n>O?y:n}var r;return o}function consumeIdentSequence(e,t){const o=[];for(;;)if(isIdentCodePoint(t.codePointSource[t.cursor]))o.push(t.codePointSource[t.cursor]),t.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,t))return o;t.advanceCodePoint(),o.push(consumeEscapedCodePoint(e,t))}}function consumeHashToken(t,r){if(r.advanceCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let n=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(n=o.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.source.slice(r.representationStart,r.representationEnd+1),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,"#",r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,o){let r=t.Integer;for(o.codePointSource[o.cursor]!==R&&o.codePointSource[o.cursor]!==l||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===l||o.codePointSource[o.cursor+1]===R)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),r]}function consumeNumericToken(t,o){const r=consumeNumber(0,o);if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const n=consumeIdentSequence(t,o);return[e.Dimension,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1],unit:String.fromCharCode(...n)}]}return o.codePointSource[o.cursor]===L?(o.advanceCodePoint(),[e.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0]}]):[e.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1]}]}function consumeWhiteSpace(t,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[e.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(t,o){let r="";const n=o.readCodePoint();for(;;){const i=o.readCodePoint();if(!1===i)return t.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(isNewLine(i))return t.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[e.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(i===n)return[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(i!==N)r+=String.fromCharCode(i);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}r+=String.fromCharCode(consumeEscapedCodePoint(t,o))}}}const $="u".charCodeAt(0),ee="U".charCodeAt(0),te="r".charCodeAt(0),oe="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,t){return 3===t.length&&((t[0]===$||t[0]===ee)&&((t[1]===te||t[1]===oe)&&(t[2]===re||t[2]===ne)))}function consumeBadURL(e,t){for(;;){if(void 0===t.codePointSource[t.cursor])return;if(t.codePointSource[t.cursor]===F)return void t.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,t)?(t.advanceCodePoint(),consumeEscapedCodePoint(e,t)):t.advanceCodePoint()}}function consumeUrlToken(t,o){consumeWhiteSpace(0,o);let n="";for(;;){if(void 0===o.codePointSource[o.cursor])return t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(o.codePointSource[o.cursor]===F)return o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):o.codePointSource[o.cursor]===F?(o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):(consumeBadURL(t,o),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===b||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===A||((c=o.codePointSource[o.cursor])===T||c===C||D<=c&&c<=i||V<=c&&c<=f))return consumeBadURL(t,o),t.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){n+=String.fromCharCode(consumeEscapedCodePoint(t,o));continue}return consumeBadURL(t,o),t.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}n+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var c}function consumeIdentLikeToken(t,o){const n=consumeIdentSequence(t,o);if(o.codePointSource[o.cursor]!==A)return[e.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];if(checkIfCodePointsMatchURLIdent(0,n)){o.advanceCodePoint();let i=0;for(;;){const t=isWhitespace(o.codePointSource[o.cursor]),c=isWhitespace(o.codePointSource[o.cursor+1]);if(t&&c){i+=2,o.advanceCodePoint(2);continue}const a=t?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(a===b||a===r)return i>0&&o.advanceCodePoint(i),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&o.advanceCodePoint(i),consumeUrlToken(t,o)}return o.advanceCodePoint(),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(t,o){const n=t.css.valueOf(),i=new Reader(n),C={onParseError:(null==o?void 0:o.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.representationStart=i.cursor,i.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,i)){if(null!=o&&o.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.representationStart=i.cursor,i.representationEnd=-1}const t=i.codePointSource[i.cursor];if(void 0===t)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(t))return consumeIdentLikeToken(C,i);if(isDigitCodePoint(t))return consumeNumericToken(C,i);switch(t){case d:return i.advanceCodePoint(),[e.Comma,",",i.representationStart,i.representationEnd,void 0];case s:return i.advanceCodePoint(),[e.Colon,":",i.representationStart,i.representationEnd,void 0];case x:return i.advanceCodePoint(),[e.Semicolon,";",i.representationStart,i.representationEnd,void 0];case A:return i.advanceCodePoint(),[e.OpenParen,"(",i.representationStart,i.representationEnd,void 0];case F:return i.advanceCodePoint(),[e.CloseParen,")",i.representationStart,i.representationEnd,void 0];case k:return i.advanceCodePoint(),[e.OpenSquare,"[",i.representationStart,i.representationEnd,void 0];case q:return i.advanceCodePoint(),[e.CloseSquare,"]",i.representationStart,i.representationEnd,void 0];case v:return i.advanceCodePoint(),[e.OpenCurly,"{",i.representationStart,i.representationEnd,void 0];case W:return i.advanceCodePoint(),[e.CloseCurly,"}",i.representationStart,i.representationEnd,void 0];case r:case b:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case R:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]);case I:case c:case S:case a:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.advanceCodePoint(3),[e.CDC,"--\x3e",i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),[e.Delim,"-",i.representationStart,i.representationEnd,{value:"-"}]);case g:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.advanceCodePoint(4),[e.CDO,"\x3c!--",i.representationStart,i.representationEnd,void 0]):(i.advanceCodePoint(),[e.Delim,"<",i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(C,i);return[e.AtKeyword,i.source.slice(i.representationStart,i.representationEnd+1),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,"@",i.representationStart,i.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,"\\",i.representationStart,i.representationEnd,{value:"\\"}])}return i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; +class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===U)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case I:case c:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case I:case c:case S:case a:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.codePointSource[t.cursor]===N&&t.codePointSource[t.cursor+1]!==I}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.codePointSource[t.cursor]===l?t.codePointSource[t.cursor+1]===l||(!!isIdentStartCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===N&&t.codePointSource[t.cursor+2]!==I):!!isIdentStartCodePoint(t.codePointSource[t.cursor])||checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.codePointSource[t.cursor]===R||t.codePointSource[t.cursor]===l?!!isDigitCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===P&&isDigitCodePoint(t.codePointSource[t.cursor+2]):t.codePointSource[t.cursor]===P?isDigitCodePoint(t.codePointSource[t.cursor+1]):!!isDigitCodePoint(t.codePointSource[t.cursor])}function checkIfTwoCodePointsStartAComment(e,t){return t.codePointSource[t.cursor]===B&&t.codePointSource[t.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.codePointSource[t.cursor]===l&&t.codePointSource[t.cursor+1]===l&&t.codePointSource[t.cursor+2]===h}function consumeComment(t,o){for(o.advanceCodePoint(2);;){const e=o.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[e.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const o=t.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==t.codePointSource[t.cursor]&&isHexDigitCodePoint(t.codePointSource[t.cursor])&&e.length<6;)e.push(t.codePointSource[t.cursor]),t.advanceCodePoint();isWhitespace(t.codePointSource[t.cursor])&&t.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:X<=(r=n)&&r<=Y||n>O?b:n}var r;return o}function consumeIdentSequence(e,t){const o=[];for(;;)if(isIdentCodePoint(t.codePointSource[t.cursor]))o.push(t.codePointSource[t.cursor]),t.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,t))return o;t.advanceCodePoint(),o.push(consumeEscapedCodePoint(e,t))}}function consumeHashToken(t,r){if(r.advanceCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let n=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(n=o.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.source.slice(r.representationStart,r.representationEnd+1),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,"#",r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,o){let r=t.Integer;for(o.codePointSource[o.cursor]!==R&&o.codePointSource[o.cursor]!==l||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===l||o.codePointSource[o.cursor+1]===R)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),r]}function consumeNumericToken(t,o){const r=consumeNumber(0,o);if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const n=consumeIdentSequence(t,o);return[e.Dimension,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1],unit:String.fromCharCode(...n)}]}return o.codePointSource[o.cursor]===L?(o.advanceCodePoint(),[e.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0]}]):[e.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1]}]}function consumeWhiteSpace(t,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[e.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(t,o){let r="";const n=o.readCodePoint();for(;;){const i=o.readCodePoint();if(!1===i)return t.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(isNewLine(i))return t.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[e.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(i===n)return[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(i!==N)r+=String.fromCharCode(i);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}r+=String.fromCharCode(consumeEscapedCodePoint(t,o))}}}const $="u".charCodeAt(0),ee="U".charCodeAt(0),te="r".charCodeAt(0),oe="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,t){return 3===t.length&&((t[0]===$||t[0]===ee)&&((t[1]===te||t[1]===oe)&&(t[2]===re||t[2]===ne)))}function consumeBadURL(e,t){for(;;){if(void 0===t.codePointSource[t.cursor])return;if(t.codePointSource[t.cursor]===F)return void t.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,t)?(t.advanceCodePoint(),consumeEscapedCodePoint(e,t)):t.advanceCodePoint()}}function consumeUrlToken(t,o){consumeWhiteSpace(0,o);let n="";for(;;){if(void 0===o.codePointSource[o.cursor])return t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(o.codePointSource[o.cursor]===F)return o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):o.codePointSource[o.cursor]===F?(o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):(consumeBadURL(t,o),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===y||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===A||((c=o.codePointSource[o.cursor])===T||c===C||D<=c&&c<=i||V<=c&&c<=f))return consumeBadURL(t,o),t.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){n+=String.fromCharCode(consumeEscapedCodePoint(t,o));continue}return consumeBadURL(t,o),t.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}n+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var c}function consumeIdentLikeToken(t,o){const n=consumeIdentSequence(t,o);if(o.codePointSource[o.cursor]!==A)return[e.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];if(checkIfCodePointsMatchURLIdent(0,n)){o.advanceCodePoint();let i=0;for(;;){const t=isWhitespace(o.codePointSource[o.cursor]),c=isWhitespace(o.codePointSource[o.cursor+1]);if(t&&c){i+=2,o.advanceCodePoint(2);continue}const a=t?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(a===y||a===r)return i>0&&o.advanceCodePoint(i),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&o.advanceCodePoint(i),consumeUrlToken(t,o)}return o.advanceCodePoint(),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(t,o){const n=t.css.valueOf(),i=new Reader(n),C={onParseError:(null==o?void 0:o.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.representationStart=i.cursor,i.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,i)){if(null!=o&&o.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.representationStart=i.cursor,i.representationEnd=-1}const t=i.codePointSource[i.cursor];if(void 0===t)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(t))return consumeIdentLikeToken(C,i);if(isDigitCodePoint(t))return consumeNumericToken(C,i);switch(t){case d:return i.advanceCodePoint(),[e.Comma,",",i.representationStart,i.representationEnd,void 0];case s:return i.advanceCodePoint(),[e.Colon,":",i.representationStart,i.representationEnd,void 0];case x:return i.advanceCodePoint(),[e.Semicolon,";",i.representationStart,i.representationEnd,void 0];case A:return i.advanceCodePoint(),[e.OpenParen,"(",i.representationStart,i.representationEnd,void 0];case F:return i.advanceCodePoint(),[e.CloseParen,")",i.representationStart,i.representationEnd,void 0];case k:return i.advanceCodePoint(),[e.OpenSquare,"[",i.representationStart,i.representationEnd,void 0];case q:return i.advanceCodePoint(),[e.CloseSquare,"]",i.representationStart,i.representationEnd,void 0];case v:return i.advanceCodePoint(),[e.OpenCurly,"{",i.representationStart,i.representationEnd,void 0];case W:return i.advanceCodePoint(),[e.CloseCurly,"}",i.representationStart,i.representationEnd,void 0];case r:case y:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case R:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]);case I:case c:case S:case a:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.advanceCodePoint(3),[e.CDC,"--\x3e",i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),[e.Delim,"-",i.representationStart,i.representationEnd,{value:"-"}]);case g:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.advanceCodePoint(4),[e.CDO,"\x3c!--",i.representationStart,i.representationEnd,void 0]):(i.advanceCodePoint(),[e.Delim,"<",i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(C,i);return[e.AtKeyword,i.source.slice(i.representationStart,i.representationEnd+1),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,"@",i.representationStart,i.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,"\\",i.representationStart,i.representationEnd,{value:"\\"}])}return i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; diff --git a/packages/css-tokenizer/src/reader.ts b/packages/css-tokenizer/src/reader.ts index 6f8b76667..ce06d1ac4 100644 --- a/packages/css-tokenizer/src/reader.ts +++ b/packages/css-tokenizer/src/reader.ts @@ -14,9 +14,9 @@ export class Reader implements CodePointReader { this.source = source; this.length = source.length; - this.codePointSource = []; - for (let i = 0; i < source.length; i++) { - this.codePointSource.push(source.charCodeAt(i)); + this.codePointSource = new Array(this.length); + for (let i = 0; i < this.length; i++) { + this.codePointSource[i] = this.source.charCodeAt(i); } } diff --git a/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs b/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs index 033712229..89fa1efcd 100644 --- a/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs +++ b/packages/css-tokenizer/test/community/bootstrap-benchmark.mjs @@ -359,61 +359,61 @@ postcssLargeSource(); // Last result: // -------------- csstools tokenizer ------------- // tokens 43 -// tokens/μs @ 95th 147.10854159869496 -// tokens/μs @ 50th 171.76673523809524 -// tokens/μs @ 5th 206.82921100917432 +// tokens/μs @ 95th 129.1941776504298 +// tokens/μs @ 50th 172.09453435114503 +// tokens/μs @ 5th 257.6501028571429 // ----------------------------------------------- -// 95th 0.0002923011779785156 -// 50th 0.0002503395080566406 -// 5th 0.0002079010009765625 -// deviation 0.00008440017700195312 +// 95th 0.00033283233642578125 +// 50th 0.0002498626708984375 +// 5th 0.00016689300537109375 +// deviation 0.0001659393310546875 // -------------- postcss tokenizer ------------- // tokens 24 -// tokens/μs @ 95th 191.3750874524715 +// tokens/μs @ 95th 192.10552671755724 // tokens/μs @ 50th 192.10552671755724 // tokens/μs @ 5th 289.2623448275862 // ----------------------------------------------- -// 95th 0.00012540817260742188 +// 95th 0.00012493133544921875 // 50th 0.00012493133544921875 // 5th 0.00008296966552734375 -// deviation 0.000042438507080078125 +// deviation 0.000041961669921875 // -------------- csstools tokenizer ------------- // tokens 252 -// tokens/μs @ 95th 2.4858291423249512 -// tokens/μs @ 50th 12.840642029302428 -// tokens/μs @ 5th 15.468529313625055 +// tokens/μs @ 95th 2.715778269963052 +// tokens/μs @ 50th 14.788099280857375 +// tokens/μs @ 5th 17.58149985029442 // ----------------------------------------------- -// 95th 0.10137462615966797 -// 50th 0.019625186920166016 -// 5th 0.016291141510009766 -// deviation 0.0850834846496582 +// 95th 0.09279108047485352 +// 50th 0.017040729522705078 +// 5th 0.014333248138427734 +// deviation 0.07845783233642578 // -------------- postcss tokenizer ------------- // tokens 214 -// tokens/μs @ 95th 3.203975983951225 -// tokens/μs @ 50th 7.9627850463973315 -// tokens/μs @ 5th 25.67745325552123 +// tokens/μs @ 95th 6.8027424968168315 +// tokens/μs @ 50th 7.901659031286864 +// tokens/μs @ 5th 36.16653461197518 // ----------------------------------------------- -// 95th 0.06679201126098633 -// 50th 0.026875019073486328 -// 5th 0.008334159851074219 -// deviation 0.05845785140991211 +// 95th 0.03145790100097656 +// 50th 0.02708292007446289 +// 5th 0.005917072296142578 +// deviation 0.025540828704833984 // -------------- csstools tokenizer ------------- // tokens 87701 -// tokens/μs @ 95th 9.514877130822835 -// tokens/μs @ 50th 11.584315742427334 -// tokens/μs @ 5th 11.894349579771065 +// tokens/μs @ 95th 10.659602521712898 +// tokens/μs @ 50th 13.135529246644223 +// tokens/μs @ 5th 13.474753513157573 // ----------------------------------------------- -// 95th 9.217249870300293 -// 50th 7.570667266845703 -// 5th 7.373332977294922 -// deviation 1.843916893005371 +// 95th 8.227417469024658 +// 50th 6.676624774932861 +// 5th 6.508542060852051 +// deviation 1.7188754081726074 // -------------- postcss tokenizer ------------- // tokens 66238 -// tokens/μs @ 95th 18.456481036392354 -// tokens/μs @ 50th 25.63886291747939 -// tokens/μs @ 5th 26.946553538250367 +// tokens/μs @ 95th 18.231267325170737 +// tokens/μs @ 50th 25.111551990929474 +// tokens/μs @ 5th 26.735369993583255 // ----------------------------------------------- -// 95th 3.5888748168945312 -// 50th 2.5834999084472656 -// 5th 2.458125114440918 -// deviation 1.1307497024536133 +// 95th 3.633208751678467 +// 50th 2.6377501487731934 +// 5th 2.477541923522949 +// deviation 1.1556668281555176 From 7bde6f4c517f18a1c0ba00a90cb3eb3ca9e99029 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Thu, 29 Dec 2022 15:31:02 +0100 Subject: [PATCH 12/24] fixes and some convenience methods --- .../consume-component-block-function.d.ts | 15 +- packages/css-parser-algorithms/dist/index.cjs | 2 +- packages/css-parser-algorithms/dist/index.mjs | 2 +- .../dist/util/component-value-type.d.ts | 4 +- .../consume-component-block-function.ts | 43 +----- .../src/util/component-value-type.ts | 2 - .../cases/various/0021.list-comma.expect.json | 113 ++++++++++++++++ .../cases/various/0021.list-space.expect.json | 111 +++++++++++++++ .../test/cases/various/0021.mjs | 14 ++ packages/css-parser-algorithms/test/test.mjs | 1 + packages/media-query-list-parser/CHANGELOG.md | 4 + .../media-query-list-parser/dist/index.cjs | 2 +- .../media-query-list-parser/dist/index.mjs | 2 +- .../dist/nodes/media-feature-boolean.d.ts | 3 +- .../dist/nodes/media-feature-name.d.ts | 3 +- .../dist/nodes/media-feature-plain.d.ts | 2 + .../dist/nodes/media-feature-range.d.ts | 6 + .../dist/nodes/media-feature.d.ts | 2 + .../src/nodes/media-feature-boolean.ts | 5 + .../src/nodes/media-feature-name.ts | 5 + .../src/nodes/media-feature-plain.ts | 8 ++ .../src/nodes/media-feature-range.ts | 24 ++++ .../src/nodes/media-feature.ts | 8 ++ .../test/cases/various/0008.expect.json | 128 ++++++++++++++++++ .../test/cases/various/0008.mjs | 13 ++ .../media-query-list-parser/test/test.mjs | 1 + 26 files changed, 456 insertions(+), 67 deletions(-) create mode 100644 packages/css-parser-algorithms/test/cases/various/0021.list-comma.expect.json create mode 100644 packages/css-parser-algorithms/test/cases/various/0021.list-space.expect.json create mode 100644 packages/css-parser-algorithms/test/cases/various/0021.mjs create mode 100644 packages/media-query-list-parser/test/cases/various/0008.expect.json create mode 100644 packages/media-query-list-parser/test/cases/various/0008.mjs diff --git a/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts b/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts index 7c8c9b67c..fca079357 100644 --- a/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts +++ b/packages/css-parser-algorithms/dist/consume/consume-component-block-function.d.ts @@ -2,7 +2,7 @@ import { CSSToken, TokenFunction } from '@csstools/css-tokenizer'; import { Context } from '../interfaces/context'; import { ComponentValueType } from '../util/component-value-type'; export type ContainerNode = FunctionNode | SimpleBlockNode; -export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode | UnclosedFunctionNode; +export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode; export declare function consumeComponentValue(ctx: Context, tokens: Array): { advance: number; node: ComponentValue; @@ -104,16 +104,3 @@ export declare class TokenNode { isTokenNode(): this is TokenNode; static isTokenNode(x: unknown): x is TokenNode; } -export declare class UnclosedFunctionNode { - type: ComponentValueType; - value: Array; - constructor(value: Array); - tokens(): Array; - toString(): string; - toJSON(): { - type: ComponentValueType; - tokens: CSSToken[]; - }; - isUnclosedFunctionNode(): this is UnclosedFunctionNode; - static isUnclosedFunctionNode(x: unknown): x is UnclosedFunctionNode; -} diff --git a/packages/css-parser-algorithms/dist/index.cjs b/packages/css-parser-algorithms/dist/index.cjs index 7feba34ea..59c0fc052 100644 --- a/packages/css-parser-algorithms/dist/index.cjs +++ b/packages/css-parser-algorithms/dist/index.cjs @@ -1 +1 @@ -"use strict";var e,n=require("@csstools/css-tokenizer");function consumeComponentValue(e,o){const t=o[0];if(t[0]===n.TokenType.OpenParen||t[0]===n.TokenType.OpenCurly||t[0]===n.TokenType.OpenSquare){const n=consumeSimpleBlock(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Function){const n=consumeFunction(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Whitespace){const n=consumeWhitespace(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Comment){const n=consumeComment(e,o);return{advance:n.advance,node:n.node}}return{advance:1,node:new TokenNode(t)}}exports.ComponentValueType=void 0,(e=exports.ComponentValueType||(exports.ComponentValueType={})).Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token",e.UnclosedFunction="unclosed-function",e.UnclosedSimpleBlock="unclosed-simple-block";class FunctionNode{type=exports.ComponentValueType.Function;name;endToken;value;constructor(e,n,o){this.name=e,this.endToken=n,this.value=o}nameTokenValue(){return this.name[4].value}tokens(){return this.endToken[0]===n.TokenType.EOF?[this.name,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens()))]:[this.name,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.name)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===exports.ComponentValueType.Function)}}function consumeFunction(e,o){const t=[];let s=1;for(;;){const i=o[s];if(!i||i[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a function.",start:o[0][2],end:o[o.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:o.length,node:new FunctionNode(o[0],i,t)};if(i[0]===n.TokenType.CloseParen)return{advance:s+1,node:new FunctionNode(o[0],i,t)};if(i[0]===n.TokenType.Comment||i[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(s));s+=n.advance,t.push(...n.nodes);continue}const r=consumeComponentValue(e,o.slice(s));s+=r.advance,t.push(r.node)}}class SimpleBlockNode{type=exports.ComponentValueType.SimpleBlock;startToken;endToken;value;constructor(e,n,o){this.startToken=e,this.endToken=n,this.value=o}tokens(){return this.endToken[0]===n.TokenType.EOF?[this.startToken,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens()))]:[this.startToken,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.startToken)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===exports.ComponentValueType.SimpleBlock)}}function consumeSimpleBlock(e,o){const t=n.mirrorVariantType(o[0][0]);if(!t)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const s=[];let i=1;for(;;){const r=o[i];if(!r||r[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a simple block.",start:o[0][2],end:o[o.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:o.length,node:new SimpleBlockNode(o[0],r,s)};if(r[0]===t)return{advance:i+1,node:new SimpleBlockNode(o[0],r,s)};if(r[0]===n.TokenType.Comment||r[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(i));i+=n.advance,s.push(...n.nodes);continue}const a=consumeComponentValue(e,o.slice(i));i+=a.advance,s.push(a.node)}}class WhitespaceNode{type=exports.ComponentValueType.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===exports.ComponentValueType.Whitespace)}}function consumeWhitespace(e,o){let t=0;for(;;){if(o[t][0]!==n.TokenType.Whitespace)return{advance:t,node:new WhitespaceNode(o.slice(0,t))};t++}}class CommentNode{type=exports.ComponentValueType.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===exports.ComponentValueType.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(e,o){const t=[];let s=0;for(;;)if(o[s][0]!==n.TokenType.Whitespace){if(o[s][0]!==n.TokenType.Comment)return{advance:s,nodes:t};t.push(new CommentNode(o[s])),s++}else{const e=consumeWhitespace(0,o.slice(s));s+=e.advance,t.push(e.node)}}class TokenNode{type=exports.ComponentValueType.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===exports.ComponentValueType.Token)}}class UnclosedFunctionNode{type=exports.ComponentValueType.UnclosedFunction;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedFunctionNode(){return UnclosedFunctionNode.isUnclosedFunctionNode(this)}static isUnclosedFunctionNode(e){return!!e&&(e instanceof UnclosedFunctionNode&&e.type===exports.ComponentValueType.UnclosedFunction)}}exports.CommentNode=CommentNode,exports.FunctionNode=FunctionNode,exports.SimpleBlockNode=SimpleBlockNode,exports.TokenNode=TokenNode,exports.UnclosedFunctionNode=UnclosedFunctionNode,exports.WhitespaceNode=WhitespaceNode,exports.consumeAllCommentsAndWhitespace=consumeAllCommentsAndWhitespace,exports.consumeComment=consumeComment,exports.consumeComponentValue=consumeComponentValue,exports.consumeFunction=consumeFunction,exports.consumeSimpleBlock=consumeSimpleBlock,exports.consumeWhitespace=consumeWhitespace,exports.gatherNodeAncestry=function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((o=>{n.set(o,e.parent)})):n.set(e.node,e.parent)})),n},exports.isCommentNode=function isCommentNode(e){return CommentNode.isCommentNode(e)},exports.isFunctionNode=function isFunctionNode(e){return FunctionNode.isFunctionNode(e)},exports.isSimpleBlockNode=function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)},exports.isTokenNode=function isTokenNode(e){return TokenNode.isTokenNode(e)},exports.isWhitespaceNode=function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)},exports.parseCommaSeparatedListOfComponentValues=function parseCommaSeparatedListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];if(0===e.length)return[];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let r=[],a=0;for(;;){if(!s[a]||s[a][0]===n.TokenType.EOF)return r.length&&i.push(r),i;if(s[a][0]===n.TokenType.Comma){i.push(r),r=[],a++;continue}const o=consumeComponentValue(t,e.slice(a));r.push(o.node),a+=o.advance}},exports.parseComponentValue=function parseComponentValue(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(t,s);if(s[Math.min(i.advance,s.length-1)][0]===n.TokenType.EOF)return i.node;t.onParseError({message:"Expected EOF after parsing a component value.",start:e[0][2],end:e[e.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})},exports.parseListOfComponentValues=function parseListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let r=0;for(;;){if(!s[r]||s[r][0]===n.TokenType.EOF)return i;const e=consumeComponentValue(t,s.slice(r));i.push(e.node),r+=e.advance}}; +"use strict";var e,n=require("@csstools/css-tokenizer");function consumeComponentValue(e,o){const t=o[0];if(t[0]===n.TokenType.OpenParen||t[0]===n.TokenType.OpenCurly||t[0]===n.TokenType.OpenSquare){const n=consumeSimpleBlock(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Function){const n=consumeFunction(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Whitespace){const n=consumeWhitespace(e,o);return{advance:n.advance,node:n.node}}if(t[0]===n.TokenType.Comment){const n=consumeComment(e,o);return{advance:n.advance,node:n.node}}return{advance:1,node:new TokenNode(t)}}exports.ComponentValueType=void 0,(e=exports.ComponentValueType||(exports.ComponentValueType={})).Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token";class FunctionNode{type=exports.ComponentValueType.Function;name;endToken;value;constructor(e,n,o){this.name=e,this.endToken=n,this.value=o}nameTokenValue(){return this.name[4].value}tokens(){return this.endToken[0]===n.TokenType.EOF?[this.name,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens()))]:[this.name,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.name)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===exports.ComponentValueType.Function)}}function consumeFunction(e,o){const t=[];let s=1;for(;;){const i=o[s];if(!i||i[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a function.",start:o[0][2],end:o[o.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:o.length,node:new FunctionNode(o[0],i,t)};if(i[0]===n.TokenType.CloseParen)return{advance:s+1,node:new FunctionNode(o[0],i,t)};if(i[0]===n.TokenType.Comment||i[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(s));s+=n.advance,t.push(...n.nodes);continue}const r=consumeComponentValue(e,o.slice(s));s+=r.advance,t.push(r.node)}}class SimpleBlockNode{type=exports.ComponentValueType.SimpleBlock;startToken;endToken;value;constructor(e,n,o){this.startToken=e,this.endToken=n,this.value=o}tokens(){return this.endToken[0]===n.TokenType.EOF?[this.startToken,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens()))]:[this.startToken,...this.value.flatMap((e=>n.isToken(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n.isToken(e)?n.stringify(e):e.toString())).join("");return n.stringify(this.startToken)+e+n.stringify(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((o,t)=>{n||(!1!==e({node:o,parent:this},t)?"walk"in o&&!1===o.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===exports.ComponentValueType.SimpleBlock)}}function consumeSimpleBlock(e,o){const t=n.mirrorVariantType(o[0][0]);if(!t)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const s=[];let i=1;for(;;){const r=o[i];if(!r||r[0]===n.TokenType.EOF)return e.onParseError({message:"Unexpected EOF while consuming a simple block.",start:o[0][2],end:o[o.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:o.length,node:new SimpleBlockNode(o[0],r,s)};if(r[0]===t)return{advance:i+1,node:new SimpleBlockNode(o[0],r,s)};if(r[0]===n.TokenType.Comment||r[0]===n.TokenType.Whitespace){const n=consumeAllCommentsAndWhitespace(e,o.slice(i));i+=n.advance,s.push(...n.nodes);continue}const a=consumeComponentValue(e,o.slice(i));i+=a.advance,s.push(a.node)}}class WhitespaceNode{type=exports.ComponentValueType.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return n.stringify(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===exports.ComponentValueType.Whitespace)}}function consumeWhitespace(e,o){let t=0;for(;;){if(o[t][0]!==n.TokenType.Whitespace)return{advance:t,node:new WhitespaceNode(o.slice(0,t))};t++}}class CommentNode{type=exports.ComponentValueType.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===exports.ComponentValueType.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(e,o){const t=[];let s=0;for(;;)if(o[s][0]!==n.TokenType.Whitespace){if(o[s][0]!==n.TokenType.Comment)return{advance:s,nodes:t};t.push(new CommentNode(o[s])),s++}else{const e=consumeWhitespace(0,o.slice(s));s+=e.advance,t.push(e.node)}}class TokenNode{type=exports.ComponentValueType.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return n.stringify(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===exports.ComponentValueType.Token)}}exports.CommentNode=CommentNode,exports.FunctionNode=FunctionNode,exports.SimpleBlockNode=SimpleBlockNode,exports.TokenNode=TokenNode,exports.WhitespaceNode=WhitespaceNode,exports.consumeAllCommentsAndWhitespace=consumeAllCommentsAndWhitespace,exports.consumeComment=consumeComment,exports.consumeComponentValue=consumeComponentValue,exports.consumeFunction=consumeFunction,exports.consumeSimpleBlock=consumeSimpleBlock,exports.consumeWhitespace=consumeWhitespace,exports.gatherNodeAncestry=function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((o=>{n.set(o,e.parent)})):n.set(e.node,e.parent)})),n},exports.isCommentNode=function isCommentNode(e){return CommentNode.isCommentNode(e)},exports.isFunctionNode=function isFunctionNode(e){return FunctionNode.isFunctionNode(e)},exports.isSimpleBlockNode=function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)},exports.isTokenNode=function isTokenNode(e){return TokenNode.isTokenNode(e)},exports.isWhitespaceNode=function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)},exports.parseCommaSeparatedListOfComponentValues=function parseCommaSeparatedListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];if(0===e.length)return[];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let r=[],a=0;for(;;){if(!s[a]||s[a][0]===n.TokenType.EOF)return r.length&&i.push(r),i;if(s[a][0]===n.TokenType.Comma){i.push(r),r=[],a++;continue}const o=consumeComponentValue(t,e.slice(a));r.push(o.node),a+=o.advance}},exports.parseComponentValue=function parseComponentValue(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(t,s);if(s[Math.min(i.advance,s.length-1)][0]===n.TokenType.EOF)return i.node;t.onParseError({message:"Expected EOF after parsing a component value.",start:e[0][2],end:e[e.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})},exports.parseListOfComponentValues=function parseListOfComponentValues(e,o){const t={onParseError:(null==o?void 0:o.onParseError)??(()=>{})},s=[...e];s[s.length-1][0]!==n.TokenType.EOF&&s.push([n.TokenType.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let r=0;for(;;){if(!s[r]||s[r][0]===n.TokenType.EOF)return i;const e=consumeComponentValue(t,s.slice(r));i.push(e.node),r+=e.advance}}; diff --git a/packages/css-parser-algorithms/dist/index.mjs b/packages/css-parser-algorithms/dist/index.mjs index c627eee41..2b53b270e 100644 --- a/packages/css-parser-algorithms/dist/index.mjs +++ b/packages/css-parser-algorithms/dist/index.mjs @@ -1 +1 @@ -import{TokenType as e,isToken as n,stringify as t,mirrorVariantType as o}from"@csstools/css-tokenizer";var s;function consumeComponentValue(n,t){const o=t[0];if(o[0]===e.OpenParen||o[0]===e.OpenCurly||o[0]===e.OpenSquare){const e=consumeSimpleBlock(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Function){const e=consumeFunction(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Whitespace){const e=consumeWhitespace(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Comment){const e=consumeComment(n,t);return{advance:e.advance,node:e.node}}return{advance:1,node:new TokenNode(o)}}!function(e){e.Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token",e.UnclosedFunction="unclosed-function",e.UnclosedSimpleBlock="unclosed-simple-block"}(s||(s={}));class FunctionNode{type=s.Function;name;endToken;value;constructor(e,n,t){this.name=e,this.endToken=n,this.value=t}nameTokenValue(){return this.name[4].value}tokens(){return this.endToken[0]===e.EOF?[this.name,...this.value.flatMap((e=>n(e)?e:e.tokens()))]:[this.name,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?t(e):e.toString())).join("");return t(this.name)+e+t(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((t,o)=>{n||(!1!==e({node:t,parent:this},o)?"walk"in t&&!1===t.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===s.Function)}}function consumeFunction(n,t){const o=[];let s=1;for(;;){const i=t[s];if(!i||i[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a function.",start:t[0][2],end:t[t.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:t.length,node:new FunctionNode(t[0],i,o)};if(i[0]===e.CloseParen)return{advance:s+1,node:new FunctionNode(t[0],i,o)};if(i[0]===e.Comment||i[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,t.slice(s));s+=e.advance,o.push(...e.nodes);continue}const a=consumeComponentValue(n,t.slice(s));s+=a.advance,o.push(a.node)}}class SimpleBlockNode{type=s.SimpleBlock;startToken;endToken;value;constructor(e,n,t){this.startToken=e,this.endToken=n,this.value=t}tokens(){return this.endToken[0]===e.EOF?[this.startToken,...this.value.flatMap((e=>n(e)?e:e.tokens()))]:[this.startToken,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?t(e):e.toString())).join("");return t(this.startToken)+e+t(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((t,o)=>{n||(!1!==e({node:t,parent:this},o)?"walk"in t&&!1===t.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===s.SimpleBlock)}}function consumeSimpleBlock(n,t){const s=o(t[0][0]);if(!s)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const i=[];let a=1;for(;;){const o=t[a];if(!o||o[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a simple block.",start:t[0][2],end:t[t.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:t.length,node:new SimpleBlockNode(t[0],o,i)};if(o[0]===s)return{advance:a+1,node:new SimpleBlockNode(t[0],o,i)};if(o[0]===e.Comment||o[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,t.slice(a));a+=e.advance,i.push(...e.nodes);continue}const c=consumeComponentValue(n,t.slice(a));a+=c.advance,i.push(c.node)}}class WhitespaceNode{type=s.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return t(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===s.Whitespace)}}function consumeWhitespace(n,t){let o=0;for(;;){if(t[o][0]!==e.Whitespace)return{advance:o,node:new WhitespaceNode(t.slice(0,o))};o++}}class CommentNode{type=s.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return t(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===s.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(n,t){const o=[];let s=0;for(;;)if(t[s][0]!==e.Whitespace){if(t[s][0]!==e.Comment)return{advance:s,nodes:o};o.push(new CommentNode(t[s])),s++}else{const e=consumeWhitespace(0,t.slice(s));s+=e.advance,o.push(e.node)}}class TokenNode{type=s.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return t(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===s.Token)}}class UnclosedFunctionNode{type=s.UnclosedFunction;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return t(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isUnclosedFunctionNode(){return UnclosedFunctionNode.isUnclosedFunctionNode(this)}static isUnclosedFunctionNode(e){return!!e&&(e instanceof UnclosedFunctionNode&&e.type===s.UnclosedFunction)}}function parseComponentValue(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(o,s);if(s[Math.min(i.advance,s.length-1)][0]===e.EOF)return i.node;o.onParseError({message:"Expected EOF after parsing a component value.",start:n[0][2],end:n[n.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})}function parseListOfComponentValues(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let a=0;for(;;){if(!s[a]||s[a][0]===e.EOF)return i;const n=consumeComponentValue(o,s.slice(a));i.push(n.node),a+=n.advance}}function parseCommaSeparatedListOfComponentValues(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];if(0===n.length)return[];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let a=[],c=0;for(;;){if(!s[c]||s[c][0]===e.EOF)return a.length&&i.push(a),i;if(s[c][0]===e.Comma){i.push(a),a=[],c++;continue}const t=consumeComponentValue(o,n.slice(c));a.push(t.node),c+=t.advance}}function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((t=>{n.set(t,e.parent)})):n.set(e.node,e.parent)})),n}function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)}function isFunctionNode(e){return FunctionNode.isFunctionNode(e)}function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)}function isCommentNode(e){return CommentNode.isCommentNode(e)}function isTokenNode(e){return TokenNode.isTokenNode(e)}export{CommentNode,s as ComponentValueType,FunctionNode,SimpleBlockNode,TokenNode,UnclosedFunctionNode,WhitespaceNode,consumeAllCommentsAndWhitespace,consumeComment,consumeComponentValue,consumeFunction,consumeSimpleBlock,consumeWhitespace,gatherNodeAncestry,isCommentNode,isFunctionNode,isSimpleBlockNode,isTokenNode,isWhitespaceNode,parseCommaSeparatedListOfComponentValues,parseComponentValue,parseListOfComponentValues}; +import{TokenType as e,isToken as n,stringify as t,mirrorVariantType as o}from"@csstools/css-tokenizer";var s;function consumeComponentValue(n,t){const o=t[0];if(o[0]===e.OpenParen||o[0]===e.OpenCurly||o[0]===e.OpenSquare){const e=consumeSimpleBlock(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Function){const e=consumeFunction(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Whitespace){const e=consumeWhitespace(n,t);return{advance:e.advance,node:e.node}}if(o[0]===e.Comment){const e=consumeComment(n,t);return{advance:e.advance,node:e.node}}return{advance:1,node:new TokenNode(o)}}!function(e){e.Function="function",e.SimpleBlock="simple-block",e.Whitespace="whitespace",e.Comment="comment",e.Token="token"}(s||(s={}));class FunctionNode{type=s.Function;name;endToken;value;constructor(e,n,t){this.name=e,this.endToken=n,this.value=t}nameTokenValue(){return this.name[4].value}tokens(){return this.endToken[0]===e.EOF?[this.name,...this.value.flatMap((e=>n(e)?e:e.tokens()))]:[this.name,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?t(e):e.toString())).join("");return t(this.name)+e+t(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((t,o)=>{n||(!1!==e({node:t,parent:this},o)?"walk"in t&&!1===t.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,name:this.nameTokenValue(),tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isFunctionNode(){return FunctionNode.isFunctionNode(this)}static isFunctionNode(e){return!!e&&(e instanceof FunctionNode&&e.type===s.Function)}}function consumeFunction(n,t){const o=[];let s=1;for(;;){const i=t[s];if(!i||i[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a function.",start:t[0][2],end:t[t.length-1][3],state:["5.4.9. Consume a function","Unexpected EOF"]}),{advance:t.length,node:new FunctionNode(t[0],i,o)};if(i[0]===e.CloseParen)return{advance:s+1,node:new FunctionNode(t[0],i,o)};if(i[0]===e.Comment||i[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,t.slice(s));s+=e.advance,o.push(...e.nodes);continue}const a=consumeComponentValue(n,t.slice(s));s+=a.advance,o.push(a.node)}}class SimpleBlockNode{type=s.SimpleBlock;startToken;endToken;value;constructor(e,n,t){this.startToken=e,this.endToken=n,this.value=t}tokens(){return this.endToken[0]===e.EOF?[this.startToken,...this.value.flatMap((e=>n(e)?e:e.tokens()))]:[this.startToken,...this.value.flatMap((e=>n(e)?e:e.tokens())),this.endToken]}toString(){const e=this.value.map((e=>n(e)?t(e):e.toString())).join("");return t(this.startToken)+e+t(this.endToken)}indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}walk(e){let n=!1;if(this.value.forEach(((t,o)=>{n||(!1!==e({node:t,parent:this},o)?"walk"in t&&!1===t.walk(e)&&(n=!0):n=!0)})),n)return!1}toJSON(){return{type:this.type,startToken:this.startToken,tokens:this.tokens(),value:this.value.map((e=>e.toJSON()))}}isSimpleBlockNode(){return SimpleBlockNode.isSimpleBlockNode(this)}static isSimpleBlockNode(e){return!!e&&(e instanceof SimpleBlockNode&&e.type===s.SimpleBlock)}}function consumeSimpleBlock(n,t){const s=o(t[0][0]);if(!s)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const i=[];let a=1;for(;;){const o=t[a];if(!o||o[0]===e.EOF)return n.onParseError({message:"Unexpected EOF while consuming a simple block.",start:t[0][2],end:t[t.length-1][3],state:["5.4.8. Consume a simple block","Unexpected EOF"]}),{advance:t.length,node:new SimpleBlockNode(t[0],o,i)};if(o[0]===s)return{advance:a+1,node:new SimpleBlockNode(t[0],o,i)};if(o[0]===e.Comment||o[0]===e.Whitespace){const e=consumeAllCommentsAndWhitespace(n,t.slice(a));a+=e.advance,i.push(...e.nodes);continue}const r=consumeComponentValue(n,t.slice(a));a+=r.advance,i.push(r.node)}}class WhitespaceNode{type=s.Whitespace;value;constructor(e){this.value=e}tokens(){return this.value}toString(){return t(...this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isWhitespaceNode(){return WhitespaceNode.isWhitespaceNode(this)}static isWhitespaceNode(e){return!!e&&(e instanceof WhitespaceNode&&e.type===s.Whitespace)}}function consumeWhitespace(n,t){let o=0;for(;;){if(t[o][0]!==e.Whitespace)return{advance:o,node:new WhitespaceNode(t.slice(0,o))};o++}}class CommentNode{type=s.Comment;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return t(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isCommentNode(){return CommentNode.isCommentNode(this)}static isCommentNode(e){return!!e&&(e instanceof CommentNode&&e.type===s.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(n,t){const o=[];let s=0;for(;;)if(t[s][0]!==e.Whitespace){if(t[s][0]!==e.Comment)return{advance:s,nodes:o};o.push(new CommentNode(t[s])),s++}else{const e=consumeWhitespace(0,t.slice(s));s+=e.advance,o.push(e.node)}}class TokenNode{type=s.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return t(this.value)}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===s.Token)}}function parseComponentValue(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=consumeComponentValue(o,s);if(s[Math.min(i.advance,s.length-1)][0]===e.EOF)return i.node;o.onParseError({message:"Expected EOF after parsing a component value.",start:n[0][2],end:n[n.length-1][3],state:["5.3.9. Parse a component value","Expected EOF"]})}function parseListOfComponentValues(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let a=0;for(;;){if(!s[a]||s[a][0]===e.EOF)return i;const n=consumeComponentValue(o,s.slice(a));i.push(n.node),a+=n.advance}}function parseCommaSeparatedListOfComponentValues(n,t){const o={onParseError:(null==t?void 0:t.onParseError)??(()=>{})},s=[...n];if(0===n.length)return[];s[s.length-1][0]!==e.EOF&&s.push([e.EOF,"",s[s.length-1][2],s[s.length-1][3],void 0]);const i=[];let a=[],r=0;for(;;){if(!s[r]||s[r][0]===e.EOF)return a.length&&i.push(a),i;if(s[r][0]===e.Comma){i.push(a),a=[],r++;continue}const t=consumeComponentValue(o,n.slice(r));a.push(t.node),r+=t.advance}}function gatherNodeAncestry(e){const n=new Map;return e.walk((e=>{Array.isArray(e.node)?e.node.forEach((t=>{n.set(t,e.parent)})):n.set(e.node,e.parent)})),n}function isSimpleBlockNode(e){return SimpleBlockNode.isSimpleBlockNode(e)}function isFunctionNode(e){return FunctionNode.isFunctionNode(e)}function isWhitespaceNode(e){return WhitespaceNode.isWhitespaceNode(e)}function isCommentNode(e){return CommentNode.isCommentNode(e)}function isTokenNode(e){return TokenNode.isTokenNode(e)}export{CommentNode,s as ComponentValueType,FunctionNode,SimpleBlockNode,TokenNode,WhitespaceNode,consumeAllCommentsAndWhitespace,consumeComment,consumeComponentValue,consumeFunction,consumeSimpleBlock,consumeWhitespace,gatherNodeAncestry,isCommentNode,isFunctionNode,isSimpleBlockNode,isTokenNode,isWhitespaceNode,parseCommaSeparatedListOfComponentValues,parseComponentValue,parseListOfComponentValues}; diff --git a/packages/css-parser-algorithms/dist/util/component-value-type.d.ts b/packages/css-parser-algorithms/dist/util/component-value-type.d.ts index a34707707..eda7ee93c 100644 --- a/packages/css-parser-algorithms/dist/util/component-value-type.d.ts +++ b/packages/css-parser-algorithms/dist/util/component-value-type.d.ts @@ -3,7 +3,5 @@ export declare enum ComponentValueType { SimpleBlock = "simple-block", Whitespace = "whitespace", Comment = "comment", - Token = "token", - UnclosedFunction = "unclosed-function", - UnclosedSimpleBlock = "unclosed-simple-block" + Token = "token" } diff --git a/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts b/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts index 62a91496e..60086a8aa 100644 --- a/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts +++ b/packages/css-parser-algorithms/src/consume/consume-component-block-function.ts @@ -4,7 +4,7 @@ import { ComponentValueType } from '../util/component-value-type'; export type ContainerNode = FunctionNode | SimpleBlockNode; -export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode | UnclosedFunctionNode; +export type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode; // https://www.w3.org/TR/css-syntax-3/#consume-a-component-value export function consumeComponentValue(ctx: Context, tokens: Array): { advance: number, node: ComponentValue } { @@ -563,44 +563,3 @@ export class TokenNode { return x.type === ComponentValueType.Token; } } - -export class UnclosedFunctionNode { - type: ComponentValueType = ComponentValueType.UnclosedFunction; - - value: Array; - - constructor(value: Array) { - this.value = value; - } - - tokens(): Array { - return this.value; - } - - toString(): string { - return stringify(...this.value); - } - - toJSON() { - return { - type: this.type, - tokens: this.tokens(), - }; - } - - isUnclosedFunctionNode(): this is UnclosedFunctionNode { - return UnclosedFunctionNode.isUnclosedFunctionNode(this); - } - - static isUnclosedFunctionNode(x: unknown): x is UnclosedFunctionNode { - if (!x) { - return false; - } - - if (!(x instanceof UnclosedFunctionNode)) { - return false; - } - - return x.type === ComponentValueType.UnclosedFunction; - } -} diff --git a/packages/css-parser-algorithms/src/util/component-value-type.ts b/packages/css-parser-algorithms/src/util/component-value-type.ts index 228ae5fc7..5f278782e 100644 --- a/packages/css-parser-algorithms/src/util/component-value-type.ts +++ b/packages/css-parser-algorithms/src/util/component-value-type.ts @@ -4,6 +4,4 @@ export enum ComponentValueType { Whitespace = 'whitespace', Comment = 'comment', Token = 'token', - UnclosedFunction = 'unclosed-function', - UnclosedSimpleBlock = 'unclosed-simple-block' } diff --git a/packages/css-parser-algorithms/test/cases/various/0021.list-comma.expect.json b/packages/css-parser-algorithms/test/cases/various/0021.list-comma.expect.json new file mode 100644 index 000000000..91cf1b1e6 --- /dev/null +++ b/packages/css-parser-algorithms/test/cases/various/0021.list-comma.expect.json @@ -0,0 +1,113 @@ +[ + [ + { + "type": "simple-block", + "startToken": [ + "(-token", + "(", + 0, + 0, + null + ], + "tokens": [ + [ + "(-token", + "(", + 0, + 0, + null + ], + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ], + [ + "colon-token", + ":", + 10, + 10, + null + ], + [ + "whitespace-token", + " ", + 11, + 11, + null + ], + [ + "dimension-token", + "300px", + 12, + 16, + { + "value": 300, + "type": "integer", + "unit": "px" + } + ] + ], + "value": [ + { + "type": "token", + "tokens": [ + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ] + ] + }, + { + "type": "token", + "tokens": [ + [ + "colon-token", + ":", + 10, + 10, + null + ] + ] + }, + { + "type": "whitespace", + "tokens": [ + [ + "whitespace-token", + " ", + 11, + 11, + null + ] + ] + }, + { + "type": "token", + "tokens": [ + [ + "dimension-token", + "300px", + 12, + 16, + { + "value": 300, + "type": "integer", + "unit": "px" + } + ] + ] + } + ] + } + ] +] \ No newline at end of file diff --git a/packages/css-parser-algorithms/test/cases/various/0021.list-space.expect.json b/packages/css-parser-algorithms/test/cases/various/0021.list-space.expect.json new file mode 100644 index 000000000..efa006b93 --- /dev/null +++ b/packages/css-parser-algorithms/test/cases/various/0021.list-space.expect.json @@ -0,0 +1,111 @@ +[ + { + "type": "simple-block", + "startToken": [ + "(-token", + "(", + 0, + 0, + null + ], + "tokens": [ + [ + "(-token", + "(", + 0, + 0, + null + ], + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ], + [ + "colon-token", + ":", + 10, + 10, + null + ], + [ + "whitespace-token", + " ", + 11, + 11, + null + ], + [ + "dimension-token", + "300px", + 12, + 16, + { + "value": 300, + "type": "integer", + "unit": "px" + } + ] + ], + "value": [ + { + "type": "token", + "tokens": [ + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ] + ] + }, + { + "type": "token", + "tokens": [ + [ + "colon-token", + ":", + 10, + 10, + null + ] + ] + }, + { + "type": "whitespace", + "tokens": [ + [ + "whitespace-token", + " ", + 11, + 11, + null + ] + ] + }, + { + "type": "token", + "tokens": [ + [ + "dimension-token", + "300px", + 12, + 16, + { + "value": 300, + "type": "integer", + "unit": "px" + } + ] + ] + } + ] + } +] \ No newline at end of file diff --git a/packages/css-parser-algorithms/test/cases/various/0021.mjs b/packages/css-parser-algorithms/test/cases/various/0021.mjs new file mode 100644 index 000000000..a0d9cb818 --- /dev/null +++ b/packages/css-parser-algorithms/test/cases/various/0021.mjs @@ -0,0 +1,14 @@ +import assert from 'assert'; +import { runTest } from '../../util/run-test.mjs'; + +runTest( + '(min-width: 300px', + 'various/0021', + (actual, expected) => { + assert.deepStrictEqual( + actual, + expected, + ); + }, + true, +); diff --git a/packages/css-parser-algorithms/test/test.mjs b/packages/css-parser-algorithms/test/test.mjs index 1d28110d3..6130229f7 100644 --- a/packages/css-parser-algorithms/test/test.mjs +++ b/packages/css-parser-algorithms/test/test.mjs @@ -36,5 +36,6 @@ import './cases/various/0017.mjs'; import './cases/various/0018.mjs'; import './cases/various/0019.mjs'; import './cases/various/0020.mjs'; +import './cases/various/0021.mjs'; import './cases/wpt/0001.mjs'; diff --git a/packages/media-query-list-parser/CHANGELOG.md b/packages/media-query-list-parser/CHANGELOG.md index cd7fc18e7..9f837f51d 100644 --- a/packages/media-query-list-parser/CHANGELOG.md +++ b/packages/media-query-list-parser/CHANGELOG.md @@ -1,3 +1,7 @@ +### Unreleased + +- Add `getName` and `getNameToken` to all nodes that have a feature name. + ### 1.0.0 (November 14, 2022) - Initial version diff --git a/packages/media-query-list-parser/dist/index.cjs b/packages/media-query-list-parser/dist/index.cjs index 203b85c88..c8290e8c8 100644 --- a/packages/media-query-list-parser/dist/index.cjs +++ b/packages/media-query-list-parser/dist/index.cjs @@ -1 +1 @@ -"use strict";var e,t,i,a=require("@csstools/css-parser-algorithms"),r=require("@csstools/css-tokenizer");exports.NodeType=void 0,(e=exports.NodeType||(exports.NodeType={})).GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid";class MediaCondition{type=exports.NodeType.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===exports.NodeType.MediaCondition)}}class MediaInParens{type=exports.NodeType.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.media.toString()+r.stringify(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&("walk"in this.media?this.media.walk(e):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===exports.NodeType.MediaInParens)}}class MediaQueryWithType{type=exports.NodeType.MediaQueryWithType;modifier;mediaType;and;media=null;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===exports.NodeType.MediaQueryInvalid)}}class GeneralEnclosed{type=exports.NodeType.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===exports.NodeType.GeneralEnclosed)}}class MediaAnd{type=exports.NodeType.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return r.stringify(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===exports.NodeType.MediaAnd)}}class MediaConditionListWithAnd{type=exports.NodeType.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===exports.NodeType.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=exports.NodeType.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===exports.NodeType.MediaConditionListWithOr)}}function isNumber(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Number||e.type===a.ComponentValueType.Function&&"calc"===e.name[4].value}function isDimension(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Dimension}function isIdent(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Ident}class MediaFeatureName{type=exports.NodeType.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.name.toString()+r.stringify(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===exports.NodeType.MediaFeatureName)}}function parseMediaFeatureName(e){let t=-1;for(let i=0;ie.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=exports.NodeType.MediaFeatureBoolean;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.name.toString()+r.stringify(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===exports.NodeType.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t.name,t.before,t.after)}class MediaFeatureValue{type=exports.NodeType.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?r.stringify(...this.before)+this.value.map((e=>e.toString())).join("")+r.stringify(...this.after):r.stringify(...this.before)+this.value.toString()+r.stringify(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===exports.NodeType.MediaFeatureValue)}}function parseMediaFeatureValue(e){let t=-1,i=-1;for(let r=0;re.tokens())),e.slice(i+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==r.TokenType.Delim)return!1;if(1===e.length)switch(e[0][4].value){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT;default:return!1}if(e[1][0]!==r.TokenType.Delim)return!1;if(e[1][4].value!==exports.MediaFeatureEQ.EQ)return!1;switch(e[0][4].value){case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT_OR_EQ;default:return!1}}exports.MediaFeatureLT=void 0,(t=exports.MediaFeatureLT||(exports.MediaFeatureLT={})).LT="<",t.LT_OR_EQ="<=",exports.MediaFeatureGT=void 0,(i=exports.MediaFeatureGT||(exports.MediaFeatureGT={})).GT=">",i.GT_OR_EQ=">=",exports.MediaFeatureEQ=void 0,(exports.MediaFeatureEQ||(exports.MediaFeatureEQ={})).EQ="=";class MediaFeatureRangeNameValue{type=exports.NodeType.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+r.stringify(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===exports.NodeType.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=exports.NodeType.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+r.stringify(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===exports.NodeType.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=exports.NodeType.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,r){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=r}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+r.stringify(...this.valueOneOperator)+this.name.toString()+r.stringify(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===exports.NodeType.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(e){let t=!1,i=!1;for(let n=0;ne.tokens())),-1!==i&&(s=e.slice(t+1,i+1).flatMap((e=>e.tokens())))):-1!==i&&(s=e.slice(0,i+1).flatMap((e=>e.tokens())));const d=parseMediaConditionWithoutOr(e.slice(Math.max(t,i,n)+1));return!1===d?new MediaQueryWithType(o,[...s,...e.slice(i+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(o,s,e.slice(i+1,n+1).flatMap((e=>e.tokens())),d)}}function parseMediaConditionListWithOr(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const r=parseMediaInParens(e);return!1!==r&&new MediaCondition(r)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(e){let t=-1;for(let i=0;ie.tokens())),i.startToken],o=[i.endToken,...e.slice(t+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(i,n,o);if(!1!==s)return new MediaInParens(s);const d=parseMediaCondition(i.value);return!1!==d?new MediaInParens(d,n,o):new MediaInParens(new GeneralEnclosed(i),e.slice(0,t).flatMap((e=>e.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==r.TokenType.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(e){let t=!1,i=null;for(let r=0;re.tokens())),t)}}}return i||!1}function parseMediaOr(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseMediaAnd(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseFromTokens(e,t){const i=a.parseCommaSeparatedListOfComponentValues(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const r=parseMediaQuery(e);return 0==r&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):r})).filter((e=>!!e))}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}exports.MediaQueryModifier=void 0,(o=exports.MediaQueryModifier||(exports.MediaQueryModifier={})).Not="not",o.Only="only",exports.MediaType=void 0,(s=exports.MediaType||(exports.MediaType={})).All="all",s.Print="print",s.Screen="screen",s.Tty="tty",s.Tv="tv",s.Projection="projection",s.Handheld="handheld",s.Braille="braille",s.Embossed="embossed",s.Aural="aural",s.Speech="speech",exports.GeneralEnclosed=GeneralEnclosed,exports.MediaAnd=MediaAnd,exports.MediaCondition=MediaCondition,exports.MediaConditionListWithAnd=MediaConditionListWithAnd,exports.MediaConditionListWithOr=MediaConditionListWithOr,exports.MediaFeature=MediaFeature,exports.MediaFeatureBoolean=MediaFeatureBoolean,exports.MediaFeatureName=MediaFeatureName,exports.MediaFeaturePlain=MediaFeaturePlain,exports.MediaFeatureRangeNameValue=MediaFeatureRangeNameValue,exports.MediaFeatureRangeValueName=MediaFeatureRangeValueName,exports.MediaFeatureRangeValueNameValue=MediaFeatureRangeValueNameValue,exports.MediaFeatureValue=MediaFeatureValue,exports.MediaInParens=MediaInParens,exports.MediaNot=MediaNot,exports.MediaOr=MediaOr,exports.MediaQueryInvalid=MediaQueryInvalid,exports.MediaQueryWithType=MediaQueryWithType,exports.MediaQueryWithoutType=MediaQueryWithoutType,exports.cloneMediaQuery=function cloneMediaQuery(e){const t=r.cloneTokens(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`)},exports.comparisonFromTokens=comparisonFromTokens,exports.invertComparison=function invertComparison(e){switch(e){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureGT.GT;case exports.MediaFeatureLT.LT_OR_EQ:return exports.MediaFeatureGT.GT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT_OR_EQ:return exports.MediaFeatureLT.LT_OR_EQ;default:return!1}},exports.isGeneralEnclosed=function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)},exports.isMediaAnd=function isMediaAnd(e){return MediaAnd.isMediaAnd(e)},exports.isMediaCondition=function isMediaCondition(e){return MediaCondition.isMediaCondition(e)},exports.isMediaConditionList=function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)},exports.isMediaConditionListWithAnd=isMediaConditionListWithAnd,exports.isMediaConditionListWithOr=isMediaConditionListWithOr,exports.isMediaFeature=function isMediaFeature(e){return MediaFeature.isMediaFeature(e)},exports.isMediaFeatureBoolean=function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)},exports.isMediaFeatureName=function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)},exports.isMediaFeaturePlain=function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)},exports.isMediaFeatureRange=function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)},exports.isMediaFeatureRangeNameValue=isMediaFeatureRangeNameValue,exports.isMediaFeatureRangeValueName=isMediaFeatureRangeValueName,exports.isMediaFeatureRangeValueNameValue=isMediaFeatureRangeValueNameValue,exports.isMediaFeatureValue=function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)},exports.isMediaInParens=function isMediaInParens(e){return MediaInParens.isMediaInParens(e)},exports.isMediaNot=function isMediaNot(e){return MediaNot.isMediaNot(e)},exports.isMediaOr=function isMediaOr(e){return MediaOr.isMediaOr(e)},exports.isMediaQuery=function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)},exports.isMediaQueryInvalid=isMediaQueryInvalid,exports.isMediaQueryWithType=isMediaQueryWithType,exports.isMediaQueryWithoutType=isMediaQueryWithoutType,exports.matchesComparison=matchesComparison,exports.matchesRatio=matchesRatio,exports.matchesRatioExactly=matchesRatioExactly,exports.modifierFromToken=modifierFromToken,exports.newMediaFeatureBoolean=function newMediaFeatureBoolean(e){return new MediaFeature(new MediaFeatureBoolean(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}])),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.newMediaFeaturePlain=function newMediaFeaturePlain(e,...t){return new MediaFeature(new MediaFeaturePlain(new MediaFeatureName(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}])),[r.TokenType.Colon,":",-1,-1,void 0],new MediaFeatureValue(t.map((e=>new a.TokenNode(e))))),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.parse=function parse(e,t){const i=r.tokenizer({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)},exports.parseFromTokens=parseFromTokens,exports.typeFromToken=function typeFromToken(e){if(e[0]!==r.TokenType.Ident)return!1;switch(e[4].value.toLowerCase()){case exports.MediaType.All:return exports.MediaType.All;case exports.MediaType.Print:return exports.MediaType.Print;case exports.MediaType.Screen:return exports.MediaType.Screen;case exports.MediaType.Tty:return exports.MediaType.Tty;case exports.MediaType.Tv:return exports.MediaType.Tv;case exports.MediaType.Projection:return exports.MediaType.Projection;case exports.MediaType.Handheld:return exports.MediaType.Handheld;case exports.MediaType.Braille:return exports.MediaType.Braille;case exports.MediaType.Embossed:return exports.MediaType.Embossed;case exports.MediaType.Aural:return exports.MediaType.Aural;case exports.MediaType.Speech:return exports.MediaType.Speech;default:return!1}}; +"use strict";var e,t,i,a=require("@csstools/css-parser-algorithms"),r=require("@csstools/css-tokenizer");exports.NodeType=void 0,(e=exports.NodeType||(exports.NodeType={})).GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid";class MediaCondition{type=exports.NodeType.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===exports.NodeType.MediaCondition)}}class MediaInParens{type=exports.NodeType.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.media.toString()+r.stringify(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&("walk"in this.media?this.media.walk(e):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===exports.NodeType.MediaInParens)}}class MediaQueryWithType{type=exports.NodeType.MediaQueryWithType;modifier;mediaType;and;media=null;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===exports.NodeType.MediaQueryInvalid)}}class GeneralEnclosed{type=exports.NodeType.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===exports.NodeType.GeneralEnclosed)}}class MediaAnd{type=exports.NodeType.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return r.stringify(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===exports.NodeType.MediaAnd)}}class MediaConditionListWithAnd{type=exports.NodeType.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===exports.NodeType.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=exports.NodeType.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===exports.NodeType.MediaConditionListWithOr)}}function isNumber(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Number||e.type===a.ComponentValueType.Function&&"calc"===e.name[4].value}function isDimension(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Dimension}function isIdent(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Ident}class MediaFeatureName{type=exports.NodeType.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.name.toString()+r.stringify(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===exports.NodeType.MediaFeatureName)}}function parseMediaFeatureName(e){let t=-1;for(let i=0;ie.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=exports.NodeType.MediaFeatureBoolean;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.name.toString()+r.stringify(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===exports.NodeType.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t.name,t.before,t.after)}class MediaFeatureValue{type=exports.NodeType.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?r.stringify(...this.before)+this.value.map((e=>e.toString())).join("")+r.stringify(...this.after):r.stringify(...this.before)+this.value.toString()+r.stringify(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===exports.NodeType.MediaFeatureValue)}}function parseMediaFeatureValue(e){let t=-1,i=-1;for(let r=0;re.tokens())),e.slice(i+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==r.TokenType.Delim)return!1;if(1===e.length)switch(e[0][4].value){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT;default:return!1}if(e[1][0]!==r.TokenType.Delim)return!1;if(e[1][4].value!==exports.MediaFeatureEQ.EQ)return!1;switch(e[0][4].value){case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT_OR_EQ;default:return!1}}exports.MediaFeatureLT=void 0,(t=exports.MediaFeatureLT||(exports.MediaFeatureLT={})).LT="<",t.LT_OR_EQ="<=",exports.MediaFeatureGT=void 0,(i=exports.MediaFeatureGT||(exports.MediaFeatureGT={})).GT=">",i.GT_OR_EQ=">=",exports.MediaFeatureEQ=void 0,(exports.MediaFeatureEQ||(exports.MediaFeatureEQ={})).EQ="=";class MediaFeatureRangeNameValue{type=exports.NodeType.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+r.stringify(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===exports.NodeType.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=exports.NodeType.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+r.stringify(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===exports.NodeType.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=exports.NodeType.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,r){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=r}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+r.stringify(...this.valueOneOperator)+this.name.toString()+r.stringify(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===exports.NodeType.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(e){let t=!1,i=!1;for(let n=0;ne.tokens())),-1!==i&&(s=e.slice(t+1,i+1).flatMap((e=>e.tokens())))):-1!==i&&(s=e.slice(0,i+1).flatMap((e=>e.tokens())));const u=parseMediaConditionWithoutOr(e.slice(Math.max(t,i,n)+1));return!1===u?new MediaQueryWithType(o,[...s,...e.slice(i+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(o,s,e.slice(i+1,n+1).flatMap((e=>e.tokens())),u)}}function parseMediaConditionListWithOr(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const r=parseMediaInParens(e);return!1!==r&&new MediaCondition(r)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(e){let t=-1;for(let i=0;ie.tokens())),i.startToken],o=[i.endToken,...e.slice(t+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(i,n,o);if(!1!==s)return new MediaInParens(s);const u=parseMediaCondition(i.value);return!1!==u?new MediaInParens(u,n,o):new MediaInParens(new GeneralEnclosed(i),e.slice(0,t).flatMap((e=>e.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==r.TokenType.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(e){let t=!1,i=null;for(let r=0;re.tokens())),t)}}}return i||!1}function parseMediaOr(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseMediaAnd(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseFromTokens(e,t){const i=a.parseCommaSeparatedListOfComponentValues(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const r=parseMediaQuery(e);return 0==r&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):r})).filter((e=>!!e))}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}exports.MediaQueryModifier=void 0,(o=exports.MediaQueryModifier||(exports.MediaQueryModifier={})).Not="not",o.Only="only",exports.MediaType=void 0,(s=exports.MediaType||(exports.MediaType={})).All="all",s.Print="print",s.Screen="screen",s.Tty="tty",s.Tv="tv",s.Projection="projection",s.Handheld="handheld",s.Braille="braille",s.Embossed="embossed",s.Aural="aural",s.Speech="speech",exports.GeneralEnclosed=GeneralEnclosed,exports.MediaAnd=MediaAnd,exports.MediaCondition=MediaCondition,exports.MediaConditionListWithAnd=MediaConditionListWithAnd,exports.MediaConditionListWithOr=MediaConditionListWithOr,exports.MediaFeature=MediaFeature,exports.MediaFeatureBoolean=MediaFeatureBoolean,exports.MediaFeatureName=MediaFeatureName,exports.MediaFeaturePlain=MediaFeaturePlain,exports.MediaFeatureRangeNameValue=MediaFeatureRangeNameValue,exports.MediaFeatureRangeValueName=MediaFeatureRangeValueName,exports.MediaFeatureRangeValueNameValue=MediaFeatureRangeValueNameValue,exports.MediaFeatureValue=MediaFeatureValue,exports.MediaInParens=MediaInParens,exports.MediaNot=MediaNot,exports.MediaOr=MediaOr,exports.MediaQueryInvalid=MediaQueryInvalid,exports.MediaQueryWithType=MediaQueryWithType,exports.MediaQueryWithoutType=MediaQueryWithoutType,exports.cloneMediaQuery=function cloneMediaQuery(e){const t=r.cloneTokens(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`)},exports.comparisonFromTokens=comparisonFromTokens,exports.invertComparison=function invertComparison(e){switch(e){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureGT.GT;case exports.MediaFeatureLT.LT_OR_EQ:return exports.MediaFeatureGT.GT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT_OR_EQ:return exports.MediaFeatureLT.LT_OR_EQ;default:return!1}},exports.isGeneralEnclosed=function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)},exports.isMediaAnd=function isMediaAnd(e){return MediaAnd.isMediaAnd(e)},exports.isMediaCondition=function isMediaCondition(e){return MediaCondition.isMediaCondition(e)},exports.isMediaConditionList=function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)},exports.isMediaConditionListWithAnd=isMediaConditionListWithAnd,exports.isMediaConditionListWithOr=isMediaConditionListWithOr,exports.isMediaFeature=function isMediaFeature(e){return MediaFeature.isMediaFeature(e)},exports.isMediaFeatureBoolean=function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)},exports.isMediaFeatureName=function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)},exports.isMediaFeaturePlain=function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)},exports.isMediaFeatureRange=function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)},exports.isMediaFeatureRangeNameValue=isMediaFeatureRangeNameValue,exports.isMediaFeatureRangeValueName=isMediaFeatureRangeValueName,exports.isMediaFeatureRangeValueNameValue=isMediaFeatureRangeValueNameValue,exports.isMediaFeatureValue=function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)},exports.isMediaInParens=function isMediaInParens(e){return MediaInParens.isMediaInParens(e)},exports.isMediaNot=function isMediaNot(e){return MediaNot.isMediaNot(e)},exports.isMediaOr=function isMediaOr(e){return MediaOr.isMediaOr(e)},exports.isMediaQuery=function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)},exports.isMediaQueryInvalid=isMediaQueryInvalid,exports.isMediaQueryWithType=isMediaQueryWithType,exports.isMediaQueryWithoutType=isMediaQueryWithoutType,exports.matchesComparison=matchesComparison,exports.matchesRatio=matchesRatio,exports.matchesRatioExactly=matchesRatioExactly,exports.modifierFromToken=modifierFromToken,exports.newMediaFeatureBoolean=function newMediaFeatureBoolean(e){return new MediaFeature(new MediaFeatureBoolean(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}])),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.newMediaFeaturePlain=function newMediaFeaturePlain(e,...t){return new MediaFeature(new MediaFeaturePlain(new MediaFeatureName(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}])),[r.TokenType.Colon,":",-1,-1,void 0],new MediaFeatureValue(t.map((e=>new a.TokenNode(e))))),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.parse=function parse(e,t){const i=r.tokenizer({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)},exports.parseFromTokens=parseFromTokens,exports.typeFromToken=function typeFromToken(e){if(e[0]!==r.TokenType.Ident)return!1;switch(e[4].value.toLowerCase()){case exports.MediaType.All:return exports.MediaType.All;case exports.MediaType.Print:return exports.MediaType.Print;case exports.MediaType.Screen:return exports.MediaType.Screen;case exports.MediaType.Tty:return exports.MediaType.Tty;case exports.MediaType.Tv:return exports.MediaType.Tv;case exports.MediaType.Projection:return exports.MediaType.Projection;case exports.MediaType.Handheld:return exports.MediaType.Handheld;case exports.MediaType.Braille:return exports.MediaType.Braille;case exports.MediaType.Embossed:return exports.MediaType.Embossed;case exports.MediaType.Aural:return exports.MediaType.Aural;case exports.MediaType.Speech:return exports.MediaType.Speech;default:return!1}}; diff --git a/packages/media-query-list-parser/dist/index.mjs b/packages/media-query-list-parser/dist/index.mjs index 890110ea1..1480c33cd 100644 --- a/packages/media-query-list-parser/dist/index.mjs +++ b/packages/media-query-list-parser/dist/index.mjs @@ -1 +1 @@ -import{ComponentValueType as e,TokenNode as t,isWhitespaceNode as i,isCommentNode as a,isTokenNode as n,parseCommaSeparatedListOfComponentValues as r}from"@csstools/css-parser-algorithms";import{stringify as s,TokenType as o,tokenizer as u,cloneTokens as d}from"@csstools/css-tokenizer";var l,h,m,f;!function(e){e.GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid"}(l||(l={}));class MediaCondition{type=l.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===l.MediaCondition)}}class MediaInParens{type=l.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return s(...this.before)+this.media.toString()+s(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&("walk"in this.media?this.media.walk(e):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===l.MediaInParens)}}class MediaQueryWithType{type=l.MediaQueryWithType;modifier;mediaType;and;media=null;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===l.MediaQueryInvalid)}}class GeneralEnclosed{type=l.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===l.GeneralEnclosed)}}class MediaAnd{type=l.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===l.MediaAnd)}}class MediaConditionListWithAnd{type=l.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===l.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=l.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===l.MediaConditionListWithOr)}}function isNumber(t){return t.type===e.Token&&t.value[0]===o.Number||t.type===e.Function&&"calc"===t.name[4].value}function isDimension(t){return t.type===e.Token&&t.value[0]===o.Dimension}function isIdent(t){return t.type===e.Token&&t.value[0]===o.Ident}class MediaFeatureName{type=l.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return s(...this.before)+this.name.toString()+s(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===l.MediaFeatureName)}}function parseMediaFeatureName(t){let i=-1;for(let a=0;ae.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=l.MediaFeatureBoolean;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return s(...this.before)+this.name.toString()+s(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===l.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t.name,t.before,t.after)}class MediaFeatureValue{type=l.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?s(...this.before)+this.value.map((e=>e.toString())).join("")+s(...this.after):s(...this.before)+this.value.toString()+s(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===l.MediaFeatureValue)}}function parseMediaFeatureValue(t){let i=-1,a=-1;for(let n=0;ne.tokens())),t.slice(a+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==o.Delim)return!1;if(1===e.length)switch(e[0][4].value){case f.EQ:return f.EQ;case h.LT:return h.LT;case m.GT:return m.GT;default:return!1}if(e[1][0]!==o.Delim)return!1;if(e[1][4].value!==f.EQ)return!1;switch(e[0][4].value){case h.LT:return h.LT_OR_EQ;case m.GT:return m.GT_OR_EQ;default:return!1}}function invertComparison(e){switch(e){case f.EQ:return f.EQ;case h.LT:return m.GT;case h.LT_OR_EQ:return m.GT_OR_EQ;case m.GT:return h.LT;case m.GT_OR_EQ:return h.LT_OR_EQ;default:return!1}}!function(e){e.LT="<",e.LT_OR_EQ="<="}(h||(h={})),function(e){e.GT=">",e.GT_OR_EQ=">="}(m||(m={})),function(e){e.EQ="="}(f||(f={}));class MediaFeatureRangeNameValue{type=l.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+s(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===l.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=l.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+s(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===l.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=l.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,n){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=n}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+s(...this.valueOneOperator)+this.name.toString()+s(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===l.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(t){let i=!1,a=!1;for(let n=0;nnew t(e))))),[[o.OpenParen,"(",-1,-1,void 0]],[[o.CloseParen,")",-1,-1,void 0]])}class MediaNot{type=l.MediaNot;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaNot(){return MediaNot.isMediaNot(this)}static isMediaNot(e){return!!e&&(e instanceof MediaNot&&e.type===l.MediaNot)}}class MediaOr{type=l.MediaOr;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaOr(){return MediaOr.isMediaOr(this)}static isMediaOr(e){return!!e&&(e instanceof MediaOr&&e.type===l.MediaOr)}}var M,p;function modifierFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case M.Not:return M.Not;case M.Only:return M.Only;default:return!1}}function parseMediaQuery(e){{const t=parseMediaCondition(e);if(!1!==t)return new MediaQueryWithoutType(t)}{let t=-1,r=-1,s=-1;for(let u=0;ue.tokens())),-1!==r&&(d=e.slice(t+1,r+1).flatMap((e=>e.tokens())))):-1!==r&&(d=e.slice(0,r+1).flatMap((e=>e.tokens())));const l=parseMediaConditionWithoutOr(e.slice(Math.max(t,r,s)+1));return!1===l?new MediaQueryWithType(u,[...d,...e.slice(r+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(u,d,e.slice(r+1,s+1).flatMap((e=>e.tokens())),l)}}function parseMediaConditionListWithOr(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const n=parseMediaInParens(e);return!1!==n&&new MediaCondition(n)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(t){let i=-1;for(let a=0;ae.tokens())),a.startToken],r=[a.endToken,...t.slice(i+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(a,n,r);if(!1!==s)return new MediaInParens(s);const u=parseMediaCondition(a.value);return!1!==u?new MediaInParens(u,n,r):new MediaInParens(new GeneralEnclosed(a),t.slice(0,i).flatMap((e=>e.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==o.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(t){let i=!1,a=null;for(let n=0;ne.tokens())),e)}}}return a||!1}function parseMediaOr(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseMediaAnd(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseFromTokens(e,t){const i=r(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const n=parseMediaQuery(e);return 0==n&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):n})).filter((e=>!!e))}function parse(e,t){const i=u({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)}function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)}function isMediaAnd(e){return MediaAnd.isMediaAnd(e)}function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaCondition(e){return MediaCondition.isMediaCondition(e)}function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)}function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)}function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)}function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)}function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaFeature(e){return MediaFeature.isMediaFeature(e)}function isMediaInParens(e){return MediaInParens.isMediaInParens(e)}function isMediaNot(e){return MediaNot.isMediaNot(e)}function isMediaOr(e){return MediaOr.isMediaOr(e)}function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}function typeFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case p.All:return p.All;case p.Print:return p.Print;case p.Screen:return p.Screen;case p.Tty:return p.Tty;case p.Tv:return p.Tv;case p.Projection:return p.Projection;case p.Handheld:return p.Handheld;case p.Braille:return p.Braille;case p.Embossed:return p.Embossed;case p.Aural:return p.Aural;case p.Speech:return p.Speech;default:return!1}}function cloneMediaQuery(e){const t=d(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${s(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${s(...t)}"`)}!function(e){e.Not="not",e.Only="only"}(M||(M={})),function(e){e.All="all",e.Print="print",e.Screen="screen",e.Tty="tty",e.Tv="tv",e.Projection="projection",e.Handheld="handheld",e.Braille="braille",e.Embossed="embossed",e.Aural="aural",e.Speech="speech"}(p||(p={}));export{GeneralEnclosed,MediaAnd,MediaCondition,MediaConditionListWithAnd,MediaConditionListWithOr,MediaFeature,MediaFeatureBoolean,f as MediaFeatureEQ,m as MediaFeatureGT,h as MediaFeatureLT,MediaFeatureName,MediaFeaturePlain,MediaFeatureRangeNameValue,MediaFeatureRangeValueName,MediaFeatureRangeValueNameValue,MediaFeatureValue,MediaInParens,MediaNot,MediaOr,MediaQueryInvalid,M as MediaQueryModifier,MediaQueryWithType,MediaQueryWithoutType,p as MediaType,l as NodeType,cloneMediaQuery,comparisonFromTokens,invertComparison,isGeneralEnclosed,isMediaAnd,isMediaCondition,isMediaConditionList,isMediaConditionListWithAnd,isMediaConditionListWithOr,isMediaFeature,isMediaFeatureBoolean,isMediaFeatureName,isMediaFeaturePlain,isMediaFeatureRange,isMediaFeatureRangeNameValue,isMediaFeatureRangeValueName,isMediaFeatureRangeValueNameValue,isMediaFeatureValue,isMediaInParens,isMediaNot,isMediaOr,isMediaQuery,isMediaQueryInvalid,isMediaQueryWithType,isMediaQueryWithoutType,matchesComparison,matchesRatio,matchesRatioExactly,modifierFromToken,newMediaFeatureBoolean,newMediaFeaturePlain,parse,parseFromTokens,typeFromToken}; +import{ComponentValueType as e,TokenNode as t,isWhitespaceNode as i,isCommentNode as a,isTokenNode as n,parseCommaSeparatedListOfComponentValues as r}from"@csstools/css-parser-algorithms";import{stringify as s,TokenType as o,tokenizer as u,cloneTokens as d}from"@csstools/css-tokenizer";var l,h,m,f;!function(e){e.GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid"}(l||(l={}));class MediaCondition{type=l.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===l.MediaCondition)}}class MediaInParens{type=l.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return s(...this.before)+this.media.toString()+s(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&("walk"in this.media?this.media.walk(e):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===l.MediaInParens)}}class MediaQueryWithType{type=l.MediaQueryWithType;modifier;mediaType;and;media=null;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===l.MediaQueryInvalid)}}class GeneralEnclosed{type=l.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===l.GeneralEnclosed)}}class MediaAnd{type=l.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===l.MediaAnd)}}class MediaConditionListWithAnd{type=l.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===l.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=l.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===l.MediaConditionListWithOr)}}function isNumber(t){return t.type===e.Token&&t.value[0]===o.Number||t.type===e.Function&&"calc"===t.name[4].value}function isDimension(t){return t.type===e.Token&&t.value[0]===o.Dimension}function isIdent(t){return t.type===e.Token&&t.value[0]===o.Ident}class MediaFeatureName{type=l.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return s(...this.before)+this.name.toString()+s(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===l.MediaFeatureName)}}function parseMediaFeatureName(t){let i=-1;for(let a=0;ae.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=l.MediaFeatureBoolean;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return s(...this.before)+this.name.toString()+s(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===l.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t.name,t.before,t.after)}class MediaFeatureValue{type=l.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?s(...this.before)+this.value.map((e=>e.toString())).join("")+s(...this.after):s(...this.before)+this.value.toString()+s(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===l.MediaFeatureValue)}}function parseMediaFeatureValue(t){let i=-1,a=-1;for(let n=0;ne.tokens())),t.slice(a+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==o.Delim)return!1;if(1===e.length)switch(e[0][4].value){case f.EQ:return f.EQ;case h.LT:return h.LT;case m.GT:return m.GT;default:return!1}if(e[1][0]!==o.Delim)return!1;if(e[1][4].value!==f.EQ)return!1;switch(e[0][4].value){case h.LT:return h.LT_OR_EQ;case m.GT:return m.GT_OR_EQ;default:return!1}}function invertComparison(e){switch(e){case f.EQ:return f.EQ;case h.LT:return m.GT;case h.LT_OR_EQ:return m.GT_OR_EQ;case m.GT:return h.LT;case m.GT_OR_EQ:return h.LT_OR_EQ;default:return!1}}!function(e){e.LT="<",e.LT_OR_EQ="<="}(h||(h={})),function(e){e.GT=">",e.GT_OR_EQ=">="}(m||(m={})),function(e){e.EQ="="}(f||(f={}));class MediaFeatureRangeNameValue{type=l.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+s(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===l.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=l.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+s(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===l.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=l.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,n){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=n}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+s(...this.valueOneOperator)+this.name.toString()+s(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===l.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(t){let i=!1,a=!1;for(let n=0;nnew t(e))))),[[o.OpenParen,"(",-1,-1,void 0]],[[o.CloseParen,")",-1,-1,void 0]])}class MediaNot{type=l.MediaNot;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaNot(){return MediaNot.isMediaNot(this)}static isMediaNot(e){return!!e&&(e instanceof MediaNot&&e.type===l.MediaNot)}}class MediaOr{type=l.MediaOr;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaOr(){return MediaOr.isMediaOr(this)}static isMediaOr(e){return!!e&&(e instanceof MediaOr&&e.type===l.MediaOr)}}var M,p;function modifierFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case M.Not:return M.Not;case M.Only:return M.Only;default:return!1}}function parseMediaQuery(e){{const t=parseMediaCondition(e);if(!1!==t)return new MediaQueryWithoutType(t)}{let t=-1,r=-1,s=-1;for(let u=0;ue.tokens())),-1!==r&&(d=e.slice(t+1,r+1).flatMap((e=>e.tokens())))):-1!==r&&(d=e.slice(0,r+1).flatMap((e=>e.tokens())));const l=parseMediaConditionWithoutOr(e.slice(Math.max(t,r,s)+1));return!1===l?new MediaQueryWithType(u,[...d,...e.slice(r+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(u,d,e.slice(r+1,s+1).flatMap((e=>e.tokens())),l)}}function parseMediaConditionListWithOr(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const n=parseMediaInParens(e);return!1!==n&&new MediaCondition(n)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(t){let i=-1;for(let a=0;ae.tokens())),a.startToken],r=[a.endToken,...t.slice(i+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(a,n,r);if(!1!==s)return new MediaInParens(s);const u=parseMediaCondition(a.value);return!1!==u?new MediaInParens(u,n,r):new MediaInParens(new GeneralEnclosed(a),t.slice(0,i).flatMap((e=>e.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==o.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(t){let i=!1,a=null;for(let n=0;ne.tokens())),e)}}}return a||!1}function parseMediaOr(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseMediaAnd(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseFromTokens(e,t){const i=r(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const n=parseMediaQuery(e);return 0==n&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):n})).filter((e=>!!e))}function parse(e,t){const i=u({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)}function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)}function isMediaAnd(e){return MediaAnd.isMediaAnd(e)}function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaCondition(e){return MediaCondition.isMediaCondition(e)}function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)}function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)}function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)}function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)}function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaFeature(e){return MediaFeature.isMediaFeature(e)}function isMediaInParens(e){return MediaInParens.isMediaInParens(e)}function isMediaNot(e){return MediaNot.isMediaNot(e)}function isMediaOr(e){return MediaOr.isMediaOr(e)}function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}function typeFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case p.All:return p.All;case p.Print:return p.Print;case p.Screen:return p.Screen;case p.Tty:return p.Tty;case p.Tv:return p.Tv;case p.Projection:return p.Projection;case p.Handheld:return p.Handheld;case p.Braille:return p.Braille;case p.Embossed:return p.Embossed;case p.Aural:return p.Aural;case p.Speech:return p.Speech;default:return!1}}function cloneMediaQuery(e){const t=d(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${s(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${s(...t)}"`)}!function(e){e.Not="not",e.Only="only"}(M||(M={})),function(e){e.All="all",e.Print="print",e.Screen="screen",e.Tty="tty",e.Tv="tv",e.Projection="projection",e.Handheld="handheld",e.Braille="braille",e.Embossed="embossed",e.Aural="aural",e.Speech="speech"}(p||(p={}));export{GeneralEnclosed,MediaAnd,MediaCondition,MediaConditionListWithAnd,MediaConditionListWithOr,MediaFeature,MediaFeatureBoolean,f as MediaFeatureEQ,m as MediaFeatureGT,h as MediaFeatureLT,MediaFeatureName,MediaFeaturePlain,MediaFeatureRangeNameValue,MediaFeatureRangeValueName,MediaFeatureRangeValueNameValue,MediaFeatureValue,MediaInParens,MediaNot,MediaOr,MediaQueryInvalid,M as MediaQueryModifier,MediaQueryWithType,MediaQueryWithoutType,p as MediaType,l as NodeType,cloneMediaQuery,comparisonFromTokens,invertComparison,isGeneralEnclosed,isMediaAnd,isMediaCondition,isMediaConditionList,isMediaConditionListWithAnd,isMediaConditionListWithOr,isMediaFeature,isMediaFeatureBoolean,isMediaFeatureName,isMediaFeaturePlain,isMediaFeatureRange,isMediaFeatureRangeNameValue,isMediaFeatureRangeValueName,isMediaFeatureRangeValueNameValue,isMediaFeatureValue,isMediaInParens,isMediaNot,isMediaOr,isMediaQuery,isMediaQueryInvalid,isMediaQueryWithType,isMediaQueryWithoutType,matchesComparison,matchesRatio,matchesRatioExactly,modifierFromToken,newMediaFeatureBoolean,newMediaFeaturePlain,parse,parseFromTokens,typeFromToken}; diff --git a/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts b/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts index a95933352..0b0cfaff5 100644 --- a/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts +++ b/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts @@ -1,6 +1,6 @@ import { ComponentValue } from '@csstools/css-parser-algorithms'; import { NodeType } from '../util/node-type'; -import { CSSToken } from '@csstools/css-tokenizer'; +import { CSSToken, TokenIdent } from '@csstools/css-tokenizer'; export declare class MediaFeatureBoolean { type: NodeType; name: ComponentValue; @@ -8,6 +8,7 @@ export declare class MediaFeatureBoolean { after: Array; constructor(name: ComponentValue, before?: Array, after?: Array); getName(): string; + getNameToken(): TokenIdent; tokens(): Array; toString(): string; indexOf(item: ComponentValue): number | string; diff --git a/packages/media-query-list-parser/dist/nodes/media-feature-name.d.ts b/packages/media-query-list-parser/dist/nodes/media-feature-name.d.ts index 52a7aa9b8..913012836 100644 --- a/packages/media-query-list-parser/dist/nodes/media-feature-name.d.ts +++ b/packages/media-query-list-parser/dist/nodes/media-feature-name.d.ts @@ -1,5 +1,5 @@ import { ComponentValue } from '@csstools/css-parser-algorithms'; -import { CSSToken } from '@csstools/css-tokenizer'; +import { CSSToken, TokenIdent } from '@csstools/css-tokenizer'; import { NodeType } from '../util/node-type'; export declare class MediaFeatureName { type: NodeType; @@ -8,6 +8,7 @@ export declare class MediaFeatureName { after: Array; constructor(name: ComponentValue, before?: Array, after?: Array); getName(): string; + getNameToken(): TokenIdent; tokens(): Array; toString(): string; indexOf(item: ComponentValue): number | string; diff --git a/packages/media-query-list-parser/dist/nodes/media-feature-plain.d.ts b/packages/media-query-list-parser/dist/nodes/media-feature-plain.d.ts index 494e2cdd9..6de07886d 100644 --- a/packages/media-query-list-parser/dist/nodes/media-feature-plain.d.ts +++ b/packages/media-query-list-parser/dist/nodes/media-feature-plain.d.ts @@ -9,6 +9,8 @@ export declare class MediaFeaturePlain { colon: TokenColon; value: MediaFeatureValue; constructor(name: MediaFeatureName, colon: TokenColon, value: MediaFeatureValue); + getName(): void; + getNameToken(): void; tokens(): Array; toString(): string; indexOf(item: MediaFeatureName | MediaFeatureValue): number | string; diff --git a/packages/media-query-list-parser/dist/nodes/media-feature-range.d.ts b/packages/media-query-list-parser/dist/nodes/media-feature-range.d.ts index 487304d61..d68cba8f7 100644 --- a/packages/media-query-list-parser/dist/nodes/media-feature-range.d.ts +++ b/packages/media-query-list-parser/dist/nodes/media-feature-range.d.ts @@ -11,6 +11,8 @@ export declare class MediaFeatureRangeNameValue { value: MediaFeatureValue; constructor(name: MediaFeatureName, operator: [TokenDelim, TokenDelim] | [TokenDelim], value: MediaFeatureValue); operatorKind(): false | import("./media-feature-comparison").MediaFeatureComparison; + getName(): void; + getNameToken(): void; tokens(): Array; toString(): string; indexOf(item: MediaFeatureName | MediaFeatureValue): number | string; @@ -43,6 +45,8 @@ export declare class MediaFeatureRangeValueName { value: MediaFeatureValue; constructor(name: MediaFeatureName, operator: [TokenDelim, TokenDelim] | [TokenDelim], value: MediaFeatureValue); operatorKind(): false | import("./media-feature-comparison").MediaFeatureComparison; + getName(): void; + getNameToken(): void; tokens(): Array; toString(): string; indexOf(item: MediaFeatureName | MediaFeatureValue): number | string; @@ -78,6 +82,8 @@ export declare class MediaFeatureRangeValueNameValue { constructor(name: MediaFeatureName, valueOne: MediaFeatureValue, valueOneOperator: [TokenDelim, TokenDelim] | [TokenDelim], valueTwo: MediaFeatureValue, valueTwoOperator: [TokenDelim, TokenDelim] | [TokenDelim]); valueOneOperatorKind(): false | import("./media-feature-comparison").MediaFeatureComparison; valueTwoOperatorKind(): false | import("./media-feature-comparison").MediaFeatureComparison; + getName(): void; + getNameToken(): void; tokens(): Array; toString(): string; indexOf(item: MediaFeatureName | MediaFeatureValue): number | string; diff --git a/packages/media-query-list-parser/dist/nodes/media-feature.d.ts b/packages/media-query-list-parser/dist/nodes/media-feature.d.ts index 3f7474784..371d926d0 100644 --- a/packages/media-query-list-parser/dist/nodes/media-feature.d.ts +++ b/packages/media-query-list-parser/dist/nodes/media-feature.d.ts @@ -10,6 +10,8 @@ export declare class MediaFeature { before: Array; after: Array; constructor(feature: MediaFeaturePlain | MediaFeatureBoolean | MediaFeatureRange, before?: Array, after?: Array); + getName(): void; + getNameToken(): void; tokens(): Array; toString(): string; indexOf(item: MediaFeaturePlain | MediaFeatureBoolean | MediaFeatureRange): number | string; diff --git a/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts b/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts index f53344500..b404de3c9 100644 --- a/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts +++ b/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts @@ -21,6 +21,11 @@ export class MediaFeatureBoolean { return token[4].value; } + getNameToken() { + const token = (((this.name as TokenNode).value as CSSToken) as TokenIdent); + return token; + } + tokens(): Array { return [ ...this.before, diff --git a/packages/media-query-list-parser/src/nodes/media-feature-name.ts b/packages/media-query-list-parser/src/nodes/media-feature-name.ts index 85bd0e592..9b5cd8cbd 100644 --- a/packages/media-query-list-parser/src/nodes/media-feature-name.ts +++ b/packages/media-query-list-parser/src/nodes/media-feature-name.ts @@ -21,6 +21,11 @@ export class MediaFeatureName { return token[4].value; } + getNameToken() { + const token = (((this.name as TokenNode).value as CSSToken) as TokenIdent); + return token; + } + tokens(): Array { return [ ...this.before, diff --git a/packages/media-query-list-parser/src/nodes/media-feature-plain.ts b/packages/media-query-list-parser/src/nodes/media-feature-plain.ts index 4d1a32d5f..35bdf157c 100644 --- a/packages/media-query-list-parser/src/nodes/media-feature-plain.ts +++ b/packages/media-query-list-parser/src/nodes/media-feature-plain.ts @@ -17,6 +17,14 @@ export class MediaFeaturePlain { this.value = value; } + getName() { + this.name.getName(); + } + + getNameToken() { + this.name.getNameToken(); + } + tokens(): Array { return [ ...this.name.tokens(), diff --git a/packages/media-query-list-parser/src/nodes/media-feature-range.ts b/packages/media-query-list-parser/src/nodes/media-feature-range.ts index 7f9f5aff4..a7d57bf47 100644 --- a/packages/media-query-list-parser/src/nodes/media-feature-range.ts +++ b/packages/media-query-list-parser/src/nodes/media-feature-range.ts @@ -26,6 +26,14 @@ export class MediaFeatureRangeNameValue { return comparisonFromTokens(this.operator); } + getName() { + this.name.getName(); + } + + getNameToken() { + this.name.getNameToken(); + } + tokens(): Array { return [ ...this.name.tokens(), @@ -113,6 +121,14 @@ export class MediaFeatureRangeValueName { return comparisonFromTokens(this.operator); } + getName() { + this.name.getName(); + } + + getNameToken() { + this.name.getNameToken(); + } + tokens(): Array { return [ ...this.value.tokens(), @@ -208,6 +224,14 @@ export class MediaFeatureRangeValueNameValue { return comparisonFromTokens(this.valueTwoOperator); } + getName() { + this.name.getName(); + } + + getNameToken() { + this.name.getNameToken(); + } + tokens(): Array { return [ ...this.valueOne.tokens(), diff --git a/packages/media-query-list-parser/src/nodes/media-feature.ts b/packages/media-query-list-parser/src/nodes/media-feature.ts index d9a9a4137..c1d585042 100644 --- a/packages/media-query-list-parser/src/nodes/media-feature.ts +++ b/packages/media-query-list-parser/src/nodes/media-feature.ts @@ -20,6 +20,14 @@ export class MediaFeature { this.after = after; } + getName() { + this.feature.getName(); + } + + getNameToken() { + this.feature.getNameToken(); + } + tokens(): Array { return [ ...this.before, diff --git a/packages/media-query-list-parser/test/cases/various/0008.expect.json b/packages/media-query-list-parser/test/cases/various/0008.expect.json new file mode 100644 index 000000000..39da3cf0b --- /dev/null +++ b/packages/media-query-list-parser/test/cases/various/0008.expect.json @@ -0,0 +1,128 @@ +[ + { + "type": "media-query-without-type", + "string": "(min-width: 300px", + "media": { + "type": "media-condition", + "media": { + "type": "media-in-parens", + "media": { + "type": "media-feature", + "feature": { + "type": "mf-plain", + "name": { + "type": "mf-name", + "name": "min-width", + "tokens": [ + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ] + ] + }, + "value": { + "type": "mf-value", + "value": { + "type": "token", + "tokens": [ + [ + "dimension-token", + "300px", + 12, + 16, + { + "value": 300, + "type": "integer", + "unit": "px" + } + ] + ] + }, + "tokens": [ + [ + "whitespace-token", + " ", + 11, + 11, + null + ], + [ + "dimension-token", + "300px", + 12, + 16, + { + "value": 300, + "type": "integer", + "unit": "px" + } + ] + ] + }, + "tokens": [ + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ], + [ + "colon-token", + ":", + 10, + 10, + null + ], + [ + "whitespace-token", + " ", + 11, + 11, + null + ], + [ + "dimension-token", + "300px", + 12, + 16, + { + "value": 300, + "type": "integer", + "unit": "px" + } + ] + ] + }, + "before": [ + [ + "(-token", + "(", + 0, + 0, + null + ] + ], + "after": [ + [ + "EOF-token", + "", + -1, + -1, + null + ] + ] + }, + "before": [], + "after": [] + } + } + } +] \ No newline at end of file diff --git a/packages/media-query-list-parser/test/cases/various/0008.mjs b/packages/media-query-list-parser/test/cases/various/0008.mjs new file mode 100644 index 000000000..a14b89947 --- /dev/null +++ b/packages/media-query-list-parser/test/cases/various/0008.mjs @@ -0,0 +1,13 @@ +import assert from 'assert'; +import { runTest } from '../../util/run-test.mjs'; + +runTest( + '(min-width: 300px', + 'various/0008', + (actual, expected) => { + assert.deepStrictEqual( + actual, + expected, + ); + }, +); diff --git a/packages/media-query-list-parser/test/test.mjs b/packages/media-query-list-parser/test/test.mjs index 67bbf4beb..e77fde399 100644 --- a/packages/media-query-list-parser/test/test.mjs +++ b/packages/media-query-list-parser/test/test.mjs @@ -65,5 +65,6 @@ import './cases/various/0004.mjs'; import './cases/various/0005.mjs'; import './cases/various/0006.mjs'; import './cases/various/0007.mjs'; +import './cases/various/0008.mjs'; import './serialize/0001.mjs'; From 27fca8c0ed90673498065265fc7104b913e2b97c Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Fri, 30 Dec 2022 14:14:25 +0100 Subject: [PATCH 13/24] more improvements --- packages/css-tokenizer/dist/index.cjs | 2 +- packages/css-tokenizer/dist/index.d.ts | 1 + packages/css-tokenizer/dist/index.mjs | 2 +- .../css-tokenizer/dist/util/mutations.d.ts | 2 + packages/css-tokenizer/src/index.ts | 4 + packages/css-tokenizer/src/util/mutations.ts | 46 +++ .../css-tokenizer/test/mutations/ident.mjs | 251 +++++++++++++ packages/css-tokenizer/test/test.mjs | 3 + packages/media-query-list-parser/CHANGELOG.md | 1 + .../media-query-list-parser/dist/index.cjs | 2 +- .../media-query-list-parser/dist/index.mjs | 2 +- .../dist/nodes/media-feature-boolean.d.ts | 21 +- .../dist/nodes/media-feature.d.ts | 27 -- .../src/nodes/media-feature-boolean.ts | 34 +- .../src/nodes/media-feature.ts | 2 +- .../test/cases/media-not/0001.expect.json | 16 +- .../test/cases/mf-boolean/0001.expect.json | 16 +- .../test/cases/mf-boolean/0002.expect.json | 30 +- .../test/cases/mf-boolean/0003.expect.json | 16 +- .../test/cases/mf-boolean/0004.expect.json | 16 +- .../test/cases/mf-plain/0006.expect.json | 351 ++++++++++++++++++ .../test/cases/mf-plain/0006.mjs | 13 + .../test/cases/mf-plain/0007.expect.json | 351 ++++++++++++++++++ .../test/cases/mf-plain/0007.mjs | 13 + .../test/cases/mf-plain/0008.expect.json | 81 ++++ .../test/cases/mf-plain/0008.mjs | 14 + .../cases/query-with-type/0008.expect.json | 16 +- .../specification-examples/0003.expect.json | 32 +- .../specification-examples/0010.expect.json | 32 +- .../specification-examples/0011.expect.json | 32 +- .../specification-examples/0012.expect.json | 32 +- .../specification-examples/0013.expect.json | 48 ++- .../specification-examples/0014.expect.json | 48 ++- .../specification-examples/0019.expect.json | 32 +- .../media-query-list-parser/test/test.mjs | 3 + 35 files changed, 1507 insertions(+), 85 deletions(-) create mode 100644 packages/css-tokenizer/dist/util/mutations.d.ts create mode 100644 packages/css-tokenizer/src/util/mutations.ts create mode 100644 packages/css-tokenizer/test/mutations/ident.mjs create mode 100644 packages/media-query-list-parser/test/cases/mf-plain/0006.expect.json create mode 100644 packages/media-query-list-parser/test/cases/mf-plain/0006.mjs create mode 100644 packages/media-query-list-parser/test/cases/mf-plain/0007.expect.json create mode 100644 packages/media-query-list-parser/test/cases/mf-plain/0007.mjs create mode 100644 packages/media-query-list-parser/test/cases/mf-plain/0008.expect.json create mode 100644 packages/media-query-list-parser/test/cases/mf-plain/0008.mjs diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index 34397314b..0b59d5468 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1 @@ -"use strict";class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===g)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===T)}function isNewLine(e){switch(e){case x:case i:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case x:case i:case S:case c:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,o){return o.codePointSource[o.cursor]===N&&o.codePointSource[o.cursor+1]!==x}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.codePointSource[o.cursor]===T?o.codePointSource[o.cursor+1]===T||(!!isIdentStartCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===N&&o.codePointSource[o.cursor+2]!==x):!!isIdentStartCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)}function checkIfThreeCodePointsWouldStartANumber(e,o){return o.codePointSource[o.cursor]===w||o.codePointSource[o.cursor]===T?!!isDigitCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===P&&isDigitCodePoint(o.codePointSource[o.cursor+2]):o.codePointSource[o.cursor]===P?isDigitCodePoint(o.codePointSource[o.cursor+1]):!!isDigitCodePoint(o.codePointSource[o.cursor])}function checkIfTwoCodePointsStartAComment(e,o){return o.codePointSource[o.cursor]===B&&o.codePointSource[o.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,o){return o.codePointSource[o.cursor]===T&&o.codePointSource[o.cursor+1]===T&&o.codePointSource[o.cursor+2]===h}function consumeComment(e,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(!1===t){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(t===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,o){const t=o.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:o.representationStart,end:o.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==o.codePointSource[o.cursor]&&isHexDigitCodePoint(o.codePointSource[o.cursor])&&e.length<6;)e.push(o.codePointSource[o.cursor]),o.advanceCodePoint();isWhitespace(o.codePointSource[o.cursor])&&o.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:X<=(r=n)&&r<=Y||n>I?b:n}var r;return t}function consumeIdentSequence(e,o){const t=[];for(;;)if(isIdentCodePoint(o.codePointSource[o.cursor]))t.push(o.codePointSource[o.cursor]),o.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,o))return t;o.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,o))}}function consumeHashToken(e,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=t.ID);const n=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n),type:r}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let t=exports.NumberType.Integer;for(o.codePointSource[o.cursor]!==w&&o.codePointSource[o.cursor]!==T||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===T||o.codePointSource[o.cursor+1]===w)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),t]}function consumeNumericToken(e,o){const t=consumeNumber(0,o);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:t[0],type:t[1],unit:String.fromCharCode(...r)}]}return o.codePointSource[o.cursor]===D?(o.advanceCodePoint(),[exports.TokenType.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0]}]):[exports.TokenType.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0],type:t[1]}]}function consumeWhiteSpace(e,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[exports.TokenType.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(e,o){let t="";const r=o.readCodePoint();for(;;){const n=o.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isNewLine(n))return e.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[exports.TokenType.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(n===r)return[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(n!==N)t+=String.fromCharCode(n);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}t+=String.fromCharCode(consumeEscapedCodePoint(e,o))}}}const $="u".charCodeAt(0),ee="U".charCodeAt(0),oe="r".charCodeAt(0),te="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,o){return 3===o.length&&((o[0]===$||o[0]===ee)&&((o[1]===oe||o[1]===te)&&(o[2]===re||o[2]===ne)))}function consumeBadURL(e,o){for(;;){if(void 0===o.codePointSource[o.cursor])return;if(o.codePointSource[o.cursor]===W)return void o.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,o)?(o.advanceCodePoint(),consumeEscapedCodePoint(e,o)):o.advanceCodePoint()}}function consumeUrlToken(e,o){consumeWhiteSpace(0,o);let t="";for(;;){if(void 0===o.codePointSource[o.cursor])return e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(o.codePointSource[o.cursor]===W)return o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):o.codePointSource[o.cursor]===W?(o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):(consumeBadURL(e,o),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===L||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===E||((n=o.codePointSource[o.cursor])===y||n===p||U<=n&&n<=s||V<=n&&n<=l))return consumeBadURL(e,o),e.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){t+=String.fromCharCode(consumeEscapedCodePoint(e,o));continue}return consumeBadURL(e,o),e.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}t+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var n}function consumeIdentLikeToken(e,o){const t=consumeIdentSequence(e,o);if(o.codePointSource[o.cursor]!==E)return[exports.TokenType.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];if(checkIfCodePointsMatchURLIdent(0,t)){o.advanceCodePoint();let n=0;for(;;){const e=isWhitespace(o.codePointSource[o.cursor]),s=isWhitespace(o.codePointSource[o.cursor+1]);if(e&&s){n+=2,o.advanceCodePoint(2);continue}const i=e?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(i===L||i===r)return n>0&&o.advanceCodePoint(n),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];break}return n>0&&o.advanceCodePoint(n),consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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.stringify=function stringify(...e){let o="";for(let t=0;t{})};return{nextToken:function nextToken(){if(n.representationStart=n.cursor,n.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,n)){if(null!=o&&o.commentsAreTokens)return consumeComment(s,n);consumeComment(s,n),n.representationStart=n.cursor,n.representationEnd=-1}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(s,n);if(isDigitCodePoint(e))return consumeNumericToken(s,n);switch(e){case d:return n.advanceCodePoint(),[exports.TokenType.Comma,",",n.representationStart,n.representationEnd,void 0];case a:return n.advanceCodePoint(),[exports.TokenType.Colon,":",n.representationStart,n.representationEnd,void 0];case q:return n.advanceCodePoint(),[exports.TokenType.Semicolon,";",n.representationStart,n.representationEnd,void 0];case E:return n.advanceCodePoint(),[exports.TokenType.OpenParen,"(",n.representationStart,n.representationEnd,void 0];case W:return n.advanceCodePoint(),[exports.TokenType.CloseParen,")",n.representationStart,n.representationEnd,void 0];case v:return n.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",n.representationStart,n.representationEnd,void 0];case F:return n.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",n.representationStart,n.representationEnd,void 0];case f:return n.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",n.representationStart,n.representationEnd,void 0];case R:return n.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",n.representationStart,n.representationEnd,void 0];case r:case L:return consumeStringToken(s,n);case O:return consumeHashToken(s,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]);case x:case i:case S:case c:case H:return consumeWhiteSpace(0,n);case T:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(s,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),[exports.TokenType.Delim,"-",n.representationStart,n.representationEnd,{value:"-"}]);case A:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",n.representationStart,n.representationEnd,void 0]):(n.advanceCodePoint(),[exports.TokenType.Delim,"<",n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(s,n);return[exports.TokenType.AtKeyword,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,"@",n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(s,n):(n.advanceCodePoint(),s.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,"\\",n.representationStart,n.representationEnd,{value:"\\"}])}return n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; +"use strict";class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===g)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case x:case s:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case x:case s:case S:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,o){return o.codePointSource[o.cursor]===N&&o.codePointSource[o.cursor+1]!==x}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.codePointSource[o.cursor]===l?o.codePointSource[o.cursor+1]===l||(!!isIdentStartCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===N&&o.codePointSource[o.cursor+2]!==x):!!isIdentStartCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)}function checkIfThreeCodePointsWouldStartANumber(e,o){return o.codePointSource[o.cursor]===w||o.codePointSource[o.cursor]===l?!!isDigitCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===P&&isDigitCodePoint(o.codePointSource[o.cursor+2]):o.codePointSource[o.cursor]===P?isDigitCodePoint(o.codePointSource[o.cursor+1]):!!isDigitCodePoint(o.codePointSource[o.cursor])}function checkIfTwoCodePointsStartAComment(e,o){return o.codePointSource[o.cursor]===B&&o.codePointSource[o.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,o){return o.codePointSource[o.cursor]===l&&o.codePointSource[o.cursor+1]===l&&o.codePointSource[o.cursor+2]===h}function consumeComment(e,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(!1===t){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(t===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,o){const t=o.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:o.representationStart,end:o.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==o.codePointSource[o.cursor]&&isHexDigitCodePoint(o.codePointSource[o.cursor])&&e.length<6;)e.push(o.codePointSource[o.cursor]),o.advanceCodePoint();isWhitespace(o.codePointSource[o.cursor])&&o.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:G<=(r=n)&&r<=X||n>I?b:n}var r;return t}function consumeIdentSequence(e,o){const t=[];for(;;)if(isIdentCodePoint(o.codePointSource[o.cursor]))t.push(o.codePointSource[o.cursor]),o.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,o))return t;o.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,o))}}function consumeHashToken(e,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=t.ID);const n=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n),type:r}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let t=exports.NumberType.Integer;for(o.codePointSource[o.cursor]!==w&&o.codePointSource[o.cursor]!==l||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===l||o.codePointSource[o.cursor+1]===w)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),t]}function consumeNumericToken(e,o){const t=consumeNumber(0,o);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:t[0],type:t[1],unit:String.fromCharCode(...r)}]}return o.codePointSource[o.cursor]===D?(o.advanceCodePoint(),[exports.TokenType.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0]}]):[exports.TokenType.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0],type:t[1]}]}function consumeWhiteSpace(e,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[exports.TokenType.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(e,o){let t="";const r=o.readCodePoint();for(;;){const n=o.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isNewLine(n))return e.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[exports.TokenType.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(n===r)return[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(n!==N)t+=String.fromCharCode(n);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}t+=String.fromCharCode(consumeEscapedCodePoint(e,o))}}}const Y="u".charCodeAt(0),ee="U".charCodeAt(0),oe="r".charCodeAt(0),te="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,o){return 3===o.length&&((o[0]===Y||o[0]===ee)&&((o[1]===oe||o[1]===te)&&(o[2]===re||o[2]===ne)))}function consumeBadURL(e,o){for(;;){if(void 0===o.codePointSource[o.cursor])return;if(o.codePointSource[o.cursor]===W)return void o.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,o)?(o.advanceCodePoint(),consumeEscapedCodePoint(e,o)):o.advanceCodePoint()}}function consumeUrlToken(e,o){consumeWhiteSpace(0,o);let t="";for(;;){if(void 0===o.codePointSource[o.cursor])return e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(o.codePointSource[o.cursor]===W)return o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):o.codePointSource[o.cursor]===W?(o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):(consumeBadURL(e,o),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===L||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===E||((n=o.codePointSource[o.cursor])===y||n===p||U<=n&&n<=i||V<=n&&n<=T))return consumeBadURL(e,o),e.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){t+=String.fromCharCode(consumeEscapedCodePoint(e,o));continue}return consumeBadURL(e,o),e.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}t+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var n}function consumeIdentLikeToken(e,o){const t=consumeIdentSequence(e,o);if(o.codePointSource[o.cursor]!==E)return[exports.TokenType.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];if(checkIfCodePointsMatchURLIdent(0,t)){o.advanceCodePoint();let n=0;for(;;){const e=isWhitespace(o.codePointSource[o.cursor]),i=isWhitespace(o.codePointSource[o.cursor+1]);if(e&&i){n+=2,o.advanceCodePoint(2);continue}const s=e?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(s===L||s===r)return n>0&&o.advanceCodePoint(n),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];break}return n>0&&o.advanceCodePoint(n),consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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){let t="";const r=new Array(o.length);for(let e=0;e{})};return{nextToken:function nextToken(){if(n.representationStart=n.cursor,n.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,n)){if(null!=o&&o.commentsAreTokens)return consumeComment(i,n);consumeComment(i,n),n.representationStart=n.cursor,n.representationEnd=-1}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,n);if(isDigitCodePoint(e))return consumeNumericToken(i,n);switch(e){case d:return n.advanceCodePoint(),[exports.TokenType.Comma,",",n.representationStart,n.representationEnd,void 0];case a:return n.advanceCodePoint(),[exports.TokenType.Colon,":",n.representationStart,n.representationEnd,void 0];case q:return n.advanceCodePoint(),[exports.TokenType.Semicolon,";",n.representationStart,n.representationEnd,void 0];case E:return n.advanceCodePoint(),[exports.TokenType.OpenParen,"(",n.representationStart,n.representationEnd,void 0];case W:return n.advanceCodePoint(),[exports.TokenType.CloseParen,")",n.representationStart,n.representationEnd,void 0];case v:return n.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",n.representationStart,n.representationEnd,void 0];case F:return n.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",n.representationStart,n.representationEnd,void 0];case f:return n.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",n.representationStart,n.representationEnd,void 0];case R:return n.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",n.representationStart,n.representationEnd,void 0];case r:case L:return consumeStringToken(i,n);case O:return consumeHashToken(i,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):(n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]);case x:case s:case S:case c:case H:return consumeWhiteSpace(0,n);case l:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(i,n):(n.advanceCodePoint(),[exports.TokenType.Delim,"-",n.representationStart,n.representationEnd,{value:"-"}]);case A:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",n.representationStart,n.representationEnd,void 0]):(n.advanceCodePoint(),[exports.TokenType.Delim,"<",n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(i,n);return[exports.TokenType.AtKeyword,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,"@",n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(i,n):(n.advanceCodePoint(),i.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,"\\",n.representationStart,n.representationEnd,{value:"\\"}])}return n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; diff --git a/packages/css-tokenizer/dist/index.d.ts b/packages/css-tokenizer/dist/index.d.ts index dab5f2866..158a901f7 100644 --- a/packages/css-tokenizer/dist/index.d.ts +++ b/packages/css-tokenizer/dist/index.d.ts @@ -5,3 +5,4 @@ export { stringify } from './stringify'; export { tokenizer } from './tokenizer'; export { cloneTokens } from './util/clone-tokens'; export type { 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, } from './interfaces/token'; +export { mutateIdent, } from './util/mutations'; diff --git a/packages/css-tokenizer/dist/index.mjs b/packages/css-tokenizer/dist/index.mjs index 9c6f1f850..babf8503a 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1 +1 @@ -class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=G}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===U)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case I:case c:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case I:case c:case S:case a:case H:return!0;default:return!1}}const X="\ud800".charCodeAt(0),Y="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.codePointSource[t.cursor]===N&&t.codePointSource[t.cursor+1]!==I}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.codePointSource[t.cursor]===l?t.codePointSource[t.cursor+1]===l||(!!isIdentStartCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===N&&t.codePointSource[t.cursor+2]!==I):!!isIdentStartCodePoint(t.codePointSource[t.cursor])||checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.codePointSource[t.cursor]===R||t.codePointSource[t.cursor]===l?!!isDigitCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===P&&isDigitCodePoint(t.codePointSource[t.cursor+2]):t.codePointSource[t.cursor]===P?isDigitCodePoint(t.codePointSource[t.cursor+1]):!!isDigitCodePoint(t.codePointSource[t.cursor])}function checkIfTwoCodePointsStartAComment(e,t){return t.codePointSource[t.cursor]===B&&t.codePointSource[t.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.codePointSource[t.cursor]===l&&t.codePointSource[t.cursor+1]===l&&t.codePointSource[t.cursor+2]===h}function consumeComment(t,o){for(o.advanceCodePoint(2);;){const e=o.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[e.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const o=t.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==t.codePointSource[t.cursor]&&isHexDigitCodePoint(t.codePointSource[t.cursor])&&e.length<6;)e.push(t.codePointSource[t.cursor]),t.advanceCodePoint();isWhitespace(t.codePointSource[t.cursor])&&t.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:X<=(r=n)&&r<=Y||n>O?b:n}var r;return o}function consumeIdentSequence(e,t){const o=[];for(;;)if(isIdentCodePoint(t.codePointSource[t.cursor]))o.push(t.codePointSource[t.cursor]),t.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,t))return o;t.advanceCodePoint(),o.push(consumeEscapedCodePoint(e,t))}}function consumeHashToken(t,r){if(r.advanceCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let n=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(n=o.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.source.slice(r.representationStart,r.representationEnd+1),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,"#",r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,o){let r=t.Integer;for(o.codePointSource[o.cursor]!==R&&o.codePointSource[o.cursor]!==l||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===l||o.codePointSource[o.cursor+1]===R)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),r]}function consumeNumericToken(t,o){const r=consumeNumber(0,o);if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const n=consumeIdentSequence(t,o);return[e.Dimension,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1],unit:String.fromCharCode(...n)}]}return o.codePointSource[o.cursor]===L?(o.advanceCodePoint(),[e.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0]}]):[e.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1]}]}function consumeWhiteSpace(t,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[e.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(t,o){let r="";const n=o.readCodePoint();for(;;){const i=o.readCodePoint();if(!1===i)return t.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(isNewLine(i))return t.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[e.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(i===n)return[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(i!==N)r+=String.fromCharCode(i);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}r+=String.fromCharCode(consumeEscapedCodePoint(t,o))}}}const $="u".charCodeAt(0),ee="U".charCodeAt(0),te="r".charCodeAt(0),oe="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,t){return 3===t.length&&((t[0]===$||t[0]===ee)&&((t[1]===te||t[1]===oe)&&(t[2]===re||t[2]===ne)))}function consumeBadURL(e,t){for(;;){if(void 0===t.codePointSource[t.cursor])return;if(t.codePointSource[t.cursor]===F)return void t.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,t)?(t.advanceCodePoint(),consumeEscapedCodePoint(e,t)):t.advanceCodePoint()}}function consumeUrlToken(t,o){consumeWhiteSpace(0,o);let n="";for(;;){if(void 0===o.codePointSource[o.cursor])return t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(o.codePointSource[o.cursor]===F)return o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):o.codePointSource[o.cursor]===F?(o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):(consumeBadURL(t,o),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===y||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===A||((c=o.codePointSource[o.cursor])===T||c===C||D<=c&&c<=i||V<=c&&c<=f))return consumeBadURL(t,o),t.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){n+=String.fromCharCode(consumeEscapedCodePoint(t,o));continue}return consumeBadURL(t,o),t.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}n+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var c}function consumeIdentLikeToken(t,o){const n=consumeIdentSequence(t,o);if(o.codePointSource[o.cursor]!==A)return[e.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];if(checkIfCodePointsMatchURLIdent(0,n)){o.advanceCodePoint();let i=0;for(;;){const t=isWhitespace(o.codePointSource[o.cursor]),c=isWhitespace(o.codePointSource[o.cursor+1]);if(t&&c){i+=2,o.advanceCodePoint(2);continue}const a=t?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(a===y||a===r)return i>0&&o.advanceCodePoint(i),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&o.advanceCodePoint(i),consumeUrlToken(t,o)}return o.advanceCodePoint(),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(t,o){const n=t.css.valueOf(),i=new Reader(n),C={onParseError:(null==o?void 0:o.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.representationStart=i.cursor,i.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,i)){if(null!=o&&o.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.representationStart=i.cursor,i.representationEnd=-1}const t=i.codePointSource[i.cursor];if(void 0===t)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(t))return consumeIdentLikeToken(C,i);if(isDigitCodePoint(t))return consumeNumericToken(C,i);switch(t){case d:return i.advanceCodePoint(),[e.Comma,",",i.representationStart,i.representationEnd,void 0];case s:return i.advanceCodePoint(),[e.Colon,":",i.representationStart,i.representationEnd,void 0];case x:return i.advanceCodePoint(),[e.Semicolon,";",i.representationStart,i.representationEnd,void 0];case A:return i.advanceCodePoint(),[e.OpenParen,"(",i.representationStart,i.representationEnd,void 0];case F:return i.advanceCodePoint(),[e.CloseParen,")",i.representationStart,i.representationEnd,void 0];case k:return i.advanceCodePoint(),[e.OpenSquare,"[",i.representationStart,i.representationEnd,void 0];case q:return i.advanceCodePoint(),[e.CloseSquare,"]",i.representationStart,i.representationEnd,void 0];case v:return i.advanceCodePoint(),[e.OpenCurly,"{",i.representationStart,i.representationEnd,void 0];case W:return i.advanceCodePoint(),[e.CloseCurly,"}",i.representationStart,i.representationEnd,void 0];case r:case y:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case R:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]);case I:case c:case S:case a:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.advanceCodePoint(3),[e.CDC,"--\x3e",i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),[e.Delim,"-",i.representationStart,i.representationEnd,{value:"-"}]);case g:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.advanceCodePoint(4),[e.CDO,"\x3c!--",i.representationStart,i.representationEnd,void 0]):(i.advanceCodePoint(),[e.Delim,"<",i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(C,i);return[e.AtKeyword,i.source.slice(i.representationStart,i.representationEnd+1),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,"@",i.representationStart,i.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,"\\",i.representationStart,i.representationEnd,{value:"\\"}])}return i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}export{t as NumberType,Reader,e as TokenType,cloneTokens,isToken,mirrorVariantType,stringify,tokenizer}; +class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===U)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case I:case c:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case I:case c:case S:case a:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.codePointSource[t.cursor]===N&&t.codePointSource[t.cursor+1]!==I}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.codePointSource[t.cursor]===l?t.codePointSource[t.cursor+1]===l||(!!isIdentStartCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===N&&t.codePointSource[t.cursor+2]!==I):!!isIdentStartCodePoint(t.codePointSource[t.cursor])||checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.codePointSource[t.cursor]===y||t.codePointSource[t.cursor]===l?!!isDigitCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===P&&isDigitCodePoint(t.codePointSource[t.cursor+2]):t.codePointSource[t.cursor]===P?isDigitCodePoint(t.codePointSource[t.cursor+1]):!!isDigitCodePoint(t.codePointSource[t.cursor])}function checkIfTwoCodePointsStartAComment(e,t){return t.codePointSource[t.cursor]===B&&t.codePointSource[t.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.codePointSource[t.cursor]===l&&t.codePointSource[t.cursor+1]===l&&t.codePointSource[t.cursor+2]===h}function consumeComment(t,o){for(o.advanceCodePoint(2);;){const e=o.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[e.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const o=t.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==t.codePointSource[t.cursor]&&isHexDigitCodePoint(t.codePointSource[t.cursor])&&e.length<6;)e.push(t.codePointSource[t.cursor]),t.advanceCodePoint();isWhitespace(t.codePointSource[t.cursor])&&t.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:G<=(r=n)&&r<=X||n>O?b:n}var r;return o}function consumeIdentSequence(e,t){const o=[];for(;;)if(isIdentCodePoint(t.codePointSource[t.cursor]))o.push(t.codePointSource[t.cursor]),t.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,t))return o;t.advanceCodePoint(),o.push(consumeEscapedCodePoint(e,t))}}function consumeHashToken(t,r){if(r.advanceCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let n=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(n=o.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.source.slice(r.representationStart,r.representationEnd+1),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,"#",r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,o){let r=t.Integer;for(o.codePointSource[o.cursor]!==y&&o.codePointSource[o.cursor]!==l||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===l||o.codePointSource[o.cursor+1]===y)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),r]}function consumeNumericToken(t,o){const r=consumeNumber(0,o);if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const n=consumeIdentSequence(t,o);return[e.Dimension,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1],unit:String.fromCharCode(...n)}]}return o.codePointSource[o.cursor]===L?(o.advanceCodePoint(),[e.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0]}]):[e.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1]}]}function consumeWhiteSpace(t,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[e.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(t,o){let r="";const n=o.readCodePoint();for(;;){const i=o.readCodePoint();if(!1===i)return t.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(isNewLine(i))return t.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[e.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(i===n)return[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(i!==N)r+=String.fromCharCode(i);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}r+=String.fromCharCode(consumeEscapedCodePoint(t,o))}}}const Y="u".charCodeAt(0),ee="U".charCodeAt(0),te="r".charCodeAt(0),oe="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,t){return 3===t.length&&((t[0]===Y||t[0]===ee)&&((t[1]===te||t[1]===oe)&&(t[2]===re||t[2]===ne)))}function consumeBadURL(e,t){for(;;){if(void 0===t.codePointSource[t.cursor])return;if(t.codePointSource[t.cursor]===F)return void t.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,t)?(t.advanceCodePoint(),consumeEscapedCodePoint(e,t)):t.advanceCodePoint()}}function consumeUrlToken(t,o){consumeWhiteSpace(0,o);let n="";for(;;){if(void 0===o.codePointSource[o.cursor])return t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(o.codePointSource[o.cursor]===F)return o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):o.codePointSource[o.cursor]===F?(o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):(consumeBadURL(t,o),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===R||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===A||((c=o.codePointSource[o.cursor])===T||c===C||D<=c&&c<=i||V<=c&&c<=f))return consumeBadURL(t,o),t.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){n+=String.fromCharCode(consumeEscapedCodePoint(t,o));continue}return consumeBadURL(t,o),t.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}n+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var c}function consumeIdentLikeToken(t,o){const n=consumeIdentSequence(t,o);if(o.codePointSource[o.cursor]!==A)return[e.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];if(checkIfCodePointsMatchURLIdent(0,n)){o.advanceCodePoint();let i=0;for(;;){const t=isWhitespace(o.codePointSource[o.cursor]),c=isWhitespace(o.codePointSource[o.cursor+1]);if(t&&c){i+=2,o.advanceCodePoint(2);continue}const a=t?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(a===R||a===r)return i>0&&o.advanceCodePoint(i),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&o.advanceCodePoint(i),consumeUrlToken(t,o)}return o.advanceCodePoint(),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(t,o){const n=t.css.valueOf(),i=new Reader(n),C={onParseError:(null==o?void 0:o.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.representationStart=i.cursor,i.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,i)){if(null!=o&&o.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.representationStart=i.cursor,i.representationEnd=-1}const t=i.codePointSource[i.cursor];if(void 0===t)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(t))return consumeIdentLikeToken(C,i);if(isDigitCodePoint(t))return consumeNumericToken(C,i);switch(t){case d:return i.advanceCodePoint(),[e.Comma,",",i.representationStart,i.representationEnd,void 0];case s:return i.advanceCodePoint(),[e.Colon,":",i.representationStart,i.representationEnd,void 0];case x:return i.advanceCodePoint(),[e.Semicolon,";",i.representationStart,i.representationEnd,void 0];case A:return i.advanceCodePoint(),[e.OpenParen,"(",i.representationStart,i.representationEnd,void 0];case F:return i.advanceCodePoint(),[e.CloseParen,")",i.representationStart,i.representationEnd,void 0];case k:return i.advanceCodePoint(),[e.OpenSquare,"[",i.representationStart,i.representationEnd,void 0];case q:return i.advanceCodePoint(),[e.CloseSquare,"]",i.representationStart,i.representationEnd,void 0];case v:return i.advanceCodePoint(),[e.OpenCurly,"{",i.representationStart,i.representationEnd,void 0];case W:return i.advanceCodePoint(),[e.CloseCurly,"}",i.representationStart,i.representationEnd,void 0];case r:case R:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case y:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]);case I:case c:case S:case a:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.advanceCodePoint(3),[e.CDC,"--\x3e",i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),[e.Delim,"-",i.representationStart,i.representationEnd,{value:"-"}]);case g:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.advanceCodePoint(4),[e.CDO,"\x3c!--",i.representationStart,i.representationEnd,void 0]):(i.advanceCodePoint(),[e.Delim,"<",i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(C,i);return[e.AtKeyword,i.source.slice(i.representationStart,i.representationEnd+1),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,"@",i.representationStart,i.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,"\\",i.representationStart,i.representationEnd,{value:"\\"}])}return i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}function mutateIdent(e,t){let o="";const r=new Array(t.length);for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===exports.NodeType.MediaQueryInvalid)}}class GeneralEnclosed{type=exports.NodeType.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===exports.NodeType.GeneralEnclosed)}}class MediaAnd{type=exports.NodeType.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return r.stringify(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===exports.NodeType.MediaAnd)}}class MediaConditionListWithAnd{type=exports.NodeType.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===exports.NodeType.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=exports.NodeType.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===exports.NodeType.MediaConditionListWithOr)}}function isNumber(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Number||e.type===a.ComponentValueType.Function&&"calc"===e.name[4].value}function isDimension(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Dimension}function isIdent(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Ident}class MediaFeatureName{type=exports.NodeType.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.name.toString()+r.stringify(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===exports.NodeType.MediaFeatureName)}}function parseMediaFeatureName(e){let t=-1;for(let i=0;ie.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=exports.NodeType.MediaFeatureBoolean;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.name.toString()+r.stringify(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===exports.NodeType.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t.name,t.before,t.after)}class MediaFeatureValue{type=exports.NodeType.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?r.stringify(...this.before)+this.value.map((e=>e.toString())).join("")+r.stringify(...this.after):r.stringify(...this.before)+this.value.toString()+r.stringify(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===exports.NodeType.MediaFeatureValue)}}function parseMediaFeatureValue(e){let t=-1,i=-1;for(let r=0;re.tokens())),e.slice(i+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==r.TokenType.Delim)return!1;if(1===e.length)switch(e[0][4].value){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT;default:return!1}if(e[1][0]!==r.TokenType.Delim)return!1;if(e[1][4].value!==exports.MediaFeatureEQ.EQ)return!1;switch(e[0][4].value){case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT_OR_EQ;default:return!1}}exports.MediaFeatureLT=void 0,(t=exports.MediaFeatureLT||(exports.MediaFeatureLT={})).LT="<",t.LT_OR_EQ="<=",exports.MediaFeatureGT=void 0,(i=exports.MediaFeatureGT||(exports.MediaFeatureGT={})).GT=">",i.GT_OR_EQ=">=",exports.MediaFeatureEQ=void 0,(exports.MediaFeatureEQ||(exports.MediaFeatureEQ={})).EQ="=";class MediaFeatureRangeNameValue{type=exports.NodeType.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+r.stringify(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===exports.NodeType.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=exports.NodeType.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+r.stringify(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===exports.NodeType.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=exports.NodeType.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,r){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=r}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+r.stringify(...this.valueOneOperator)+this.name.toString()+r.stringify(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===exports.NodeType.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(e){let t=!1,i=!1;for(let n=0;ne.tokens())),-1!==i&&(s=e.slice(t+1,i+1).flatMap((e=>e.tokens())))):-1!==i&&(s=e.slice(0,i+1).flatMap((e=>e.tokens())));const u=parseMediaConditionWithoutOr(e.slice(Math.max(t,i,n)+1));return!1===u?new MediaQueryWithType(o,[...s,...e.slice(i+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(o,s,e.slice(i+1,n+1).flatMap((e=>e.tokens())),u)}}function parseMediaConditionListWithOr(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const r=parseMediaInParens(e);return!1!==r&&new MediaCondition(r)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(e){let t=-1;for(let i=0;ie.tokens())),i.startToken],o=[i.endToken,...e.slice(t+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(i,n,o);if(!1!==s)return new MediaInParens(s);const u=parseMediaCondition(i.value);return!1!==u?new MediaInParens(u,n,o):new MediaInParens(new GeneralEnclosed(i),e.slice(0,t).flatMap((e=>e.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==r.TokenType.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(e){let t=!1,i=null;for(let r=0;re.tokens())),t)}}}return i||!1}function parseMediaOr(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseMediaAnd(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseFromTokens(e,t){const i=a.parseCommaSeparatedListOfComponentValues(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const r=parseMediaQuery(e);return 0==r&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):r})).filter((e=>!!e))}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}exports.MediaQueryModifier=void 0,(o=exports.MediaQueryModifier||(exports.MediaQueryModifier={})).Not="not",o.Only="only",exports.MediaType=void 0,(s=exports.MediaType||(exports.MediaType={})).All="all",s.Print="print",s.Screen="screen",s.Tty="tty",s.Tv="tv",s.Projection="projection",s.Handheld="handheld",s.Braille="braille",s.Embossed="embossed",s.Aural="aural",s.Speech="speech",exports.GeneralEnclosed=GeneralEnclosed,exports.MediaAnd=MediaAnd,exports.MediaCondition=MediaCondition,exports.MediaConditionListWithAnd=MediaConditionListWithAnd,exports.MediaConditionListWithOr=MediaConditionListWithOr,exports.MediaFeature=MediaFeature,exports.MediaFeatureBoolean=MediaFeatureBoolean,exports.MediaFeatureName=MediaFeatureName,exports.MediaFeaturePlain=MediaFeaturePlain,exports.MediaFeatureRangeNameValue=MediaFeatureRangeNameValue,exports.MediaFeatureRangeValueName=MediaFeatureRangeValueName,exports.MediaFeatureRangeValueNameValue=MediaFeatureRangeValueNameValue,exports.MediaFeatureValue=MediaFeatureValue,exports.MediaInParens=MediaInParens,exports.MediaNot=MediaNot,exports.MediaOr=MediaOr,exports.MediaQueryInvalid=MediaQueryInvalid,exports.MediaQueryWithType=MediaQueryWithType,exports.MediaQueryWithoutType=MediaQueryWithoutType,exports.cloneMediaQuery=function cloneMediaQuery(e){const t=r.cloneTokens(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`)},exports.comparisonFromTokens=comparisonFromTokens,exports.invertComparison=function invertComparison(e){switch(e){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureGT.GT;case exports.MediaFeatureLT.LT_OR_EQ:return exports.MediaFeatureGT.GT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT_OR_EQ:return exports.MediaFeatureLT.LT_OR_EQ;default:return!1}},exports.isGeneralEnclosed=function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)},exports.isMediaAnd=function isMediaAnd(e){return MediaAnd.isMediaAnd(e)},exports.isMediaCondition=function isMediaCondition(e){return MediaCondition.isMediaCondition(e)},exports.isMediaConditionList=function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)},exports.isMediaConditionListWithAnd=isMediaConditionListWithAnd,exports.isMediaConditionListWithOr=isMediaConditionListWithOr,exports.isMediaFeature=function isMediaFeature(e){return MediaFeature.isMediaFeature(e)},exports.isMediaFeatureBoolean=function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)},exports.isMediaFeatureName=function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)},exports.isMediaFeaturePlain=function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)},exports.isMediaFeatureRange=function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)},exports.isMediaFeatureRangeNameValue=isMediaFeatureRangeNameValue,exports.isMediaFeatureRangeValueName=isMediaFeatureRangeValueName,exports.isMediaFeatureRangeValueNameValue=isMediaFeatureRangeValueNameValue,exports.isMediaFeatureValue=function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)},exports.isMediaInParens=function isMediaInParens(e){return MediaInParens.isMediaInParens(e)},exports.isMediaNot=function isMediaNot(e){return MediaNot.isMediaNot(e)},exports.isMediaOr=function isMediaOr(e){return MediaOr.isMediaOr(e)},exports.isMediaQuery=function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)},exports.isMediaQueryInvalid=isMediaQueryInvalid,exports.isMediaQueryWithType=isMediaQueryWithType,exports.isMediaQueryWithoutType=isMediaQueryWithoutType,exports.matchesComparison=matchesComparison,exports.matchesRatio=matchesRatio,exports.matchesRatioExactly=matchesRatioExactly,exports.modifierFromToken=modifierFromToken,exports.newMediaFeatureBoolean=function newMediaFeatureBoolean(e){return new MediaFeature(new MediaFeatureBoolean(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}])),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.newMediaFeaturePlain=function newMediaFeaturePlain(e,...t){return new MediaFeature(new MediaFeaturePlain(new MediaFeatureName(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}])),[r.TokenType.Colon,":",-1,-1,void 0],new MediaFeatureValue(t.map((e=>new a.TokenNode(e))))),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.parse=function parse(e,t){const i=r.tokenizer({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)},exports.parseFromTokens=parseFromTokens,exports.typeFromToken=function typeFromToken(e){if(e[0]!==r.TokenType.Ident)return!1;switch(e[4].value.toLowerCase()){case exports.MediaType.All:return exports.MediaType.All;case exports.MediaType.Print:return exports.MediaType.Print;case exports.MediaType.Screen:return exports.MediaType.Screen;case exports.MediaType.Tty:return exports.MediaType.Tty;case exports.MediaType.Tv:return exports.MediaType.Tv;case exports.MediaType.Projection:return exports.MediaType.Projection;case exports.MediaType.Handheld:return exports.MediaType.Handheld;case exports.MediaType.Braille:return exports.MediaType.Braille;case exports.MediaType.Embossed:return exports.MediaType.Embossed;case exports.MediaType.Aural:return exports.MediaType.Aural;case exports.MediaType.Speech:return exports.MediaType.Speech;default:return!1}}; +"use strict";var e,t,i,a=require("@csstools/css-parser-algorithms"),r=require("@csstools/css-tokenizer");exports.NodeType=void 0,(e=exports.NodeType||(exports.NodeType={})).GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid";class MediaCondition{type=exports.NodeType.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===exports.NodeType.MediaCondition)}}class MediaInParens{type=exports.NodeType.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.media.toString()+r.stringify(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&("walk"in this.media?this.media.walk(e):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===exports.NodeType.MediaInParens)}}class MediaQueryWithType{type=exports.NodeType.MediaQueryWithType;modifier;mediaType;and;media=null;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===exports.NodeType.MediaQueryInvalid)}}class GeneralEnclosed{type=exports.NodeType.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===exports.NodeType.GeneralEnclosed)}}class MediaAnd{type=exports.NodeType.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return r.stringify(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===exports.NodeType.MediaAnd)}}class MediaConditionListWithAnd{type=exports.NodeType.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===exports.NodeType.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=exports.NodeType.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return r.stringify(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+r.stringify(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===exports.NodeType.MediaConditionListWithOr)}}function isNumber(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Number||e.type===a.ComponentValueType.Function&&"calc"===e.name[4].value}function isDimension(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Dimension}function isIdent(e){return e.type===a.ComponentValueType.Token&&e.value[0]===r.TokenType.Ident}class MediaFeatureName{type=exports.NodeType.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return r.stringify(...this.before)+this.name.toString()+r.stringify(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===exports.NodeType.MediaFeatureName)}}function parseMediaFeatureName(e){let t=-1;for(let i=0;ie.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=exports.NodeType.MediaFeatureBoolean;name;constructor(e){this.name=e}getName(){return this.name.getName()}getNameToken(){return this.name.getNameToken()}tokens(){return this.name.tokens()}toString(){return this.name.toString()}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.name.toJSON(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===exports.NodeType.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t)}class MediaFeatureValue{type=exports.NodeType.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?r.stringify(...this.before)+this.value.map((e=>e.toString())).join("")+r.stringify(...this.after):r.stringify(...this.before)+this.value.toString()+r.stringify(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===exports.NodeType.MediaFeatureValue)}}function parseMediaFeatureValue(e){let t=-1,i=-1;for(let r=0;re.tokens())),e.slice(i+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==r.TokenType.Delim)return!1;if(1===e.length)switch(e[0][4].value){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT;default:return!1}if(e[1][0]!==r.TokenType.Delim)return!1;if(e[1][4].value!==exports.MediaFeatureEQ.EQ)return!1;switch(e[0][4].value){case exports.MediaFeatureLT.LT:return exports.MediaFeatureLT.LT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureGT.GT_OR_EQ;default:return!1}}exports.MediaFeatureLT=void 0,(t=exports.MediaFeatureLT||(exports.MediaFeatureLT={})).LT="<",t.LT_OR_EQ="<=",exports.MediaFeatureGT=void 0,(i=exports.MediaFeatureGT||(exports.MediaFeatureGT={})).GT=">",i.GT_OR_EQ=">=",exports.MediaFeatureEQ=void 0,(exports.MediaFeatureEQ||(exports.MediaFeatureEQ={})).EQ="=";class MediaFeatureRangeNameValue{type=exports.NodeType.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+r.stringify(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===exports.NodeType.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=exports.NodeType.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+r.stringify(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===exports.NodeType.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=exports.NodeType.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,r){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=r}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+r.stringify(...this.valueOneOperator)+this.name.toString()+r.stringify(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===exports.NodeType.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(e){let t=!1,i=!1;for(let n=0;ne.tokens())),-1!==i&&(s=e.slice(t+1,i+1).flatMap((e=>e.tokens())))):-1!==i&&(s=e.slice(0,i+1).flatMap((e=>e.tokens())));const d=parseMediaConditionWithoutOr(e.slice(Math.max(t,i,n)+1));return!1===d?new MediaQueryWithType(o,[...s,...e.slice(i+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(o,s,e.slice(i+1,n+1).flatMap((e=>e.tokens())),d)}}function parseMediaConditionListWithOr(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(e){let t=!1;const i=[];let r=-1,n=-1;for(let o=0;oe.tokens())),e.slice(n+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const r=parseMediaInParens(e);return!1!==r&&new MediaCondition(r)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(e){let t=-1;for(let i=0;ie.tokens())),i.startToken],o=[i.endToken,...e.slice(t+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(i,n,o);if(!1!==s)return new MediaInParens(s);const d=parseMediaCondition(i.value);return!1!==d?new MediaInParens(d,n,o):new MediaInParens(new GeneralEnclosed(i),e.slice(0,t).flatMap((e=>e.tokens())),e.slice(t+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==r.TokenType.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(e){let t=!1,i=null;for(let r=0;re.tokens())),t)}}}return i||!1}function parseMediaOr(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseMediaAnd(e){let t=!1;for(let i=0;ie.tokens())),t)}}return!1}}return!1}function parseFromTokens(e,t){const i=a.parseCommaSeparatedListOfComponentValues(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const r=parseMediaQuery(e);return 0==r&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):r})).filter((e=>!!e))}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}exports.MediaQueryModifier=void 0,(o=exports.MediaQueryModifier||(exports.MediaQueryModifier={})).Not="not",o.Only="only",exports.MediaType=void 0,(s=exports.MediaType||(exports.MediaType={})).All="all",s.Print="print",s.Screen="screen",s.Tty="tty",s.Tv="tv",s.Projection="projection",s.Handheld="handheld",s.Braille="braille",s.Embossed="embossed",s.Aural="aural",s.Speech="speech",exports.GeneralEnclosed=GeneralEnclosed,exports.MediaAnd=MediaAnd,exports.MediaCondition=MediaCondition,exports.MediaConditionListWithAnd=MediaConditionListWithAnd,exports.MediaConditionListWithOr=MediaConditionListWithOr,exports.MediaFeature=MediaFeature,exports.MediaFeatureBoolean=MediaFeatureBoolean,exports.MediaFeatureName=MediaFeatureName,exports.MediaFeaturePlain=MediaFeaturePlain,exports.MediaFeatureRangeNameValue=MediaFeatureRangeNameValue,exports.MediaFeatureRangeValueName=MediaFeatureRangeValueName,exports.MediaFeatureRangeValueNameValue=MediaFeatureRangeValueNameValue,exports.MediaFeatureValue=MediaFeatureValue,exports.MediaInParens=MediaInParens,exports.MediaNot=MediaNot,exports.MediaOr=MediaOr,exports.MediaQueryInvalid=MediaQueryInvalid,exports.MediaQueryWithType=MediaQueryWithType,exports.MediaQueryWithoutType=MediaQueryWithoutType,exports.cloneMediaQuery=function cloneMediaQuery(e){const t=r.cloneTokens(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${r.stringify(...t)}"`)},exports.comparisonFromTokens=comparisonFromTokens,exports.invertComparison=function invertComparison(e){switch(e){case exports.MediaFeatureEQ.EQ:return exports.MediaFeatureEQ.EQ;case exports.MediaFeatureLT.LT:return exports.MediaFeatureGT.GT;case exports.MediaFeatureLT.LT_OR_EQ:return exports.MediaFeatureGT.GT_OR_EQ;case exports.MediaFeatureGT.GT:return exports.MediaFeatureLT.LT;case exports.MediaFeatureGT.GT_OR_EQ:return exports.MediaFeatureLT.LT_OR_EQ;default:return!1}},exports.isGeneralEnclosed=function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)},exports.isMediaAnd=function isMediaAnd(e){return MediaAnd.isMediaAnd(e)},exports.isMediaCondition=function isMediaCondition(e){return MediaCondition.isMediaCondition(e)},exports.isMediaConditionList=function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)},exports.isMediaConditionListWithAnd=isMediaConditionListWithAnd,exports.isMediaConditionListWithOr=isMediaConditionListWithOr,exports.isMediaFeature=function isMediaFeature(e){return MediaFeature.isMediaFeature(e)},exports.isMediaFeatureBoolean=function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)},exports.isMediaFeatureName=function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)},exports.isMediaFeaturePlain=function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)},exports.isMediaFeatureRange=function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)},exports.isMediaFeatureRangeNameValue=isMediaFeatureRangeNameValue,exports.isMediaFeatureRangeValueName=isMediaFeatureRangeValueName,exports.isMediaFeatureRangeValueNameValue=isMediaFeatureRangeValueNameValue,exports.isMediaFeatureValue=function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)},exports.isMediaInParens=function isMediaInParens(e){return MediaInParens.isMediaInParens(e)},exports.isMediaNot=function isMediaNot(e){return MediaNot.isMediaNot(e)},exports.isMediaOr=function isMediaOr(e){return MediaOr.isMediaOr(e)},exports.isMediaQuery=function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)},exports.isMediaQueryInvalid=isMediaQueryInvalid,exports.isMediaQueryWithType=isMediaQueryWithType,exports.isMediaQueryWithoutType=isMediaQueryWithoutType,exports.matchesComparison=matchesComparison,exports.matchesRatio=matchesRatio,exports.matchesRatioExactly=matchesRatioExactly,exports.modifierFromToken=modifierFromToken,exports.newMediaFeatureBoolean=function newMediaFeatureBoolean(e){return new MediaFeature(new MediaFeatureBoolean(new MediaFeatureName(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}]))),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.newMediaFeaturePlain=function newMediaFeaturePlain(e,...t){return new MediaFeature(new MediaFeaturePlain(new MediaFeatureName(new a.TokenNode([r.TokenType.Ident,e,-1,-1,{value:e}])),[r.TokenType.Colon,":",-1,-1,void 0],new MediaFeatureValue(t.map((e=>new a.TokenNode(e))))),[[r.TokenType.OpenParen,"(",-1,-1,void 0]],[[r.TokenType.CloseParen,")",-1,-1,void 0]])},exports.parse=function parse(e,t){const i=r.tokenizer({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)},exports.parseFromTokens=parseFromTokens,exports.typeFromToken=function typeFromToken(e){if(e[0]!==r.TokenType.Ident)return!1;switch(e[4].value.toLowerCase()){case exports.MediaType.All:return exports.MediaType.All;case exports.MediaType.Print:return exports.MediaType.Print;case exports.MediaType.Screen:return exports.MediaType.Screen;case exports.MediaType.Tty:return exports.MediaType.Tty;case exports.MediaType.Tv:return exports.MediaType.Tv;case exports.MediaType.Projection:return exports.MediaType.Projection;case exports.MediaType.Handheld:return exports.MediaType.Handheld;case exports.MediaType.Braille:return exports.MediaType.Braille;case exports.MediaType.Embossed:return exports.MediaType.Embossed;case exports.MediaType.Aural:return exports.MediaType.Aural;case exports.MediaType.Speech:return exports.MediaType.Speech;default:return!1}}; diff --git a/packages/media-query-list-parser/dist/index.mjs b/packages/media-query-list-parser/dist/index.mjs index 1480c33cd..47f5c01c8 100644 --- a/packages/media-query-list-parser/dist/index.mjs +++ b/packages/media-query-list-parser/dist/index.mjs @@ -1 +1 @@ -import{ComponentValueType as e,TokenNode as t,isWhitespaceNode as i,isCommentNode as a,isTokenNode as n,parseCommaSeparatedListOfComponentValues as r}from"@csstools/css-parser-algorithms";import{stringify as s,TokenType as o,tokenizer as u,cloneTokens as d}from"@csstools/css-tokenizer";var l,h,m,f;!function(e){e.GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid"}(l||(l={}));class MediaCondition{type=l.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===l.MediaCondition)}}class MediaInParens{type=l.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return s(...this.before)+this.media.toString()+s(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&("walk"in this.media?this.media.walk(e):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===l.MediaInParens)}}class MediaQueryWithType{type=l.MediaQueryWithType;modifier;mediaType;and;media=null;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===l.MediaQueryInvalid)}}class GeneralEnclosed{type=l.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===l.GeneralEnclosed)}}class MediaAnd{type=l.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===l.MediaAnd)}}class MediaConditionListWithAnd{type=l.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===l.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=l.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===l.MediaConditionListWithOr)}}function isNumber(t){return t.type===e.Token&&t.value[0]===o.Number||t.type===e.Function&&"calc"===t.name[4].value}function isDimension(t){return t.type===e.Token&&t.value[0]===o.Dimension}function isIdent(t){return t.type===e.Token&&t.value[0]===o.Ident}class MediaFeatureName{type=l.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return s(...this.before)+this.name.toString()+s(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===l.MediaFeatureName)}}function parseMediaFeatureName(t){let i=-1;for(let a=0;ae.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=l.MediaFeatureBoolean;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return s(...this.before)+this.name.toString()+s(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===l.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t.name,t.before,t.after)}class MediaFeatureValue{type=l.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?s(...this.before)+this.value.map((e=>e.toString())).join("")+s(...this.after):s(...this.before)+this.value.toString()+s(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===l.MediaFeatureValue)}}function parseMediaFeatureValue(t){let i=-1,a=-1;for(let n=0;ne.tokens())),t.slice(a+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==o.Delim)return!1;if(1===e.length)switch(e[0][4].value){case f.EQ:return f.EQ;case h.LT:return h.LT;case m.GT:return m.GT;default:return!1}if(e[1][0]!==o.Delim)return!1;if(e[1][4].value!==f.EQ)return!1;switch(e[0][4].value){case h.LT:return h.LT_OR_EQ;case m.GT:return m.GT_OR_EQ;default:return!1}}function invertComparison(e){switch(e){case f.EQ:return f.EQ;case h.LT:return m.GT;case h.LT_OR_EQ:return m.GT_OR_EQ;case m.GT:return h.LT;case m.GT_OR_EQ:return h.LT_OR_EQ;default:return!1}}!function(e){e.LT="<",e.LT_OR_EQ="<="}(h||(h={})),function(e){e.GT=">",e.GT_OR_EQ=">="}(m||(m={})),function(e){e.EQ="="}(f||(f={}));class MediaFeatureRangeNameValue{type=l.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+s(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===l.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=l.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+s(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===l.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=l.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,n){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=n}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+s(...this.valueOneOperator)+this.name.toString()+s(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===l.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(t){let i=!1,a=!1;for(let n=0;nnew t(e))))),[[o.OpenParen,"(",-1,-1,void 0]],[[o.CloseParen,")",-1,-1,void 0]])}class MediaNot{type=l.MediaNot;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaNot(){return MediaNot.isMediaNot(this)}static isMediaNot(e){return!!e&&(e instanceof MediaNot&&e.type===l.MediaNot)}}class MediaOr{type=l.MediaOr;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaOr(){return MediaOr.isMediaOr(this)}static isMediaOr(e){return!!e&&(e instanceof MediaOr&&e.type===l.MediaOr)}}var M,p;function modifierFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case M.Not:return M.Not;case M.Only:return M.Only;default:return!1}}function parseMediaQuery(e){{const t=parseMediaCondition(e);if(!1!==t)return new MediaQueryWithoutType(t)}{let t=-1,r=-1,s=-1;for(let u=0;ue.tokens())),-1!==r&&(d=e.slice(t+1,r+1).flatMap((e=>e.tokens())))):-1!==r&&(d=e.slice(0,r+1).flatMap((e=>e.tokens())));const l=parseMediaConditionWithoutOr(e.slice(Math.max(t,r,s)+1));return!1===l?new MediaQueryWithType(u,[...d,...e.slice(r+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(u,d,e.slice(r+1,s+1).flatMap((e=>e.tokens())),l)}}function parseMediaConditionListWithOr(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const n=parseMediaInParens(e);return!1!==n&&new MediaCondition(n)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(t){let i=-1;for(let a=0;ae.tokens())),a.startToken],r=[a.endToken,...t.slice(i+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(a,n,r);if(!1!==s)return new MediaInParens(s);const u=parseMediaCondition(a.value);return!1!==u?new MediaInParens(u,n,r):new MediaInParens(new GeneralEnclosed(a),t.slice(0,i).flatMap((e=>e.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==o.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(t){let i=!1,a=null;for(let n=0;ne.tokens())),e)}}}return a||!1}function parseMediaOr(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseMediaAnd(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseFromTokens(e,t){const i=r(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const n=parseMediaQuery(e);return 0==n&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):n})).filter((e=>!!e))}function parse(e,t){const i=u({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)}function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)}function isMediaAnd(e){return MediaAnd.isMediaAnd(e)}function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaCondition(e){return MediaCondition.isMediaCondition(e)}function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)}function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)}function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)}function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)}function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaFeature(e){return MediaFeature.isMediaFeature(e)}function isMediaInParens(e){return MediaInParens.isMediaInParens(e)}function isMediaNot(e){return MediaNot.isMediaNot(e)}function isMediaOr(e){return MediaOr.isMediaOr(e)}function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}function typeFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case p.All:return p.All;case p.Print:return p.Print;case p.Screen:return p.Screen;case p.Tty:return p.Tty;case p.Tv:return p.Tv;case p.Projection:return p.Projection;case p.Handheld:return p.Handheld;case p.Braille:return p.Braille;case p.Embossed:return p.Embossed;case p.Aural:return p.Aural;case p.Speech:return p.Speech;default:return!1}}function cloneMediaQuery(e){const t=d(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${s(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${s(...t)}"`)}!function(e){e.Not="not",e.Only="only"}(M||(M={})),function(e){e.All="all",e.Print="print",e.Screen="screen",e.Tty="tty",e.Tv="tv",e.Projection="projection",e.Handheld="handheld",e.Braille="braille",e.Embossed="embossed",e.Aural="aural",e.Speech="speech"}(p||(p={}));export{GeneralEnclosed,MediaAnd,MediaCondition,MediaConditionListWithAnd,MediaConditionListWithOr,MediaFeature,MediaFeatureBoolean,f as MediaFeatureEQ,m as MediaFeatureGT,h as MediaFeatureLT,MediaFeatureName,MediaFeaturePlain,MediaFeatureRangeNameValue,MediaFeatureRangeValueName,MediaFeatureRangeValueNameValue,MediaFeatureValue,MediaInParens,MediaNot,MediaOr,MediaQueryInvalid,M as MediaQueryModifier,MediaQueryWithType,MediaQueryWithoutType,p as MediaType,l as NodeType,cloneMediaQuery,comparisonFromTokens,invertComparison,isGeneralEnclosed,isMediaAnd,isMediaCondition,isMediaConditionList,isMediaConditionListWithAnd,isMediaConditionListWithOr,isMediaFeature,isMediaFeatureBoolean,isMediaFeatureName,isMediaFeaturePlain,isMediaFeatureRange,isMediaFeatureRangeNameValue,isMediaFeatureRangeValueName,isMediaFeatureRangeValueNameValue,isMediaFeatureValue,isMediaInParens,isMediaNot,isMediaOr,isMediaQuery,isMediaQueryInvalid,isMediaQueryWithType,isMediaQueryWithoutType,matchesComparison,matchesRatio,matchesRatioExactly,modifierFromToken,newMediaFeatureBoolean,newMediaFeaturePlain,parse,parseFromTokens,typeFromToken}; +import{ComponentValueType as e,TokenNode as t,isWhitespaceNode as i,isCommentNode as a,isTokenNode as n,parseCommaSeparatedListOfComponentValues as r}from"@csstools/css-parser-algorithms";import{stringify as s,TokenType as o,tokenizer as u,cloneTokens as d}from"@csstools/css-tokenizer";var l,h,m,f;!function(e){e.GeneralEnclosed="general-enclosed",e.MediaAnd="media-and",e.MediaCondition="media-condition",e.MediaConditionListWithAnd="media-condition-list-and",e.MediaConditionListWithOr="media-condition-list-or",e.MediaFeature="media-feature",e.MediaFeatureBoolean="mf-boolean",e.MediaFeatureName="mf-name",e.MediaFeaturePlain="mf-plain",e.MediaFeatureRangeNameValue="mf-range-name-value",e.MediaFeatureRangeValueName="mf-range-value-name",e.MediaFeatureRangeValueNameValue="mf-range-value-name-value",e.MediaFeatureValue="mf-value",e.MediaInParens="media-in-parens",e.MediaNot="media-not",e.MediaOr="media-or",e.MediaQueryWithType="media-query-with-type",e.MediaQueryWithoutType="media-query-without-type",e.MediaQueryInvalid="media-query-invalid"}(l||(l={}));class MediaCondition{type=l.MediaCondition;media;constructor(e){this.media=e}tokens(){return this.media.tokens()}toString(){return this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,media:this.media.toJSON()}}isMediaCondition(){return MediaCondition.isMediaCondition(this)}static isMediaCondition(e){return!!e&&(e instanceof MediaCondition&&e.type===l.MediaCondition)}}class MediaInParens{type=l.MediaInParens;media;before;after;constructor(e,t=[],i=[]){this.media=e,this.before=t,this.after=i}tokens(){return[...this.before,...this.media.tokens(),...this.after]}toString(){return s(...this.before)+this.media.toString()+s(...this.after)}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&("walk"in this.media?this.media.walk(e):void 0)}toJSON(){return{type:this.type,media:this.media.toJSON(),before:this.before,after:this.after}}isMediaInParens(){return MediaInParens.isMediaInParens(this)}static isMediaInParens(e){return!!e&&(e instanceof MediaInParens&&e.type===l.MediaInParens)}}class MediaQueryWithType{type=l.MediaQueryWithType;modifier;mediaType;and;media=null;constructor(e,t,i,a){this.modifier=e,this.mediaType=t,i&&a&&(this.and=i,this.media=a)}getModifier(){if(!this.modifier.length)return"";for(let e=0;ee.tokens()))}toString(){return this.media.map((e=>e.toString())).join("")}walk(e){let t=!1;if(this.media.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),t)return!1}toJSON(){return{type:this.type,string:this.toString(),media:this.media}}isMediaQueryInvalid(){return MediaQueryInvalid.isMediaQueryInvalid(this)}static isMediaQueryInvalid(e){return!!e&&(e instanceof MediaQueryInvalid&&e.type===l.MediaQueryInvalid)}}class GeneralEnclosed{type=l.GeneralEnclosed;value;constructor(e){this.value=e}tokens(){return this.value.tokens()}toString(){return this.value.toString()}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,tokens:this.tokens()}}isGeneralEnclosed(){return GeneralEnclosed.isGeneralEnclosed(this)}static isGeneralEnclosed(e){return!!e&&(e instanceof GeneralEnclosed&&e.type===l.GeneralEnclosed)}}class MediaAnd{type=l.MediaAnd;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaAnd(){return MediaAnd.isMediaAnd(this)}static isMediaAnd(e){return!!e&&(e instanceof MediaAnd&&e.type===l.MediaAnd)}}class MediaConditionListWithAnd{type=l.MediaConditionListWithAnd;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-and"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithAnd(){return MediaConditionListWithAnd.isMediaConditionListWithAnd(this)}static isMediaConditionListWithAnd(e){return!!e&&(e instanceof MediaConditionListWithAnd&&e.type===l.MediaConditionListWithAnd)}}class MediaConditionListWithOr{type=l.MediaConditionListWithOr;leading;list;before;after;constructor(e,t,i=[],a=[]){this.leading=e,this.list=t,this.before=i,this.after=a}tokens(){return[...this.before,...this.leading.tokens(),...this.list.flatMap((e=>e.tokens())),...this.after]}toString(){return s(...this.before)+this.leading.toString()+this.list.map((e=>e.toString())).join("")+s(...this.after)}indexOf(e){return e===this.leading?"leading":"media-or"===e.type?this.list.indexOf(e):-1}at(e){return"leading"===e?this.leading:"number"==typeof e?(e<0&&(e=this.list.length+e),this.list[e]):void 0}walk(e){if(!1===e({node:this.leading,parent:this},"leading"))return!1;if("walk"in this.leading&&!1===this.leading.walk(e))return!1;let t=!1;return this.list.forEach(((i,a)=>{t||(!1!==e({node:i,parent:this},a)?"walk"in i&&!1===i.walk(e)&&(t=!0):t=!0)})),!t&&void 0}toJSON(){return{type:this.type,leading:this.leading.toJSON(),list:this.list.map((e=>e.toJSON())),before:this.before,after:this.after}}isMediaConditionListWithOr(){return MediaConditionListWithOr.isMediaConditionListWithOr(this)}static isMediaConditionListWithOr(e){return!!e&&(e instanceof MediaConditionListWithOr&&e.type===l.MediaConditionListWithOr)}}function isNumber(t){return t.type===e.Token&&t.value[0]===o.Number||t.type===e.Function&&"calc"===t.name[4].value}function isDimension(t){return t.type===e.Token&&t.value[0]===o.Dimension}function isIdent(t){return t.type===e.Token&&t.value[0]===o.Ident}class MediaFeatureName{type=l.MediaFeatureName;name;before;after;constructor(e,t=[],i=[]){this.name=e,this.before=t,this.after=i}getName(){return this.name.value[4].value}getNameToken(){return this.name.value}tokens(){return[...this.before,...this.name.tokens(),...this.after]}toString(){return s(...this.before)+this.name.toString()+s(...this.after)}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.getName(),tokens:this.tokens()}}isMediaFeatureName(){return MediaFeatureName.isMediaFeatureName(this)}static isMediaFeatureName(e){return!!e&&(e instanceof MediaFeatureName&&e.type===l.MediaFeatureName)}}function parseMediaFeatureName(t){let i=-1;for(let a=0;ae.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}class MediaFeatureBoolean{type=l.MediaFeatureBoolean;name;constructor(e){this.name=e}getName(){return this.name.getName()}getNameToken(){return this.name.getNameToken()}tokens(){return this.name.tokens()}toString(){return this.name.toString()}indexOf(e){return e===this.name?"name":-1}at(e){if("name"===e)return this.name}toJSON(){return{type:this.type,name:this.name.toJSON(),tokens:this.tokens()}}isMediaFeatureBoolean(){return MediaFeatureBoolean.isMediaFeatureBoolean(this)}static isMediaFeatureBoolean(e){return!!e&&(e instanceof MediaFeatureBoolean&&e.type===l.MediaFeatureBoolean)}}function parseMediaFeatureBoolean(e){const t=parseMediaFeatureName(e);return!1===t?t:new MediaFeatureBoolean(t)}class MediaFeatureValue{type=l.MediaFeatureValue;value;before;after;constructor(e,t=[],i=[]){Array.isArray(e)&&1===e.length?this.value=e[0]:this.value=e,this.before=t,this.after=i}tokens(){return Array.isArray(this.value)?[...this.before,...this.value.flatMap((e=>e.tokens())),...this.after]:[...this.before,...this.value.tokens(),...this.after]}toString(){return Array.isArray(this.value)?s(...this.before)+this.value.map((e=>e.toString())).join("")+s(...this.after):s(...this.before)+this.value.toString()+s(...this.after)}indexOf(e){return e===this.value?"value":-1}at(e){if("value"===e)return this.value}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return Array.isArray(this.value)?{type:this.type,value:this.value.map((e=>e.toJSON())),tokens:this.tokens()}:{type:this.type,value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureValue(){return MediaFeatureValue.isMediaFeatureValue(this)}static isMediaFeatureValue(e){return!!e&&(e instanceof MediaFeatureValue&&e.type===l.MediaFeatureValue)}}function parseMediaFeatureValue(t){let i=-1,a=-1;for(let n=0;ne.tokens())),t.slice(a+1).flatMap((e=>e.tokens())))}function matchesRatioExactly(e){let t=-1,i=-1;const a=matchesRatio(e);if(-1===a)return-1;t=a[0],i=a[1];for(let t=i+1;t2)return!1;if(e[0][0]!==o.Delim)return!1;if(1===e.length)switch(e[0][4].value){case f.EQ:return f.EQ;case h.LT:return h.LT;case m.GT:return m.GT;default:return!1}if(e[1][0]!==o.Delim)return!1;if(e[1][4].value!==f.EQ)return!1;switch(e[0][4].value){case h.LT:return h.LT_OR_EQ;case m.GT:return m.GT_OR_EQ;default:return!1}}function invertComparison(e){switch(e){case f.EQ:return f.EQ;case h.LT:return m.GT;case h.LT_OR_EQ:return m.GT_OR_EQ;case m.GT:return h.LT;case m.GT_OR_EQ:return h.LT_OR_EQ;default:return!1}}!function(e){e.LT="<",e.LT_OR_EQ="<="}(h||(h={})),function(e){e.GT=">",e.GT_OR_EQ=">="}(m||(m={})),function(e){e.EQ="="}(f||(f={}));class MediaFeatureRangeNameValue{type=l.MediaFeatureRangeNameValue;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.name.tokens(),...this.operator,...this.value.tokens()]}toString(){return this.name.toString()+s(...this.operator)+this.value.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeNameValue(){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(this)}static isMediaFeatureRangeNameValue(e){return!!e&&(e instanceof MediaFeatureRangeNameValue&&e.type===l.MediaFeatureRangeNameValue)}}class MediaFeatureRangeValueName{type=l.MediaFeatureRangeValueName;name;operator;value;constructor(e,t,i){this.name=e,this.operator=t,this.value=i}operatorKind(){return comparisonFromTokens(this.operator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.value.tokens(),...this.operator,...this.name.tokens()]}toString(){return this.value.toString()+s(...this.operator)+this.name.toString()}indexOf(e){return e===this.name?"name":e===this.value?"value":-1}at(e){return"name"===e?this.name:"value"===e?this.value:void 0}walk(e){return!1!==e({node:this.value,parent:this},"value")&&("walk"in this.value?this.value.walk(e):void 0)}toJSON(){return{type:this.type,name:this.name.toJSON(),value:this.value.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueName(){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(this)}static isMediaFeatureRangeValueName(e){return!!e&&(e instanceof MediaFeatureRangeValueName&&e.type===l.MediaFeatureRangeValueName)}}class MediaFeatureRangeValueNameValue{type=l.MediaFeatureRangeValueNameValue;name;valueOne;valueOneOperator;valueTwo;valueTwoOperator;constructor(e,t,i,a,n){this.name=e,this.valueOne=t,this.valueOneOperator=i,this.valueTwo=a,this.valueTwoOperator=n}valueOneOperatorKind(){return comparisonFromTokens(this.valueOneOperator)}valueTwoOperatorKind(){return comparisonFromTokens(this.valueTwoOperator)}getName(){this.name.getName()}getNameToken(){this.name.getNameToken()}tokens(){return[...this.valueOne.tokens(),...this.valueOneOperator,...this.name.tokens(),...this.valueTwoOperator,...this.valueTwo.tokens()]}toString(){return this.valueOne.toString()+s(...this.valueOneOperator)+this.name.toString()+s(...this.valueTwoOperator)+this.valueTwo.toString()}indexOf(e){return e===this.name?"name":e===this.valueOne?"valueOne":e===this.valueTwo?"valueTwo":-1}at(e){return"name"===e?this.name:"valueOne"===e?this.valueOne:"valueTwo"===e?this.valueTwo:void 0}walk(e){return!1!==e({node:this.valueOne,parent:this},"valueOne")&&((!("walk"in this.valueOne)||!1!==this.valueOne.walk(e))&&(!1!==e({node:this.valueTwo,parent:this},"valueTwo")&&((!("walk"in this.valueTwo)||!1!==this.valueTwo.walk(e))&&void 0)))}toJSON(){return{type:this.type,name:this.name.toJSON(),valueOne:this.valueOne.toJSON(),valueTwo:this.valueTwo.toJSON(),tokens:this.tokens()}}isMediaFeatureRangeValueNameValue(){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(this)}static isMediaFeatureRangeValueNameValue(e){return!!e&&(e instanceof MediaFeatureRangeValueNameValue&&e.type===l.MediaFeatureRangeValueNameValue)}}function parseMediaFeatureRange(t){let i=!1,a=!1;for(let n=0;nnew t(e))))),[[o.OpenParen,"(",-1,-1,void 0]],[[o.CloseParen,")",-1,-1,void 0]])}class MediaNot{type=l.MediaNot;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaNot(){return MediaNot.isMediaNot(this)}static isMediaNot(e){return!!e&&(e instanceof MediaNot&&e.type===l.MediaNot)}}class MediaOr{type=l.MediaOr;modifier;media;constructor(e,t){this.modifier=e,this.media=t}tokens(){return[...this.modifier,...this.media.tokens()]}toString(){return s(...this.modifier)+this.media.toString()}indexOf(e){return e===this.media?"media":-1}at(e){if("media"===e)return this.media}walk(e){return!1!==e({node:this.media,parent:this},"media")&&this.media.walk(e)}toJSON(){return{type:this.type,modifier:this.modifier,media:this.media.toJSON()}}isMediaOr(){return MediaOr.isMediaOr(this)}static isMediaOr(e){return!!e&&(e instanceof MediaOr&&e.type===l.MediaOr)}}var M,p;function modifierFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case M.Not:return M.Not;case M.Only:return M.Only;default:return!1}}function parseMediaQuery(e){{const t=parseMediaCondition(e);if(!1!==t)return new MediaQueryWithoutType(t)}{let t=-1,r=-1,s=-1;for(let u=0;ue.tokens())),-1!==r&&(d=e.slice(t+1,r+1).flatMap((e=>e.tokens())))):-1!==r&&(d=e.slice(0,r+1).flatMap((e=>e.tokens())));const l=parseMediaConditionWithoutOr(e.slice(Math.max(t,r,s)+1));return!1===l?new MediaQueryWithType(u,[...d,...e.slice(r+1).flatMap((e=>e.tokens()))]):new MediaQueryWithType(u,d,e.slice(r+1,s+1).flatMap((e=>e.tokens())),l)}}function parseMediaConditionListWithOr(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaConditionListWithAnd(t){let i=!1;const a=[];let n=-1,r=-1;for(let s=0;se.tokens())),t.slice(r+1).flatMap((e=>e.tokens())))}function parseMediaCondition(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaConditionListWithOr(e);if(!1!==a)return new MediaCondition(a);const n=parseMediaInParens(e);return!1!==n&&new MediaCondition(n)}function parseMediaConditionWithoutOr(e){const t=parseMediaNot(e);if(!1!==t)return new MediaCondition(t);const i=parseMediaConditionListWithAnd(e);if(!1!==i)return new MediaCondition(i);const a=parseMediaInParens(e);return!1!==a&&new MediaCondition(a)}function parseMediaInParens(t){let i=-1;for(let a=0;ae.tokens())),a.startToken],r=[a.endToken,...t.slice(i+1).flatMap((e=>e.tokens()))],s=parseMediaFeature(a,n,r);if(!1!==s)return new MediaInParens(s);const u=parseMediaCondition(a.value);return!1!==u?new MediaInParens(u,n,r):new MediaInParens(new GeneralEnclosed(a),t.slice(0,i).flatMap((e=>e.tokens())),t.slice(i+1).flatMap((e=>e.tokens())))}function parseMediaInParensFromSimpleBlock(e){if(e.startToken[0]!==o.OpenParen)return!1;const t=parseMediaFeature(e,[e.startToken],[e.endToken]);if(!1!==t)return new MediaInParens(t);const i=parseMediaCondition(e.value);return!1!==i?new MediaInParens(i,[e.startToken],[e.endToken]):new MediaInParens(new GeneralEnclosed(e))}function parseMediaNot(t){let i=!1,a=null;for(let n=0;ne.tokens())),e)}}}return a||!1}function parseMediaOr(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseMediaAnd(t){let i=!1;for(let a=0;ae.tokens())),e)}}return!1}}return!1}function parseFromTokens(e,t){const i=r(e,{onParseError:null==t?void 0:t.onParseError});return i.map(((e,a)=>{const n=parseMediaQuery(e);return 0==n&&!0===(null==t?void 0:t.preserveInvalidMediaQueries)?new MediaQueryInvalid(i[a]):n})).filter((e=>!!e))}function parse(e,t){const i=u({css:e},{commentsAreTokens:!0,onParseError:null==t?void 0:t.onParseError}),a=[];for(;!i.endOfFile();)a.push(i.nextToken());return a.push(i.nextToken()),parseFromTokens(a,t)}function isGeneralEnclosed(e){return GeneralEnclosed.isGeneralEnclosed(e)}function isMediaAnd(e){return MediaAnd.isMediaAnd(e)}function isMediaConditionList(e){return isMediaConditionListWithAnd(e)||isMediaConditionListWithOr(e)}function isMediaConditionListWithAnd(e){return MediaConditionListWithAnd.isMediaConditionListWithAnd(e)}function isMediaConditionListWithOr(e){return MediaConditionListWithOr.isMediaConditionListWithOr(e)}function isMediaCondition(e){return MediaCondition.isMediaCondition(e)}function isMediaFeatureBoolean(e){return MediaFeatureBoolean.isMediaFeatureBoolean(e)}function isMediaFeatureName(e){return MediaFeatureName.isMediaFeatureName(e)}function isMediaFeatureValue(e){return MediaFeatureValue.isMediaFeatureValue(e)}function isMediaFeaturePlain(e){return MediaFeaturePlain.isMediaFeaturePlain(e)}function isMediaFeatureRange(e){return isMediaFeatureRangeNameValue(e)||isMediaFeatureRangeValueName(e)||isMediaFeatureRangeValueNameValue(e)}function isMediaFeatureRangeNameValue(e){return MediaFeatureRangeNameValue.isMediaFeatureRangeNameValue(e)}function isMediaFeatureRangeValueName(e){return MediaFeatureRangeValueName.isMediaFeatureRangeValueName(e)}function isMediaFeatureRangeValueNameValue(e){return MediaFeatureRangeValueNameValue.isMediaFeatureRangeValueNameValue(e)}function isMediaFeature(e){return MediaFeature.isMediaFeature(e)}function isMediaInParens(e){return MediaInParens.isMediaInParens(e)}function isMediaNot(e){return MediaNot.isMediaNot(e)}function isMediaOr(e){return MediaOr.isMediaOr(e)}function isMediaQuery(e){return isMediaQueryWithType(e)||isMediaQueryWithoutType(e)||isMediaQueryInvalid(e)}function isMediaQueryWithType(e){return MediaQueryWithType.isMediaQueryWithType(e)}function isMediaQueryWithoutType(e){return MediaQueryWithoutType.isMediaQueryWithoutType(e)}function isMediaQueryInvalid(e){return MediaQueryInvalid.isMediaQueryInvalid(e)}function typeFromToken(e){if(e[0]!==o.Ident)return!1;switch(e[4].value.toLowerCase()){case p.All:return p.All;case p.Print:return p.Print;case p.Screen:return p.Screen;case p.Tty:return p.Tty;case p.Tv:return p.Tv;case p.Projection:return p.Projection;case p.Handheld:return p.Handheld;case p.Braille:return p.Braille;case p.Embossed:return p.Embossed;case p.Aural:return p.Aural;case p.Speech:return p.Speech;default:return!1}}function cloneMediaQuery(e){const t=d(e.tokens()),i=parseFromTokens(t,{preserveInvalidMediaQueries:!0})[0];if(!i)throw new Error(`Failed to clone media query for : "${s(...t)}"`);if(isMediaQueryInvalid(e)&&isMediaQueryInvalid(i))return i;if(isMediaQueryWithType(e)&&isMediaQueryWithType(i))return i;if(isMediaQueryWithoutType(e)&&isMediaQueryWithoutType(i))return i;throw new Error(`Failed to clone media query for : "${s(...t)}"`)}!function(e){e.Not="not",e.Only="only"}(M||(M={})),function(e){e.All="all",e.Print="print",e.Screen="screen",e.Tty="tty",e.Tv="tv",e.Projection="projection",e.Handheld="handheld",e.Braille="braille",e.Embossed="embossed",e.Aural="aural",e.Speech="speech"}(p||(p={}));export{GeneralEnclosed,MediaAnd,MediaCondition,MediaConditionListWithAnd,MediaConditionListWithOr,MediaFeature,MediaFeatureBoolean,f as MediaFeatureEQ,m as MediaFeatureGT,h as MediaFeatureLT,MediaFeatureName,MediaFeaturePlain,MediaFeatureRangeNameValue,MediaFeatureRangeValueName,MediaFeatureRangeValueNameValue,MediaFeatureValue,MediaInParens,MediaNot,MediaOr,MediaQueryInvalid,M as MediaQueryModifier,MediaQueryWithType,MediaQueryWithoutType,p as MediaType,l as NodeType,cloneMediaQuery,comparisonFromTokens,invertComparison,isGeneralEnclosed,isMediaAnd,isMediaCondition,isMediaConditionList,isMediaConditionListWithAnd,isMediaConditionListWithOr,isMediaFeature,isMediaFeatureBoolean,isMediaFeatureName,isMediaFeaturePlain,isMediaFeatureRange,isMediaFeatureRangeNameValue,isMediaFeatureRangeValueName,isMediaFeatureRangeValueNameValue,isMediaFeatureValue,isMediaInParens,isMediaNot,isMediaOr,isMediaQuery,isMediaQueryInvalid,isMediaQueryWithType,isMediaQueryWithoutType,matchesComparison,matchesRatio,matchesRatioExactly,modifierFromToken,newMediaFeatureBoolean,newMediaFeaturePlain,parse,parseFromTokens,typeFromToken}; diff --git a/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts b/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts index 0b0cfaff5..314f3ca96 100644 --- a/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts +++ b/packages/media-query-list-parser/dist/nodes/media-feature-boolean.d.ts @@ -1,21 +1,24 @@ import { ComponentValue } from '@csstools/css-parser-algorithms'; +import { MediaFeatureName } from './media-feature-name'; import { NodeType } from '../util/node-type'; -import { CSSToken, TokenIdent } from '@csstools/css-tokenizer'; +import { CSSToken } from '@csstools/css-tokenizer'; export declare class MediaFeatureBoolean { type: NodeType; - name: ComponentValue; - before: Array; - after: Array; - constructor(name: ComponentValue, before?: Array, after?: Array); + name: MediaFeatureName; + constructor(name: MediaFeatureName); getName(): string; - getNameToken(): TokenIdent; + getNameToken(): import("@csstools/css-tokenizer").TokenIdent; tokens(): Array; toString(): string; - indexOf(item: ComponentValue): number | string; - at(index: number | string): ComponentValue; + indexOf(item: MediaFeatureName): number | string; + at(index: number | string): MediaFeatureName; toJSON(): { type: NodeType; - name: string; + name: { + type: NodeType; + name: string; + tokens: CSSToken[]; + }; tokens: CSSToken[]; }; isMediaFeatureBoolean(): this is MediaFeatureBoolean; diff --git a/packages/media-query-list-parser/dist/nodes/media-feature.d.ts b/packages/media-query-list-parser/dist/nodes/media-feature.d.ts index 371d926d0..3432aedd1 100644 --- a/packages/media-query-list-parser/dist/nodes/media-feature.d.ts +++ b/packages/media-query-list-parser/dist/nodes/media-feature.d.ts @@ -23,39 +23,12 @@ export declare class MediaFeature { toJSON(): { type: NodeType; feature: { - type: NodeType; - name: string; - tokens: CSSToken[]; - } | { - type: NodeType; - name: { - type: NodeType; - name: string; - tokens: CSSToken[]; - }; - value: { - type: NodeType; - value: any; - tokens: CSSToken[]; - }; - tokens: CSSToken[]; - } | { type: NodeType; name: { type: NodeType; name: string; tokens: CSSToken[]; }; - valueOne: { - type: NodeType; - value: any; - tokens: CSSToken[]; - }; - valueTwo: { - type: NodeType; - value: any; - tokens: CSSToken[]; - }; tokens: CSSToken[]; }; before: CSSToken[]; diff --git a/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts b/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts index b404de3c9..74ae5ec11 100644 --- a/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts +++ b/packages/media-query-list-parser/src/nodes/media-feature-boolean.ts @@ -1,44 +1,34 @@ -import { ComponentValue, TokenNode } from '@csstools/css-parser-algorithms'; -import { parseMediaFeatureName } from './media-feature-name'; +import { ComponentValue } from '@csstools/css-parser-algorithms'; +import { MediaFeatureName, parseMediaFeatureName } from './media-feature-name'; import { NodeType } from '../util/node-type'; -import { CSSToken, stringify, TokenIdent } from '@csstools/css-tokenizer'; +import { CSSToken } from '@csstools/css-tokenizer'; export class MediaFeatureBoolean { type = NodeType.MediaFeatureBoolean; - name: ComponentValue; - before: Array; - after: Array; + name: MediaFeatureName; - constructor(name: ComponentValue, before: Array = [], after: Array = []) { + constructor(name: MediaFeatureName) { this.name = name; - this.before = before; - this.after = after; } getName() { - const token = (((this.name as TokenNode).value as CSSToken) as TokenIdent); - return token[4].value; + return this.name.getName(); } getNameToken() { - const token = (((this.name as TokenNode).value as CSSToken) as TokenIdent); - return token; + return this.name.getNameToken(); } tokens(): Array { - return [ - ...this.before, - ...this.name.tokens(), - ...this.after, - ]; + return this.name.tokens(); } toString(): string { - return stringify(...this.before) + this.name.toString() + stringify(...this.after); + return this.name.toString(); } - indexOf(item: ComponentValue): number | string { + indexOf(item: MediaFeatureName): number | string { if (item === this.name) { return 'name'; } @@ -55,7 +45,7 @@ export class MediaFeatureBoolean { toJSON() { return { type: this.type, - name: this.getName(), + name: this.name.toJSON(), tokens: this.tokens(), }; } @@ -83,5 +73,5 @@ export function parseMediaFeatureBoolean(componentValues: Array) return mediaFeatureName; } - return new MediaFeatureBoolean(mediaFeatureName.name, mediaFeatureName.before, mediaFeatureName.after); + return new MediaFeatureBoolean(mediaFeatureName); } diff --git a/packages/media-query-list-parser/src/nodes/media-feature.ts b/packages/media-query-list-parser/src/nodes/media-feature.ts index c1d585042..32b71e84d 100644 --- a/packages/media-query-list-parser/src/nodes/media-feature.ts +++ b/packages/media-query-list-parser/src/nodes/media-feature.ts @@ -119,7 +119,7 @@ export function parseMediaFeature(simpleBlock: SimpleBlockNode, before: Array { + assert.deepStrictEqual( + actual, + expected, + ); + }, +); diff --git a/packages/media-query-list-parser/test/cases/mf-plain/0007.expect.json b/packages/media-query-list-parser/test/cases/mf-plain/0007.expect.json new file mode 100644 index 000000000..049a166df --- /dev/null +++ b/packages/media-query-list-parser/test/cases/mf-plain/0007.expect.json @@ -0,0 +1,351 @@ +[ + { + "type": "media-query-without-type", + "string": "(min-width: c\\61 lc(10px + 2px))", + "media": { + "type": "media-condition", + "media": { + "type": "media-in-parens", + "media": { + "type": "media-feature", + "feature": { + "type": "mf-plain", + "name": { + "type": "mf-name", + "name": "min-width", + "tokens": [ + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ] + ] + }, + "value": { + "type": "mf-value", + "value": { + "type": "function", + "name": "calc", + "tokens": [ + [ + "function-token", + "c\\61 lc(", + 12, + 19, + { + "value": "calc" + } + ], + [ + "dimension-token", + "10px", + 20, + 23, + { + "value": 10, + "type": "integer", + "unit": "px" + } + ], + [ + "whitespace-token", + " ", + 24, + 24, + null + ], + [ + "delim-token", + "+", + 25, + 25, + { + "value": "+" + } + ], + [ + "whitespace-token", + " ", + 26, + 26, + null + ], + [ + "dimension-token", + "2px", + 27, + 29, + { + "value": 2, + "type": "integer", + "unit": "px" + } + ], + [ + ")-token", + ")", + 30, + 30, + null + ] + ], + "value": [ + { + "type": "token", + "tokens": [ + [ + "dimension-token", + "10px", + 20, + 23, + { + "value": 10, + "type": "integer", + "unit": "px" + } + ] + ] + }, + { + "type": "whitespace", + "tokens": [ + [ + "whitespace-token", + " ", + 24, + 24, + null + ] + ] + }, + { + "type": "token", + "tokens": [ + [ + "delim-token", + "+", + 25, + 25, + { + "value": "+" + } + ] + ] + }, + { + "type": "whitespace", + "tokens": [ + [ + "whitespace-token", + " ", + 26, + 26, + null + ] + ] + }, + { + "type": "token", + "tokens": [ + [ + "dimension-token", + "2px", + 27, + 29, + { + "value": 2, + "type": "integer", + "unit": "px" + } + ] + ] + } + ] + }, + "tokens": [ + [ + "whitespace-token", + " ", + 11, + 11, + null + ], + [ + "function-token", + "c\\61 lc(", + 12, + 19, + { + "value": "calc" + } + ], + [ + "dimension-token", + "10px", + 20, + 23, + { + "value": 10, + "type": "integer", + "unit": "px" + } + ], + [ + "whitespace-token", + " ", + 24, + 24, + null + ], + [ + "delim-token", + "+", + 25, + 25, + { + "value": "+" + } + ], + [ + "whitespace-token", + " ", + 26, + 26, + null + ], + [ + "dimension-token", + "2px", + 27, + 29, + { + "value": 2, + "type": "integer", + "unit": "px" + } + ], + [ + ")-token", + ")", + 30, + 30, + null + ] + ] + }, + "tokens": [ + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ], + [ + "colon-token", + ":", + 10, + 10, + null + ], + [ + "whitespace-token", + " ", + 11, + 11, + null + ], + [ + "function-token", + "c\\61 lc(", + 12, + 19, + { + "value": "calc" + } + ], + [ + "dimension-token", + "10px", + 20, + 23, + { + "value": 10, + "type": "integer", + "unit": "px" + } + ], + [ + "whitespace-token", + " ", + 24, + 24, + null + ], + [ + "delim-token", + "+", + 25, + 25, + { + "value": "+" + } + ], + [ + "whitespace-token", + " ", + 26, + 26, + null + ], + [ + "dimension-token", + "2px", + 27, + 29, + { + "value": 2, + "type": "integer", + "unit": "px" + } + ], + [ + ")-token", + ")", + 30, + 30, + null + ] + ] + }, + "before": [ + [ + "(-token", + "(", + 0, + 0, + null + ] + ], + "after": [ + [ + ")-token", + ")", + 31, + 31, + null + ] + ] + }, + "before": [], + "after": [] + } + } + } +] \ No newline at end of file diff --git a/packages/media-query-list-parser/test/cases/mf-plain/0007.mjs b/packages/media-query-list-parser/test/cases/mf-plain/0007.mjs new file mode 100644 index 000000000..3f5b8a294 --- /dev/null +++ b/packages/media-query-list-parser/test/cases/mf-plain/0007.mjs @@ -0,0 +1,13 @@ +import assert from 'assert'; +import { runTest } from '../../util/run-test.mjs'; + +runTest( + '(min-width: c\\61 lc(10px + 2px))', + 'mf-plain/0007', + (actual, expected) => { + assert.deepStrictEqual( + actual, + expected, + ); + }, +); diff --git a/packages/media-query-list-parser/test/cases/mf-plain/0008.expect.json b/packages/media-query-list-parser/test/cases/mf-plain/0008.expect.json new file mode 100644 index 000000000..3dcecbc18 --- /dev/null +++ b/packages/media-query-list-parser/test/cases/mf-plain/0008.expect.json @@ -0,0 +1,81 @@ +[ + { + "type": "media-query-without-type", + "string": "(min-width: token('foo'))", + "media": { + "type": "media-condition", + "media": { + "type": "media-in-parens", + "media": { + "type": "general-enclosed", + "tokens": [ + [ + "(-token", + "(", + 0, + 0, + null + ], + [ + "ident-token", + "min-width", + 1, + 9, + { + "value": "min-width" + } + ], + [ + "colon-token", + ":", + 10, + 10, + null + ], + [ + "whitespace-token", + " ", + 11, + 11, + null + ], + [ + "function-token", + "token(", + 12, + 17, + { + "value": "token" + } + ], + [ + "string-token", + "'foo'", + 18, + 22, + { + "value": "foo" + } + ], + [ + ")-token", + ")", + 23, + 23, + null + ], + [ + ")-token", + ")", + 24, + 24, + null + ] + ] + }, + "before": [], + "after": [] + } + } + } +] \ No newline at end of file diff --git a/packages/media-query-list-parser/test/cases/mf-plain/0008.mjs b/packages/media-query-list-parser/test/cases/mf-plain/0008.mjs new file mode 100644 index 000000000..d467ff39a --- /dev/null +++ b/packages/media-query-list-parser/test/cases/mf-plain/0008.mjs @@ -0,0 +1,14 @@ +import assert from 'assert'; +import { runTest } from '../../util/run-test.mjs'; + +runTest( + '(min-width: token(\'foo\'))', + 'mf-plain/0008', + (actual, expected) => { + assert.deepStrictEqual( + actual, + expected, + ); + }, + 1, +); diff --git a/packages/media-query-list-parser/test/cases/query-with-type/0008.expect.json b/packages/media-query-list-parser/test/cases/query-with-type/0008.expect.json index 68d2f7108..327ef6ac7 100644 --- a/packages/media-query-list-parser/test/cases/query-with-type/0008.expect.json +++ b/packages/media-query-list-parser/test/cases/query-with-type/0008.expect.json @@ -42,7 +42,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "height", + "name": { + "type": "mf-name", + "name": "height", + "tokens": [ + [ + "ident-token", + "height", + 12, + 17, + { + "value": "height" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/cases/specification-examples/0003.expect.json b/packages/media-query-list-parser/test/cases/specification-examples/0003.expect.json index 632d6888f..d9e88c40a 100644 --- a/packages/media-query-list-parser/test/cases/specification-examples/0003.expect.json +++ b/packages/media-query-list-parser/test/cases/specification-examples/0003.expect.json @@ -40,7 +40,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 12, + 16, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -132,7 +146,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 36, + 40, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/cases/specification-examples/0010.expect.json b/packages/media-query-list-parser/test/cases/specification-examples/0010.expect.json index 86d043cf0..b4dae1431 100644 --- a/packages/media-query-list-parser/test/cases/specification-examples/0010.expect.json +++ b/packages/media-query-list-parser/test/cases/specification-examples/0010.expect.json @@ -36,7 +36,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 6, + 10, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -126,7 +140,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "hover", + "name": { + "type": "mf-name", + "name": "hover", + "tokens": [ + [ + "ident-token", + "hover", + 18, + 22, + { + "value": "hover" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/cases/specification-examples/0011.expect.json b/packages/media-query-list-parser/test/cases/specification-examples/0011.expect.json index 388ba1017..e5428a881 100644 --- a/packages/media-query-list-parser/test/cases/specification-examples/0011.expect.json +++ b/packages/media-query-list-parser/test/cases/specification-examples/0011.expect.json @@ -36,7 +36,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 6, + 10, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -105,7 +119,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "hover", + "name": { + "type": "mf-name", + "name": "hover", + "tokens": [ + [ + "ident-token", + "hover", + 17, + 21, + { + "value": "hover" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/cases/specification-examples/0012.expect.json b/packages/media-query-list-parser/test/cases/specification-examples/0012.expect.json index 0ff982293..d9808f695 100644 --- a/packages/media-query-list-parser/test/cases/specification-examples/0012.expect.json +++ b/packages/media-query-list-parser/test/cases/specification-examples/0012.expect.json @@ -36,7 +36,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 6, + 10, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -150,7 +164,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "hover", + "name": { + "type": "mf-name", + "name": "hover", + "tokens": [ + [ + "ident-token", + "hover", + 24, + 28, + { + "value": "hover" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/cases/specification-examples/0013.expect.json b/packages/media-query-list-parser/test/cases/specification-examples/0013.expect.json index 24a092e18..0f0138d02 100644 --- a/packages/media-query-list-parser/test/cases/specification-examples/0013.expect.json +++ b/packages/media-query-list-parser/test/cases/specification-examples/0013.expect.json @@ -12,7 +12,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 1, + 5, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -87,7 +101,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "pointer", + "name": { + "type": "mf-name", + "name": "pointer", + "tokens": [ + [ + "ident-token", + "pointer", + 14, + 20, + { + "value": "pointer" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -156,7 +184,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "hover", + "name": { + "type": "mf-name", + "name": "hover", + "tokens": [ + [ + "ident-token", + "hover", + 27, + 31, + { + "value": "hover" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/cases/specification-examples/0014.expect.json b/packages/media-query-list-parser/test/cases/specification-examples/0014.expect.json index 26292910c..9d2414f11 100644 --- a/packages/media-query-list-parser/test/cases/specification-examples/0014.expect.json +++ b/packages/media-query-list-parser/test/cases/specification-examples/0014.expect.json @@ -18,7 +18,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 2, + 6, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -87,7 +101,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "pointer", + "name": { + "type": "mf-name", + "name": "pointer", + "tokens": [ + [ + "ident-token", + "pointer", + 14, + 20, + { + "value": "pointer" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -181,7 +209,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "hover", + "name": { + "type": "mf-name", + "name": "hover", + "tokens": [ + [ + "ident-token", + "hover", + 28, + 32, + { + "value": "hover" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/cases/specification-examples/0019.expect.json b/packages/media-query-list-parser/test/cases/specification-examples/0019.expect.json index 67bb1b659..74aa8072c 100644 --- a/packages/media-query-list-parser/test/cases/specification-examples/0019.expect.json +++ b/packages/media-query-list-parser/test/cases/specification-examples/0019.expect.json @@ -16,7 +16,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "color", + "name": { + "type": "mf-name", + "name": "color", + "tokens": [ + [ + "ident-token", + "color", + 2, + 6, + { + "value": "color" + } + ] + ] + }, "tokens": [ [ "ident-token", @@ -85,7 +99,21 @@ "type": "media-feature", "feature": { "type": "mf-boolean", - "name": "width", + "name": { + "type": "mf-name", + "name": "width", + "tokens": [ + [ + "ident-token", + "width", + 14, + 18, + { + "value": "width" + } + ] + ] + }, "tokens": [ [ "ident-token", diff --git a/packages/media-query-list-parser/test/test.mjs b/packages/media-query-list-parser/test/test.mjs index e77fde399..9e6e70b79 100644 --- a/packages/media-query-list-parser/test/test.mjs +++ b/packages/media-query-list-parser/test/test.mjs @@ -13,6 +13,9 @@ import './cases/mf-plain/0002.mjs'; import './cases/mf-plain/0003.mjs'; import './cases/mf-plain/0004.mjs'; import './cases/mf-plain/0005.mjs'; +import './cases/mf-plain/0006.mjs'; +import './cases/mf-plain/0007.mjs'; +import './cases/mf-plain/0008.mjs'; import './cases/mf-range/0001.mjs'; import './cases/mf-range/0002.mjs'; From 374b5f0837aac1127332546e0ea69c746fea8e8c Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Tue, 3 Jan 2023 23:07:22 +0100 Subject: [PATCH 14/24] more tests and fixes --- .../dist/code-points/code-points.d.ts | 78 ++++++------ packages/css-tokenizer/dist/index.cjs | 2 +- packages/css-tokenizer/dist/index.mjs | 2 +- .../src/code-points/code-points.ts | 78 ++++++------ .../css-tokenizer/src/code-points/ranges.ts | 116 ++++-------------- .../src/consume/ident-like-token.ts | 8 +- packages/css-tokenizer/test/test.mjs | 2 + packages/css-tokenizer/test/token/basic.mjs | 29 +++++ packages/css-tokenizer/test/token/cdo.mjs | 50 ++++++++ packages/css-tokenizer/test/token/numeric.mjs | 20 +++ packages/css-tokenizer/test/token/string.mjs | 85 +++++++++++++ packages/css-tokenizer/test/token/url.mjs | 87 +++++++++++++ 12 files changed, 376 insertions(+), 181 deletions(-) create mode 100644 packages/css-tokenizer/test/token/cdo.mjs create mode 100644 packages/css-tokenizer/test/token/string.mjs diff --git a/packages/css-tokenizer/dist/code-points/code-points.d.ts b/packages/css-tokenizer/dist/code-points/code-points.d.ts index 66cbce284..c920f6193 100644 --- a/packages/css-tokenizer/dist/code-points/code-points.d.ts +++ b/packages/css-tokenizer/dist/code-points/code-points.d.ts @@ -1,78 +1,78 @@ /** ' */ -export declare const APOSTROPHE: number; +export declare const APOSTROPHE = 39; /** * */ -export declare const ASTERISK: number; +export declare const ASTERISK = 42; /** \b */ -export declare const BACKSPACE: number; +export declare const BACKSPACE = 8; /** \r */ -export declare const CARRIAGE_RETURN: number; +export declare const CARRIAGE_RETURN = 13; /** \t */ -export declare const CHARACTER_TABULATION: number; +export declare const CHARACTER_TABULATION = 9; /** : */ -export declare const COLON: number; +export declare const COLON = 58; /** , */ -export declare const COMMA: number; +export declare const COMMA = 44; /** @ */ -export declare const COMMERCIAL_AT: number; +export declare const COMMERCIAL_AT = 64; /** \x7F */ -export declare const DELETE: number; +export declare const DELETE = 127; /** ! */ -export declare const EXCLAMATION_MARK: number; +export declare const EXCLAMATION_MARK = 33; /** \f */ -export declare const FORM_FEED: number; +export declare const FORM_FEED = 12; /** . */ -export declare const FULL_STOP: number; +export declare const FULL_STOP = 46; /** > */ -export declare const GREATER_THAN_SIGN: number; +export declare const GREATER_THAN_SIGN = 62; /** - */ -export declare const HYPHEN_MINUS: number; +export declare const HYPHEN_MINUS = 45; /** \x1F */ -export declare const INFORMATION_SEPARATOR_ONE: number; +export declare const INFORMATION_SEPARATOR_ONE = 31; /** E */ -export declare const LATIN_CAPITAL_LETTER_E: number; +export declare const LATIN_CAPITAL_LETTER_E = 69; /** e */ -export declare const LATIN_SMALL_LETTER_E: number; +export declare const LATIN_SMALL_LETTER_E = 101; /** { */ -export declare const LEFT_CURLY_BRACKET: number; +export declare const LEFT_CURLY_BRACKET = 123; /** ( */ -export declare const LEFT_PARENTHESIS: number; +export declare const LEFT_PARENTHESIS = 40; /** [ */ -export declare const LEFT_SQUARE_BRACKET: number; +export declare const LEFT_SQUARE_BRACKET = 91; /** < */ -export declare const LESS_THAN_SIGN: number; +export declare const LESS_THAN_SIGN = 60; /** \n */ -export declare const LINE_FEED: number; +export declare const LINE_FEED = 10; /** \v */ -export declare const LINE_TABULATION: number; +export declare const LINE_TABULATION = 11; /** _ */ -export declare const LOW_LINE: number; +export declare const LOW_LINE = 95; /** \x10FFFF */ -export declare const MAXIMUM_ALLOWED_CODEPOINT: number; +export declare const MAXIMUM_ALLOWED_CODEPOINT = 1114111; /** \x00 */ -export declare const NULL: number; +export declare const NULL = 0; /** # */ -export declare const NUMBER_SIGN: number; +export declare const NUMBER_SIGN = 35; /** % */ -export declare const PERCENTAGE_SIGN: number; +export declare const PERCENTAGE_SIGN = 37; /** + */ -export declare const PLUS_SIGN: number; +export declare const PLUS_SIGN = 43; /** " */ -export declare const QUOTATION_MARK: number; +export declare const QUOTATION_MARK = 34; /** � */ -export declare const REPLACEMENT_CHARACTER: number; +export declare const REPLACEMENT_CHARACTER = 65533; /** \ */ -export declare const REVERSE_SOLIDUS: number; +export declare const REVERSE_SOLIDUS = 92; /** } */ -export declare const RIGHT_CURLY_BRACKET: number; +export declare const RIGHT_CURLY_BRACKET = 125; /** ) */ -export declare const RIGHT_PARENTHESIS: number; +export declare const RIGHT_PARENTHESIS = 41; /** ] */ -export declare const RIGHT_SQUARE_BRACKET: number; +export declare const RIGHT_SQUARE_BRACKET = 93; /** ; */ -export declare const SEMICOLON: number; +export declare const SEMICOLON = 59; /** \u0E */ -export declare const SHIFT_OUT: number; +export declare const SHIFT_OUT = 14; /** / */ -export declare const SOLIDUS: number; +export declare const SOLIDUS = 47; /** \u20 */ -export declare const SPACE: number; +export declare const SPACE = 32; diff --git a/packages/css-tokenizer/dist/index.cjs b/packages/css-tokenizer/dist/index.cjs index 0b59d5468..dd78dc610 100644 --- a/packages/css-tokenizer/dist/index.cjs +++ b/packages/css-tokenizer/dist/index.cjs @@ -1 +1 @@ -"use strict";class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===g)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case x:case s:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case x:case s:case S:case c:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,o){return o.codePointSource[o.cursor]===N&&o.codePointSource[o.cursor+1]!==x}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.codePointSource[o.cursor]===l?o.codePointSource[o.cursor+1]===l||(!!isIdentStartCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===N&&o.codePointSource[o.cursor+2]!==x):!!isIdentStartCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)}function checkIfThreeCodePointsWouldStartANumber(e,o){return o.codePointSource[o.cursor]===w||o.codePointSource[o.cursor]===l?!!isDigitCodePoint(o.codePointSource[o.cursor+1])||o.codePointSource[o.cursor+1]===P&&isDigitCodePoint(o.codePointSource[o.cursor+2]):o.codePointSource[o.cursor]===P?isDigitCodePoint(o.codePointSource[o.cursor+1]):!!isDigitCodePoint(o.codePointSource[o.cursor])}function checkIfTwoCodePointsStartAComment(e,o){return o.codePointSource[o.cursor]===B&&o.codePointSource[o.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,o){return o.codePointSource[o.cursor]===l&&o.codePointSource[o.cursor+1]===l&&o.codePointSource[o.cursor+2]===h}function consumeComment(e,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(!1===t){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(t===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[exports.TokenType.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,o){const t=o.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:o.representationStart,end:o.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==o.codePointSource[o.cursor]&&isHexDigitCodePoint(o.codePointSource[o.cursor])&&e.length<6;)e.push(o.codePointSource[o.cursor]),o.advanceCodePoint();isWhitespace(o.codePointSource[o.cursor])&&o.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:G<=(r=n)&&r<=X||n>I?b:n}var r;return t}function consumeIdentSequence(e,o){const t=[];for(;;)if(isIdentCodePoint(o.codePointSource[o.cursor]))t.push(o.codePointSource[o.cursor]),o.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,o))return t;o.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,o))}}function consumeHashToken(e,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=t.ID);const n=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n),type:r}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let t=exports.NumberType.Integer;for(o.codePointSource[o.cursor]!==w&&o.codePointSource[o.cursor]!==l||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===k||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===l||o.codePointSource[o.cursor+1]===w)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),t]}function consumeNumericToken(e,o){const t=consumeNumber(0,o);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:t[0],type:t[1],unit:String.fromCharCode(...r)}]}return o.codePointSource[o.cursor]===D?(o.advanceCodePoint(),[exports.TokenType.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0]}]):[exports.TokenType.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0],type:t[1]}]}function consumeWhiteSpace(e,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[exports.TokenType.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(e,o){let t="";const r=o.readCodePoint();for(;;){const n=o.readCodePoint();if(!1===n)return e.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isNewLine(n))return e.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[exports.TokenType.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(n===r)return[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(n!==N)t+=String.fromCharCode(n);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}t+=String.fromCharCode(consumeEscapedCodePoint(e,o))}}}const Y="u".charCodeAt(0),ee="U".charCodeAt(0),oe="r".charCodeAt(0),te="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,o){return 3===o.length&&((o[0]===Y||o[0]===ee)&&((o[1]===oe||o[1]===te)&&(o[2]===re||o[2]===ne)))}function consumeBadURL(e,o){for(;;){if(void 0===o.codePointSource[o.cursor])return;if(o.codePointSource[o.cursor]===W)return void o.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,o)?(o.advanceCodePoint(),consumeEscapedCodePoint(e,o)):o.advanceCodePoint()}}function consumeUrlToken(e,o){consumeWhiteSpace(0,o);let t="";for(;;){if(void 0===o.codePointSource[o.cursor])return e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(o.codePointSource[o.cursor]===W)return o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):o.codePointSource[o.cursor]===W?(o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):(consumeBadURL(e,o),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===L||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===E||((n=o.codePointSource[o.cursor])===y||n===p||U<=n&&n<=i||V<=n&&n<=T))return consumeBadURL(e,o),e.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){t+=String.fromCharCode(consumeEscapedCodePoint(e,o));continue}return consumeBadURL(e,o),e.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}t+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var n}function consumeIdentLikeToken(e,o){const t=consumeIdentSequence(e,o);if(o.codePointSource[o.cursor]!==E)return[exports.TokenType.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];if(checkIfCodePointsMatchURLIdent(0,t)){o.advanceCodePoint();let n=0;for(;;){const e=isWhitespace(o.codePointSource[o.cursor]),i=isWhitespace(o.codePointSource[o.cursor+1]);if(e&&i){n+=2,o.advanceCodePoint(2);continue}const s=e?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(s===L||s===r)return n>0&&o.advanceCodePoint(n),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];break}return n>0&&o.advanceCodePoint(n),consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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){let t="";const r=new Array(o.length);for(let e=0;e{})};return{nextToken:function nextToken(){if(n.representationStart=n.cursor,n.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,n)){if(null!=o&&o.commentsAreTokens)return consumeComment(i,n);consumeComment(i,n),n.representationStart=n.cursor,n.representationEnd=-1}const e=n.codePointSource[n.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,n);if(isDigitCodePoint(e))return consumeNumericToken(i,n);switch(e){case d:return n.advanceCodePoint(),[exports.TokenType.Comma,",",n.representationStart,n.representationEnd,void 0];case a:return n.advanceCodePoint(),[exports.TokenType.Colon,":",n.representationStart,n.representationEnd,void 0];case q:return n.advanceCodePoint(),[exports.TokenType.Semicolon,";",n.representationStart,n.representationEnd,void 0];case E:return n.advanceCodePoint(),[exports.TokenType.OpenParen,"(",n.representationStart,n.representationEnd,void 0];case W:return n.advanceCodePoint(),[exports.TokenType.CloseParen,")",n.representationStart,n.representationEnd,void 0];case v:return n.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",n.representationStart,n.representationEnd,void 0];case F:return n.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",n.representationStart,n.representationEnd,void 0];case f:return n.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",n.representationStart,n.representationEnd,void 0];case R:return n.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",n.representationStart,n.representationEnd,void 0];case r:case L:return consumeStringToken(i,n);case O:return consumeHashToken(i,n);case w:case P:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):(n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]);case x:case s:case S:case c:case H:return consumeWhiteSpace(0,n);case l:return checkIfThreeCodePointsWouldStartANumber(0,n)?consumeNumericToken(i,n):checkIfThreeCodePointsWouldStartCDC(0,n)?(n.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",n.representationStart,n.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)?consumeIdentLikeToken(i,n):(n.advanceCodePoint(),[exports.TokenType.Delim,"-",n.representationStart,n.representationEnd,{value:"-"}]);case A:return checkIfFourCodePointsWouldStartCDO(0,n)?(n.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",n.representationStart,n.representationEnd,void 0]):(n.advanceCodePoint(),[exports.TokenType.Delim,"<",n.representationStart,n.representationEnd,{value:"<"}]);case u:if(n.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,n)){const e=consumeIdentSequence(i,n);return[exports.TokenType.AtKeyword,n.source.slice(n.representationStart,n.representationEnd+1),n.representationStart,n.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,"@",n.representationStart,n.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,n)?consumeIdentLikeToken(i,n):(n.advanceCodePoint(),i.onParseError({message:'Invalid escape sequence after "\\"',start:n.representationStart,end:n.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,"\\",n.representationStart,n.representationEnd,{value:"\\"}])}return n.advanceCodePoint(),[exports.TokenType.Delim,n.source[n.representationStart],n.representationStart,n.representationEnd,{value:n.source[n.representationStart]}]},endOfFile:function endOfFile(){return void 0===n.codePointSource[n.cursor]}}}; +"use strict";class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=48&&e<=57}function isUppercaseLetterCodePoint(e){return e>=65&&e<=90}function isLowercaseLetterCodePoint(e){return e>=97&&e<=122}function isHexDigitCodePoint(e){return isDigitCodePoint(e)||e>=97&&e<=102||e>=65&&e<=70}function isLetterCodePoint(e){return isLowercaseLetterCodePoint(e)||isUppercaseLetterCodePoint(e)}function isNonASCIICodePoint(e){return e>=128}function isIdentStartCodePoint(e){return isLetterCodePoint(e)||isNonASCIICodePoint(e)||95===e}function isIdentCodePoint(e){return isIdentStartCodePoint(e)||isDigitCodePoint(e)||e===n}function isNewLine(e){return 10===e||13===e||12===e}function isWhitespace(e){return 32===e||10===e||9===e||13===e||12===e}function checkIfTwoCodePointsAreAValidEscape(e,o){return 92===o.codePointSource[o.cursor]&&10!==o.codePointSource[o.cursor+1]}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,o){return o.codePointSource[o.cursor]===n?o.codePointSource[o.cursor+1]===n||(!!isIdentStartCodePoint(o.codePointSource[o.cursor+1])||92===o.codePointSource[o.cursor+1]&&10!==o.codePointSource[o.cursor+2]):!!isIdentStartCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)}function checkIfThreeCodePointsWouldStartANumber(e,o){return 43===o.codePointSource[o.cursor]||o.codePointSource[o.cursor]===n?!!isDigitCodePoint(o.codePointSource[o.cursor+1])||46===o.codePointSource[o.cursor+1]&&isDigitCodePoint(o.codePointSource[o.cursor+2]):46===o.codePointSource[o.cursor]?isDigitCodePoint(o.codePointSource[o.cursor+1]):!!isDigitCodePoint(o.codePointSource[o.cursor])}function checkIfTwoCodePointsStartAComment(e,o){return 47===o.codePointSource[o.cursor]&&42===o.codePointSource[o.cursor+1]}function checkIfThreeCodePointsWouldStartCDC(e,o){return o.codePointSource[o.cursor]===n&&o.codePointSource[o.cursor+1]===n&&62===o.codePointSource[o.cursor+2]}function consumeComment(e,o){for(o.advanceCodePoint(2);;){const t=o.readCodePoint();if(!1===t){e.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(42===t&&(void 0!==o.codePointSource[o.cursor]&&47===o.codePointSource[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(e,o){const t=o.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:o.representationStart,end:o.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),r;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==o.codePointSource[o.cursor]&&isHexDigitCodePoint(o.codePointSource[o.cursor])&&e.length<6;)e.push(o.codePointSource[o.cursor]),o.advanceCodePoint();isWhitespace(o.codePointSource[o.cursor])&&o.advanceCodePoint();const i=parseInt(String.fromCharCode(...e),16);return 0===i?r:(n=i)>=55296&&n<=57343||i>1114111?r:i}var n;return t}function consumeIdentSequence(e,o){const t=[];for(;;)if(isIdentCodePoint(o.codePointSource[o.cursor]))t.push(o.codePointSource[o.cursor]),o.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,o))return t;o.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,o))}}function consumeHashToken(e,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let n=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(n=t.ID);const r=consumeIdentSequence(e,o);return[exports.TokenType.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...r),type:n}]}return[exports.TokenType.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,o){let t=exports.NumberType.Integer;for(43!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]!==n||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(46===o.codePointSource[o.cursor]&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((101===o.codePointSource[o.cursor]||69===o.codePointSource[o.cursor])&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((101===o.codePointSource[o.cursor]||69===o.codePointSource[o.cursor])&&(o.codePointSource[o.cursor+1]===n||43===o.codePointSource[o.cursor+1])&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),t=exports.NumberType.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),t]}function consumeNumericToken(e,o){const t=consumeNumber(0,o);if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const n=consumeIdentSequence(e,o);return[exports.TokenType.Dimension,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0],type:t[1],unit:String.fromCharCode(...n)}]}return 37===o.codePointSource[o.cursor]?(o.advanceCodePoint(),[exports.TokenType.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0]}]):[exports.TokenType.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t[0],type:t[1]}]}function consumeWhiteSpace(e,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[exports.TokenType.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(e,o){let t="";const n=o.readCodePoint();for(;;){const r=o.readCodePoint();if(!1===r)return e.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(isNewLine(r))return e.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[exports.TokenType.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(r===n)return[exports.TokenType.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(92!==r)t+=String.fromCharCode(r);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}t+=String.fromCharCode(consumeEscapedCodePoint(e,o))}}}const i="u".charCodeAt(0),s="U".charCodeAt(0),c="r".charCodeAt(0),a="R".charCodeAt(0),u="l".charCodeAt(0),d="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,o){return 3===o.length&&((o[0]===i||o[0]===s)&&((o[1]===c||o[1]===a)&&(o[2]===u||o[2]===d)))}function consumeBadURL(e,o){for(;;){if(void 0===o.codePointSource[o.cursor])return;if(41===o.codePointSource[o.cursor])return void o.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,o)?(o.advanceCodePoint(),consumeEscapedCodePoint(e,o)):o.advanceCodePoint()}}function consumeUrlToken(e,o){consumeWhiteSpace(0,o);let t="";for(;;){if(void 0===o.codePointSource[o.cursor])return e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}];if(41===o.codePointSource[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.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(e.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):41===o.codePointSource[o.cursor]?(o.advanceCodePoint(),[exports.TokenType.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:t}]):(consumeBadURL(e,o),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(34===o.codePointSource[o.cursor]||39===o.codePointSource[o.cursor]||40===o.codePointSource[o.cursor]||(11===(n=o.codePointSource[o.cursor])||127===n||0<=n&&n<=8||14<=n&&n<=31))return consumeBadURL(e,o),e.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(92===o.codePointSource[o.cursor]){if(checkIfTwoCodePointsAreAValidEscape(0,o)){t+=String.fromCharCode(consumeEscapedCodePoint(e,o));continue}return consumeBadURL(e,o),e.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}t+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var n}function consumeIdentLikeToken(e,o){const t=consumeIdentSequence(e,o);if(40!==o.codePointSource[o.cursor])return[exports.TokenType.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];if(checkIfCodePointsMatchURLIdent(0,t)){o.advanceCodePoint();let n=0;for(;;){const e=isWhitespace(o.codePointSource[o.cursor]),r=isWhitespace(o.codePointSource[o.cursor+1]);if(e&&r){n+=1,o.advanceCodePoint(1);continue}const i=e?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(34===i||39===i)return[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}];break}return n>0&&o.advanceCodePoint(n),consumeUrlToken(e,o)}return o.advanceCodePoint(),[exports.TokenType.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...t)}]}exports.Reader=Reader,exports.cloneTokens=function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))},exports.isToken=function isToken(e){return!!Array.isArray(e)&&(!(e.length<4)&&(e[0]in exports.TokenType&&("string"==typeof e[1]&&("number"==typeof e[2]&&"number"==typeof e[3]))))},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){let t="";const r=new Array(o.length);for(let e=0;e{})};return{nextToken:function nextToken(){if(r.representationStart=r.cursor,r.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,r)){if(null!=o&&o.commentsAreTokens)return consumeComment(i,r);consumeComment(i,r),r.representationStart=r.cursor,r.representationEnd=-1}const e=r.codePointSource[r.cursor];if(void 0===e)return[exports.TokenType.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(e))return consumeIdentLikeToken(i,r);if(isDigitCodePoint(e))return consumeNumericToken(i,r);switch(e){case 44:return r.advanceCodePoint(),[exports.TokenType.Comma,",",r.representationStart,r.representationEnd,void 0];case 58:return r.advanceCodePoint(),[exports.TokenType.Colon,":",r.representationStart,r.representationEnd,void 0];case 59:return r.advanceCodePoint(),[exports.TokenType.Semicolon,";",r.representationStart,r.representationEnd,void 0];case 40:return r.advanceCodePoint(),[exports.TokenType.OpenParen,"(",r.representationStart,r.representationEnd,void 0];case 41:return r.advanceCodePoint(),[exports.TokenType.CloseParen,")",r.representationStart,r.representationEnd,void 0];case 91:return r.advanceCodePoint(),[exports.TokenType.OpenSquare,"[",r.representationStart,r.representationEnd,void 0];case 93:return r.advanceCodePoint(),[exports.TokenType.CloseSquare,"]",r.representationStart,r.representationEnd,void 0];case 123:return r.advanceCodePoint(),[exports.TokenType.OpenCurly,"{",r.representationStart,r.representationEnd,void 0];case 125:return r.advanceCodePoint(),[exports.TokenType.CloseCurly,"}",r.representationStart,r.representationEnd,void 0];case 39:case 34:return consumeStringToken(i,r);case 35:return consumeHashToken(i,r);case 43:case 46:return checkIfThreeCodePointsWouldStartANumber(0,r)?consumeNumericToken(i,r):(r.advanceCodePoint(),[exports.TokenType.Delim,r.source[r.representationStart],r.representationStart,r.representationEnd,{value:r.source[r.representationStart]}]);case 10:case 13:case 12:case 9:case 32:return consumeWhiteSpace(0,r);case n:return checkIfThreeCodePointsWouldStartANumber(0,r)?consumeNumericToken(i,r):checkIfThreeCodePointsWouldStartCDC(0,r)?(r.advanceCodePoint(3),[exports.TokenType.CDC,"--\x3e",r.representationStart,r.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)?consumeIdentLikeToken(i,r):(r.advanceCodePoint(),[exports.TokenType.Delim,"-",r.representationStart,r.representationEnd,{value:"-"}]);case 60:return checkIfFourCodePointsWouldStartCDO(0,r)?(r.advanceCodePoint(4),[exports.TokenType.CDO,"\x3c!--",r.representationStart,r.representationEnd,void 0]):(r.advanceCodePoint(),[exports.TokenType.Delim,"<",r.representationStart,r.representationEnd,{value:"<"}]);case 64:if(r.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)){const e=consumeIdentSequence(i,r);return[exports.TokenType.AtKeyword,r.source.slice(r.representationStart,r.representationEnd+1),r.representationStart,r.representationEnd,{value:String.fromCharCode(...e)}]}return[exports.TokenType.Delim,"@",r.representationStart,r.representationEnd,{value:"@"}];case 92:return checkIfTwoCodePointsAreAValidEscape(0,r)?consumeIdentLikeToken(i,r):(r.advanceCodePoint(),i.onParseError({message:'Invalid escape sequence after "\\"',start:r.representationStart,end:r.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[exports.TokenType.Delim,"\\",r.representationStart,r.representationEnd,{value:"\\"}])}return r.advanceCodePoint(),[exports.TokenType.Delim,r.source[r.representationStart],r.representationStart,r.representationEnd,{value:r.source[r.representationStart]}]},endOfFile:function endOfFile(){return void 0===r.codePointSource[r.cursor]}}}; diff --git a/packages/css-tokenizer/dist/index.mjs b/packages/css-tokenizer/dist/index.mjs index babf8503a..7575e15c2 100644 --- a/packages/css-tokenizer/dist/index.mjs +++ b/packages/css-tokenizer/dist/index.mjs @@ -1 +1 @@ -class Reader{cursor;source="";codePointSource=[];length=0;representationStart=0;representationEnd=-1;constructor(e){this.cursor=0,this.source=e,this.length=e.length,this.codePointSource=new Array(this.length);for(let e=0;e=j}function isIdentStartCodePoint(e){return!!isLetterCodePoint(e)||(!!isNonASCIICodePoint(e)||e===U)}function isIdentCodePoint(e){return!!isIdentStartCodePoint(e)||(!!isDigitCodePoint(e)||e===l)}function isNewLine(e){switch(e){case I:case c:case S:return!0;default:return!1}}function isWhitespace(e){switch(e){case I:case c:case S:case a:case H:return!0;default:return!1}}const G="\ud800".charCodeAt(0),X="\udfff".charCodeAt(0);function checkIfTwoCodePointsAreAValidEscape(e,t){return t.codePointSource[t.cursor]===N&&t.codePointSource[t.cursor+1]!==I}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,t){return t.codePointSource[t.cursor]===l?t.codePointSource[t.cursor+1]===l||(!!isIdentStartCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===N&&t.codePointSource[t.cursor+2]!==I):!!isIdentStartCodePoint(t.codePointSource[t.cursor])||checkIfTwoCodePointsAreAValidEscape(0,t)}function checkIfThreeCodePointsWouldStartANumber(e,t){return t.codePointSource[t.cursor]===y||t.codePointSource[t.cursor]===l?!!isDigitCodePoint(t.codePointSource[t.cursor+1])||t.codePointSource[t.cursor+1]===P&&isDigitCodePoint(t.codePointSource[t.cursor+2]):t.codePointSource[t.cursor]===P?isDigitCodePoint(t.codePointSource[t.cursor+1]):!!isDigitCodePoint(t.codePointSource[t.cursor])}function checkIfTwoCodePointsStartAComment(e,t){return t.codePointSource[t.cursor]===B&&t.codePointSource[t.cursor+1]===n}function checkIfThreeCodePointsWouldStartCDC(e,t){return t.codePointSource[t.cursor]===l&&t.codePointSource[t.cursor+1]===l&&t.codePointSource[t.cursor+2]===h}function consumeComment(t,o){for(o.advanceCodePoint(2);;){const e=o.readCodePoint();if(!1===e){t.onParseError({message:"Unexpected EOF while consuming a comment.",start:o.representationStart,end:o.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(e===n&&(void 0!==o.codePointSource[o.cursor]&&o.codePointSource[o.cursor]===B)){o.advanceCodePoint();break}}return[e.Comment,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeEscapedCodePoint(e,t){const o=t.readCodePoint();if(!1===o)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:t.representationStart,end:t.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),b;if(isHexDigitCodePoint(o)){const e=[o];for(;void 0!==t.codePointSource[t.cursor]&&isHexDigitCodePoint(t.codePointSource[t.cursor])&&e.length<6;)e.push(t.codePointSource[t.cursor]),t.advanceCodePoint();isWhitespace(t.codePointSource[t.cursor])&&t.advanceCodePoint();const n=parseInt(String.fromCharCode(...e),16);return 0===n?b:G<=(r=n)&&r<=X||n>O?b:n}var r;return o}function consumeIdentSequence(e,t){const o=[];for(;;)if(isIdentCodePoint(t.codePointSource[t.cursor]))o.push(t.codePointSource[t.cursor]),t.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,t))return o;t.advanceCodePoint(),o.push(consumeEscapedCodePoint(e,t))}}function consumeHashToken(t,r){if(r.advanceCodePoint(),void 0!==r.codePointSource[r.cursor]&&isIdentCodePoint(r.codePointSource[r.cursor])||checkIfTwoCodePointsAreAValidEscape(0,r)){let n=o.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,r)&&(n=o.ID);const i=consumeIdentSequence(t,r);return[e.Hash,r.source.slice(r.representationStart,r.representationEnd+1),r.representationStart,r.representationEnd,{value:String.fromCharCode(...i),type:n}]}return[e.Delim,"#",r.representationStart,r.representationEnd,{value:"#"}]}function consumeNumber(e,o){let r=t.Integer;for(o.codePointSource[o.cursor]!==y&&o.codePointSource[o.cursor]!==l||o.advanceCodePoint();isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if(o.codePointSource[o.cursor]===P&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&isDigitCodePoint(o.codePointSource[o.cursor+1]))for(o.advanceCodePoint(2),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();if((o.codePointSource[o.cursor]===E||o.codePointSource[o.cursor]===m)&&(o.codePointSource[o.cursor+1]===l||o.codePointSource[o.cursor+1]===y)&&isDigitCodePoint(o.codePointSource[o.cursor+2]))for(o.advanceCodePoint(3),r=t.Number;isDigitCodePoint(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[parseFloat(o.source.slice(o.representationStart,o.representationEnd+1)),r]}function consumeNumericToken(t,o){const r=consumeNumber(0,o);if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)){const n=consumeIdentSequence(t,o);return[e.Dimension,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1],unit:String.fromCharCode(...n)}]}return o.codePointSource[o.cursor]===L?(o.advanceCodePoint(),[e.Percentage,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0]}]):[e.Number,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r[0],type:r[1]}]}function consumeWhiteSpace(t,o){for(;isWhitespace(o.codePointSource[o.cursor]);)o.advanceCodePoint();return[e.Whitespace,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}function consumeStringToken(t,o){let r="";const n=o.readCodePoint();for(;;){const i=o.readCodePoint();if(!1===i)return t.onParseError({message:"Unexpected EOF while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(isNewLine(i))return t.onParseError({message:"Unexpected newline while consuming a string token.",start:o.representationStart,end:o.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),o.unreadCodePoint(),[e.BadString,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(i===n)return[e.String,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:r}];if(i!==N)r+=String.fromCharCode(i);else{if(void 0===o.codePointSource[o.cursor])continue;if(isNewLine(o.codePointSource[o.cursor])){o.advanceCodePoint();continue}r+=String.fromCharCode(consumeEscapedCodePoint(t,o))}}}const Y="u".charCodeAt(0),ee="U".charCodeAt(0),te="r".charCodeAt(0),oe="R".charCodeAt(0),re="l".charCodeAt(0),ne="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,t){return 3===t.length&&((t[0]===Y||t[0]===ee)&&((t[1]===te||t[1]===oe)&&(t[2]===re||t[2]===ne)))}function consumeBadURL(e,t){for(;;){if(void 0===t.codePointSource[t.cursor])return;if(t.codePointSource[t.cursor]===F)return void t.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,t)?(t.advanceCodePoint(),consumeEscapedCodePoint(e,t)):t.advanceCodePoint()}}function consumeUrlToken(t,o){consumeWhiteSpace(0,o);let n="";for(;;){if(void 0===o.codePointSource[o.cursor])return t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(o.codePointSource[o.cursor]===F)return o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}];if(isWhitespace(o.codePointSource[o.cursor]))return consumeWhiteSpace(0,o),void 0===o.codePointSource[o.cursor]?(t.onParseError({message:"Unexpected EOF while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):o.codePointSource[o.cursor]===F?(o.advanceCodePoint(),[e.URL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:n}]):(consumeBadURL(t,o),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]);if(o.codePointSource[o.cursor]===R||o.codePointSource[o.cursor]===r||o.codePointSource[o.cursor]===A||((c=o.codePointSource[o.cursor])===T||c===C||D<=c&&c<=i||V<=c&&c<=f))return consumeBadURL(t,o),t.onParseError({message:"Unexpected character while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0];if(o.codePointSource[o.cursor]===N){if(checkIfTwoCodePointsAreAValidEscape(0,o)){n+=String.fromCharCode(consumeEscapedCodePoint(t,o));continue}return consumeBadURL(t,o),t.onParseError({message:"Invalid escape sequence while consuming a url token.",start:o.representationStart,end:o.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.BadURL,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,void 0]}n+=String.fromCharCode(o.codePointSource[o.cursor]),o.advanceCodePoint()}var c}function consumeIdentLikeToken(t,o){const n=consumeIdentSequence(t,o);if(o.codePointSource[o.cursor]!==A)return[e.Ident,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];if(checkIfCodePointsMatchURLIdent(0,n)){o.advanceCodePoint();let i=0;for(;;){const t=isWhitespace(o.codePointSource[o.cursor]),c=isWhitespace(o.codePointSource[o.cursor+1]);if(t&&c){i+=2,o.advanceCodePoint(2);continue}const a=t?o.codePointSource[o.cursor+1]:o.codePointSource[o.cursor];if(a===R||a===r)return i>0&&o.advanceCodePoint(i),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}];break}return i>0&&o.advanceCodePoint(i),consumeUrlToken(t,o)}return o.advanceCodePoint(),[e.Function,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...n)}]}function tokenizer(t,o){const n=t.css.valueOf(),i=new Reader(n),C={onParseError:(null==o?void 0:o.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.representationStart=i.cursor,i.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,i)){if(null!=o&&o.commentsAreTokens)return consumeComment(C,i);consumeComment(C,i),i.representationStart=i.cursor,i.representationEnd=-1}const t=i.codePointSource[i.cursor];if(void 0===t)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(t))return consumeIdentLikeToken(C,i);if(isDigitCodePoint(t))return consumeNumericToken(C,i);switch(t){case d:return i.advanceCodePoint(),[e.Comma,",",i.representationStart,i.representationEnd,void 0];case s:return i.advanceCodePoint(),[e.Colon,":",i.representationStart,i.representationEnd,void 0];case x:return i.advanceCodePoint(),[e.Semicolon,";",i.representationStart,i.representationEnd,void 0];case A:return i.advanceCodePoint(),[e.OpenParen,"(",i.representationStart,i.representationEnd,void 0];case F:return i.advanceCodePoint(),[e.CloseParen,")",i.representationStart,i.representationEnd,void 0];case k:return i.advanceCodePoint(),[e.OpenSquare,"[",i.representationStart,i.representationEnd,void 0];case q:return i.advanceCodePoint(),[e.CloseSquare,"]",i.representationStart,i.representationEnd,void 0];case v:return i.advanceCodePoint(),[e.OpenCurly,"{",i.representationStart,i.representationEnd,void 0];case W:return i.advanceCodePoint(),[e.CloseCurly,"}",i.representationStart,i.representationEnd,void 0];case r:case R:return consumeStringToken(C,i);case w:return consumeHashToken(C,i);case y:case P:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):(i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]);case I:case c:case S:case a:case H:return consumeWhiteSpace(0,i);case l:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(C,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.advanceCodePoint(3),[e.CDC,"--\x3e",i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),[e.Delim,"-",i.representationStart,i.representationEnd,{value:"-"}]);case g:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.advanceCodePoint(4),[e.CDO,"\x3c!--",i.representationStart,i.representationEnd,void 0]):(i.advanceCodePoint(),[e.Delim,"<",i.representationStart,i.representationEnd,{value:"<"}]);case u:if(i.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const t=consumeIdentSequence(C,i);return[e.AtKeyword,i.source.slice(i.representationStart,i.representationEnd+1),i.representationStart,i.representationEnd,{value:String.fromCharCode(...t)}]}return[e.Delim,"@",i.representationStart,i.representationEnd,{value:"@"}];case N:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(C,i):(i.advanceCodePoint(),C.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,"\\",i.representationStart,i.representationEnd,{value:"\\"}])}return i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}function mutateIdent(e,t){let o="";const r=new Array(t.length);for(let e=0;e=48&&e<=57}function isUppercaseLetterCodePoint(e){return e>=65&&e<=90}function isLowercaseLetterCodePoint(e){return e>=97&&e<=122}function isHexDigitCodePoint(e){return isDigitCodePoint(e)||e>=97&&e<=102||e>=65&&e<=70}function isLetterCodePoint(e){return isLowercaseLetterCodePoint(e)||isUppercaseLetterCodePoint(e)}function isNonASCIICodePoint(e){return e>=128}function isIdentStartCodePoint(e){return isLetterCodePoint(e)||isNonASCIICodePoint(e)||95===e}function isIdentCodePoint(e){return isIdentStartCodePoint(e)||isDigitCodePoint(e)||e===o}function isNewLine(e){return 10===e||13===e||12===e}function isWhitespace(e){return 32===e||10===e||9===e||13===e||12===e}function checkIfTwoCodePointsAreAValidEscape(e,n){return 92===n.codePointSource[n.cursor]&&10!==n.codePointSource[n.cursor+1]}function checkIfThreeCodePointsWouldStartAnIdentSequence(e,n){return n.codePointSource[n.cursor]===o?n.codePointSource[n.cursor+1]===o||(!!isIdentStartCodePoint(n.codePointSource[n.cursor+1])||92===n.codePointSource[n.cursor+1]&&10!==n.codePointSource[n.cursor+2]):!!isIdentStartCodePoint(n.codePointSource[n.cursor])||checkIfTwoCodePointsAreAValidEscape(0,n)}function checkIfThreeCodePointsWouldStartANumber(e,n){return 43===n.codePointSource[n.cursor]||n.codePointSource[n.cursor]===o?!!isDigitCodePoint(n.codePointSource[n.cursor+1])||46===n.codePointSource[n.cursor+1]&&isDigitCodePoint(n.codePointSource[n.cursor+2]):46===n.codePointSource[n.cursor]?isDigitCodePoint(n.codePointSource[n.cursor+1]):!!isDigitCodePoint(n.codePointSource[n.cursor])}function checkIfTwoCodePointsStartAComment(e,n){return 47===n.codePointSource[n.cursor]&&42===n.codePointSource[n.cursor+1]}function checkIfThreeCodePointsWouldStartCDC(e,n){return n.codePointSource[n.cursor]===o&&n.codePointSource[n.cursor+1]===o&&62===n.codePointSource[n.cursor+2]}function consumeComment(n,t){for(t.advanceCodePoint(2);;){const e=t.readCodePoint();if(!1===e){n.onParseError({message:"Unexpected EOF while consuming a comment.",start:t.representationStart,end:t.representationEnd,state:["4.3.2. Consume comments","Unexpected EOF"]});break}if(42===e&&(void 0!==t.codePointSource[t.cursor]&&47===t.codePointSource[t.cursor])){t.advanceCodePoint();break}}return[e.Comment,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0]}function consumeEscapedCodePoint(e,n){const t=n.readCodePoint();if(!1===t)return e.onParseError({message:"Unexpected EOF while consuming an escaped code point.",start:n.representationStart,end:n.representationEnd,state:["4.3.7. Consume an escaped code point","Unexpected EOF"]}),r;if(isHexDigitCodePoint(t)){const e=[t];for(;void 0!==n.codePointSource[n.cursor]&&isHexDigitCodePoint(n.codePointSource[n.cursor])&&e.length<6;)e.push(n.codePointSource[n.cursor]),n.advanceCodePoint();isWhitespace(n.codePointSource[n.cursor])&&n.advanceCodePoint();const i=parseInt(String.fromCharCode(...e),16);return 0===i?r:(o=i)>=55296&&o<=57343||i>1114111?r:i}var o;return t}function consumeIdentSequence(e,n){const t=[];for(;;)if(isIdentCodePoint(n.codePointSource[n.cursor]))t.push(n.codePointSource[n.cursor]),n.advanceCodePoint();else{if(!checkIfTwoCodePointsAreAValidEscape(0,n))return t;n.advanceCodePoint(),t.push(consumeEscapedCodePoint(e,n))}}function consumeHashToken(n,o){if(o.advanceCodePoint(),void 0!==o.codePointSource[o.cursor]&&isIdentCodePoint(o.codePointSource[o.cursor])||checkIfTwoCodePointsAreAValidEscape(0,o)){let r=t.Unrestricted;checkIfThreeCodePointsWouldStartAnIdentSequence(0,o)&&(r=t.ID);const i=consumeIdentSequence(n,o);return[e.Hash,o.source.slice(o.representationStart,o.representationEnd+1),o.representationStart,o.representationEnd,{value:String.fromCharCode(...i),type:r}]}return[e.Delim,"#",o.representationStart,o.representationEnd,{value:"#"}]}function consumeNumber(e,t){let r=n.Integer;for(43!==t.codePointSource[t.cursor]&&t.codePointSource[t.cursor]!==o||t.advanceCodePoint();isDigitCodePoint(t.codePointSource[t.cursor]);)t.advanceCodePoint();if(46===t.codePointSource[t.cursor]&&isDigitCodePoint(t.codePointSource[t.cursor+1]))for(t.advanceCodePoint(2),r=n.Number;isDigitCodePoint(t.codePointSource[t.cursor]);)t.advanceCodePoint();if((101===t.codePointSource[t.cursor]||69===t.codePointSource[t.cursor])&&isDigitCodePoint(t.codePointSource[t.cursor+1]))for(t.advanceCodePoint(2),r=n.Number;isDigitCodePoint(t.codePointSource[t.cursor]);)t.advanceCodePoint();if((101===t.codePointSource[t.cursor]||69===t.codePointSource[t.cursor])&&(t.codePointSource[t.cursor+1]===o||43===t.codePointSource[t.cursor+1])&&isDigitCodePoint(t.codePointSource[t.cursor+2]))for(t.advanceCodePoint(3),r=n.Number;isDigitCodePoint(t.codePointSource[t.cursor]);)t.advanceCodePoint();return[parseFloat(t.source.slice(t.representationStart,t.representationEnd+1)),r]}function consumeNumericToken(n,t){const o=consumeNumber(0,t);if(checkIfThreeCodePointsWouldStartAnIdentSequence(0,t)){const r=consumeIdentSequence(n,t);return[e.Dimension,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o[0],type:o[1],unit:String.fromCharCode(...r)}]}return 37===t.codePointSource[t.cursor]?(t.advanceCodePoint(),[e.Percentage,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o[0]}]):[e.Number,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o[0],type:o[1]}]}function consumeWhiteSpace(n,t){for(;isWhitespace(t.codePointSource[t.cursor]);)t.advanceCodePoint();return[e.Whitespace,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0]}function consumeStringToken(n,t){let o="";const r=t.readCodePoint();for(;;){const i=t.readCodePoint();if(!1===i)return n.onParseError({message:"Unexpected EOF while consuming a string token.",start:t.representationStart,end:t.representationEnd,state:["4.3.5. Consume a string token","Unexpected EOF"]}),[e.String,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];if(isNewLine(i))return n.onParseError({message:"Unexpected newline while consuming a string token.",start:t.representationStart,end:t.representationEnd,state:["4.3.5. Consume a string token","Unexpected newline"]}),t.unreadCodePoint(),[e.BadString,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];if(i===r)return[e.String,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];if(92!==i)o+=String.fromCharCode(i);else{if(void 0===t.codePointSource[t.cursor])continue;if(isNewLine(t.codePointSource[t.cursor])){t.advanceCodePoint();continue}o+=String.fromCharCode(consumeEscapedCodePoint(n,t))}}}const i="u".charCodeAt(0),c="U".charCodeAt(0),s="r".charCodeAt(0),a="R".charCodeAt(0),u="l".charCodeAt(0),d="L".charCodeAt(0);function checkIfCodePointsMatchURLIdent(e,n){return 3===n.length&&((n[0]===i||n[0]===c)&&((n[1]===s||n[1]===a)&&(n[2]===u||n[2]===d)))}function consumeBadURL(e,n){for(;;){if(void 0===n.codePointSource[n.cursor])return;if(41===n.codePointSource[n.cursor])return void n.advanceCodePoint();checkIfTwoCodePointsAreAValidEscape(0,n)?(n.advanceCodePoint(),consumeEscapedCodePoint(e,n)):n.advanceCodePoint()}}function consumeUrlToken(n,t){consumeWhiteSpace(0,t);let o="";for(;;){if(void 0===t.codePointSource[t.cursor])return n.onParseError({message:"Unexpected EOF while consuming a url token.",start:t.representationStart,end:t.representationEnd,state:["4.3.6. Consume a url token","Unexpected EOF"]}),[e.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];if(41===t.codePointSource[t.cursor])return t.advanceCodePoint(),[e.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}];if(isWhitespace(t.codePointSource[t.cursor]))return consumeWhiteSpace(0,t),void 0===t.codePointSource[t.cursor]?(n.onParseError({message:"Unexpected EOF while consuming a url token.",start:t.representationStart,end:t.representationEnd,state:["4.3.6. Consume a url token","Consume as much whitespace as possible","Unexpected EOF"]}),[e.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}]):41===t.codePointSource[t.cursor]?(t.advanceCodePoint(),[e.URL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:o}]):(consumeBadURL(n,t),[e.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0]);if(34===t.codePointSource[t.cursor]||39===t.codePointSource[t.cursor]||40===t.codePointSource[t.cursor]||(11===(r=t.codePointSource[t.cursor])||127===r||0<=r&&r<=8||14<=r&&r<=31))return consumeBadURL(n,t),n.onParseError({message:"Unexpected character while consuming a url token.",start:t.representationStart,end:t.representationEnd,state:["4.3.6. Consume a url token","Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"]}),[e.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0];if(92===t.codePointSource[t.cursor]){if(checkIfTwoCodePointsAreAValidEscape(0,t)){o+=String.fromCharCode(consumeEscapedCodePoint(n,t));continue}return consumeBadURL(n,t),n.onParseError({message:"Invalid escape sequence while consuming a url token.",start:t.representationStart,end:t.representationEnd,state:["4.3.6. Consume a url token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.BadURL,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,void 0]}o+=String.fromCharCode(t.codePointSource[t.cursor]),t.advanceCodePoint()}var r}function consumeIdentLikeToken(n,t){const o=consumeIdentSequence(n,t);if(40!==t.codePointSource[t.cursor])return[e.Ident,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:String.fromCharCode(...o)}];if(checkIfCodePointsMatchURLIdent(0,o)){t.advanceCodePoint();let r=0;for(;;){const n=isWhitespace(t.codePointSource[t.cursor]),i=isWhitespace(t.codePointSource[t.cursor+1]);if(n&&i){r+=1,t.advanceCodePoint(1);continue}const c=n?t.codePointSource[t.cursor+1]:t.codePointSource[t.cursor];if(34===c||39===c)return[e.Function,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:String.fromCharCode(...o)}];break}return r>0&&t.advanceCodePoint(r),consumeUrlToken(n,t)}return t.advanceCodePoint(),[e.Function,t.source.slice(t.representationStart,t.representationEnd+1),t.representationStart,t.representationEnd,{value:String.fromCharCode(...o)}]}function tokenizer(n,t){const r=n.css.valueOf(),i=new Reader(r),c={onParseError:(null==t?void 0:t.onParseError)??(()=>{})};return{nextToken:function nextToken(){if(i.representationStart=i.cursor,i.representationEnd=-1,checkIfTwoCodePointsStartAComment(0,i)){if(null!=t&&t.commentsAreTokens)return consumeComment(c,i);consumeComment(c,i),i.representationStart=i.cursor,i.representationEnd=-1}const n=i.codePointSource[i.cursor];if(void 0===n)return[e.EOF,"",-1,-1,void 0];if(isIdentStartCodePoint(n))return consumeIdentLikeToken(c,i);if(isDigitCodePoint(n))return consumeNumericToken(c,i);switch(n){case 44:return i.advanceCodePoint(),[e.Comma,",",i.representationStart,i.representationEnd,void 0];case 58:return i.advanceCodePoint(),[e.Colon,":",i.representationStart,i.representationEnd,void 0];case 59:return i.advanceCodePoint(),[e.Semicolon,";",i.representationStart,i.representationEnd,void 0];case 40:return i.advanceCodePoint(),[e.OpenParen,"(",i.representationStart,i.representationEnd,void 0];case 41:return i.advanceCodePoint(),[e.CloseParen,")",i.representationStart,i.representationEnd,void 0];case 91:return i.advanceCodePoint(),[e.OpenSquare,"[",i.representationStart,i.representationEnd,void 0];case 93:return i.advanceCodePoint(),[e.CloseSquare,"]",i.representationStart,i.representationEnd,void 0];case 123:return i.advanceCodePoint(),[e.OpenCurly,"{",i.representationStart,i.representationEnd,void 0];case 125:return i.advanceCodePoint(),[e.CloseCurly,"}",i.representationStart,i.representationEnd,void 0];case 39:case 34:return consumeStringToken(c,i);case 35:return consumeHashToken(c,i);case 43:case 46:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(c,i):(i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]);case 10:case 13:case 12:case 9:case 32:return consumeWhiteSpace(0,i);case o:return checkIfThreeCodePointsWouldStartANumber(0,i)?consumeNumericToken(c,i):checkIfThreeCodePointsWouldStartCDC(0,i)?(i.advanceCodePoint(3),[e.CDC,"--\x3e",i.representationStart,i.representationEnd,void 0]):checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)?consumeIdentLikeToken(c,i):(i.advanceCodePoint(),[e.Delim,"-",i.representationStart,i.representationEnd,{value:"-"}]);case 60:return checkIfFourCodePointsWouldStartCDO(0,i)?(i.advanceCodePoint(4),[e.CDO,"\x3c!--",i.representationStart,i.representationEnd,void 0]):(i.advanceCodePoint(),[e.Delim,"<",i.representationStart,i.representationEnd,{value:"<"}]);case 64:if(i.advanceCodePoint(),checkIfThreeCodePointsWouldStartAnIdentSequence(0,i)){const n=consumeIdentSequence(c,i);return[e.AtKeyword,i.source.slice(i.representationStart,i.representationEnd+1),i.representationStart,i.representationEnd,{value:String.fromCharCode(...n)}]}return[e.Delim,"@",i.representationStart,i.representationEnd,{value:"@"}];case 92:return checkIfTwoCodePointsAreAValidEscape(0,i)?consumeIdentLikeToken(c,i):(i.advanceCodePoint(),c.onParseError({message:'Invalid escape sequence after "\\"',start:i.representationStart,end:i.representationEnd,state:["4.3.1. Consume a token","U+005C REVERSE SOLIDUS (\\)","The input stream does not start with a valid escape sequence"]}),[e.Delim,"\\",i.representationStart,i.representationEnd,{value:"\\"}])}return i.advanceCodePoint(),[e.Delim,i.source[i.representationStart],i.representationStart,i.representationEnd,{value:i.source[i.representationStart]}]},endOfFile:function endOfFile(){return void 0===i.codePointSource[i.cursor]}}}function cloneTokens(e){return"undefined"!=typeof globalThis&&"structuredClone"in globalThis?structuredClone(e):JSON.parse(JSON.stringify(e))}function mutateIdent(e,n){let t="";const r=new Array(n.length);for(let e=0;e */ -export const GREATER_THAN_SIGN = '\u{3e}'.charCodeAt(0); +export const GREATER_THAN_SIGN = 0x003e; /** - */ -export const HYPHEN_MINUS = '\u{2d}'.charCodeAt(0); +export const HYPHEN_MINUS = 0x002d; /** \x1F */ -export const INFORMATION_SEPARATOR_ONE = '\u{1f}'.charCodeAt(0); +export const INFORMATION_SEPARATOR_ONE = 0x001f; /** E */ -export const LATIN_CAPITAL_LETTER_E = '\u{45}'.charCodeAt(0); +export const LATIN_CAPITAL_LETTER_E = 0x0045; /** e */ -export const LATIN_SMALL_LETTER_E = '\u{65}'.charCodeAt(0); +export const LATIN_SMALL_LETTER_E = 0x0065; /** { */ -export const LEFT_CURLY_BRACKET = '\u{7b}'.charCodeAt(0); +export const LEFT_CURLY_BRACKET = 0x007b; /** ( */ -export const LEFT_PARENTHESIS = '\u{28}'.charCodeAt(0); +export const LEFT_PARENTHESIS = 0x0028; /** [ */ -export const LEFT_SQUARE_BRACKET = '\u{5b}'.charCodeAt(0); +export const LEFT_SQUARE_BRACKET = 0x005b; /** < */ -export const LESS_THAN_SIGN = '\u{3c}'.charCodeAt(0); +export const LESS_THAN_SIGN = 0x003c; /** \n */ -export const LINE_FEED = '\u{a}'.charCodeAt(0); +export const LINE_FEED = 0x00a; /** \v */ -export const LINE_TABULATION = '\u{b}'.charCodeAt(0); +export const LINE_TABULATION = 0x00b; /** _ */ -export const LOW_LINE = '\u{5f}'.charCodeAt(0); +export const LOW_LINE = 0x005f; /** \x10FFFF */ -export const MAXIMUM_ALLOWED_CODEPOINT = '\u{10FFFF}'.charCodeAt(0); +export const MAXIMUM_ALLOWED_CODEPOINT = 0x10FFFF; /** \x00 */ -export const NULL = '\u{0}'.charCodeAt(0); +export const NULL = 0x000; /** # */ -export const NUMBER_SIGN = '\u{23}'.charCodeAt(0); +export const NUMBER_SIGN = 0x0023; /** % */ -export const PERCENTAGE_SIGN = '\u{25}'.charCodeAt(0); +export const PERCENTAGE_SIGN = 0x0025; /** + */ -export const PLUS_SIGN = '\u{2b}'.charCodeAt(0); +export const PLUS_SIGN = 0x002b; /** " */ -export const QUOTATION_MARK = '\u{22}'.charCodeAt(0); +export const QUOTATION_MARK = 0x0022; /** � */ -export const REPLACEMENT_CHARACTER = '\u{0FFFD}'.charCodeAt(0); +export const REPLACEMENT_CHARACTER = 0xFFFD; /** \ */ -export const REVERSE_SOLIDUS = '\u{5c}'.charCodeAt(0); +export const REVERSE_SOLIDUS = 0x005c; /** } */ -export const RIGHT_CURLY_BRACKET = '\u{7d}'.charCodeAt(0); +export const RIGHT_CURLY_BRACKET = 0x007d; /** ) */ -export const RIGHT_PARENTHESIS = '\u{29}'.charCodeAt(0); +export const RIGHT_PARENTHESIS = 0x0029; /** ] */ -export const RIGHT_SQUARE_BRACKET = '\u{5d}'.charCodeAt(0); +export const RIGHT_SQUARE_BRACKET = 0x005d; /** ; */ -export const SEMICOLON = '\u{3b}'.charCodeAt(0); +export const SEMICOLON = 0x003b; /** \u0E */ -export const SHIFT_OUT = '\u{e}'.charCodeAt(0); +export const SHIFT_OUT = 0x00e; /** / */ -export const SOLIDUS = '\u{2f}'.charCodeAt(0); +export const SOLIDUS = 0x002f; /** \u20 */ -export const SPACE = '\u{20}'.charCodeAt(0); +export const SPACE = 0x0020; diff --git a/packages/css-tokenizer/src/code-points/ranges.ts b/packages/css-tokenizer/src/code-points/ranges.ts index 25a0be222..43d494624 100644 --- a/packages/css-tokenizer/src/code-points/ranges.ts +++ b/packages/css-tokenizer/src/code-points/ranges.ts @@ -1,48 +1,28 @@ -import { BACKSPACE, DELETE, INFORMATION_SEPARATOR_ONE, LINE_TABULATION, LOW_LINE, HYPHEN_MINUS, NULL, SHIFT_OUT, LINE_FEED, CARRIAGE_RETURN, FORM_FEED, CHARACTER_TABULATION, SPACE } from './code-points'; +import { BACKSPACE, DELETE, INFORMATION_SEPARATOR_ONE, LINE_TABULATION, LOW_LINE, HYPHEN_MINUS, NULL, SHIFT_OUT } from './code-points'; // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokenizer-definitions -const digitsLow = '\u{30}'.charCodeAt(0); -const digitsHigh = '\u{39}'.charCodeAt(0); - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#digit export function isDigitCodePoint(search: number): boolean { - return digitsLow <= search && search <= digitsHigh; + return search >= 0x0030 && search <= 0x0039; } -const letterUppercaseLow = '\u{41}'.charCodeAt(0); -const letterUppercaseHigh = '\u{5a}'.charCodeAt(0); - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#uppercase-letter export function isUppercaseLetterCodePoint(search: number): boolean { - return letterUppercaseLow <= search && search <= letterUppercaseHigh; + return search >= 0x0041 && search <= 0x005a; } -const letterLowercaseLow = '\u{61}'.charCodeAt(0); -const letterLowercaseHigh = '\u{7a}'.charCodeAt(0); - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#lowercase-letter export function isLowercaseLetterCodePoint(search: number): boolean { - return letterLowercaseLow <= search && search <= letterLowercaseHigh; + return search >= 0x0061 && search <= 0x007a; } -const afUppercaseHigh = '\u{46}'.charCodeAt(0); -const afLowercaseHigh = '\u{66}'.charCodeAt(0); - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#hex-digit export function isHexDigitCodePoint(search: number): boolean { - if (digitsLow <= search && search <= digitsHigh) { - return true; - } - - if (letterLowercaseLow <= search && search <= afLowercaseHigh) { - return true; - } - - if (letterUppercaseLow <= search && search <= afUppercaseHigh) { - return true; - } - - return false; + return ( + isDigitCodePoint(search) || // 0 .. 9 + (search >= 0x0061 && search <= 0x0066) || // a .. f + (search >= 0x0041 && search <= 0x0046) // A .. F + ); } // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#letter @@ -50,96 +30,42 @@ export function isLetterCodePoint(search: number): boolean { return isLowercaseLetterCodePoint(search) || isUppercaseLetterCodePoint(search); } -const nonASCIILow = '\u{80}'.charCodeAt(0); - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-ascii-code-point export function isNonASCIICodePoint(search: number): boolean { - return search >= nonASCIILow; + return search >= 0x0080; } // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-start-code-point export function isIdentStartCodePoint(search: number): boolean { - if (isLetterCodePoint(search)) { - return true; - } - - if (isNonASCIICodePoint(search)) { - return true; - } - - return search === LOW_LINE; + return isLetterCodePoint(search) || isNonASCIICodePoint(search) || search === LOW_LINE; } // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#ident-code-point export function isIdentCodePoint(search: number): boolean { - if (isIdentStartCodePoint(search)) { - return true; - } - - if (isDigitCodePoint(search)) { - return true; - } - - return search === HYPHEN_MINUS; + return isIdentStartCodePoint(search) || isDigitCodePoint(search) || search === HYPHEN_MINUS; } // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#non-printable-code-point export function isNonPrintableCodePoint(search: number): boolean { - if (search === LINE_TABULATION) { - return true; - } - - if (search === DELETE) { - return true; - } - - if (NULL <= search && search <= BACKSPACE) { - return true; - } - - return SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE; + return ( + (search === LINE_TABULATION) || + (search === DELETE) || + (NULL <= search && search <= BACKSPACE) || + (SHIFT_OUT <= search && search <= INFORMATION_SEPARATOR_ONE) + ); } // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace export function isNewLine(search: number): boolean { - switch (search) { - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing - // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. - // Applying the preprocessing rules would make it impossible to match the input. - // A side effect of this is that our definition of whitespace is broader. - return true; - default: - return false; - } + return search === 0x000a || search === 0x000d || search === 0x000c; } // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#whitespace export function isWhitespace(search: number): boolean { - // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#input-preprocessing - // We can not follow the preprocessing rules because our output is text and must be minimally different from the input. - // Applying the preprocessing rules would make it impossible to match the input. - // A side effect of this is that our definition of whitespace is broader. - - switch (search) { - case LINE_FEED: - case CARRIAGE_RETURN: - case FORM_FEED: - case CHARACTER_TABULATION: - case SPACE: - return true; - - default: - return false; - } + return search === 0x0020 || search === 0x000a || search === 0x0009 || search === 0x000d || search === 0x000c; } -const surrogateLow = '\u{d800}'.charCodeAt(0); -const surrogateHigh = '\u{dfff}'.charCodeAt(0); - // https://infra.spec.whatwg.org/#surrogate export function isSurrogate(search: number): boolean { - return surrogateLow <= search && search <= surrogateHigh; + return search >= 0xd800 && search <= 0xdfff; } diff --git a/packages/css-tokenizer/src/consume/ident-like-token.ts b/packages/css-tokenizer/src/consume/ident-like-token.ts index 71f97b352..73a377564 100644 --- a/packages/css-tokenizer/src/consume/ident-like-token.ts +++ b/packages/css-tokenizer/src/consume/ident-like-token.ts @@ -32,17 +32,13 @@ export function consumeIdentLikeToken(ctx: Context, reader: CodePointReader): To const firstIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor]); const secondIsWhitespace = isWhitespace(reader.codePointSource[reader.cursor+1]); if (firstIsWhitespace && secondIsWhitespace) { - read += 2; - reader.advanceCodePoint(2); + read += 1; + reader.advanceCodePoint(1); continue; } const firstNonWhitespace = firstIsWhitespace ? reader.codePointSource[reader.cursor+1] : reader.codePointSource[reader.cursor]; if (firstNonWhitespace === QUOTATION_MARK || firstNonWhitespace === APOSTROPHE) { - if (read > 0) { - reader.advanceCodePoint(read); - } - return [ TokenType.Function, 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 e2e1ae732..b07842dc7 100644 --- a/packages/css-tokenizer/test/test.mjs +++ b/packages/css-tokenizer/test/test.mjs @@ -7,8 +7,10 @@ import './code-points/ranges.mjs'; // Tokens import './token/basic.mjs'; +import './token/cdo.mjs'; import './token/comment.mjs'; import './token/numeric.mjs'; +import './token/string.mjs'; import './token/url.mjs'; // Complex diff --git a/packages/css-tokenizer/test/token/basic.mjs b/packages/css-tokenizer/test/token/basic.mjs index e5f471d6d..70ab67ba2 100644 --- a/packages/css-tokenizer/test/token/basic.mjs +++ b/packages/css-tokenizer/test/token/basic.mjs @@ -316,3 +316,32 @@ bar") and (fancy(baz))) {}`, ); } } + +{ + const t = tokenizer({ + css: '\\0', + }); + + assert.deepEqual( + collectTokens(t), + [ + ['ident-token', '\\0', 0, 1, { value: '�' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} + +{ + const t = tokenizer({ + css: `\\0 +`, + }); + + assert.deepEqual( + collectTokens(t), + [ + ['ident-token', '\\0\n', 0, 2, { value: '�' }], + ['EOF-token', '', -1, -1, undefined], + ], + ); +} diff --git a/packages/css-tokenizer/test/token/cdo.mjs b/packages/css-tokenizer/test/token/cdo.mjs new file mode 100644 index 000000000..583ab18f3 --- /dev/null +++ b/packages/css-tokenizer/test/token/cdo.mjs @@ -0,0 +1,50 @@ +import { tokenizer } from '@csstools/css-tokenizer'; +import assert from 'assert'; +import { collectTokens } from '../util/collect-tokens.mjs'; + +{ + const t = tokenizer({ + css: '