1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | /**
|
---|
9 | * A css selector contains an element name,
|
---|
10 | * css classes and attribute/value pairs with the purpose
|
---|
11 | * of selecting subsets out of them.
|
---|
12 | */
|
---|
13 | export declare class CssSelector {
|
---|
14 | element: string | null;
|
---|
15 | classNames: string[];
|
---|
16 | /**
|
---|
17 | * The selectors are encoded in pairs where:
|
---|
18 | * - even locations are attribute names
|
---|
19 | * - odd locations are attribute values.
|
---|
20 | *
|
---|
21 | * Example:
|
---|
22 | * Selector: `[key1=value1][key2]` would parse to:
|
---|
23 | * ```
|
---|
24 | * ['key1', 'value1', 'key2', '']
|
---|
25 | * ```
|
---|
26 | */
|
---|
27 | attrs: string[];
|
---|
28 | notSelectors: CssSelector[];
|
---|
29 | static parse(selector: string): CssSelector[];
|
---|
30 | /**
|
---|
31 | * Unescape `\$` sequences from the CSS attribute selector.
|
---|
32 | *
|
---|
33 | * This is needed because `$` can have a special meaning in CSS selectors,
|
---|
34 | * but we might want to match an attribute that contains `$`.
|
---|
35 | * [MDN web link for more
|
---|
36 | * info](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors).
|
---|
37 | * @param attr the attribute to unescape.
|
---|
38 | * @returns the unescaped string.
|
---|
39 | */
|
---|
40 | unescapeAttribute(attr: string): string;
|
---|
41 | /**
|
---|
42 | * Escape `$` sequences from the CSS attribute selector.
|
---|
43 | *
|
---|
44 | * This is needed because `$` can have a special meaning in CSS selectors,
|
---|
45 | * with this method we are escaping `$` with `\$'.
|
---|
46 | * [MDN web link for more
|
---|
47 | * info](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors).
|
---|
48 | * @param attr the attribute to escape.
|
---|
49 | * @returns the escaped string.
|
---|
50 | */
|
---|
51 | escapeAttribute(attr: string): string;
|
---|
52 | isElementSelector(): boolean;
|
---|
53 | hasElementSelector(): boolean;
|
---|
54 | setElement(element?: string | null): void;
|
---|
55 | /** Gets a template string for an element that matches the selector. */
|
---|
56 | getMatchingElementTemplate(): string;
|
---|
57 | getAttrs(): string[];
|
---|
58 | addAttribute(name: string, value?: string): void;
|
---|
59 | addClassName(name: string): void;
|
---|
60 | toString(): string;
|
---|
61 | }
|
---|
62 | /**
|
---|
63 | * Reads a list of CssSelectors and allows to calculate which ones
|
---|
64 | * are contained in a given CssSelector.
|
---|
65 | */
|
---|
66 | export declare class SelectorMatcher<T = any> {
|
---|
67 | static createNotMatcher(notSelectors: CssSelector[]): SelectorMatcher<null>;
|
---|
68 | private _elementMap;
|
---|
69 | private _elementPartialMap;
|
---|
70 | private _classMap;
|
---|
71 | private _classPartialMap;
|
---|
72 | private _attrValueMap;
|
---|
73 | private _attrValuePartialMap;
|
---|
74 | private _listContexts;
|
---|
75 | addSelectables(cssSelectors: CssSelector[], callbackCtxt?: T): void;
|
---|
76 | /**
|
---|
77 | * Add an object that can be found later on by calling `match`.
|
---|
78 | * @param cssSelector A css selector
|
---|
79 | * @param callbackCtxt An opaque object that will be given to the callback of the `match` function
|
---|
80 | */
|
---|
81 | private _addSelectable;
|
---|
82 | private _addTerminal;
|
---|
83 | private _addPartial;
|
---|
84 | /**
|
---|
85 | * Find the objects that have been added via `addSelectable`
|
---|
86 | * whose css selector is contained in the given css selector.
|
---|
87 | * @param cssSelector A css selector
|
---|
88 | * @param matchedCallback This callback will be called with the object handed into `addSelectable`
|
---|
89 | * @return boolean true if a match was found
|
---|
90 | */
|
---|
91 | match(cssSelector: CssSelector, matchedCallback: ((c: CssSelector, a: T) => void) | null): boolean;
|
---|
92 | }
|
---|
93 | export declare class SelectorListContext {
|
---|
94 | selectors: CssSelector[];
|
---|
95 | alreadyMatched: boolean;
|
---|
96 | constructor(selectors: CssSelector[]);
|
---|
97 | }
|
---|
98 | export declare class SelectorContext<T = any> {
|
---|
99 | selector: CssSelector;
|
---|
100 | cbContext: T;
|
---|
101 | listContext: SelectorListContext;
|
---|
102 | notSelectors: CssSelector[];
|
---|
103 | constructor(selector: CssSelector, cbContext: T, listContext: SelectorListContext);
|
---|
104 | finalize(cssSelector: CssSelector, callback: ((c: CssSelector, a: T) => void) | null): boolean;
|
---|
105 | }
|
---|