{"version":3,"file":"index.mjs","sources":["../../../../src/components/AnimateView/index.tsx"],"sourcesContent":["\"use client\"\n\nimport React, {\n    ComponentType,\n    PropsWithChildren,\n    useInsertionEffect,\n} from \"react\"\nimport { animateViewLayers } from \"./animate-view-layers\"\nimport { useResetViewTransitions } from \"./hooks/use-reset-view-transitions\"\nimport { sharedProps } from \"./shared-props\"\nimport { AnimateViewProps, ViewAnimationType } from \"./types\"\n\ntype ViewTransitionEvent = (\n    instance: { name: string },\n    types: string[]\n) => VoidFunction\n\ninterface ViewTransitionProps {\n    name?: string\n    onEnter: ViewTransitionEvent\n    onExit: ViewTransitionEvent\n    onShare: ViewTransitionEvent\n    onUpdate: ViewTransitionEvent\n}\n\n// Keep the entry point importable with React 18 and its type definitions.\nconst ViewTransition = (\n    React as unknown as {\n        ViewTransition?: ComponentType<PropsWithChildren<ViewTransitionProps>>\n    }\n).ViewTransition\n\n/**\n * Animate enter, exit, update and shared view transitions.\n * Requires React and React DOM 19.3 or later.\n */\nexport function AnimateView({\n    children,\n    ...props\n}: PropsWithChildren<AnimateViewProps>): React.ReactElement {\n    if (!ViewTransition) {\n        throw new Error(\"AnimateView requires React 19.3 or later.\")\n    }\n\n    useResetViewTransitions()\n    const { name } = props\n\n    useInsertionEffect(() => {\n        if (!name) return\n        sharedProps.set(name, props)\n        return () => {\n            if (sharedProps.get(name) === props) sharedProps.delete(name)\n        }\n    })\n\n    const createAnimation =\n        (type: ViewAnimationType): ViewTransitionEvent =>\n        ({ name: viewName }, types) =>\n            animateViewLayers(\n                viewName,\n                type,\n                sharedProps.get(viewName) || props,\n                types\n            )\n\n    return (\n        <ViewTransition\n            name={name}\n            onEnter={createAnimation(\"enter\")}\n            onExit={createAnimation(\"exit\")}\n            onShare={createAnimation(\"share\")}\n            onUpdate={createAnimation(\"update\")}\n        >\n            {children}\n        </ViewTransition>\n    )\n}\n"],"names":[],"mappings":";;;;;;;AAyBA;AACA;AAMA;;;AAGG;AACG;;AAKE;;AAGJ;AACA;;AAGI;;AACA;AACA;AACI;AAAqC;AACzC;AACJ;AAEA;AAUA;AAWJ;;"}