heartbeat-monitor/node_modules/framer-motion/dist/es/utils/use-instant-transition.mjs.map

1 line
2.0 KiB
Plaintext

{"version":3,"file":"use-instant-transition.mjs","sources":["../../../src/utils/use-instant-transition.ts"],"sourcesContent":["\"use client\"\n\nimport { frame } from \"motion-dom\"\nimport { MotionGlobalConfig } from \"motion-utils\"\nimport { useEffect, useRef } from \"react\"\nimport { useInstantLayoutTransition } from \"../projection/use-instant-layout-transition\"\nimport { useForceUpdate } from \"./use-force-update\"\n\nexport function useInstantTransition() {\n const [forceUpdate, forcedRenderCount] = useForceUpdate()\n const startInstantLayoutTransition = useInstantLayoutTransition()\n const unlockOnFrameRef = useRef<number>(-1)\n\n useEffect(() => {\n /**\n * Unblock after two animation frames, otherwise this will unblock too soon.\n */\n frame.postRender(() =>\n frame.postRender(() => {\n /**\n * If the callback has been called again after the effect\n * triggered this 2 frame delay, don't unblock animations. This\n * prevents the previous effect from unblocking the current\n * instant transition too soon. This becomes more likely when\n * used in conjunction with React.startTransition().\n */\n if (forcedRenderCount !== unlockOnFrameRef.current) return\n MotionGlobalConfig.instantAnimations = false\n })\n )\n }, [forcedRenderCount])\n\n return (callback: () => void) => {\n startInstantLayoutTransition(() => {\n MotionGlobalConfig.instantAnimations = true\n forceUpdate()\n callback()\n unlockOnFrameRef.current = forcedRenderCount + 1\n })\n }\n}\n\nexport function disableInstantTransitions() {\n MotionGlobalConfig.instantAnimations = false\n}\n"],"names":[],"mappings":";;;;;;;;;AAUI;AACA;;AAGI;;AAEG;;AAGK;;;;;;AAMG;AACH;;AACA;;AAGZ;;;AAIQ;AACA;AACA;AACA;AACJ;AACJ;AACJ;;AAGI;AACJ;;"}