1 import Comment from './comment';
2 import postcss from './postcss';
3 import AtRule from './at-rule';
4 import Node from './node';
5 import Rule from './rule';
7 * Containers can store any content. If you write a rule inside a rule,
8 * PostCSS will parse it.
10 export default class Container extends Node implements postcss.Container {
14 * Contains the container's children.
18 * @param overrides New properties to override in the clone.
19 * @returns A clone of this node. The node and its (cloned) children will
20 * have a clean parent and code style properties.
22 clone(overrides?: Object): any;
23 toJSON(): postcss.JsonContainer;
24 push(child: any): this;
26 * Iterates through the container's immediate children, calling the
27 * callback function for each child. If you need to recursively iterate
28 * through all the container's descendant nodes, use container.walk().
29 * Unlike the for {} -cycle or Array#forEach() this iterator is safe if you
30 * are mutating the array of child nodes during iteration.
31 * @param callback Iterator. Returning false will break iteration. Safe
32 * if you are mutating the array of child nodes during iteration. PostCSS
33 * will adjust the current index to match the mutations.
35 each(callback: (node: Node, index: number) => any): boolean | void;
37 * Traverses the container's descendant nodes, calling `callback` for each
38 * node. Like container.each(), this method is safe to use if you are
39 * mutating arrays during iteration. If you only need to iterate through
40 * the container's immediate children, use container.each().
41 * @param callback Iterator.
43 walk(callback: (node: Node, index: number) => any): boolean | void;
45 * Traverses the container's descendant nodes, calling `callback` for each
46 * declaration. Like container.each(), this method is safe to use if you
47 * are mutating arrays during iteration.
48 * @param propFilter Filters declarations by property name. Only those
49 * declarations whose property matches propFilter will be iterated over.
50 * @param callback Called for each declaration node within the container.
52 walkDecls(propFilter: string | RegExp, callback?: (decl: postcss.Declaration, index: number) => any): boolean | void;
53 walkDecls(callback: (decl: postcss.Declaration, index: number) => any): boolean | void;
55 * Traverses the container's descendant nodes, calling `callback` for each
56 * rule. Like container.each(), this method is safe to use if you are
57 * mutating arrays during iteration.
58 * @param selectorFilter Filters rules by selector. If provided, iteration
59 * will only happen over rules that have matching names.
60 * @param callback Iterator called for each rule node within the
63 walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => any): boolean | void;
64 walkRules(callback: (atRule: Rule, index: number) => any): boolean | void;
66 * Traverses the container's descendant nodes, calling `callback` for each
67 * at-rule. Like container.each(), this method is safe to use if you are
68 * mutating arrays during iteration.
69 * @param nameFilter Filters at-rules by name. If provided, iteration will
70 * only happen over at-rules that have matching names.
71 * @param callback Iterator called for each at-rule node within the
74 walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => any): boolean | void;
75 walkAtRules(callback: (atRule: AtRule, index: number) => any): boolean | void;
77 * Traverses the container's descendant nodes, calling `callback` for each
78 * commennt. Like container.each(), this method is safe to use if you are
79 * mutating arrays during iteration.
80 * @param callback Iterator called for each comment node within the container.
82 walkComments(callback: (comment: Comment, indexed: number) => any): void | boolean;
84 * Inserts new nodes to the end of the container.
85 * Because each node class is identifiable by unique properties, use the
86 * following shortcuts to create nodes in insert methods:
87 * root.append({ name: '@charset', params: '"UTF-8"' }); // at-rule
88 * root.append({ selector: 'a' }); // rule
89 * rule.append({ prop: 'color', value: 'black' }); // declaration
90 * rule.append({ text: 'Comment' }) // comment
91 * A string containing the CSS of the new element can also be used. This
92 * approach is slower than the above shortcuts.
93 * root.append('a {}');
94 * root.first.append('color: black; z-index: 1');
95 * @param nodes New nodes.
96 * @returns This container for chaining.
98 append(...nodes: (Node | Object | string)[]): this;
100 * Inserts new nodes to the beginning of the container.
101 * Because each node class is identifiable by unique properties, use the
102 * following shortcuts to create nodes in insert methods:
103 * root.prepend({ name: 'charset', params: '"UTF-8"' }); // at-rule
104 * root.prepend({ selector: 'a' }); // rule
105 * rule.prepend({ prop: 'color', value: 'black' }); // declaration
106 * rule.prepend({ text: 'Comment' }) // comment
107 * A string containing the CSS of the new element can also be used. This
108 * approach is slower than the above shortcuts.
109 * root.prepend('a {}');
110 * root.first.prepend('color: black; z-index: 1');
111 * @param nodes New nodes.
112 * @returns This container for chaining.
114 prepend(...nodes: (Node | Object | string)[]): this;
115 cleanRaws(keepBetween?: boolean): void;
117 * Insert newNode before oldNode within the container.
118 * @param oldNode Child or child's index.
119 * @returns This container for chaining.
121 insertBefore(oldNode: Node | number, newNode: Node | Object | string): this;
123 * Insert newNode after oldNode within the container.
124 * @param oldNode Child or child's index.
125 * @returns This container for chaining.
127 insertAfter(oldNode: Node | number, newNode: Node | Object | string): this;
129 * Removes the container from its parent and cleans the parent property in the
130 * container and its children.
131 * @returns This container for chaining.
135 * Removes child from the container and clean the parent properties from the
136 * node and its children.
137 * @param child Child or child's index.
138 * @returns This container for chaining.
140 removeChild(child: Node | number): this;
142 * Removes all children from the container and cleans their parent
144 * @returns This container for chaining.
148 * Passes all declaration values within the container that match pattern
149 * through the callback, replacing those values with the returned result of
150 * callback. This method is useful if you are using a custom unit or
151 * function and need to iterate through all values.
152 * @param pattern Pattern that we need to replace.
153 * @param options Options to speed up the search.
154 * @param callbackOrReplaceValue String to replace pattern or callback
155 * that will return a new value. The callback will receive the same
156 * arguments as those passed to a function parameter of String#replace.
158 replaceValues(pattern: string | RegExp, options: {
160 * Property names. The method will only search for values that match
161 * regexp within declarations of listed properties.
165 * Used to narrow down values and speed up the regexp search. Searching
166 * every single value with a regexp can be slow. If you pass a fast
167 * string, PostCSS will first check whether the value contains the fast
168 * string; and only if it does will PostCSS check that value against
169 * regexp. For example, instead of just checking for /\d+rem/ on all
170 * values, set fast: 'rem' to first check whether a value has the rem
171 * unit, and only if it does perform the regexp check.
174 }, callbackOrReplaceValue: string | {
175 (substring: string, ...args: any[]): string;
177 replaceValues(pattern: string | RegExp, callbackOrReplaceValue: string | {
178 (substring: string, ...args: any[]): string;
181 * Determines whether all child nodes satisfy the specified test.
182 * @param callback A function that accepts up to three arguments. The
183 * every method calls the callback function for each node until the
184 * callback returns false, or until the end of the array.
185 * @returns True if the callback returns true for all of the container's
188 every(callback: (node: Node, index: number, nodes: Node[]) => any, thisArg?: any): boolean;
190 * Determines whether the specified callback returns true for any child node.
191 * @param callback A function that accepts up to three arguments. The some
192 * method calls the callback for each node until the callback returns true,
193 * or until the end of the array.
194 * @param thisArg An object to which the this keyword can refer in the
195 * callback function. If thisArg is omitted, undefined is used as the
197 * @returns True if callback returns true for (at least) one of the
198 * container's children.
200 some(callback: (node: Node, index: number, nodes: Node[]) => boolean, thisArg?: any): boolean;
202 * @param child Child of the current container.
203 * @returns The child's index within the container's "nodes" array.
205 index(child: Node | number): number;
207 * @returns The container's first child.
211 * @returns The container's last child.
214 protected normalize(node: Node | string, sample?: Node, type?: string | boolean): Node[];
215 protected normalize(props: postcss.AtRuleNewProps | postcss.RuleNewProps | postcss.DeclarationNewProps | postcss.CommentNewProps, sample?: Node, type?: string | boolean): Node[];
216 rebuild(node: Node, parent?: Container): any;
217 eachInside(callback: any): any;
218 eachDecl(propFilter: any, callback?: any): any;
219 eachRule(selectorFilter: any, callback?: any): any;
220 eachAtRule(nameFilter: any, callback?: any): any;
221 eachComment(selectorFilter: any, callback?: any): any;