source: node_modules/postcss/lib/input.d.ts@ 57e58a3

Last change on this file since 57e58a3 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 4.7 KB
Line 
1import { CssSyntaxError, ProcessOptions } from './postcss.js'
2import PreviousMap from './previous-map.js'
3
4declare 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 */
54declare 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 * Input source with support for non-CSS documents.
67 *
68 * ```js
69 * const input = postcss.parse('a{}', { from: file, document: '<style>a {}</style>' }).input
70 * input.document //=> "<style>a {}</style>"
71 * input.css //=> "a{}"
72 * ```
73 */
74 document: string
75
76 /**
77 * The absolute path to the CSS source file defined
78 * with the `from` option.
79 *
80 * ```js
81 * const root = postcss.parse(css, { from: 'a.css' })
82 * root.source.input.file //=> '/home/ai/a.css'
83 * ```
84 */
85 file?: string
86
87 /**
88 * The flag to indicate whether or not the source code has Unicode BOM.
89 */
90 hasBOM: boolean
91
92 /**
93 * The unique ID of the CSS source. It will be created if `from` option
94 * is not provided (because PostCSS does not know the file path).
95 *
96 * ```js
97 * const root = postcss.parse(css)
98 * root.source.input.file //=> undefined
99 * root.source.input.id //=> "<input css 8LZeVF>"
100 * ```
101 */
102 id?: string
103
104 /**
105 * The input source map passed from a compilation step before PostCSS
106 * (for example, from Sass compiler).
107 *
108 * ```js
109 * root.source.input.map.consumer().sources //=> ['a.sass']
110 * ```
111 */
112 map: PreviousMap
113
114 /**
115 * @param css Input CSS source.
116 * @param opts Process options.
117 */
118 constructor(css: string, opts?: ProcessOptions)
119
120 error(
121 message: string,
122 start:
123 | {
124 column: number
125 line: number
126 }
127 | {
128 offset: number
129 },
130 end:
131 | {
132 column: number
133 line: number
134 }
135 | {
136 offset: number
137 },
138 opts?: { plugin?: CssSyntaxError['plugin'] }
139 ): CssSyntaxError
140
141 /**
142 * Returns `CssSyntaxError` with information about the error and its position.
143 */
144 error(
145 message: string,
146 line: number,
147 column: number,
148 opts?: { plugin?: CssSyntaxError['plugin'] }
149 ): CssSyntaxError
150
151 error(
152 message: string,
153 offset: number,
154 opts?: { plugin?: CssSyntaxError['plugin'] }
155 ): CssSyntaxError
156
157 /**
158 * Converts source offset to line and column.
159 *
160 * @param offset Source offset.
161 */
162 fromOffset(offset: number): { col: number; line: number } | null
163 /**
164 * Reads the input source map and returns a symbol position
165 * in the input source (e.g., in a Sass file that was compiled
166 * to CSS before being passed to PostCSS). Optionally takes an
167 * end position, exclusive.
168 *
169 * ```js
170 * root.source.input.origin(1, 1) //=> { file: 'a.css', line: 3, column: 1 }
171 * root.source.input.origin(1, 1, 1, 4)
172 * //=> { file: 'a.css', line: 3, column: 1, endLine: 3, endColumn: 4 }
173 * ```
174 *
175 * @param line Line for inclusive start position in input CSS.
176 * @param column Column for inclusive start position in input CSS.
177 * @param endLine Line for exclusive end position in input CSS.
178 * @param endColumn Column for exclusive end position in input CSS.
179 *
180 * @return Position in input source.
181 */
182 origin(
183 line: number,
184 column: number,
185 endLine?: number,
186 endColumn?: number
187 ): false | Input.FilePosition
188 /** Converts this to a JSON-friendly object representation. */
189 toJSON(): object
190
191 /**
192 * The CSS source identifier. Contains `Input#file` if the user
193 * set the `from` option, or `Input#id` if they did not.
194 *
195 * ```js
196 * const root = postcss.parse(css, { from: 'a.css' })
197 * root.source.input.from //=> "/home/ai/a.css"
198 *
199 * const root = postcss.parse(css)
200 * root.source.input.from //=> "<input css 1>"
201 * ```
202 */
203 get from(): string
204}
205
206declare class Input extends Input_ {}
207
208export = Input
Note: See TracBrowser for help on using the repository browser.