Comparing version 8.4.5 to 8.4.24
import Container, { ContainerProps } from './container.js' | ||
interface AtRuleRaws extends Record<string, unknown> { | ||
/** | ||
* The space symbols before the node. It also stores `*` | ||
* and `_` symbols before the declaration (IE hack). | ||
*/ | ||
before?: string | ||
declare namespace AtRule { | ||
export interface AtRuleRaws extends Record<string, unknown> { | ||
/** | ||
* The space symbols before the node. It also stores `*` | ||
* and `_` symbols before the declaration (IE hack). | ||
*/ | ||
before?: string | ||
/** | ||
* The space symbols after the last child of the node to the end of the node. | ||
*/ | ||
after?: string | ||
/** | ||
* 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 between the at-rule name and its parameters. | ||
*/ | ||
afterName?: string | ||
/** | ||
* The symbols between the last parameter and `{` for rules. | ||
*/ | ||
between?: string | ||
/** | ||
* The symbols between the last parameter and `{` for rules. | ||
*/ | ||
between?: string | ||
/** | ||
* Contains `true` if the last child has an (optional) semicolon. | ||
*/ | ||
semicolon?: boolean | ||
/** | ||
* Contains `true` if the last child has an (optional) semicolon. | ||
*/ | ||
semicolon?: boolean | ||
/** | ||
* The rule’s selector with comments. | ||
*/ | ||
params?: { | ||
value: string | ||
raw: string | ||
/** | ||
* The rule’s selector with comments. | ||
*/ | ||
params?: { | ||
value: string | ||
raw: string | ||
} | ||
} | ||
} | ||
export interface AtRuleProps extends ContainerProps { | ||
/** Name of the at-rule. */ | ||
name: string | ||
/** Parameters following the name of the at-rule. */ | ||
params?: string | number | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: AtRuleRaws | ||
export interface AtRuleProps extends ContainerProps { | ||
/** Name of the at-rule. */ | ||
name: string | ||
/** Parameters following the name of the at-rule. */ | ||
params?: string | number | ||
/** 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 } | ||
} | ||
@@ -59,3 +64,3 @@ | ||
* | ||
* If it’s followed in the CSS by a {} block, this node will have | ||
* If it’s followed in the CSS by a `{}` block, this node will have | ||
* a nodes property representing its children. | ||
@@ -74,6 +79,6 @@ * | ||
*/ | ||
export default class AtRule extends Container { | ||
declare class AtRule_ extends Container { | ||
type: 'atrule' | ||
parent: Container | undefined | ||
raws: AtRuleRaws | ||
raws: AtRule.AtRuleRaws | ||
@@ -93,3 +98,3 @@ /** | ||
* The at-rule’s parameters, the values that follow the at-rule’s name | ||
* but precede any {} block. | ||
* but precede any `{}` block. | ||
* | ||
@@ -104,7 +109,11 @@ * ```js | ||
constructor(defaults?: AtRuleProps) | ||
assign(overrides: object | AtRuleProps): this | ||
clone(overrides?: Partial<AtRuleProps>): this | ||
cloneBefore(overrides?: Partial<AtRuleProps>): this | ||
cloneAfter(overrides?: Partial<AtRuleProps>): this | ||
constructor(defaults?: AtRule.AtRuleProps) | ||
assign(overrides: object | AtRule.AtRuleProps): this | ||
clone(overrides?: Partial<AtRule.AtRuleProps>): this | ||
cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this | ||
cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this | ||
} | ||
declare class AtRule extends AtRule_ {} | ||
export = AtRule |
import Container from './container.js' | ||
import Node, { NodeProps } from './node.js' | ||
interface CommentRaws extends Record<string, unknown> { | ||
/** | ||
* The space symbols before the node. | ||
*/ | ||
before?: string | ||
declare namespace Comment { | ||
export interface CommentRaws extends Record<string, unknown> { | ||
/** | ||
* The space symbols before the node. | ||
*/ | ||
before?: string | ||
/** | ||
* The space symbols between `/*` and the comment’s text. | ||
*/ | ||
left?: string | ||
/** | ||
* The space symbols between `/*` and the comment’s text. | ||
*/ | ||
left?: string | ||
/** | ||
* The space symbols between the comment’s text. | ||
*/ | ||
right?: string | ||
} | ||
/** | ||
* The space symbols between the comment’s text. | ||
*/ | ||
right?: string | ||
} | ||
export interface CommentProps extends NodeProps { | ||
/** Content of the comment. */ | ||
text: string | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: CommentRaws | ||
export interface CommentProps extends NodeProps { | ||
/** Content of the comment. */ | ||
text: string | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: CommentRaws | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Comment_ as default } | ||
} | ||
@@ -41,6 +46,6 @@ | ||
*/ | ||
export default class Comment extends Node { | ||
declare class Comment_ extends Node { | ||
type: 'comment' | ||
parent: Container | undefined | ||
raws: CommentRaws | ||
raws: Comment.CommentRaws | ||
@@ -52,7 +57,11 @@ /** | ||
constructor(defaults?: CommentProps) | ||
assign(overrides: object | CommentProps): this | ||
clone(overrides?: Partial<CommentProps>): this | ||
cloneBefore(overrides?: Partial<CommentProps>): this | ||
cloneAfter(overrides?: Partial<CommentProps>): this | ||
constructor(defaults?: Comment.CommentProps) | ||
assign(overrides: object | Comment.CommentProps): this | ||
clone(overrides?: Partial<Comment.CommentProps>): this | ||
cloneBefore(overrides?: Partial<Comment.CommentProps>): this | ||
cloneAfter(overrides?: Partial<Comment.CommentProps>): this | ||
} | ||
declare class Comment extends Comment_ {} | ||
export = Comment |
@@ -7,16 +7,21 @@ import Node, { ChildNode, NodeProps, ChildProps } from './node.js' | ||
interface ValueOptions { | ||
/** | ||
* An array of property names. | ||
*/ | ||
props?: string[] | ||
declare namespace Container { | ||
export interface ValueOptions { | ||
/** | ||
* An array of property names. | ||
*/ | ||
props?: string[] | ||
/** | ||
* String that’s used to narrow down values and speed up the regexp search. | ||
*/ | ||
fast?: string | ||
} | ||
/** | ||
* String that’s used to narrow down values and speed up the regexp search. | ||
*/ | ||
fast?: string | ||
} | ||
export interface ContainerProps extends NodeProps { | ||
nodes?: (ChildNode | ChildProps)[] | ||
export interface ContainerProps extends NodeProps { | ||
nodes?: (ChildNode | ChildProps)[] | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Container_ as default } | ||
} | ||
@@ -31,3 +36,3 @@ | ||
*/ | ||
export default abstract class Container< | ||
declare abstract class Container_< | ||
Child extends Node = ChildNode | ||
@@ -395,3 +400,3 @@ > extends Node { | ||
pattern: string | RegExp, | ||
options: ValueOptions, | ||
options: Container.ValueOptions, | ||
replaced: string | { (substring: string, ...args: any[]): string } | ||
@@ -446,1 +451,5 @@ ): this | ||
} | ||
declare class Container<Child extends Node = ChildNode> extends Container_<Child> {} | ||
export = Container |
@@ -8,3 +8,3 @@ 'use strict' | ||
let parse, Rule, AtRule | ||
let parse, Rule, AtRule, Root | ||
@@ -180,12 +180,12 @@ function cleanSource(nodes) { | ||
insertBefore(exist, add) { | ||
exist = this.index(exist) | ||
let existIndex = this.index(exist) | ||
let type = existIndex === 0 ? 'prepend' : false | ||
let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse() | ||
existIndex = this.index(exist) | ||
for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node) | ||
let type = exist === 0 ? 'prepend' : false | ||
let nodes = this.normalize(add, this.proxyOf.nodes[exist], type).reverse() | ||
for (let node of nodes) this.proxyOf.nodes.splice(exist, 0, node) | ||
let index | ||
for (let id in this.indexes) { | ||
index = this.indexes[id] | ||
if (exist <= index) { | ||
if (existIndex <= index) { | ||
this.indexes[id] = index + nodes.length | ||
@@ -201,11 +201,11 @@ } | ||
insertAfter(exist, add) { | ||
exist = this.index(exist) | ||
let existIndex = this.index(exist) | ||
let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse() | ||
existIndex = this.index(exist) | ||
for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node) | ||
let nodes = this.normalize(add, this.proxyOf.nodes[exist]).reverse() | ||
for (let node of nodes) this.proxyOf.nodes.splice(exist + 1, 0, node) | ||
let index | ||
for (let id in this.indexes) { | ||
index = this.indexes[id] | ||
if (exist < index) { | ||
if (existIndex < index) { | ||
this.indexes[id] = index + nodes.length | ||
@@ -332,3 +332,3 @@ } | ||
} | ||
i.parent = this | ||
i.parent = this.proxyOf | ||
return i | ||
@@ -414,2 +414,6 @@ }) | ||
Container.registerRoot = dependant => { | ||
Root = dependant | ||
} | ||
module.exports = Container | ||
@@ -428,2 +432,4 @@ Container.default = Container | ||
Object.setPrototypeOf(node, Comment.prototype) | ||
} else if (node.type === 'root') { | ||
Object.setPrototypeOf(node, Root.prototype) | ||
} | ||
@@ -430,0 +436,0 @@ |
import { FilePosition } from './input.js' | ||
/** | ||
* A position that is part of a range. | ||
*/ | ||
export interface RangePosition { | ||
declare namespace CssSyntaxError { | ||
/** | ||
* The line number in the input. | ||
* A position that is part of a range. | ||
*/ | ||
line: number | ||
export interface RangePosition { | ||
/** | ||
* The line number in the input. | ||
*/ | ||
line: number | ||
/** | ||
* The column number in the input. | ||
*/ | ||
column: number | ||
/** | ||
* The column number in the input. | ||
*/ | ||
column: number | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { CssSyntaxError_ as default } | ||
} | ||
@@ -47,3 +52,3 @@ | ||
*/ | ||
export default class CssSyntaxError { | ||
declare class CssSyntaxError_ { | ||
/** | ||
@@ -63,4 +68,4 @@ * Instantiates a CSS syntax error. Can be instantiated for a single position | ||
message: string, | ||
lineOrStartPos?: number | RangePosition, | ||
columnOrEndPos?: number | RangePosition, | ||
lineOrStartPos?: number | CssSyntaxError.RangePosition, | ||
columnOrEndPos?: number | CssSyntaxError.RangePosition, | ||
source?: string, | ||
@@ -242,1 +247,5 @@ file?: string, | ||
} | ||
declare class CssSyntaxError extends CssSyntaxError_ {} | ||
export = CssSyntaxError |
import Container from './container.js' | ||
import Node from './node.js' | ||
interface DeclarationRaws extends Record<string, unknown> { | ||
/** | ||
* The space symbols before the node. It also stores `*` | ||
* and `_` symbols before the declaration (IE hack). | ||
*/ | ||
before?: string | ||
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 symbols between the property and value for declarations. | ||
*/ | ||
between?: string | ||
/** | ||
* The content of the important statement, if it is not just `!important`. | ||
*/ | ||
important?: string | ||
/** | ||
* The content of the important statement, if it is not just `!important`. | ||
*/ | ||
important?: string | ||
/** | ||
* Declaration value with comments. | ||
*/ | ||
value: { | ||
/** | ||
* Declaration value with comments. | ||
*/ | ||
value?: { | ||
value: string | ||
raw: string | ||
} | ||
} | ||
export interface DeclarationProps { | ||
/** Name of the declaration. */ | ||
prop: string | ||
/** Value of the declaration. */ | ||
value: string | ||
raw: string | ||
/** Whether the declaration has an `!important` annotation. */ | ||
important?: boolean | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: DeclarationRaws | ||
} | ||
} | ||
export interface DeclarationProps { | ||
/** Name of the declaration. */ | ||
prop: string | ||
/** Value of the declaration. */ | ||
value: string | ||
/** Whether the declaration has an `!important` annotation. */ | ||
important?: boolean | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: DeclarationRaws | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Declaration_ as default } | ||
} | ||
@@ -58,6 +63,6 @@ | ||
*/ | ||
export default class Declaration extends Node { | ||
declare class Declaration_ extends Node { | ||
type: 'decl' | ||
parent: Container | undefined | ||
raws: DeclarationRaws | ||
raws: Declaration.DeclarationRaws | ||
@@ -120,7 +125,11 @@ /** | ||
constructor(defaults?: DeclarationProps) | ||
assign(overrides: object | DeclarationProps): this | ||
clone(overrides?: Partial<DeclarationProps>): this | ||
cloneBefore(overrides?: Partial<DeclarationProps>): this | ||
cloneAfter(overrides?: Partial<DeclarationProps>): this | ||
constructor(defaults?: Declaration.DeclarationProps) | ||
assign(overrides: object | Declaration.DeclarationProps): this | ||
clone(overrides?: Partial<Declaration.DeclarationProps>): this | ||
cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this | ||
cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this | ||
} | ||
declare class Declaration extends Declaration_ {} | ||
export = Declaration |
import Container, { ContainerProps } from './container.js' | ||
import { ProcessOptions } from './postcss.js' | ||
import Result from './result.js' | ||
import Root, { RootProps } from './root.js' | ||
import Root from './root.js' | ||
export interface DocumentProps extends ContainerProps { | ||
nodes?: Root[] | ||
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> | ||
/** | ||
* 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 } | ||
} | ||
type ChildNode = Root | ||
type ChildProps = RootProps | ||
/** | ||
@@ -35,7 +37,7 @@ * Represents a file and contains all its parsed nodes. | ||
*/ | ||
export default class Document extends Container<Root> { | ||
declare class Document_ extends Container<Root> { | ||
type: 'document' | ||
parent: undefined | ||
constructor(defaults?: DocumentProps) | ||
constructor(defaults?: Document.DocumentProps) | ||
@@ -59,1 +61,5 @@ /** | ||
} | ||
declare class Document extends Document_ {} | ||
export = Document |
import { JSONHydrator } from './postcss.js' | ||
declare const fromJSON: JSONHydrator | ||
interface FromJSON extends JSONHydrator { | ||
default: FromJSON | ||
} | ||
export default fromJSON | ||
declare const fromJSON: FromJSON | ||
export = fromJSON |
@@ -1,39 +0,44 @@ | ||
import { ProcessOptions } from './postcss.js' | ||
import { CssSyntaxError, ProcessOptions } from './postcss.js' | ||
import PreviousMap from './previous-map.js' | ||
export interface FilePosition { | ||
/** | ||
* URL for the source file. | ||
*/ | ||
url: string | ||
declare namespace Input { | ||
export interface FilePosition { | ||
/** | ||
* URL for the source file. | ||
*/ | ||
url: string | ||
/** | ||
* Absolute path to the source file. | ||
*/ | ||
file?: string | ||
/** | ||
* Absolute path to the source file. | ||
*/ | ||
file?: string | ||
/** | ||
* Line of inclusive start position in source file. | ||
*/ | ||
line: number | ||
/** | ||
* Line of inclusive start position in source file. | ||
*/ | ||
line: number | ||
/** | ||
* Column of inclusive start position in source file. | ||
*/ | ||
column: number | ||
/** | ||
* Column of inclusive start position in source file. | ||
*/ | ||
column: number | ||
/** | ||
* Line of exclusive end position in source file. | ||
*/ | ||
endLine?: number | ||
/** | ||
* Line of exclusive end position in source file. | ||
*/ | ||
endLine?: number | ||
/** | ||
* Column of exclusive end position in source file. | ||
*/ | ||
endColumn?: number | ||
/** | ||
* Column of exclusive end position in source file. | ||
*/ | ||
endColumn?: number | ||
/** | ||
* Source code. | ||
*/ | ||
source?: string | ||
/** | ||
* Source code. | ||
*/ | ||
source?: string | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Input_ as default } | ||
} | ||
@@ -49,3 +54,3 @@ | ||
*/ | ||
export default class Input { | ||
declare class Input_ { | ||
/** | ||
@@ -143,3 +148,3 @@ * Input CSS source. | ||
endColumn?: number | ||
): FilePosition | false | ||
): Input.FilePosition | false | ||
@@ -152,2 +157,41 @@ /** | ||
fromOffset(offset: number): { line: number; col: number } | null | ||
/** | ||
* 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 | ||
error( | ||
message: string, | ||
start: | ||
| { | ||
offset: number | ||
} | ||
| { | ||
line: number | ||
column: number | ||
}, | ||
end: | ||
| { | ||
offset: number | ||
} | ||
| { | ||
line: number | ||
column: number | ||
}, | ||
opts?: { plugin?: CssSyntaxError['plugin'] } | ||
): CssSyntaxError | ||
} | ||
declare class Input extends Input_ {} | ||
export = Input |
@@ -111,3 +111,3 @@ 'use strict' | ||
let end = column | ||
if (typeof line.offset === 'number') { | ||
if (typeof start.offset === 'number') { | ||
let pos = this.fromOffset(start.offset) | ||
@@ -114,0 +114,0 @@ line = pos.line |
@@ -7,2 +7,7 @@ import Result, { Message, ResultOptions } from './result.js' | ||
declare namespace LazyResult { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { LazyResult_ as default } | ||
} | ||
/** | ||
@@ -17,3 +22,3 @@ * A Promise proxy for the result of PostCSS transformations. | ||
*/ | ||
export default class LazyResult implements PromiseLike<Result> { | ||
declare class LazyResult_ implements PromiseLike<Result> { | ||
/** | ||
@@ -179,1 +184,5 @@ * Processes input CSS through synchronous and asynchronous plugins | ||
} | ||
declare class LazyResult extends LazyResult_ {} | ||
export = LazyResult |
@@ -1,51 +0,57 @@ | ||
export type List = { | ||
/** | ||
* 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[] | ||
/** | ||
* 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[] | ||
declare namespace list { | ||
type List = { | ||
default: 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[] | ||
/** | ||
* 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[] | ||
/** | ||
* 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 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[] | ||
} | ||
} | ||
declare const list: List | ||
// eslint-disable-next-line @typescript-eslint/no-redeclare | ||
declare const list: list.List | ||
export default list | ||
export = list |
@@ -10,3 +10,4 @@ 'use strict' | ||
let func = 0 | ||
let quote = false | ||
let inQuote = false | ||
let prevQuote = '' | ||
let escape = false | ||
@@ -19,8 +20,9 @@ | ||
escape = true | ||
} else if (quote) { | ||
if (letter === quote) { | ||
quote = false | ||
} else if (inQuote) { | ||
if (letter === prevQuote) { | ||
inQuote = false | ||
} | ||
} else if (letter === '"' || letter === "'") { | ||
quote = letter | ||
inQuote = true | ||
prevQuote = letter | ||
} else if (letter === '(') { | ||
@@ -27,0 +29,0 @@ func += 1 |
@@ -19,2 +19,3 @@ 'use strict' | ||
this.css = cssString | ||
this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute | ||
} | ||
@@ -101,6 +102,6 @@ | ||
already[from] = true | ||
this.map.setSourceContent( | ||
this.toUrl(this.path(from)), | ||
node.source.input.css | ||
) | ||
let fromUrl = this.usesFileUrls | ||
? this.toFileUrl(from) | ||
: this.toUrl(this.path(from)) | ||
this.map.setSourceContent(fromUrl, node.source.input.css) | ||
} | ||
@@ -237,13 +238,17 @@ } | ||
toFileUrl(path) { | ||
if (pathToFileURL) { | ||
return pathToFileURL(path).toString() | ||
} else { | ||
throw new Error( | ||
'`map.absolute` option is not available in this PostCSS build' | ||
) | ||
} | ||
} | ||
sourcePath(node) { | ||
if (this.mapOpts.from) { | ||
return this.toUrl(this.mapOpts.from) | ||
} else if (this.mapOpts.absolute) { | ||
if (pathToFileURL) { | ||
return pathToFileURL(node.source.input.from).toString() | ||
} else { | ||
throw new Error( | ||
'`map.absolute` option is not available in this PostCSS build' | ||
) | ||
} | ||
} else if (this.usesFileUrls) { | ||
return this.toFileUrl(node.source.input.from) | ||
} else { | ||
@@ -299,3 +304,5 @@ return this.toUrl(this.path(node.source.input.from)) | ||
let p = node.parent || { raws: {} } | ||
if (node.type !== 'decl' || node !== p.last || p.raws.semicolon) { | ||
let childless = | ||
node.type === 'decl' || (node.type === 'atrule' && !node.nodes) | ||
if (!childless || node !== p.last || p.raws.semicolon) { | ||
if (node.source && node.source.end) { | ||
@@ -302,0 +309,0 @@ mapping.source = this.sourcePath(node) |
@@ -8,2 +8,7 @@ import Result, { Message, ResultOptions } from './result.js' | ||
declare namespace NoWorkResult { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { NoWorkResult_ as default } | ||
} | ||
/** | ||
@@ -21,3 +26,3 @@ * A Promise proxy for the result of PostCSS transformations. | ||
*/ | ||
export default class NoWorkResult implements LazyResult { | ||
declare class NoWorkResult_ implements LazyResult { | ||
then: Promise<Result>['then'] | ||
@@ -40,1 +45,5 @@ catch: Promise<Result>['catch'] | ||
} | ||
declare class NoWorkResult extends NoWorkResult_ {} | ||
export = NoWorkResult |
@@ -81,5 +81,8 @@ 'use strict' | ||
this._root = root | ||
return root | ||
if (this.error) { | ||
throw this.error | ||
} else { | ||
this._root = root | ||
return root | ||
} | ||
} | ||
@@ -86,0 +89,0 @@ |
import Declaration, { DeclarationProps } from './declaration.js' | ||
import Comment, { CommentProps } from './comment.js' | ||
import { Stringifier, Syntax } from './postcss.js' | ||
import AtRule, { AtRuleProps } from './at-rule.js' | ||
import AtRule = require('./at-rule.js') | ||
import { AtRuleProps } from './at-rule.js' | ||
import Rule, { RuleProps } from './rule.js' | ||
import { WarningOptions } from './warning.js' | ||
import Warning, { WarningOptions } from './warning.js' | ||
import CssSyntaxError from './css-syntax-error.js' | ||
@@ -14,80 +15,86 @@ import Result from './result.js' | ||
export type ChildNode = AtRule | Rule | Declaration | Comment | ||
declare namespace Node { | ||
export type ChildNode = AtRule.default | Rule | Declaration | Comment | ||
export type AnyNode = AtRule | Rule | Declaration | Comment | Root | Document | ||
export type AnyNode = AtRule.default | Rule | Declaration | Comment | Root | Document | ||
export type ChildProps = | ||
| AtRuleProps | ||
| RuleProps | ||
| DeclarationProps | ||
| CommentProps | ||
export type ChildProps = | ||
| AtRuleProps | ||
| RuleProps | ||
| DeclarationProps | ||
| CommentProps | ||
export interface Position { | ||
/** | ||
* Source offset in file. It starts from 0. | ||
*/ | ||
offset: number | ||
export interface Position { | ||
/** | ||
* Source offset in file. It starts from 0. | ||
*/ | ||
offset: number | ||
/** | ||
* Source line in file. In contrast to `offset` it starts from 1. | ||
*/ | ||
column: number | ||
/** | ||
* Source line in file. In contrast to `offset` it starts from 1. | ||
*/ | ||
column: number | ||
/** | ||
* Source column in file. | ||
*/ | ||
line: number | ||
} | ||
/** | ||
* Source column in file. | ||
*/ | ||
line: number | ||
} | ||
export interface Range { | ||
/** | ||
* Start position, inclusive. | ||
*/ | ||
start: Position | ||
export interface Range { | ||
/** | ||
* Start position, inclusive. | ||
*/ | ||
start: Position | ||
/** | ||
* End position, exclusive. | ||
*/ | ||
end: Position | ||
} | ||
/** | ||
* End position, exclusive. | ||
*/ | ||
end: Position | ||
} | ||
export interface Source { | ||
/** | ||
* The file source of the node. | ||
*/ | ||
input: Input | ||
/** | ||
* The inclusive starting position of the node’s source. | ||
*/ | ||
start?: Position | ||
/** | ||
* The inclusive ending position of the node's source. | ||
*/ | ||
end?: Position | ||
} | ||
export interface Source { | ||
/** | ||
* The file source of the node. | ||
*/ | ||
input: Input | ||
/** | ||
* The inclusive starting position of the node’s source. | ||
*/ | ||
start?: Position | ||
/** | ||
* The inclusive ending position of the node's source. | ||
*/ | ||
end?: Position | ||
} | ||
export interface NodeProps { | ||
source?: Source | ||
} | ||
export interface NodeProps { | ||
source?: Source | ||
} | ||
interface NodeErrorOptions { | ||
/** | ||
* 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 | ||
/** | ||
* An index inside a node's string that should be highlighted as source | ||
* of error. | ||
*/ | ||
index?: number | ||
/** | ||
* An ending index inside a node's string that should be highlighted as | ||
* source of error. | ||
*/ | ||
endIndex?: number | ||
export interface NodeErrorOptions { | ||
/** | ||
* 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 | ||
/** | ||
* An index inside a node's string that should be highlighted as source | ||
* of error. | ||
*/ | ||
index?: number | ||
/** | ||
* An ending index inside a node's string that should be highlighted as | ||
* source of error. | ||
*/ | ||
endIndex?: number | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-shadow | ||
class Node extends Node_ {} | ||
export { Node as default } | ||
} | ||
@@ -101,3 +108,3 @@ | ||
*/ | ||
export default abstract class Node { | ||
declare abstract class Node_ { | ||
/** | ||
@@ -158,3 +165,3 @@ * tring representing the node’s type. Possible values are `root`, `atrule`, | ||
*/ | ||
source?: Source | ||
source?: Node.Source | ||
@@ -228,3 +235,3 @@ /** | ||
*/ | ||
error(message: string, options?: NodeErrorOptions): CssSyntaxError | ||
error(message: string, options?: Node.NodeErrorOptions): CssSyntaxError | ||
@@ -248,3 +255,3 @@ /** | ||
*/ | ||
warn(result: Result, text: string, opts?: WarningOptions): void | ||
warn(result: Result, text: string, opts?: WarningOptions): Warning | ||
@@ -345,3 +352,3 @@ /** | ||
replaceWith( | ||
...nodes: (ChildNode | ChildProps | ChildNode[] | ChildProps[])[] | ||
...nodes: (Node.ChildNode | Node.ChildProps | Node.ChildNode[] | Node.ChildProps[])[] | ||
): this | ||
@@ -364,3 +371,3 @@ | ||
*/ | ||
next(): ChildNode | undefined | ||
next(): Node.ChildNode | undefined | ||
@@ -380,3 +387,3 @@ /** | ||
*/ | ||
prev(): ChildNode | undefined | ||
prev(): Node.ChildNode | undefined | ||
@@ -395,3 +402,3 @@ /** | ||
*/ | ||
before(newNode: Node | ChildProps | string | Node[]): this | ||
before(newNode: Node | Node.ChildProps | string | Node[]): this | ||
@@ -410,3 +417,3 @@ /** | ||
*/ | ||
after(newNode: Node | ChildProps | string | Node[]): this | ||
after(newNode: Node | Node.ChildProps | string | Node[]): this | ||
@@ -470,3 +477,3 @@ /** | ||
*/ | ||
positionInside(index: number): Position | ||
positionInside(index: number): Node.Position | ||
@@ -479,3 +486,3 @@ /** | ||
*/ | ||
positionBy(opts?: Pick<WarningOptions, 'word' | 'index'>): Position | ||
positionBy(opts?: Pick<WarningOptions, 'word' | 'index'>): Node.Position | ||
@@ -489,3 +496,7 @@ /** | ||
*/ | ||
rangeBy(opts?: Pick<WarningOptions, 'word' | 'index' | 'endIndex'>): Range | ||
rangeBy(opts?: Pick<WarningOptions, 'word' | 'index' | 'endIndex'>): Node.Range | ||
} | ||
declare class Node extends Node_ {} | ||
export = Node |
import { Parser } from './postcss.js' | ||
declare const parse: Parser | ||
interface Parse extends Parser { | ||
default: Parse | ||
} | ||
export default parse | ||
declare const parse: Parse | ||
export = parse |
@@ -10,2 +10,15 @@ 'use strict' | ||
const SAFE_COMMENT_NEIGHBOR = { | ||
empty: true, | ||
space: true | ||
} | ||
function findLastWithPosition(tokens) { | ||
for (let i = tokens.length - 1; i >= 0; i--) { | ||
let token = tokens[i] | ||
let pos = token[3] || token[2] | ||
if (pos) return pos | ||
} | ||
} | ||
class Parser { | ||
@@ -143,6 +156,8 @@ constructor(input) { | ||
if (end && colon) { | ||
while (tokens.length) { | ||
token = tokens[tokens.length - 1][0] | ||
if (token !== 'space' && token !== 'comment') break | ||
this.tokenizer.back(tokens.pop()) | ||
if (!customProperty) { | ||
while (tokens.length) { | ||
token = tokens[tokens.length - 1][0] | ||
if (token !== 'space' && token !== 'comment') break | ||
this.tokenizer.back(tokens.pop()) | ||
} | ||
} | ||
@@ -175,4 +190,7 @@ this.decl(tokens, customProperty) | ||
} | ||
node.source.end = this.getPosition(last[3] || last[2]) | ||
node.source.end = this.getPosition( | ||
last[3] || last[2] || findLastWithPosition(tokens) | ||
) | ||
while (tokens[0][0] !== 'word') { | ||
@@ -214,3 +232,11 @@ if (tokens.length === 1) this.unknownWord(tokens) | ||
} | ||
let firstSpaces = this.spacesAndCommentsFromStart(tokens) | ||
let firstSpaces = [] | ||
let next | ||
while (tokens.length) { | ||
next = tokens[0][0] | ||
if (next !== 'space' && next !== 'comment') break | ||
firstSpaces.push(tokens.shift()) | ||
} | ||
this.precheckMissedSemicolon(tokens) | ||
@@ -249,8 +275,8 @@ | ||
let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment') | ||
this.raw(node, 'value', tokens) | ||
if (hasWord) { | ||
node.raws.between += firstSpaces | ||
} else { | ||
node.value = firstSpaces + node.value | ||
node.raws.between += firstSpaces.map(i => i[1]).join('') | ||
firstSpaces = [] | ||
} | ||
this.raw(node, 'value', firstSpaces.concat(tokens), customProperty) | ||
@@ -403,3 +429,3 @@ if (node.value.includes(':') && !customProperty) { | ||
raw(node, prop, tokens) { | ||
raw(node, prop, tokens, customProperty) { | ||
let token, type | ||
@@ -410,3 +436,2 @@ let length = tokens.length | ||
let next, prev | ||
let pattern = /^([#.|])?(\w)+/i | ||
@@ -416,23 +441,16 @@ for (let i = 0; i < length; i += 1) { | ||
type = token[0] | ||
if (type === 'comment' && node.type === 'rule') { | ||
prev = tokens[i - 1] | ||
next = tokens[i + 1] | ||
if ( | ||
prev[0] !== 'space' && | ||
next[0] !== 'space' && | ||
pattern.test(prev[1]) && | ||
pattern.test(next[1]) | ||
) { | ||
value += token[1] | ||
if (type === 'space' && i === length - 1 && !customProperty) { | ||
clean = false | ||
} else if (type === 'comment') { | ||
prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty' | ||
next = tokens[i + 1] ? tokens[i + 1][0] : 'empty' | ||
if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) { | ||
if (value.slice(-1) === ',') { | ||
clean = false | ||
} else { | ||
value += token[1] | ||
} | ||
} else { | ||
clean = false | ||
} | ||
continue | ||
} | ||
if (type === 'comment' || (type === 'space' && i === length - 1)) { | ||
clean = false | ||
} else { | ||
@@ -439,0 +457,0 @@ value += token[1] |
@@ -23,61 +23,20 @@ import { SourceMapGenerator, RawSourceMap } from 'source-map-js' | ||
import CssSyntaxError from './css-syntax-error.js' | ||
import list, { List } from './list.js' | ||
import list from './list.js' | ||
import LazyResult from './lazy-result.js' | ||
import Processor from './processor.js' | ||
export { | ||
NodeErrorOptions, | ||
DeclarationProps, | ||
CssSyntaxError, | ||
ContainerProps, | ||
WarningOptions, | ||
DocumentProps, | ||
FilePosition, | ||
CommentProps, | ||
AtRuleProps, | ||
Declaration, | ||
ChildProps, | ||
LazyResult, | ||
ChildNode, | ||
NodeProps, | ||
Processor, | ||
RuleProps, | ||
RootProps, | ||
Container, | ||
Position, | ||
Document, | ||
AnyNode, | ||
Warning, | ||
Message, | ||
Comment, | ||
Source, | ||
AtRule, | ||
Result, | ||
Input, | ||
Node, | ||
list, | ||
Rule, | ||
Root | ||
} | ||
export type SourceMap = SourceMapGenerator & { | ||
toJSON(): RawSourceMap | ||
} | ||
export type Helpers = { result: Result; postcss: Postcss } & Postcss | ||
type DocumentProcessor = ( | ||
document: Document, | ||
helper: Helpers | ||
helper: postcss.Helpers | ||
) => Promise<void> | void | ||
type RootProcessor = (root: Root, helper: Helpers) => Promise<void> | void | ||
type RootProcessor = (root: Root, helper: postcss.Helpers) => Promise<void> | void | ||
type DeclarationProcessor = ( | ||
decl: Declaration, | ||
helper: Helpers | ||
helper: postcss.Helpers | ||
) => Promise<void> | void | ||
type RuleProcessor = (rule: Rule, helper: Helpers) => Promise<void> | void | ||
type AtRuleProcessor = (atRule: AtRule, helper: 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: Helpers | ||
helper: postcss.Helpers | ||
) => Promise<void> | void | ||
@@ -183,190 +142,208 @@ | ||
CommentExit?: CommentProcessor | ||
/** | ||
* Will be called when all other listeners processed the document. | ||
* | ||
* This listener will not be called again. | ||
*/ | ||
Exit?: RootProcessor | ||
} | ||
export interface Plugin extends Processors { | ||
postcssPlugin: string | ||
prepare?: (result: Result) => Processors | ||
} | ||
declare namespace postcss { | ||
export { | ||
NodeErrorOptions, | ||
DeclarationProps, | ||
CssSyntaxError, | ||
ContainerProps, | ||
WarningOptions, | ||
DocumentProps, | ||
FilePosition, | ||
CommentProps, | ||
AtRuleProps, | ||
Declaration, | ||
ChildProps, | ||
LazyResult, | ||
ChildNode, | ||
NodeProps, | ||
Processor, | ||
RuleProps, | ||
RootProps, | ||
Container, | ||
Position, | ||
Document, | ||
AnyNode, | ||
Warning, | ||
Message, | ||
Comment, | ||
Source, | ||
AtRule, | ||
Result, | ||
Input, | ||
Node, | ||
list, | ||
Rule, | ||
Root | ||
} | ||
export interface PluginCreator<PluginOptions> { | ||
(opts?: PluginOptions): Plugin | Processor | ||
postcss: true | ||
} | ||
export type SourceMap = SourceMapGenerator & { | ||
toJSON(): RawSourceMap | ||
} | ||
export interface Transformer extends TransformCallback { | ||
postcssPlugin: string | ||
postcssVersion: string | ||
} | ||
export type Helpers = { result: Result; postcss: Postcss } & Postcss | ||
export interface TransformCallback { | ||
(root: Root, result: Result): Promise<void> | void | ||
} | ||
export interface Plugin extends Processors { | ||
postcssPlugin: string | ||
prepare?: (result: Result) => Processors | ||
} | ||
export interface OldPlugin<T> extends Transformer { | ||
(opts?: T): Transformer | ||
postcss: Transformer | ||
} | ||
export interface PluginCreator<PluginOptions> { | ||
(opts?: PluginOptions): Plugin | Processor | ||
postcss: true | ||
} | ||
export type AcceptedPlugin = | ||
| Plugin | ||
| PluginCreator<any> | ||
| OldPlugin<any> | ||
| TransformCallback | ||
| { | ||
postcss: TransformCallback | Processor | ||
} | ||
| Processor | ||
export interface Transformer extends TransformCallback { | ||
postcssPlugin: string | ||
postcssVersion: string | ||
} | ||
export interface Parser<RootNode = Root | Document> { | ||
( | ||
css: string | { toString(): string }, | ||
opts?: Pick<ProcessOptions, 'map' | 'from'> | ||
): RootNode | ||
} | ||
export interface TransformCallback { | ||
(root: Root, result: Result): Promise<void> | void | ||
} | ||
export interface Builder { | ||
(part: string, node?: AnyNode, type?: 'start' | 'end'): void | ||
} | ||
export interface OldPlugin<T> extends Transformer { | ||
(opts?: T): Transformer | ||
postcss: Transformer | ||
} | ||
export interface Stringifier { | ||
(node: AnyNode, builder: Builder): void | ||
} | ||
export type AcceptedPlugin = | ||
| Plugin | ||
| PluginCreator<any> | ||
| OldPlugin<any> | ||
| TransformCallback | ||
| { | ||
postcss: TransformCallback | Processor | ||
} | ||
| Processor | ||
export interface JSONHydrator { | ||
(data: object[]): Node[] | ||
(data: object): Node | ||
} | ||
export interface Parser<RootNode = Root | Document> { | ||
( | ||
css: string | { toString(): string }, | ||
opts?: Pick<ProcessOptions, 'map' | 'from'> | ||
): RootNode | ||
} | ||
export interface Syntax { | ||
/** | ||
* Function to generate AST by string. | ||
*/ | ||
parse?: Parser | ||
export interface Builder { | ||
(part: string, node?: AnyNode, type?: 'start' | 'end'): void | ||
} | ||
/** | ||
* Class to generate string by AST. | ||
*/ | ||
stringify?: Stringifier | ||
} | ||
export interface Stringifier { | ||
(node: AnyNode, builder: Builder): void | ||
} | ||
export interface SourceMapOptions { | ||
/** | ||
* 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 | ||
export interface JSONHydrator { | ||
(data: object[]): Node[] | ||
(data: object): Node | ||
} | ||
/** | ||
* 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?: string | boolean | object | ((file: string) => string) | ||
export interface Syntax { | ||
/** | ||
* Function to generate AST by string. | ||
*/ | ||
parse?: Parser | ||
/** | ||
* 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 | ||
/** | ||
* Class to generate string by AST. | ||
*/ | ||
stringify?: Stringifier | ||
} | ||
/** | ||
* 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?: string | boolean | ((file: string, root: Root) => string) | ||
export interface SourceMapOptions { | ||
/** | ||
* 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 | ||
/** | ||
* Override `from` in map’s sources. | ||
*/ | ||
from?: string | ||
/** | ||
* 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?: string | boolean | object | ((file: string) => string) | ||
/** | ||
* Use absolute path in generated source map. | ||
*/ | ||
absolute?: boolean | ||
} | ||
/** | ||
* 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 { | ||
/** | ||
* 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 | ||
/** | ||
* 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?: string | boolean | ((file: string, root: Root) => string) | ||
/** | ||
* The path where you'll put the output CSS file. You should always set `to` | ||
* to generate correct source maps. | ||
*/ | ||
to?: string | ||
/** | ||
* Override `from` in map’s sources. | ||
*/ | ||
from?: string | ||
/** | ||
* Function to generate AST by string. | ||
*/ | ||
parser?: Syntax | Parser | ||
/** | ||
* Use absolute path in generated source map. | ||
*/ | ||
absolute?: boolean | ||
} | ||
/** | ||
* Class to generate string by AST. | ||
*/ | ||
stringifier?: Syntax | Stringifier | ||
export interface ProcessOptions { | ||
/** | ||
* 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 | ||
/** | ||
* Object with parse and stringify. | ||
*/ | ||
syntax?: Syntax | ||
/** | ||
* The path where you'll put the output CSS file. You should always set `to` | ||
* to generate correct source maps. | ||
*/ | ||
to?: string | ||
/** | ||
* Source map options | ||
*/ | ||
map?: SourceMapOptions | boolean | ||
} | ||
/** | ||
* Function to generate AST by string. | ||
*/ | ||
parser?: Syntax | Parser | ||
export interface Postcss { | ||
/** | ||
* 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. | ||
*/ | ||
(plugins?: AcceptedPlugin[]): Processor | ||
(...plugins: AcceptedPlugin[]): Processor | ||
/** | ||
* Class to generate string by AST. | ||
*/ | ||
stringifier?: Syntax | Stringifier | ||
/** | ||
* Object with parse and stringify. | ||
*/ | ||
syntax?: Syntax | ||
/** | ||
* Source map options | ||
*/ | ||
map?: SourceMapOptions | boolean | ||
} | ||
export type Postcss = typeof postcss | ||
/** | ||
* Default function to convert a node tree into a CSS string. | ||
*/ | ||
stringify: Stringifier | ||
export let stringify: Stringifier | ||
@@ -384,3 +361,3 @@ /** | ||
*/ | ||
parse: Parser<Root> | ||
export let parse: Parser<Root> | ||
@@ -396,10 +373,5 @@ /** | ||
*/ | ||
fromJSON: JSONHydrator | ||
export let fromJSON: JSONHydrator | ||
/** | ||
* Contains the `list` module. | ||
*/ | ||
list: List | ||
/** | ||
* Creates a new `Comment` node. | ||
@@ -410,3 +382,3 @@ * | ||
*/ | ||
comment(defaults?: CommentProps): Comment | ||
export function comment(defaults?: CommentProps): Comment | ||
@@ -419,3 +391,3 @@ /** | ||
*/ | ||
atRule(defaults?: AtRuleProps): AtRule | ||
export function atRule(defaults?: AtRuleProps): AtRule | ||
@@ -428,3 +400,3 @@ /** | ||
*/ | ||
decl(defaults?: DeclarationProps): Declaration | ||
export function decl(defaults?: DeclarationProps): Declaration | ||
@@ -437,3 +409,3 @@ /** | ||
*/ | ||
rule(defaults?: RuleProps): Rule | ||
export function rule(defaults?: RuleProps): Rule | ||
@@ -446,3 +418,3 @@ /** | ||
*/ | ||
root(defaults?: RootProps): Root | ||
export function root(defaults?: RootProps): Root | ||
@@ -455,29 +427,25 @@ /** | ||
*/ | ||
document(defaults?: DocumentProps): Document | ||
export function document(defaults?: DocumentProps): Document | ||
CssSyntaxError: typeof CssSyntaxError | ||
Declaration: typeof Declaration | ||
Container: typeof Container | ||
Comment: typeof Comment | ||
Warning: typeof Warning | ||
AtRule: typeof AtRule | ||
Result: typeof Result | ||
Input: typeof Input | ||
Rule: typeof Rule | ||
Root: typeof Root | ||
Node: typeof Node | ||
export { postcss as default } | ||
} | ||
export const stringify: Stringifier | ||
export const parse: Parser<Root> | ||
export const fromJSON: JSONHydrator | ||
/** | ||
* 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 const comment: Postcss['comment'] | ||
export const atRule: Postcss['atRule'] | ||
export const decl: Postcss['decl'] | ||
export const rule: Postcss['rule'] | ||
export const root: Postcss['root'] | ||
declare const postcss: Postcss | ||
export default postcss | ||
export = postcss |
@@ -30,21 +30,23 @@ 'use strict' | ||
postcss.plugin = function plugin(name, initializer) { | ||
// eslint-disable-next-line no-console | ||
if (console && console.warn) { | ||
let warningPrinted = false | ||
function creator(...args) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
name + | ||
': postcss.plugin was deprecated. Migration guide:\n' + | ||
'https://evilmartians.com/chronicles/postcss-8-plugin-migration' | ||
) | ||
if (process.env.LANG && process.env.LANG.startsWith('cn')) { | ||
/* c8 ignore next 7 */ | ||
if (console && console.warn && !warningPrinted) { | ||
warningPrinted = true | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
name + | ||
': 里面 postcss.plugin 被弃用. 迁移指南:\n' + | ||
'https://www.w3ctech.com/topic/2226' | ||
': postcss.plugin was deprecated. Migration guide:\n' + | ||
'https://evilmartians.com/chronicles/postcss-8-plugin-migration' | ||
) | ||
if (process.env.LANG && process.env.LANG.startsWith('cn')) { | ||
/* c8 ignore next 7 */ | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
name + | ||
': 里面 postcss.plugin 被弃用. 迁移指南:\n' + | ||
'https://www.w3ctech.com/topic/2226' | ||
) | ||
} | ||
} | ||
} | ||
function creator(...args) { | ||
let transformer = initializer(...args) | ||
@@ -51,0 +53,0 @@ transformer.postcssPlugin = name |
@@ -5,2 +5,7 @@ import { SourceMapConsumer } from 'source-map-js' | ||
declare namespace PreviousMap { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { PreviousMap_ as default } | ||
} | ||
/** | ||
@@ -18,3 +23,3 @@ * Source map information from input CSS. | ||
*/ | ||
export default class PreviousMap { | ||
declare class PreviousMap_ { | ||
/** | ||
@@ -75,1 +80,5 @@ * Was source map inlined by data-uri to input CSS. | ||
} | ||
declare class PreviousMap extends PreviousMap_ {} | ||
export = PreviousMap |
@@ -13,2 +13,7 @@ import { | ||
declare namespace Processor { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Processor_ as default } | ||
} | ||
/** | ||
@@ -24,3 +29,3 @@ * Contains plugins to process CSS. Create one `Processor` instance, | ||
*/ | ||
export default class Processor { | ||
declare class Processor_ { | ||
/** | ||
@@ -59,3 +64,3 @@ * Current PostCSS version. | ||
* PostCSS will call this function without argument to get plugin. | ||
* * A function. PostCSS will pass the function a @{link Root} | ||
* * A function. PostCSS will pass the function a {@link Root} | ||
* as the first argument and current `Result` instance | ||
@@ -78,3 +83,3 @@ * as the second. | ||
* @param plugin PostCSS plugin or `Processor` with plugins. | ||
* @return {Processes} Current processor to make methods chain. | ||
* @return Current processor to make methods chain. | ||
*/ | ||
@@ -97,3 +102,3 @@ use(plugin: AcceptedPlugin): this | ||
* @param css String with input CSS or any object with a `toString()` method, | ||
* like a Buffer. Optionally, senda `Result` instance | ||
* like a Buffer. Optionally, send a `Result` instance | ||
* and the processor will take the `Root` from it. | ||
@@ -108,1 +113,5 @@ * @param opts Options. | ||
} | ||
declare class Processor extends Processor_ {} | ||
export = Processor |
@@ -10,3 +10,3 @@ 'use strict' | ||
constructor(plugins = []) { | ||
this.version = '8.4.5' | ||
this.version = '8.4.24' | ||
this.plugins = this.normalize(plugins) | ||
@@ -13,0 +13,0 @@ } |
@@ -14,27 +14,33 @@ import { | ||
export interface Message { | ||
/** | ||
* Message type. | ||
*/ | ||
type: string | ||
declare namespace Result { | ||
export interface Message { | ||
/** | ||
* Message type. | ||
*/ | ||
type: string | ||
/** | ||
* Source PostCSS plugin name. | ||
*/ | ||
plugin?: string | ||
/** | ||
* Source PostCSS plugin name. | ||
*/ | ||
plugin?: string | ||
[others: string]: any | ||
} | ||
[others: string]: any | ||
} | ||
export interface ResultOptions extends ProcessOptions { | ||
/** | ||
* The CSS node that was the source of the warning. | ||
*/ | ||
node?: Node | ||
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 | ||
/** | ||
* 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 } | ||
} | ||
@@ -58,3 +64,3 @@ | ||
*/ | ||
export default class Result { | ||
declare class Result_ { | ||
/** | ||
@@ -91,3 +97,3 @@ * The Processor instance used for this transformation. | ||
*/ | ||
messages: Message[] | ||
messages: Result.Message[] | ||
@@ -111,3 +117,3 @@ /** | ||
*/ | ||
opts: ResultOptions | ||
opts: Result.ResultOptions | ||
@@ -149,3 +155,3 @@ /** | ||
*/ | ||
constructor(processor: Processor, root: Root | Document, opts: ResultOptions) | ||
constructor(processor: Processor, root: Root | Document, opts: Result.ResultOptions) | ||
@@ -202,1 +208,5 @@ /** | ||
} | ||
declare class Result extends Result_ {} | ||
export = Result |
@@ -6,36 +6,41 @@ import Container, { ContainerProps } from './container.js' | ||
interface RootRaws extends Record<string, any> { | ||
/** | ||
* The space symbols after the last child to the end of file. | ||
*/ | ||
after?: string | ||
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 before `Root`, when `Root` is inside `Document`. | ||
* | ||
* **Experimental:** some aspects of this node could change within minor | ||
* or patch version releases. | ||
*/ | ||
codeBefore?: 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 | ||
/** | ||
* 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 after `Root`, when `Root` is inside `Document`. | ||
* | ||
* **Experimental:** some aspects of this node could change within minor | ||
* or patch version releases. | ||
*/ | ||
codeAfter?: string | ||
/** | ||
* Is the last child has an (optional) semicolon. | ||
*/ | ||
semicolon?: boolean | ||
} | ||
/** | ||
* 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 | ||
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 } | ||
} | ||
@@ -52,6 +57,6 @@ | ||
*/ | ||
export default class Root extends Container { | ||
declare class Root_ extends Container { | ||
type: 'root' | ||
parent: Document | undefined | ||
raws: RootRaws | ||
raws: Root.RootRaws | ||
@@ -71,6 +76,10 @@ /** | ||
*/ | ||
toResult(options?: ProcessOptions): Result | ||
toResult(options?: ProcessOptions): Result | ||
constructor(defaults?: RootProps) | ||
assign(overrides: object | RootProps): this | ||
constructor(defaults?: Root.RootProps) | ||
assign(overrides: object | Root.RootProps): this | ||
} | ||
declare class Root extends Root_ {} | ||
export = Root |
@@ -60,1 +60,3 @@ 'use strict' | ||
Root.default = Root | ||
Container.registerRoot(Root) |
import Container, { ContainerProps } from './container.js' | ||
interface RuleRaws extends Record<string, unknown> { | ||
/** | ||
* The space symbols before the node. It also stores `*` | ||
* and `_` symbols before the declaration (IE hack). | ||
*/ | ||
before?: string | ||
declare namespace Rule { | ||
export interface RuleRaws extends Record<string, unknown> { | ||
/** | ||
* The space symbols before the node. It also stores `*` | ||
* and `_` symbols before the declaration (IE hack). | ||
*/ | ||
before?: string | ||
/** | ||
* The space symbols after the last child of the node to the end of the node. | ||
*/ | ||
after?: string | ||
/** | ||
* The space symbols after the last child of the node to the end of the node. | ||
*/ | ||
after?: string | ||
/** | ||
* The symbols between the selector and `{` for rules. | ||
*/ | ||
between?: string | ||
/** | ||
* The symbols between the selector and `{` for rules. | ||
*/ | ||
between?: string | ||
/** | ||
* Contains `true` if the last child has an (optional) semicolon. | ||
*/ | ||
semicolon?: boolean | ||
/** | ||
* Contains `true` if the last child has an (optional) semicolon. | ||
*/ | ||
semicolon?: boolean | ||
/** | ||
* Contains `true` if there is semicolon after rule. | ||
*/ | ||
ownSemicolon?: string | ||
/** | ||
* Contains `true` if there is semicolon after rule. | ||
*/ | ||
ownSemicolon?: string | ||
/** | ||
* The rule’s selector with comments. | ||
*/ | ||
selector?: { | ||
value: string | ||
raw: string | ||
/** | ||
* The rule’s selector with comments. | ||
*/ | ||
selector?: { | ||
value: string | ||
raw: string | ||
} | ||
} | ||
} | ||
export interface RuleProps extends ContainerProps { | ||
/** Selector or selectors of the rule. */ | ||
selector?: string | ||
/** Selectors of the rule represented as an array of strings. */ | ||
selectors?: string[] | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: RuleRaws | ||
export interface RuleProps extends ContainerProps { | ||
/** Selector or selectors of the rule. */ | ||
selector?: string | ||
/** Selectors of the rule represented as an array of strings. */ | ||
selectors?: string[] | ||
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */ | ||
raws?: RuleRaws | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Rule_ as default } | ||
} | ||
@@ -66,6 +71,6 @@ | ||
*/ | ||
export default class Rule extends Container { | ||
declare class Rule_ extends Container { | ||
type: 'rule' | ||
parent: Container | undefined | ||
raws: RuleRaws | ||
raws: Rule.RuleRaws | ||
@@ -100,7 +105,11 @@ /** | ||
constructor(defaults?: RuleProps) | ||
assign(overrides: object | RuleProps): this | ||
clone(overrides?: Partial<RuleProps>): this | ||
cloneBefore(overrides?: Partial<RuleProps>): this | ||
cloneAfter(overrides?: Partial<RuleProps>): this | ||
constructor(defaults?: Rule.RuleProps) | ||
assign(overrides: object | Rule.RuleProps): this | ||
clone(overrides?: Partial<Rule.RuleProps>): this | ||
cloneBefore(overrides?: Partial<Rule.RuleProps>): this | ||
cloneAfter(overrides?: Partial<Rule.RuleProps>): this | ||
} | ||
declare class Rule extends Rule_ {} | ||
export = Rule |
@@ -13,3 +13,8 @@ import { | ||
export default class Stringifier { | ||
declare namespace Stringifier { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Stringifier_ as default } | ||
} | ||
declare class Stringifier_ { | ||
builder: Builder | ||
@@ -39,1 +44,5 @@ constructor(builder: Builder) | ||
} | ||
declare class Stringifier extends Stringifier_ {} | ||
export = Stringifier |
import { Stringifier } from './postcss.js' | ||
declare const stringify: Stringifier | ||
interface Stringify extends Stringifier { | ||
default: Stringify | ||
} | ||
export default stringify | ||
declare const stringify: Stringify | ||
export = stringify |
import { RangePosition } from './css-syntax-error.js' | ||
import Node from './node.js' | ||
export interface WarningOptions { | ||
/** | ||
* CSS node that caused the warning. | ||
*/ | ||
node?: Node | ||
declare namespace Warning { | ||
export interface WarningOptions { | ||
/** | ||
* CSS node that caused the warning. | ||
*/ | ||
node?: Node | ||
/** | ||
* Word in CSS source that caused the warning. | ||
*/ | ||
word?: string | ||
/** | ||
* Word in CSS source that caused the warning. | ||
*/ | ||
word?: string | ||
/** | ||
* Start index, inclusive, in CSS node string that caused the warning. | ||
*/ | ||
index?: number | ||
/** | ||
* Start index, inclusive, in CSS node string that caused the warning. | ||
*/ | ||
index?: number | ||
/** | ||
* End index, exclusive, in CSS node string that caused the warning. | ||
*/ | ||
endIndex?: number | ||
/** | ||
* End index, exclusive, in CSS node string that caused the warning. | ||
*/ | ||
endIndex?: number | ||
/** | ||
* Start position, inclusive, in CSS node string that caused the warning. | ||
*/ | ||
start?: RangePosition | ||
/** | ||
* Start position, inclusive, in CSS node string that caused the warning. | ||
*/ | ||
start?: RangePosition | ||
/** | ||
* End position, exclusive, in CSS node string that caused the warning. | ||
*/ | ||
end?: RangePosition | ||
/** | ||
* End position, exclusive, in CSS node string that caused the warning. | ||
*/ | ||
end?: RangePosition | ||
/** | ||
* Name of the plugin that created this warning. `Result#warn` fills | ||
* this property automatically. | ||
*/ | ||
plugin?: string | ||
/** | ||
* Name of the plugin that created this warning. `Result#warn` fills | ||
* this property automatically. | ||
*/ | ||
plugin?: string | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
export { Warning_ as default } | ||
} | ||
@@ -51,3 +56,3 @@ | ||
*/ | ||
export default class Warning { | ||
declare class Warning_ { | ||
/** | ||
@@ -127,3 +132,3 @@ * Type to filter warnings from `Result#messages`. | ||
*/ | ||
constructor(text: string, opts?: WarningOptions) | ||
constructor(text: string, opts?: Warning.WarningOptions) | ||
@@ -141,1 +146,5 @@ /** | ||
} | ||
declare class Warning extends Warning_ {} | ||
export = Warning |
{ | ||
"name": "postcss", | ||
"version": "8.4.5", | ||
"version": "8.4.24", | ||
"description": "Tool for transforming styles with JS plugins", | ||
@@ -11,4 +11,3 @@ "engines": { | ||
"require": "./lib/postcss.js", | ||
"import": "./lib/postcss.mjs", | ||
"types": "./lib/postcss.d.ts" | ||
"import": "./lib/postcss.mjs" | ||
}, | ||
@@ -57,6 +56,16 @@ "./lib/at-rule": "./lib/at-rule.js", | ||
], | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/postcss/" | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/postcss/" | ||
}, | ||
{ | ||
"type": "tidelift", | ||
"url": "https://tidelift.com/funding/github/npm/postcss" | ||
}, | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/ai" | ||
} | ||
], | ||
"author": "Andrey Sitnik <andrey@sitnik.ru>", | ||
@@ -70,5 +79,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"nanoid": "^3.1.30", | ||
"nanoid": "^3.3.6", | ||
"picocolors": "^1.0.0", | ||
"source-map-js": "^1.0.1" | ||
"source-map-js": "^1.0.2" | ||
}, | ||
@@ -75,0 +84,0 @@ "browser": { |
@@ -44,2 +44,2 @@ # PostCSS [![Gitter][chat-img]][chat] | ||
## Docs | ||
Read **[full docs](https://github.com/postcss/postcss#readme)** on GitHub. | ||
Read full docs **[here](https://postcss.org/)**. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
193541
55
6645
Updatednanoid@^3.3.6
Updatedsource-map-js@^1.0.2