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CAAI,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAElG,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;KACpD;IAED,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK,IAAI,SAAS,CAAC,YAAY,EAAE;QACnD,OAAO,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC;KAC5D;IAED,OAAO,SAAS,CAAC;AACnB;;;;","names":[],"sources":["src/functions/animate.ts","src/functions/animation-registry.ts"],"sourcesContent":["//\n// Animates an element using keyframes. Returns a promise that resolves after the animation completes or gets canceled.\n//\nexport function animateTo(el: HTMLElement, keyframes: Keyframe[], options?: KeyframeAnimationOptions) {\n return new Promise(resolve => {\n if (options?.duration === Infinity) {\n throw new Error('Promise-based animations must be finite.');\n }\n\n if (!el?.animate) {\n return;\n }\n\n const animation = el.animate(keyframes, {\n ...options,\n duration: prefersReducedMotion() ? 0 : options!.duration,\n });\n\n if (!animation) {\n return;\n }\n\n animation.addEventListener('cancel', resolve, { once: true });\n animation.addEventListener('finish', resolve, { once: true });\n });\n}\n\n//\n// Parses a CSS duration and returns the number of milliseconds.\n//\nexport function parseDuration(delay: number | string) {\n delay = delay.toString().toLowerCase();\n\n if (delay.indexOf('ms') > -1) {\n return parseFloat(delay);\n }\n\n if (delay.indexOf('s') > -1) {\n return parseFloat(delay) * 1000;\n }\n\n return parseFloat(delay);\n}\n\n//\n// Tells if the user has enabled the \"reduced motion\" setting in their browser or OS.\n//\nexport function prefersReducedMotion() {\n const query = window.matchMedia('(prefers-reduced-motion: reduce)');\n return query.matches;\n}\n\n//\n// Stops all active animations on the target element. Returns a promise that resolves after all animations are canceled.\n//\nexport function stopAnimations(el: HTMLElement) {\n return Promise.all(\n (el?.getAnimations?.() || []).map(animation => {\n return new Promise(resolve => {\n const handleAnimationEvent = requestAnimationFrame(resolve);\n\n animation.addEventListener('cancel', () => handleAnimationEvent, { once: true });\n animation.addEventListener('finish', () => handleAnimationEvent, { once: true });\n animation.cancel();\n });\n }),\n );\n}\n\n// We can't animate `height: auto`, but we can calculate the height and shim keyframes by replacing it with the\n// element's scrollHeight before the animation.\nexport function shimKeyframesHeightAuto(keyframes: Keyframe[], calculatedHeight: number) {\n return keyframes.map(keyframe => ({\n ...keyframe,\n height: keyframe.height === 'auto' ? `${calculatedHeight}px` : keyframe.height,\n }));\n}\n","interface ElementAnimation {\n keyframes: Keyframe[];\n rtlKeyframes?: Keyframe[];\n options?: KeyframeAnimationOptions;\n}\n\ninterface ElementAnimationMap {\n [animationName: string]: ElementAnimation;\n}\n\ninterface GetAnimationOptions {\n dir?: 'ltr' | 'rtl';\n}\n\nconst defaultAnimationRegistry = new Map<string, ElementAnimation>();\nconst customAnimationRegistry = new WeakMap<Element, ElementAnimationMap>();\n\nfunction ensureAnimation(animation: ElementAnimation | null) {\n return animation ?? { keyframes: [], options: { duration: 0 } };\n}\n\n//\n// Sets a default animation. Components should use the `name.animation` for primary animations and `name.part.animation`\n// for secondary animations, e.g. `dialog.show` and `dialog.overlay.show`. For modifiers, use `drawer.showTop`.\n//\nexport function setDefaultAnimation(animationName: string, animation: ElementAnimation | null) {\n defaultAnimationRegistry.set(animationName, ensureAnimation(animation));\n}\n\n//\n// Sets a custom animation for the specified element.\n//\nexport function setAnimation(el: Element, animationName: string, animation: ElementAnimation | null) {\n customAnimationRegistry.set(el, { ...customAnimationRegistry.get(el), [animationName]: ensureAnimation(animation) });\n}\n\n//\n// Gets an element's animation. Falls back to the default if no animation is found.\n// Pass `{ dir: 'rtl' }` to receive the mirrored keyframes (when the animation provides them).\n//\nexport function getAnimation(el: Element, animationName: string, options: GetAnimationOptions = {}): ElementAnimation {\n const customAnimation = customAnimationRegistry.get(el);\n const animation = customAnimation?.[animationName] ?? defaultAnimationRegistry.get(animationName);\n\n if (!animation) {\n return { keyframes: [], options: { duration: 0 } };\n }\n\n if (options.dir === 'rtl' && animation.rtlKeyframes) {\n return { ...animation, keyframes: animation.rtlKeyframes };\n }\n\n return animation;\n}\n"],"version":3}