UNPKG

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