90d99a9107711cd49ee5b45a82e84fb8d4e25f347bdb6b63f670eef290eccaf147072c5298ecfdd127e8996cba999a16cfae1524b528b0965cdf287ac360b8 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import type { Selector } from "css-what";
  2. export declare type InternalSelector = Selector | {
  3. type: "_flexibleDescendant";
  4. };
  5. export declare type Predicate<Value> = (v: Value) => boolean;
  6. export interface Adapter<Node, ElementNode extends Node> {
  7. /**
  8. * Is the node a tag?
  9. */
  10. isTag: (node: Node) => node is ElementNode;
  11. /**
  12. * Does at least one of passed element nodes pass the test predicate?
  13. */
  14. existsOne: (test: Predicate<ElementNode>, elems: Node[]) => boolean;
  15. /**
  16. * Get the attribute value.
  17. */
  18. getAttributeValue: (elem: ElementNode, name: string) => string | undefined;
  19. /**
  20. * Get the node's children
  21. */
  22. getChildren: (node: Node) => Node[];
  23. /**
  24. * Get the name of the tag
  25. */
  26. getName: (elem: ElementNode) => string;
  27. /**
  28. * Get the parent of the node
  29. */
  30. getParent: (node: ElementNode) => ElementNode | null;
  31. /**
  32. * Get the siblings of the node. Note that unlike jQuery's `siblings` method,
  33. * this is expected to include the current node as well
  34. */
  35. getSiblings: (node: Node) => Node[];
  36. /**
  37. * Returns the previous element sibling of a node.
  38. */
  39. prevElementSibling?: (node: Node) => ElementNode | null;
  40. /**
  41. * Get the text content of the node, and its children if it has any.
  42. */
  43. getText: (node: Node) => string;
  44. /**
  45. * Does the element have the named attribute?
  46. */
  47. hasAttrib: (elem: ElementNode, name: string) => boolean;
  48. /**
  49. * Takes an array of nodes, and removes any duplicates, as well as any
  50. * nodes whose ancestors are also in the array.
  51. */
  52. removeSubsets: (nodes: Node[]) => Node[];
  53. /**
  54. * Finds all of the element nodes in the array that match the test predicate,
  55. * as well as any of their children that match it.
  56. */
  57. findAll: (test: Predicate<ElementNode>, nodes: Node[]) => ElementNode[];
  58. /**
  59. * Finds the first node in the array that matches the test predicate, or one
  60. * of its children.
  61. */
  62. findOne: (test: Predicate<ElementNode>, elems: Node[]) => ElementNode | null;
  63. /**
  64. * The adapter can also optionally include an equals method, if your DOM
  65. * structure needs a custom equality test to compare two objects which refer
  66. * to the same underlying node. If not provided, `css-select` will fall back to
  67. * `a === b`.
  68. */
  69. equals?: (a: Node, b: Node) => boolean;
  70. /**
  71. * Is the element in hovered state?
  72. */
  73. isHovered?: (elem: ElementNode) => boolean;
  74. /**
  75. * Is the element in visited state?
  76. */
  77. isVisited?: (elem: ElementNode) => boolean;
  78. /**
  79. * Is the element in active state?
  80. */
  81. isActive?: (elem: ElementNode) => boolean;
  82. }
  83. export interface Options<Node, ElementNode extends Node> {
  84. /**
  85. * When enabled, tag names will be case-sensitive.
  86. *
  87. * @default false
  88. */
  89. xmlMode?: boolean;
  90. /**
  91. * Lower-case attribute names.
  92. *
  93. * @default !xmlMode
  94. */
  95. lowerCaseAttributeNames?: boolean;
  96. /**
  97. * Lower-case tag names.
  98. *
  99. * @default !xmlMode
  100. */
  101. lowerCaseTags?: boolean;
  102. /**
  103. * Is the document in quirks mode?
  104. *
  105. * This will lead to .className and #id being case-insensitive.
  106. *
  107. * @default false
  108. */
  109. quirksMode?: boolean;
  110. /**
  111. * The last function in the stack, will be called with the last element
  112. * that's looked at.
  113. */
  114. rootFunc?: (element: ElementNode) => boolean;
  115. /**
  116. * The adapter to use when interacting with the backing DOM structure. By
  117. * default it uses the `domutils` module.
  118. */
  119. adapter?: Adapter<Node, ElementNode>;
  120. /**
  121. * The context of the current query. Used to limit the scope of searches.
  122. * Can be matched directly using the `:scope` pseudo-selector.
  123. */
  124. context?: Node | Node[];
  125. /**
  126. * Allow css-select to cache results for some selectors, sometimes greatly
  127. * improving querying performance. Disable this if your document can
  128. * change in between queries with the same compiled selector.
  129. *
  130. * @default true
  131. */
  132. cacheResults?: boolean;
  133. }
  134. export interface InternalOptions<Node, ElementNode extends Node> extends Options<Node, ElementNode> {
  135. adapter: Adapter<Node, ElementNode>;
  136. equals: (a: Node, b: Node) => boolean;
  137. }
  138. export interface CompiledQuery<ElementNode> {
  139. (node: ElementNode): boolean;
  140. shouldTestNextSiblings?: boolean;
  141. }
  142. export declare type Query<ElementNode> = string | CompiledQuery<ElementNode> | Selector[][];
  143. export declare type CompileToken<Node, ElementNode extends Node> = (token: InternalSelector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node) => CompiledQuery<ElementNode>;
  144. //# sourceMappingURL=types.d.ts.map