1 | import { CssSyntaxError, ProcessOptions } from './postcss.js'
|
2 | import PreviousMap from './previous-map.js'
|
3 |
|
4 | declare namespace Input {
|
5 | export interface FilePosition {
|
6 | /**
|
7 | * Column of inclusive start position in source file.
|
8 | */
|
9 | column: number
|
10 |
|
11 | /**
|
12 | * Column of exclusive end position in source file.
|
13 | */
|
14 | endColumn?: number
|
15 |
|
16 | /**
|
17 | * Line of exclusive end position in source file.
|
18 | */
|
19 | endLine?: number
|
20 |
|
21 | /**
|
22 | * Absolute path to the source file.
|
23 | */
|
24 | file?: string
|
25 |
|
26 | /**
|
27 | * Line of inclusive start position in source file.
|
28 | */
|
29 | line: number
|
30 |
|
31 | /**
|
32 | * Source code.
|
33 | */
|
34 | source?: string
|
35 |
|
36 | /**
|
37 | * URL for the source file.
|
38 | */
|
39 | url: string
|
40 | }
|
41 |
|
42 | // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
43 | export { Input_ as default }
|
44 | }
|
45 |
|
46 | /**
|
47 | * Represents the source CSS.
|
48 | *
|
49 | * ```js
|
50 | * const root = postcss.parse(css, { from: file })
|
51 | * const input = root.source.input
|
52 | * ```
|
53 | */
|
54 | declare class Input_ {
|
55 | /**
|
56 | * Input CSS source.
|
57 | *
|
58 | * ```js
|
59 | * const input = postcss.parse('a{}', { from: file }).input
|
60 | * input.css //=> "a{}"
|
61 | * ```
|
62 | */
|
63 | css: string
|
64 |
|
65 | /**
|
66 | * The absolute path to the CSS source file defined
|
67 | * with the `from` option.
|
68 | *
|
69 | * ```js
|
70 | * const root = postcss.parse(css, { from: 'a.css' })
|
71 | * root.source.input.file //=> '/home/ai/a.css'
|
72 | * ```
|
73 | */
|
74 | file?: string
|
75 |
|
76 | /**
|
77 | * The flag to indicate whether or not the source code has Unicode BOM.
|
78 | */
|
79 | hasBOM: boolean
|
80 |
|
81 | /**
|
82 | * The unique ID of the CSS source. It will be created if `from` option
|
83 | * is not provided (because PostCSS does not know the file path).
|
84 | *
|
85 | * ```js
|
86 | * const root = postcss.parse(css)
|
87 | * root.source.input.file //=> undefined
|
88 | * root.source.input.id //=> "<input css 8LZeVF>"
|
89 | * ```
|
90 | */
|
91 | id?: string
|
92 |
|
93 | /**
|
94 | * The input source map passed from a compilation step before PostCSS
|
95 | * (for example, from Sass compiler).
|
96 | *
|
97 | * ```js
|
98 | * root.source.input.map.consumer().sources //=> ['a.sass']
|
99 | * ```
|
100 | */
|
101 | map: PreviousMap
|
102 |
|
103 | /**
|
104 | * @param css Input CSS source.
|
105 | * @param opts Process options.
|
106 | */
|
107 | constructor(css: string, opts?: ProcessOptions)
|
108 |
|
109 | error(
|
110 | message: string,
|
111 | start:
|
112 | | {
|
113 | column: number
|
114 | line: number
|
115 | }
|
116 | | {
|
117 | offset: number
|
118 | },
|
119 | end:
|
120 | | {
|
121 | column: number
|
122 | line: number
|
123 | }
|
124 | | {
|
125 | offset: number
|
126 | },
|
127 | opts?: { plugin?: CssSyntaxError['plugin'] }
|
128 | ): CssSyntaxError
|
129 |
|
130 | /**
|
131 | * Returns `CssSyntaxError` with information about the error and its position.
|
132 | */
|
133 | error(
|
134 | message: string,
|
135 | line: number,
|
136 | column: number,
|
137 | opts?: { plugin?: CssSyntaxError['plugin'] }
|
138 | ): CssSyntaxError
|
139 |
|
140 | error(
|
141 | message: string,
|
142 | offset: number,
|
143 | opts?: { plugin?: CssSyntaxError['plugin'] }
|
144 | ): CssSyntaxError
|
145 |
|
146 | /**
|
147 | * The CSS source identifier. Contains `Input#file` if the user
|
148 | * set the `from` option, or `Input#id` if they did not.
|
149 | *
|
150 | * ```js
|
151 | * const root = postcss.parse(css, { from: 'a.css' })
|
152 | * root.source.input.from //=> "/home/ai/a.css"
|
153 | *
|
154 | * const root = postcss.parse(css)
|
155 | * root.source.input.from //=> "<input css 1>"
|
156 | * ```
|
157 | */
|
158 | get from(): string
|
159 | /**
|
160 | * Converts source offset to line and column.
|
161 | *
|
162 | * @param offset Source offset.
|
163 | */
|
164 | fromOffset(offset: number): { col: number; line: number } | null
|
165 | /**
|
166 | * Reads the input source map and returns a symbol position
|
167 | * in the input source (e.g., in a Sass file that was compiled
|
168 | * to CSS before being passed to PostCSS). Optionally takes an
|
169 | * end position, exclusive.
|
170 | *
|
171 | * ```js
|
172 | * root.source.input.origin(1, 1) //=> { file: 'a.css', line: 3, column: 1 }
|
173 | * root.source.input.origin(1, 1, 1, 4)
|
174 | * //=> { file: 'a.css', line: 3, column: 1, endLine: 3, endColumn: 4 }
|
175 | * ```
|
176 | *
|
177 | * @param line Line for inclusive start position in input CSS.
|
178 | * @param column Column for inclusive start position in input CSS.
|
179 | * @param endLine Line for exclusive end position in input CSS.
|
180 | * @param endColumn Column for exclusive end position in input CSS.
|
181 | *
|
182 | * @return Position in input source.
|
183 | */
|
184 | origin(
|
185 | line: number,
|
186 | column: number,
|
187 | endLine?: number,
|
188 | endColumn?: number
|
189 | ): false | Input.FilePosition
|
190 | }
|
191 |
|
192 | declare class Input extends Input_ {}
|
193 |
|
194 | export = Input
|