update at 2025-09-22 13:55:41

This commit is contained in:
douboer
2025-09-22 13:55:41 +08:00
parent f33b2ee535
commit 0090ce9b93
85 changed files with 20418 additions and 0 deletions

140
src/postcss/at-rule.d.ts vendored Normal file
View File

@@ -0,0 +1,140 @@
import Container, {
ContainerProps,
ContainerWithChildren
} from './container.js'
declare namespace AtRule {
export interface AtRuleRaws extends Record<string, unknown> {
/**
* The space symbols after the last child of the node to the end of the node.
*/
after?: string
/**
* The space between the at-rule name and its parameters.
*/
afterName?: string
/**
* The space symbols before the node. It also stores `*`
* and `_` symbols before the declaration (IE hack).
*/
before?: string
/**
* The symbols between the last parameter and `{` for rules.
*/
between?: string
/**
* The rules selector with comments.
*/
params?: {
raw: string
value: string
}
/**
* Contains `true` if the last child has an (optional) semicolon.
*/
semicolon?: boolean
}
export interface AtRuleProps extends ContainerProps {
/** Name of the at-rule. */
name: string
/** Parameters following the name of the at-rule. */
params?: number | string
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: AtRuleRaws
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { AtRule_ as default }
}
/**
* Represents an at-rule.
*
* ```js
* Once (root, { AtRule }) {
* let media = new AtRule({ name: 'media', params: 'print' })
* media.append(…)
* root.append(media)
* }
* ```
*
* If its followed in the CSS by a `{}` block, this node will have
* a nodes property representing its children.
*
* ```js
* const root = postcss.parse('@charset "UTF-8"; @media print {}')
*
* const charset = root.first
* charset.type //=> 'atrule'
* charset.nodes //=> undefined
*
* const media = root.last
* media.nodes //=> []
* ```
*/
declare class AtRule_ extends Container {
/**
* The at-rules name immediately follows the `@`.
*
* ```js
* const root = postcss.parse('@media print {}')
* const media = root.first
* media.name //=> 'media'
* ```
*/
get name(): string
set name(value: string)
/**
* An array containing the layers children.
*
* ```js
* const root = postcss.parse('@layer example { a { color: black } }')
* const layer = root.first
* layer.nodes.length //=> 1
* layer.nodes[0].selector //=> 'a'
* ```
*
* Can be `undefinded` if the at-rule has no body.
*
* ```js
* const root = postcss.parse('@layer a, b, c;')
* const layer = root.first
* layer.nodes //=> undefined
* ```
*/
nodes: Container['nodes']
/**
* The at-rules parameters, the values that follow the at-rules name
* but precede any `{}` block.
*
* ```js
* const root = postcss.parse('@media print, screen {}')
* const media = root.first
* media.params //=> 'print, screen'
* ```
*/
get params(): string
set params(value: string)
parent: ContainerWithChildren | undefined
raws: AtRule.AtRuleRaws
type: 'atrule'
constructor(defaults?: AtRule.AtRuleProps)
assign(overrides: AtRule.AtRuleProps | object): this
clone(overrides?: Partial<AtRule.AtRuleProps>): AtRule
cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): AtRule
cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): AtRule
}
declare class AtRule extends AtRule_ {}
export = AtRule

68
src/postcss/comment.d.ts vendored Normal file
View File

@@ -0,0 +1,68 @@
import Container from './container.js'
import Node, { NodeProps } from './node.js'
declare namespace Comment {
export interface CommentRaws extends Record<string, unknown> {
/**
* The space symbols before the node.
*/
before?: string
/**
* The space symbols between `/*` and the comments text.
*/
left?: string
/**
* The space symbols between the comments text.
*/
right?: string
}
export interface CommentProps extends NodeProps {
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: CommentRaws
/** Content of the comment. */
text: string
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Comment_ as default }
}
/**
* It represents a class that handles
* [CSS comments](https://developer.mozilla.org/en-US/docs/Web/CSS/Comments)
*
* ```js
* Once (root, { Comment }) {
* const note = new Comment({ text: 'Note: …' })
* root.append(note)
* }
* ```
*
* Remember that CSS comments inside selectors, at-rule parameters,
* or declaration values will be stored in the `raws` properties
* explained above.
*/
declare class Comment_ extends Node {
parent: Container | undefined
raws: Comment.CommentRaws
/**
* The comment's text.
*/
get text(): string
set text(value: string)
type: 'comment'
constructor(defaults?: Comment.CommentProps)
assign(overrides: Comment.CommentProps | object): this
clone(overrides?: Partial<Comment.CommentProps>): Comment
cloneAfter(overrides?: Partial<Comment.CommentProps>): Comment
cloneBefore(overrides?: Partial<Comment.CommentProps>): Comment
}
declare class Comment extends Comment_ {}
export = Comment

490
src/postcss/container.d.ts vendored Normal file
View File

