ccc-tnt-psd2ui/npm-packages/mac-v3.4.+/postcss/lib/node.d.ts

537 lines
14 KiB
TypeScript
Raw Normal View History

2023-09-06 01:51:55 +00:00
import AtRule = require('./at-rule.js')
import { AtRuleProps } from './at-rule.js'
2023-07-24 03:13:08 +00:00
import Comment, { CommentProps } from './comment.js'
2023-09-06 01:51:55 +00:00
import Container from './container.js'
2023-07-24 03:13:08 +00:00
import CssSyntaxError from './css-syntax-error.js'
2023-09-06 01:51:55 +00:00
import Declaration, { DeclarationProps } from './declaration.js'
import Document from './document.js'
2023-07-24 03:13:08 +00:00
import Input from './input.js'
2023-09-06 01:51:55 +00:00
import { Stringifier, Syntax } from './postcss.js'
import Result from './result.js'
2023-07-24 03:13:08 +00:00
import Root from './root.js'
2023-09-06 01:51:55 +00:00
import Rule, { RuleProps } from './rule.js'
import Warning, { WarningOptions } from './warning.js'
2023-07-24 03:13:08 +00:00
2023-09-06 01:51:55 +00:00
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 }
2023-07-24 03:13:08 +00:00
}
/**
2023-09-06 01:51:55 +00:00
* It represents an abstract class that handles common
* methods for other CSS abstract syntax tree nodes.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* Any node that represents CSS selector or value should
* not extend the `Node` class.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
declare abstract class Node_ {
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It represents parent of the current node.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* root.nodes[0].parent === root //=> true
2023-07-24 03:13:08 +00:00
* ```
*/
2023-09-06 01:51:55 +00:00
parent: Container | Document | undefined
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* 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.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* const root = postcss.parse('a {\n color:black\n}')
* root.first.first.raws //=> { before: '\n ', between: ':' }
2023-07-24 03:13:08 +00:00
* ```
*/
2023-09-06 01:51:55 +00:00
raws: any
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It represents information related to origin of a node and is required
* for generating source maps.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* 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.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* 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.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* decl.source.input.from //=> '/home/ai/source.css'
2023-07-24 03:13:08 +00:00
* decl.source.start //=> { line: 10, column: 2 }
* decl.source.end //=> { line: 10, column: 12 }
* ```
*
* ```js
2023-09-06 01:51:55 +00:00
* // Incorrect method, source not specified!
2023-07-24 03:13:08 +00:00
* const prefixed = postcss.decl({
* prop: '-moz-' + decl.prop,
* value: decl.value
* })
*
2023-09-06 01:51:55 +00:00
* // Correct method, source is inherited when duplicating.
* const prefixed = decl.clone({
* prop: '-moz-' + decl.prop
* })
2023-07-24 03:13:08 +00:00
* ```
*
* ```js
* if (atrule.name === 'add-link') {
2023-09-06 01:51:55 +00:00
* const rule = postcss.rule({
* selector: 'a',
* source: atrule.source
* })
*
* atrule.parent.insertBefore(atrule, rule)
2023-07-24 03:13:08 +00:00
* }
* ```
*/
2023-09-06 01:51:55 +00:00
source?: Node.Source
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It represents type of a node in
* an abstract syntax tree.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* A type of node helps in identification of a node
* and perform operation based on it's type.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* const declaration = new Declaration({
* prop: 'color',
* value: 'black'
* })
*
* declaration.type //=> 'decl'
2023-07-24 03:13:08 +00:00
* ```
*/
2023-09-06 01:51:55 +00:00
type: string
2023-07-24 03:13:08 +00:00
constructor(defaults?: object)
/**
2023-09-06 01:51:55 +00:00
* Insert new node after current node to current nodes parent.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* Just alias for `node.parent.insertAfter(node, add)`.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* decl.after('color: black')
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @param newNode New node.
* @return This node for methods chain.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
after(newNode: Node | Node.ChildProps | Node[] | string): this
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It assigns properties to an existing node instance.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* decl.assign({ prop: 'word-wrap', value: 'break-word' })
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @param overrides New properties to override the node.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* @return `this` for method chaining.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
assign(overrides: object): this
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* Insert new node before current node to current nodes parent.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* Just alias for `node.parent.insertBefore(node, add)`.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* decl.before('content: ""')
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @param newNode New node.
* @return This node for methods chain.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
before(newNode: Node | Node.ChildProps | Node[] | string): this
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* Clear the code style properties for the node and its children.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* node.raws.before //=> ' '
* node.cleanRaws()
* node.raws.before //=> undefined
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @param keepBetween Keep the `raws.between` symbols.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
cleanRaws(keepBetween?: boolean): void
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It creates clone of an existing node, which includes all the properties
* and their values, that includes `raws` but not `type`.
2023-07-24 03:13:08 +00:00
*
* ```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.
2023-09-06 01:51:55 +00:00
*
* @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.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
cloneAfter(overrides?: object): Node
2023-07-24 03:13:08 +00:00
/**
* 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
*/
2023-09-06 01:51:55 +00:00
cloneBefore(overrides?: object): Node
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It creates an instance of the class `CssSyntaxError` and parameters passed
* to this method are assigned to the error instance.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* 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.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* 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
2023-07-24 03:13:08 +00:00
* }
* ```
*
2023-09-06 01:51:55 +00:00
* @param message Description for the error instance.
* @param options Options for the error instance.
*
* @return Error instance is returned.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
error(message: string, options?: Node.NodeErrorOptions): CssSyntaxError
2023-07-24 03:13:08 +00:00
/**
* 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.
*/
2023-09-06 01:51:55 +00:00
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
2023-07-24 03:13:08 +00:00
/**
* 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.
*/
2023-09-06 01:51:55 +00:00
prev(): Node.ChildNode | undefined
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* Get the range for a word or start and end index inside the node.
* The start index is inclusive; the end index is exclusive.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* @param opts Options.
* @return Range.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
rangeBy(
opts?: Pick<WarningOptions, 'endIndex' | 'index' | 'word'>
): Node.Range
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* 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.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* 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') //=> ' '
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @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.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
raw(prop: string, defaultType?: string): string
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It removes the node from its parent and deletes its parent property.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* if (decl.prop.match(/^-webkit-/)) {
* decl.remove()
* }
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @return `this` for method chaining.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
remove(): this
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* Inserts node(s) before the current node and removes the current node.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* AtRule: {
* mixin: atrule => {
* atrule.replaceWith(mixinRules[atrule.params])
* }
* }
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @param nodes Mode(s) to replace current one.
* @return Current node to methods chain.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
replaceWith(
...nodes: (
| Node.ChildNode
| Node.ChildNode[]
| Node.ChildProps
| Node.ChildProps[]
)[]
): this
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* Finds the Root instance of the nodes tree.
2023-07-24 03:13:08 +00:00
*
* ```js
2023-09-06 01:51:55 +00:00
* root.nodes[0].nodes[0].root() === root
2023-07-24 03:13:08 +00:00
* ```
*
2023-09-06 01:51:55 +00:00
* @return Root parent.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
root(): Root
2023-07-24 03:13:08 +00:00
/**
* Fix circular links on `JSON.stringify()`.
*
* @return Cleaned object.
*/
toJSON(): object
/**
2023-09-06 01:51:55 +00:00
* It compiles the node to browser readable cascading style sheets string
* depending on it's type.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* ```js
* new Rule({ selector: 'a' }).toString() //=> "a {}"
* ```
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* @param stringifier A syntax to use in string generation.
* @return CSS string of this node.
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
toString(stringifier?: Stringifier | Syntax): string
2023-07-24 03:13:08 +00:00
/**
2023-09-06 01:51:55 +00:00
* It is a wrapper for {@link Result#warn}, providing convenient
* way of generating warnings.
2023-07-24 03:13:08 +00:00
*
2023-09-06 01:51:55 +00:00
* ```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
2023-07-24 03:13:08 +00:00
*/
2023-09-06 01:51:55 +00:00
warn(result: Result, message: string, options?: WarningOptions): Warning
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
declare class Node extends Node_ { }
export = Node