import { type MasonryOptions } from '../core'; /** * Vanilla JS masonry grid layout engine. * * @example * const masonry = new MasonrySnapGridLayout(container, { * layoutMode: 'auto', * gutter: 16, * minColWidth: 240, * animate: true, * items, * renderItem: (item) => { * const el = document.createElement('div'); * el.textContent = item.title; * return el; * }, * }); */ export default class MasonrySnapGridLayout { private container; private options; private elements; private resizeObserver?; private itemObserver?; private scheduler; private usesCss; private destroyed; /** Element cache keyed by `getItemKey`, enabling reuse across updates. */ private keyed; constructor(container: HTMLElement, options: MasonryOptions); private init; private shouldUseCss; /** * Build the element list for the current items. * * With `getItemKey` supplied, elements are reused across updates instead of * being torn down and rebuilt — preserving focus, text selection, scroll * position inside items, and in-flight media playback. Without it, indices * carry no identity so a full rebuild is the only correct option. */ private buildElements; /** * Detach elements from the item observer. * * Removing a node from the DOM does not stop a ResizeObserver watching it, so * skipping this would make the observer's set grow with every update. */ private releaseElements; /** Unobserve and remove every current element, resetting the key cache. */ private discardElements; private render; private layout; private observeResize; /** Replace all items and re-render the grid. */ updateItems(newItems: T[]): void; /** * Merge in new options and re-layout. * * Changing `layoutMode` re-evaluates which engine is used and cleans up the * previous engine's styles before switching, so callers never have to * destroy and rebuild the instance to change a single option. */ setOptions(next: Partial, 'items'>>): void; /** * Recompute the layout immediately. * * Rarely needed — item resizes, image loads, and container resizes are all * detected automatically — but useful after mutating item content directly. */ refresh(): void; /** Clean up DOM mutations and stop observing resize. */ destroy(): void; }