|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export = parser; |
|
|
|
|
|
type Diff<T, U> = T extends U ? never : T; |
|
|
|
|
|
declare function parser(): parser.Processor<never>; |
|
declare function parser<Transform>(processor: parser.AsyncProcessor<Transform>): parser.Processor<Transform, never>; |
|
declare function parser(processor: parser.AsyncProcessor<void>): parser.Processor<never, never>; |
|
declare function parser<Transform>(processor: parser.SyncProcessor<Transform>): parser.Processor<Transform>; |
|
declare function parser(processor: parser.SyncProcessor<void>): parser.Processor<never>; |
|
declare function parser<Transform>(processor?: parser.SyncProcessor<Transform> | parser.AsyncProcessor<Transform>): parser.Processor<Transform>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
declare namespace parser { |
|
|
|
type ErrorOptions = { |
|
plugin?: string; |
|
word?: string; |
|
index?: number |
|
}; |
|
|
|
type PostCSSRuleNode = { |
|
selector: string |
|
|
|
|
|
|
|
|
|
error(message: string, options?: ErrorOptions): Error; |
|
}; |
|
|
|
type Selectors = string | PostCSSRuleNode |
|
type ProcessorFn<ReturnType = void> = (root: parser.Root) => ReturnType; |
|
type SyncProcessor<Transform = void> = ProcessorFn<Transform>; |
|
type AsyncProcessor<Transform = void> = ProcessorFn<PromiseLike<Transform>>; |
|
|
|
const TAG: "tag"; |
|
const STRING: "string"; |
|
const SELECTOR: "selector"; |
|
const ROOT: "root"; |
|
const PSEUDO: "pseudo"; |
|
const NESTING: "nesting"; |
|
const ID: "id"; |
|
const COMMENT: "comment"; |
|
const COMBINATOR: "combinator"; |
|
const CLASS: "class"; |
|
const ATTRIBUTE: "attribute"; |
|
const UNIVERSAL: "universal"; |
|
|
|
interface NodeTypes { |
|
tag: Tag, |
|
string: String, |
|
selector: Selector, |
|
root: Root, |
|
pseudo: Pseudo, |
|
nesting: Nesting, |
|
id: Identifier, |
|
comment: Comment, |
|
combinator: Combinator, |
|
class: ClassName, |
|
attribute: Attribute, |
|
universal: Universal |
|
} |
|
|
|
type Node = NodeTypes[keyof NodeTypes]; |
|
|
|
function isNode(node: any): node is Node; |
|
|
|
interface Options { |
|
|
|
|
|
|
|
lossless: boolean; |
|
|
|
|
|
|
|
|
|
updateSelector: boolean; |
|
} |
|
class Processor< |
|
TransformType = never, |
|
SyncSelectorsType extends Selectors | never = Selectors |
|
> { |
|
res: Root; |
|
readonly result: String; |
|
ast(selectors: Selectors, options?: Partial<Options>): Promise<Root>; |
|
astSync(selectors: SyncSelectorsType, options?: Partial<Options>): Root; |
|
transform(selectors: Selectors, options?: Partial<Options>): Promise<TransformType>; |
|
transformSync(selectors: SyncSelectorsType, options?: Partial<Options>): TransformType; |
|
process(selectors: Selectors, options?: Partial<Options>): Promise<string>; |
|
processSync(selectors: SyncSelectorsType, options?: Partial<Options>): string; |
|
} |
|
interface ParserOptions { |
|
css: string; |
|
error: (message: string, options: ErrorOptions) => Error; |
|
options: Options; |
|
} |
|
class Parser { |
|
input: ParserOptions; |
|
lossy: boolean; |
|
position: number; |
|
root: Root; |
|
selectors: string; |
|
current: Selector; |
|
constructor(input: ParserOptions); |
|
|
|
|
|
|
|
|
|
error(message: string, options?: ErrorOptions): void; |
|
} |
|
interface NodeSource { |
|
start?: { |
|
line: number, |
|
column: number |
|
}, |
|
end?: { |
|
line: number, |
|
column: number |
|
} |
|
} |
|
interface SpaceAround { |
|
before: string; |
|
after: string; |
|
} |
|
interface Spaces extends SpaceAround { |
|
[spaceType: string]: string | Partial<SpaceAround> | undefined; |
|
} |
|
interface NodeOptions<Value = string> { |
|
value: Value; |
|
spaces?: Partial<Spaces>; |
|
source?: NodeSource; |
|
sourceIndex?: number; |
|
} |
|
interface Base< |
|
Value extends string | undefined = string, |
|
ParentType extends Container | undefined = Container | undefined |
|
> { |
|
type: keyof NodeTypes; |
|
parent: ParentType; |
|
value: Value; |
|
spaces: Spaces; |
|
source?: NodeSource; |
|
sourceIndex: number; |
|
rawSpaceBefore: string; |
|
rawSpaceAfter: string; |
|
remove(): Node; |
|
replaceWith(...nodes: Node[]): Node; |
|
next(): Node; |
|
prev(): Node; |
|
clone(opts: {[override: string]:any}): Node; |
|
|
|
|
|
|
|
|
|
|
|
|
|
isAtPosition(line: number, column: number): boolean | undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPropertyAndEscape(name: string, value: any, valueEscaped: string): void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPropertyWithoutEscape(name: string, value: any): void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appendToPropertyAndEscape(name: string, value: any, valueEscaped: string): void; |
|
toString(): string; |
|
} |
|
interface ContainerOptions extends NodeOptions { |
|
nodes?: Array<Node>; |
|
} |
|
interface Container< |
|
Value extends string | undefined = string, |
|
Child extends Node = Node |
|
> extends Base<Value> { |
|
nodes: Array<Child>; |
|
append(selector: Selector): this; |
|
prepend(selector: Selector): this; |
|
at(index: number): Child; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
atPosition(line: number, column: number): Child; |
|
index(child: Child): number; |
|
readonly first: Child; |
|
readonly last: Child; |
|
readonly length: number; |
|
removeChild(child: Child): this; |
|
removeAll(): Container; |
|
empty(): Container; |
|
insertAfter(oldNode: Child, newNode: Child): this; |
|
insertBefore(oldNode: Child, newNode: Child): this; |
|
each(callback: (node: Child) => boolean | void): boolean | undefined; |
|
walk( |
|
callback: (node: Node) => boolean | void |
|
): boolean | undefined; |
|
walkAttributes( |
|
callback: (node: Attribute) => boolean | void |
|
): boolean | undefined; |
|
walkClasses( |
|
callback: (node: ClassName) => boolean | void |
|
): boolean | undefined; |
|
walkCombinators( |
|
callback: (node: Combinator) => boolean | void |
|
): boolean | undefined; |
|
walkComments( |
|
callback: (node: Comment) => boolean | void |
|
): boolean | undefined; |
|
walkIds( |
|
callback: (node: Identifier) => boolean | void |
|
): boolean | undefined; |
|
walkNesting( |
|
callback: (node: Nesting) => boolean | void |
|
): boolean | undefined; |
|
walkPseudos( |
|
callback: (node: Pseudo) => boolean | void |
|
): boolean | undefined; |
|
walkTags(callback: (node: Tag) => boolean | void): boolean | undefined; |
|
split(callback: (node: Child) => boolean): [Child[], Child[]]; |
|
map<T>(callback: (node: Child) => T): T[]; |
|
reduce( |
|
callback: ( |
|
previousValue: Child, |
|
currentValue: Child, |
|
currentIndex: number, |
|
array: readonly Child[] |
|
) => Child |
|
): Child; |
|
reduce( |
|
callback: ( |
|
previousValue: Child, |
|
currentValue: Child, |
|
currentIndex: number, |
|
array: readonly Child[] |
|
) => Child, |
|
initialValue: Child |
|
): Child; |
|
reduce<T>( |
|
callback: ( |
|
previousValue: T, |
|
currentValue: Child, |
|
currentIndex: number, |
|
array: readonly Child[] |
|
) => T, |
|
initialValue: T |
|
): T; |
|
every(callback: (node: Child) => boolean): boolean; |
|
some(callback: (node: Child) => boolean): boolean; |
|
filter(callback: (node: Child) => boolean): Child[]; |
|
sort(callback: (nodeA: Child, nodeB: Child) => number): Child[]; |
|
toString(): string; |
|
} |
|
function isContainer(node: any): node is Root | Selector | Pseudo; |
|
|
|
interface NamespaceOptions<Value extends string | undefined = string> extends NodeOptions<Value> { |
|
namespace?: string | true; |
|
} |
|
interface Namespace<Value extends string | undefined = string> extends Base<Value> { |
|
|
|
ns: string | true; |
|
|
|
|
|
|
|
namespace: string | true; |
|
|
|
|
|
|
|
qualifiedName(value: string): string; |
|
|
|
|
|
|
|
readonly namespaceString: string; |
|
} |
|
function isNamespace(node: any): node is Attribute | Tag; |
|
|
|
interface Root extends Container<undefined, Selector> { |
|
type: "root"; |
|
|
|
|
|
|
|
|
|
error(message: string, options?: ErrorOptions): Error; |
|
nodeAt(line: number, column: number): Node |
|
} |
|
function root(opts: ContainerOptions): Root; |
|
function isRoot(node: any): node is Root; |
|
|
|
interface _Selector<S> extends Container<string, Diff<Node, S>> { |
|
type: "selector"; |
|
} |
|
type Selector = _Selector<Selector>; |
|
function selector(opts: ContainerOptions): Selector; |
|
function isSelector(node: any): node is Selector; |
|
|
|
interface CombinatorRaws { |
|
value?: string; |
|
spaces?: { |
|
before?: string; |
|
after?: string; |
|
}; |
|
} |
|
interface Combinator extends Base { |
|
type: "combinator"; |
|
raws?: CombinatorRaws; |
|
} |
|
function combinator(opts: NodeOptions): Combinator; |
|
function isCombinator(node: any): node is Combinator; |
|
|
|
interface ClassName extends Base { |
|
type: "class"; |
|
} |
|
function className(opts: NamespaceOptions): ClassName; |
|
function isClassName(node: any): node is ClassName; |
|
|
|
type AttributeOperator = "=" | "~=" | "|=" | "^=" | "$=" | "*="; |
|
type QuoteMark = '"' | "'" | null; |
|
interface PreferredQuoteMarkOptions { |
|
quoteMark?: QuoteMark; |
|
preferCurrentQuoteMark?: boolean; |
|
} |
|
interface SmartQuoteMarkOptions extends PreferredQuoteMarkOptions { |
|
smart?: boolean; |
|
} |
|
interface AttributeOptions extends NamespaceOptions<string | undefined> { |
|
attribute: string; |
|
operator?: AttributeOperator; |
|
insensitive?: boolean; |
|
quoteMark?: QuoteMark; |
|
|
|
quoted?: boolean; |
|
spaces?: { |
|
before?: string; |
|
after?: string; |
|
attribute?: Partial<SpaceAround>; |
|
operator?: Partial<SpaceAround>; |
|
value?: Partial<SpaceAround>; |
|
insensitive?: Partial<SpaceAround>; |
|
} |
|
raws: { |
|
unquoted?: string; |
|
attribute?: string; |
|
operator?: string; |
|
value?: string; |
|
insensitive?: string; |
|
spaces?: { |
|
attribute?: Partial<Spaces>; |
|
operator?: Partial<Spaces>; |
|
value?: Partial<Spaces>; |
|
insensitive?: Partial<Spaces>; |
|
} |
|
}; |
|
} |
|
interface Attribute extends Namespace<string | undefined> { |
|
type: "attribute"; |
|
attribute: string; |
|
operator?: AttributeOperator; |
|
insensitive?: boolean; |
|
quoteMark: QuoteMark; |
|
quoted?: boolean; |
|
spaces: { |
|
before: string; |
|
after: string; |
|
attribute?: Partial<Spaces>; |
|
operator?: Partial<Spaces>; |
|
value?: Partial<Spaces>; |
|
insensitive?: Partial<Spaces>; |
|
} |
|
raws: { |
|
|
|
unquoted?: string; |
|
attribute?: string; |
|
operator?: string; |
|
|
|
value?: string; |
|
insensitive?: string; |
|
spaces?: { |
|
attribute?: Partial<Spaces>; |
|
operator?: Partial<Spaces>; |
|
value?: Partial<Spaces>; |
|
insensitive?: Partial<Spaces>; |
|
} |
|
}; |
|
|
|
|
|
|
|
readonly qualifiedAttribute: string; |
|
|
|
|
|
|
|
|
|
|
|
readonly insensitiveFlag : 'i' | ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getQuotedValue(options?: SmartQuoteMarkOptions): string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setValue(value: string, options?: SmartQuoteMarkOptions): void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
smartQuoteMark(options: PreferredQuoteMarkOptions): QuoteMark; |
|
|
|
|
|
|
|
|
|
|
|
|
|
preferredQuoteMark(options: PreferredQuoteMarkOptions): QuoteMark |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
offsetOf(part: "ns" | "namespace" | "attribute" | "attributeNS" | "operator" | "value" | "insensitive"): number; |
|
} |
|
function attribute(opts: AttributeOptions): Attribute; |
|
function isAttribute(node: any): node is Attribute; |
|
|
|
interface Pseudo extends Container<string, Selector> { |
|
type: "pseudo"; |
|
} |
|
function pseudo(opts: ContainerOptions): Pseudo; |
|
|
|
|
|
|
|
function isPseudo(node: any): node is Pseudo; |
|
|
|
|
|
|
|
|
|
|
|
function isPseudoElement(node: any): node is Pseudo; |
|
|
|
|
|
|
|
|
|
|
|
function isPseudoClass(node: any): node is Pseudo; |
|
|
|
|
|
interface Tag extends Namespace { |
|
type: "tag"; |
|
} |
|
function tag(opts: NamespaceOptions): Tag; |
|
function isTag(node: any): node is Tag; |
|
|
|
interface Comment extends Base { |
|
type: "comment"; |
|
} |
|
function comment(opts: NodeOptions): Comment; |
|
function isComment(node: any): node is Comment; |
|
|
|
interface Identifier extends Base { |
|
type: "id"; |
|
} |
|
function id(opts: any): any; |
|
function isIdentifier(node: any): node is Identifier; |
|
|
|
interface Nesting extends Base { |
|
type: "nesting"; |
|
} |
|
function nesting(opts: any): any; |
|
function isNesting(node: any): node is Nesting; |
|
|
|
interface String extends Base { |
|
type: "string"; |
|
} |
|
function string(opts: NodeOptions): String; |
|
function isString(node: any): node is String; |
|
|
|
interface Universal extends Base { |
|
type: "universal"; |
|
} |
|
function universal(opts?: NamespaceOptions): any; |
|
function isUniversal(node: any): node is Universal; |
|
} |
|
|