box-overflow-core
Version:
Headless UI for automatically collapsing boxes when overflow.
73 lines (72 loc) • 2.25 kB
text/typescript
/**
* @author shunzi <tobyzsj@gmail.com>
* @date 2024-03-24 18:03:46
*/
import { Observer } from './observer.cjs';
import type { CSSProperties, SetRequired } from './types.cjs';
export interface BoxOverflowOptions {
idAttribute?: string;
maxCount?: number;
maxLine?: number;
/**
* 排列方向
* @default 'ltr'
*/
direction?: 'ltr' | 'rtl';
getContainer: () => HTMLElement;
/**
* 显示的数量变更
*/
onDisplayChange?: (count: OverflowItem[]) => void;
getIdByIndex?: (index: number) => string;
}
export interface OverflowItem {
key: string;
index: number;
line: number;
left: number;
top: number;
width: number;
height: number;
}
interface SizeRect {
width: number;
height: number;
}
export declare class BoxOverflow {
options: SetRequired<BoxOverflowOptions, 'idAttribute'>;
displayCount: number;
isRestReady: boolean;
hasRest: boolean;
containerElement: HTMLElement | null;
sizeChanged: boolean;
sizeCache: Map<string, SizeRect>;
measurementsCache: OverflowItem[];
measureElementCache: Map<string, HTMLElement>;
itemsObserver: Observer<import("./types").ObserverType.Resize>;
containerObserver: Observer<import("./types").ObserverType.Resize>;
childrenObserver: Observer<import("./types").ObserverType.Mutation>;
itemMeasurer(element: HTMLElement): void;
containerMeasurer(element: HTMLElement): void;
childrenChange(mutation: MutationRecord): void;
constructor(options: BoxOverflowOptions);
setOptions(options: BoxOverflowOptions): void;
onMount(): () => void;
onUpdate(): void;
destroy(): void;
triggerChange: () => NonNullable<void>;
idOfElement(node: HTMLElement): string;
measureElements(): void;
measureElement(node: HTMLElement): void;
measureContainer(element: HTMLElement): void;
getRests: () => string[];
private getItemCounts;
private getMaxCount;
private getMaxLine;
getMeasurements(): OverflowItem[];
private updateMeasurementsCache;
getContainerStyle(): Partial<CSSProperties>;
getItemStyle(id: string): Partial<CSSProperties>;
getRestStyle(): Partial<CSSProperties>;
}
export {};