{"version":3,"file":"StickyNav-CmQ0HPOh.js","sources":["../../ClientApp/src/js/components/StickyNav.ts"],"sourcesContent":["import gsap from 'gsap';\r\nimport ScrollTrigger from 'gsap/ScrollTrigger';\r\nimport { ScrollToPlugin } from 'gsap/ScrollToPlugin';\r\ngsap.registerPlugin(ScrollToPlugin, ScrollTrigger);\r\nconst StickyNav = (): {\r\n init: () => void;\r\n refresh: () => void;\r\n setActiveBtn: (sectionId: string) => void;\r\n} => {\r\n const nav: HTMLElement | null = document.querySelector(\r\n '.js-sticky-nav-container',\r\n );\r\n let sections: NodeListOf = document.querySelectorAll(\r\n '.js-content-section',\r\n );\r\n let navLinks: NodeListOf = nav\r\n ? nav.querySelectorAll('a')\r\n : (document.querySelectorAll('a') as NodeListOf);\r\n\r\n const mobileDropdown: HTMLSelectElement | null = document.querySelector(\r\n '#js-sticky-nav-select',\r\n );\r\n\r\n const setActiveBtn = (sectionId: string): void => {\r\n navLinks.forEach(link => {\r\n link.classList.toggle(\r\n 'active',\r\n link.getAttribute('href') === `#${sectionId}`,\r\n );\r\n });\r\n\r\n // Update the mobile dropdown to match the current section\r\n if (mobileDropdown) {\r\n const matchingOption = Array.from(mobileDropdown.options).find(\r\n option => option.value === `#${sectionId}`,\r\n );\r\n if (matchingOption) {\r\n mobileDropdown.value = `#${sectionId}`; // Update the value without triggering 'change' event\r\n }\r\n }\r\n };\r\n\r\n const initScrollTrigger = (): void => {\r\n sections.forEach((section: HTMLElement) => {\r\n ScrollTrigger.create({\r\n trigger: section,\r\n start: 'top center',\r\n end: 'bottom center',\r\n onEnter: () => setActiveBtn(section.id),\r\n onEnterBack: () => setActiveBtn(section.id),\r\n });\r\n });\r\n };\r\n\r\n const scrollToSection = (sectionId: string): void => {\r\n const targetSection: HTMLElement | null =\r\n document.getElementById(sectionId);\r\n\r\n if (targetSection) {\r\n gsap.to(window, {\r\n scrollTo: { y: targetSection, offsetY: 182 },\r\n duration: 1,\r\n ease: 'power2.out',\r\n onComplete: () => setActiveBtn(sectionId), // Ensure button highlighting after scroll\r\n });\r\n }\r\n };\r\n\r\n const handleQueryParamScroll = (): void => {\r\n const params = new URLSearchParams(window.location.search);\r\n const sectionId = params.get('st');\r\n\r\n if (sectionId) {\r\n scrollToSection(sectionId);\r\n }\r\n };\r\n\r\n const addClickListeners = (): void => {\r\n navLinks.forEach(link => {\r\n link.addEventListener('click', (e: MouseEvent) => {\r\n e.preventDefault();\r\n const targetId = link.getAttribute('href')?.replace('#', '') || '';\r\n if (targetId) {\r\n scrollToSection(targetId);\r\n }\r\n });\r\n });\r\n };\r\n\r\n const addDropdownListener = (): void => {\r\n if (mobileDropdown) {\r\n mobileDropdown.addEventListener('change', (e: Event) => {\r\n const selectedValue = (e.target as HTMLSelectElement).value.replace(\r\n '#',\r\n '',\r\n );\r\n scrollToSection(selectedValue);\r\n });\r\n }\r\n };\r\n\r\n const refresh = (): void => {\r\n sections = document.querySelectorAll('.js-content-section');\r\n navLinks = nav\r\n ? nav.querySelectorAll('a')\r\n : (document.querySelectorAll('a') as NodeListOf);\r\n\r\n ScrollTrigger.getAll().forEach(trigger => trigger.kill());\r\n initScrollTrigger();\r\n ScrollTrigger.refresh();\r\n };\r\n\r\n const init = (): void => {\r\n if (!nav || sections.length === 0) return;\r\n initScrollTrigger();\r\n addClickListeners();\r\n addDropdownListener();\r\n handleQueryParamScroll(); // Scroll based on query parameter\r\n };\r\n\r\n return { init, refresh, setActiveBtn };\r\n};\r\n\r\nexport default StickyNav;\r\n"],"names":["gsap","ScrollToPlugin","ScrollTrigger","StickyNav","nav","sections","navLinks","mobileDropdown","setActiveBtn","sectionId","link","option","initScrollTrigger","section","scrollToSection","targetSection","handleQueryParamScroll","addClickListeners","e","targetId","_a","addDropdownListener","selectedValue","trigger"],"mappings":"2FAGAA,EAAK,eAAeC,EAAgBC,CAAa,EACjD,MAAMC,EAAY,IAIb,CACH,MAAMC,EAA0B,SAAS,cACvC,0BAAA,EAEF,IAAIC,EAAoC,SAAS,iBAC/C,qBA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