@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
56 lines (55 loc) • 2.65 kB
TypeScript
import type { ESLMediaChangeEvent, IMediaQueryCondition } from './conditions/media-query-base';
export interface IMediaQueryPreprocessor {
process: (match: string) => IMediaQueryCondition | undefined;
}
/**
* ESL Media Query
* @implements EventTarget
* Provides special media condition syntax - ESLMediaQuery
* @author Alexey Stsefanovich (ala'n), Yuliya Adamskaya, Natallia Harshunova
*
* Utility to support extended MediaQuery features
* Supports
* - CSS MediaQuery matching check
* - DPR display queries (`@x1|@x2|@x3`)
* - Registered screen default sizes (breakpoints) shortcuts (`@[-|+](XS|SM|MD|LG|XL)`)
* - Device and browser shortcuts (`@MOBILE|@DESKTOP|@IE`)
* - Custom static shortcuts and custom query preprocessors
* - `not` logic operation (can have multiple not operators before any term of the query)
* - `or` or `,` logical operator (have a lowest priority)
* - Query matching change listeners
* - Implements {@link EventTarget}, compatible with {@link ESLEventListener}
*
* Building query process:
*
* [Building query logical tree] - [preprocess nodes queries] - [building native MediaQueryList nodes] - [query tree optimization]
*/
export declare abstract class ESLMediaQuery implements IMediaQueryCondition {
/** Always true condition */
static readonly ALL: ESLMediaQuery;
/** Always false condition */
static readonly NOT_ALL: ESLMediaQuery;
protected static readonly SHORTCUT_PATTERN: RegExp;
protected static readonly _preprocessors: IMediaQueryPreprocessor[];
/** Adds {@link IMediaQueryPreprocessor} instance for query preprocessing step */
static use(preprocessor: IMediaQueryPreprocessor): typeof ESLMediaQuery;
/** Cached method to create {@link ESLMediaQuery} condition instance from query string */
static for(query: string): ESLMediaQuery;
/** Creates {@link ESLMediaQuery} condition instance from query string */
static from(query: string): ESLMediaQuery;
/** Creates simple {@link ESLMediaQuery} condition */
protected static parseSingleQuery(term: string): ESLMediaQuery;
abstract matches: boolean;
abstract optimize(): ESLMediaQuery;
abstract dispatchEvent(event: ESLMediaChangeEvent): boolean;
abstract toString(): string;
abstract addEventListener(callback: EventListener): void;
abstract addEventListener(type: 'change', callback: EventListener): void;
abstract removeEventListener(callback: EventListener): void;
abstract removeEventListener(type: 'change', callback: EventListener): void;
}
declare global {
export interface ESLLibrary {
MediaQuery: typeof ESLMediaQuery;
}
}