UNPKG

2.84 kBTypeScriptView Raw
1import Container, {
2 ContainerProps,
3 ContainerWithChildren
4} from './container.js'
5
6declare namespace Rule {
7 export interface RuleRaws extends Record<string, unknown> {
8 /**
9 * The space symbols after the last child of the node to the end of the node.
10 */
11 after?: string
12
13 /**
14 * The space symbols before the node. It also stores `*`
15 * and `_` symbols before the declaration (IE hack).
16 */
17 before?: string
18
19 /**
20 * The symbols between the selector and `{` for rules.
21 */
22 between?: string
23
24 /**
25 * Contains `true` if there is semicolon after rule.
26 */
27 ownSemicolon?: string
28
29 /**
30 * The rule’s selector with comments.
31 */
32 selector?: {
33 raw: string
34 value: string
35 }
36
37 /**
38 * Contains `true` if the last child has an (optional) semicolon.
39 */
40 semicolon?: boolean
41 }
42
43 export interface RuleProps extends ContainerProps {
44 /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
45 raws?: RuleRaws
46 /** Selector or selectors of the rule. */
47 selector?: string
48 /** Selectors of the rule represented as an array of strings. */
49 selectors?: string[]
50 }
51
52 // eslint-disable-next-line @typescript-eslint/no-use-before-define
53 export { Rule_ as default }
54}
55
56/**
57 * Represents a CSS rule: a selector followed by a declaration block.
58 *
59 * ```js
60 * Once (root, { Rule }) {
61 * let a = new Rule({ selector: 'a' })
62 * a.append(…)
63 * root.append(a)
64 * }
65 * ```
66 *
67 * ```js
68 * const root = postcss.parse('a{}')
69 * const rule = root.first
70 * rule.type //=> 'rule'
71 * rule.toString() //=> 'a{}'
72 * ```
73 */
74declare class Rule_ extends Container {
75 nodes: NonNullable<Container['nodes']>
76 parent: ContainerWithChildren | undefined
77 raws: Rule.RuleRaws
78 /**
79 * The rule’s full selector represented as a string.
80 *
81 * ```js
82 * const root = postcss.parse('a, b { }')
83 * const rule = root.first
84 * rule.selector //=> 'a, b'
85 * ```
86 */
87 get selector(): string
88 set selector(value: string);
89
90 /**
91 * An array containing the rule’s individual selectors.
92 * Groups of selectors are split at commas.
93 *
94 * ```js
95 * const root = postcss.parse('a, b { }')
96 * const rule = root.first
97 *
98 * rule.selector //=> 'a, b'
99 * rule.selectors //=> ['a', 'b']
100 *
101 * rule.selectors = ['a', 'strong']
102 * rule.selector //=> 'a, strong'
103 * ```
104 */
105 get selectors(): string[]
106 set selectors(values: string[]);
107
108 type: 'rule'
109
110 constructor(defaults?: Rule.RuleProps)
111 assign(overrides: object | Rule.RuleProps): this
112 clone(overrides?: Partial<Rule.RuleProps>): Rule
113 cloneAfter(overrides?: Partial<Rule.RuleProps>): Rule
114 cloneBefore(overrides?: Partial<Rule.RuleProps>): Rule
115}
116
117declare class Rule extends Rule_ {}
118
119export = Rule