@@ -0,0 +1,490 @@
import AtRule from './at-rule.js'
import Comment from './comment.js'
import Declaration from './declaration.js'
import Node, { ChildNode, ChildProps, NodeProps } from './node.js'
import Rule from './rule.js'
declare namespace Container {
export class ContainerWithChildren<
Child extends Node = ChildNode
> extends Container_<Child> {
nodes: Child[]
}
export interface ValueOptions {
/**
* String thats used to narrow down values and speed up the regexp search.
*/
fast?: string
/**
* An array of property names.
*/
props?: string[]
}
export interface ContainerProps extends NodeProps {
nodes?: (ChildNode | ChildProps)[]
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Container_ as default }
}
/**
* The `Root`, `AtRule`, and `Rule` container nodes
* inherit some common methods to help work with their children.
*
* Note that all containers can store any content. If you write a rule inside
* a rule, PostCSS will parse it.
*/
declare abstract class Container_<Child extends Node = ChildNode> extends Node {
/**
* An array containing the containers children.
*
* ```js
* const root = postcss.parse('a { color: black }')
* root.nodes.length //=> 1
* root.nodes[0].selector //=> 'a'
* root.nodes[0].nodes[0].prop //=> 'color'
* ```
*/
nodes: Child[] | undefined
/**
* Inserts new nodes to the end of the container.
*
* ```js
* const decl1 = new Declaration({ prop: 'color', value: 'black' })
* const decl2 = new Declaration({ prop: 'background-color', value: 'white' })
* rule.append(decl1, decl2)
*
* root.append({ name: 'charset', params: '"UTF-8"' }) // at-rule
* root.append({ selector: 'a' }) // rule
* rule.append({ prop: 'color', value: 'black' }) // declaration
* rule.append({ text: 'Comment' }) // comment
*
* root.append('a {}')
* root.first.append('color: black; z-index: 1')
* ```
*
* @param nodes New nodes.
* @return This node for methods chain.
*/
append(
...nodes: (
| ChildProps
| ChildProps[]
| Node
| Node[]
| string
| string[]
| undefined
)[]
): this
assign(overrides: Container.ContainerProps | object): this
clone(overrides?: Partial<Container.ContainerProps>): Container<Child>
cloneAfter(overrides?: Partial<Container.ContainerProps>): Container<Child>
cloneBefore(overrides?: Partial<Container.ContainerProps>): Container<Child>
/**
* Iterates through the containers immediate children,
* calling `callback` for each child.
*
* Returning `false` in the callback will break iteration.
*
* This method only iterates through the containers immediate children.
* If you need to recursively iterate through all the containers descendant
* nodes, use `Container#walk`.
*
* Unlike the for `{}`-cycle or `Array#forEach` this iterator is safe
* if you are mutating the array of child nodes during iteration.
* PostCSS will adjust the current index to match the mutations.
*
* ```js
* const root = postcss.parse('a { color: black; z-index: 1 }')
* const rule = root.first
*
* for (const decl of rule.nodes) {
* decl.cloneBefore({ prop: '-webkit-' + decl.prop })
* // Cycle will be infinite, because cloneBefore moves the current node
* // to the next index
* }
*
* rule.each(decl => {
* decl.cloneBefore({ prop: '-webkit-' + decl.prop })
* // Will be executed only for color and z-index
* })
* ```
*
* @param callback Iterator receives each node and index.
* @return Returns `false` if iteration was broke.
*/
each(
callback: (node: Child, index: number) => false | void
): false | undefined
/**
* Returns `true` if callback returns `true`
* for all of the containers children.
*
* ```js
* const noPrefixes = rule.every(i => i.prop[0] !== '-')
* ```
*
* @param condition Iterator returns true or false.
* @return Is every child pass condition.
*/
every(
condition: (node: Child, index: number, nodes: Child[]) => boolean
): boolean
/**
* Returns a `child`s index within the `Container#nodes` array.
*
* ```js
* rule.index( rule.nodes[2] ) //=> 2
* ```
*
* @param child Child of the current container.
* @return Child index.
*/
index(child: Child | number): number
/**
* Insert new node after old node within the container.
*
* @param oldNode Child or childs index.
* @param newNode New node.
* @return This node for methods chain.
*/
insertAfter(
oldNode: Child | number,
newNode:
| Child
| Child[]
| ChildProps
| ChildProps[]
| string
| string[]
| undefined
): this
/**
* Insert new node before old node within the container.
*
* ```js
* rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }))
* ```
*
* @param oldNode Child or childs index.
* @param newNode New node.
* @return This node for methods chain.
*/
insertBefore(
oldNode: Child | number,
newNode:
| Child
| Child[]
| ChildProps
| ChildProps[]
| string
| string[]
| undefined
): this
/**
* Traverses the containers descendant nodes, calling callback
* for each comment node.
*
* Like `Container#each`, this method is safe
* to use if you are mutating arrays during iteration.
*
* ```js
* root.walkComments(comment => {
* comment.remove()
* })
* ```
*
* @param callback Iterator receives each node and index.
* @return Returns `false` if iteration was broke.
*/
/**
* Inserts new nodes to the start of the container.
*
* ```js
* const decl1 = new Declaration({ prop: 'color', value: 'black' })
* const decl2 = new Declaration({ prop: 'background-color', value: 'white' })
* rule.prepend(decl1, decl2)
*
* root.append({ name: 'charset', params: '"UTF-8"' }) // at-rule
* root.append({ selector: 'a' }) // rule
* rule.append({ prop: 'color', value: 'black' }) // declaration
* rule.append({ text: 'Comment' }) // comment
*
* root.append('a {}')
* root.first.append('color: black; z-index: 1')
* ```
*
* @param nodes New nodes.
* @return This node for methods chain.
*/
prepend(
...nodes: (
| ChildProps
| ChildProps[]
| Node
| Node[]
| string
| string[]
| undefined
)[]
): this
/**
* Add child to the end of the node.
*
* ```js
* rule.push(new Declaration({ prop: 'color', value: 'black' }))
* ```
*
* @param child New node.
* @return This node for methods chain.
*/
push(child: Child): this
/**
* Removes all children from the container
* and cleans their parent properties.
*
* ```js
* rule.removeAll()
* rule.nodes.length //=> 0
* ```
*
* @return This node for methods chain.
*/
removeAll(): this
/**
* Removes node from the container and cleans the parent properties
* from the node and its children.
*
* ```js
* rule.nodes.length //=> 5
* rule.removeChild(decl)
* rule.nodes.length //=> 4
* decl.parent //=> undefined
* ```
*
* @param child Child or childs index.
* @return This node for methods chain.
*/
removeChild(child: Child | number): this
replaceValues(
pattern: RegExp | string,
replaced: { (substring: string, ...args: any[]): string } | string
): this
/**
* Passes all declaration values within the container that match pattern
* through callback, replacing those values with the returned result
* of callback.
*
* This method is useful if you are using a custom unit or function
* and need to iterate through all values.
*
* ```js
* root.replaceValues(/\d+rem/, { fast: 'rem' }, string => {
* return 15 * parseInt(string) + 'px'
* })
* ```
*
* @param pattern Replace pattern.
* @param {object} opts Options to speed up the search.
* @param callback String to replace pattern or callback
* that returns a new value. The callback
* will receive the same arguments
* as those passed to a function parameter
* of `String#replace`.
* @return This node for methods chain.
*/
replaceValues(
pattern: RegExp | string,
options: Container.ValueOptions,
replaced: { (substring: string, ...args: any[]): string } | string
): this
/**
* Returns `true` if callback returns `true` for (at least) one
* of the containers children.
*
* ```js
* const hasPrefix = rule.some(i => i.prop[0] === '-')
* ```
*
* @param condition Iterator returns true or false.
* @return Is some child pass condition.
*/
some(
condition: (node: Child, index: number, nodes: Child[]) => boolean
): boolean
/**
* Traverses the containers descendant nodes, calling callback
* for each node.
*
* Like container.each(), this method is safe to use
* if you are mutating arrays during iteration.
*
* If you only need to iterate through the containers immediate children,
* use `Container#each`.
*
* ```js
* root.walk(node => {
* // Traverses all descendant nodes.
* })
* ```
*
* @param callback Iterator receives each node and index.
* @return Returns `false` if iteration was broke.
*/
walk(
callback: (node: ChildNode, index: number) => false | void
): false | undefined
/**
* Traverses the containers descendant nodes, calling callback
* for each at-rule node.
*
* If you pass a filter, iteration will only happen over at-rules
* that have matching names.
*
* Like `Container#each`, this method is safe
* to use if you are mutating arrays during iteration.
*
* ```js
* root.walkAtRules(rule => {
* if (isOld(rule.name)) rule.remove()
* })
*
* let first = false
* root.walkAtRules('charset', rule => {
* if (!first) {
* first = true
* } else {
* rule.remove()
* }
* })
* ```
*
* @param name String or regular expression to filter at-rules by name.
* @param callback Iterator receives each node and index.
* @return Returns `false` if iteration was broke.
*/
walkAtRules(
nameFilter: RegExp | string,
callback: (atRule: AtRule, index: number) => false | void
): false | undefined
walkAtRules(
callback: (atRule: AtRule, index: number) => false | void
): false | undefined
walkComments(
callback: (comment: Comment, indexed: number) => false | void
): false | undefined
walkComments(
callback: (comment: Comment, indexed: number) => false | void
): false | undefined
/**
* Traverses the containers descendant nodes, calling callback
* for each declaration node.
*
* If you pass a filter, iteration will only happen over declarations
* with matching properties.
*
* ```js
* root.walkDecls(decl => {
* checkPropertySupport(decl.prop)
* })
*
* root.walkDecls('border-radius', decl => {
* decl.remove()
* })
*
* root.walkDecls(/^background/, decl => {
* decl.value = takeFirstColorFromGradient(decl.value)
* })
* ```
*
* Like `Container#each`, this method is safe
* to use if you are mutating arrays during iteration.
*
* @param prop String or regular expression to filter declarations
* by property name.
* @param callback Iterator receives each node and index.
* @return Returns `false` if iteration was broke.
*/
walkDecls(
propFilter: RegExp | string,
callback: (decl: Declaration, index: number) => false | void
): false | undefined
walkDecls(
callback: (decl: Declaration, index: number) => false | void
): false | undefined
/**
* Traverses the containers descendant nodes, calling callback
* for each rule node.
*
* If you pass a filter, iteration will only happen over rules
* with matching selectors.
*
* Like `Container#each`, this method is safe
* to use if you are mutating arrays during iteration.
*
* ```js
* const selectors = []
* root.walkRules(rule => {
* selectors.push(rule.selector)
* })
* console.log(`Your CSS uses ${ selectors.length } selectors`)
* ```
*
* @param selector String or regular expression to filter rules by selector.
* @param callback Iterator receives each node and index.
* @return Returns `false` if iteration was broke.
*/
walkRules(
selectorFilter: RegExp | string,
callback: (rule: Rule, index: number) => false | void
): false | undefined
walkRules(
callback: (rule: Rule, index: number) => false | void
): false | undefined
/**
* The containers first child.
*
* ```js
* rule.first === rules.nodes[0]
* ```
*/
get first(): Child | undefined
/**
* The containers last child.
*
* ```js
* rule.last === rule.nodes[rule.nodes.length - 1]
* ```
*/
get last(): Child | undefined
}
declare class Container<
Child extends Node = ChildNode
> extends Container_<Child> {}
export = Container

248
src/postcss/css-syntax-error.d.ts vendored Normal file
View File

