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