import { Feature } from "../feature.mjs"; import { isHidden } from "../../utils/is-hidden.mjs"; import { defaultScaleCorrector } from "./config.mjs"; import { addScaleCorrector, globalProjectionState } from "motion-dom"; //#region src/features/layout/layout.ts var LayoutFeature = class extends Feature { static { this.key = "layout"; } constructor(state) { super(state); addScaleCorrector(defaultScaleCorrector); } updatePrevLead(isPresent) { const projection = this.state.visualElement.projection; if (projection.isPresent !== isPresent) { projection.isPresent = isPresent; if (isPresent) !projection.isLead() && projection?.promote(); else projection.isLead() && projection?.relegate(); } } didUpdate() { if (this.state.options.layout || this.state.options.layoutId || this.state.options.drag) this.state.visualElement.projection?.root?.didUpdate(); } mount() { const options = this.state.options; const layoutGroup = this.state.options.layoutGroup; if (options.layout || options.layoutId) { const projection = this.state.visualElement.projection; if (options.layoutId) { const isPresent = !isHidden(this.state.element); projection.isPresent = isPresent; if (isPresent) projection?.promote(); else projection?.relegate(); } layoutGroup?.group?.add(projection); globalProjectionState.hasEverUpdated = true; } this.didUpdate(); } unmount() { const layoutGroup = this.state.options.layoutGroup; const projection = this.state.visualElement.projection; if (projection) { if (layoutGroup?.group && (this.state.options.layout || this.state.options.layoutId)) layoutGroup.group.remove(projection); } } /** * Capture a layout snapshot. Options are always refreshed by the caller * before this runs (updateOptions → lifecycle hook), so the only remaining * signal is presence: an exiting element is treated as not present. */ getSnapshot(isPresent) { const projection = this.state.visualElement.projection; const { layout, layoutId, drag, layoutDependency } = this.state.visualElement.props; const prevProps = this.state.visualElement.prevProps; if (!projection || !layout && !layoutId && !drag) return; /** * If drag is enabled, no layoutDependency is set, or presence changed, * we need to update the snapshot */ if (drag || prevProps.layoutDependency !== layoutDependency || layoutDependency === void 0 || isPresent !== projection.isPresent) projection.willUpdate(); /** * If presence has changed, promote or relegate the projection accordingly */ if (layoutId) this.updatePrevLead(isPresent); this.didUpdate(); } refreshRootScroll() { const root = this.state.visualElement?.projection?.root; if (root && this.state.options.layoutId) { root.scroll = void 0; root.updateScroll?.(); } } }; //#endregion export { LayoutFeature };