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