UNPKG

3.35 kBTypeScriptView Raw
1import Container, {
2 ContainerProps,
3 ContainerWithChildren
4} from './container.js'
5
6declare namespace AtRule {
7 export interface AtRuleRaws 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 between the at-rule name and its parameters.
15 */
16 afterName?: string
17
18 /**
19 * The space symbols before the node. It also stores `*`
20 * and `_` symbols before the declaration (IE hack).
21 */
22 before?: string
23
24 /**
25 * The symbols between the last parameter and `{` for rules.
26 */
27 between?: string
28
29 /**
30 * The rule’s selector with comments.
31 */
32 params?: {
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 AtRuleProps extends ContainerProps {
44 /** Name of the at-rule. */
45 name: string
46 /** Parameters following the name of the at-rule. */
47 params?: number | string
48 /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
49 raws?: AtRuleRaws
50 }
51
52 // eslint-disable-next-line @typescript-eslint/no-use-before-define
53 export { AtRule_ as default }
54}
55
56/**
57 * Represents an at-rule.
58 *
59 * ```js
60 * Once (root, { AtRule }) {
61 * let media = new AtRule({ name: 'media', params: 'print' })
62 * media.append(…)
63 * root.append(media)
64 * }
65 * ```
66 *
67 * If it’s followed in the CSS by a `{}` block, this node will have
68 * a nodes property representing its children.
69 *
70 * ```js
71 * const root = postcss.parse('@charset "UTF-8"; @media print {}')
72 *
73 * const charset = root.first
74 * charset.type //=> 'atrule'
75 * charset.nodes //=> undefined
76 *
77 * const media = root.last
78 * media.nodes //=> []
79 * ```
80 */
81declare class AtRule_ extends Container {
82 /**
83 * The at-rule’s name immediately follows the `@`.
84 *
85 * ```js
86 * const root = postcss.parse('@media print {}')
87 * const media = root.first
88 * media.name //=> 'media'
89 * ```
90 */
91 name: string
92 /**
93 * An array containing the layer’s children.
94 *
95 * ```js
96 * const root = postcss.parse('@layer example { a { color: black } }')
97 * const layer = root.first
98 * layer.nodes.length //=> 1
99 * layer.nodes[0].selector //=> 'a'
100 * ```
101 *
102 * Can be `undefinded` if the at-rule has no body.
103 *
104 * ```js
105 * const root = postcss.parse('@layer a, b, c;')
106 * const layer = root.first
107 * layer.nodes //=> undefined
108 * ```
109 */
110 nodes: Container['nodes']
111 /**
112 * The at-rule’s parameters, the values that follow the at-rule’s name
113 * but precede any `{}` block.
114 *
115 * ```js
116 * const root = postcss.parse('@media print, screen {}')
117 * const media = root.first
118 * media.params //=> 'print, screen'
119 * ```
120 */
121 params: string
122 parent: ContainerWithChildren | undefined
123
124 raws: AtRule.AtRuleRaws
125
126 type: 'atrule'
127
128 constructor(defaults?: AtRule.AtRuleProps)
129 assign(overrides: AtRule.AtRuleProps | object): this
130 clone(overrides?: Partial<AtRule.AtRuleProps>): AtRule
131 cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): AtRule
132 cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): AtRule
133}
134
135declare class AtRule extends AtRule_ {}
136
137export = AtRule