@@ -0,0 +1,248 @@
import { FilePosition } from './input.js'
declare namespace CssSyntaxError {
/**
* A position that is part of a range.
*/
export interface RangePosition {
/**
* The column number in the input.
*/
column: number
/**
* The line number in the input.
*/
line: number
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { CssSyntaxError_ as default }
}
/**
* The CSS parser throws this error for broken CSS.
*
* Custom parsers can throw this error for broken custom syntax using
* the `Node#error` method.
*
* PostCSS will use the input source map to detect the original error location.
* If you wrote a Sass file, compiled it to CSS and then parsed it with PostCSS,
* PostCSS will show the original position in the Sass file.
*
* If you need the position in the PostCSS input
* (e.g., to debug the previous compiler), use `error.input.file`.
*
* ```js
* // Raising error from plugin
* throw node.error('Unknown variable', { plugin: 'postcss-vars' })
* ```
*
* ```js
* // Catching and checking syntax error
* try {
* postcss.parse('a{')
* } catch (error) {
* if (error.name === 'CssSyntaxError') {
* error //=> CssSyntaxError
* }
* }
* ```
*/
declare class CssSyntaxError_ extends Error {
/**
* Source column of the error.
*
* ```js
* error.column //=> 1
* error.input.column //=> 4
* ```
*
* PostCSS will use the input source map to detect the original location.
* If you need the position in the PostCSS input, use `error.input.column`.
*/
column?: number
/**
* Source column of the error's end, exclusive. Provided if the error pertains
* to a range.
*
* ```js
* error.endColumn //=> 1
* error.input.endColumn //=> 4
* ```
*
* PostCSS will use the input source map to detect the original location.
* If you need the position in the PostCSS input, use `error.input.endColumn`.
*/
endColumn?: number
/**
* Source line of the error's end, exclusive. Provided if the error pertains
* to a range.
*
* ```js
* error.endLine //=> 3
* error.input.endLine //=> 4
* ```
*
* PostCSS will use the input source map to detect the original location.
* If you need the position in the PostCSS input, use `error.input.endLine`.
*/
endLine?: number
/**
* Absolute path to the broken file.
*
* ```js
* error.file //=> 'a.sass'
* error.input.file //=> 'a.css'
* ```
*
* PostCSS will use the input source map to detect the original location.
* If you need the position in the PostCSS input, use `error.input.file`.
*/
file?: string
/**
* Input object with PostCSS internal information
* about input file. If input has source map
* from previous tool, PostCSS will use origin
* (for example, Sass) source. You can use this
* object to get PostCSS input source.
*
* ```js
* error.input.file //=> 'a.css'
* error.file //=> 'a.sass'
* ```
*/
input?: FilePosition
/**
* Source line of the error.
*
* ```js
* error.line //=> 2
* error.input.line //=> 4
* ```
*
* PostCSS will use the input source map to detect the original location.
* If you need the position in the PostCSS input, use `error.input.line`.
*/
line?: number
/**
* Full error text in the GNU error format
* with plugin, file, line and column.
*
* ```js
* error.message //=> 'a.css:1:1: Unclosed block'
* ```
*/
message: string
/**
* Always equal to `'CssSyntaxError'`. You should always check error type
* by `error.name === 'CssSyntaxError'`
* instead of `error instanceof CssSyntaxError`,
* because npm could have several PostCSS versions.
*
* ```js
* if (error.name === 'CssSyntaxError') {
* error //=> CssSyntaxError
* }
* ```
*/
name: 'CssSyntaxError'
/**
* Plugin name, if error came from plugin.
*
* ```js
* error.plugin //=> 'postcss-vars'
* ```
*/
plugin?: string
/**
* Error message.
*
* ```js
* error.message //=> 'Unclosed block'
* ```
*/
reason: string
/**
* Source code of the broken file.
*
* ```js
* error.source //=> 'a { b {} }'
* error.input.source //=> 'a b { }'
* ```
*/
source?: string
stack: string
/**
* Instantiates a CSS syntax error. Can be instantiated for a single position
* or for a range.
* @param message Error message.
* @param lineOrStartPos If for a single position, the line number, or if for
* a range, the inclusive start position of the error.
* @param columnOrEndPos If for a single position, the column number, or if for
* a range, the exclusive end position of the error.
* @param source Source code of the broken file.
* @param file Absolute path to the broken file.
* @param plugin PostCSS plugin name, if error came from plugin.
*/
constructor(
message: string,
lineOrStartPos?: CssSyntaxError.RangePosition | number,
columnOrEndPos?: CssSyntaxError.RangePosition | number,
source?: string,
file?: string,
plugin?: string
)
/**
* Returns a few lines of CSS source that caused the error.
*
* If the CSS has an input source map without `sourceContent`,
* this method will return an empty string.
*
* ```js
* error.showSourceCode() //=> " 4 | }
* // 5 | a {
* // > 6 | bad
* // | ^
* // 7 | }
* // 8 | b {"
* ```
*
* @param color Whether arrow will be colored red by terminal
* color codes. By default, PostCSS will detect
* color support by `process.stdout.isTTY`
* and `process.env.NODE_DISABLE_COLORS`.
* @return Few lines of CSS source that caused the error.
*/
showSourceCode(color?: boolean): string
/**
* Returns error position, message and source code of the broken part.
*
* ```js
* error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block
* // > 1 | a {
* // | ^"
* ```
*
* @return Error position, message and source code.
*/
toString(): string
}
declare class CssSyntaxError extends CssSyntaxError_ {}
export = CssSyntaxError

152
src/postcss/declaration.d.ts vendored Normal file
View File

@@ -0,0 +1,152 @@
import { ContainerWithChildren } from './container.js'
import Node from './node.js'
declare namespace Declaration {
export interface DeclarationRaws extends Record<string, unknown> {
/**
* The space symbols before the node. It also stores `*`
* and `_` symbols before the declaration (IE hack).
*/
before?: string
/**
* The symbols between the property and value for declarations.
*/
between?: string
/**
* The content of the important statement, if it is not just `!important`.
*/
important?: string
/**
* Declaration value with comments.
*/
value?: {
raw: string
value: string
}
}
export interface DeclarationProps {
/** Whether the declaration has an `!important` annotation. */
important?: boolean
/** Name of the declaration. */
prop: string
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: DeclarationRaws
/** Value of the declaration. */
value: string
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Declaration_ as default }
}
/**
* It represents a class that handles
* [CSS declarations](https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declarations)
*
* ```js
* Once (root, { Declaration }) {
* const color = new Declaration({ prop: 'color', value: 'black' })
* root.append(color)
* }
* ```
*
* ```js
* const root = postcss.parse('a { color: black }')
* const decl = root.first?.first
*
* decl.type //=> 'decl'
* decl.toString() //=> ' color: black'
* ```
*/
declare class Declaration_ extends Node {
/**
* It represents a specificity of the declaration.
*
* If true, the CSS declaration will have an
* [important](https://developer.mozilla.org/en-US/docs/Web/CSS/important)
* specifier.
*
* ```js
* const root = postcss.parse('a { color: black !important; color: red }')
*
* root.first.first.important //=> true
* root.first.last.important //=> undefined
* ```
*/
get important(): boolean
set important(value: boolean)
parent: ContainerWithChildren | undefined
/**
* The property name for a CSS declaration.
*
* ```js
* const root = postcss.parse('a { color: black }')
* const decl = root.first.first
*
* decl.prop //=> 'color'
* ```
*/
get prop(): string
set prop(value: string)
raws: Declaration.DeclarationRaws
type: 'decl'
/**
* The property value for a CSS declaration.
*
* Any CSS comments inside the value string will be filtered out.
* CSS comments present in the source value will be available in
* the `raws` property.
*
* Assigning new `value` would ignore the comments in `raws`
* property while compiling node to string.
*
* ```js
* const root = postcss.parse('a { color: black }')
* const decl = root.first.first
*
* decl.value //=> 'black'
* ```
*/
get value(): string
set value(value: string)
/**
* It represents a getter that returns `true` if a declaration starts with
* `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
*
* ```js
* const root = postcss.parse(':root { --one: 1 }')
* const one = root.first.first
*
* one.variable //=> true
* ```
*
* ```js
* const root = postcss.parse('$one: 1')
* const one = root.first
*
* one.variable //=> true
* ```
*/
get variable(): boolean
set varaible(value: string)
constructor(defaults?: Declaration.DeclarationProps)
assign(overrides: Declaration.DeclarationProps | object): this
clone(overrides?: Partial<Declaration.DeclarationProps>): Declaration
cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): Declaration
cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): Declaration
}
declare class Declaration extends Declaration_ {}
export = Declaration

69
src/postcss/document.d.ts vendored Normal file
View File

@@ -0,0 +1,69 @@
import Container, { ContainerProps } from './container.js'
import { ProcessOptions } from './postcss.js'
import Result from './result.js'
import Root from './root.js'
declare namespace Document {
export interface DocumentProps extends ContainerProps {
nodes?: Root[]
/**
* Information to generate byte-to-byte equal node string as it was
* in the origin input.
*
* Every parser saves its own properties.
*/
raws?: Record<string, any>
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Document_ as default }
}
/**
* Represents a file and contains all its parsed nodes.
*
* **Experimental:** some aspects of this node could change within minor
* or patch version releases.
*
* ```js
* const document = htmlParser(
* '<html><style>a{color:black}</style><style>b{z-index:2}</style>'
* )
* document.type //=> 'document'
* document.nodes.length //=> 2
* ```
*/
declare class Document_ extends Container<Root> {
nodes: Root[]
parent: undefined
type: 'document'
constructor(defaults?: Document.DocumentProps)
assign(overrides: Document.DocumentProps | object): this
clone(overrides?: Partial<Document.DocumentProps>): Document
cloneAfter(overrides?: Partial<Document.DocumentProps>): Document
cloneBefore(overrides?: Partial<Document.DocumentProps>): Document
/**
* Returns a `Result` instance representing the documents CSS roots.
*
* ```js
* const root1 = postcss.parse(css1, { from: 'a.css' })
* const root2 = postcss.parse(css2, { from: 'b.css' })
* const document = postcss.document()
* document.append(root1)
* document.append(root2)
* const result = document.toResult({ to: 'all.css', map: true })
* ```
*
* @param opts Options.
* @return Result with current documents CSS.
*/
toResult(options?: ProcessOptions): Result
}
declare class Document extends Document_ {}
export = Document

9
src/postcss/fromJSON.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
import { JSONHydrator } from './postcss.js'
interface FromJSON extends JSONHydrator {
default: FromJSON
}
declare const fromJSON: FromJSON
export = fromJSON

194
src/postcss/input.d.ts vendored Normal file
View File

@@ -0,0 +1,194 @@
import { CssSyntaxError, ProcessOptions } from './postcss.js'
import PreviousMap from './previous-map.js'
declare namespace Input {
export interface FilePosition {
/**
* Column of inclusive start position in source file.
*/
column: number
/**
* Column of exclusive end position in source file.
*/
endColumn?: number
/**
* Line of exclusive end position in source file.
*/
endLine?: number
/**
* Absolute path to the source file.
*/
file?: string
/**
* Line of inclusive start position in source file.
*/
line: number
/**
* Source code.
*/
source?: string
/**
* URL for the source file.
*/
url: string
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Input_ as default }
}
/**
* Represents the source CSS.
*
* ```js
* const root = postcss.parse(css, { from: file })
* const input = root.source.input
* ```
*/
declare class Input_ {
/**
* Input CSS source.
*
* ```js
* const input = postcss.parse('a{}', { from: file }).input
* input.css //=> "a{}"
* ```
*/
css: string
/**
* The absolute path to the CSS source file defined
* with the `from` option.
*
* ```js
* const root = postcss.parse(css, { from: 'a.css' })
* root.source.input.file //=> '/home/ai/a.css'
* ```
*/
file?: string
/**
* The flag to indicate whether or not the source code has Unicode BOM.
*/
hasBOM: boolean
/**
* The unique ID of the CSS source. It will be created if `from` option
* is not provided (because PostCSS does not know the file path).
*
* ```js
* const root = postcss.parse(css)
* root.source.input.file //=> undefined
* root.source.input.id //=> "<input css 8LZeVF>"
* ```
*/
id?: string
/**
* The input source map passed from a compilation step before PostCSS
* (for example, from Sass compiler).
*
* ```js
* root.source.input.map.consumer().sources //=> ['a.sass']
* ```
*/
map: PreviousMap
/**
* @param css Input CSS source.
* @param opts Process options.
*/
constructor(css: string, opts?: ProcessOptions)
error(
message: string,
start:
| {
column: number
line: number
}
| {
offset: number
},
end:
| {
column: number
line: number
}
| {
offset: number
},
opts?: { plugin?: CssSyntaxError['plugin'] }
): CssSyntaxError
/**
* Returns `CssSyntaxError` with information about the error and its position.
*/
error(
message: string,
line: number,
column: number,
opts?: { plugin?: CssSyntaxError['plugin'] }
): CssSyntaxError
error(
message: string,
offset: number,
opts?: { plugin?: CssSyntaxError['plugin'] }
): CssSyntaxError
/**
* Converts source offset to line and column.
*
* @param offset Source offset.
*/
fromOffset(offset: number): { col: number; line: number } | null
/**
* Reads the input source map and returns a symbol position
* in the input source (e.g., in a Sass file that was compiled
* to CSS before being passed to PostCSS). Optionally takes an
* end position, exclusive.
*
* ```js
* root.source.input.origin(1, 1) //=> { file: 'a.css', line: 3, column: 1 }
* root.source.input.origin(1, 1, 1, 4)
* //=> { file: 'a.css', line: 3, column: 1, endLine: 3, endColumn: 4 }
* ```
*
* @param line Line for inclusive start position in input CSS.
* @param column Column for inclusive start position in input CSS.
* @param endLine Line for exclusive end position in input CSS.
* @param endColumn Column for exclusive end position in input CSS.
*
* @return Position in input source.
*/
origin(
line: number,
column: number,
endLine?: number,
endColumn?: number
): false | Input.FilePosition
/**
* The CSS source identifier. Contains `Input#file` if the user
* set the `from` option, or `Input#id` if they did not.
*
* ```js
* const root = postcss.parse(css, { from: 'a.css' })
* root.source.input.from //=> "/home/ai/a.css"
*
* const root = postcss.parse(css)
* root.source.input.from //=> "<input css 1>"
* ```
*/
get from(): string
}
declare class Input extends Input_ {}
export = Input

