{"version":3,"sources":["webpack:///./app/javascript/Slider.js","webpack:///./node_modules/throttle-debounce/esm/index.js"],"names":["scrollLeft","el","position","callback","a","steps","current","step","i","sleep","Slider","node","items","querySelector","sliderItemsArray","Array","from","querySelectorAll","length","sliderLeft","sliderRight","dotsArray","initialCurrent","classList","add","scrollToCurrent","getBoundingClientRect","left","offsetWidth","updateNavi","filter","forEach","toggleClass","scrollWidth","index","indexOf","remove","slideTo","slide","slidesPerPage","Math","max","floor","addEventListener","e","preventDefault","contains","createDelegator","delegateTarget","initialScroll","initialTouchX","lastTouchX","window","scrollTop","touches","clientX","diff","abs","onResize","throttle","removeEventListener","delay","noTrailing","debounceMode","timeoutID","cancelled","lastExec","clearExistingTimeout","clearTimeout","wrapper","_len","arguments","arguments_","_key","self","this","elapsed","Date","now","exec","apply","clear","undefined","setTimeout","cancel"],"mappings":"yfAIeA,E,wEAAf,WAA0BC,EAAIC,EAAUC,GAAxC,qBAAAC,EAAA,sDACQC,EAAQ,GACRC,EAAUL,EAAGD,WACbO,GAAQL,EAAWI,GAAWD,EAE3BG,EAAI,EALf,YAKkBA,EAAIH,GALtB,wBAMIJ,EAAGD,WAAaM,GAAWE,EAAI,GAAKD,EANxC,SAQUE,YAAM,IARhB,OAK6BD,IAL7B,uBAWEL,IAXF,6C,sBAce,SAASO,EAAOC,GAAO,IAAD,EAC7BC,EAAQD,EAAKE,cAAc,iBACjC,GAAKD,EAAL,CAEA,IAAME,EAAmBC,MAAMC,KAAKL,EAAKM,iBAAiB,iBAC1D,GAAgC,IAA5BH,EAAiBI,OAArB,CAEA,IAAMC,EAAaR,EAAKE,cAAc,gBAChCO,EAAcT,EAAKE,cAAc,iBAEjCQ,EAAYN,MAAMC,KAAKL,EAAKM,iBAAiB,gBAE7CK,EAAiBX,EAAKE,cAAc,yBAA2BF,EAAKE,cAAc,gBAC1E,OAAdS,QAAc,IAAdA,GAAA,UAAAA,EAAgBC,iBAAhB,SAA2BC,IAAI,uBAE/B,IAAMC,EAAkB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MuD,GAAOG,EAAO,EAAGA,EAAOH,EAAMG,IACrFD,EAAWC,GAAQF,UAAUE,GAG/B,IAAIC,EAAOC,KACPC,EAAUC,KAAKC,MAAQZ,EAO3B,SAASa,IACPb,EAAWW,KAAKC,MAChB3E,EAAS6E,MAAMN,EAAMF,GAQvB,SAASS,IACPjB,OAAYkB,EAhBVjB,IAmBAF,IAAiBC,GAKnBe,IAGFZ,SAEqBe,IAAjBnB,GAA8Ba,EAAUf,EAK1CkB,KACwB,IAAfjB,IAYTE,EAAYmB,WAAWpB,EAAekB,EAAQF,OAAuBG,IAAjBnB,EAA6BF,EAAQe,EAAUf,KAMvG,MAzE0B,mBAAfC,IACTC,EAAe5D,EACfA,EAAW2D,EACXA,OAAaoB,GAoEfb,EAAQe,OA7ER,WACEjB,IACAF,GAAY,GA6EPI,EAnHT","file":"js/Slider-759d6a7b2643b5091b4b.chunk.js","sourcesContent":["import { throttle } from \"throttle-debounce\"\nimport { createDelegator, toggleClass } from \"./domHelpers\"\nimport sleep from \"./sleep\"\n\nasync function scrollLeft(el, position, callback) {\n const steps = 10\n const current = el.scrollLeft\n const step = (position - current) / steps\n\n for (let i = 0; i < steps; i++) {\n el.scrollLeft = current + (i + 1) * step\n\n await sleep(20)\n }\n\n callback()\n}\n\nexport default function Slider(node) {\n const items = node.querySelector(\".slider-items\")\n if (!items) return\n\n const sliderItemsArray = Array.from(node.querySelectorAll(\".slider-item\"))\n if (sliderItemsArray.length === 0) return\n\n const sliderLeft = node.querySelector(\".slider-left\")\n const sliderRight = node.querySelector(\".slider-right\")\n\n const dotsArray = Array.from(node.querySelectorAll(\".slider-dot\"))\n\n const initialCurrent = node.querySelector(\".slider-item-current\") || node.querySelector(\".slider-item\")\n initialCurrent?.classList?.add(\"slider-item-current\")\n\n const scrollToCurrent = (callback = null) => {\n const current = node.querySelector(\".slider-item-current\")\n if (!current) return\n\n const position = items.scrollLeft + current.getBoundingClientRect().left + current.offsetWidth / 2 - items.offsetWidth / 2 - items.getBoundingClientRect().left\n\n callback ? scrollLeft(items, position, callback) : items.scrollLeft = position\n }\n\n const updateNavi = () => {\n [sliderLeft, sliderRight].filter((el) => el).forEach((el) => {\n toggleClass(el, \"is-hidden\", items.scrollWidth <= items.offsetWidth + 5)\n })\n\n if (sliderLeft) toggleClass(sliderLeft, \"is-disabled\", items.scrollLeft <= 5)\n if (sliderRight) toggleClass(sliderRight, \"is-disabled\", items.scrollLeft + items.offsetWidth >= items.scrollWidth - 5)\n\n const index = sliderItemsArray.indexOf(node.querySelector(\".slider-item-current\"))\n if (index < 0) return\n\n dotsArray.forEach((el) => el.classList.remove(\"is-current\"))\n dotsArray[index]?.classList?.add(\"is-current\")\n }\n\n node.slideTo = (slide) => {\n if (!sliderItemsArray[slide]) return\n\n sliderItemsArray.forEach((el) => el.classList.remove(\"slider-item-current\"))\n sliderItemsArray[slide].classList.add(\"slider-item-current\")\n\n scrollToCurrent(() => updateNavi())\n }\n\n const slidesPerPage = () => {\n return Math.max(1, initialCurrent.offsetWidth ? Math.floor(items.offsetWidth / initialCurrent.offsetWidth) : 0)\n }\n\n sliderLeft?.addEventListener(\"click\", (e) => {\n e.preventDefault()\n\n if (sliderLeft.classList.contains(\"is-disabled\")) return\n sliderLeft.classList.add(\"is-disabled\")\n\n node.slideTo(sliderItemsArray.indexOf(node.querySelector(\".slider-item-current\")) - slidesPerPage())\n })\n\n sliderRight?.addEventListener(\"click\", (e) => {\n e.preventDefault()\n\n if (sliderRight.classList.contains(\"is-disabled\")) return\n sliderRight.classList.add(\"is-disabled\")\n\n node.slideTo(sliderItemsArray.indexOf(node.querySelector(\".slider-item-current\")) + slidesPerPage())\n })\n\n node.addEventListener(\"click\", createDelegator(\".slider-dot\", (e) => {\n e.preventDefault()\n\n node.slideTo(dotsArray.indexOf(e.delegateTarget))\n }))\n\n let initialScroll = 0, initialWindowScroll = 0, initialTouchX = 0, lastTouchX = 0\n\n items.addEventListener(\"touchstart\", (e) => {\n initialScroll = items.scrollLeft\n initialWindowScroll = window.scrollTop\n initialTouchX = e.touches[0].clientX\n lastTouchX = e.touches[0].clientX\n })\n\n items.addEventListener(\"touchmove\", (e) => {\n lastTouchX = e.touches[0].clientX\n items.scrollLeft = initialScroll + initialTouchX - lastTouchX\n })\n\n items.addEventListener(\"touchend\", (e) => {\n const index = sliderItemsArray.indexOf(node.querySelector(\".slider-item-current\"))\n const diff = initialTouchX - lastTouchX\n\n Math.abs(diff) < 40 ? node.slideTo(index) : node.slideTo(diff > 0 ? index + 1 : index - 1)\n })\n\n const onResize = throttle(150, () => {\n scrollToCurrent()\n updateNavi()\n })\n\n window.addEventListener(\"resize\", onResize)\n\n scrollToCurrent()\n updateNavi()\n\n return () => {\n window.removeEventListener(\"resize\", onResize)\n }\n}\n","/* eslint-disable no-undefined,no-param-reassign,no-shadow */\n\n/**\n * Throttle execution of a function. Especially useful for rate limiting\n * execution of handlers on events like resize and scroll.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {boolean} [noTrailing] - Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the\n * throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time\n * after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,\n * the internal counter is reset).\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the throttled-function is executed.\n * @param {boolean} [debounceMode] - If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),\n * schedule `callback` to execute after `delay` ms.\n *\n * @returns {Function} A new, throttled, function.\n */\nfunction throttle(delay, noTrailing, callback, debounceMode) {\n /*\n * After wrapper has stopped being called, this timeout ensures that\n * `callback` is executed at the proper times in `throttle` and `end`\n * debounce modes.\n */\n var timeoutID;\n var cancelled = false; // Keep track of the last time `callback` was executed.\n\n var lastExec = 0; // Function to clear existing timeout\n\n function clearExistingTimeout() {\n if (timeoutID) {\n clearTimeout(timeoutID);\n }\n } // Function to cancel next exec\n\n\n function cancel() {\n clearExistingTimeout();\n cancelled = true;\n } // `noTrailing` defaults to falsy.\n\n\n if (typeof noTrailing !== 'boolean') {\n debounceMode = callback;\n callback = noTrailing;\n noTrailing = undefined;\n }\n /*\n * The `wrapper` function encapsulates all of the throttling / debouncing\n * functionality and when executed will limit the rate at which `callback`\n * is executed.\n */\n\n\n function wrapper() {\n for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {\n arguments_[_key] = arguments[_key];\n }\n\n var self = this;\n var elapsed = Date.now() - lastExec;\n\n if (cancelled) {\n return;\n } // Execute `callback` and update the `lastExec` timestamp.\n\n\n function exec() {\n lastExec = Date.now();\n callback.apply(self, arguments_);\n }\n /*\n * If `debounceMode` is true (at begin) this is used to clear the flag\n * to allow future `callback` executions.\n */\n\n\n function clear() {\n timeoutID = undefined;\n }\n\n if (debounceMode && !timeoutID) {\n /*\n * Since `wrapper` is being called for the first time and\n * `debounceMode` is true (at begin), execute `callback`.\n */\n exec();\n }\n\n clearExistingTimeout();\n\n if (debounceMode === undefined && elapsed > delay) {\n /*\n * In throttle mode, if `delay` time has been exceeded, execute\n * `callback`.\n */\n exec();\n } else if (noTrailing !== true) {\n /*\n * In trailing throttle mode, since `delay` time has not been\n * exceeded, schedule `callback` to execute `delay` ms after most\n * recent execution.\n *\n * If `debounceMode` is true (at begin), schedule `clear` to execute\n * after `delay` ms.\n *\n * If `debounceMode` is false (at end), schedule `callback` to\n * execute after `delay` ms.\n */\n timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);\n }\n }\n\n wrapper.cancel = cancel; // Return the wrapper function.\n\n return wrapper;\n}\n/* eslint-disable no-undefined */\n\n/**\n * Debounce execution of a function. Debouncing, unlike throttling,\n * guarantees that a function is only executed a single time, either at the\n * very beginning of a series of calls, or at the very end.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {boolean} [atBegin] - Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds\n * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.\n * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the debounced-function is executed.\n *\n * @returns {Function} A new, debounced function.\n */\n\n\nfunction debounce(delay, atBegin, callback) {\n return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false);\n}\n\nexport { debounce, throttle };"],"sourceRoot":""}