UNPKG

@fireng/core

Version:

Core utilities for Fireng Angular responsive library.

60 lines (59 loc) 2.94 kB
import { Signal } from '@angular/core'; import { FirengBreakpoints, FirengResponsiveMap } from './fireng.types'; import * as i0 from "@angular/core"; export declare class FirengScreenService { private readonly document; private readonly window; private _windowWidth; readonly windowWidth: Signal<number>; private _windowHeight; readonly windowHeight: Signal<number>; private readonly _breakpoint; private readonly _sortedBreakpoints; readonly currentBreakpoint: Signal<string>; readonly activeBreakpoints: Signal<string[]>; constructor(); /** * Checks if the current screen width matches the specified breakpoint. * @param breakpointName The name of the breakpoint (e.g., 'xs', 'md'). * @returns A signal indicating if the current screen width matches the specified breakpoint. */ isBreakpoint(breakpointName: string): Signal<boolean>; /** * Checks if the current screen size is at or above a specific breakpoint. * @param breakpointName The name of the breakpoint (e.g., 'sm', 'md'). * @returns A signal indicating if the current screen is at or above the breakpoint. */ isBreakpointUp(breakpointName: string): Signal<boolean>; /** * Checks if the current screen size is below a specific breakpoint. * @param breakpointName The name of the breakpoint (e.g., 'sm', 'md'). * @returns A signal indicating if the current screen is below the breakpoint. */ isBreakpointDown(breakpointName: string): Signal<boolean>; /** * Allows users to update breakpoints dynamically at runtime. * This will immediately update the `currentBreakpoint` and `activeBreakpoints` signals. * @param newBreakpoints An array of new breakpoint definitions. */ setBreakpoints(newBreakpoints: FirengBreakpoints): void; readonly isPortrait: Signal<boolean>; /** * Resolves a responsive value from a map based on current active breakpoints. * * It applies cascading logic: the value for the largest active breakpoint in `valueMap` is returned. * If no match is found, the `fallback` value is returned. * * @template T The type of the value (e.g., `number`, `string`). * @param valueMap An object mapping breakpoint names to values (e.g., `{ xs: 5, md: 10 }`). * @param fallback An optional default value if no matching breakpoint is found. * @returns A signal emitting the resolved value, or `fallback`, or `undefined`. * * @example * // Get items per page: 5 for xs, 10 for md and up, default 5 * const itemsPerPage = this.screenService.resolveBreakpointValue({ xs: 5, md: 10 }, 5); */ resolveBreakpointValue<T>(valueMap: FirengResponsiveMap<T>, fallback?: T): Signal<T | undefined>; static ɵfac: i0.ɵɵFactoryDeclaration<FirengScreenService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<FirengScreenService>; }