CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
postcss-selector-parser.d.ts570 linesDownload Raw Back to postcss-selector-parser
1// Type definitions for postcss-selector-parser 2.2.32// Definitions by: Chris Eppstein <chris@eppsteins.net>3 4/*~ Note that ES6 modules cannot directly export callable functions.5 *~ This file should be imported using the CommonJS-style:6 *~   import x = require('someLibrary');7 *~8 *~ Refer to the documentation to understand common9 *~ workarounds for this limitation of ES6 modules.10 */11 12/*~ This declaration specifies that the function13 *~ is the exported object from the file14 */15export = parser;16 17// A type that's T but not U.18type Diff<T, U> = T extends U ? never : T;19 20// TODO: Conditional types in TS 1.8 will really clean this up.21declare function parser(): parser.Processor<never>;22declare function parser<Transform>(processor: parser.AsyncProcessor<Transform>): parser.Processor<Transform, never>;23declare function parser(processor: parser.AsyncProcessor<void>): parser.Processor<never, never>;24declare function parser<Transform>(processor: parser.SyncProcessor<Transform>): parser.Processor<Transform>;25declare function parser(processor: parser.SyncProcessor<void>): parser.Processor<never>;26declare function parser<Transform>(processor?: parser.SyncProcessor<Transform> | parser.AsyncProcessor<Transform>): parser.Processor<Transform>;27 28/*~ If you want to expose types from your module as well, you can29 *~ place them in this block. Often you will want to describe the30 *~ shape of the return type of the function; that type should31 *~ be declared in here, as this example shows.32 */33declare namespace parser {34    /* copied from postcss -- so we don't need to add a dependency */35    type ErrorOptions = {36        plugin?: string;37        word?: string;38        index?: number39    };40    /* the bits we use of postcss.Rule, copied from postcss -- so we don't need to add a dependency */41    type PostCSSRuleNode = {42        selector: string43        /**44         * @returns postcss.CssSyntaxError but it's a complex object, caller45         *   should cast to it if they have a dependency on postcss.46         */47        error(message: string, options?: ErrorOptions): Error;48    };49    /** Accepts a string  */50    type Selectors = string | PostCSSRuleNode51    type ProcessorFn<ReturnType = void> = (root: parser.Root) => ReturnType;52    type SyncProcessor<Transform = void> = ProcessorFn<Transform>;53    type AsyncProcessor<Transform = void> = ProcessorFn<PromiseLike<Transform>>;54 55    const TAG: "tag";56    const STRING: "string";57    const SELECTOR: "selector";58    const ROOT: "root";59    const PSEUDO: "pseudo";60    const NESTING: "nesting";61    const ID: "id";62    const COMMENT: "comment";63    const COMBINATOR: "combinator";64    const CLASS: "class";65    const ATTRIBUTE: "attribute";66    const UNIVERSAL: "universal";67 68    interface NodeTypes {69        tag: Tag,70        string: String,71        selector: Selector,72        root: Root,73        pseudo: Pseudo,74        nesting: Nesting,75        id: Identifier,76        comment: Comment,77        combinator: Combinator,78        class: ClassName,79        attribute: Attribute,80        universal: Universal81    }82 83    type Node = NodeTypes[keyof NodeTypes];84 85    function isNode(node: any): node is Node;86 87    interface Options {88        /**89         * Preserve whitespace when true. Default: false;90         */91        lossless: boolean;92        /**93         * When true and a postcss.Rule is passed, set the result of94         * processing back onto the rule when done. Default: false.95         */96        updateSelector: boolean;97        /**98         * The maximum selector nesting depth allowed while parsing. Selectors99         * nested deeper than this (e.g. `:not(:not(:not(…)))`) raise an error100         * instead of overflowing the call stack. Default: 256.101         */102        maxNestingDepth: number;103    }104    interface StringifyOptions {105        /**106         * The maximum selector nesting depth allowed while serializing.107         * Serializing an AST nested deeper than this raises an error instead of108         * overflowing the call stack. Default: 256.109         */110        maxNestingDepth?: number;111    }112    class Processor<113        TransformType = never,114        SyncSelectorsType extends Selectors | never = Selectors115    > {116        res: Root;117        readonly result: String;118        ast(selectors: Selectors, options?: Partial<Options>): Promise<Root>;119        astSync(selectors: SyncSelectorsType, options?: Partial<Options>): Root;120        transform(selectors: Selectors, options?: Partial<Options>): Promise<TransformType>;121        transformSync(selectors: SyncSelectorsType, options?: Partial<Options>): TransformType;122        process(selectors: Selectors, options?: Partial<Options>): Promise<string>;123        processSync(selectors: SyncSelectorsType, options?: Partial<Options>): string;124    }125    interface ParserOptions {126        css: string;127        error: (message: string, options: ErrorOptions) => Error;128        options: Options;129    }130    class Parser {131        input: ParserOptions;132        lossy: boolean;133        position: number;134        root: Root;135        selectors: string;136        current: Selector;137        constructor(input: ParserOptions);138        /**139         * Raises an error, if the processor is invoked on140         * a postcss Rule node, a better error message is raised.141         */142        error(message: string, options?: ErrorOptions): void;143    }144    interface NodeSource {145        start?: {146            line: number,147            column: number148        },149        end?: {150            line: number,151            column: number152        }153    }154    interface SpaceAround {155      before: string;156      after: string;157    }158    interface Spaces extends SpaceAround {159      [spaceType: string]: string | Partial<SpaceAround> | undefined;160    }161    interface NodeOptions<Value = string> {162        value: Value;163        spaces?: Partial<Spaces>;164        source?: NodeSource;165        sourceIndex?: number;166    }167    interface Base<168        Value extends string | undefined = string,169        ParentType extends Container | undefined = Container | undefined170    > {171        type: keyof NodeTypes;172        parent: ParentType;173        value: Value;174        spaces: Spaces;175        source?: NodeSource;176        sourceIndex: number;177        rawSpaceBefore: string;178        rawSpaceAfter: string;179        remove(): Node;180        replaceWith(...nodes: Node[]): Node;181        next(): Node | undefined;182        prev(): Node | undefined;183        clone(opts?: {[override: string]:any}): this;184        /**185         * Return whether this node includes the character at the position of the given line and column.186         * Returns undefined if the nodes lack sufficient source metadata to determine the position.187         * @param line 1-index based line number relative to the start of the selector.188         * @param column 1-index based column number relative to the start of the selector.189         */190        isAtPosition(line: number, column: number): boolean | undefined;191        /**192         * Some non-standard syntax doesn't follow normal escaping rules for css,193         * this allows the escaped value to be specified directly, allowing illegal characters to be194         * directly inserted into css output.195         * @param name the property to set196         * @param value the unescaped value of the property197         * @param valueEscaped optional. the escaped value of the property.198         */199        setPropertyAndEscape(name: string, value: any, valueEscaped: string): void;200        /**201         * When you want a value to passed through to CSS directly. This method202         * deletes the corresponding raw value causing the stringifier to fallback203         * to the unescaped value.204         * @param name the property to set.205         * @param value The value that is both escaped and unescaped.206         */207        setPropertyWithoutEscape(name: string, value: any): void;208        /**209         * Some non-standard syntax doesn't follow normal escaping rules for css.210         * This allows non standard syntax to be appended to an existing property211         * by specifying the escaped value. By specifying the escaped value,212         * illegal characters are allowed to be directly inserted into css output.213         * @param {string} name the property to set214         * @param {any} value the unescaped value of the property215         * @param {string} valueEscaped optional. the escaped value of the property.216         */217        appendToPropertyAndEscape(name: string, value: any, valueEscaped: string): void;218        toString(options?: StringifyOptions): string;219    }220    interface ContainerOptions extends NodeOptions {221        nodes?: Array<Node>;222    }223    interface Container<224        Value extends string | undefined = string,225        Child extends Node = Node226    > extends Base<Value> {227        nodes: Array<Child>;228        append(selector: Child): this;229        prepend(selector: Child): this;230        at(index: number): Child;231        /**232         * Return the most specific node at the line and column number given.233         * The source location is based on the original parsed location, locations aren't234         * updated as selector nodes are mutated.235         *236         * Note that this location is relative to the location of the first character237         * of the selector, and not the location of the selector in the overall document238         * when used in conjunction with postcss.239         *240         * If not found, returns undefined.241         * @param line The line number of the node to find. (1-based index)242         * @param col  The column number of the node to find. (1-based index)243         */244        atPosition(line: number, column: number): Child;245        index(child: Child): number;246        readonly first: Child;247        readonly last: Child;248        readonly length: number;249        removeChild(child: Child): this;250        removeAll(): this;251        empty(): this;252        insertAfter(oldNode: Child, newNode: Child): this;253        insertBefore(oldNode: Child, newNode: Child): this;254        each(callback: (node: Child, index: number) => boolean | void): boolean | undefined;255        walk(256            callback: (node: Node, index: number) => boolean | void257        ): boolean | undefined;258        walkAttributes(259            callback: (node: Attribute) => boolean | void260        ): boolean | undefined;261        walkClasses(262            callback: (node: ClassName) => boolean | void263        ): boolean | undefined;264        walkCombinators(265            callback: (node: Combinator) => boolean | void266        ): boolean | undefined;267        walkComments(268            callback: (node: Comment) => boolean | void269        ): boolean | undefined;270        walkIds(271            callback: (node: Identifier) => boolean | void272        ): boolean | undefined;273        walkNesting(274            callback: (node: Nesting) => boolean | void275        ): boolean | undefined;276        walkPseudos(277            callback: (node: Pseudo) => boolean | void278        ): boolean | undefined;279        walkTags(callback: (node: Tag) => boolean | void): boolean | undefined;280        split(callback: (node: Child) => boolean): [Child[], Child[]];281        map<T>(callback: (node: Child) => T): T[];282        reduce(283            callback: (284                previousValue: Child,285                currentValue: Child,286                currentIndex: number,287                array: readonly Child[]288            ) => Child289        ): Child;290        reduce(291            callback: (292                previousValue: Child,293                currentValue: Child,294                currentIndex: number,295                array: readonly Child[]296            ) => Child,297            initialValue: Child298        ): Child;299        reduce<T>(300            callback: (301                previousValue: T,302                currentValue: Child,303                currentIndex: number,304                array: readonly Child[]305            ) => T,306            initialValue: T307        ): T;308        every(callback: (node: Child) => boolean): boolean;309        some(callback: (node: Child) => boolean): boolean;310        filter(callback: (node: Child) => boolean): Child[];311        sort(callback: (nodeA: Child, nodeB: Child) => number): Child[];312        toString(options?: StringifyOptions): string;313    }314    function isContainer(node: any): node is Root | Selector | Pseudo;315 316    interface NamespaceOptions<Value extends string | undefined = string> extends NodeOptions<Value> {317        namespace?: string | true;318    }319    interface Namespace<Value extends string | undefined = string> extends Base<Value> {320        /** alias for namespace */321        ns: string | true;322        /**323         *  namespace prefix.324         */325        namespace: string | true;326        /**327         * If a namespace exists, prefix the value provided with it, separated by |.328         */329        qualifiedName(value: string): string;330        /**331         * A string representing the namespace suitable for output.332         */333        readonly namespaceString: string;334    }335    function isNamespace(node: any): node is Attribute | Tag;336 337    interface Root extends Container<undefined, Selector> {338        type: "root";339        /**340         * Raises an error, if the processor is invoked on341         * a postcss Rule node, a better error message is raised.342         */343        error(message: string, options?: ErrorOptions): Error;344        nodeAt(line: number, column: number): Node345    }346    function root(opts: ContainerOptions): Root;347    function isRoot(node: any): node is Root;348 349    interface _Selector<S> extends Container<string, Diff<Node, S>> {350        type: "selector";351    }352    type Selector = _Selector<Selector>;353    function selector(opts: ContainerOptions): Selector;354    function isSelector(node: any): node is Selector;355 356    interface CombinatorRaws {357        value?: string;358        spaces?: {359            before?: string;360            after?: string;361        };362    }363    interface Combinator extends Base {364        type: "combinator";365        raws?: CombinatorRaws;366    }367    function combinator(opts: NodeOptions): Combinator;368    function isCombinator(node: any): node is Combinator;369 370    interface ClassName extends Base {371        type: "class";372    }373    function className(opts: NamespaceOptions): ClassName;374    function isClassName(node: any): node is ClassName;375 376    type AttributeOperator = "=" | "~=" | "|=" | "^=" | "$=" | "*=";377    type QuoteMark = '"' | "'" | null;378    interface PreferredQuoteMarkOptions {379        quoteMark?: QuoteMark;380        preferCurrentQuoteMark?: boolean;381    }382    interface SmartQuoteMarkOptions extends PreferredQuoteMarkOptions {383        smart?: boolean;384    }385    interface AttributeOptions extends NamespaceOptions<string | undefined> {386        attribute: string;387        operator?: AttributeOperator;388        insensitive?: boolean;389        quoteMark?: QuoteMark;390        /** @deprecated Use quoteMark instead. */391        quoted?: boolean;392        spaces?: {393            before?: string;394            after?: string;395            attribute?: Partial<SpaceAround>;396            operator?: Partial<SpaceAround>;397            value?: Partial<SpaceAround>;398            insensitive?: Partial<SpaceAround>;399        }400        raws: {401            unquoted?: string;402            attribute?: string;403            operator?: string;404            value?: string;405            insensitive?: string;406            spaces?: {407                attribute?: Partial<Spaces>;408                operator?: Partial<Spaces>;409                value?: Partial<Spaces>;410                insensitive?: Partial<Spaces>;411            }412        };413    }414    interface Attribute extends Namespace<string | undefined> {415        type: "attribute";416        attribute: string;417        operator?: AttributeOperator;418        insensitive?: boolean;419        quoteMark: QuoteMark;420        quoted?: boolean;421        spaces: {422            before: string;423            after: string;424            attribute?: Partial<Spaces>;425            operator?: Partial<Spaces>;426            value?: Partial<Spaces>;427            insensitive?: Partial<Spaces>;428        }429        raws: {430            /** @deprecated The attribute value is unquoted, use that instead.. */431            unquoted?: string;432            attribute?: string;433            operator?: string;434            /** The value of the attribute with quotes and escapes. */435            value?: string;436            insensitive?: string;437            spaces?: {438                attribute?: Partial<Spaces>;439                operator?: Partial<Spaces>;440                value?: Partial<Spaces>;441                insensitive?: Partial<Spaces>;442            }443        };444        /**445         * The attribute name after having been qualified with a namespace.446         */447        readonly qualifiedAttribute: string;448 449        /**450         * The case insensitivity flag or an empty string depending on whether this451         * attribute is case insensitive.452         */453        readonly insensitiveFlag : 'i' | '';454 455        /**456         * Returns the attribute's value quoted such that it would be legal to use457         * in the value of a css file. The original value's quotation setting458         * used for stringification is left unchanged. See `setValue(value, options)`459         * if you want to control the quote settings of a new value for the attribute or460         * `set quoteMark(mark)` if you want to change the quote settings of the current461         * value.462         *463         * You can also change the quotation used for the current value by setting quoteMark.464         **/465        getQuotedValue(options?: SmartQuoteMarkOptions): string;466 467        /**468         * Set the unescaped value with the specified quotation options. The value469         * provided must not include any wrapping quote marks -- those quotes will470         * be interpreted as part of the value and escaped accordingly.471         * @param value472         */473        setValue(value: string, options?: SmartQuoteMarkOptions): void;474 475        /**476         * Intelligently select a quoteMark value based on the value's contents. If477         * the value is a legal CSS ident, it will not be quoted. Otherwise a quote478         * mark will be picked that minimizes the number of escapes.479         *480         * If there's no clear winner, the quote mark from these options is used,481         * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is482         * true). If the quoteMark is unspecified, a double quote is used.483         **/484        smartQuoteMark(options: PreferredQuoteMarkOptions): QuoteMark;485 486        /**487         * Selects the preferred quote mark based on the options and the current quote mark value.488         * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`489         * instead.490         */491        preferredQuoteMark(options: PreferredQuoteMarkOptions): QuoteMark492 493        /**494         * returns the offset of the attribute part specified relative to the495         * start of the node of the output string.496         *497         * * "ns" - alias for "namespace"498         * * "namespace" - the namespace if it exists.499         * * "attribute" - the attribute name500         * * "attributeNS" - the start of the attribute or its namespace501         * * "operator" - the match operator of the attribute502         * * "value" - The value (string or identifier)503         * * "insensitive" - the case insensitivity flag;504         * @param part One of the possible values inside an attribute.505         * @returns -1 if the name is invalid or the value doesn't exist in this attribute.506         */507        offsetOf(part: "ns" | "namespace" | "attribute" | "attributeNS" | "operator" | "value" | "insensitive"): number;508    }509    function attribute(opts: AttributeOptions): Attribute;510    function isAttribute(node: any): node is Attribute;511 512    interface Pseudo extends Container<string, Selector> {513        type: "pseudo";514    }515    function pseudo(opts: ContainerOptions): Pseudo;516    /**517     * Checks whether the node is the Pseudo subtype of node.518     */519    function isPseudo(node: any): node is Pseudo;520 521    /**522     * Checks whether the node is, specifically, a pseudo element instead of523     * pseudo class.524     */525    function isPseudoElement(node: any): node is Pseudo;526 527    /**528     * Checks whether the node is, specifically, a pseudo class instead of529     * pseudo element.530     */531    function isPseudoClass(node: any): node is Pseudo;532 533 534    interface Tag extends Namespace {535        type: "tag";536    }537    function tag(opts: NamespaceOptions): Tag;538    function isTag(node: any): node is Tag;539 540    interface Comment extends Base {541        type: "comment";542    }543    function comment(opts: NodeOptions): Comment;544    function isComment(node: any): node is Comment;545 546    interface Identifier extends Base {547        type: "id";548    }549    function id(opts: any): Identifier;550    function isIdentifier(node: any): node is Identifier;551 552    interface Nesting extends Base {553        type: "nesting";554    }555    function nesting(opts?: any): Nesting;556    function isNesting(node: any): node is Nesting;557 558    interface String extends Base {559        type: "string";560    }561    function string(opts: NodeOptions): String;562    function isString(node: any): node is String;563 564    interface Universal extends Base {565        type: "universal";566    }567    function universal(opts?: NamespaceOptions): Universal;568    function isUniversal(node: any): node is Universal;569}570