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EAAyB,GACtC,G","sources":["webpack:///./Features/Components/AccordionBlock/_js/accordion-block.ts"],"sourcesContent":["export const useAccordion = (detailsElement: HTMLDetailsElement) => {\r\n let summary = detailsElement.querySelector('summary') as HTMLElement;\r\n let content = detailsElement.querySelector('.accordion-block__content') as HTMLDivElement;\r\n let animation: Animation | null = null;\r\n let isClosing = false;\r\n let isExpanding = false;\r\n let animationDuration: number | string = 250;\r\n\r\n const onClick = (e: Event) => {\r\n e.preventDefault();\r\n detailsElement.style.overflow = 'hidden';\r\n\r\n if (isClosing || !detailsElement.open) {\r\n open();\r\n } else if (isExpanding || detailsElement.open) {\r\n shrink();\r\n }\r\n };\r\n\r\n const shrink = () => {\r\n isClosing = true;\r\n const startHeight = `${detailsElement.offsetHeight}px`;\r\n const endHeight = `${summary.offsetHeight}px`;\r\n\r\n if (animation) {\r\n animation.cancel();\r\n }\r\n\r\n animation = detailsElement.animate(\r\n {\r\n height: [startHeight, endHeight],\r\n },\r\n {\r\n duration: 150,\r\n easing: 'ease-out',\r\n }\r\n );\r\n\r\n animation.onfinish = () => onAnimationFinish(false);\r\n animation.oncancel = () => (isClosing = false);\r\n };\r\n\r\n const open = () => {\r\n detailsElement.style.height = `${detailsElement.offsetHeight}px`;\r\n detailsElement.open = true;\r\n\r\n window.requestAnimationFrame(() => expand());\r\n };\r\n\r\n const expand = () => {\r\n isExpanding = true;\r\n const startHeight = `${detailsElement.offsetHeight}px`;\r\n const endHeight = `${summary.offsetHeight + content.offsetHeight}px`;\r\n\r\n if (animation) {\r\n animation.cancel();\r\n }\r\n\r\n animation = detailsElement.animate(\r\n {\r\n height: [startHeight, endHeight],\r\n },\r\n {\r\n duration: animationDuration,\r\n easing: 'ease-out',\r\n }\r\n );\r\n\r\n animation.onfinish = () => onAnimationFinish(true);\r\n animation.oncancel = () => (isExpanding = false);\r\n };\r\n\r\n const onAnimationFinish = (open: boolean) => {\r\n detailsElement.open = open;\r\n animation = null;\r\n isClosing = false;\r\n isExpanding = false;\r\n detailsElement.style.height = detailsElement.style.overflow = '';\r\n };\r\n\r\n summary.addEventListener('click', onClick);\r\n};\r\n\r\n// This is used to initialize the accordion on the page load\r\ndocument.addEventListener('DOMContentLoaded', () => {\r\n document.querySelectorAll('details').forEach((el) => {\r\n useAccordion(el as HTMLDetailsElement);\r\n });\r\n});\r\n"],"names":["document","addEventListener","querySelectorAll","forEach","el","detailsElement","summary","querySelector","content","animation","isClosing","isExpanding","shrink","startHeight","offsetHeight","endHeight","cancel","animate","height","duration","easing","onfinish","onAnimationFinish","oncancel","open","style","window","requestAnimationFrame","expand","overflow","e","preventDefault","useAccordion"],"sourceRoot":""}