import { ExportNs } from '../../../esl-utils/environment/export-ns' ; const registry = new Map < string , ESLScreenBreakpoint > ( ) ; author Yuliya Adamskaya, Alexey Stsefanovich (ala'n) *
 * Screen Breakpoint registry is used to provide custom breakpoints for  ESLMediaQuery implements IMediaQueryPreprocessor @ ExportNs ( 'ScreenBreakpoints' ) export abstract class ESLScreenBreakpoints { protected static readonly BP_REGEXP = /^([+-]?)([a-z]+)/i ; protected static readonly BP_NAME_REGEXP = /^[a-z]+/i ; param name param minWidth param maxWidth public static add ( name , minWidth , maxWidth ) { name = name . toLowerCase ( ) ; if ( ESLScreenBreakpoints . BP_NAME_REGEXP . test ( name ) ) { const current = registry . get ( name ) ; registry . set ( name , new ESLScreenBreakpoint ( name , minWidth , maxWidth ) ) ; return current ; } throw new Error ( 'The shortcut should consist only of Latin characters and be at least one character long.' ) ; } /** Removes screen breakpoint */ public static remove ( name ) { return registry . delete ( name . toLowerCase ( ) ) ; } returns public static get ( name ) { return registry . get ( ( name || '' ) . toLowerCase ( ) ) ; } /** All available breakpoints names */ public static get names ( ) : string [ ] { const keys = [ ] ; registry . forEach ( ( value , key ) => keys . push ( key ) ) ; return keys ; } returns public static process ( term ) { const [ , sign , bp ] = term . match ( ESLScreenBreakpoints . BP_REGEXP ) || [ ] ; const shortcut = ESLScreenBreakpoints . get ( bp ) ; if ( ! shortcut ) return ; if ( sign === '+' ) return shortcut . mediaQueryGE ; if ( sign === '-' ) return shortcut . mediaQueryLE ; return shortcut . mediaQuery ; } } /** ESL Screen Breakpoint description */ export class ESLScreenBreakpoint { constructor ( public readonly name , public readonly min , public readonly max ) { } public get mediaQuery ( ) : string { return `(min-width: ${ this . min }px) and (max-width: ${ this . max }px)` ; } public get mediaQueryGE ( ) : string { return `(min-width: ${ this . min }px)` ; } public get mediaQueryLE ( ) : string { return `(max-width: ${ this . max }px)` ; } public toString ( ) { return `[${ this . name }]: ${ this . min } to ${ this . max }` ; } } ESLScreenBreakpoints . add ( 'xs' , 1 , 767 ) ; ESLScreenBreakpoints . add ( 'sm' , 768 , 991 ) ; ESLScreenBreakpoints . add ( 'md' , 992 , 1199 ) ; ESLScreenBreakpoints . add ( 'lg' , 1200 , 1599 ) ; ESLScreenBreakpoints . add ( 'xl' , 1600 , 999999 ) ; declare global { export interface ESLLibrary { ScreenBreakpoints : typeof ESLScreenBreakpoints ; } }