1 | /**
|
2 | * The namespace for selector related utilities.
|
3 | */
|
4 | export declare namespace Selector {
|
5 | /**
|
6 | * Calculate the specificity of a single CSS selector.
|
7 | *
|
8 | * @param selector - The CSS selector of interest.
|
9 | *
|
10 | * @returns The specificity of the selector.
|
11 | *
|
12 | * #### Undefined Behavior
|
13 | * The selector is invalid.
|
14 | *
|
15 | * #### Notes
|
16 | * This is based on https://www.w3.org/TR/css3-selectors/#specificity
|
17 | *
|
18 | * A larger number represents a more specific selector.
|
19 | *
|
20 | * The smallest possible specificity is `0`.
|
21 | *
|
22 | * The result is represented as a hex number `0x<aa><bb><cc>` where
|
23 | * each component is the count of the respective selector clause.
|
24 | *
|
25 | * If the selector contains commas, only the first clause is used.
|
26 | *
|
27 | * The computed result is cached, so subsequent calculations for the
|
28 | * same selector are extremely fast.
|
29 | */
|
30 | function calculateSpecificity(selector: string): number;
|
31 | /**
|
32 | * Test whether a selector is a valid CSS selector.
|
33 | *
|
34 | * @param selector - The CSS selector of interest.
|
35 | *
|
36 | * @returns `true` if the selector is valid, `false` otherwise.
|
37 | *
|
38 | * #### Notes
|
39 | * The computed result is cached, so subsequent tests for the same
|
40 | * selector are extremely fast.
|
41 | */
|
42 | function isValid(selector: string): boolean;
|
43 | /**
|
44 | * Test whether an element matches a CSS selector.
|
45 | *
|
46 | * @param element - The element of interest.
|
47 | *
|
48 | * @param selector - The valid CSS selector of interest.
|
49 | *
|
50 | * @returns `true` if the element is a match, `false` otherwise.
|
51 | *
|
52 | * #### Notes
|
53 | * This function uses the builtin browser capabilities when possible,
|
54 | * falling back onto a document query otherwise.
|
55 | */
|
56 | function matches(element: Element, selector: string): boolean;
|
57 | }
|