aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/@csstools/css-parser-algorithms/dist
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
commit76cb9c2a39d477a64824a985ade40507e3bbade1 (patch)
tree41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/@csstools/css-parser-algorithms/dist
parent819a39a21ac992b1393244a4c283bbb125208c69 (diff)
downloadneko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/@csstools/css-parser-algorithms/dist')
-rw-r--r--vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.d.ts604
-rw-r--r--vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.mjs1
2 files changed, 605 insertions, 0 deletions
diff --git a/vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.d.ts b/vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.d.ts
new file mode 100644
index 0000000..c59d3dd
--- /dev/null
+++ b/vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.d.ts
@@ -0,0 +1,604 @@
+/**
+ * Parse CSS following the {@link https://drafts.csswg.org/css-syntax/#parsing | 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.
+ *
+ * The implementation of the AST nodes is kept lightweight and simple.
+ * Do not expect magic methods, instead assume that arrays and class instances behave like any other JavaScript.
+ *
+ * @example
+ * Parse a string of CSS into a component value:
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseComponentValue } from '@csstools/css-parser-algorithms';
+ *
+ * const myCSS = `calc(1px * 2)`;
+ *
+ * const componentValue = parseComponentValue(tokenize({
+ * css: myCSS,
+ * }));
+ *
+ * console.log(componentValue);
+ * ```
+ *
+ * @example
+ * Use the right algorithm for the job.
+ *
+ * Algorithms that can parse larger structures (comma-separated lists, ...) can also parse smaller structures.
+ * However, the opposite is not true.
+ *
+ * If your context allows a list of component values, use {@link parseListOfComponentValues}:
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseListOfComponentValues } from '@csstools/css-parser-algorithms';
+ *
+ * parseListOfComponentValues(tokenize({ css: `10x 20px` }));
+ * ```
+ *
+ * If your context allows a comma-separated list of component values, use {@link parseCommaSeparatedListOfComponentValues}:
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseCommaSeparatedListOfComponentValues } from '@csstools/css-parser-algorithms';
+ *
+ * parseCommaSeparatedListOfComponentValues(tokenize({ css: `20deg, 50%, 30%` }));
+ * ```
+ *
+ * @example
+ * Use the stateful walkers to keep track of the context of a given component value.
+ *
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseComponentValue, isSimpleBlockNode } from '@csstools/css-parser-algorithms';
+ *
+ * const myCSS = `calc(1px * (5 / 2))`;
+ *
+ * const componentValue = parseComponentValue(tokenize({ css: myCSS }));
+ *
+ * let state = { inSimpleBlock: false };
+ * componentValue.walk((entry) => {
+ * if (isSimpleBlockNode(entry)) {
+ * entry.state.inSimpleBlock = true;
+ * return;
+ * }
+ *
+ * if (entry.state.inSimpleBlock) {
+ * console.log(entry.node.toString()); // `5`, ...
+ * }
+ * }, state);
+ * ```
+ *
+ * @packageDocumentation
+ */
+
+import type { CSSToken } from '@csstools/css-tokenizer';
+import { ParseError } from '@csstools/css-tokenizer';
+import type { TokenFunction } from '@csstools/css-tokenizer';
+
+export declare class CommentNode {
+ /**
+ * The node type, always `ComponentValueType.Comment`
+ */
+ type: ComponentValueType;
+ /**
+ * The comment token.
+ */
+ value: CSSToken;
+ constructor(value: CSSToken);
+ /**
+ * Retrieve the tokens for the current comment.
+ * This is the inverse of parsing from a list of tokens.
+ */
+ tokens(): Array<CSSToken>;
+ /**
+ * Convert the current comment to a string.
+ * This is not a true serialization.
+ * It is purely a concatenation of the string representation of the tokens.
+ */
+ toString(): string;
+ /**
+ * @internal
+ *
+ * A debug helper to convert the current object to a JSON representation.
+ * This is useful in asserts and to store large ASTs in files.
+ */
+ toJSON(): Record<string, unknown>;
+ /**
+ * @internal
+ */
+ isCommentNode(): this is CommentNode;
+ /**
+ * @internal
+ */
+ static isCommentNode(x: unknown): x is CommentNode;
+}
+
+export declare type ComponentValue = FunctionNode | SimpleBlockNode | WhitespaceNode | CommentNode | TokenNode;
+
+export declare enum ComponentValueType {
+ Function = "function",
+ SimpleBlock = "simple-block",
+ Whitespace = "whitespace",
+ Comment = "comment",
+ Token = "token"
+}
+
+export declare type ContainerNode = FunctionNode | SimpleBlockNode;
+
+export declare abstract class ContainerNodeBaseClass {
+ /**
+ * The contents of the `Function` or `Simple Block`.
+ * This is a list of component values.
+ */
+ value: Array<ComponentValue>;
+ /**
+ * Retrieve the index of the given item in the current node.
+ * For most node types this will be trivially implemented as `this.value.indexOf(item)`.
+ */
+ indexOf(item: ComponentValue): number | string;
+ /**
+ * Retrieve the item at the given index in the current node.
+ * For most node types this will be trivially implemented as `this.value[index]`.
+ */
+ at(index: number | string): ComponentValue | undefined;
+ /**
+ * Iterates over each item in the `value` array of the current node.
+ *
+ * @param cb - The callback function to execute for each item.
+ * The function receives an object containing the current node (`node`), its parent (`parent`),
+ * and an optional `state` object.
+ * A second parameter is the index of the current node.
+ * The function can return `false` to stop the iteration.
+ *
+ * @param state - An optional state object that can be used to pass additional information to the callback function.
+ * The state object is cloned for each iteration. This means that changes to the state object are not reflected in the next iteration.
+ *
+ * @returns `false` if the iteration was halted, `undefined` otherwise.
+ */
+ forEach<T extends Record<string, unknown>, U extends ContainerNode>(this: U, cb: (entry: {
+ node: ComponentValue;
+ parent: ContainerNode;
+ state?: T;
+ }, index: number | string) => boolean | void, state?: T): false | undefined;
+ /**
+ * Walks the current node and all its children.
+ *
+ * @param cb - The callback function to execute for each item.
+ * The function receives an object containing the current node (`node`), its parent (`parent`),
+ * and an optional `state` object.
+ * A second parameter is the index of the current node.
+ * The function can return `false` to stop the iteration.
+ *
+ * @param state - An optional state object that can be used to pass additional information to the callback function.
+ * The state object is cloned for each iteration. This means that changes to the state object are not reflected in the next iteration.
+ * However changes are passed down to child node iterations.
+ *
+ * @returns `false` if the iteration was halted, `undefined` otherwise.
+ */
+ walk<T extends Record<string, unknown>, U extends ContainerNode>(this: U, cb: (entry: {
+ node: ComponentValue;
+ parent: ContainerNode;
+ state?: T;
+ }, index: number | string) => boolean | void, state?: T): false | undefined;
+}
+
+/**
+ * Iterates over each item in a list of component values.
+ *
+ * @param cb - The callback function to execute for each item.
+ * The function receives an object containing the current node (`node`), its parent (`parent`),
+ * and an optional `state` object.
+ * A second parameter is the index of the current node.
+ * The function can return `false` to stop the iteration.
+ *
+ * @param state - An optional state object that can be used to pass additional information to the callback function.
+ * The state object is cloned for each iteration. This means that changes to the state object are not reflected in the next iteration.
+ *
+ * @returns `false` if the iteration was halted, `undefined` otherwise.
+ */
+export declare function forEach<T extends Record<string, unknown>>(componentValues: Array<ComponentValue>, cb: (entry: {
+ node: ComponentValue;
+ parent: ContainerNode | {
+ value: Array<ComponentValue>;
+ };
+ state?: T;
+}, index: number | string) => boolean | void, state?: T): false | undefined;
+
+/**
+ * A function node.
+ *
+ * @example
+ * ```js
+ * const node = parseComponentValue(tokenize('calc(1 + 1)'));
+ *
+ * isFunctionNode(node); // true
+ * node.getName(); // 'calc'
+ * ```
+ */
+export declare class FunctionNode extends ContainerNodeBaseClass {
+ /**
+ * The node type, always `ComponentValueType.Function`
+ */
+ type: ComponentValueType;
+ /**
+ * The token for the name of the function.
+ */
+ name: TokenFunction;
+ /**
+ * The token for the closing parenthesis of the function.
+ * If the function is unclosed, this will be an EOF token.
+ */
+ endToken: CSSToken;
+ constructor(name: TokenFunction, endToken: CSSToken, value: Array<ComponentValue>);
+ /**
+ * Retrieve the name of the current function.
+ * This is the parsed and unescaped name of the function.
+ */
+ getName(): string;
+ /**
+ * Normalize the current function:
+ * 1. if the "endToken" is EOF, replace with a ")-token"
+ */
+ normalize(): void;
+ /**
+ * Retrieve the tokens for the current function.
+ * This is the inverse of parsing from a list of tokens.
+ */
+ tokens(): Array<CSSToken>;
+ /**
+ * Convert the current function to a string.
+ * This is not a true serialization.
+ * It is purely a concatenation of the string representation of the tokens.
+ */
+ toString(): string;
+ /**
+ * @internal
+ *
+ * A debug helper to convert the current object to a JSON representation.
+ * This is useful in asserts and to store large ASTs in files.
+ */
+ toJSON(): unknown;
+ /**
+ * @internal
+ */
+ isFunctionNode(): this is FunctionNode;
+ /**
+ * @internal
+ */
+ static isFunctionNode(x: unknown): x is FunctionNode;
+}
+
+/**
+ * AST nodes do not have a `parent` property or method.
+ * This makes it harder to traverse the AST upwards.
+ * This function builds a `Map<Child, Parent>` that can be used to lookup ancestors of a node.
+ *
+ * @remarks
+ * There is no magic behind this or the map it returns.
+ * Mutating the AST will not update the map.
+ *
+ * Types are erased and any content of the map has type `unknown`.
+ * If someone knows a clever way to type this, please let us know.
+ *
+ * @example
+ * ```js
+ * const ancestry = gatherNodeAncestry(mediaQuery);
+ * mediaQuery.walk((entry) => {
+ * const node = entry.node; // directly exposed
+ * const parent = entry.parent; // directly exposed
+ * const grandParent: unknown = ancestry.get(parent); // lookup
+ *
+ * console.log('node', node);
+ * console.log('parent', parent);
+ * console.log('grandParent', grandParent);
+ * });
+ * ```
+ */
+export declare function gatherNodeAncestry(node: {
+ walk(cb: (entry: {
+ node: unknown;
+ parent: unknown;
+ }, index: number | string) => boolean | void): false | undefined;
+}): Map<unknown, unknown>;
+
+/**
+ * Check if the current object is a `CommentNode`.
+ * This is a type guard.
+ */
+export declare function isCommentNode(x: unknown): x is CommentNode;
+
+/**
+ * Check if the current object is a `FunctionNode`.
+ * This is a type guard.
+ */
+export declare function isFunctionNode(x: unknown): x is FunctionNode;
+
+/**
+ * Check if the current object is a `SimpleBlockNode`.
+ * This is a type guard.
+ */
+export declare function isSimpleBlockNode(x: unknown): x is SimpleBlockNode;
+
+/**
+ * Check if the current object is a `TokenNode`.
+ * This is a type guard.
+ */
+export declare function isTokenNode(x: unknown): x is TokenNode;
+
+/**
+ * Check if the current object is a `WhitespaceNode`.
+ * This is a type guard.
+ */
+export declare function isWhitespaceNode(x: unknown): x is WhitespaceNode;
+
+/**
+ * Check if the current object is a `WhiteSpaceNode` or a `CommentNode`.
+ * This is a type guard.
+ */
+export declare function isWhiteSpaceOrCommentNode(x: unknown): x is WhitespaceNode | CommentNode;
+
+/**
+ * Parse a comma-separated list of component values.
+ *
+ * @example
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseCommaSeparatedListOfComponentValues } from '@csstools/css-parser-algorithms';
+ *
+ * parseCommaSeparatedListOfComponentValues(tokenize({ css: `20deg, 50%, 30%` }));
+ * ```
+ */
+export declare function parseCommaSeparatedListOfComponentValues(tokens: Array<CSSToken>, options?: {
+ onParseError?: (error: ParseError) => void;
+}): Array<Array<ComponentValue>>;
+
+/**
+ * Parse a single component value.
+ *
+ * @example
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseComponentValue } from '@csstools/css-parser-algorithms';
+ *
+ * parseComponentValue(tokenize({ css: `10px` }));
+ * parseComponentValue(tokenize({ css: `calc((10px + 1x) * 4)` }));
+ * ```
+ */
+export declare function parseComponentValue(tokens: Array<CSSToken>, options?: {
+ onParseError?: (error: ParseError) => void;
+}): ComponentValue | undefined;
+
+/**
+ * Parse a list of component values.
+ *
+ * @example
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseListOfComponentValues } from '@csstools/css-parser-algorithms';
+ *
+ * parseListOfComponentValues(tokenize({ css: `20deg 30%` }));
+ * ```
+ */
+export declare function parseListOfComponentValues(tokens: Array<CSSToken>, options?: {
+ onParseError?: (error: ParseError) => void;
+}): Array<ComponentValue>;
+
+/**
+ * Replace specific component values in a list of component values.
+ * A helper for the most common and simplistic cases when mutating an AST.
+ */
+export declare function replaceComponentValues(componentValuesList: Array<Array<ComponentValue>>, replaceWith: (componentValue: ComponentValue) => Array<ComponentValue> | ComponentValue | void): Array<Array<ComponentValue>>;
+
+/**
+ * A simple block node.
+ *
+ * @example
+ * ```js
+ * const node = parseComponentValue(tokenize('[foo=bar]'));
+ *
+ * isSimpleBlockNode(node); // true
+ * node.startToken; // [TokenType.OpenSquare, '[', 0, 0, undefined]
+ * ```
+ */
+export declare class SimpleBlockNode extends ContainerNodeBaseClass {
+ /**
+ * The node type, always `ComponentValueType.SimpleBlock`
+ */
+ type: ComponentValueType;
+ /**
+ * The token for the opening token of the block.
+ */
+ startToken: CSSToken;
+ /**
+ * The token for the closing token of the block.
+ * If the block is closed it will be the mirror variant of the `startToken`.
+ * If the block is unclosed, this will be an EOF token.
+ */
+ endToken: CSSToken;
+ constructor(startToken: CSSToken, endToken: CSSToken, value: Array<ComponentValue>);
+ /**
+ * Normalize the current simple block
+ * 1. if the "endToken" is EOF, replace with the mirror token of the "startToken"
+ */
+ normalize(): void;
+ /**
+ * Retrieve the tokens for the current simple block.
+ * This is the inverse of parsing from a list of tokens.
+ */
+ tokens(): Array<CSSToken>;
+ /**
+ * Convert the current simple block to a string.
+ * This is not a true serialization.
+ * It is purely a concatenation of the string representation of the tokens.
+ */
+ toString(): string;
+ /**
+ * @internal
+ *
+ * A debug helper to convert the current object to a JSON representation.
+ * This is useful in asserts and to store large ASTs in files.
+ */
+ toJSON(): unknown;
+ /**
+ * @internal
+ */
+ isSimpleBlockNode(): this is SimpleBlockNode;
+ /**
+ * @internal
+ */
+ static isSimpleBlockNode(x: unknown): x is SimpleBlockNode;
+}
+
+/**
+ * Returns the start and end index of a node in the CSS source string.
+ */
+export declare function sourceIndices(x: {
+ tokens(): Array<CSSToken>;
+} | Array<{
+ tokens(): Array<CSSToken>;
+}>): [number, number];
+
+/**
+ * Concatenate the string representation of a collection of component values.
+ * This is not a proper serializer that will handle escaping and whitespace.
+ * It only produces valid CSS for token lists that are also valid.
+ */
+export declare function stringify(componentValueLists: Array<Array<ComponentValue>>): string;
+
+export declare class TokenNode {
+ /**
+ * The node type, always `ComponentValueType.Token`
+ */
+ type: ComponentValueType;
+ /**
+ * The token.
+ */
+ value: CSSToken;
+ constructor(value: CSSToken);
+ /**
+ * This is the inverse of parsing from a list of tokens.
+ */
+ tokens(): [CSSToken];
+ /**
+ * Convert the current token to a string.
+ * This is not a true serialization.
+ * It is purely the string representation of token.
+ */
+ toString(): string;
+ /**
+ * @internal
+ *
+ * A debug helper to convert the current object to a JSON representation.
+ * This is useful in asserts and to store large ASTs in files.
+ */
+ toJSON(): Record<string, unknown>;
+ /**
+ * @internal
+ */
+ isTokenNode(): this is TokenNode;
+ /**
+ * @internal
+ */
+ static isTokenNode(x: unknown): x is TokenNode;
+}
+
+/**
+ * Walks each item in a list of component values all of their children.
+ *
+ * @param cb - The callback function to execute for each item.
+ * The function receives an object containing the current node (`node`), its parent (`parent`),
+ * and an optional `state` object.
+ * A second parameter is the index of the current node.
+ * The function can return `false` to stop the iteration.
+ *
+ * @param state - An optional state object that can be used to pass additional information to the callback function.
+ * The state object is cloned for each iteration. This means that changes to the state object are not reflected in the next iteration.
+ * However changes are passed down to child node iterations.
+ *
+ * @returns `false` if the iteration was halted, `undefined` otherwise.
+ *
+ * @example
+ * ```js
+ * import { tokenize } from '@csstools/css-tokenizer';
+ * import { parseListOfComponentValues, isSimpleBlockNode } from '@csstools/css-parser-algorithms';
+ *
+ * const myCSS = `calc(1px * (5 / 2)) 10px`;
+ *
+ * const componentValues = parseListOfComponentValues(tokenize({ css: myCSS }));
+ *
+ * let state = { inSimpleBlock: false };
+ * walk(componentValues, (entry) => {
+ * if (isSimpleBlockNode(entry)) {
+ * entry.state.inSimpleBlock = true;
+ * return;
+ * }
+ *
+ * if (entry.state.inSimpleBlock) {
+ * console.log(entry.node.toString()); // `5`, ...
+ * }
+ * }, state);
+ * ```
+ */
+export declare function walk<T extends Record<string, unknown>>(componentValues: Array<ComponentValue>, cb: (entry: {
+ node: ComponentValue;
+ parent: ContainerNode | {
+ value: Array<ComponentValue>;
+ };
+ state?: T;
+}, index: number | string) => boolean | void, state?: T): false | undefined;
+
+/**
+ * Generate a function that finds the next element that should be visited when walking an AST.
+ * Rules :
+ * 1. the previous iteration is used as a reference, so any checks are relative to the start of the current iteration.
+ * 2. the next element always appears after the current index.
+ * 3. the next element always exists in the list.
+ * 4. replacing an element does not cause the replaced element to be visited.
+ * 5. removing an element does not cause elements to be skipped.
+ * 6. an element added later in the list will be visited.
+ */
+export declare function walkerIndexGenerator<T>(initialList: Array<T>): (list: Array<T>, child: T, index: number) => number;
+
+export declare class WhitespaceNode {
+ /**
+ * The node type, always `ComponentValueType.WhiteSpace`
+ */
+ type: ComponentValueType;
+ /**
+ * The list of consecutive whitespace tokens.
+ */
+ value: Array<CSSToken>;
+ constructor(value: Array<CSSToken>);
+ /**
+ * Retrieve the tokens for the current whitespace.
+ * This is the inverse of parsing from a list of tokens.
+ */
+ tokens(): Array<CSSToken>;
+ /**
+ * Convert the current whitespace to a string.
+ * This is not a true serialization.
+ * It is purely a concatenation of the string representation of the tokens.
+ */
+ toString(): string;
+ /**
+ * @internal
+ *
+ * A debug helper to convert the current object to a JSON representation.
+ * This is useful in asserts and to store large ASTs in files.
+ */
+ toJSON(): Record<string, unknown>;
+ /**
+ * @internal
+ */
+ isWhitespaceNode(): this is WhitespaceNode;
+ /**
+ * @internal
+ */
+ static isWhitespaceNode(x: unknown): x is WhitespaceNode;
+}
+
+export { }
diff --git a/vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.mjs b/vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.mjs
new file mode 100644
index 0000000..ca4f76d
--- /dev/null
+++ b/vanilla/node_modules/@csstools/css-parser-algorithms/dist/index.mjs
@@ -0,0 +1 @@
+import{isTokenEOF as e,TokenType as n,isToken as t,stringify as o,mirrorVariant as s,isTokenOpenParen as i,isTokenOpenCurly as r,isTokenOpenSquare as a,isTokenFunction as c,isTokenWhitespace as u,isTokenComment as l,mirrorVariantType as d,ParseError as h,isTokenWhiteSpaceOrComment as p,isTokenCloseParen as m,isTokenComma as k}from"@csstools/css-tokenizer";var f;function walkerIndexGenerator(e){let n=e.slice();return(e,t,o)=>{let s=-1;for(let i=n.indexOf(t);i<n.length&&(s=e.indexOf(n[i]),-1===s||s<o);i++);return-1===s||s===o&&t===e[o]&&(s++,s>=e.length)?-1:(n=e.slice(),s)}}function consumeComponentValue(e,n){const t=n[0];if(i(t)||r(t)||a(t)){const t=consumeSimpleBlock(e,n);return{advance:t.advance,node:t.node}}if(c(t)){const t=consumeFunction(e,n);return{advance:t.advance,node:t.node}}if(u(t)){const t=consumeWhitespace(e,n);return{advance:t.advance,node:t.node}}if(l(t)){const t=consumeComment(e,n);return{advance:t.advance,node:t.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"}(f||(f={}));class ContainerNodeBaseClass{value=[];indexOf(e){return this.value.indexOf(e)}at(e){if("number"==typeof e)return e<0&&(e=this.value.length+e),this.value[e]}forEach(e,n){if(0===this.value.length)return;const t=walkerIndexGenerator(this.value);let o=0;for(;o<this.value.length;){const s=this.value[o];let i;if(n&&(i={...n}),!1===e({node:s,parent:this,state:i},o))return!1;if(o=t(this.value,s,o),-1===o)break}}walk(e,n){0!==this.value.length&&this.forEach((n,t)=>!1!==e(n,t)&&((!("walk"in n.node)||!this.value.includes(n.node)||!1!==n.node.walk(e,n.state))&&void 0),n)}}class FunctionNode extends ContainerNodeBaseClass{type=f.Function;name;endToken;constructor(e,n,t){super(),this.name=e,this.endToken=n,this.value=t}getName(){return this.name[4].value}normalize(){e(this.endToken)&&(this.endToken=[n.CloseParen,")",-1,-1,void 0])}tokens(){return e(this.endToken)?[this.name,...this.value.flatMap(e=>e.tokens())]:[this.name,...this.value.flatMap(e=>e.tokens()),this.endToken]}toString(){const e=this.value.map(e=>t(e)?o(e):e.toString()).join("");return o(this.name)+e+o(this.endToken)}toJSON(){return{type:this.type,name:this.getName(),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===f.Function)}}function consumeFunction(n,t){const o=[];let s=1;for(;;){const i=t[s];if(!i||e(i))return n.onParseError(new h("Unexpected EOF while consuming a function.",t[0][2],t[t.length-1][3],["5.4.9. Consume a function","Unexpected EOF"])),{advance:t.length,node:new FunctionNode(t[0],i,o)};if(m(i))return{advance:s+1,node:new FunctionNode(t[0],i,o)};if(p(i)){const e=consumeAllCommentsAndWhitespace(n,t.slice(s));s+=e.advance,o.push(...e.nodes);continue}const r=consumeComponentValue(n,t.slice(s));s+=r.advance,o.push(r.node)}}class SimpleBlockNode extends ContainerNodeBaseClass{type=f.SimpleBlock;startToken;endToken;constructor(e,n,t){super(),this.startToken=e,this.endToken=n,this.value=t}normalize(){if(e(this.endToken)){const e=s(this.startToken);e&&(this.endToken=e)}}tokens(){return e(this.endToken)?[this.startToken,...this.value.flatMap(e=>e.tokens())]:[this.startToken,...this.value.flatMap(e=>e.tokens()),this.endToken]}toString(){const e=this.value.map(e=>t(e)?o(e):e.toString()).join("");return o(this.startToken)+e+o(this.endToken)}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===f.SimpleBlock)}}function consumeSimpleBlock(n,t){const o=d(t[0][0]);if(!o)throw new Error("Failed to parse, a mirror variant must exist for all block open tokens.");const s=[];let i=1;for(;;){const r=t[i];if(!r||e(r))return n.onParseError(new h("Unexpected EOF while consuming a simple block.",t[0][2],t[t.length-1][3],["5.4.8. Consume a simple block","Unexpected EOF"])),{advance:t.length,node:new SimpleBlockNode(t[0],r,s)};if(r[0]===o)return{advance:i+1,node:new SimpleBlockNode(t[0],r,s)};if(p(r)){const e=consumeAllCommentsAndWhitespace(n,t.slice(i));i+=e.advance,s.push(...e.nodes);continue}const a=consumeComponentValue(n,t.slice(i));i+=a.advance,s.push(a.node)}}class WhitespaceNode{type=f.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===f.Whitespace)}}function consumeWhitespace(e,n){let t=0;for(;;){const e=n[t];if(!u(e))return{advance:t,node:new WhitespaceNode(n.slice(0,t))};t++}}class CommentNode{type=f.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===f.Comment)}}function consumeComment(e,n){return{advance:1,node:new CommentNode(n[0])}}function consumeAllCommentsAndWhitespace(e,n){const t=[];let o=0;for(;;){if(u(n[o])){const e=consumeWhitespace(0,n.slice(o));o+=e.advance,t.push(e.node);continue}if(!l(n[o]))return{advance:o,nodes:t};t.push(new CommentNode(n[o])),o++}}class TokenNode{type=f.Token;value;constructor(e){this.value=e}tokens(){return[this.value]}toString(){return this.value[1]}toJSON(){return{type:this.type,tokens:this.tokens()}}isTokenNode(){return TokenNode.isTokenNode(this)}static isTokenNode(e){return!!e&&(e instanceof TokenNode&&e.type===f.Token)}}function parseComponentValue(t,o){const s={onParseError:o?.onParseError??(()=>{})},i=[...t];e(i[i.length-1])||i.push([n.EOF,"",i[i.length-1][2],i[i.length-1][3],void 0]);const r=consumeComponentValue(s,i);if(e(i[Math.min(r.advance,i.length-1)]))return r.node;s.onParseError(new h("Expected EOF after parsing a component value.",t[0][2],t[t.length-1][3],["5.3.9. Parse a component value","Expected EOF"]))}function parseListOfComponentValues(t,o){const s={onParseError:o?.onParseError??(()=>{})},i=[...t];e(i[i.length-1])&&i.push([n.EOF,"",i[i.length-1][2],i[i.length-1][3],void 0]);const r=[];let a=0;for(;;){if(!i[a]||e(i[a]))return r;const n=consumeComponentValue(s,i.slice(a));r.push(n.node),a+=n.advance}}function parseCommaSeparatedListOfComponentValues(t,o){const s={onParseError:o?.onParseError??(()=>{})},i=[...t];if(0===t.length)return[];e(i[i.length-1])&&i.push([n.EOF,"",i[i.length-1][2],i[i.length-1][3],void 0]);const r=[];let a=[],c=0;for(;;){if(!i[c]||e(i[c]))return a.length&&r.push(a),r;if(k(i[c])){r.push(a),a=[],c++;continue}const n=consumeComponentValue(s,t.slice(c));a.push(n.node),c+=n.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 forEach(e,n,t){if(0===e.length)return;const o=walkerIndexGenerator(e);let s=0;for(;s<e.length;){const i=e[s];let r;if(t&&(r={...t}),!1===n({node:i,parent:{value:e},state:r},s))return!1;if(s=o(e,i,s),-1===s)break}}function walk(e,n,t){0!==e.length&&forEach(e,(t,o)=>!1!==n(t,o)&&((!("walk"in t.node)||!e.includes(t.node)||!1!==t.node.walk(n,t.state))&&void 0),t)}function replaceComponentValues(e,n){for(let t=0;t<e.length;t++){walk(e[t],(e,t)=>{if("number"!=typeof t)return;const o=n(e.node);o&&(Array.isArray(o)?e.parent.value.splice(t,1,...o):e.parent.value.splice(t,1,o))})}return e}function stringify(e){return e.map(e=>e.map(e=>o(...e.tokens())).join("")).join(",")}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 isWhiteSpaceOrCommentNode(e){return isWhitespaceNode(e)||isCommentNode(e)}function isTokenNode(e){return TokenNode.isTokenNode(e)}function sourceIndices(e){if(Array.isArray(e)){const n=e[0];if(!n)return[0,0];const t=e[e.length-1]||n;return[sourceIndices(n)[0],sourceIndices(t)[1]]}const n=e.tokens(),t=n[0],o=n[n.length-1];return t&&o?[t[2],o[3]]:[0,0]}export{CommentNode,f as ComponentValueType,ContainerNodeBaseClass,FunctionNode,SimpleBlockNode,TokenNode,WhitespaceNode,forEach,gatherNodeAncestry,isCommentNode,isFunctionNode,isSimpleBlockNode,isTokenNode,isWhiteSpaceOrCommentNode,isWhitespaceNode,parseCommaSeparatedListOfComponentValues,parseComponentValue,parseListOfComponentValues,replaceComponentValues,sourceIndices,stringify,walk,walkerIndexGenerator};