import { ParseError } from "./errors"; import { SourceLocation } from "./locations"; import { Token } from "./tokens"; export interface INode { type: string; parent: IContainer | INode | null; raws: { before: string; } | { after: string; }; source: SourceLocation; toString(): string; walk(type: string | RegExp, callback: (node: any) => boolean | void): boolean | void; } export interface IContainer extends INode { readonly nodes: INode[]; readonly first: INode | null; readonly last: INode | null; removeAll(): this; removeChild(child: INode): this; push(child: INode): this; append(...children: INode[]): this; prepend(...children: INode[]): this; insertBefore(exist: INode, add: INode): this; insertAfter(exist: INode, add: INode): this; } export declare type Expression = NumberValue | LengthValue | AngleValue | TimeValue | FrequencyValue | ResolutionValue | PercentageValue | FlexValue | Word | MathExpression | FunctionNode | Parentheses | StringNode; export interface NumberValue extends INode { type: "Number"; value: number; raws: { before: string; value: { raw: string; value: number; }; }; } export interface LengthValue extends INode { type: "Length"; value: number; unit: LengthUnit; raws: { before: string; value: { raw: string; value: number; }; unit?: { raw: string; value: string; }; }; } export declare type LengthUnit = "em" | "ex" | "ch" | "rem" | "vw" | "vh" | "vmin" | "vmax" | "px" | "mm" | "cm" | "in" | "pt" | "pc" | "Q" | "vm"; export interface AngleValue extends INode { type: "Angle"; value: number; unit: AngleUnit; raws: { before: string; value: { raw: string; value: number; }; unit?: { raw: string; value: string; }; }; } export declare type AngleUnit = "deg" | "grad" | "turn" | "rad"; export interface TimeValue extends INode { type: "Time"; value: number; unit: TimeUnit; raws: { before: string; value: { raw: string; value: number; }; unit?: { raw: string; value: string; }; }; } export declare type TimeUnit = "s" | "ms"; export interface FrequencyValue extends INode { type: "Frequency"; value: number; unit: FrequencyUnit; raws: { before: string; value: { raw: string; value: number; }; unit?: { raw: string; value: string; }; }; } export declare type FrequencyUnit = "Hz" | "kHz"; export interface ResolutionValue extends INode { type: "Resolution"; value: number; unit: ResolutionUnit; raws: { before: string; value: { raw: string; value: number; }; unit?: { raw: string; value: string; }; }; } export declare type ResolutionUnit = "dpi" | "dpcm" | "dppm"; export interface PercentageValue extends INode { type: "Percentage"; value: number; unit: "%"; raws: { before: string; value: { raw: string; value: number; }; unit?: { raw: string; value: string; }; }; } export interface FlexValue extends INode { type: "Flex"; value: number; unit: FlexUnit; raws: { before: string; value: { raw: string; value: number; }; unit?: { raw: string; value: string; }; }; } export declare type FlexUnit = "fr"; export interface Word extends INode { type: "Word"; value: string; raws: { before: string; }; } export interface MathExpression extends INode { type: "MathExpression"; left: Expression; operator: "+" | "-" | "*" | "/"; right: Expression; raws: { before: string; between: string; }; source: { operator: SourceLocation; } & SourceLocation; } export interface FunctionNode extends IContainer { type: "Function"; name: string; nodes: (Expression | Other)[]; raws: { before: string; beforeClose?: string; }; unclosed?: boolean; } export interface Parentheses extends IContainer { type: "Parentheses"; nodes: (Expression | Other)[]; raws: { before: string; beforeClose?: string; }; unclosed?: boolean; } export interface StringNode extends INode { type: "String"; value: string; raws: { before: string; }; } export interface Root extends IContainer { type: "Root"; nodes: (Expression | Other)[]; tokens: Token[]; errors: ParseError[]; raws: { after: string; }; } export declare type Other = Operator | Punctuator; export interface Punctuator extends INode { type: "Punctuator"; value: "," | ")"; raws: { before: string; }; } export interface Operator extends INode { type: "Operator"; value: "+" | "-" | "*" | "/"; raws: { before: string; }; } export declare type Node = Expression | Other | Root;