UNPKG

2.76 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 selector: string
88
89 /**
90 * An array containing the rule’s individual selectors.
91 * Groups of selectors are split at commas.
92 *
93 * ```js
94 * const root = postcss.parse('a, b { }')
95 * const rule = root.first
96 *
97 * rule.selector //=> 'a, b'
98 * rule.selectors //=> ['a', 'b']
99 *
100 * rule.selectors = ['a', 'strong']
101 * rule.selector //=> 'a, strong'
102 * ```
103 */
104 selectors: string[]
105
106 type: 'rule'
107
108 constructor(defaults?: Rule.RuleProps)
109 assign(overrides: object | Rule.RuleProps): this
110 clone(overrides?: Partial<Rule.RuleProps>): Rule
111 cloneAfter(overrides?: Partial<Rule.RuleProps>): Rule
112 cloneBefore(overrides?: Partial<Rule.RuleProps>): Rule
113}
114
115declare class Rule extends Rule_ {}
116
117export = Rule