{ "version": 3, "sources": ["../../javascript/warp/utilities/horizontalScroll.ts"], "sourcesContent": ["export default function horizontalScroll() {\n const containers = document.querySelectorAll(\".horizontal-scroll__container\")\n\n containers.forEach((container) => {\n const scrollableContent = container.querySelector(\n \".horizontal-scroll__card-container\"\n ) as HTMLDivElement\n const leftArrow = container.querySelector(\n \".carousel__arrow-prev\"\n ) as HTMLButtonElement\n const rightArrow = container.querySelector(\n \".carousel__arrow-next\"\n ) as HTMLButtonElement\n\n const scrollItem = container.querySelector(\".horizontal-scroll__card\")\n\n if (!scrollableContent || !scrollItem) {\n return\n }\n\n const itemWidth = scrollItem.clientWidth\n\n function handleScroll(event: WheelEvent) {\n // Scroll horizontally\n // This can be only 1 or -1 depending on the scrolling direction.\n // We multiply by 40 to set the scrolling speed (40px)\n var delta = Math.max(-1, Math.min(1, event.deltaY || -event.detail))\n scrollableContent.scrollLeft -= -delta * 40\n\n event.preventDefault()\n }\n\n // Check if we need to disable one of the arrows\n function handleArrows() {\n if (scrollableContent.scrollLeft === 0) {\n // Case 1: The scrollable content is in the initial position,\n // so we disable the left arrow and enable the right one\n leftArrow.disabled = true\n rightArrow.disabled = false\n } else if (\n Math.floor(scrollableContent.scrollWidth) -\n Math.floor(scrollableContent.scrollLeft) <=\n container.clientWidth + 20\n ) {\n // Case 2: The scrollable content is at the end,\n // so we disable the right arrow and enable the left one\n rightArrow.disabled = true\n leftArrow.disabled = false\n } else {\n // Case 3: We are in the middle of a scroll,\n // so we enable both the arrows\n leftArrow.disabled = false\n rightArrow.disabled = false\n }\n }\n\n // Chrome, Safari\n scrollableContent.addEventListener(\n \"mousewheel\",\n handleScroll as EventListener,\n false\n )\n // Firefox\n scrollableContent.addEventListener(\n \"DOMMouseScroll\",\n handleScroll as EventListener,\n false\n )\n\n // We handle the arrows even if the scrolling is caused by the\n // arrow themselves, so we need to listen to the general scroll\n // event\n scrollableContent.addEventListener(\"scroll\", handleArrows)\n\n // Initially we disable the left arrow\n leftArrow.disabled = true\n\n // Add click listeners to the arrows to scroll the content\n function handleArrowClick(negative: boolean) {\n return () => {\n // Calculate current item position (rounded to nearest item)\n const currentPosition =\n Math.round(scrollableContent.scrollLeft / itemWidth) * itemWidth\n\n // Calculate max scroll position\n const maxScroll =\n scrollableContent.scrollWidth - scrollableContent.clientWidth\n\n // Calculate next scroll position\n const nextPosition = negative\n ? Math.max(0, currentPosition - itemWidth) // Don't go below 0\n : Math.min(maxScroll, currentPosition + itemWidth) // Don't exceed max\n\n // Scroll to the calculated position\n scrollableContent.scrollTo({\n left: nextPosition,\n behavior: \"smooth\"\n })\n }\n }\n\n leftArrow.addEventListener(\"click\", handleArrowClick(true))\n rightArrow.addEventListener(\"click\", handleArrowClick(false))\n\n handleArrows()\n })\n}\n"], "mappings": "AAAe,SAARA,GAAoC,CACtB,SAAS,iBAAiB,+BAA+B,EAEjE,QAASC,GAAc,CAChC,IAAMC,EAAoBD,EAAU,cAClC,oCACF,EACME,EAAYF,EAAU,cAC1B,uBACF,EACMG,EAAaH,EAAU,cAC3B,uBACF,EAEMI,EAAaJ,EAAU,cAAc,0BAA0B,EAErE,GAAI,CAACC,GAAqB,CAACG,EACzB,OAGF,IAAMC,EAAYD,EAAW,YAE7B,SAASE,EAAaC,EAAmB,CAIvC,IAAIC,EAAQ,KAAK,IAAI,GAAI,KAAK,IAAI,EAAGD,EAAM,QAAU,CAACA,EAAM,MAAM,CAAC,EACnEN,EAAkB,YAAc,CAACO,EAAQ,GAEzCD,EAAM,eAAe,CACvB,CAGA,SAASE,GAAe,CAClBR,EAAkB,aAAe,GAGnCC,EAAU,SAAW,GACrBC,EAAW,SAAW,IAEtB,KAAK,MAAMF,EAAkB,WAAW,EACtC,KAAK,MAAMA,EAAkB,UAAU,GACzCD,EAAU,YAAc,IAIxBG,EAAW,SAAW,GACtBD,EAAU,SAAW,KAIrBA,EAAU,SAAW,GACrBC,EAAW,SAAW,GAE1B,CAGAF,EAAkB,iBAChB,aACAK,EACA,EACF,EAEAL,EAAkB,iBAChB,iBACAK,EACA,EACF,EAKAL,EAAkB,iBAAiB,SAAUQ,CAAY,EAGzDP,EAAU,SAAW,GAGrB,SAASQ,EAAiBC,EAAmB,CAC3C,MAAO,IAAM,CAEX,IAAMC,EACJ,KAAK,MAAMX,EAAkB,WAAaI,CAAS,EAAIA,EAGnDQ,EACJZ,EAAkB,YAAcA,EAAkB,YAG9Ca,EAAeH,EACjB,KAAK,IAAI,EAAGC,EAAkBP,CAAS,EACvC,KAAK,IAAIQ,EAAWD,EAAkBP,CAAS,EAGnDJ,EAAkB,SAAS,CACzB,KAAMa,EACN,SAAU,QACZ,CAAC,CACH,CACF,CAEAZ,EAAU,iBAAiB,QAASQ,EAAiB,EAAI,CAAC,EAC1DP,EAAW,iBAAiB,QAASO,EAAiB,EAAK,CAAC,EAE5DD,EAAa,CACf,CAAC,CACH", "names": ["horizontalScroll", "container", "scrollableContent", "leftArrow", "rightArrow", "scrollItem", "itemWidth", "handleScroll", "event", "delta", "handleArrows", "handleArrowClick", "negative", "currentPosition", "maxScroll", "nextPosition"] }