190
src/postcss/lazy-result.d.ts vendored Normal file
View File

@@ -0,0 +1,190 @@
import Document from './document.js'
import { SourceMap } from './postcss.js'
import Processor from './processor.js'
import Result, { Message, ResultOptions } from './result.js'
import Root from './root.js'
import Warning from './warning.js'
declare namespace LazyResult {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { LazyResult_ as default }
}
/**
* A Promise proxy for the result of PostCSS transformations.
*
* A `LazyResult` instance is returned by `Processor#process`.
*
* ```js
* const lazy = postcss([autoprefixer]).process(css)
* ```
*/
declare class LazyResult_<RootNode = Document | Root>
implements PromiseLike<Result<RootNode>>
{
/**
* Processes input CSS through synchronous and asynchronous plugins
* and calls onRejected for each error thrown in any plugin.
*
* It implements standard Promise API.
*
* ```js
* postcss([autoprefixer]).process(css).then(result => {
* console.log(result.css)
* }).catch(error => {
* console.error(error)
* })
* ```
*/
catch: Promise<Result<RootNode>>['catch']
/**
* Processes input CSS through synchronous and asynchronous plugins
* and calls onFinally on any error or when all plugins will finish work.
*
* It implements standard Promise API.
*
* ```js
* postcss([autoprefixer]).process(css).finally(() => {
* console.log('processing ended')
* })
* ```
*/
finally: Promise<Result<RootNode>>['finally']
/**
* Processes input CSS through synchronous and asynchronous plugins
* and calls `onFulfilled` with a Result instance. If a plugin throws
* an error, the `onRejected` callback will be executed.
*
* It implements standard Promise API.
*
* ```js
* postcss([autoprefixer]).process(css, { from: cssPath }).then(result => {
* console.log(result.css)
* })
* ```
*/
then: Promise<Result<RootNode>>['then']
/**
* @param processor Processor used for this transformation.
* @param css CSS to parse and transform.
* @param opts Options from the `Processor#process` or `Root#toResult`.
*/
constructor(processor: Processor, css: string, opts: ResultOptions)
/**
* Run plugin in async way and return `Result`.
*
* @return Result with output content.
*/
async(): Promise<Result<RootNode>>
/**
* Run plugin in sync way and return `Result`.
*
* @return Result with output content.
*/
sync(): Result<RootNode>
/**
* Alias for the `LazyResult#css` property.
*
* ```js
* lazy + '' === lazy.css
* ```
*
* @return Output CSS.
*/
toString(): string
/**
* Processes input CSS through synchronous plugins
* and calls `Result#warnings`.
*
* @return Warnings from plugins.
*/
warnings(): Warning[]
/**
* An alias for the `css` property. Use it with syntaxes
* that generate non-CSS output.
*
* This property will only work with synchronous plugins.
* If the processor contains any asynchronous plugins
* it will throw an error.
*
* PostCSS runners should always use `LazyResult#then`.
*/
get content(): string
/**
* Processes input CSS through synchronous plugins, converts `Root`
* to a CSS string and returns `Result#css`.
*
* This property will only work with synchronous plugins.
* If the processor contains any asynchronous plugins
* it will throw an error.
*
* PostCSS runners should always use `LazyResult#then`.
*/
get css(): string
/**
* Processes input CSS through synchronous plugins
* and returns `Result#map`.
*
* This property will only work with synchronous plugins.
* If the processor contains any asynchronous plugins
* it will throw an error.
*
* PostCSS runners should always use `LazyResult#then`.
*/
get map(): SourceMap
/**
* Processes input CSS through synchronous plugins
* and returns `Result#messages`.
*
* This property will only work with synchronous plugins. If the processor
* contains any asynchronous plugins it will throw an error.
*
* PostCSS runners should always use `LazyResult#then`.
*/
get messages(): Message[]
/**
* Options from the `Processor#process` call.
*/
get opts(): ResultOptions
/**
* Returns a `Processor` instance, which will be used
* for CSS transformations.
*/
get processor(): Processor
/**
* Processes input CSS through synchronous plugins
* and returns `Result#root`.
*
* This property will only work with synchronous plugins. If the processor
* contains any asynchronous plugins it will throw an error.
*
* PostCSS runners should always use `LazyResult#then`.
*/
get root(): RootNode
/**
* Returns the default string description of an object.
* Required to implement the Promise interface.
*/
get [Symbol.toStringTag](): string
}
declare class LazyResult<
RootNode = Document | Root
> extends LazyResult_<RootNode> {}
export = LazyResult

57
src/postcss/list.d.ts vendored Normal file
View File

@@ -0,0 +1,57 @@
declare namespace list {
type List = {
/**
* Safely splits comma-separated values (such as those for `transition-*`
* and `background` properties).
*
* ```js
* Once (root, { list }) {
* list.comma('black, linear-gradient(white, black)')
* //=> ['black', 'linear-gradient(white, black)']
* }
* ```
*
* @param str Comma-separated values.
* @return Split values.
*/
comma(str: string): string[]
default: List
/**
* Safely splits space-separated values (such as those for `background`,
* `border-radius`, and other shorthand properties).
*
* ```js
* Once (root, { list }) {
* list.space('1px calc(10% + 1px)') //=> ['1px', 'calc(10% + 1px)']
* }
* ```
*
* @param str Space-separated values.
* @return Split values.
*/
space(str: string): string[]
/**
* Safely splits values.
*
* ```js
* Once (root, { list }) {
* list.split('1px calc(10% + 1px)', [' ', '\n', '\t']) //=> ['1px', 'calc(10% + 1px)']
* }
* ```
*
* @param string separated values.
* @param separators array of separators.
* @param last boolean indicator.
* @return Split values.
*/
split(string: string, separators: string[], last: boolean): string[]
}
}
// eslint-disable-next-line @typescript-eslint/no-redeclare
declare const list: list.List
export = list

46
src/postcss/no-work-result.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
import LazyResult from './lazy-result.js'
import { SourceMap } from './postcss.js'
import Processor from './processor.js'
import Result, { Message, ResultOptions } from './result.js'
import Root from './root.js'
import Warning from './warning.js'
declare namespace NoWorkResult {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { NoWorkResult_ as default }
}
/**
* A Promise proxy for the result of PostCSS transformations.
* This lazy result instance doesn't parse css unless `NoWorkResult#root` or `Result#root`
* are accessed. See the example below for details.
* A `NoWork` instance is returned by `Processor#process` ONLY when no plugins defined.
*
* ```js
* const noWorkResult = postcss().process(css) // No plugins are defined.
* // CSS is not parsed
* let root = noWorkResult.root // now css is parsed because we accessed the root
* ```
*/
declare class NoWorkResult_ implements LazyResult<Root> {
catch: Promise<Result<Root>>['catch']
finally: Promise<Result<Root>>['finally']
then: Promise<Result<Root>>['then']
constructor(processor: Processor, css: string, opts: ResultOptions)
async(): Promise<Result<Root>>
sync(): Result<Root>
toString(): string
warnings(): Warning[]
get content(): string
get css(): string
get map(): SourceMap
get messages(): Message[]
get opts(): ResultOptions
get processor(): Processor
get root(): Root
get [Symbol.toStringTag](): string
}
declare class NoWorkResult extends NoWorkResult_ {}
export = NoWorkResult

536
src/postcss/node.d.ts vendored Normal file
View File

