From 275f9dc0bdf3e58aa36b800f55f8648fbc55d8af Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 4 Jan 2024 11:07:54 +0800 Subject: upgrade --- .../@csstools/css-tokenizer/dist/index.d.ts | 457 +++++++++++++++++---- 1 file changed, 377 insertions(+), 80 deletions(-) (limited to 'node_modules/@csstools/css-tokenizer/dist/index.d.ts') diff --git a/node_modules/@csstools/css-tokenizer/dist/index.d.ts b/node_modules/@csstools/css-tokenizer/dist/index.d.ts index cd375797..e503c818 100644 --- a/node_modules/@csstools/css-tokenizer/dist/index.d.ts +++ b/node_modules/@csstools/css-tokenizer/dist/index.d.ts @@ -1,5 +1,44 @@ +/** + * Tokenize CSS following the {@link https://drafts.csswg.org/css-syntax/#tokenization | CSS Syntax Level 3 specification}. + * + * @remarks + * The tokenizing and parsing tools provided by CSS Tools are designed to be low level and generic with strong ties to their respective specifications. + * + * Any analysis or mutation of CSS source code should be done with the least powerful tool that can accomplish the task. + * For many applications it is sufficient to work with tokens. + * For others you might need to use {@link https://github.com/csstools/postcss-plugins/tree/main/packages/css-parser-algorithms | @csstools/css-parser-algorithms} or a more specific parser. + * + * @example + * Tokenize a string of CSS into an array of tokens: + * ```js + * import { tokenize } from '@csstools/css-tokenizer'; + * + * const myCSS = `@media only screen and (min-width: 768rem) { + * .foo { + * content: 'Some content!' !important; + * } + * } + * `; + * + * const tokens = tokenize({ + * css: myCSS, + * }); + * + * console.log(tokens); + * ``` + * + * @packageDocumentation + */ + +/** + * Deep clone a list of tokens. + * Useful for mutations without altering the original list. + */ export declare function cloneTokens(tokens: Array): Array; +/** + * @internal + */ export declare type CodePointReader = { representationStart: number; representationEnd: number; @@ -13,26 +52,84 @@ export declare type CodePointReader = { resetRepresentation(): void; }; +/** + * The union of all possible CSS tokens + */ export declare type CSSToken = TokenAtKeyword | TokenBadString | TokenBadURL | TokenCDC | TokenCDO | TokenColon | TokenComma | TokenComment | TokenDelim | TokenDimension | TokenEOF | TokenFunction | TokenHash | TokenIdent | TokenNumber | TokenPercentage | TokenSemicolon | TokenString | TokenURL | TokenWhitespace | TokenOpenParen | TokenCloseParen | TokenOpenSquare | TokenCloseSquare | TokenOpenCurly | TokenCloseCurly | TokenUnicodeRange; +/** + * The type of hash token + */ export declare enum HashType { + /** + * The hash token did not start with an ident sequence (e.g. `#-2`) + */ Unrestricted = "unrestricted", + /** + * The hash token started with an ident sequence (e.g. `#foo`) + * Only hash tokens with the "id" type are valid ID selectors. + */ ID = "id" } +/** + * Assert that a given value has the general structure of a CSS token: + * 1. is an array. + * 2. has at least four items. + * 3. has a known token type. + * 4. has a string representation. + * 5. has a start position. + * 6. has an end position. + */ export declare function isToken(x: any): x is CSSToken; +/** + * Get the mirror variant of a given token + * + * @example + * + * ```js + * const input = [TokenType.OpenParen, '(', 0, 1, undefined]; + * const output = mirrorVariant(input); + * + * console.log(output); // [TokenType.CloseParen, ')', -1, -1, undefined] + * ``` + */ export declare function mirrorVariant(token: CSSToken): CSSToken | null; +/** + * Get the mirror variant type of a given token type + * + * @example + * + * ```js + * const input = TokenType.OpenParen; + * const output = mirrorVariantType(input); + * + * console.log(output); // TokenType.CloseParen + * ``` + */ export declare function mirrorVariantType(type: TokenType): TokenType | null; +/** + * Set the ident value and update the string representation. + * This handles escaping. + */ export declare function mutateIdent(ident: TokenIdent, newValue: string): void; +/** + * The type of number token + * Either `integer` or `number` + */ export declare enum NumberType { Integer = "integer", Number = "number" } +/** + * The CSS Tokenizer is forgiving and will never throw on invalid input. + * Any errors are reported through the `onParseError` callback. + */ export declare class ParseError extends Error { /** The index of the start character of the current token. */ sourceStart: number; @@ -43,6 +140,9 @@ export declare class ParseError extends Error { constructor(message: string, sourceStart: number, sourceEnd: number, parserState: Array); } +/** + * @internal + */ export declare class Reader implements CodePointReader { cursor: number; source: string; @@ -58,71 +158,161 @@ export declare class Reader implements CodePointReader { resetRepresentation(): void; } +/** + * Concatenate the string representation of a list of tokens. + * This is not a proper serializer that will handle escaping and whitespace. + * It only produces valid CSS for a token list that is also valid. + */ export declare function stringify(...tokens: Array): string; -export declare type Token = [ -/** The type of token */ -T, -/** The token representation */ -string, -/** Start position of representation */ -number, -/** End position of representation */ -number, -/** Extra data */ -U -]; - -export declare type TokenAtKeyword = Token extends Array { + /** + * The type of token + */ + 0: T; + /** + * The token representation + * + * @remarks + * This field will be used when stringifying the token. + * Any stored value is assumed to be valid CSS. + * + * You should never use this field when analyzing the token when there is a parsed value available. + * But you must store mutated values here. + */ + 1: string; + /** + * Start position of representation + */ + 2: number; + /** + * End position of representation + */ + 3: number; + /** + * Extra data + * + * @remarks + * This holds the parsed value of each token. + * These values are unescaped, unquoted, converted to numbers, etc. + * + * You should always use this field when analyzing the token. + * But you must not assume that mutating only this field will have any effect. + */ + 4: U; +} + +export declare interface TokenAtKeyword extends Token; +}> { +} -export declare type TokenBadString = Token; +export declare interface TokenBadString extends Token { +} -export declare type TokenBadURL = Token; +export declare interface TokenBadURL extends Token { +} -export declare type TokenCDC = Token; +export declare interface TokenCDC extends Token { +} -export declare type TokenCDO = Token; +export declare interface TokenCDO extends Token { +} -export declare type TokenCloseCurly = Token; +export declare interface TokenCloseCurly extends Token { +} -export declare type TokenCloseParen = Token; +export declare interface TokenCloseParen extends Token { +} -export declare type TokenCloseSquare = Token; +export declare interface TokenCloseSquare extends Token { +} -export declare type TokenColon = Token; +export declare interface TokenColon extends Token { +} -export declare type TokenComma = Token; +export declare interface TokenComma extends Token { +} -export declare type TokenComment = Token; +export declare interface TokenComment extends Token { +} -export declare type TokenDelim = Token; +}> { +} -export declare type TokenDimension = Token; + /** + * The sign character as it appeared in the source. + * This is only useful if you need to determine if a value was written as "2px" or "+2px". + */ + signCharacter?: '+' | '-'; +}> { +} -export declare type TokenEOF = Token; +export declare interface TokenEOF extends Token { +} -export declare type TokenFunction = Token; +}> { +} -export declare type TokenHash = Token; +}> { +} -export declare type TokenIdent = Token; +}> { +} +/** + * Tokenize a CSS string into a list of tokens. + */ export declare function tokenize(input: { css: { valueOf(): string; @@ -132,6 +322,9 @@ export declare function tokenize(input: { onParseError?: (error: ParseError) => void; }): Array; +/** + * Create a tokenizer for a CSS string. + */ export declare function tokenizer(input: { css: { valueOf(): string; @@ -144,95 +337,199 @@ export declare function tokenizer(input: { endOfFile: () => boolean; }; -export declare type TokenNumber = Token; + /** + * The sign character as it appeared in the source. + * This is only useful if you need to determine if a value was written as "2" or "+2". + */ + signCharacter?: '+' | '-'; +}> { +} -export declare type TokenOpenCurly = Token; +export declare interface TokenOpenCurly extends Token { +} -export declare type TokenOpenParen = Token; +export declare interface TokenOpenParen extends Token { +} -export declare type TokenOpenSquare = Token; +export declare interface TokenOpenSquare extends Token { +} -export declare type TokenPercentage = Token; +}> { +} -export declare type TokenSemicolon = Token; +export declare interface TokenSemicolon extends Token { +} -export declare type TokenString = Token; +}> { +} +/** + * All possible CSS token types + */ export declare enum TokenType { - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#comment-diagram} + */ Comment = "comment", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-at-keyword-token} + */ AtKeyword = "at-keyword-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-string-token} + */ BadString = "bad-string-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-bad-url-token} + */ BadURL = "bad-url-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdc-token} + */ CDC = "CDC-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-cdo-token} + */ CDO = "CDO-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-colon-token} + */ Colon = "colon-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-comma-token} + */ Comma = "comma-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-delim-token} + */ Delim = "delim-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-dimension-token} + */ Dimension = "dimension-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-eof-token} + */ EOF = "EOF-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-function-token} + */ Function = "function-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-hash-token} + */ Hash = "hash-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token} + */ Ident = "ident-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token} + */ Number = "number-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-percentage-token} + */ Percentage = "percentage-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-semicolon-token} + */ Semicolon = "semicolon-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-string-token} + */ String = "string-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-url-token} + */ URL = "url-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-whitespace-token} + */ Whitespace = "whitespace-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-paren} + */ OpenParen = "(-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-paren} + */ CloseParen = ")-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-square} + */ OpenSquare = "[-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-square} + */ CloseSquare = "]-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-open-curly} + */ OpenCurly = "{-token", - /** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly */ + /** + * @see {@link https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#tokendef-close-curly} + */ CloseCurly = "}-token", - /** https://drafts.csswg.org/css-syntax/#typedef-unicode-range-token */ + /** + * Only appears in the token stream when the `unicodeRangesAllowed` option is set to true. + * + * @example + * ```js + * import { tokenize } from '@csstools/css-tokenizer'; + * + * const tokens = tokenize({ + * css: `U+0025-00FF, U+4??`, + * unicodeRangesAllowed: true, + * }); + * + * console.log(tokens); + * ``` + * + * @see {@link https://drafts.csswg.org/css-syntax/#typedef-unicode-range-token} + */ UnicodeRange = "unicode-range-token" } -export declare type TokenUnicodeRange = Token; +}> { +} -export declare type TokenURL = Token; +}> { +} -export declare type TokenWhitespace = Token; +export declare interface TokenWhitespace extends Token { +} export { } -- cgit v1.2.3