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