@@ -0,0 +1,536 @@
import AtRule = require('./at-rule.js')
import { AtRuleProps } from './at-rule.js'
import Comment, { CommentProps } from './comment.js'
import Container from './container.js'
import CssSyntaxError from './css-syntax-error.js'
import Declaration, { DeclarationProps } from './declaration.js'
import Document from './document.js'
import Input from './input.js'
import { Stringifier, Syntax } from './postcss.js'
import Result from './result.js'
import Root from './root.js'
import Rule, { RuleProps } from './rule.js'
import Warning, { WarningOptions } from './warning.js'
declare namespace Node {
export type ChildNode = AtRule.default | Comment | Declaration | Rule
export type AnyNode =
| AtRule.default
| Comment
| Declaration
| Document
| Root
| Rule
export type ChildProps =
| AtRuleProps
| CommentProps
| DeclarationProps
| RuleProps
export interface Position {
/**
* Source line in file. In contrast to `offset` it starts from 1.
*/
column: number
/**
* Source column in file.
*/
line: number
/**
* Source offset in file. It starts from 0.
*/
offset: number
}
export interface Range {
/**
* End position, exclusive.
*/
end: Position
/**
* Start position, inclusive.
*/
start: Position
}
/**
* Source represents an interface for the {@link Node.source} property.
*/
export interface Source {
/**
* The inclusive ending position for the source
* code of a node.
*/
end?: Position
/**
* The source file from where a node has originated.
*/
input: Input
/**
* The inclusive starting position for the source
* code of a node.
*/
start?: Position
}
/**
* Interface represents an interface for an object received
* as parameter by Node class constructor.
*/
export interface NodeProps {
source?: Source
}
export interface NodeErrorOptions {
/**
* An ending index inside a node's string that should be highlighted as
* source of error.
*/
endIndex?: number
/**
* An index inside a node's string that should be highlighted as source
* of error.
*/
index?: number
/**
* Plugin name that created this error. PostCSS will set it automatically.
*/
plugin?: string
/**
* A word inside a node's string, that should be highlighted as source
* of error.
*/
word?: string
}
// eslint-disable-next-line @typescript-eslint/no-shadow
class Node extends Node_ {}
export { Node as default }
}
/**
* It represents an abstract class that handles common
* methods for other CSS abstract syntax tree nodes.
*
* Any node that represents CSS selector or value should
* not extend the `Node` class.
*/
declare abstract class Node_ {
/**
* It represents parent of the current node.
*
* ```js
* root.nodes[0].parent === root //=> true
* ```
*/
parent: Container | Document | undefined
/**
* It represents unnecessary whitespace and characters present
* in the css source code.
*
* Information to generate byte-to-byte equal node string as it was
* in the origin input.
*
* The properties of the raws object are decided by parser,
* the default parser uses the following properties:
*
* * `before`: the space symbols before the node. It also stores `*`
* and `_` symbols before the declaration (IE hack).
* * `after`: the space symbols after the last child of the node
* to the end of the node.
* * `between`: the symbols between the property and value
* for declarations, selector and `{` for rules, or last parameter
* and `{` for at-rules.
* * `semicolon`: contains true if the last child has
* an (optional) semicolon.
* * `afterName`: the space between the at-rule name and its parameters.
* * `left`: the space symbols between `/*` and the comments text.
* * `right`: the space symbols between the comments text
* and <code>*&#47;</code>.
* - `important`: the content of the important statement,
* if it is not just `!important`.
*
* PostCSS filters out the comments inside selectors, declaration values
* and at-rule parameters but it stores the origin content in raws.
*
* ```js
* const root = postcss.parse('a {\n color:black\n}')
* root.first.first.raws //=> { before: '\n ', between: ':' }
* ```
*/
raws: any
/**
* It represents information related to origin of a node and is required
* for generating source maps.
*
* The nodes that are created manually using the public APIs
* provided by PostCSS will have `source` undefined and
* will be absent in the source map.
*
* For this reason, the plugin developer should consider
* duplicating nodes as the duplicate node will have the
* same source as the original node by default or assign
* source to a node created manually.
*
* ```js
* decl.source.input.from //=> '/home/ai/source.css'
* decl.source.start //=> { line: 10, column: 2 }
* decl.source.end //=> { line: 10, column: 12 }
* ```
*
* ```js
* // Incorrect method, source not specified!
* const prefixed = postcss.decl({
* prop: '-moz-' + decl.prop,
* value: decl.value
* })
*
* // Correct method, source is inherited when duplicating.
* const prefixed = decl.clone({
* prop: '-moz-' + decl.prop
* })
* ```
*
* ```js
* if (atrule.name === 'add-link') {
* const rule = postcss.rule({
* selector: 'a',
* source: atrule.source
* })
*
* atrule.parent.insertBefore(atrule, rule)
* }
* ```
*/
source?: Node.Source
/**
* It represents type of a node in
* an abstract syntax tree.
*
* A type of node helps in identification of a node
* and perform operation based on it's type.
*
* ```js
* const declaration = new Declaration({
* prop: 'color',
* value: 'black'
* })
*
* declaration.type //=> 'decl'
* ```
*/
type: string
constructor(defaults?: object)
/**
* Insert new node after current node to current nodes parent.
*
* Just alias for `node.parent.insertAfter(node, add)`.
*
* ```js
* decl.after('color: black')
* ```
*
* @param newNode New node.
* @return This node for methods chain.
*/
after(newNode: Node | Node.ChildProps | Node[] | string | undefined): this
/**
* It assigns properties to an existing node instance.
*
* ```js
* decl.assign({ prop: 'word-wrap', value: 'break-word' })
* ```
*
* @param overrides New properties to override the node.
*
* @return `this` for method chaining.
*/
assign(overrides: object): this
/**
* Insert new node before current node to current nodes parent.
*
* Just alias for `node.parent.insertBefore(node, add)`.
*
* ```js
* decl.before('content: ""')
* ```
*
* @param newNode New node.
* @return This node for methods chain.
*/
before(newNode: Node | Node.ChildProps | Node[] | string | undefined): this
/**
* Clear the code style properties for the node and its children.
*
* ```js
* node.raws.before //=> ' '
* node.cleanRaws()
* node.raws.before //=> undefined
* ```
*
* @param keepBetween Keep the `raws.between` symbols.
*/
cleanRaws(keepBetween?: boolean): void
/**
* It creates clone of an existing node, which includes all the properties
* and their values, that includes `raws` but not `type`.
*
* ```js
* decl.raws.before //=> "\n "
* const cloned = decl.clone({ prop: '-moz-' + decl.prop })
* cloned.raws.before //=> "\n "
* cloned.toString() //=> -moz-transform: scale(0)
* ```
*
* @param overrides New properties to override in the clone.
*
* @return Duplicate of the node instance.
*/
clone(overrides?: object): Node
/**
* Shortcut to clone the node and insert the resulting cloned node
* after the current node.
*
* @param overrides New properties to override in the clone.
* @return New node.
*/
cloneAfter(overrides?: object): Node
/**
* Shortcut to clone the node and insert the resulting cloned node
* before the current node.
*
* ```js
* decl.cloneBefore({ prop: '-moz-' + decl.prop })
* ```
*
* @param overrides Mew properties to override in the clone.
*
* @return New node
*/
cloneBefore(overrides?: object): Node
/**
* It creates an instance of the class `CssSyntaxError` and parameters passed
* to this method are assigned to the error instance.
*
* The error instance will have description for the
* error, original position of the node in the
* source, showing line and column number.
*
* If any previous map is present, it would be used
* to get original position of the source.
*
* The Previous Map here is referred to the source map
* generated by previous compilation, example: Less,
* Stylus and Sass.
*
* This method returns the error instance instead of
* throwing it.
*
* ```js
* if (!variables[name]) {
* throw decl.error(`Unknown variable ${name}`, { word: name })
* // CssSyntaxError: postcss-vars:a.sass:4:3: Unknown variable $black
* // color: $black
* // a
* // ^
* // background: white
* }
* ```
*
* @param message Description for the error instance.
* @param options Options for the error instance.
*
* @return Error instance is returned.
*/
error(message: string, options?: Node.NodeErrorOptions): CssSyntaxError
/**
* Returns the next child of the nodes parent.
* Returns `undefined` if the current node is the last child.
*
* ```js
* if (comment.text === 'delete next') {
* const next = comment.next()
* if (next) {
* next.remove()
* }
* }
* ```
*
* @return Next node.
*/
next(): Node.ChildNode | undefined
/**
* Get the position for a word or an index inside the node.
*
* @param opts Options.
* @return Position.
*/
positionBy(opts?: Pick<WarningOptions, 'index' | 'word'>): Node.Position
/**
* Convert string index to line/column.
*
* @param index The symbol number in the nodes string.
* @return Symbol position in file.
*/
positionInside(index: number): Node.Position
/**
* Returns the previous child of the nodes parent.
* Returns `undefined` if the current node is the first child.
*
* ```js
* const annotation = decl.prev()
* if (annotation.type === 'comment') {
* readAnnotation(annotation.text)
* }
* ```
*
* @return Previous node.
*/
prev(): Node.ChildNode | undefined
/**
* Get the range for a word or start and end index inside the node.
* The start index is inclusive; the end index is exclusive.
*
* @param opts Options.
* @return Range.
*/
rangeBy(
opts?: Pick<WarningOptions, 'endIndex' | 'index' | 'word'>
): Node.Range
/**
* Returns a `raws` value. If the node is missing
* the code style property (because the node was manually built or cloned),
* PostCSS will try to autodetect the code style property by looking
* at other nodes in the tree.
*
* ```js
* const root = postcss.parse('a { background: white }')
* root.nodes[0].append({ prop: 'color', value: 'black' })
* root.nodes[0].nodes[1].raws.before //=> undefined
* root.nodes[0].nodes[1].raw('before') //=> ' '
* ```
*
* @param prop Name of code style property.
* @param defaultType Name of default value, it can be missed
* if the value is the same as prop.
* @return {string} Code style value.
*/
raw(prop: string, defaultType?: string): string
/**
* It removes the node from its parent and deletes its parent property.
*
* ```js
* if (decl.prop.match(/^-webkit-/)) {
* decl.remove()
* }
* ```
*
* @return `this` for method chaining.
*/
remove(): this
/**
* Inserts node(s) before the current node and removes the current node.
*
* ```js
* AtRule: {
* mixin: atrule => {
* atrule.replaceWith(mixinRules[atrule.params])
* }
* }
* ```
*
* @param nodes Mode(s) to replace current one.
* @return Current node to methods chain.
*/
replaceWith(
...nodes: (
| Node.ChildNode
| Node.ChildNode[]
| Node.ChildProps
| Node.ChildProps[]
)[]
): this
/**
* Finds the Root instance of the nodes tree.
*
* ```js
* root.nodes[0].nodes[0].root() === root
* ```
*
* @return Root parent.
*/
root(): Root
/**
* Fix circular links on `JSON.stringify()`.
*
* @return Cleaned object.
*/
toJSON(): object
/**
* It compiles the node to browser readable cascading style sheets string
* depending on it's type.
*
* ```js
* new Rule({ selector: 'a' }).toString() //=> "a {}"
* ```
*
* @param stringifier A syntax to use in string generation.
* @return CSS string of this node.
*/
toString(stringifier?: Stringifier | Syntax): string
/**
* It is a wrapper for {@link Result#warn}, providing convenient
* way of generating warnings.
*
* ```js
* Declaration: {
* bad: (decl, { result }) => {
* decl.warn(result, 'Deprecated property: bad')
* }
* }
* ```
*
* @param result The `Result` instance that will receive the warning.
* @param message Description for the warning.
* @param options Options for the warning.
*
* @return `Warning` instance is returned
*/
warn(result: Result, message: string, options?: WarningOptions): Warning
}
declare class Node extends Node_ {}
export = Node

