{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/components/accordion.ts"], "sourcesContent": ["import gsap from 'gsap'\n\nconst accordion = {\n init(): void {\n document.querySelectorAll('.accordion').forEach((target: HTMLElement) => {\n this.handleAccordion(target)\n })\n },\n\n handleAccordion(target): void {\n const el = {\n items: target.querySelectorAll('.accordion__item'),\n itemHeads: target.querySelectorAll('.accordion__head'),\n }\n\n const method = {\n init(): void {\n el.items.forEach((item, index) => {\n el.itemHeads[index].addEventListener('click', () => {\n method.toggleItem(item)\n })\n })\n },\n\n runAnimation(action, item): void {\n gsap.to(item.querySelector('.accordion__body'), {\n clearProps: 'all',\n duration: 0.543,\n ease: 'power3.inOut',\n height: action === 'open' ? 'auto' : 0,\n opacity: action === 'open' ? 1 : 0,\n onStart: () => {\n if (action === 'open') {\n item.firstElementChild.ariaExpanded = 'true'\n item.classList.add('accordion__item--active')\n } else {\n item.firstElementChild.ariaExpanded = 'false'\n item.classList.remove('accordion__item--active')\n }\n },\n })\n },\n\n toggleItem(item): void {\n const isActive = item.classList.contains('accordion__item--active')\n const currentlyActive = item.closest('.accordion').querySelector('.accordion__item--active')\n\n if (currentlyActive) {\n this.runAnimation('close', currentlyActive)\n }\n\n this.runAnimation(isActive ? 'close' : 'open', item)\n },\n }\n\n method.init()\n },\n}\n\nexport default accordion\n"], "mappings": "uEAEA,IAAMA,EAAY,CAChB,MAAa,CACX,SAAS,iBAA8B,YAAY,EAAE,QAASC,GAAwB,CACpF,KAAK,gBAAgBA,CAAM,CAC7B,CAAC,CACH,EAEA,gBAAgBA,EAAc,CAC5B,IAAMC,EAAK,CACT,MAAOD,EAAO,iBAAiB,kBAAkB,EACjD,UAAWA,EAAO,iBAAiB,kBAAkB,CACvD,EAEME,EAAS,CACb,MAAa,CACXD,EAAG,MAAM,QAAQ,CAACE,EAAMC,IAAU,CAChCH,EAAG,UAAUG,CAAK,EAAE,iBAAiB,QAAS,IAAM,CAClDF,EAAO,WAAWC,CAAI,CACxB,CAAC,CACH,CAAC,CACH,EAEA,aAAaE,EAAQF,EAAY,CAC/BG,EAAK,GAAGH,EAAK,cAAc,kBAAkB,EAAG,CAC9C,WAAY,MACZ,SAAU,KACV,KAAM,eACN,OAAQE,IAAW,OAAS,OAAS,EACrC,QAASA,IAAW,OAAS,EAAI,EACjC,QAAS,IAAM,CACTA,IAAW,QACbF,EAAK,kBAAkB,aAAe,OACtCA,EAAK,UAAU,IAAI,yBAAyB,IAE5CA,EAAK,kBAAkB,aAAe,QACtCA,EAAK,UAAU,OAAO,yBAAyB,EAEnD,CACF,CAAC,CACH,EAEA,WAAWA,EAAY,CACrB,IAAMI,EAAWJ,EAAK,UAAU,SAAS,yBAAyB,EAC5DK,EAAkBL,EAAK,QAAQ,YAAY,EAAE,cAAc,0BAA0B,EAEvFK,GACF,KAAK,aAAa,QAASA,CAAe,EAG5C,KAAK,aAAaD,EAAW,QAAU,OAAQJ,CAAI,CACrD,CACF,EAEAD,EAAO,KAAK,CACd,CACF,EAEOO,EAAQV", "names": ["accordion", "target", "el", "method", "item", "index", "action", "gsapWithCSS", "isActive", "currentlyActive", "accordion_default"] }