{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/sections/mobile-header.ts"], "sourcesContent": ["import gsap from 'gsap'\n// import { lenisScroll } from 'utility/smooth-scroll'\n\nconst mobileHeader = {\n el: {\n menuItems: document.querySelectorAll('.mobile-header__menu-link, .mobile-header__menu .button'),\n modal: document.querySelector('.mobile-header__modal'),\n trigger: document.querySelector('.mobile-header__menu-trigger'),\n },\n\n init(): void {\n this.el.trigger.addEventListener('click', this.toggleMenu.bind(this))\n },\n\n closeOnEscPress(event): void {\n if (event.key.match('Escape') && mobileHeader.isActive()) {\n mobileHeader.toggleMenu()\n }\n },\n\n closeOnOutsideClick(event): void {\n if (\n !event.target.closest('.mobile-header .mobile-header__modal') &&\n !event.target.closest('.mobile-header .mobile-header__menu-trigger') &&\n !event.target.closest('.body .search') &&\n mobileHeader.isActive()\n ) {\n mobileHeader.toggleMenu()\n }\n },\n\n isActive(): boolean {\n return this.el.modal.classList.contains('mobile-header__modal--active')\n },\n\n runAnimation(action): void {\n const props = {\n clearProps: 'all',\n duration: 0.543,\n ease: 'power3.inOut',\n }\n\n gsap.fromTo(\n this.el.modal,\n {\n height: action === 'open' ? 0 : this.el.modal.offsetHeight,\n opacity: action === 'open' ? 0 : 1,\n scale: action === 'open' ? 0.77 : 1,\n },\n {\n height: action === 'open' ? 'auto' : 0,\n // TODO: Decide later if it makes sense to pause scroll when cart is open on mobile\n // onComplete: () => {\n // if (action === 'open') {\n // window.innerWidth < breakpoint.tablet && lenisScroll.stop()\n // } else {\n // lenisScroll.isStopped && lenisScroll.start()\n // }\n // },\n opacity: action === 'open' ? 1 : 0,\n scale: action === 'open' ? 1 : 0.77,\n ...props,\n }\n )\n\n gsap.fromTo(\n this.el.menuItems,\n {\n opacity: action === 'open' ? 0 : 1,\n },\n {\n delay: action === 'open' ? 0.15 : 0,\n opacity: action === 'open' ? 1 : 0,\n overwrite: true,\n stagger: action === 'open' ? 0.06 : 0,\n ...props,\n duration: action === 'open' ? 0.543 : 0.321,\n }\n )\n },\n\n toggleMenu(): void {\n this.runAnimation(this.isActive() ? 'close' : 'open')\n\n if (!this.isActive()) {\n this.el.modal.classList.add('mobile-header__modal--active')\n this.el.trigger.classList.add('mobile-header__menu-trigger--active')\n this.el.trigger.ariaExpanded = 'true'\n document.body.addEventListener('click', mobileHeader.closeOnOutsideClick)\n window.addEventListener('keydown', mobileHeader.closeOnEscPress)\n } else {\n this.el.modal.classList.remove('mobile-header__modal--active')\n this.el.trigger.classList.remove('mobile-header__menu-trigger--active')\n this.el.trigger.ariaExpanded = 'false'\n document.body.removeEventListener('click', mobileHeader.closeOnOutsideClick)\n window.removeEventListener('keydown', mobileHeader.closeOnEscPress)\n }\n },\n}\n\nexport default mobileHeader\n"], "mappings": "+FAGA,IAAMA,EAAe,CACnB,GAAI,CACF,UAAW,SAAS,iBAA8B,yDAAyD,EAC3G,MAAO,SAAS,cAA2B,uBAAuB,EAClE,QAAS,SAAS,cAA2B,8BAA8B,CAC7E,EAEA,MAAa,CACX,KAAK,GAAG,QAAQ,iBAAiB,QAAS,KAAK,WAAW,KAAK,IAAI,CAAC,CACtE,EAEA,gBAAgBC,EAAa,CACvBA,EAAM,IAAI,MAAM,QAAQ,GAAKD,EAAa,SAAS,GACrDA,EAAa,WAAW,CAE5B,EAEA,oBAAoBC,EAAa,CAE7B,CAACA,EAAM,OAAO,QAAQ,sCAAsC,GAC5D,CAACA,EAAM,OAAO,QAAQ,6CAA6C,GACnE,CAACA,EAAM,OAAO,QAAQ,eAAe,GACrCD,EAAa,SAAS,GAEtBA,EAAa,WAAW,CAE5B,EAEA,UAAoB,CAClB,OAAO,KAAK,GAAG,MAAM,UAAU,SAAS,8BAA8B,CACxE,EAEA,aAAaE,EAAc,CACzB,IAAMC,EAAQ,CACZ,WAAY,MACZ,SAAU,KACV,KAAM,cACR,EAEAC,EAAK,OACH,KAAK,GAAG,MACR,CACE,OAAQF,IAAW,OAAS,EAAI,KAAK,GAAG,MAAM,aAC9C,QAASA,IAAW,OAAS,EAAI,EACjC,MAAOA,IAAW,OAAS,IAAO,CACpC,EACAG,EAAA,CACE,OAAQH,IAAW,OAAS,OAAS,EASrC,QAASA,IAAW,OAAS,EAAI,EACjC,MAAOA,IAAW,OAAS,EAAI,KAC5BC,EAEP,EAEAC,EAAK,OACH,KAAK,GAAG,UACR,CACE,QAASF,IAAW,OAAS,EAAI,CACnC,EACAI,EAAAD,EAAA,CACE,MAAOH,IAAW,OAAS,IAAO,EAClC,QAASA,IAAW,OAAS,EAAI,EACjC,UAAW,GACX,QAASA,IAAW,OAAS,IAAO,GACjCC,GALL,CAME,SAAUD,IAAW,OAAS,KAAQ,IACxC,EACF,CACF,EAEA,YAAmB,CACjB,KAAK,aAAa,KAAK,SAAS,EAAI,QAAU,MAAM,EAE/C,KAAK,SAAS,GAOjB,KAAK,GAAG,MAAM,UAAU,OAAO,8BAA8B,EAC7D,KAAK,GAAG,QAAQ,UAAU,OAAO,qCAAqC,EACtE,KAAK,GAAG,QAAQ,aAAe,QAC/B,SAAS,KAAK,oBAAoB,QAASF,EAAa,mBAAmB,EAC3E,OAAO,oBAAoB,UAAWA,EAAa,eAAe,IAVlE,KAAK,GAAG,MAAM,UAAU,IAAI,8BAA8B,EAC1D,KAAK,GAAG,QAAQ,UAAU,IAAI,qCAAqC,EACnE,KAAK,GAAG,QAAQ,aAAe,OAC/B,SAAS,KAAK,iBAAiB,QAASA,EAAa,mBAAmB,EACxE,OAAO,iBAAiB,UAAWA,EAAa,eAAe,EAQnE,CACF,EAEOO,EAAQP", "names": ["mobileHeader", "event", "action", "props", "gsapWithCSS", "__spreadValues", "__spreadProps", "mobile_header_default"] }