9
src/postcss/parse.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
import { Parser } from './postcss.js'
interface Parse extends Parser {
default: Parse
}
declare const parse: Parse
export = parse

436
src/postcss/postcss.d.ts vendored Normal file
View File

@@ -0,0 +1,436 @@
import AtRule, { AtRuleProps } from './at-rule.js'
import Comment, { CommentProps } from './comment.js'
import Container, { ContainerProps } from './container.js'
import CssSyntaxError from './css-syntax-error.js'
import Declaration, { DeclarationProps } from './declaration.js'
import Document, { DocumentProps } from './document.js'
import Input, { FilePosition } from './input.js'
import LazyResult from './lazy-result.js'
import list from './list.js'
import Node, {
AnyNode,
ChildNode,
ChildProps,
NodeErrorOptions,
NodeProps,
Position,
Source
} from './node.js'
import Processor from './processor.js'
import Result, { Message } from './result.js'
import Root, { RootProps } from './root.js'
import Rule, { RuleProps } from './rule.js'
import Warning, { WarningOptions } from './warning.js'
type DocumentProcessor = (
document: Document,
helper: postcss.Helpers
) => Promise<void> | void
type RootProcessor = (root: Root, helper: postcss.Helpers) => Promise<void> | void
type DeclarationProcessor = (
decl: Declaration,
helper: postcss.Helpers
) => Promise<void> | void
type RuleProcessor = (rule: Rule, helper: postcss.Helpers) => Promise<void> | void
type AtRuleProcessor = (atRule: AtRule, helper: postcss.Helpers) => Promise<void> | void
type CommentProcessor = (
comment: Comment,
helper: postcss.Helpers
) => Promise<void> | void
interface Processors {
/**
* Will be called on all`AtRule` nodes.
*
* Will be called again on node or children changes.
*/
AtRule?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
/**
* Will be called on all `AtRule` nodes, when all children will be processed.
*
* Will be called again on node or children changes.
*/
AtRuleExit?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
/**
* Will be called on all `Comment` nodes.
*
* Will be called again on node or children changes.
*/
Comment?: CommentProcessor
/**
* Will be called on all `Comment` nodes after listeners
* for `Comment` event.
*
* Will be called again on node or children changes.
*/
CommentExit?: CommentProcessor
/**
* Will be called on all `Declaration` nodes after listeners
* for `Declaration` event.
*
* Will be called again on node or children changes.
*/
Declaration?: { [prop: string]: DeclarationProcessor } | DeclarationProcessor
/**
* Will be called on all `Declaration` nodes.
*
* Will be called again on node or children changes.
*/
DeclarationExit?:
| { [prop: string]: DeclarationProcessor }
| DeclarationProcessor
/**
* Will be called on `Document` node.
*
* Will be called again on children changes.
*/
Document?: DocumentProcessor
/**
* Will be called on `Document` node, when all children will be processed.
*
* Will be called again on children changes.
*/
DocumentExit?: DocumentProcessor
/**
* Will be called on `Root` node once.
*/
Once?: RootProcessor
/**
* Will be called on `Root` node once, when all children will be processed.
*/
OnceExit?: RootProcessor
/**
* Will be called on `Root` node.
*
* Will be called again on children changes.
*/
Root?: RootProcessor
/**
* Will be called on `Root` node, when all children will be processed.
*
* Will be called again on children changes.
*/
RootExit?: RootProcessor
/**
* Will be called on all `Rule` nodes.
*
* Will be called again on node or children changes.
*/
Rule?: RuleProcessor
/**
* Will be called on all `Rule` nodes, when all children will be processed.
*
* Will be called again on node or children changes.
*/
RuleExit?: RuleProcessor
}
declare namespace postcss {
export {
AnyNode,
AtRule,
AtRuleProps,
ChildNode,
ChildProps,
Comment,
CommentProps,
Container,
ContainerProps,
CssSyntaxError,
Declaration,
DeclarationProps,
Document,
DocumentProps,
FilePosition,
Input,
LazyResult,
list,
Message,
Node,
NodeErrorOptions,
NodeProps,
Position,
Processor,
Result,
Root,
RootProps,
Rule,
RuleProps,
Source,
Warning,
WarningOptions
}
export type Helpers = { postcss: Postcss; result: Result } & Postcss
export interface Plugin extends Processors {
postcssPlugin: string
prepare?: (result: Result) => Processors
}
export interface PluginCreator<PluginOptions> {
(opts?: PluginOptions): Plugin | Processor
postcss: true
}
export interface Transformer extends TransformCallback {
postcssPlugin: string
postcssVersion: string
}
export interface TransformCallback {
(root: Root, result: Result): Promise<void> | void
}
export interface OldPlugin<T> extends Transformer {
(opts?: T): Transformer
postcss: Transformer
}
export type AcceptedPlugin =
| {
postcss: Processor | TransformCallback
}
| OldPlugin<any>
| Plugin
| PluginCreator<any>
| Processor
| TransformCallback
export interface Parser<RootNode = Document | Root> {
(
css: { toString(): string } | string,
opts?: Pick<ProcessOptions, 'from' | 'map'>
): RootNode
}
export interface Builder {
(part: string, node?: AnyNode, type?: 'end' | 'start'): void
}
export interface Stringifier {
(node: AnyNode, builder: Builder): void
}
export interface JSONHydrator {
(data: object): Node
(data: object[]): Node[]
}
export interface Syntax<RootNode = Document | Root> {
/**
* Function to generate AST by string.
*/
parse?: Parser<RootNode>
/**
* Class to generate string by AST.
*/
stringify?: Stringifier
}
export interface SourceMapOptions {
/**
* Use absolute path in generated source map.
*/
absolute?: boolean
/**
* Indicates that PostCSS should add annotation comments to the CSS.
* By default, PostCSS will always add a comment with a path
* to the source map. PostCSS will not add annotations to CSS files
* that do not contain any comments.
*
* By default, PostCSS presumes that you want to save the source map as
* `opts.to + '.map'` and will use this path in the annotation comment.
* A different path can be set by providing a string value for annotation.
*
* If you have set `inline: true`, annotation cannot be disabled.
*/
annotation?: ((file: string, root: Root) => string) | boolean | string
/**
* Override `from` in maps sources.
*/
from?: string
/**
* Indicates that the source map should be embedded in the output CSS
* as a Base64-encoded comment. By default, it is `true`.
* But if all previous maps are external, not inline, PostCSS will not embed
* the map even if you do not set this option.
*
* If you have an inline source map, the result.map property will be empty,
* as the source map will be contained within the text of `result.css`.
*/
inline?: boolean
/**
* Source map content from a previous processing step (e.g., Sass).
*
* PostCSS will try to read the previous source map
* automatically (based on comments within the source CSS), but you can use
* this option to identify it manually.
*
* If desired, you can omit the previous map with prev: `false`.
*/
prev?: ((file: string) => string) | boolean | object | string
/**
* Indicates that PostCSS should set the origin content (e.g., Sass source)
* of the source map. By default, it is true. But if all previous maps do not
* contain sources content, PostCSS will also leave it out even if you
* do not set this option.
*/
sourcesContent?: boolean
}
export interface ProcessOptions<RootNode = Document | Root> {
/**
* The path of the CSS source file. You should always set `from`,
* because it is used in source map generation and syntax error messages.
*/
from?: string | undefined
/**
* Source map options
*/
map?: boolean | SourceMapOptions
/**
* Function to generate AST by string.
*/
parser?: Parser<RootNode> | Syntax<RootNode>
/**
* Class to generate string by AST.
*/
stringifier?: Stringifier | Syntax<RootNode>
/**
* Object with parse and stringify.
*/
syntax?: Syntax<RootNode>
/**
* The path where you'll put the output CSS file. You should always set `to`
* to generate correct source maps.
*/
to?: string
}
export type Postcss = typeof postcss
/**
* Default function to convert a node tree into a CSS string.
*/
export let stringify: Stringifier
/**
* Parses source css and returns a new `Root` or `Document` node,
* which contains the source CSS nodes.
*
* ```js
* // Simple CSS concatenation with source map support
* const root1 = postcss.parse(css1, { from: file1 })
* const root2 = postcss.parse(css2, { from: file2 })
* root1.append(root2).toResult().css
* ```
*/
export let parse: Parser<Root>
/**
* Rehydrate a JSON AST (from `Node#toJSON`) back into the AST classes.
*
* ```js
* const json = root.toJSON()
* // save to file, send by network, etc
* const root2 = postcss.fromJSON(json)
* ```
*/
export let fromJSON: JSONHydrator
/**
* Creates a new `Comment` node.
*
* @param defaults Properties for the new node.
* @return New comment node
*/
export function comment(defaults?: CommentProps): Comment
/**
* Creates a new `AtRule` node.
*
* @param defaults Properties for the new node.
* @return New at-rule node.
*/
export function atRule(defaults?: AtRuleProps): AtRule
/**
* Creates a new `Declaration` node.
*
* @param defaults Properties for the new node.
* @return New declaration node.
*/
export function decl(defaults?: DeclarationProps): Declaration
/**
* Creates a new `Rule` node.
*
* @param default Properties for the new node.
* @return New rule node.
*/
export function rule(defaults?: RuleProps): Rule
/**
* Creates a new `Root` node.
*
* @param defaults Properties for the new node.
* @return New root node.
*/
export function root(defaults?: RootProps): Root
/**
* Creates a new `Document` node.
*
* @param defaults Properties for the new node.
* @return New document node.
*/
export function document(defaults?: DocumentProps): Document
export { postcss as default }
}
/**
* Create a new `Processor` instance that will apply `plugins`
* as CSS processors.
*
* ```js
* let postcss = require('postcss')
*
* postcss(plugins).process(css, { from, to }).then(result => {
* console.log(result.css)
* })
* ```
*
* @param plugins PostCSS plugins.
* @return Processor to process multiple CSS.
*/
declare function postcss(plugins?: postcss.AcceptedPlugin[]): Processor
declare function postcss(...plugins: postcss.AcceptedPlugin[]): Processor
export = postcss

