@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) • 3.69 kB
TypeScript
import { ESLCarouselDirection } from './esl-carousel.types';
import type { ESLCarouselNavInfo, ESLCarouselSlideTarget, ESLCarouselState, ESLCarouselStaticState } from './esl-carousel.types';
/** @returns stringified sign of the value */
export declare const dir: (value: number) => "+1" | "-1" | "";
/** @returns sign of the value */
export declare const sign: (value: number) => -1 | 1 | 0;
export declare const bounds: (value: number, min: number, max: number) => number;
/** @returns normalized slide index in bounds of [0, count] range */
export declare function normalize(index: number, size: number): number;
/** @returns normalize first slide index according to the carousel mode */
export declare function normalizeIndex(index: number, { size, count, loop }: ESLCarouselStaticState): number;
/** @returns normalized sequence of slides starting from the current index */
export declare function sequence(current: number, count: number, size: number): number[];
/** @returns numeric index from group index */
export declare function groupToIndex(group: number, count: number, size: number): number;
/** @returns numeric group index from slide index */
export declare function indexToGroup(index: number, count: number, size: number): number;
/** @returns closest direction to move to the passed index */
export declare function indexToDirection(index: number, { activeIndex, size, loop }: ESLCarouselState): ESLCarouselDirection | undefined;
/** @returns normalized first index from target definition and current state */
export declare function toIndex(target: ESLCarouselSlideTarget, cfg: ESLCarouselState): ESLCarouselNavInfo;
/**
* @returns whether the carousel can navigate to the target passed as {@link ESLCarouselSlideTarget}
* E.g.: carousel can't navigate to invalid target or to the next slide if it's the last slide and loop is disabled
*/
export declare function canNavigate(target: ESLCarouselSlideTarget, cfg: ESLCarouselState): boolean;
/**
* Checks whether given (0-based) slide index is currently active.
*
* @param index - 0-based slide index to check.
* @param state - current carousel state (size, count, activeIndex, loop).
* @returns true if index corresponds to an active slide of the current view; otherwise false.
*/
export declare function isCurrentIndex(index: number, { count, size, activeIndex, loop }: ESLCarouselState): boolean;
/**
* Determines if a navigation target refers to a currently active slide (or group) of the carousel.
*
* Supported target syntaxes (absolute only considered "current"):
* - Numeric (short form): `0`, `1`, `2`, `-1` (negative only meaningful in loop mode, normalized by size).
* - Slide explicit: `slide:1`, `slide:2`, ... (1-based). Internally converted to 0-based index (value - 1).
* - Group explicit: `group:1`, `group:2`, ... (1-based). A group is considered current if its FIRST slide is active.
*
* Relative syntaxes are NEVER considered current and always return false
*
* Semantics:
* - For a slide target we only check the single referenced slide.
* - For a group target we resolve the first slide of the group via {@link groupToIndex} and test it.
* - For numeric (short) targets in loop mode we normalize the raw value modulo size; in non-loop mode value must be within [0, size).
* - No validation beyond what is needed for determining activity; invalid (out-of-range) absolute slide/group indexes yield false.
*
* @param target - navigation target specification.
* @param state - current carousel state.
* @returns true if target points to an active slide/group; otherwise false.
*/
export declare function isCurrent(target: ESLCarouselSlideTarget, state: ESLCarouselState): boolean;