UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

54 lines (53 loc) 3.01 kB
/** * Traversing Query utility to find element via extended selector query * Extended query supports * - plain CSS selectors * - relative selectors (selectors that don't start from a plain selector will use passed base Element as a root) * - ::next and ::prev sibling pseudo-selectors * - ::parent, ::closest and ::child pseudo-selectors * - ::find pseudo-selector * - ::first, ::last and :nth(#) limitation pseudo-selectors * - ::filter, ::not filtration pseudo-selectors * * @example * - `#id .class [attr]` - find by CSS selector in a current document * - ` ` - get current base element * - `::next` - get next sibling element * - `::prev` - get previous sibling element * - `::parent` - get base element parent * - `::parent(#id .class [attr])` - find the closest parent matching passed selector * - `::closest(#id .class [attr])` - find the closest ancestor including base element that matches passed selector * - `::child(#id .class [attr])` - find direct child element(s) that match passed selector * - `::find(#id .class [attr])` - find child element(s) that match passed selector * - `::find(buttons, a)::not([hidden])` - find all buttons and anchors that are not have hidden attribute * - `::find(buttons, a)::filter(:first-child)` - find all buttons and anchors that are first child in container * - `::parent::child(some-tag)` - find direct child element(s) that match tag 'some-tag' in the parent * - `#id .class [attr]::parent` - find parent of element matching selector '#id .class [attr]' in document * - `::find(.row)::last::parent` - find parent of the last element matching selector '.row' from the base element subtree */ export declare class ESLTraversingQuery { private static ELEMENT_PROCESSORS; private static COLLECTION_PROCESSORS; /** * @returns RegExp that selects all known processors in query string * e.g. /(::parent|::closest|::child|::next|::prev)/ */ private static get PROCESSORS_REGEX(); private static isCollectionProcessor; private static processElement; private static processCollection; private static traverseChain; /** Split multiple queries separated by comma (respects query brackets) */ static splitQueries(str: string): string[]; protected static traverse(query: string, findFirst: boolean, base?: Element | null, scope?: Element | Document): Element[]; protected static traverseQuery(query: string, findFirst: boolean, base?: Element | null, scope?: Element | Document): Element[]; /** @returns first matching element reached via {@link ESLTraversingQuery} rules */ static first(query: string, base?: Element | null, scope?: Element | Document): Element | null; /** @returns Array of all matching elements reached via {@link ESLTraversingQuery} rules */ static all(query: string, base?: Element | null, scope?: Element | Document): Element[]; } declare global { export interface ESLLibrary { TraversingQuery: typeof ESLTraversingQuery; } }