import { useMotionConfig } from "../motion-config/context.mjs"; import { provideAnimatePresence } from "./presence.mjs"; import { createExitSession } from "./exit-session.mjs"; import { onMounted, onUnmounted } from "vue"; //#region src/components/animate-presence/use-presence-container.ts function usePresenceContainer(props) { const motionConfig = useMotionConfig(); const sessions = createExitSession({ props, getNonce: () => motionConfig.value.nonce, onAllComplete: () => props.onExitComplete?.() }); const registered = /* @__PURE__ */ new Set(); const handlers = /* @__PURE__ */ new Set(); let hasMounted = false; provideAnimatePresence({ get initial() { return hasMounted ? void 0 : props.initial; }, get custom() { return props.custom; }, register: (state) => registered.add(state), unregister: (state) => registered.delete(state), registerHandler: (handler) => handlers.add(handler), unregisterHandler: (handler) => handlers.delete(handler) }); onMounted(() => { hasMounted = true; }); function findMotionStates(container) { const states = []; for (const state of registered) { const el = state.element; if (el && (el === container || container.contains(el))) states.push(state); } return states; } function findHandlers(container) { const found = []; for (const handler of handlers) { const el = handler.element(); if (el && (el === container || container.contains(el))) found.push(handler); } return found; } function enter(el, done) { sessions.abort(el); findMotionStates(el).forEach((state) => { state.getFeature("exit")?.reenter(); }); done(); } function exit(el, done) { const container = el; const states = findMotionStates(container); const exiting = findHandlers(container); if (states.length === 0 && exiting.length === 0) { done(); props.onExitComplete?.(); return; } sessions.track(container, states, done, exiting); } onUnmounted(() => { sessions.dispose(); }); return { enter, exit }; } //#endregion export { usePresenceContainer };