6520
src/postcss/postcss.js Normal file

File diff suppressed because it is too large Load Diff

81
src/postcss/previous-map.d.ts vendored Normal file
View File

@@ -0,0 +1,81 @@
import { SourceMapConsumer } from 'source-map-js'
import { ProcessOptions } from './postcss.js'
declare namespace PreviousMap {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { PreviousMap_ as default }
}
/**
* Source map information from input CSS.
* For example, source map after Sass compiler.
*
* This class will automatically find source map in input CSS or in file system
* near input file (according `from` option).
*
* ```js
* const root = parse(css, { from: 'a.sass.css' })
* root.input.map //=> PreviousMap
* ```
*/
declare class PreviousMap_ {
/**
* `sourceMappingURL` content.
*/
annotation?: string
/**
* The CSS source identifier. Contains `Input#file` if the user
* set the `from` option, or `Input#id` if they did not.
*/
file?: string
/**
* Was source map inlined by data-uri to input CSS.
*/
inline: boolean
/**
* Path to source map file.
*/
mapFile?: string
/**
* The directory with source map file, if source map is in separated file.
*/
root?: string
/**
* Source map file content.
*/
text?: string
/**
* @param css Input CSS source.
* @param opts Process options.
*/
constructor(css: string, opts?: ProcessOptions)
/**
* Create a instance of `SourceMapGenerator` class
* from the `source-map` library to work with source map information.
*
* It is lazy method, so it will create object only on first call
* and then it will use cache.
*
* @return Object with source map information.
*/
consumer(): SourceMapConsumer
/**
* Does source map contains `sourcesContent` with input source text.
*
* @return Is `sourcesContent` present.
*/
withContent(): boolean
}
declare class PreviousMap extends PreviousMap_ {}
export = PreviousMap

115
src/postcss/processor.d.ts vendored Normal file
View File

@@ -0,0 +1,115 @@
import Document from './document.js'
import LazyResult from './lazy-result.js'
import NoWorkResult from './no-work-result.js'
import {
AcceptedPlugin,
Plugin,
ProcessOptions,
TransformCallback,
Transformer
} from './postcss.js'
import Result from './result.js'
import Root from './root.js'
declare namespace Processor {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Processor_ as default }
}
/**
* Contains plugins to process CSS. Create one `Processor` instance,
* initialize its plugins, and then use that instance on numerous CSS files.
*
* ```js
* const processor = postcss([autoprefixer, postcssNested])
* processor.process(css1).then(result => console.log(result.css))
* processor.process(css2).then(result => console.log(result.css))
* ```
*/
declare class Processor_ {
/**
* Plugins added to this processor.
*
* ```js
* const processor = postcss([autoprefixer, postcssNested])
* processor.plugins.length //=> 2
* ```
*/
plugins: (Plugin | TransformCallback | Transformer)[]
/**
* Current PostCSS version.
*
* ```js
* if (result.processor.version.split('.')[0] !== '6') {
* throw new Error('This plugin works only with PostCSS 6')
* }
* ```
*/
version: string
/**
* @param plugins PostCSS plugins
*/
constructor(plugins?: AcceptedPlugin[])
/**
* Parses source CSS and returns a `LazyResult` Promise proxy.
* Because some plugins can be asynchronous it doesnt make
* any transformations. Transformations will be applied
* in the `LazyResult` methods.
*
* ```js
* processor.process(css, { from: 'a.css', to: 'a.out.css' })
* .then(result => {
* console.log(result.css)
* })
* ```
*
* @param css String with input CSS or any object with a `toString()` method,
* like a Buffer. Optionally, send a `Result` instance
* and the processor will take the `Root` from it.
* @param opts Options.
* @return Promise proxy.
*/
process(
css: { toString(): string } | LazyResult | Result | Root | string
): LazyResult | NoWorkResult
process<RootNode extends Document | Root = Root>(
css: { toString(): string } | LazyResult | Result | Root | string,
options: ProcessOptions<RootNode>
): LazyResult<RootNode>
/**
* Adds a plugin to be used as a CSS processor.
*
* PostCSS plugin can be in 4 formats:
* * A plugin in `Plugin` format.
* * A plugin creator function with `pluginCreator.postcss = true`.
* PostCSS will call this function without argument to get plugin.
* * A function. PostCSS will pass the function a {@link Root}
* as the first argument and current `Result` instance
* as the second.
* * Another `Processor` instance. PostCSS will copy plugins
* from that instance into this one.
*
* Plugins can also be added by passing them as arguments when creating
* a `postcss` instance (see [`postcss(plugins)`]).
*
* Asynchronous plugins should return a `Promise` instance.
*
* ```js
* const processor = postcss()
* .use(autoprefixer)
* .use(postcssNested)
* ```
*
* @param plugin PostCSS plugin or `Processor` with plugins.
* @return Current processor to make methods chain.
*/
use(plugin: AcceptedPlugin): this
}
declare class Processor extends Processor_ {}
export = Processor

206
src/postcss/result.d.ts vendored Normal file
View File

@@ -0,0 +1,206 @@
import {
Document,
Node,
Plugin,
ProcessOptions,
Root,
SourceMap,
TransformCallback,
Warning,
WarningOptions
} from './postcss.js'
import Processor from './processor.js'
declare namespace Result {
export interface Message {
[others: string]: any
/**
* Source PostCSS plugin name.
*/
plugin?: string
/**
* Message type.
*/
type: string
}
export interface ResultOptions extends ProcessOptions {
/**
* The CSS node that was the source of the warning.
*/
node?: Node
/**
* Name of plugin that created this warning. `Result#warn` will fill it
* automatically with `Plugin#postcssPlugin` value.
*/
plugin?: string
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Result_ as default }
}
/**
* Provides the result of the PostCSS transformations.
*
* A Result instance is returned by `LazyResult#then`
* or `Root#toResult` methods.
*
* ```js
* postcss([autoprefixer]).process(css).then(result => {
* console.log(result.css)
* })
* ```
*
* ```js
* const result2 = postcss.parse(css).toResult()
* ```
*/
declare class Result_<RootNode = Document | Root> {
/**
* A CSS string representing of `Result#root`.
*
* ```js
* postcss.parse('a{}').toResult().css //=> "a{}"
* ```
*/
css: string
/**
* Last runned PostCSS plugin.
*/
lastPlugin: Plugin | TransformCallback
/**
* An instance of `SourceMapGenerator` class from the `source-map` library,
* representing changes to the `Result#root` instance.
*
* ```js
* result.map.toJSON() //=> { version: 3, file: 'a.css', … }
* ```
*
* ```js
* if (result.map) {
* fs.writeFileSync(result.opts.to + '.map', result.map.toString())
* }
* ```
*/
map: SourceMap
/**
* Contains messages from plugins (e.g., warnings or custom messages).
* Each message should have type and plugin properties.
*
* ```js
* AtRule: {
* import: (atRule, { result }) {
* const importedFile = parseImport(atRule)
* result.messages.push({
* type: 'dependency',
* plugin: 'postcss-import',
* file: importedFile,
* parent: result.opts.from
* })
* }
* }
* ```
*/
messages: Result.Message[]
/**
* Options from the `Processor#process` or `Root#toResult` call
* that produced this Result instance.]
*
* ```js
* root.toResult(opts).opts === opts
* ```
*/
opts: Result.ResultOptions
/**
* The Processor instance used for this transformation.
*
* ```js
* for (const plugin of result.processor.plugins) {
* if (plugin.postcssPlugin === 'postcss-bad') {
* throw 'postcss-good is incompatible with postcss-bad'
* }
* })
* ```
*/
processor: Processor
/**
* Root node after all transformations.
*
* ```js
* root.toResult().root === root
* ```
*/
root: RootNode
/**
* @param processor Processor used for this transformation.
* @param root Root node after all transformations.
* @param opts Options from the `Processor#process` or `Root#toResult`.
*/
constructor(processor: Processor, root: RootNode, opts: Result.ResultOptions)
/**
* Returns for `Result#css` content.
*
* ```js
* result + '' === result.css
* ```
*
* @return String representing of `Result#root`.
*/
toString(): string
/**
* Creates an instance of `Warning` and adds it to `Result#messages`.
*
* ```js
* if (decl.important) {
* result.warn('Avoid !important', { node: decl, word: '!important' })
* }
* ```
*
* @param text Warning message.
* @param opts Warning options.
* @return Created warning.
*/
warn(message: string, options?: WarningOptions): Warning
/**
* Returns warnings from plugins. Filters `Warning` instances
* from `Result#messages`.
*
* ```js
* result.warnings().forEach(warn => {
* console.warn(warn.toString())
* })
* ```
*
* @return Warnings from plugins.
*/
warnings(): Warning[]
/**
* An alias for the `Result#css` property.
* Use it with syntaxes that generate non-CSS output.
*
* ```js
* result.css === result.content
* ```
*/
get content(): string
}
declare class Result<RootNode = Document | Root> extends Result_<RootNode> {}
export = Result

