1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | import * as postcss from "postcss";
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export interface NodeBase {
|
20 |
|
21 | next(): ChildNode | void;
|
22 | prev(): ChildNode | void;
|
23 | before(newNode: ChildNode | object | string | ChildNode[]): this;
|
24 | after(newNode: ChildNode | object | string | ChildNode[]): this;
|
25 | root(): Root;
|
26 | replaceWith(...nodes: Array<ChildNode | object>): this;
|
27 |
|
28 |
|
29 | source?: postcss.NodeSource;
|
30 | raws: postcss.NodeRaws;
|
31 | toString(stringifier?: Stringifier | Syntax): string;
|
32 | error(
|
33 | message: string,
|
34 | options?: postcss.NodeErrorOptions
|
35 | ): postcss.CssSyntaxError;
|
36 | warn(
|
37 | result: postcss.Result,
|
38 | text: string,
|
39 | opts?: postcss.WarningOptions
|
40 | ): void;
|
41 | remove(): this;
|
42 | clone(overrides?: object): this;
|
43 | cloneBefore(overrides?: object): this;
|
44 | cloneAfter(overrides?: object): this;
|
45 | raw(prop: string, defaultType?: string): any;
|
46 | }
|
47 |
|
48 | export interface ContainerBase extends NodeBase {
|
49 | walkFuncs(callback: (decl: Func, index: number) => any): boolean | void;
|
50 | walkInterpolations(
|
51 | callback: (interpolation: Interpolation, index: number) => any
|
52 | ): boolean | void;
|
53 | walkNumerics(
|
54 | callback: (numeric: Numeric, index: number) => any
|
55 | ): boolean | void;
|
56 | walkOperators(
|
57 | callback: (operator: Operator, index: number) => any
|
58 | ): boolean | void;
|
59 | walkPunctuations(
|
60 | callback: (punctuation: Punctuation, index: number) => any
|
61 | ): boolean | void;
|
62 | walkQuoteds(callback: (quoted: Quoted, index: number) => any): boolean | void;
|
63 | walkUnicodeRanges(
|
64 | callback: (unicodeRange: UnicodeRange, index: number) => any
|
65 | ): boolean | void;
|
66 | walkWords(callback: (word: Word, index: number) => any): boolean | void;
|
67 | walkType(
|
68 | type: string,
|
69 | callback: (node: ChildNode, index: number) => any
|
70 | ): boolean | void;
|
71 |
|
72 |
|
73 | nodes: ChildNode[];
|
74 | first?: ChildNode;
|
75 | last?: ChildNode;
|
76 | index(child: ChildNode | number): number;
|
77 | every(
|
78 | callback: (node: ChildNode, index: number, nodes: ChildNode[]) => any,
|
79 | thisArg?: any
|
80 | ): boolean;
|
81 | some(
|
82 | callback: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean,
|
83 | thisArg?: any
|
84 | ): boolean;
|
85 | each(callback: (node: ChildNode, index: number) => any): boolean | void;
|
86 | walk(callback: (node: ChildNode, index: number) => any): boolean | void;
|
87 | walkAtWords(callback: (atWord: AtWord, index: number) => any): boolean | void;
|
88 | walkComments(
|
89 | callback: (comment: Comment, index: number) => any
|
90 | ): boolean | void;
|
91 | prepend(...nodes: Array<ChildNode | object | string>): this;
|
92 | append(...nodes: Array<ChildNode | object | string>): this;
|
93 | insertBefore(
|
94 | oldNode: ChildNode | number,
|
95 | newNode: ChildNode | object | string
|
96 | ): this;
|
97 | insertAfter(
|
98 | oldNode: ChildNode | number,
|
99 | newNode: ChildNode | object | string
|
100 | ): this;
|
101 | removeChild(child: ChildNode | number): this;
|
102 |
|
103 |
|
104 | clone(overrides?: object): this;
|
105 | remove(): this;
|
106 | removeAll(): this;
|
107 | }
|
108 |
|
109 | export interface Root extends ContainerBase {
|
110 | type: "root";
|
111 | parent: undefined;
|
112 | toResult(options?: {
|
113 | to?: string;
|
114 | map?: postcss.SourceMapOptions;
|
115 | }): postcss.Result;
|
116 | }
|
117 |
|
118 | export type Node = Root | ChildNode;
|
119 |
|
120 | export type ChildNode =
|
121 | | AtWord
|
122 | | Comment
|
123 | | Func
|
124 | | Interpolation
|
125 | | Numeric
|
126 | | Operator
|
127 | | Punctuation
|
128 | | Quoted
|
129 | | UnicodeRange
|
130 | | Word;
|
131 |
|
132 | export type Container = Root | Func | Interpolation;
|
133 |
|
134 | export interface AtWord extends NodeBase {
|
135 | type: "atrule";
|
136 | parent: Container;
|
137 | name: string;
|
138 | params: string;
|
139 | }
|
140 |
|
141 | export interface Comment extends NodeBase {
|
142 | type: "comment";
|
143 | parent: Container;
|
144 | inline: boolean;
|
145 | text: string;
|
146 | }
|
147 |
|
148 | export interface Func extends ContainerBase {
|
149 | type: "func";
|
150 | parent: Container;
|
151 | isColor: boolean;
|
152 | isVar: boolean;
|
153 | name: string;
|
154 | params: string;
|
155 | }
|
156 |
|
157 | export interface Interpolation extends ContainerBase {
|
158 | type: "interpolation";
|
159 | parent: Container;
|
160 | params: string;
|
161 | prefix: string;
|
162 | }
|
163 |
|
164 | export interface Numeric extends NodeBase {
|
165 | type: "numeric";
|
166 | parent: Container;
|
167 | unit: string;
|
168 | value: string;
|
169 | }
|
170 |
|
171 | export interface Operator extends NodeBase {
|
172 | type: "operator";
|
173 | parent: Container;
|
174 | value: string;
|
175 | }
|
176 |
|
177 | export interface Punctuation extends NodeBase {
|
178 | type: "punctuation";
|
179 | parent: Container;
|
180 | value: string;
|
181 | }
|
182 |
|
183 | export interface Quoted extends NodeBase {
|
184 | type: "quoted";
|
185 | parent: Container;
|
186 | quote: string;
|
187 | value: string;
|
188 | }
|
189 |
|
190 | export interface UnicodeRange extends NodeBase {
|
191 | type: "unicodeRange";
|
192 | parent: Container;
|
193 | name: string;
|
194 | }
|
195 |
|
196 | export interface Word extends NodeBase {
|
197 | type: "word";
|
198 | parent: Container;
|
199 | isColor: boolean;
|
200 | isHex: boolean;
|
201 | isUrl: boolean;
|
202 | isVariable: boolean;
|
203 | value: string;
|
204 | }
|
205 |
|
206 | export function parse(css: string, options?: ParseOptions): Root;
|
207 |
|
208 | export interface ParseOptions {
|
209 | ignoreUnknownWords?: boolean;
|
210 | interpolation?: boolean | InterpolationOptions;
|
211 | variables?: VariablesOptions;
|
212 | }
|
213 |
|
214 | export interface InterpolationOptions {
|
215 | prefix: string;
|
216 | }
|
217 |
|
218 | export interface VariablesOptions {
|
219 | prefixes: string[];
|
220 | }
|
221 |
|
222 | interface Syntax {
|
223 | stringify?: Stringifier;
|
224 | }
|
225 |
|
226 | interface Builder {
|
227 | (part: string, node?: Node, type?: "start" | "end"): void;
|
228 | }
|
229 |
|
230 | export interface Stringifier {
|
231 | (node: Node, builder: Builder): void;
|
232 | }
|
233 |
|
234 | export const stringify: Stringifier;
|
235 |
|
236 | export function nodeToString(node: Node): string;
|