1 | import Container, { ContainerProps } from './container.js'
|
2 |
|
3 | interface AtRuleRaws 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 space between the at-rule name and its parameters.
|
17 | */
|
18 | afterName?: string
|
19 |
|
20 | /**
|
21 | * The symbols between the last parameter and `{` for rules.
|
22 | */
|
23 | between?: string
|
24 |
|
25 | /**
|
26 | * Contains `true` if the last child has an (optional) semicolon.
|
27 | */
|
28 | semicolon?: boolean
|
29 |
|
30 | /**
|
31 | * The rule’s selector with comments.
|
32 | */
|
33 | params?: {
|
34 | value: string
|
35 | raw: string
|
36 | }
|
37 | }
|
38 |
|
39 | export interface AtRuleProps extends ContainerProps {
|
40 | /** Name of the at-rule. */
|
41 | name: string
|
42 | /** Parameters following the name of the at-rule. */
|
43 | params?: string | number
|
44 | /** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
45 | raws?: AtRuleRaws
|
46 | }
|
47 |
|
48 | /**
|
49 | * Represents an at-rule.
|
50 | *
|
51 | * ```js
|
52 | * Once (root, { AtRule }) {
|
53 | * let media = new AtRule({ name: 'media', params: 'print' })
|
54 | * media.append(…)
|
55 | * root.append(media)
|
56 | * }
|
57 | * ```
|
58 | *
|
59 | * If it’s followed in the CSS by a {} block, this node will have
|
60 | * a nodes property representing its children.
|
61 | *
|
62 | * ```js
|
63 | * const root = postcss.parse('@charset "UTF-8"; @media print {}')
|
64 | *
|
65 | * const charset = root.first
|
66 | * charset.type //=> 'atrule'
|
67 | * charset.nodes //=> undefined
|
68 | *
|
69 | * const media = root.last
|
70 | * media.nodes //=> []
|
71 | * ```
|
72 | */
|
73 | export default class AtRule extends Container {
|
74 | type: 'atrule'
|
75 | parent: Container | undefined
|
76 | raws: AtRuleRaws
|
77 |
|
78 | /**
|
79 | * The at-rule’s name immediately follows the `@`.
|
80 | *
|
81 | * ```js
|
82 | * const root = postcss.parse('@media print {}')
|
83 | * media.name //=> 'media'
|
84 | * const media = root.first
|
85 | * ```
|
86 | */
|
87 | name: string
|
88 |
|
89 | /**
|
90 | * The at-rule’s parameters, the values that follow the at-rule’s name
|
91 | * but precede any {} block.
|
92 | *
|
93 | * ```js
|
94 | * const root = postcss.parse('@media print, screen {}')
|
95 | * const media = root.first
|
96 | * media.params //=> 'print, screen'
|
97 | * ```
|
98 | */
|
99 | params: string
|
100 |
|
101 | constructor(defaults?: AtRuleProps)
|
102 | assign(overrides: object | AtRuleProps): this
|
103 | clone(overrides?: Partial<AtRuleProps>): this
|
104 | cloneBefore(overrides?: Partial<AtRuleProps>): this
|
105 | cloneAfter(overrides?: Partial<AtRuleProps>): this
|
106 | }
|