87
src/postcss/root.d.ts vendored Normal file
View File

@@ -0,0 +1,87 @@
import Container, { ContainerProps } from './container.js'
import Document from './document.js'
import { ProcessOptions } from './postcss.js'
import Result from './result.js'
declare namespace Root {
export interface RootRaws extends Record<string, any> {
/**
* The space symbols after the last child to the end of file.
*/
after?: string
/**
* Non-CSS code after `Root`, when `Root` is inside `Document`.
*
* **Experimental:** some aspects of this node could change within minor
* or patch version releases.
*/
codeAfter?: string
/**
* Non-CSS code before `Root`, when `Root` is inside `Document`.
*
* **Experimental:** some aspects of this node could change within minor
* or patch version releases.
*/
codeBefore?: string
/**
* Is the last child has an (optional) semicolon.
*/
semicolon?: boolean
}
export interface RootProps extends ContainerProps {
/**
* Information used to generate byte-to-byte equal node string
* as it was in the origin input.
* */
raws?: RootRaws
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Root_ as default }
}
/**
* Represents a CSS file and contains all its parsed nodes.
*
* ```js
* const root = postcss.parse('a{color:black} b{z-index:2}')
* root.type //=> 'root'
* root.nodes.length //=> 2
* ```
*/
declare class Root_ extends Container {
nodes: NonNullable<Container['nodes']>
parent: Document | undefined
raws: Root.RootRaws
type: 'root'
constructor(defaults?: Root.RootProps)
assign(overrides: object | Root.RootProps): this
clone(overrides?: Partial<Root.RootProps>): Root
cloneAfter(overrides?: Partial<Root.RootProps>): Root
cloneBefore(overrides?: Partial<Root.RootProps>): Root
/**
* Returns a `Result` instance representing the roots CSS.
*
* ```js
* const root1 = postcss.parse(css1, { from: 'a.css' })
* const root2 = postcss.parse(css2, { from: 'b.css' })
* root1.append(root2)
* const result = root1.toResult({ to: 'all.css', map: true })
* ```
*
* @param opts Options.
* @return Result with current roots CSS.
*/
toResult(options?: ProcessOptions): Result
}
declare class Root extends Root_ {}
export = Root

119
src/postcss/rule.d.ts vendored Normal file
View File

@@ -0,0 +1,119 @@
import Container, {
ContainerProps,
ContainerWithChildren
} from './container.js'
declare namespace Rule {
export interface RuleRaws extends Record<string, unknown> {
/**
* The space symbols after the last child of the node to the end of the node.
*/
after?: string
/**
* The space symbols before the node. It also stores `*`
* and `_` symbols before the declaration (IE hack).
*/
before?: string
/**
* The symbols between the selector and `{` for rules.
*/
between?: string
/**
* Contains `true` if there is semicolon after rule.
*/
ownSemicolon?: string
/**
* The rules selector with comments.
*/
selector?: {
raw: string
value: string
}
/**
* Contains `true` if the last child has an (optional) semicolon.
*/
semicolon?: boolean
}
export interface RuleProps extends ContainerProps {
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: RuleRaws
/** Selector or selectors of the rule. */
selector?: string
/** Selectors of the rule represented as an array of strings. */
selectors?: string[]
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Rule_ as default }
}
/**
* Represents a CSS rule: a selector followed by a declaration block.
*
* ```js
* Once (root, { Rule }) {
* let a = new Rule({ selector: 'a' })
* a.append(…)
* root.append(a)
* }
* ```
*
* ```js
* const root = postcss.parse('a{}')
* const rule = root.first
* rule.type //=> 'rule'
* rule.toString() //=> 'a{}'
* ```
*/
declare class Rule_ extends Container {
nodes: NonNullable<Container['nodes']>
parent: ContainerWithChildren | undefined
raws: Rule.RuleRaws
/**
* The rules full selector represented as a string.
*
* ```js
* const root = postcss.parse('a, b { }')
* const rule = root.first
* rule.selector //=> 'a, b'
* ```
*/
get selector(): string
set selector(value: string);
/**
* An array containing the rules individual selectors.
* Groups of selectors are split at commas.
*
* ```js
* const root = postcss.parse('a, b { }')
* const rule = root.first
*
* rule.selector //=> 'a, b'
* rule.selectors //=> ['a', 'b']
*
* rule.selectors = ['a', 'strong']
* rule.selector //=> 'a, strong'
* ```
*/
get selectors(): string[]
set selectors(values: string[]);
type: 'rule'
constructor(defaults?: Rule.RuleProps)
assign(overrides: object | Rule.RuleProps): this
clone(overrides?: Partial<Rule.RuleProps>): Rule
cloneAfter(overrides?: Partial<Rule.RuleProps>): Rule
cloneBefore(overrides?: Partial<Rule.RuleProps>): Rule
}
declare class Rule extends Rule_ {}
export = Rule

46
src/postcss/stringifier.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
import {
AnyNode,
AtRule,
Builder,
Comment,
Container,
Declaration,
Document,
Root,
Rule
} from './postcss.js'
declare namespace Stringifier {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Stringifier_ as default }
}
declare class Stringifier_ {
builder: Builder
constructor(builder: Builder)
atrule(node: AtRule, semicolon?: boolean): void
beforeAfter(node: AnyNode, detect: 'after' | 'before'): string
block(node: AnyNode, start: string): void
body(node: Container): void
comment(node: Comment): void
decl(node: Declaration, semicolon?: boolean): void
document(node: Document): void
raw(node: AnyNode, own: null | string, detect?: string): string
rawBeforeClose(root: Root): string | undefined
rawBeforeComment(root: Root, node: Comment): string | undefined
rawBeforeDecl(root: Root, node: Declaration): string | undefined
rawBeforeOpen(root: Root): string | undefined
rawBeforeRule(root: Root): string | undefined
rawColon(root: Root): string | undefined
rawEmptyBody(root: Root): string | undefined
rawIndent(root: Root): string | undefined
rawSemicolon(root: Root): boolean | undefined
rawValue(node: AnyNode, prop: string): string
root(node: Root): void
rule(node: Rule): void
stringify(node: AnyNode, semicolon?: boolean): void
}
declare class Stringifier extends Stringifier_ {}
export = Stringifier

9
src/postcss/stringify.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
import { Stringifier } from './postcss.js'
interface Stringify extends Stringifier {
default: Stringify
}
declare const stringify: Stringify
export = stringify

147
src/postcss/warning.d.ts vendored Normal file
View File

@@ -0,0 +1,147 @@
import { RangePosition } from './css-syntax-error.js'
import Node from './node.js'
declare namespace Warning {
export interface WarningOptions {
/**
* End position, exclusive, in CSS node string that caused the warning.
*/
end?: RangePosition
/**
* End index, exclusive, in CSS node string that caused the warning.
*/
endIndex?: number
/**
* Start index, inclusive, in CSS node string that caused the warning.
*/
index?: number
/**
* CSS node that caused the warning.
*/
node?: Node
/**
* Name of the plugin that created this warning. `Result#warn` fills
* this property automatically.
*/
plugin?: string
/**
* Start position, inclusive, in CSS node string that caused the warning.
*/
start?: RangePosition
/**
* Word in CSS source that caused the warning.
*/
word?: string
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Warning_ as default }
}
/**
* Represents a plugins warning. It can be created using `Node#warn`.
*
* ```js
* if (decl.important) {
* decl.warn(result, 'Avoid !important', { word: '!important' })
* }
* ```
*/
declare class Warning_ {
/**
* Column for inclusive start position in the input file with this warnings source.
*
* ```js
* warning.column //=> 6
* ```
*/
column: number
/**
* Column for exclusive end position in the input file with this warnings source.
*
* ```js
* warning.endColumn //=> 4
* ```
*/
endColumn?: number
/**
* Line for exclusive end position in the input file with this warnings source.
*
* ```js
* warning.endLine //=> 6
* ```
*/
endLine?: number
/**
* Line for inclusive start position in the input file with this warnings source.
*
* ```js
* warning.line //=> 5
* ```
*/
line: number
/**
* Contains the CSS node that caused the warning.
*
* ```js
* warning.node.toString() //=> 'color: white !important'
* ```
*/
node: Node
/**
* The name of the plugin that created this warning.
* When you call `Node#warn` it will fill this property automatically.
*
* ```js
* warning.plugin //=> 'postcss-important'
* ```
*/
plugin: string
/**
* The warning message.
*
* ```js
* warning.text //=> 'Try to avoid !important'
* ```
*/
text: string
/**
* Type to filter warnings from `Result#messages`.
* Always equal to `"warning"`.
*/
type: 'warning'
/**
* @param text Warning message.
* @param opts Warning options.
*/
constructor(text: string, opts?: Warning.WarningOptions)
/**
* Returns a warning position and message.
*
* ```js
* warning.toString() //=> 'postcss-lint:a.css:10:14: Avoid !important'
* ```
*
* @return Warning position and message.
*/
toString(): string
}
declare class Warning extends Warning_ {}
export = Warning