!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["react-horizontal-scrolling-menu"]={},e.React)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);const o="react-horizontal-scrolling-menu",l="-separator",i=`${o}-${l}`,a=`${o}--item`,s=`${o}--scroll-container`,u=`${o}--wrapper`,d=`${o}--inner-wrapper`,c=`${o}--header`,f=`${o}--arrow-left`,v=`${o}--arrow-right`,m=`${o}--footer`,h="itemId",g="itemClassName",p="data-key",b="data-index";var y=Object.freeze({__proto__:null,rootClassName:o,separatorString:l,separatorClassName:i,itemClassName:a,scrollContainerClassName:s,wrapperClassName:u,innerWrapperClassName:d,headerClassName:c,arrowLeftClassName:f,arrowRightClassName:v,footerClassName:m,id:h,customClassName:g,dataKeyAttribute:p,dataIndexAttribute:b});function E({className:e="",children:t,onScroll:n=(()=>{}),scrollRef:o}){const l=r.default.useMemo((()=>`${s} ${e}`),[e]);return r.default.createElement("div",{className:l,onScroll:n,ref:o},t)}var w=r.default.memo((function({className:e,id:t,index:n,refs:o}){const l=r.default.useRef(null);return o[n]=l,r.default.createElement("div",Object.assign({className:e},{[p]:t,[b]:n},{ref:l}))}));var C=r.default.memo((function({children:e,className:t,id:n,index:o,refs:l}){const i=r.default.useRef(null);return l[String(o)]=i,r.default.createElement("div",Object.assign({className:t},{[p]:n,[b]:o},{ref:i}),e)}));function I(e){return"object"==typeof e&&null!=e&&1===e.nodeType}function N(e,t){return(!t||"hidden"!==e)&&"visible"!==e&&"clip"!==e}function x(e,t){if(e.clientHeightt||l>e&&i=t&&a>=n?l-e-r:i>t&&an?i-t+o:0}var M,$=function(e,t){var n=window,r=t.scrollMode,o=t.block,l=t.inline,i=t.boundary,a=t.skipOverflowHiddenElements,s="function"==typeof i?i:function(e){return e!==i};if(!I(e))throw new TypeError("Invalid target");for(var u,d,c=document.scrollingElement||document.documentElement,f=[],v=e;I(v)&&s(v);){if((v=null==(d=(u=v).parentElement)?u.getRootNode().host||null:d)===c){f.push(v);break}null!=v&&v===document.body&&x(v)&&!x(document.documentElement)||null!=v&&x(v,a)&&f.push(v)}for(var m=n.visualViewport?n.visualViewport.width:innerWidth,h=n.visualViewport?n.visualViewport.height:innerHeight,g=window.scrollX||pageXOffset,p=window.scrollY||pageYOffset,b=e.getBoundingClientRect(),y=b.height,E=b.width,w=b.top,C=b.right,N=b.bottom,M=b.left,$="start"===o||"nearest"===o?w:"end"===o?N:w+y/2,W="center"===l?M+E/2:"end"===l?C:M,k=[],T=0;T=0&&M>=0&&N<=h&&C<=m&&w>=A&&N<=H&&M>=L&&C<=B)return k;var P=getComputedStyle(O),D=parseInt(P.borderLeftWidth,10),_=parseInt(P.borderTopWidth,10),F=parseInt(P.borderRightWidth,10),X=parseInt(P.borderBottomWidth,10),Y=0,q=0,z="offsetWidth"in O?O.offsetWidth-O.clientWidth-D-F:0,J="offsetHeight"in O?O.offsetHeight-O.clientHeight-_-X:0,U="offsetWidth"in O?0===O.offsetWidth?0:R/O.offsetWidth:0,K="offsetHeight"in O?0===O.offsetHeight?0:j/O.offsetHeight:0;if(c===O)Y="start"===o?$:"end"===o?$-h:"nearest"===o?S(p,p+h,h,_,X,p+$,p+$+y,y):$-h/2,q="start"===l?W:"center"===l?W-m/2:"end"===l?W-m:S(g,g+m,m,D,F,g+W,g+W+E,E),Y=Math.max(0,Y+p),q=Math.max(0,q+g);else{Y="start"===o?$-A-_:"end"===o?$-H+X+J:"nearest"===o?S(A,H,j,_,X+J,$,$+y,y):$-(A+j/2)+J/2,q="start"===l?W-L-D:"center"===l?W-(L+R/2)+z/2:"end"===l?W-B+F+z:S(L,B,R,D,F+z,W,W+E,E);var G=O.scrollLeft,Q=O.scrollTop;$+=Q-(Y=Math.max(0,Math.min(Q+Y/K,O.scrollHeight-j/K+J))),W+=G-(q=Math.max(0,Math.min(G+q/U,O.scrollWidth-R/U+z)))}k.push({el:O,top:Y,left:q})}return k};function W(e){return e===Object(e)&&0!==Object.keys(e).length}function k(e,t){var n=e.isConnected||e.ownerDocument.documentElement.contains(e);if(W(t)&&"function"==typeof t.behavior)return t.behavior(n?$(e,t):[]);if(n){var r=function(e){return!1===e?{block:"end",inline:"nearest"}:W(e)?e:{block:"start",inline:"nearest"}}(t);return function(e,t){void 0===t&&(t="auto");var n="scrollBehavior"in document.body.style;e.forEach((function(e){var r=e.el,o=e.top,l=e.left;r.scroll&&n?r.scroll({top:o,left:l,behavior:t}):(r.scrollTop=o,r.scrollLeft=l)}))}($(e,r),r.behavior)}}var T=function(){return M||(M="performance"in window?performance.now.bind(performance):Date.now),M()};function O(e){var t=T(),n=Math.min((t-e.startTime)/e.duration,1),r=e.ease(n),o=e.startX+(e.x-e.startX)*r,l=e.startY+(e.y-e.startY)*r;e.method(o,l),o!==e.x||l!==e.y?requestAnimationFrame((function(){return O(e)})):e.cb()}function V(e,t,n,r,o,l){var i,a,s,u;void 0===r&&(r=600),void 0===o&&(o=function(e){return 1+--e*e*e*e*e}),i=e,a=e.scrollLeft,s=e.scrollTop,u=function(t,n){e.scrollLeft=Math.ceil(t),e.scrollTop=Math.ceil(n)},O({scrollable:i,method:u,startTime:T(),startX:a,startY:s,x:t,y:n,duration:r,ease:o,cb:l})}var j=function(e){return e&&!e.behavior||"smooth"===e.behavior};var R=function(e,t){var n=t||{};return j(n)?k(e,{block:n.block,inline:n.inline,scrollMode:n.scrollMode,boundary:n.boundary,behavior:function(e){return Promise.all(e.reduce((function(e,t){var r=t.el,o=t.left,l=t.top,i=r.scrollLeft,a=r.scrollTop;return i===o&&a===l?e:[].concat(e,[new Promise((function(e){return V(r,o,l,n.duration,n.ease,(function(){return e({el:r,left:[i,o],top:[a,l]})}))}))])}),[]))}}):Promise.resolve(k(e,t))};const A=e=>Object.values(e).map((e=>e.current)).filter(Boolean);function B(e,t,n,r,o,l){var i;const a=(null===(i=null==e?void 0:e.entry)||void 0===i?void 0:i.target)||e,s=t||"smooth";if(a)return l?null==a?void 0:a.scrollIntoView({behavior:s,inline:n||"end",block:r||"nearest"}):R(a,Object.assign({behavior:s,inline:n||"end",block:r||"nearest",duration:500},o))}const H=(e,t)=>(t||document).querySelector(`[${p}='${e}']`),L=(e,t)=>(t||document).querySelector(`[${b}='${e}']`);function P(e){return r.default.isValidElement(e)&&e||"function"==typeof e&&r.default.createElement(e,null)||null}const D=e=>e.filter((e=>!new RegExp(`.*${l}$`).test(e))),_=e=>{var t;return String((null===(t=null==e?void 0:e.props)||void 0===t?void 0:t[h])||String((null==e?void 0:e.key)||"").replace(/^\.\$/,""))};function F({children:e,itemClassName:t="",refs:n,separatorClassName:o=""}){const s=r.default.Children.toArray(e).filter(Boolean),u=s.length,d=r.default.useMemo((()=>`${a} ${t}`),[t]),c=r.default.useMemo((()=>`${i} ${o}`),[o]);return r.default.createElement(r.default.Fragment,null,s.map(((e,t)=>{var o;const i=_(e),a=null===(o=null==e?void 0:e.props)||void 0===o?void 0:o[g],s=i+l,f=t+1===u,v=[d,a].filter(Boolean).join(" ");return[r.default.createElement(C,{className:v,id:i,key:"menuItem__"+i,refs:n,index:t},e),!f&&r.default.createElement(w,{className:c,id:s,refs:n,key:s,index:t+.1})]})))}const X="undefined"!=typeof window?r.default.useLayoutEffect:r.default.useEffect;function Y({items:e,itemsChanged:t,refs:n,options:o}){const l=r.default.useRef(),[i,a]=r.default.useState([]),s=r.default.useRef(+setTimeout((()=>{}),0)),u=r.default.useCallback((t=>{e.set(function(e,t){return[...e].map((e=>{var n,r,o,l;const i=e.target,a=String(null!==(r=null===(n=null==i?void 0:i.dataset)||void 0===n?void 0:n.key)&&void 0!==r?r:"");return[a,{index:String(null!==(l=null===(o=null==i?void 0:i.dataset)||void 0===o?void 0:o.index)&&void 0!==l?l:""),key:a,entry:e,visible:e.intersectionRatio>=t.ratio}]}))}(t,o)),clearTimeout(s.current),s.current=+setTimeout((()=>requestAnimationFrame((()=>{a((t=>{const n=e.getVisible().map((e=>e[1].key));return JSON.stringify(t)!==JSON.stringify(n)?n:t}))}))),o.throttle)}),[e,o]);return X((()=>{const e=A(n),t=l.current||new IntersectionObserver(u,o);return l.current=t,e.forEach((e=>t.observe(e))),()=>{clearTimeout(s.current),t.disconnect(),l.current=void 0}}),[u,t,o,n]),{visibleElementsWithSeparators:i}}const q=e=>r.default.Children.toArray(e).map(_).filter(Boolean);class z extends Map{toArr(){return this.sort([...this])}toItems(){return this.toArr().map((([e])=>e))}toItemsWithoutSeparators(){return D(this.toItems())}toItemsKeys(){return this.toItems()}sort(e){return e.sort((([,e],[,t])=>+e.index-+t.index))}set(e,t){return Array.isArray(e)?this.sort(e).forEach((([e,t])=>{super.set(String(e),t)})):super.set(String(e),t),this}first(){var e;return null===(e=this.toArr()[0])||void 0===e?void 0:e[1]}last(){var e,t;return null===(t=null===(e=this.toArr().slice(-1))||void 0===e?void 0:e[0])||void 0===t?void 0:t[1]}filter(e){return this.toArr().filter(e)}find(e){return this.toArr().find(e)}findIndex(e){return this.toArr().findIndex(e)}getCurrentPos(e,t){const n=this.toArr().filter((e=>{var n;return t?!(null===(n=null==e?void 0:e[0])||void 0===n?void 0:n.includes(l)):e})),r=n.findIndex((([t,n])=>t===e||n===e));return[n,r]}prev(e,t){var n;const[r,o]=this.getCurrentPos(e,!!t);return-1!==o?null===(n=r[o-1])||void 0===n?void 0:n[1]:void 0}next(e,t){var n;const[r,o]=this.getCurrentPos(e,!!t);return-1!==o?null===(n=r[o+1])||void 0===n?void 0:n[1]:void 0}getVisible(){return this.filter((e=>e[1].visible))}getVisibleElements(){return this.filter((e=>!e[0].includes(l)&&e[1].visible))}}const J={ratio:.9,rootMargin:"5px",threshold:[.05,.5,.75,.95],throttle:100};const U=r.default.createContext({}),K=e=>e.reduce(((e,t)=>e.concat(t).concat(`${t}${l}`)),[]).slice(0,-1);e.ScrollMenu=function({LeftArrow:e,RightArrow:t,children:n,Header:o,Footer:i,transitionDuration:a=500,transitionEase:s,transitionBehavior:h,onInit:g=(()=>{}),onUpdate:p=(()=>{}),onMouseDown:b,onMouseUp:y,onMouseMove:w,onScroll:C=(()=>{}),onTouchMove:I,onTouchStart:N,onTouchEnd:x,onWheel:S=(()=>{}),options:M=J,scrollContainerClassName:$="",itemClassName:W="",separatorClassName:k="",wrapperClassName:T="",apiRef:O={current:{}},RTL:V,noPolyfill:j}){const R=P(e),A=P(t),_=P(o),X=P(i),K=r.default.useRef(null),[G]=r.default.useState({}),Q=r.default.useMemo((()=>Object.assign(Object.assign(Object.assign({},J),M),{root:K.current})),[M,K.current]),Z=r.default.useRef(new z).current,ee=function(e,t){const[n,o]=r.default.useState(""),i=r.default.useMemo((()=>q(e)),[e]);return r.default.useEffect((()=>{const e=i.filter(Boolean).join("");t.toItemsWithoutSeparators().filter((e=>!i.includes(e))).forEach((e=>{var n,r;const o=(null===(n=t.last())||void 0===n?void 0:n.key)===e&&(null===(r=t.prev(e))||void 0===r?void 0:r.key)||"";t.delete(o),t.delete(`${e}${l}`),t.delete(e)})),o(e)}),[i,t]),n}(n,Z),{visibleElementsWithSeparators:te}=Y({items:Z,itemsChanged:ee,options:Q,refs:G}),ne=!!te.length,re=r.default.useMemo((()=>function(e,t=[],n,r,o,l){var i,a;const s=D(t),u=!!(null===(i=e.first())||void 0===i?void 0:i.visible),d=!!(null===(a=e.last())||void 0===a?void 0:a.visible),c=t=>{var n;return null===(n=e.find((e=>e[1].key===String(t))))||void 0===n?void 0:n[1]},f=()=>{var t,n;return e.prev(null===(n=null===(t=e.getVisible())||void 0===t?void 0:t[0])||void 0===n?void 0:n[1])},v=()=>{var t,n,r,o;return e.next(null===(o=null===(r=null===(n=null===(t=e.getVisible())||void 0===t?void 0:t.slice)||void 0===n?void 0:n.call(t,-1))||void 0===r?void 0:r[0])||void 0===o?void 0:o[1])};return{getItemById:c,getItemElementById:e=>H(e,null==n?void 0:n.current),getItemByIndex:t=>{var n;return null===(n=e.find((e=>String(e[1].index)===String(t))))||void 0===n?void 0:n[1]},getItemElementByIndex:e=>L(e,null==n?void 0:n.current),getNextItem:v,getNextElement:()=>{var t,n,r,o;return e.next(null===(o=null===(r=null===(n=null===(t=e.getVisibleElements())||void 0===t?void 0:t.slice)||void 0===n?void 0:n.call(t,-1))||void 0===r?void 0:r[0])||void 0===o?void 0:o[1],!0)},getPrevItem:f,getPrevElement:()=>{var t,n;return e.prev(null===(n=null===(t=e.getVisibleElements())||void 0===t?void 0:t[0])||void 0===n?void 0:n[1],!0)},isFirstItemVisible:u,isItemVisible:e=>s.includes(String(e)),isLastItem:t=>e.last()===c(t),isLastItemVisible:d,scrollNext:(e,t,i,{duration:a,ease:s,boundary:u=(null==n?void 0:n.current)}={})=>{const d=null!=e?e:null==r?void 0:r.behavior;return B(v(),d,t||"start",i||"nearest",{boundary:u,duration:null!=a?a:null==r?void 0:r.duration,ease:null!=s?s:null==r?void 0:r.ease},o||l)},scrollPrev:(e,t,i,{duration:a,ease:s,boundary:u=(null==n?void 0:n.current)}={})=>{const d=null!=e?e:null==r?void 0:r.behavior;return B(f(),d,t||"end",i||"nearest",{boundary:u,duration:null!=a?a:null==r?void 0:r.duration,ease:null!=s?s:null==r?void 0:r.ease},o||l)},scrollToItem:(e,t,o,l,i)=>{var a,s;return B(e,null!=t?t:null==r?void 0:r.behavior,o,l,Object.assign(Object.assign({boundary:null==n?void 0:n.current},i),{duration:null!==(a=null==i?void 0:i.duration)&&void 0!==a?a:null==r?void 0:r.duration,ease:null!==(s=null==i?void 0:i.ease)&&void 0!==s?s:null==r?void 0:r.ease}))},visibleElements:s,visibleElementsWithSeparators:t,visibleItems:t,visibleItemsWithoutSeparators:s}}(Z,te,K,{duration:a,ease:s,behavior:h},V,j)),[Z,te,ee,V,j]),oe=r.default.useCallback((()=>Object.assign(Object.assign({},re),{initComplete:ne,items:Z,visibleElementsWithSeparators:te,scrollContainer:K})),[re,ne,Z,te,K]),[le,ie]=r.default.useState(oe);!function({cb:e=(()=>{}),condition:t,hash:n}){r.default.useEffect((()=>{t&&e()}),[n,t])}({cb:()=>p(le),condition:function({cb:e,condition:t}){const[n,o]=r.default.useState(!1);return r.default.useEffect((()=>{t&&!n&&(o(!0),e())}),[t,n]),n}({cb:()=>g(le),condition:ne}),hash:JSON.stringify(te.concat(String(null==le?void 0:le.isFirstItemVisible)).concat(String(null==le?void 0:le.isLastItemVisible)))}),r.default.useEffect((()=>ie(oe())),[oe]),O.current=le;const ae=r.default.useCallback((e=>C(le,e)),[C,le]),se=r.default.useCallback((e=>S(le,e)),[S,le]),ue=r.default.useMemo((()=>`${u} ${T}`),[T]),de=r.default.useMemo((()=>`${$}${V?" rtl":""}`),[V,$]);return r.default.createElement("div",{className:ue,onWheel:se,onMouseDown:null==b?void 0:b(le),onMouseUp:null==y?void 0:y(le),onMouseMove:null==w?void 0:w(le),onTouchStart:null==N?void 0:N(le),onTouchMove:null==I?void 0:I(le),onTouchEnd:null==x?void 0:x(le)},r.default.createElement(U.Provider,{value:le},r.default.createElement("div",{className:c},_),r.default.createElement("div",{className:d},r.default.createElement("div",{className:f},R),r.default.createElement(E,{className:de,onScroll:ae,scrollRef:K},r.default.createElement(F,{refs:G,itemClassName:W,separatorClassName:k},n)),r.default.createElement("div",{className:v},A)),r.default.createElement("div",{className:m},X)))},e.VisibilityContext=U,e.constants=y,e.getItemsPos=e=>{var t;const n=(e=>e.filter(((e,t,n)=>{const r=0===t,o=t===n.length-1,i=new RegExp(l).test(e);return!((r||o)&&i)})))(e),r=n[Math.floor(n.length/2)];return{first:null==n?void 0:n[0],center:r,last:null===(t=n.slice(-1))||void 0===t?void 0:t[0]}},e.slidingWindow=function(e,t){const n=D(e),r=D(t);return{prev:()=>K(function(e,t){const n=e.findIndex((e=>e===(null==t?void 0:t[0]))),r=t.length,o=n-r,l=o<0,i=l?0:o,a=e.slice(i,l?r:n);return a.length===r?a:e.slice(n,r)}(n,r)),next:()=>K(function(e,t){const n=e.findIndex((e=>{var n;return e===(null===(n=t.slice(-1))||void 0===n?void 0:n[0])})),r=t.length,o=n+r+1,l=o>e.length-1,i=l?e.length-1:o,a=e.slice(l?i-r+1:n+1,i);return a.length===r?a:e.slice(e.length-r,e.length+r)}(n,r))}},Object.defineProperty(e,"__esModule",{value:!0})}));