morphing-scroll 2.5.1 → 2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");const t=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},r=({className:r,children:n,style:o,root:l,threshold:s,rootMargin:i,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),p=e.useMemo((()=>{if(!i)return"";const e=t(i);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[i]),h=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(h,{root:l,threshold:s,rootMargin:p});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[h,l,s,p]),e.createElement("div",{"intersection-tracker":"",className:r,ref:m,style:o},c||u?n:null)};r.displayName="IntersectionTracker";const n=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const s=e.useRef(null);e.useEffect((()=>{const e=s.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const i={width:"max-content",height:"max-content"},c={inner:Object.assign({},i),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},i)};return e.createElement("div",{"resize-tracker":"",className:t,ref:s,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};n.displayName="ResizeTracker";let o=1;const l=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:s,scrollBarEvent:i,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const p="sliderMenu"!==t?{onMouseDown:i,onTouchStart:i}:{},h=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",s="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{i(s*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,i,null==l?void 0:l.progressElement,m,d]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px",left:"50%"},n?{top:0,transform:"rotate(-90deg) translate(-100%, -50%)"}:{transform:"rotate(-90deg) translateY(-50%)"}):Object.assign({top:"50%",transform:"translateY(-50%)",height:o[1]+"px"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},p,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),h))};l.displayName="ScrollBar";var s=e.memo(l);const i=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};i.displayName="Edge";var c=e.memo(i);const a=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const s=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},s),onClick:()=>o(n)},r.element)};a.displayName="Arrow";var u=e.memo(a);function d(e,t){return e>t?Math.floor(e/t):1}function m(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const p=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},h=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function f(e,t,r=0,n=0){return o=>{var l,s,i,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(s=o.height)&&void 0!==s?s:0)-n};(null===(i=e.current)||void 0===i?void 0:i.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function g(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function y(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,s={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const i=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:s.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:s.y,o=e.scrollElementRef;if("thumb"===e.clicked){const s=e.objectsWrapperRef,i=getComputedStyle(s),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?o.clientWidth-e.scrollBarEdge[0]:o.clientHeight-e.scrollBarEdge[1],u="x"===t?s.clientWidth+parseFloat(i.marginLeft)+parseFloat(i.marginRight):s.clientHeight+parseFloat(i.marginTop)+parseFloat(i.marginBottom),d=a-e.thumbSize,m=u-c;if(0>=d||0>=m)return;const p=n*(m/d)+l.leftover,h=Math.trunc(p),f=p-h;e.prevCoordsRef.current.leftover=f,r=h}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=s[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],i="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&i>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?i(t):"wrapp"===e.clicked?"slider"===e.type?c(t):i(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function b(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}let v=0;const x={timeout:{tasks:[],timer:null},requestFrame:{tasks:[],rafId:null}},E={timeout:{scheduleNext(){const{tasks:e}=x.timeout;if(null!==x.timeout.timer&&(clearTimeout(x.timeout.timer),x.timeout.timer=null),0===e.length)return;const t=e[0],r=performance.now(),n=Math.max(0,t.runAt-r);x.timeout.timer=window.setTimeout((()=>{const t=performance.now(),r=[];for(;e.length&&e[0].runAt<=t;)r.push(e.shift());r.forEach((e=>e.callback())),E.timeout.scheduleNext()}),n)},clearAll(){null!==x.timeout.timer&&(clearTimeout(x.timeout.timer),x.timeout.timer=null),x.timeout.tasks=[]}},requestFrame:{scheduleNext(){const{tasks:e}=x.requestFrame;if(null!==x.requestFrame.rafId)return;if(0===e.length)return;const t=()=>{x.requestFrame.rafId=null;const r=performance.now(),n=[];for(;e.length&&e[0].runAt<=r;)n.push(e.shift());n.forEach((e=>e.callback())),e.length>0&&(x.requestFrame.rafId=requestAnimationFrame(t))};x.requestFrame.rafId=requestAnimationFrame(t)},clearAll(){null!==x.requestFrame.rafId&&(cancelAnimationFrame(x.requestFrame.rafId),x.requestFrame.rafId=null),x.requestFrame.tasks=[]}}},j=(e,t,r)=>{const n="task_"+v++,o="string"==typeof t?"requestFrame":"timeout";x[o].tasks=x[o].tasks.filter((e=>e.id!==n));const l="requestFrame"===o?performance.now():performance.now()+t,s={id:n,callback:e,runAt:l};let i=x[o].tasks.length;for(;i>0&&x[o].tasks[i-1].runAt>s.runAt;)i--;return x[o].tasks.splice(i,0,s),E[o].scheduleNext(),n},w="wrap-id";function O(e,t,r,n){if(!t)return 0;const o=Math.round(e/t*r);return!Number.isFinite(o)||n>o?n:o}const k=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},S=({className:r,children:l,type:i="scroll",direction:a="y",scrollPosition:v,onScrollValue:x,isScrolling:S,size:M,objectsSize:R,crossCount:A,gap:z,wrapperMargin:T,wrapperMinSize:C,wrapperAlign:F,elementsAlign:L,elementsDirection:N="row",edgeGradient:I,progressTrigger:q={wheel:!0},progressReverse:B=!1,scrollBarOnHover:$=!1,scrollBarEdge:W,thumbMinSize:X,render:Y,emptyElements:H,suspending:P=!1,fallback:D})=>{var K,_,V,U,G;const J=function(){const t=e.useRef(null);return null===t.current&&(t.current=""+o++),t.current}();if(!M)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${J}〉`);Object.keys(q).length;const[Q,Z]=e.useState(0),ee=()=>{Z((e=>"number"==typeof e&&1e3>e?e+1:0))},te=e.useRef(null),re=e.useRef(null),ne=e.useRef(null),oe=e.useRef(null),le=e.useRef([]),se=e.useRef(null),ie=e.useRef("none"),ce=e.useRef({loaded:[],empty:[]}),ae=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),ue=e.useRef(!1),de=e.useRef(0),me=e.useRef(null),pe=e.useRef(!1);function he(){return e.useRef({width:0,height:0})}const fe=he(),ge=he(),ye=he(),[be,ve,xe,Ee,je,we,Oe,ke,Se,Me,Re]=function(...e){return e.map(g)}(null==v?void 0:v.value,Y,M,R,H,C,F,z,q,ce.current.empty,W),Ae=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==v?void 0:v.value)||"string"==typeof(null==v?void 0:v.value)?[v.value,v.value]:null!==(e=null==v?void 0:v.value)&&void 0!==e?e:[null],duration:null!==(t=null==v?void 0:v.duration)&&void 0!==t?t:200}}),[be,null==v?void 0:v.duration]),ze={color:null,size:40},Te=e.useMemo((()=>"object"==typeof I?Object.assign(Object.assign({},ze),I):ze),[I]),Ce=e.useMemo((()=>Object.assign(Object.assign({},ze),"object"==typeof q.arrows?q.arrows:{})),[Se]),Fe=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Fe):[r]}return[t]}),[]),Le=e.useMemo((()=>e.Children.toArray(l).flatMap(Fe).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==H?void 0:H.mode)||!(null===(t=ce.current.empty)||void 0===t?void 0:t.includes(e))}))),[l,Fe,je,Me]),[Ne,Ie,qe,Be]=T?t(T):[0,0,0,0],$e=Ne+qe,We=Be+Ie,[Xe,Ye]=e.useMemo((()=>{var e,t;return"number"==typeof z?[z,z]:Array.isArray(z)?[null!==(e=z[1])&&void 0!==e?e:0,null!==(t=z[0])&&void 0!==t?t:0]:[0,0]}),[z]),He=e.useMemo((()=>t((null==Y?void 0:Y.rootMargin)||0,"x"===a)),[ve,a]),[Pe,De]=He?[He[2],He[0]]:[0,0],Ke=e.useMemo((()=>{const[e,t]=Array.isArray(M)?M:"number"==typeof M?[M,M]:[fe.current.width,fe.current.height];if(!q.arrows||!Ce.size)return[e,t,e,t];const r=2*Ce.size;let n=e,o=t;return"x"===a?n=e-r:"y"===a?o=t-r:"hybrid"===a&&(n=e-r,o=t-r),[n,o,e,t]}),[xe,Se,a,Ce.size,fe.current.height,fe.current.width]),_e="x"===a?Ke[0]:Ke[1],Ve=e.useMemo((()=>{if(!W)return[0,0];if("number"==typeof W){const e=2*W;return[e,e]}if(Array.isArray(W)){const[e=0,t]=W;return[2*e,2*(null!=t?t:e)]}return[0,0]}),[Re]),Ue="x"===a?Ve[0]:Ve[1],Ge=e.useMemo((()=>[Ke[0]-Ve[0],Ke[1]-Ve[1]]),[Ve.join(),Ke[0],Ke[1]]),Je="x"===a?Ge[0]:Ge[1],Qe=e.useMemo((()=>R?Array.isArray(R)?R:t(R,!0,2):[null,null]),[Ee]),Ze=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(Qe[0]&&"none"!==Qe[0]&&"size"!==Qe[0]?Qe[0]:"y"===a&&"none"!==Qe[0]||"size"===Qe[0]?Ke[0]:0,ye.current.width),e(Qe[1]&&"none"!==Qe[1]&&"size"!==Qe[1]?Qe[1]:"x"===a&&"none"!==Qe[1]||"size"===Qe[1]?Ke[1]:0,ye.current.height)]}),[Qe.join(),a,ye.current.width,ye.current.height,Ke.join()]),et=e.useMemo((()=>{const e="x"===a,t="row"===N,r="column"===N,n=e?Ke[1]:Ke[0],o=e?Ze[1]+Ye:Ze[0]+Xe,l="hybrid"===a?o*(Le.length+1)-o:n,s=Math.floor(l/o)||1,i=A&&s>=A?"hybrid"===a?Math.ceil(s/A):A:s,c=i>1&&i<Le.length?Math.ceil(Le.length/i):i>Le.length?1:Le.length,u=A&&A<Le.length,d=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===a){const e=u?t?A:i:t?Le.length:1,n=u?r?A:i:r?Le.length:1;return[d(e),d(n)]}return[d(i),d(c)]}),[N,Ye,Xe,Ze.join(),Le.length,a,Ke.join(),A]),tt=e.useMemo((()=>{const e=et[0]?et[0]*Ye-Ye:0,t="x"===a?et[1]:et[0];return Ze[0]?(Ze[0]+Ye)*t-Ye:(null==Y?void 0:Y.type)?ye.current.width+e:ge.current.width}),[a,Ze[0],et.join(),Ye,ge.current.width,ye.current.width,null==Y?void 0:Y.type]),rt=e.useMemo((()=>{const e=1>et[1]?1:et[0]*Xe-Xe;return Ze[1]?"x"===a?(Ze[1]+Xe)*et[0]-Xe:(Ze[1]+Xe)*et[1]-Xe:(null==Y?void 0:Y.type)?ye.current.height+e:ge.current.height}),[a,Ze[1],et.join(),Xe,ge.current.height,ye.current.height,null==Y?void 0:Y.type]),nt=e.useMemo((()=>rt+$e),[rt,$e]),ot=e.useMemo((()=>tt+We),[tt,We]),lt="x"===a?ot:nt,st="x"===a?(null===(K=ne.current)||void 0===K?void 0:K.scrollLeft)||0:(null===(_=ne.current)||void 0===_?void 0:_.scrollTop)||0,it=st>1&&!0,ct=lt>Math.round(st+_e);let at=!1,ut=!1;"hybrid"===a&&(at=((null===(V=ne.current)||void 0===V?void 0:V.scrollLeft)||0)>1&&!0,ut=Math.round(((null===(U=ne.current)||void 0===U?void 0:U.scrollLeft)||0)+Ke[0])<ot);const dt=e.useMemo((()=>null!=X?X:30),[X]),mt=e.useMemo((()=>q.progressElement&&lt?O(Je,lt,Je,dt):0),[Je,lt,q.progressElement,dt]),pt=e.useMemo((()=>q.progressElement?O(Ge[0],ot,Ge[0],dt):0),[Ge[0],ot,q.progressElement,dt]),ht=e.useMemo((()=>_e?lt-_e:lt),[lt,_e]),ft=e.useMemo((()=>Ke[0]?ot-Ke[0]:ot),[ot,Ke[0]]),gt=e.useCallback((()=>{if(!(null==Y?void 0:Y.type)||1>=et[0])return[];const e=Array.from({length:Le.length},((e,t)=>t)),t=Array.from({length:et[0]},(()=>[])),r="x"===a&&"column"===N||"x"!==a&&"row"===N;return e.forEach((e=>{const n=r?e%et[0]:Math.floor(e/et[1]);t[n]&&t[n].push(e)})),t}),[Le.length,et.join(),null==Y?void 0:Y.type,N,a]),yt=e.useMemo((()=>{if(!(null==Y?void 0:Y.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if(L){const r=Array.from({length:Le.length},((e,t)=>t)),n=Math.abs(Math.floor(Le.length/et[0])*et[0]-Le.length);e=n?r.slice(-n):[],"center"===L?t=(Ze[0]+Ye)*(et[0]-n)/2:"end"===L&&(t=(Ze[0]+Ye)*(et[0]-n))}return Le.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===a?n:r,["hybrid","y"].includes(a)?n:r]}return[0,0]}(n,gt()),l=e.length>0&&e.includes(n)?t:0,s=function(e){const t="x"===a?l:0;return e>0?t+(Ze[1]+Xe)*e:t}(et[0]>1||["hybrid","x"].includes(a)?o[1]:n),i=Ze[1]?s+Ze[1]:s,c=function(e){const t="x"===a?0:l;return e>0?t+(Ze[0]+Ye)*e:t}(1===et[0]&&"x"===a?n:o[0]);return{elementTop:s,elementBottom:i,left:c,right:c+Ze[0]}}))}),[a,et[0],Ze.join(),Xe,Ye,null==Y?void 0:Y.type,N,L,gt,Le.join()]),bt=e.useMemo((()=>(null==Ke?void 0:Ke.length)&&F?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,s={display:"flex"};return t[0]>r&&(s.justifyContent=h(o)),t[1]>n&&(s.alignItems=h(l)),s}(F,Ke,ot,nt):{}),[F,Ke.join(),nt,ot]),vt=e.useMemo((()=>[d(ot,Ke[0]),d(nt,Ke[1])]),[ot,nt,Ke.join()]),xt=e.useMemo((()=>"x"===a?vt[0]:vt[1]),[a,vt[0],vt[1]]),Et=e.useCallback(f(fe,ee),[fe.current.height,fe.current.width]),jt=e.useCallback(f(ge,ee,We,$e),[ge.current.height,ge.current.width,We,$e]),wt=e.useCallback(f(ye,ee),[ye.current.height,ye.current.width]),Ot=e.useCallback(((e,t,r,n)=>{const o=ne.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const s=performance.now(),i=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-s)/r,1);"y"===e?t.scrollTop=i+(n-i)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[]),kt=e.useCallback(((e,t,r)=>{if(se.current){if(se.current!==Le[0])return void(se.current=Le[0])}else se.current=Le[0];const n=Ot(t,e,Ae.duration);n&&r.push(n)}),[Le[0],Ae.duration,Ot]),St=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:T?`${Ne}px ${Ie}px ${qe}px ${Be}px`:"",height:Qe[1]&&"none"!==Qe[1]?rt+"px":"fit-content",width:Qe[0]&&"none"!==Qe[0]?tt+"px":"fit-content"},q.content&&{cursor:"grab"}),z&&!(null==Y?void 0:Y.type)&&{gap:`${Xe}px ${Ye}px`}),C&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let s,i;return Array.isArray(e)?[s,i]=e:s=i=e,{minWidth:l(s,"x")+"px",minHeight:l(i,"y")+"px"}}(C,a,Ke,We,$e)),F&&{flexShrink:0});if(null==Y?void 0:Y.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=Qe[1]?"wrap":void 0,r=1===et[0]?"y"===a?"column":"row":N;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:h(L)})}),[T,Oe,we,[Ne,Ie,qe,Be,We,$e,Xe,Ye].join(),Ke.join(),ke,Qe[1],rt,tt,q.content,ke,null==Y?void 0:Y.type,a,et[0],N,L]),Mt=e.useCallback((e=>{if(!$)return;const t=()=>((e,t,r)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const n=e;["mouseleave","mouseup","touchend"].includes(r.type)?(n.style.opacity="0",n.classList.remove("hover"),n.classList.add("leave"),j((()=>n.classList.remove("leave")),200)):(n.style.opacity="1",n.classList.add("hover"))}))})(re.current,0,e);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ie.current)&&t():t()}),[$]),Rt=e.useCallback(((e,t="mousedown",r)=>{const n=e||("scroll"===i?"thumb":"slider");if("wrapp"===e&&!q.content||["thumb","slider"].includes(n)&&!q.progressElement)return;p(i,te.current,le);let o=null;r&&(o=r.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>y(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),y(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:t,scrollElementRef:ne.current,objectsWrapperRef:oe.current,scrollBar:r||null,clickedObject:ie,scrollContentRef:re.current,scrollStateRef:ae.current,type:i,scrollBarOnHover:$,mouseOnEl:k,mouseOnRefHandle:Mt,triggerUpdate:ee,direction:a,smoothScroll:Ot,sizeLocal:[Ke[0],Ke[1]],clicked:n,numForSliderRef:de,isScrollingRef:ue,prevCoordsRef:me,thumbSize:"x"===o?pt:mt,axisFromAtr:o,duration:Ae.duration,scrollBarEdge:Ve})}),[a,i,q.content,q.progressElement,Ke.join(),mt,pt,Ae.duration,Ot,Mt,$,Ve.join()]),At=e.useCallback((e=>{Rt(null,e.type,e.target)}),[Rt]),zt=e.useCallback((()=>{Rt("wrapp")}),[Rt]),Tt=e.useCallback((e=>{ne.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const s=r[0],i=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?i:s,d=(e,t)=>o(m(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==i?d(c+n[1],"y"):"right"===e&&a+n[0]!==s&&d(a+n[0],"x")})({arrowType:e,scrollElement:ne.current,wrapSize:[ot,nt],scrollSize:Ke,smoothScroll:Ot,duration:Ae.duration})}),[Ke.join(),ot,nt,Ae.duration,Ot]),Ct=e.useCallback((()=>{p(i,te.current,le);const e=ne.current;re.current&&e&&0!==le.current.length&&((e,t,r,n)=>{!function(){var o,l,s,i;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(i=null===(s=t[1])||void 0===s?void 0:s.querySelectorAll(".ms-slider-element"))&&void 0!==i?i:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,le.current,Ke,a)}),[Ke.join(),a,ne,re,i]),Ft=e.useCallback((()=>{te.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(w)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(w);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),s=new Set(t.current.loaded);o.forEach((e=>s.add(e)));let i=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),i=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(s):o.map((e=>e)),empty:i},r()})(te.current,ce,ee,null==Y?void 0:Y.type)}),[ve]),Lt=e.useCallback((e=>{(null==H?void 0:H.clickTrigger)&&((e,t,r)=>{const n=e.target;if(!n.closest(t.selector))return;const o=n.closest(`[${w}]`);o&&o.classList.add("remove"),j((()=>{o&&o.classList.remove("remove"),r()}),t.delay||0)})(e,H.clickTrigger,Ft)}),[je,Ft]),Nt=e.useCallback((()=>{j((()=>{const e=ne.current;e&&(null==x||x(e.scrollLeft,e.scrollTop),ue.current=!0,null==S||S(!0),j((()=>{ue.current=!1,null==S||S(!1),Ft()}),200),"slider"===i&&j((()=>Ct()),33),ee())}),6)}),[x,S,i,Ct,Ft]),It=m(st/ht*(Je-mt),0,Je-mt),qt=m(((null===(G=ne.current)||void 0===G?void 0:G.scrollLeft)||0)/ft*(Ge[0]-Ge[0]/ot*Ge[0]),0,Ge[0]-pt),Bt=e.useCallback((e=>{const t="object"==typeof q.wheel&&"string"==typeof q.wheel.changeDirectionKey?q.wheel.changeDirectionKey:"KeyX";e.code!==t||"hybrid"!==a||pe.current||(e.stopPropagation(),pe.current=!0,ee())}),[a,JSON.stringify(q.wheel)]),$t=e.useCallback((e=>{pe.current&&(e.stopPropagation(),pe.current=!1,ee())}),[]);e.useEffect((()=>{(H||(null==Y?void 0:Y.type))&&(H||null===ce.current.empty||(ce.current.empty=null),Ft())}),[je,null==Y?void 0:Y.type,Ft]),e.useEffect((()=>{const e=ae.current.animationFrameId;return((null==Y?void 0:Y.type)||S)&&S&&(S(!1),ee()),Ct(),()=>{e&&cancelAnimationFrame(e),["timeout"].forEach((e=>E[e].clearAll()))}}),[]),e.useEffect((()=>{const e=ne.current;if(!e)return;const t=e=>e.preventDefault(),r="hybrid"===a&&"object"==typeof q.wheel&&q.wheel.changeDirection?"x":a,n="hybrid"===a&&rt+$e<=Ke[1]||pe.current?["hybrid","y"].includes(r)?"x":"y":r,o=q.wheel?e=>{t(e),function(e,t,r){const n=e.target.closest(".ms-element");n.matches(":focus")||n.focus(),t.animating||(t.targetScrollX=n.scrollLeft,t.targetScrollY=n.scrollTop),"x"===r?t.targetScrollX=m(t.targetScrollX+e.deltaY,0,n.scrollWidth-n.clientWidth+2):t.targetScrollY=m(t.targetScrollY+e.deltaY,0,n.scrollHeight-n.clientHeight+2),t.animating||(t.animating=!0,t.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===r?(n.scrollLeft+=.4*(t.targetScrollX-n.scrollLeft),o=Math.abs(n.scrollLeft-t.targetScrollX)):(n.scrollTop+=.4*(t.targetScrollY-n.scrollTop),o=Math.abs(n.scrollTop-t.targetScrollY)),o>2.5?t.animationFrameId=requestAnimationFrame(e):(t.animating=!1,null!==t.animationFrameId&&(cancelAnimationFrame(t.animationFrameId),t.animationFrameId=null))})))}(e,ae.current,n)}:t;return e.addEventListener("wheel",o,{passive:!1}),()=>{e.removeEventListener("wheel",o)}}),[a,JSON.stringify(q.wheel),rt,Ke[1],$e,pe.current]),e.useEffect((()=>{if(!Ae.value)return;const e=[];return("hybrid"===a?["x","y"]:[a]).forEach((t=>{const r="x"===t?0:1;"end"===Ae.value[r]&&kt(t,"x"===t?ft:ht,e)})),()=>{e.forEach((e=>e()))}}),[a,Ae.value.join(),be,ht,ft,ot,nt]),e.useEffect((()=>{if(!Ae.value)return;const e=[];return("hybrid"===a?["x","y"]:[a]).forEach((t=>{const r="x"===t?0:1;"number"==typeof Ae.value[r]&&kt(t,Ae.value[r],e)})),()=>{e.forEach((e=>e()))}}),[be,null==v?void 0:v.updater,a,kt,Ae.value.join()]);const Wt=e.useCallback(((t,r,n,o)=>{var l;const s=Object.assign({width:Ze[0]?Ze[0]+"px":void 0,height:Ze[1]?Ze[1]+"px":void 0},(null==Y?void 0:Y.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!Ze[0]&&1===et[0]&&{transform:"translateX(-50%)"})),i=P?e.createElement(e.Suspense,{fallback:D},o):o,c=(null===(l=null==H?void 0:H.clickTrigger)||void 0===l?void 0:l.selector)&&Lt;return e.createElement("div",Object.assign({key:t},Y||H?{[w]:""+t}:{},{className:"ms-object-box",style:s,onClick:c}),i)}),[P,!!D,Ze.join(),ve,je,et[0],Lt]),Xt=e.useMemo((()=>[{positionType:"x"===a?"left":"top",visibility:it},{positionType:"x"===a?"right":"bottom",visibility:ct},..."hybrid"===a?[{positionType:"left",visibility:at},{positionType:"right",visibility:ut}]:[]]),[it,ct,a,at,ut]),Yt=e.useMemo((()=>({width:Ke[2]+"px",height:Ke[3]+"px"})),[Ke]),Ht=e.useMemo((()=>[{shouldRender:lt-Ue>mt,direction:a,thumbSize:mt,thumbSpace:It,objLengthPerSize:xt,progressReverseIndex:0},{shouldRender:"hybrid"===a&&pt<ot-Ve[0],direction:"x",thumbSize:pt,thumbSpace:qt,objLengthPerSize:vt[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e))),[mt,lt,Ue,a,pt,ot,Ve[0],It,qt,xt,vt]),Pt=e.useMemo((()=>{const e={position:"relative",width:Ke[0]+"px",height:Ke[1]+"px"};return q.arrows&&Ce.size&&("x"===a?e.left=Ce.size+"px":"y"===a?e.top=Ce.size+"px":(e.top=Ce.size+"px",e.left=Ce.size+"px")),e}),[Ke,Se,Ce.size,a]),Dt=e.useMemo((()=>{var e;return null!==(e={x:ot>Ke[0]?"scroll hidden":"hidden",y:nt>Ke[1]?"hidden scroll":"hidden",hybrid:`${ot>Ke[0]?"scroll":"hidden"} ${nt>Ke[1]?"scroll":"hidden"}`,hide:"hidden"}[q.wheel||q.content?a:"hide"])&&void 0!==e?e:"hidden"}),[ot,nt,Ke[0],Ke[1],Se,a]),Kt=e.useMemo((()=>I?Xt.map((({positionType:t,visibility:r})=>e.createElement(c,{key:"edge-"+t,edgeGradient:Te,visibility:r,edgeType:t}))):null),[I,Xt,Te]),_t=e.useMemo((()=>q.arrows?Xt.map((({positionType:t,visibility:r})=>e.createElement(u,{key:"arrow-"+t,activity:r,arrows:Ce,arrowType:t,handleArrow:Tt,size:"hybrid"===a?Ke[0]+2*Ce.size:Ke[0]}))):null),[q.arrows,Xt,Ce,Tt,Ke[0],a]),Vt=e.useMemo((()=>q.progressElement&&!0!==q.progressElement?Ht.map((t=>{const r="boolean"==typeof B?B:B[t.progressReverseIndex];return e.createElement(s,{key:t.direction+"",type:i,direction:t.direction,progressReverse:r,size:Ge,progressTrigger:q,scrollBarOnHover:$,scrollBarEvent:"sliderMenu"===i?Ot:At,thumbSize:t.thumbSize,thumbSpace:t.thumbSpace,objLengthPerSize:t.objLengthPerSize,sliderCheckLocal:Ct,duration:Ae.duration})})):null),[q.progressElement,Ht,i,B,Ge,q,$,Ot,At,Ct,Ae.duration]),Ut=e.createElement("div",{className:"ms-objects-wrapper",ref:oe,onMouseDown:zt,style:St},Le.map(((t,r)=>{var o,s,i;const c=e.Children.toArray(l).find((r=>e.isValidElement(r)&&r.key===t)),u=(null==Y?void 0:Y.stopLoadOnScroll)&&ue.current&&!ce.current.loaded.includes(""+t)?D:(null===(o=ce.current.empty)||void 0===o?void 0:o.includes(t))?"object"==typeof(null==H?void 0:H.mode)?H.mode.fallback:D:c,d="number"==typeof Qe[0]&&"number"==typeof Qe[1]||"firstChild"!==Qe[0]&&"firstChild"!==Qe[1]||0!==r?u:e.createElement(n,{onResize:wt},u);if(!(null==Y?void 0:Y.type))return Wt(t,0,0,d);{const{elementTop:e,elementBottom:n,left:o,right:l}=yt[r],c="x"===a?Pe:De,u=_e+c>("x"===a?o:e)-st&&("x"===a?l:n)-st>0-c,m="hybrid"!==a||Ke[0]+Pe>o-((null===(s=ne.current)||void 0===s?void 0:s.scrollLeft)||0)&&l-((null===(i=ne.current)||void 0===i?void 0:i.scrollLeft)||0)>0-Pe;if(u&&m)return Wt(t,e,o,d)}}))),Gt=e.createElement("div",{"morph-scroll":`〈♦${J}〉`,className:r,ref:te,style:Yt},e.createElement("div",{className:"ms-content",ref:re,onMouseEnter:Mt,onMouseLeave:Mt,onTouchStart:Mt,onTouchEnd:Mt,style:Pt},e.createElement("div",{className:"ms-element",ref:ne,onScroll:Nt,onKeyDown:Bt,onKeyUp:$t,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%",outline:"none"},bt),{overflow:Dt}),"scroll"!==i||"boolean"!=typeof q.progressElement||!1===q.progressElement?{scrollbarWidth:"none"}:{})},Ze[0]&&Ze[1]?Ut:e.createElement(n,{onResize:jt,style:bt},Ut)),Kt,Vt),_t);return"auto"===M?e.createElement(n,{measure:"outer",onResize:Et},Gt):Gt};S.displayName="MorphScroll";const M={MorphScroll:S,ResizeTracker:n,IntersectionTracker:r};exports.IntersectionTracker=r,exports.MorphScroll=S,exports.ResizeTracker=n,exports.default=M;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");const t=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},r=({className:r,children:n,style:o,root:l,threshold:s,rootMargin:i,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),h=e.useMemo((()=>{if(!i)return"";const e=t(i);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[i]),p=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(p,{root:l,threshold:s,rootMargin:h});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[p,l,s,h]),e.createElement("div",{"intersection-tracker":"",className:r,ref:m,style:o},c||u?n:null)};r.displayName="IntersectionTracker";const n=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const s=e.useRef(null);e.useEffect((()=>{const e=s.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const i={width:"max-content",height:"max-content"},c={inner:Object.assign({},i),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},i)};return e.createElement("div",{"resize-tracker":"",className:t,ref:s,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};n.displayName="ResizeTracker";let o=1;const l=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:s,scrollBarEvent:i,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const h="sliderMenu"!==t?{onMouseDown:i,onTouchStart:i}:{},p=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",s="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{i(s*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,i,null==l?void 0:l.progressElement,m,d]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px",left:"50%"},n?{top:0,transform:"rotate(-90deg) translate(-100%, -50%)"}:{transform:"rotate(-90deg) translateY(-50%)"}):Object.assign({top:"50%",transform:"translateY(-50%)",height:o[1]+"px"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},h,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},h,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),p))};l.displayName="ScrollBar";var s=e.memo(l);const i=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};i.displayName="Edge";var c=e.memo(i);const a=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const s=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},s),onClick:()=>o(n)},r.element)};a.displayName="Arrow";var u=e.memo(a);function d(e,t){return e>t?Math.floor(e/t):1}function m(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const h=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},p=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function f(e,t,r=0,n=0){return o=>{var l,s,i,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(s=o.height)&&void 0!==s?s:0)-n};(null===(i=e.current)||void 0===i?void 0:i.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function g(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function y(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,s={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const i=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:s.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:s.y,o=e.scrollElementRef;if("thumb"===e.clicked){const s=e.objectsWrapperRef,i=getComputedStyle(s),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?o.clientWidth-e.scrollBarEdge[0]:o.clientHeight-e.scrollBarEdge[1],u="x"===t?s.clientWidth+parseFloat(i.marginLeft)+parseFloat(i.marginRight):s.clientHeight+parseFloat(i.marginTop)+parseFloat(i.marginBottom),d=a-e.thumbSize,m=u-c;if(0>=d||0>=m)return;const h=n*(m/d)+l.leftover,p=Math.trunc(h),f=h-p;e.prevCoordsRef.current.leftover=f,r=p}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=s[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],i="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&i>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?i(t):"wrapp"===e.clicked?"slider"===e.type?c(t):i(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function b(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}let v=0;const x={timeout:{tasks:[],timer:null},requestFrame:{tasks:[],rafId:null}},E={timeout:{scheduleNext(){const{tasks:e}=x.timeout;if(null!==x.timeout.timer&&(clearTimeout(x.timeout.timer),x.timeout.timer=null),0===e.length)return;const t=e[0],r=performance.now(),n=Math.max(0,t.runAt-r);x.timeout.timer=window.setTimeout((()=>{const t=performance.now(),r=[];for(;e.length&&e[0].runAt<=t;)r.push(e.shift());r.forEach((e=>e.callback())),E.timeout.scheduleNext()}),n)},clearAll(){null!==x.timeout.timer&&(clearTimeout(x.timeout.timer),x.timeout.timer=null),x.timeout.tasks=[]}},requestFrame:{scheduleNext(){const{tasks:e}=x.requestFrame;if(null!==x.requestFrame.rafId)return;if(0===e.length)return;const t=()=>{x.requestFrame.rafId=null;const r=performance.now(),n=[];for(;e.length&&e[0].runAt<=r;)n.push(e.shift());n.forEach((e=>e.callback())),e.length>0&&(x.requestFrame.rafId=requestAnimationFrame(t))};x.requestFrame.rafId=requestAnimationFrame(t)},clearAll(){null!==x.requestFrame.rafId&&(cancelAnimationFrame(x.requestFrame.rafId),x.requestFrame.rafId=null),x.requestFrame.tasks=[]}}},j=(e,t,r)=>{const n="task_"+v++,o="string"==typeof t?"requestFrame":"timeout";x[o].tasks=x[o].tasks.filter((e=>e.id!==n));const l="requestFrame"===o?performance.now():performance.now()+t,s={id:n,callback:e,runAt:l};let i=x[o].tasks.length;for(;i>0&&x[o].tasks[i-1].runAt>s.runAt;)i--;return x[o].tasks.splice(i,0,s),E[o].scheduleNext(),n},w="wrap-id";function O(e,t,r){return t?m(Math.round(e/t*e),r,e):0}function k(e,t,r,n){return t?m(e/t*(r-n),0,r-n):0}const S=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},R=({className:r,children:l,type:i="scroll",direction:a="y",scrollPosition:v,onScrollValue:x,isScrolling:R,size:M,objectsSize:A,crossCount:z,gap:T,wrapperMargin:C,wrapperMinSize:L,wrapperAlign:F,elementsAlign:N,elementsDirection:I="row",edgeGradient:q,progressTrigger:B={wheel:!0},progressReverse:$=!1,scrollBarOnHover:W=!1,scrollBarEdge:X,thumbMinSize:Y,render:H,emptyElements:P,suspending:D=!1,fallback:K})=>{var _,V,U,G,J;const Q=function(){const t=e.useRef(null);return null===t.current&&(t.current=""+o++),t.current}();if(!M)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${Q}〉`);Object.keys(B).length;const[Z,ee]=e.useState(0),te=()=>{ee((e=>"number"==typeof e&&1e3>e?e+1:0))},re=e.useRef(null),ne=e.useRef(null),oe=e.useRef(null),le=e.useRef(null),se=e.useRef([]),ie=e.useRef(null),ce=e.useRef("none"),ae=e.useRef({loaded:[],empty:[]}),ue=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),de=e.useRef(!1),me=e.useRef(0),he=e.useRef(null),pe=e.useRef(!1);function fe(){return e.useRef({width:0,height:0})}const ge=fe(),ye=fe(),be=fe(),[ve,xe,Ee,je,we,Oe,ke,Se,Re,Me,Ae]=function(...e){return e.map(g)}(null==v?void 0:v.value,H,M,A,P,L,F,T,B,ae.current.empty,X),ze=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==v?void 0:v.value)||"string"==typeof(null==v?void 0:v.value)?[v.value,v.value]:null!==(e=null==v?void 0:v.value)&&void 0!==e?e:[null],duration:null!==(t=null==v?void 0:v.duration)&&void 0!==t?t:200}}),[ve,null==v?void 0:v.duration]),Te={color:null,size:40},Ce=e.useMemo((()=>"object"==typeof q?Object.assign(Object.assign({},Te),q):Te),[q]),Le=e.useMemo((()=>Object.assign(Object.assign({},Te),"object"==typeof B.arrows?B.arrows:{})),[Re]),Fe=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Fe):[r]}return[t]}),[]),Ne=e.useMemo((()=>e.Children.toArray(l).flatMap(Fe).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==P?void 0:P.mode)||!(null===(t=ae.current.empty)||void 0===t?void 0:t.includes(e))}))),[l,Fe,we,Me]),[Ie,qe,Be,$e]=C?t(C):[0,0,0,0],We=Ie+Be,Xe=$e+qe,[Ye,He]=e.useMemo((()=>{var e,t;return"number"==typeof T?[T,T]:Array.isArray(T)?[null!==(e=T[1])&&void 0!==e?e:0,null!==(t=T[0])&&void 0!==t?t:0]:[0,0]}),[T]),Pe=e.useMemo((()=>t((null==H?void 0:H.rootMargin)||0,"x"===a)),[xe,a]),[De,Ke]=Pe?[Pe[2],Pe[0]]:[0,0],_e=e.useMemo((()=>{const[e,t]=Array.isArray(M)?M:"number"==typeof M?[M,M]:[ge.current.width,ge.current.height];if(!B.arrows||!Le.size)return[e,t,e,t];const r=2*Le.size;let n=e,o=t;return"x"===a?n=e-r:"y"===a?o=t-r:"hybrid"===a&&(n=e-r,o=t-r),[n,o,e,t]}),[Ee,Re,a,Le.size,ge.current.height,ge.current.width]),Ve="x"===a?_e[0]:_e[1],Ue=e.useMemo((()=>{if(!X)return[0,0];if("number"==typeof X){const e=2*X;return[e,e]}if(Array.isArray(X)){const[e=0,t]=X;return[2*e,2*(null!=t?t:e)]}return[0,0]}),[Ae]),Ge="x"===a?Ue[0]:Ue[1],Je=e.useMemo((()=>[_e[0]-Ue[0],_e[1]-Ue[1]]),[Ue.join(),_e[0],_e[1]]),Qe="x"===a?Je[0]:Je[1],Ze=e.useMemo((()=>A?Array.isArray(A)?A:t(A,!0,2):[null,null]),[je]),et=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(Ze[0]&&"none"!==Ze[0]&&"size"!==Ze[0]?Ze[0]:"y"===a&&"none"!==Ze[0]||"size"===Ze[0]?_e[0]:0,be.current.width),e(Ze[1]&&"none"!==Ze[1]&&"size"!==Ze[1]?Ze[1]:"x"===a&&"none"!==Ze[1]||"size"===Ze[1]?_e[1]:0,be.current.height)]}),[Ze.join(),a,be.current.width,be.current.height,_e.join()]),tt=e.useMemo((()=>{const e="x"===a,t="row"===I,r="column"===I,n=e?_e[1]:_e[0],o=e?et[1]+He:et[0]+Ye,l="hybrid"===a?o*(Ne.length+1)-o:n,s=Math.floor(l/o)||1,i=z&&s>=z?"hybrid"===a?Math.ceil(s/z):z:s,c=i>1&&i<Ne.length?Math.ceil(Ne.length/i):i>Ne.length?1:Ne.length,u=z&&z<Ne.length,d=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===a){const e=u?t?z:i:t?Ne.length:1,n=u?r?z:i:r?Ne.length:1;return[d(e),d(n)]}return[d(i),d(c)]}),[I,He,Ye,et.join(),Ne.length,a,_e.join(),z]),rt=e.useMemo((()=>{const e=tt[0]?tt[0]*He-He:0,t="x"===a?tt[1]:tt[0];return et[0]?(et[0]+He)*t-He:(null==H?void 0:H.type)?be.current.width+e:ye.current.width}),[a,et[0],tt.join(),He,ye.current.width,be.current.width,null==H?void 0:H.type]),nt=e.useMemo((()=>{const e=1>tt[1]?1:tt[0]*Ye-Ye;return et[1]?"x"===a?(et[1]+Ye)*tt[0]-Ye:(et[1]+Ye)*tt[1]-Ye:(null==H?void 0:H.type)?be.current.height+e:ye.current.height}),[a,et[1],tt.join(),Ye,ye.current.height,be.current.height,null==H?void 0:H.type]),ot=e.useMemo((()=>nt+We),[nt,We]),lt=e.useMemo((()=>rt+Xe),[rt,Xe]),st="x"===a?lt:ot,it="x"===a?(null===(_=oe.current)||void 0===_?void 0:_.scrollLeft)||0:(null===(V=oe.current)||void 0===V?void 0:V.scrollTop)||0,ct=it>1&&!0,at=st>Math.round(it+Ve);let ut=!1,dt=!1;"hybrid"===a&&(ut=((null===(U=oe.current)||void 0===U?void 0:U.scrollLeft)||0)>1&&!0,dt=Math.round(((null===(G=oe.current)||void 0===G?void 0:G.scrollLeft)||0)+_e[0])<lt);const mt=e.useMemo((()=>null!=Y?Y:30),[Y]),ht=e.useCallback((({withLimit:e=!0,xSize:t})=>B.progressElement&&st?t?O(e?Je[0]:_e[0],e?lt-Ue[0]:lt,mt):O(e?Qe:Ve,e?st-Ge:st,mt):0),[Re,st,Qe,Ge,Ue[0],Ve,_e[0],Je[0],lt,mt]),pt=e.useMemo((()=>Ve?st-Ve:st),[st,Ve]),ft=e.useMemo((()=>_e[0]?lt-_e[0]:lt),[lt,_e[0]]),gt=e.useCallback((()=>{if(!(null==H?void 0:H.type)||1>=tt[0])return[];const e=Array.from({length:Ne.length},((e,t)=>t)),t=Array.from({length:tt[0]},(()=>[])),r="x"===a&&"column"===I||"x"!==a&&"row"===I;return e.forEach((e=>{const n=r?e%tt[0]:Math.floor(e/tt[1]);t[n]&&t[n].push(e)})),t}),[Ne.length,tt.join(),null==H?void 0:H.type,I,a]),yt=e.useMemo((()=>{if(!(null==H?void 0:H.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if(N){const r=Array.from({length:Ne.length},((e,t)=>t)),n=Math.abs(Math.floor(Ne.length/tt[0])*tt[0]-Ne.length);e=n?r.slice(-n):[],"center"===N?t=(et[0]+He)*(tt[0]-n)/2:"end"===N&&(t=(et[0]+He)*(tt[0]-n))}return Ne.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===a?n:r,["hybrid","y"].includes(a)?n:r]}return[0,0]}(n,gt()),l=e.length>0&&e.includes(n)?t:0,s=function(e){const t="x"===a?l:0;return e>0?t+(et[1]+Ye)*e:t}(tt[0]>1||["hybrid","x"].includes(a)?o[1]:n),i=et[1]?s+et[1]:s,c=function(e){const t="x"===a?0:l;return e>0?t+(et[0]+He)*e:t}(1===tt[0]&&"x"===a?n:o[0]);return{elementTop:s,elementBottom:i,left:c,right:c+et[0]}}))}),[a,tt[0],et.join(),Ye,He,null==H?void 0:H.type,I,N,gt,Ne.join()]),bt=e.useMemo((()=>(null==_e?void 0:_e.length)&&F?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,s={display:"flex"};return t[0]>r&&(s.justifyContent=p(o)),t[1]>n&&(s.alignItems=p(l)),s}(F,_e,lt,ot):{}),[F,_e.join(),ot,lt]),vt=e.useMemo((()=>[d(lt,_e[0]),d(ot,_e[1])]),[lt,ot,_e.join()]),xt=e.useMemo((()=>"x"===a?vt[0]:vt[1]),[a,vt[0],vt[1]]),Et=e.useCallback(f(ge,te),[ge.current.height,ge.current.width]),jt=e.useCallback(f(ye,te,Xe,We),[ye.current.height,ye.current.width,Xe,We]),wt=e.useCallback(f(be,te),[be.current.height,be.current.width]),Ot=e.useCallback(((e,t,r,n)=>{const o=oe.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const s=performance.now(),i=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-s)/r,1);"y"===e?t.scrollTop=i+(n-i)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[]),kt=e.useCallback(((e,t,r)=>{if(ie.current){if(ie.current!==Ne[0])return void(ie.current=Ne[0])}else ie.current=Ne[0];const n=Ot(t,e,ze.duration);n&&r.push(n)}),[Ne[0],ze.duration,Ot]),St=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:C?`${Ie}px ${qe}px ${Be}px ${$e}px`:"",height:Ze[1]&&"none"!==Ze[1]?nt+"px":"fit-content",width:Ze[0]&&"none"!==Ze[0]?rt+"px":"fit-content"},B.content&&{cursor:"grab"}),T&&!(null==H?void 0:H.type)&&{gap:`${Ye}px ${He}px`}),L&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let s,i;return Array.isArray(e)?[s,i]=e:s=i=e,{minWidth:l(s,"x")+"px",minHeight:l(i,"y")+"px"}}(L,a,_e,Xe,We)),F&&{flexShrink:0});if(null==H?void 0:H.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=Ze[1]?"wrap":void 0,r=1===tt[0]?"y"===a?"column":"row":I;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:p(N)})}),[C,ke,Oe,[Ie,qe,Be,$e,Xe,We,Ye,He].join(),_e.join(),Se,Ze[1],nt,rt,B.content,Se,null==H?void 0:H.type,a,tt[0],I,N]),Rt=e.useCallback((e=>{if(!W)return;const t=()=>((e,t,r)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const n=e;["mouseleave","mouseup","touchend"].includes(r.type)?(n.style.opacity="0",n.classList.remove("hover"),n.classList.add("leave"),j((()=>n.classList.remove("leave")),200)):(n.style.opacity="1",n.classList.add("hover"))}))})(ne.current,0,e);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ce.current)&&t():t()}),[W]),Mt=e.useCallback(((e,t="mousedown",r)=>{const n=e||("scroll"===i?"thumb":"slider");if("wrapp"===e&&!B.content||["thumb","slider"].includes(n)&&!B.progressElement)return;h(i,re.current,se);let o=null;r&&(o=r.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>y(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),y(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>b(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:t,scrollElementRef:oe.current,objectsWrapperRef:le.current,scrollBar:r||null,clickedObject:ce,scrollContentRef:ne.current,scrollStateRef:ue.current,type:i,scrollBarOnHover:W,mouseOnEl:S,mouseOnRefHandle:Rt,triggerUpdate:te,direction:a,smoothScroll:Ot,sizeLocal:[_e[0],_e[1]],clicked:n,numForSliderRef:me,isScrollingRef:de,prevCoordsRef:he,thumbSize:ht("x"===o?{xSize:!0}:{}),axisFromAtr:o,duration:ze.duration,scrollBarEdge:Ue})}),[a,i,B.content,B.progressElement,_e.join(),ht({}),ht({xSize:!0}),ze.duration,Ot,Rt,W,Ue.join()]),At=e.useCallback((e=>{Mt(null,e.type,e.target)}),[Mt]),zt=e.useCallback((()=>{Mt("wrapp")}),[Mt]),Tt=e.useCallback((e=>{oe.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const s=r[0],i=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?i:s,d=(e,t)=>o(m(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==i?d(c+n[1],"y"):"right"===e&&a+n[0]!==s&&d(a+n[0],"x")})({arrowType:e,scrollElement:oe.current,wrapSize:[lt,ot],scrollSize:_e,smoothScroll:Ot,duration:ze.duration})}),[_e.join(),lt,ot,ze.duration,Ot]),Ct=e.useCallback((()=>{h(i,re.current,se);const e=oe.current;ne.current&&e&&0!==se.current.length&&((e,t,r,n)=>{!function(){var o,l,s,i;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(i=null===(s=t[1])||void 0===s?void 0:s.querySelectorAll(".ms-slider-element"))&&void 0!==i?i:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,se.current,_e,a)}),[_e.join(),a,oe,ne,i]),Lt=e.useCallback((()=>{re.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(w)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(w);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),s=new Set(t.current.loaded);o.forEach((e=>s.add(e)));let i=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),i=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(s):o.map((e=>e)),empty:i},r()})(re.current,ae,te,null==H?void 0:H.type)}),[xe]),Ft=e.useCallback((e=>{(null==P?void 0:P.clickTrigger)&&((e,t,r)=>{const n=e.target;if(!n.closest(t.selector))return;const o=n.closest(`[${w}]`);o&&o.classList.add("remove"),j((()=>{o&&o.classList.remove("remove"),r()}),t.delay||0)})(e,P.clickTrigger,Lt)}),[we,Lt]),Nt=e.useCallback((()=>{j((()=>{const e=oe.current;e&&(null==x||x(e.scrollLeft,e.scrollTop),de.current=!0,null==R||R(!0),j((()=>{de.current=!1,null==R||R(!1),Lt()}),200),"slider"===i&&j((()=>Ct()),33),te())}),6)}),[x,R,i,Ct,Lt]),It=k(it,pt,Qe,ht({})),qt=k((null===(J=oe.current)||void 0===J?void 0:J.scrollLeft)||0,ft,Je[0],ht({xSize:!0})),Bt=e.useCallback((e=>{const t="object"==typeof B.wheel&&"string"==typeof B.wheel.changeDirectionKey?B.wheel.changeDirectionKey:"KeyX";e.code!==t||"hybrid"!==a||pe.current||(e.stopPropagation(),pe.current=!0,te())}),[a,JSON.stringify(B.wheel)]),$t=e.useCallback((e=>{pe.current&&(e.stopPropagation(),pe.current=!1,te())}),[]);e.useEffect((()=>{(P||(null==H?void 0:H.type))&&(P||null===ae.current.empty||(ae.current.empty=null),Lt())}),[we,null==H?void 0:H.type,Lt]),e.useEffect((()=>{const e=ue.current.animationFrameId;return((null==H?void 0:H.type)||R)&&R&&(R(!1),te()),Ct(),()=>{e&&cancelAnimationFrame(e),["timeout"].forEach((e=>E[e].clearAll()))}}),[]),e.useEffect((()=>{const e=oe.current;if(!e)return;const t=e=>e.preventDefault(),r="hybrid"===a&&"object"==typeof B.wheel&&B.wheel.changeDirection?"x":a,n="hybrid"===a&&nt+We<=_e[1]||pe.current?["hybrid","y"].includes(r)?"x":"y":r,o=B.wheel?e=>{t(e),function(e,t,r){const n=e.target.closest(".ms-element");n.matches(":focus")||n.focus(),t.animating||(t.targetScrollX=n.scrollLeft,t.targetScrollY=n.scrollTop),"x"===r?t.targetScrollX=m(t.targetScrollX+e.deltaY,0,n.scrollWidth-n.clientWidth+2):t.targetScrollY=m(t.targetScrollY+e.deltaY,0,n.scrollHeight-n.clientHeight+2),t.animating||(t.animating=!0,t.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===r?(n.scrollLeft+=.4*(t.targetScrollX-n.scrollLeft),o=Math.abs(n.scrollLeft-t.targetScrollX)):(n.scrollTop+=.4*(t.targetScrollY-n.scrollTop),o=Math.abs(n.scrollTop-t.targetScrollY)),o>2.5?t.animationFrameId=requestAnimationFrame(e):(t.animating=!1,null!==t.animationFrameId&&(cancelAnimationFrame(t.animationFrameId),t.animationFrameId=null))})))}(e,ue.current,n)}:t;return e.addEventListener("wheel",o,{passive:!1}),()=>{e.removeEventListener("wheel",o)}}),[a,Re,nt,_e[1],We,pe.current]),e.useEffect((()=>{if(!ze.value)return;const e=[];return("hybrid"===a?["x","y"]:[a]).forEach((t=>{const r="x"===t?0:1;"end"===ze.value[r]&&kt(t,"x"===t?ft:pt,e)})),()=>{e.forEach((e=>e()))}}),[a,ze.value.join(),ve,pt,ft,lt,ot]),e.useEffect((()=>{if(!ze.value)return;const e=[];return("hybrid"===a?["x","y"]:[a]).forEach((t=>{const r="x"===t?0:1;"number"==typeof ze.value[r]&&kt(t,ze.value[r],e)})),()=>{e.forEach((e=>e()))}}),[ve,null==v?void 0:v.updater,a,kt,ze.value.join()]);const Wt=e.useCallback(((t,r,n,o)=>{var l;const s=Object.assign({width:et[0]?et[0]+"px":void 0,height:et[1]?et[1]+"px":void 0},(null==H?void 0:H.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!et[0]&&1===tt[0]&&{transform:"translateX(-50%)"})),i=D?e.createElement(e.Suspense,{fallback:K},o):o,c=(null===(l=null==P?void 0:P.clickTrigger)||void 0===l?void 0:l.selector)&&Ft;return e.createElement("div",Object.assign({key:t},H||P?{[w]:""+t}:{},{className:"ms-object-box",style:s,onClick:c}),i)}),[D,!!K,et.join(),xe,we,tt[0],Ft]),Xt=e.useMemo((()=>[{positionType:"x"===a?"left":"top",visibility:ct},{positionType:"x"===a?"right":"bottom",visibility:at},..."hybrid"===a?[{positionType:"left",visibility:ut},{positionType:"right",visibility:dt}]:[]]),[ct,at,a,ut,dt]),Yt=e.useMemo((()=>({width:_e[2]+"px",height:_e[3]+"px"})),[_e]),Ht=e.useMemo((()=>[{shouldRender:ht({withLimit:!1})<Ve,direction:a,thumbSize:ht({}),thumbSpace:It,objLengthPerSize:xt,progressReverseIndex:0},{shouldRender:"hybrid"===a&&ht({withLimit:!1,xSize:!0})<Je[0],direction:"x",thumbSize:ht({xSize:!0}),thumbSpace:qt,objLengthPerSize:vt[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e))),[ht,Qe,a,Je[0],It,qt,xt,vt]),Pt=e.useMemo((()=>{const e={position:"relative",width:_e[0]+"px",height:_e[1]+"px"};return B.arrows&&Le.size&&("x"===a?e.left=Le.size+"px":"y"===a?e.top=Le.size+"px":(e.top=Le.size+"px",e.left=Le.size+"px")),e}),[_e,Re,Le.size,a]),Dt=e.useMemo((()=>{var e;return null!==(e={x:lt>_e[0]?"scroll hidden":"hidden",y:ot>_e[1]?"hidden scroll":"hidden",hybrid:`${lt>_e[0]?"scroll":"hidden"} ${ot>_e[1]?"scroll":"hidden"}`,hide:"hidden"}[B.wheel||B.content?a:"hide"])&&void 0!==e?e:"hidden"}),[lt,ot,_e[0],_e[1],Re,a]),Kt=e.useMemo((()=>q?Xt.map((({positionType:t,visibility:r})=>e.createElement(c,{key:"edge-"+t,edgeGradient:Ce,visibility:r,edgeType:t}))):null),[q,Xt,Ce]),_t=e.useMemo((()=>B.arrows?Xt.map((({positionType:t,visibility:r})=>e.createElement(u,{key:"arrow-"+t,activity:r,arrows:Le,arrowType:t,handleArrow:Tt,size:"hybrid"===a?_e[0]+2*Le.size:_e[0]}))):null),[B.arrows,Xt,Le,Tt,_e[0],a]),Vt=e.useMemo((()=>B.progressElement&&!0!==B.progressElement?Ht.map((t=>{const r="boolean"==typeof $?$:$[t.progressReverseIndex];return e.createElement(s,{key:t.direction+"",type:i,direction:t.direction,progressReverse:r,size:Je,progressTrigger:B,scrollBarOnHover:W,scrollBarEvent:"sliderMenu"===i?Ot:At,thumbSize:t.thumbSize,thumbSpace:t.thumbSpace,objLengthPerSize:t.objLengthPerSize,sliderCheckLocal:Ct,duration:ze.duration})})):null),[B.progressElement,Ht,i,$,Je,B,W,Ot,At,Ct,ze.duration]),Ut=e.createElement("div",{className:"ms-objects-wrapper",ref:le,onMouseDown:zt,style:St},Ne.map(((t,r)=>{var o,s,i;const c=e.Children.toArray(l).find((r=>e.isValidElement(r)&&r.key===t)),u=(null==H?void 0:H.stopLoadOnScroll)&&de.current&&!ae.current.loaded.includes(""+t)?K:(null===(o=ae.current.empty)||void 0===o?void 0:o.includes(t))?"object"==typeof(null==P?void 0:P.mode)?P.mode.fallback:K:c,d="number"==typeof Ze[0]&&"number"==typeof Ze[1]||"firstChild"!==Ze[0]&&"firstChild"!==Ze[1]||0!==r?u:e.createElement(n,{onResize:wt},u);if(!(null==H?void 0:H.type))return Wt(t,0,0,d);{const{elementTop:e,elementBottom:n,left:o,right:l}=yt[r],c="x"===a?De:Ke,u=Ve+c>("x"===a?o:e)-it&&("x"===a?l:n)-it>0-c,m="hybrid"!==a||_e[0]+De>o-((null===(s=oe.current)||void 0===s?void 0:s.scrollLeft)||0)&&l-((null===(i=oe.current)||void 0===i?void 0:i.scrollLeft)||0)>0-De;if(u&&m)return Wt(t,e,o,d)}}))),Gt=e.createElement("div",{"morph-scroll":`〈♦${Q}〉`,className:r,ref:re,style:Yt},e.createElement("div",{className:"ms-content",ref:ne,onMouseEnter:Rt,onMouseLeave:Rt,onTouchStart:Rt,onTouchEnd:Rt,style:Pt},e.createElement("div",{className:"ms-element",ref:oe,onScroll:Nt,onKeyDown:Bt,onKeyUp:$t,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%",outline:"none"},bt),{overflow:Dt}),"scroll"!==i||"boolean"!=typeof B.progressElement||!1===B.progressElement?{scrollbarWidth:"none"}:{})},et[0]&&et[1]?Ut:e.createElement(n,{onResize:jt,style:bt},Ut)),Kt,Vt),_t);return"auto"===M?e.createElement(n,{measure:"outer",onResize:Et},Gt):Gt};R.displayName="MorphScroll";const M={MorphScroll:R,ResizeTracker:n,IntersectionTracker:r};exports.IntersectionTracker=r,exports.MorphScroll=R,exports.ResizeTracker=n,exports.default=M;
package/esm/index.js CHANGED
@@ -1 +1 @@
1
- import e,{useRef as t}from"react";const r=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},n=({className:t,children:n,style:o,root:l,threshold:s,rootMargin:i,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),h=e.useMemo((()=>{if(!i)return"";const e=r(i);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[i]),p=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(p,{root:l,threshold:s,rootMargin:h});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[p,l,s,h]),e.createElement("div",{"intersection-tracker":"",className:t,ref:m,style:o},c||u?n:null)};n.displayName="IntersectionTracker";const o=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const s=e.useRef(null);e.useEffect((()=>{const e=s.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const i={width:"max-content",height:"max-content"},c={inner:Object.assign({},i),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},i)};return e.createElement("div",{"resize-tracker":"",className:t,ref:s,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};o.displayName="ResizeTracker";let l=1;const s=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:s,scrollBarEvent:i,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const h="sliderMenu"!==t?{onMouseDown:i,onTouchStart:i}:{},p=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",s="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{i(s*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,i,null==l?void 0:l.progressElement,m,d]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px",left:"50%"},n?{top:0,transform:"rotate(-90deg) translate(-100%, -50%)"}:{transform:"rotate(-90deg) translateY(-50%)"}):Object.assign({top:"50%",transform:"translateY(-50%)",height:o[1]+"px"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},h,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},h,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),p))};s.displayName="ScrollBar";var i=e.memo(s);const c=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};c.displayName="Edge";var a=e.memo(c);const u=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const s=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},s),onClick:()=>o(n)},r.element)};u.displayName="Arrow";var d=e.memo(u);function m(e,t){return e>t?Math.floor(e/t):1}function h(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const p=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},f=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function g(e,t,r=0,n=0){return o=>{var l,s,i,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(s=o.height)&&void 0!==s?s:0)-n};(null===(i=e.current)||void 0===i?void 0:i.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function y(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function b(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,s={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const i=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:s.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:s.y,o=e.scrollElementRef;if("thumb"===e.clicked){const s=e.objectsWrapperRef,i=getComputedStyle(s),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?o.clientWidth-e.scrollBarEdge[0]:o.clientHeight-e.scrollBarEdge[1],u="x"===t?s.clientWidth+parseFloat(i.marginLeft)+parseFloat(i.marginRight):s.clientHeight+parseFloat(i.marginTop)+parseFloat(i.marginBottom),d=a-e.thumbSize,m=u-c;if(0>=d||0>=m)return;const h=n*(m/d)+l.leftover,p=Math.trunc(h),f=h-p;e.prevCoordsRef.current.leftover=f,r=p}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=s[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],i="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&i>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?i(t):"wrapp"===e.clicked?"slider"===e.type?c(t):i(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function v(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}let x=0;const E={timeout:{tasks:[],timer:null},requestFrame:{tasks:[],rafId:null}},j={timeout:{scheduleNext(){const{tasks:e}=E.timeout;if(null!==E.timeout.timer&&(clearTimeout(E.timeout.timer),E.timeout.timer=null),0===e.length)return;const t=e[0],r=performance.now(),n=Math.max(0,t.runAt-r);E.timeout.timer=window.setTimeout((()=>{const t=performance.now(),r=[];for(;e.length&&e[0].runAt<=t;)r.push(e.shift());r.forEach((e=>e.callback())),j.timeout.scheduleNext()}),n)},clearAll(){null!==E.timeout.timer&&(clearTimeout(E.timeout.timer),E.timeout.timer=null),E.timeout.tasks=[]}},requestFrame:{scheduleNext(){const{tasks:e}=E.requestFrame;if(null!==E.requestFrame.rafId)return;if(0===e.length)return;const t=()=>{E.requestFrame.rafId=null;const r=performance.now(),n=[];for(;e.length&&e[0].runAt<=r;)n.push(e.shift());n.forEach((e=>e.callback())),e.length>0&&(E.requestFrame.rafId=requestAnimationFrame(t))};E.requestFrame.rafId=requestAnimationFrame(t)},clearAll(){null!==E.requestFrame.rafId&&(cancelAnimationFrame(E.requestFrame.rafId),E.requestFrame.rafId=null),E.requestFrame.tasks=[]}}},w=(e,t,r)=>{const n="task_"+x++,o="string"==typeof t?"requestFrame":"timeout";E[o].tasks=E[o].tasks.filter((e=>e.id!==n));const l="requestFrame"===o?performance.now():performance.now()+t,s={id:n,callback:e,runAt:l};let i=E[o].tasks.length;for(;i>0&&E[o].tasks[i-1].runAt>s.runAt;)i--;return E[o].tasks.splice(i,0,s),j[o].scheduleNext(),n},O="wrap-id";function k(e,t,r,n){if(!t)return 0;const o=Math.round(e/t*r);return!Number.isFinite(o)||n>o?n:o}const S=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},M=({className:n,children:s,type:c="scroll",direction:u="y",scrollPosition:x,onScrollValue:E,isScrolling:M,size:R,objectsSize:A,crossCount:z,gap:C,wrapperMargin:T,wrapperMinSize:F,wrapperAlign:L,elementsAlign:N,elementsDirection:I="row",edgeGradient:q,progressTrigger:B={wheel:!0},progressReverse:$=!1,scrollBarOnHover:W=!1,scrollBarEdge:X,thumbMinSize:Y,render:H,emptyElements:P,suspending:D=!1,fallback:K})=>{var V,U,_,G,J;const Q=function(){const e=t(null);return null===e.current&&(e.current=""+l++),e.current}();if(!R)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${Q}〉`);Object.keys(B).length;const[Z,ee]=e.useState(0),te=()=>{ee((e=>"number"==typeof e&&1e3>e?e+1:0))},re=e.useRef(null),ne=e.useRef(null),oe=e.useRef(null),le=e.useRef(null),se=e.useRef([]),ie=e.useRef(null),ce=e.useRef("none"),ae=e.useRef({loaded:[],empty:[]}),ue=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),de=e.useRef(!1),me=e.useRef(0),he=e.useRef(null),pe=e.useRef(!1);function fe(){return e.useRef({width:0,height:0})}const ge=fe(),ye=fe(),be=fe(),[ve,xe,Ee,je,we,Oe,ke,Se,Me,Re,Ae]=function(...e){return e.map(y)}(null==x?void 0:x.value,H,R,A,P,F,L,C,B,ae.current.empty,X),ze=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==x?void 0:x.value)||"string"==typeof(null==x?void 0:x.value)?[x.value,x.value]:null!==(e=null==x?void 0:x.value)&&void 0!==e?e:[null],duration:null!==(t=null==x?void 0:x.duration)&&void 0!==t?t:200}}),[ve,null==x?void 0:x.duration]),Ce={color:null,size:40},Te=e.useMemo((()=>"object"==typeof q?Object.assign(Object.assign({},Ce),q):Ce),[q]),Fe=e.useMemo((()=>Object.assign(Object.assign({},Ce),"object"==typeof B.arrows?B.arrows:{})),[Me]),Le=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Le):[r]}return[t]}),[]),Ne=e.useMemo((()=>e.Children.toArray(s).flatMap(Le).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==P?void 0:P.mode)||!(null===(t=ae.current.empty)||void 0===t?void 0:t.includes(e))}))),[s,Le,we,Re]),[Ie,qe,Be,$e]=T?r(T):[0,0,0,0],We=Ie+Be,Xe=$e+qe,[Ye,He]=e.useMemo((()=>{var e,t;return"number"==typeof C?[C,C]:Array.isArray(C)?[null!==(e=C[1])&&void 0!==e?e:0,null!==(t=C[0])&&void 0!==t?t:0]:[0,0]}),[C]),Pe=e.useMemo((()=>r((null==H?void 0:H.rootMargin)||0,"x"===u)),[xe,u]),[De,Ke]=Pe?[Pe[2],Pe[0]]:[0,0],Ve=e.useMemo((()=>{const[e,t]=Array.isArray(R)?R:"number"==typeof R?[R,R]:[ge.current.width,ge.current.height];if(!B.arrows||!Fe.size)return[e,t,e,t];const r=2*Fe.size;let n=e,o=t;return"x"===u?n=e-r:"y"===u?o=t-r:"hybrid"===u&&(n=e-r,o=t-r),[n,o,e,t]}),[Ee,Me,u,Fe.size,ge.current.height,ge.current.width]),Ue="x"===u?Ve[0]:Ve[1],_e=e.useMemo((()=>{if(!X)return[0,0];if("number"==typeof X){const e=2*X;return[e,e]}if(Array.isArray(X)){const[e=0,t]=X;return[2*e,2*(null!=t?t:e)]}return[0,0]}),[Ae]),Ge="x"===u?_e[0]:_e[1],Je=e.useMemo((()=>[Ve[0]-_e[0],Ve[1]-_e[1]]),[_e.join(),Ve[0],Ve[1]]),Qe="x"===u?Je[0]:Je[1],Ze=e.useMemo((()=>A?Array.isArray(A)?A:r(A,!0,2):[null,null]),[je]),et=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(Ze[0]&&"none"!==Ze[0]&&"size"!==Ze[0]?Ze[0]:"y"===u&&"none"!==Ze[0]||"size"===Ze[0]?Ve[0]:0,be.current.width),e(Ze[1]&&"none"!==Ze[1]&&"size"!==Ze[1]?Ze[1]:"x"===u&&"none"!==Ze[1]||"size"===Ze[1]?Ve[1]:0,be.current.height)]}),[Ze.join(),u,be.current.width,be.current.height,Ve.join()]),tt=e.useMemo((()=>{const e="x"===u,t="row"===I,r="column"===I,n=e?Ve[1]:Ve[0],o=e?et[1]+He:et[0]+Ye,l="hybrid"===u?o*(Ne.length+1)-o:n,s=Math.floor(l/o)||1,i=z&&s>=z?"hybrid"===u?Math.ceil(s/z):z:s,c=i>1&&i<Ne.length?Math.ceil(Ne.length/i):i>Ne.length?1:Ne.length,a=z&&z<Ne.length,d=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===u){const e=a?t?z:i:t?Ne.length:1,n=a?r?z:i:r?Ne.length:1;return[d(e),d(n)]}return[d(i),d(c)]}),[I,He,Ye,et.join(),Ne.length,u,Ve.join(),z]),rt=e.useMemo((()=>{const e=tt[0]?tt[0]*He-He:0,t="x"===u?tt[1]:tt[0];return et[0]?(et[0]+He)*t-He:(null==H?void 0:H.type)?be.current.width+e:ye.current.width}),[u,et[0],tt.join(),He,ye.current.width,be.current.width,null==H?void 0:H.type]),nt=e.useMemo((()=>{const e=1>tt[1]?1:tt[0]*Ye-Ye;return et[1]?"x"===u?(et[1]+Ye)*tt[0]-Ye:(et[1]+Ye)*tt[1]-Ye:(null==H?void 0:H.type)?be.current.height+e:ye.current.height}),[u,et[1],tt.join(),Ye,ye.current.height,be.current.height,null==H?void 0:H.type]),ot=e.useMemo((()=>nt+We),[nt,We]),lt=e.useMemo((()=>rt+Xe),[rt,Xe]),st="x"===u?lt:ot,it="x"===u?(null===(V=oe.current)||void 0===V?void 0:V.scrollLeft)||0:(null===(U=oe.current)||void 0===U?void 0:U.scrollTop)||0,ct=it>1&&!0,at=st>Math.round(it+Ue);let ut=!1,dt=!1;"hybrid"===u&&(ut=((null===(_=oe.current)||void 0===_?void 0:_.scrollLeft)||0)>1&&!0,dt=Math.round(((null===(G=oe.current)||void 0===G?void 0:G.scrollLeft)||0)+Ve[0])<lt);const mt=e.useMemo((()=>null!=Y?Y:30),[Y]),ht=e.useMemo((()=>B.progressElement&&st?k(Qe,st,Qe,mt):0),[Qe,st,B.progressElement,mt]),pt=e.useMemo((()=>B.progressElement?k(Je[0],lt,Je[0],mt):0),[Je[0],lt,B.progressElement,mt]),ft=e.useMemo((()=>Ue?st-Ue:st),[st,Ue]),gt=e.useMemo((()=>Ve[0]?lt-Ve[0]:lt),[lt,Ve[0]]),yt=e.useCallback((()=>{if(!(null==H?void 0:H.type)||1>=tt[0])return[];const e=Array.from({length:Ne.length},((e,t)=>t)),t=Array.from({length:tt[0]},(()=>[])),r="x"===u&&"column"===I||"x"!==u&&"row"===I;return e.forEach((e=>{const n=r?e%tt[0]:Math.floor(e/tt[1]);t[n]&&t[n].push(e)})),t}),[Ne.length,tt.join(),null==H?void 0:H.type,I,u]),bt=e.useMemo((()=>{if(!(null==H?void 0:H.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if(N){const r=Array.from({length:Ne.length},((e,t)=>t)),n=Math.abs(Math.floor(Ne.length/tt[0])*tt[0]-Ne.length);e=n?r.slice(-n):[],"center"===N?t=(et[0]+He)*(tt[0]-n)/2:"end"===N&&(t=(et[0]+He)*(tt[0]-n))}return Ne.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===u?n:r,["hybrid","y"].includes(u)?n:r]}return[0,0]}(n,yt()),l=e.length>0&&e.includes(n)?t:0,s=function(e){const t="x"===u?l:0;return e>0?t+(et[1]+Ye)*e:t}(tt[0]>1||["hybrid","x"].includes(u)?o[1]:n),i=et[1]?s+et[1]:s,c=function(e){const t="x"===u?0:l;return e>0?t+(et[0]+He)*e:t}(1===tt[0]&&"x"===u?n:o[0]);return{elementTop:s,elementBottom:i,left:c,right:c+et[0]}}))}),[u,tt[0],et.join(),Ye,He,null==H?void 0:H.type,I,N,yt,Ne.join()]),vt=e.useMemo((()=>(null==Ve?void 0:Ve.length)&&L?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,s={display:"flex"};return t[0]>r&&(s.justifyContent=f(o)),t[1]>n&&(s.alignItems=f(l)),s}(L,Ve,lt,ot):{}),[L,Ve.join(),ot,lt]),xt=e.useMemo((()=>[m(lt,Ve[0]),m(ot,Ve[1])]),[lt,ot,Ve.join()]),Et=e.useMemo((()=>"x"===u?xt[0]:xt[1]),[u,xt[0],xt[1]]),jt=e.useCallback(g(ge,te),[ge.current.height,ge.current.width]),wt=e.useCallback(g(ye,te,Xe,We),[ye.current.height,ye.current.width,Xe,We]),Ot=e.useCallback(g(be,te),[be.current.height,be.current.width]),kt=e.useCallback(((e,t,r,n)=>{const o=oe.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const s=performance.now(),i=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-s)/r,1);"y"===e?t.scrollTop=i+(n-i)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[]),St=e.useCallback(((e,t,r)=>{if(ie.current){if(ie.current!==Ne[0])return void(ie.current=Ne[0])}else ie.current=Ne[0];const n=kt(t,e,ze.duration);n&&r.push(n)}),[Ne[0],ze.duration,kt]),Mt=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:T?`${Ie}px ${qe}px ${Be}px ${$e}px`:"",height:Ze[1]&&"none"!==Ze[1]?nt+"px":"fit-content",width:Ze[0]&&"none"!==Ze[0]?rt+"px":"fit-content"},B.content&&{cursor:"grab"}),C&&!(null==H?void 0:H.type)&&{gap:`${Ye}px ${He}px`}),F&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let s,i;return Array.isArray(e)?[s,i]=e:s=i=e,{minWidth:l(s,"x")+"px",minHeight:l(i,"y")+"px"}}(F,u,Ve,Xe,We)),L&&{flexShrink:0});if(null==H?void 0:H.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=Ze[1]?"wrap":void 0,r=1===tt[0]?"y"===u?"column":"row":I;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:f(N)})}),[T,ke,Oe,[Ie,qe,Be,$e,Xe,We,Ye,He].join(),Ve.join(),Se,Ze[1],nt,rt,B.content,Se,null==H?void 0:H.type,u,tt[0],I,N]),Rt=e.useCallback((e=>{if(!W)return;const t=()=>((e,t,r)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const n=e;["mouseleave","mouseup","touchend"].includes(r.type)?(n.style.opacity="0",n.classList.remove("hover"),n.classList.add("leave"),w((()=>n.classList.remove("leave")),200)):(n.style.opacity="1",n.classList.add("hover"))}))})(ne.current,0,e);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ce.current)&&t():t()}),[W]),At=e.useCallback(((e,t="mousedown",r)=>{const n=e||("scroll"===c?"thumb":"slider");if("wrapp"===e&&!B.content||["thumb","slider"].includes(n)&&!B.progressElement)return;p(c,re.current,se);let o=null;r&&(o=r.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>b(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>v(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),b(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>v(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:t,scrollElementRef:oe.current,objectsWrapperRef:le.current,scrollBar:r||null,clickedObject:ce,scrollContentRef:ne.current,scrollStateRef:ue.current,type:c,scrollBarOnHover:W,mouseOnEl:S,mouseOnRefHandle:Rt,triggerUpdate:te,direction:u,smoothScroll:kt,sizeLocal:[Ve[0],Ve[1]],clicked:n,numForSliderRef:me,isScrollingRef:de,prevCoordsRef:he,thumbSize:"x"===o?pt:ht,axisFromAtr:o,duration:ze.duration,scrollBarEdge:_e})}),[u,c,B.content,B.progressElement,Ve.join(),ht,pt,ze.duration,kt,Rt,W,_e.join()]),zt=e.useCallback((e=>{At(null,e.type,e.target)}),[At]),Ct=e.useCallback((()=>{At("wrapp")}),[At]),Tt=e.useCallback((e=>{oe.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const s=r[0],i=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?i:s,d=(e,t)=>o(h(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==i?d(c+n[1],"y"):"right"===e&&a+n[0]!==s&&d(a+n[0],"x")})({arrowType:e,scrollElement:oe.current,wrapSize:[lt,ot],scrollSize:Ve,smoothScroll:kt,duration:ze.duration})}),[Ve.join(),lt,ot,ze.duration,kt]),Ft=e.useCallback((()=>{p(c,re.current,se);const e=oe.current;ne.current&&e&&0!==se.current.length&&((e,t,r,n)=>{!function(){var o,l,s,i;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(i=null===(s=t[1])||void 0===s?void 0:s.querySelectorAll(".ms-slider-element"))&&void 0!==i?i:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,se.current,Ve,u)}),[Ve.join(),u,oe,ne,c]),Lt=e.useCallback((()=>{re.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(O)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(O);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),s=new Set(t.current.loaded);o.forEach((e=>s.add(e)));let i=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),i=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(s):o.map((e=>e)),empty:i},r()})(re.current,ae,te,null==H?void 0:H.type)}),[xe]),Nt=e.useCallback((e=>{(null==P?void 0:P.clickTrigger)&&((e,t,r)=>{const n=e.target;if(!n.closest(t.selector))return;const o=n.closest(`[${O}]`);o&&o.classList.add("remove"),w((()=>{o&&o.classList.remove("remove"),r()}),t.delay||0)})(e,P.clickTrigger,Lt)}),[we,Lt]),It=e.useCallback((()=>{w((()=>{const e=oe.current;e&&(null==E||E(e.scrollLeft,e.scrollTop),de.current=!0,null==M||M(!0),w((()=>{de.current=!1,null==M||M(!1),Lt()}),200),"slider"===c&&w((()=>Ft()),33),te())}),6)}),[E,M,c,Ft,Lt]),qt=h(it/ft*(Qe-ht),0,Qe-ht),Bt=h(((null===(J=oe.current)||void 0===J?void 0:J.scrollLeft)||0)/gt*(Je[0]-Je[0]/lt*Je[0]),0,Je[0]-pt),$t=e.useCallback((e=>{const t="object"==typeof B.wheel&&"string"==typeof B.wheel.changeDirectionKey?B.wheel.changeDirectionKey:"KeyX";e.code!==t||"hybrid"!==u||pe.current||(e.stopPropagation(),pe.current=!0,te())}),[u,JSON.stringify(B.wheel)]),Wt=e.useCallback((e=>{pe.current&&(e.stopPropagation(),pe.current=!1,te())}),[]);e.useEffect((()=>{(P||(null==H?void 0:H.type))&&(P||null===ae.current.empty||(ae.current.empty=null),Lt())}),[we,null==H?void 0:H.type,Lt]),e.useEffect((()=>{const e=ue.current.animationFrameId;return((null==H?void 0:H.type)||M)&&M&&(M(!1),te()),Ft(),()=>{e&&cancelAnimationFrame(e),["timeout"].forEach((e=>j[e].clearAll()))}}),[]),e.useEffect((()=>{const e=oe.current;if(!e)return;const t=e=>e.preventDefault(),r="hybrid"===u&&"object"==typeof B.wheel&&B.wheel.changeDirection?"x":u,n="hybrid"===u&&nt+We<=Ve[1]||pe.current?["hybrid","y"].includes(r)?"x":"y":r,o=B.wheel?e=>{t(e),function(e,t,r){const n=e.target.closest(".ms-element");n.matches(":focus")||n.focus(),t.animating||(t.targetScrollX=n.scrollLeft,t.targetScrollY=n.scrollTop),"x"===r?t.targetScrollX=h(t.targetScrollX+e.deltaY,0,n.scrollWidth-n.clientWidth+2):t.targetScrollY=h(t.targetScrollY+e.deltaY,0,n.scrollHeight-n.clientHeight+2),t.animating||(t.animating=!0,t.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===r?(n.scrollLeft+=.4*(t.targetScrollX-n.scrollLeft),o=Math.abs(n.scrollLeft-t.targetScrollX)):(n.scrollTop+=.4*(t.targetScrollY-n.scrollTop),o=Math.abs(n.scrollTop-t.targetScrollY)),o>2.5?t.animationFrameId=requestAnimationFrame(e):(t.animating=!1,null!==t.animationFrameId&&(cancelAnimationFrame(t.animationFrameId),t.animationFrameId=null))})))}(e,ue.current,n)}:t;return e.addEventListener("wheel",o,{passive:!1}),()=>{e.removeEventListener("wheel",o)}}),[u,JSON.stringify(B.wheel),nt,Ve[1],We,pe.current]),e.useEffect((()=>{if(!ze.value)return;const e=[];return("hybrid"===u?["x","y"]:[u]).forEach((t=>{const r="x"===t?0:1;"end"===ze.value[r]&&St(t,"x"===t?gt:ft,e)})),()=>{e.forEach((e=>e()))}}),[u,ze.value.join(),ve,ft,gt,lt,ot]),e.useEffect((()=>{if(!ze.value)return;const e=[];return("hybrid"===u?["x","y"]:[u]).forEach((t=>{const r="x"===t?0:1;"number"==typeof ze.value[r]&&St(t,ze.value[r],e)})),()=>{e.forEach((e=>e()))}}),[ve,null==x?void 0:x.updater,u,St,ze.value.join()]);const Xt=e.useCallback(((t,r,n,o)=>{var l;const s=Object.assign({width:et[0]?et[0]+"px":void 0,height:et[1]?et[1]+"px":void 0},(null==H?void 0:H.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!et[0]&&1===tt[0]&&{transform:"translateX(-50%)"})),i=D?e.createElement(e.Suspense,{fallback:K},o):o,c=(null===(l=null==P?void 0:P.clickTrigger)||void 0===l?void 0:l.selector)&&Nt;return e.createElement("div",Object.assign({key:t},H||P?{[O]:""+t}:{},{className:"ms-object-box",style:s,onClick:c}),i)}),[D,!!K,et.join(),xe,we,tt[0],Nt]),Yt=e.useMemo((()=>[{positionType:"x"===u?"left":"top",visibility:ct},{positionType:"x"===u?"right":"bottom",visibility:at},..."hybrid"===u?[{positionType:"left",visibility:ut},{positionType:"right",visibility:dt}]:[]]),[ct,at,u,ut,dt]),Ht=e.useMemo((()=>({width:Ve[2]+"px",height:Ve[3]+"px"})),[Ve]),Pt=e.useMemo((()=>[{shouldRender:st-Ge>ht,direction:u,thumbSize:ht,thumbSpace:qt,objLengthPerSize:Et,progressReverseIndex:0},{shouldRender:"hybrid"===u&&pt<lt-_e[0],direction:"x",thumbSize:pt,thumbSpace:Bt,objLengthPerSize:xt[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e))),[ht,st,Ge,u,pt,lt,_e[0],qt,Bt,Et,xt]),Dt=e.useMemo((()=>{const e={position:"relative",width:Ve[0]+"px",height:Ve[1]+"px"};return B.arrows&&Fe.size&&("x"===u?e.left=Fe.size+"px":"y"===u?e.top=Fe.size+"px":(e.top=Fe.size+"px",e.left=Fe.size+"px")),e}),[Ve,Me,Fe.size,u]),Kt=e.useMemo((()=>{var e;return null!==(e={x:lt>Ve[0]?"scroll hidden":"hidden",y:ot>Ve[1]?"hidden scroll":"hidden",hybrid:`${lt>Ve[0]?"scroll":"hidden"} ${ot>Ve[1]?"scroll":"hidden"}`,hide:"hidden"}[B.wheel||B.content?u:"hide"])&&void 0!==e?e:"hidden"}),[lt,ot,Ve[0],Ve[1],Me,u]),Vt=e.useMemo((()=>q?Yt.map((({positionType:t,visibility:r})=>e.createElement(a,{key:"edge-"+t,edgeGradient:Te,visibility:r,edgeType:t}))):null),[q,Yt,Te]),Ut=e.useMemo((()=>B.arrows?Yt.map((({positionType:t,visibility:r})=>e.createElement(d,{key:"arrow-"+t,activity:r,arrows:Fe,arrowType:t,handleArrow:Tt,size:"hybrid"===u?Ve[0]+2*Fe.size:Ve[0]}))):null),[B.arrows,Yt,Fe,Tt,Ve[0],u]),_t=e.useMemo((()=>B.progressElement&&!0!==B.progressElement?Pt.map((t=>{const r="boolean"==typeof $?$:$[t.progressReverseIndex];return e.createElement(i,{key:t.direction+"",type:c,direction:t.direction,progressReverse:r,size:Je,progressTrigger:B,scrollBarOnHover:W,scrollBarEvent:"sliderMenu"===c?kt:zt,thumbSize:t.thumbSize,thumbSpace:t.thumbSpace,objLengthPerSize:t.objLengthPerSize,sliderCheckLocal:Ft,duration:ze.duration})})):null),[B.progressElement,Pt,c,$,Je,B,W,kt,zt,Ft,ze.duration]),Gt=e.createElement("div",{className:"ms-objects-wrapper",ref:le,onMouseDown:Ct,style:Mt},Ne.map(((t,r)=>{var n,l,i;const c=e.Children.toArray(s).find((r=>e.isValidElement(r)&&r.key===t)),a=(null==H?void 0:H.stopLoadOnScroll)&&de.current&&!ae.current.loaded.includes(""+t)?K:(null===(n=ae.current.empty)||void 0===n?void 0:n.includes(t))?"object"==typeof(null==P?void 0:P.mode)?P.mode.fallback:K:c,d="number"==typeof Ze[0]&&"number"==typeof Ze[1]||"firstChild"!==Ze[0]&&"firstChild"!==Ze[1]||0!==r?a:e.createElement(o,{onResize:Ot},a);if(!(null==H?void 0:H.type))return Xt(t,0,0,d);{const{elementTop:e,elementBottom:n,left:o,right:s}=bt[r],c="x"===u?De:Ke,a=Ue+c>("x"===u?o:e)-it&&("x"===u?s:n)-it>0-c,m="hybrid"!==u||Ve[0]+De>o-((null===(l=oe.current)||void 0===l?void 0:l.scrollLeft)||0)&&s-((null===(i=oe.current)||void 0===i?void 0:i.scrollLeft)||0)>0-De;if(a&&m)return Xt(t,e,o,d)}}))),Jt=e.createElement("div",{"morph-scroll":`〈♦${Q}〉`,className:n,ref:re,style:Ht},e.createElement("div",{className:"ms-content",ref:ne,onMouseEnter:Rt,onMouseLeave:Rt,onTouchStart:Rt,onTouchEnd:Rt,style:Dt},e.createElement("div",{className:"ms-element",ref:oe,onScroll:It,onKeyDown:$t,onKeyUp:Wt,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%",outline:"none"},vt),{overflow:Kt}),"scroll"!==c||"boolean"!=typeof B.progressElement||!1===B.progressElement?{scrollbarWidth:"none"}:{})},et[0]&&et[1]?Gt:e.createElement(o,{onResize:wt,style:vt},Gt)),Vt,_t),Ut);return"auto"===R?e.createElement(o,{measure:"outer",onResize:jt},Jt):Jt};M.displayName="MorphScroll";const R={MorphScroll:M,ResizeTracker:o,IntersectionTracker:n};export{n as IntersectionTracker,M as MorphScroll,o as ResizeTracker,R as default};
1
+ import e,{useRef as t}from"react";const r=(e,t=!1,r)=>{let n=[];if(n=Array.isArray(e)?2===e.length?[e[1],e[0],e[1],e[0]]:[...e]:[e,e,e,e],t&&(n=[n[1],n[0],n[3],n[2]]),r){const e=[];for(let t=0;r>t;t++)e.push(n[t%4]);n=e}return n},n=({className:t,children:n,style:o,root:l,threshold:s,rootMargin:i,visibleContent:c=!1,onIntersection:a})=>{const[u,d]=e.useState(!1),m=e.useRef(null),h=e.useMemo((()=>{if(!i)return"";const e=r(i);return`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px`}),[i]),p=e.useCallback((([e])=>{d(e.isIntersecting),a&&a({time:e.time,rootBounds:e.rootBounds,boundingClientRect:e.boundingClientRect,intersectionRect:e.intersectionRect,isIntersecting:e.isIntersecting,intersectionRatio:e.intersectionRatio,target:e.target})}),[a]);return e.useEffect((()=>{const e=new IntersectionObserver(p,{root:l,threshold:s,rootMargin:h});return m.current&&e.observe(m.current),()=>{e.disconnect()}}),[p,l,s,h]),e.createElement("div",{"intersection-tracker":"",className:t,ref:m,style:o},c||u?n:null)};n.displayName="IntersectionTracker";const o=({className:t,children:r,style:n,measure:o="inner",onResize:l})=>{const s=e.useRef(null);e.useEffect((()=>{const e=s.current;if(!e)return;const t=new ResizeObserver((e=>{for(const t of e)l&&l(t.contentRect)}));return t.observe(e),()=>{t.unobserve(e),t.disconnect()}}),[o,l]);const i={width:"max-content",height:"max-content"},c={inner:Object.assign({},i),outer:Object.assign({},{width:"100%",height:"100%"}),all:Object.assign({minWidth:"100%",minHeight:"100%"},i)};return e.createElement("div",{"resize-tracker":"",className:t,ref:s,style:Object.assign(Object.assign({willChange:"width, height"},c[o]),n)},r)};o.displayName="ResizeTracker";let l=1;const s=({type:t,direction:r,progressReverse:n,size:o,progressTrigger:l,scrollBarOnHover:s,scrollBarEvent:i,thumbSize:c,thumbSpace:a,objLengthPerSize:u,sliderCheckLocal:d,duration:m})=>{const h="sliderMenu"!==t?{onMouseDown:i,onTouchStart:i}:{},p=e.useMemo((()=>{if("scroll"===t||!r)return;const n=["hybrid","y"].includes(r)?"y":"x",s="x"===n?o[0]:o[1];return Array.from({length:u},((r,o)=>e.createElement("div",{key:o,className:"ms-slider-element",style:Object.assign({},"sliderMenu"===t&&{cursor:"pointer"}),onClick:"sliderMenu"===t?()=>{i(s*o,n,m,d)}:void 0},Array.isArray(null==l?void 0:l.progressElement)?l.progressElement[o]:null==l?void 0:l.progressElement)))}),[u,r,o,t,i,null==l?void 0:l.progressElement,m,d]);return e.createElement(e.Fragment,null,"scroll"===t?e.createElement("div",{className:"ms-bar",style:Object.assign(Object.assign(Object.assign({position:"absolute",width:"fit-content"},"x"===r?Object.assign({transformOrigin:"left top",height:o[0]+"px",left:"50%"},n?{top:0,transform:"rotate(-90deg) translate(-100%, -50%)"}:{transform:"rotate(-90deg) translateY(-50%)"}):Object.assign({top:"50%",transform:"translateY(-50%)",height:o[1]+"px"},n?{left:0}:{right:0})),0!=!(null==l?void 0:l.progressElement)&&{pointerEvents:"none"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"})},e.createElement("div",Object.assign({className:"ms-thumb","data-direction":["hybrid","y"].includes(r)?"y":r},h,{style:Object.assign(Object.assign({height:c+"px",willChange:"transform, height",transform:`translateY(${a}px)`},(null==l?void 0:l.progressElement)&&{cursor:"grab"}),{transition:"height 0.05s ease-in-out"})}),null==l?void 0:l.progressElement)):u>1&&(null==l?void 0:l.progressElement)&&e.createElement("div",Object.assign({className:"ms-slider","data-direction":["hybrid","y"].includes(r)?"y":r},h,{style:Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex"},"slider"===t&&{cursor:"grab"}),s&&{opacity:0,transition:"opacity 0.1s ease-in-out"}),"x"===r?Object.assign({transformOrigin:"left top",left:"50%",transform:"translateX(-50%)"},n?{top:0}:{bottom:0}):Object.assign({flexDirection:"column",top:"50%",transform:"translateY(-50%)"},n?{left:0}:{right:0}))}),p))};s.displayName="ScrollBar";var i=e.memo(s);const c=({edgeGradient:t,visibility:r,edgeType:n})=>{if(!t)return null;const o=Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",pointerEvents:"none",transition:"opacity 0.1s ease-in-out"},t.color&&{background:t.color&&`linear-gradient(${"right"===n||"left"===n?"90deg, ":""}${t.color}, transparent)`}),"right"===n||"left"===n?{height:"100%",width:t.size+"px",top:0}:{width:"100%",height:t.size+"px",left:0}),n?{[n]:0}:{}),"right"===n?{transform:"scaleX(-1)"}:"bottom"===n?{transform:"scaleY(-1)"}:{});return e.createElement("div",{className:"ms-edge"+(n?" "+n:""),style:Object.assign(Object.assign({},o),{opacity:r?1:0})})};c.displayName="Edge";var a=e.memo(c);const u=({activity:t,arrows:r,arrowType:n,handleArrow:o,size:l})=>{const s=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({position:"absolute",display:"flex",justifyContent:"center",alignItems:"center",cursor:"pointer",width:r.size+"px"},n?{[n]:0}:{}),"top"===n&&{transform:"rotate(-90deg) translateX(-100%)",transformOrigin:"left top"}),"bottom"===n&&{transform:"rotate(90deg) translateX(-100%)",transformOrigin:"left bottom"}),"left"===n&&{transform:"scaleX(-1)"}),["top","bottom"].includes(n)?{height:l+"px"}:{height:"100%",top:0});return e.createElement("div",{className:`ms-arrow-box ${n}${t?" active":""}`,style:Object.assign({},s),onClick:()=>o(n)},r.element)};u.displayName="Arrow";var d=e.memo(u);function m(e,t){return e>t?Math.floor(e/t):1}function h(e,t=0,r=1/0){return Math.max(t,Math.min(Math.round(e),r))}const p=(e,t,r)=>{if(!t)return;const n=t.querySelectorAll("."+("scroll"===e?"ms-thumb":"ms-slider"));n.length>0&&(r.current=n)},f=e=>e?"start"===e?"flex-start":"center"===e?"center":"flex-end":void 0;function g(e,t,r=0,n=0){return o=>{var l,s,i,c;const a={width:(null!==(l=o.width)&&void 0!==l?l:0)-r,height:(null!==(s=o.height)&&void 0!==s?s:0)-n};(null===(i=e.current)||void 0===i?void 0:i.width)===a.width&&(null===(c=e.current)||void 0===c?void 0:c.height)===a.height||(e.current=a,t())}}function y(t){const r=[],n=t=>{if(null===t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)r.push(t+"");else if("string"==typeof t)r.push(t);else if("function"==typeof t)r.push("<function>");else if(e.isValidElement(t))r.push("<react-node>");else if(Array.isArray(t))t.forEach(n);else if("object"==typeof t){const e=Object.entries(t).sort((([e],[t])=>e.localeCompare(t)));for(const[,t]of e)n(t)}else void 0===t&&r.push("<undefined>")};return n(t),r.join("/")}function b(e){var t,r,n;const o={x:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientX:e.mouseEvent.clientX,y:"touches"in e.mouseEvent?e.mouseEvent.touches[0].clientY:e.mouseEvent.clientY,leftover:null!==(r=null===(t=e.prevCoordsRef.current)||void 0===t?void 0:t.leftover)&&void 0!==r?r:0},l=null!==(n=e.prevCoordsRef.current)&&void 0!==n?n:o,s={x:o.x-l.x,y:o.y-l.y};e.prevCoordsRef.current=o;const i=t=>{if(!e.scrollElementRef||!e.objectsWrapperRef)return;let r=0;const n="x"===t?"movementX"in e.mouseEvent?e.mouseEvent.movementX:s.x:"movementY"in e.mouseEvent?e.mouseEvent.movementY:s.y,o=e.scrollElementRef;if("thumb"===e.clicked){const s=e.objectsWrapperRef,i=getComputedStyle(s),c="x"===t?o.clientWidth:o.clientHeight,a="x"===t?o.clientWidth-e.scrollBarEdge[0]:o.clientHeight-e.scrollBarEdge[1],u="x"===t?s.clientWidth+parseFloat(i.marginLeft)+parseFloat(i.marginRight):s.clientHeight+parseFloat(i.marginTop)+parseFloat(i.marginBottom),d=a-e.thumbSize,m=u-c;if(0>=d||0>=m)return;const h=n*(m/d)+l.leftover,p=Math.trunc(h),f=h-p;e.prevCoordsRef.current.leftover=f,r=p}else r=-n;"x"===t?(o.scrollLeft+=r,e.scrollStateRef.targetScrollX=o.scrollLeft):(o.scrollTop+=r,e.scrollStateRef.targetScrollY=o.scrollTop)},c=t=>{const r=e.objectsWrapperRef;if(!r)return;const n="slider"===e.type&&"wrapp"===e.clicked?-1:1,o=s[t]*n,l="x"===t?e.sizeLocal[0]:e.sizeLocal[1],i="x"===t?r.offsetWidth:r.offsetHeight,c="x"===t?e.scrollElementRef.scrollLeft:e.scrollElementRef.scrollTop;e.numForSliderRef.current+=Math.abs(o),e.numForSliderRef.current>6&&!e.isScrollingRef.current&&(o>0&&i>c+l?e.smoothScroll(c+l,t,e.duration):0>o&&c>0&&e.smoothScroll(c-l,t,e.duration),e.numForSliderRef.current=0)},a=t=>{"thumb"===e.clicked?i(t):"wrapp"===e.clicked?"slider"===e.type?c(t):i(t):"slider"===e.clicked&&c(t)};"hybrid"===e.direction?"wrapp"===e.clicked?(a("x"),a("y")):e.axisFromAtr&&a(e.axisFromAtr):a(e.direction||"y")}function v(e){if(e.controller.abort(),document.body.style.removeProperty("cursor"),["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),e.clickedObject.current="none",e.scrollBarOnHover){let t=e.mouseEvent.target,r=!1;for(;t&&t!==document.body;){if(t===e.scrollContentRef){r=!0;break}t=t.parentNode}r||e.mouseOnRefHandle(e.mouseEvent)}e.prevCoordsRef.current=null,e.triggerUpdate()}let x=0;const E={timeout:{tasks:[],timer:null},requestFrame:{tasks:[],rafId:null}},j={timeout:{scheduleNext(){const{tasks:e}=E.timeout;if(null!==E.timeout.timer&&(clearTimeout(E.timeout.timer),E.timeout.timer=null),0===e.length)return;const t=e[0],r=performance.now(),n=Math.max(0,t.runAt-r);E.timeout.timer=window.setTimeout((()=>{const t=performance.now(),r=[];for(;e.length&&e[0].runAt<=t;)r.push(e.shift());r.forEach((e=>e.callback())),j.timeout.scheduleNext()}),n)},clearAll(){null!==E.timeout.timer&&(clearTimeout(E.timeout.timer),E.timeout.timer=null),E.timeout.tasks=[]}},requestFrame:{scheduleNext(){const{tasks:e}=E.requestFrame;if(null!==E.requestFrame.rafId)return;if(0===e.length)return;const t=()=>{E.requestFrame.rafId=null;const r=performance.now(),n=[];for(;e.length&&e[0].runAt<=r;)n.push(e.shift());n.forEach((e=>e.callback())),e.length>0&&(E.requestFrame.rafId=requestAnimationFrame(t))};E.requestFrame.rafId=requestAnimationFrame(t)},clearAll(){null!==E.requestFrame.rafId&&(cancelAnimationFrame(E.requestFrame.rafId),E.requestFrame.rafId=null),E.requestFrame.tasks=[]}}},w=(e,t,r)=>{const n="task_"+x++,o="string"==typeof t?"requestFrame":"timeout";E[o].tasks=E[o].tasks.filter((e=>e.id!==n));const l="requestFrame"===o?performance.now():performance.now()+t,s={id:n,callback:e,runAt:l};let i=E[o].tasks.length;for(;i>0&&E[o].tasks[i-1].runAt>s.runAt;)i--;return E[o].tasks.splice(i,0,s),j[o].scheduleNext(),n},O="wrap-id";function S(e,t,r){return t?h(Math.round(e/t*e),r,e):0}function k(e,t,r,n){return t?h(e/t*(r-n),0,r-n):0}const R=e=>{e&&("grab"===e.style.cursor?(e.style.cursor="grabbing",e.classList.add("active")):"grabbing"===e.style.cursor&&(e.style.cursor="grab",e.classList.remove("active")))},M=({className:n,children:s,type:c="scroll",direction:u="y",scrollPosition:x,onScrollValue:E,isScrolling:M,size:A,objectsSize:z,crossCount:C,gap:L,wrapperMargin:T,wrapperMinSize:F,wrapperAlign:N,elementsAlign:I,elementsDirection:q="row",edgeGradient:B,progressTrigger:$={wheel:!0},progressReverse:W=!1,scrollBarOnHover:X=!1,scrollBarEdge:Y,thumbMinSize:H,render:P,emptyElements:D,suspending:K=!1,fallback:V})=>{var U,_,G,J,Q;const Z=function(){const e=t(null);return null===e.current&&(e.current=""+l++),e.current}();if(!A)throw Error(`Prop "size" is not provided\nMorphScroll〈♦${Z}〉`);Object.keys($).length;const[ee,te]=e.useState(0),re=()=>{te((e=>"number"==typeof e&&1e3>e?e+1:0))},ne=e.useRef(null),oe=e.useRef(null),le=e.useRef(null),se=e.useRef(null),ie=e.useRef([]),ce=e.useRef(null),ae=e.useRef("none"),ue=e.useRef({loaded:[],empty:[]}),de=e.useRef({targetScrollY:0,targetScrollX:0,animating:!1,animationFrameId:0}),me=e.useRef(!1),he=e.useRef(0),pe=e.useRef(null),fe=e.useRef(!1);function ge(){return e.useRef({width:0,height:0})}const ye=ge(),be=ge(),ve=ge(),[xe,Ee,je,we,Oe,Se,ke,Re,Me,Ae,ze]=function(...e){return e.map(y)}(null==x?void 0:x.value,P,A,z,D,F,N,L,$,ue.current.empty,Y),Ce=e.useMemo((()=>{var e,t;return{value:"number"==typeof(null==x?void 0:x.value)||"string"==typeof(null==x?void 0:x.value)?[x.value,x.value]:null!==(e=null==x?void 0:x.value)&&void 0!==e?e:[null],duration:null!==(t=null==x?void 0:x.duration)&&void 0!==t?t:200}}),[xe,null==x?void 0:x.duration]),Le={color:null,size:40},Te=e.useMemo((()=>"object"==typeof B?Object.assign(Object.assign({},Le),B):Le),[B]),Fe=e.useMemo((()=>Object.assign(Object.assign({},Le),"object"==typeof $.arrows?$.arrows:{})),[Me]),Ne=e.useCallback((t=>{if(null==t)return[];if(e.isValidElement(t)){const r=t;return r.type===e.Fragment?e.Children.toArray(r.props.children).flatMap(Ne):[r]}return[t]}),[]),Ie=e.useMemo((()=>e.Children.toArray(s).flatMap(Ne).map((t=>e.isValidElement(t)&&t.key?t.key+"":null)).filter((e=>null!==e)).filter((e=>{var t;return"clear"!==(null==D?void 0:D.mode)||!(null===(t=ue.current.empty)||void 0===t?void 0:t.includes(e))}))),[s,Ne,Oe,Ae]),[qe,Be,$e,We]=T?r(T):[0,0,0,0],Xe=qe+$e,Ye=We+Be,[He,Pe]=e.useMemo((()=>{var e,t;return"number"==typeof L?[L,L]:Array.isArray(L)?[null!==(e=L[1])&&void 0!==e?e:0,null!==(t=L[0])&&void 0!==t?t:0]:[0,0]}),[L]),De=e.useMemo((()=>r((null==P?void 0:P.rootMargin)||0,"x"===u)),[Ee,u]),[Ke,Ve]=De?[De[2],De[0]]:[0,0],Ue=e.useMemo((()=>{const[e,t]=Array.isArray(A)?A:"number"==typeof A?[A,A]:[ye.current.width,ye.current.height];if(!$.arrows||!Fe.size)return[e,t,e,t];const r=2*Fe.size;let n=e,o=t;return"x"===u?n=e-r:"y"===u?o=t-r:"hybrid"===u&&(n=e-r,o=t-r),[n,o,e,t]}),[je,Me,u,Fe.size,ye.current.height,ye.current.width]),_e="x"===u?Ue[0]:Ue[1],Ge=e.useMemo((()=>{if(!Y)return[0,0];if("number"==typeof Y){const e=2*Y;return[e,e]}if(Array.isArray(Y)){const[e=0,t]=Y;return[2*e,2*(null!=t?t:e)]}return[0,0]}),[ze]),Je="x"===u?Ge[0]:Ge[1],Qe=e.useMemo((()=>[Ue[0]-Ge[0],Ue[1]-Ge[1]]),[Ge.join(),Ue[0],Ue[1]]),Ze="x"===u?Qe[0]:Qe[1],et=e.useMemo((()=>z?Array.isArray(z)?z:r(z,!0,2):[null,null]),[we]),tt=e.useMemo((()=>{const e=(e,t)=>"number"==typeof e?e:"firstChild"===e?t:0;return[e(et[0]&&"none"!==et[0]&&"size"!==et[0]?et[0]:"y"===u&&"none"!==et[0]||"size"===et[0]?Ue[0]:0,ve.current.width),e(et[1]&&"none"!==et[1]&&"size"!==et[1]?et[1]:"x"===u&&"none"!==et[1]||"size"===et[1]?Ue[1]:0,ve.current.height)]}),[et.join(),u,ve.current.width,ve.current.height,Ue.join()]),rt=e.useMemo((()=>{const e="x"===u,t="row"===q,r="column"===q,n=e?Ue[1]:Ue[0],o=e?tt[1]+Pe:tt[0]+He,l="hybrid"===u?o*(Ie.length+1)-o:n,s=Math.floor(l/o)||1,i=C&&s>=C?"hybrid"===u?Math.ceil(s/C):C:s,c=i>1&&i<Ie.length?Math.ceil(Ie.length/i):i>Ie.length?1:Ie.length,a=C&&C<Ie.length,d=e=>Number.isFinite(e)&&e>0?e:1;if("hybrid"===u){const e=a?t?C:i:t?Ie.length:1,n=a?r?C:i:r?Ie.length:1;return[d(e),d(n)]}return[d(i),d(c)]}),[q,Pe,He,tt.join(),Ie.length,u,Ue.join(),C]),nt=e.useMemo((()=>{const e=rt[0]?rt[0]*Pe-Pe:0,t="x"===u?rt[1]:rt[0];return tt[0]?(tt[0]+Pe)*t-Pe:(null==P?void 0:P.type)?ve.current.width+e:be.current.width}),[u,tt[0],rt.join(),Pe,be.current.width,ve.current.width,null==P?void 0:P.type]),ot=e.useMemo((()=>{const e=1>rt[1]?1:rt[0]*He-He;return tt[1]?"x"===u?(tt[1]+He)*rt[0]-He:(tt[1]+He)*rt[1]-He:(null==P?void 0:P.type)?ve.current.height+e:be.current.height}),[u,tt[1],rt.join(),He,be.current.height,ve.current.height,null==P?void 0:P.type]),lt=e.useMemo((()=>ot+Xe),[ot,Xe]),st=e.useMemo((()=>nt+Ye),[nt,Ye]),it="x"===u?st:lt,ct="x"===u?(null===(U=le.current)||void 0===U?void 0:U.scrollLeft)||0:(null===(_=le.current)||void 0===_?void 0:_.scrollTop)||0,at=ct>1&&!0,ut=it>Math.round(ct+_e);let dt=!1,mt=!1;"hybrid"===u&&(dt=((null===(G=le.current)||void 0===G?void 0:G.scrollLeft)||0)>1&&!0,mt=Math.round(((null===(J=le.current)||void 0===J?void 0:J.scrollLeft)||0)+Ue[0])<st);const ht=e.useMemo((()=>null!=H?H:30),[H]),pt=e.useCallback((({withLimit:e=!0,xSize:t})=>$.progressElement&&it?t?S(e?Qe[0]:Ue[0],e?st-Ge[0]:st,ht):S(e?Ze:_e,e?it-Je:it,ht):0),[Me,it,Ze,Je,Ge[0],_e,Ue[0],Qe[0],st,ht]),ft=e.useMemo((()=>_e?it-_e:it),[it,_e]),gt=e.useMemo((()=>Ue[0]?st-Ue[0]:st),[st,Ue[0]]),yt=e.useCallback((()=>{if(!(null==P?void 0:P.type)||1>=rt[0])return[];const e=Array.from({length:Ie.length},((e,t)=>t)),t=Array.from({length:rt[0]},(()=>[])),r="x"===u&&"column"===q||"x"!==u&&"row"===q;return e.forEach((e=>{const n=r?e%rt[0]:Math.floor(e/rt[1]);t[n]&&t[n].push(e)})),t}),[Ie.length,rt.join(),null==P?void 0:P.type,q,u]),bt=e.useMemo((()=>{if(!(null==P?void 0:P.type))return[{elementTop:0,elementBottom:0,left:0,right:0}];let e=[],t=0;if(I){const r=Array.from({length:Ie.length},((e,t)=>t)),n=Math.abs(Math.floor(Ie.length/rt[0])*rt[0]-Ie.length);e=n?r.slice(-n):[],"center"===I?t=(tt[0]+Pe)*(rt[0]-n)/2:"end"===I&&(t=(tt[0]+Pe)*(rt[0]-n))}return Ie.map(((r,n)=>{const o=function(e,t){for(let r=0;r<t.length;r++){const n=t[r].indexOf(e);if(-1!==n)return["x"===u?n:r,["hybrid","y"].includes(u)?n:r]}return[0,0]}(n,yt()),l=e.length>0&&e.includes(n)?t:0,s=function(e){const t="x"===u?l:0;return e>0?t+(tt[1]+He)*e:t}(rt[0]>1||["hybrid","x"].includes(u)?o[1]:n),i=tt[1]?s+tt[1]:s,c=function(e){const t="x"===u?0:l;return e>0?t+(tt[0]+Pe)*e:t}(1===rt[0]&&"x"===u?n:o[0]);return{elementTop:s,elementBottom:i,left:c,right:c+tt[0]}}))}),[u,rt[0],tt.join(),He,Pe,null==P?void 0:P.type,q,I,yt,Ie.join()]),vt=e.useMemo((()=>(null==Ue?void 0:Ue.length)&&N?function(e,t,r,n){const[o,l="start"]="string"==typeof e?[e,e]:e,s={display:"flex"};return t[0]>r&&(s.justifyContent=f(o)),t[1]>n&&(s.alignItems=f(l)),s}(N,Ue,st,lt):{}),[N,Ue.join(),lt,st]),xt=e.useMemo((()=>[m(st,Ue[0]),m(lt,Ue[1])]),[st,lt,Ue.join()]),Et=e.useMemo((()=>"x"===u?xt[0]:xt[1]),[u,xt[0],xt[1]]),jt=e.useCallback(g(ye,re),[ye.current.height,ye.current.width]),wt=e.useCallback(g(be,re,Ye,Xe),[be.current.height,be.current.width,Ye,Xe]),Ot=e.useCallback(g(ve,re),[ve.current.height,ve.current.width]),St=e.useCallback(((e,t,r,n)=>{const o=le.current;return o?function(e,t,r,n,o){let l;if(!t&&!n)return null;const s=performance.now(),i=t.scrollTop,c=t.scrollLeft,a=u=>{const d=Math.min((u-s)/r,1);"y"===e?t.scrollTop=i+(n-i)*d:"x"===e&&(t.scrollLeft=c+(n-c)*d),1>d?l=requestAnimationFrame(a):null==o||o()};return l=requestAnimationFrame(a),()=>cancelAnimationFrame(l)}(t,o,r,e,n):null}),[]),kt=e.useCallback(((e,t,r)=>{if(ce.current){if(ce.current!==Ie[0])return void(ce.current=Ie[0])}else ce.current=Ie[0];const n=St(t,e,Ce.duration);n&&r.push(n)}),[Ie[0],Ce.duration,St]),Rt=e.useMemo((()=>{const e=Object.assign(Object.assign(Object.assign(Object.assign({margin:T?`${qe}px ${Be}px ${$e}px ${We}px`:"",height:et[1]&&"none"!==et[1]?ot+"px":"fit-content",width:et[0]&&"none"!==et[0]?nt+"px":"fit-content"},$.content&&{cursor:"grab"}),L&&!(null==P?void 0:P.type)&&{gap:`${He}px ${Pe}px`}),F&&function(e,t,r,n,o){const l=(e,t)=>"full"===e?("x"===t?r[0]:r[1])-("x"===t?n:o):e;if("hybrid"!==t&&!Array.isArray(e)){const r=l(e,t)+"px";return"x"===t?{minWidth:r}:{minHeight:r}}let s,i;return Array.isArray(e)?[s,i]=e:s=i=e,{minWidth:l(s,"x")+"px",minHeight:l(i,"y")+"px"}}(F,u,Ue,Ye,Xe)),N&&{flexShrink:0});if(null==P?void 0:P.type)return Object.assign(Object.assign({},e),{position:"relative"});const t=et[1]?"wrap":void 0,r=1===rt[0]?"y"===u?"column":"row":q;return Object.assign(Object.assign({},e),{display:"flex",flexDirection:r,flexWrap:t,justifyContent:f(I)})}),[T,ke,Se,[qe,Be,$e,We,Ye,Xe,He,Pe].join(),Ue.join(),Re,et[1],ot,nt,$.content,Re,null==P?void 0:P.type,u,rt[0],q,I]),Mt=e.useCallback((e=>{if(!X)return;const t=()=>((e,t,r)=>{e&&e.querySelectorAll(".ms-bar").forEach(((e,t)=>{const n=e;["mouseleave","mouseup","touchend"].includes(r.type)?(n.style.opacity="0",n.classList.remove("hover"),n.classList.add("leave"),w((()=>n.classList.remove("leave")),200)):(n.style.opacity="1",n.classList.add("hover"))}))})(oe.current,0,e);"mouseleave"===e.type?!["thumb","slider","wrapp"].includes(ae.current)&&t():t()}),[X]),At=e.useCallback(((e,t="mousedown",r)=>{const n=e||("scroll"===c?"thumb":"slider");if("wrapp"===e&&!$.content||["thumb","slider"].includes(n)&&!$.progressElement)return;p(c,ne.current,ie);let o=null;r&&(o=r.getAttribute("data-direction")),function(e){const t=new AbortController,{signal:r}=t;e.clickedObject.current=e.clicked,e.triggerUpdate(),"mousedown"===e.eventType?(["thumb","slider"].includes(e.clicked)&&e.mouseOnEl(e.scrollBar),"wrapp"===e.clicked&&e.mouseOnEl(e.objectsWrapperRef),document.addEventListener("mousemove",(t=>b(Object.assign(Object.assign({},e),{mouseEvent:t}))),{signal:r}),document.addEventListener("mouseup",(r=>v(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})):"touchstart"===e.eventType&&(document.addEventListener("touchmove",(t=>{t.preventDefault(),b(Object.assign(Object.assign({},e),{mouseEvent:t}))}),{signal:r,passive:!1}),document.addEventListener("touchend",(r=>v(Object.assign(Object.assign({},e),{mouseEvent:r,controller:t}))),{signal:r})),document.body.style.cursor="grabbing"}({eventType:t,scrollElementRef:le.current,objectsWrapperRef:se.current,scrollBar:r||null,clickedObject:ae,scrollContentRef:oe.current,scrollStateRef:de.current,type:c,scrollBarOnHover:X,mouseOnEl:R,mouseOnRefHandle:Mt,triggerUpdate:re,direction:u,smoothScroll:St,sizeLocal:[Ue[0],Ue[1]],clicked:n,numForSliderRef:he,isScrollingRef:me,prevCoordsRef:pe,thumbSize:pt("x"===o?{xSize:!0}:{}),axisFromAtr:o,duration:Ce.duration,scrollBarEdge:Ge})}),[u,c,$.content,$.progressElement,Ue.join(),pt({}),pt({xSize:!0}),Ce.duration,St,Mt,X,Ge.join()]),zt=e.useCallback((e=>{At(null,e.type,e.target)}),[At]),Ct=e.useCallback((()=>{At("wrapp")}),[At]),Lt=e.useCallback((e=>{le.current&&(({arrowType:e,scrollElement:t,wrapSize:r,scrollSize:n,smoothScroll:o,duration:l})=>{const s=r[0],i=r[1],c=t.scrollTop,a=t.scrollLeft,u=["top","bottom"].includes(e)?i:s,d=(e,t)=>o(h(e,0,u),t,l);"top"===e&&c>0?d(c-n[1],"y"):"left"===e&&a>0&&d(a-n[0],"x"),"bottom"===e&&c+n[1]!==i?d(c+n[1],"y"):"right"===e&&a+n[0]!==s&&d(a+n[0],"x")})({arrowType:e,scrollElement:le.current,wrapSize:[st,lt],scrollSize:Ue,smoothScroll:St,duration:Ce.duration})}),[Ue.join(),st,lt,Ce.duration,St]),Tt=e.useCallback((()=>{p(c,ne.current,ie);const e=le.current;oe.current&&e&&0!==ie.current.length&&((e,t,r,n)=>{!function(){var o,l,s,i;const c=null!==(l=null===(o=t[0])||void 0===o?void 0:o.querySelectorAll(".ms-slider-element"))&&void 0!==l?l:[],a=null!==(i=null===(s=t[1])||void 0===s?void 0:s.querySelectorAll(".ms-slider-element"))&&void 0!==i?i:[];function u(e,t,r,n){const o="x"===n?r.scrollLeft:r.scrollTop;e.forEach(((e,r)=>{const l="x"===n?t[0]:t[1];o>=l*r&&l*(r+1)>o?e.classList.add("active"):e.classList.remove("active")}))}c.length>0&&u(c,r,e,n),a.length>0&&u(a,r,e,"x")}()})(e,ie.current,Ue,u)}),[Ue.join(),u,le,oe,c]),Ft=e.useCallback((()=>{ne.current&&((e,t,r,n)=>{const{allIds:o,emptyKeysRaw:l}=(()=>{const t=[],r=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e instanceof Element&&e.hasAttribute(O)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const e=o,l=e.getAttribute(O);l&&(t.push(l),0===e.children.length&&r.push(l)),o=n.nextNode()}return{allIds:t,emptyKeysRaw:r}})(),s=new Set(t.current.loaded);o.forEach((e=>s.add(e)));let i=null;if(t.current.empty){const e=new Set(t.current.empty);l.forEach((t=>e.add(t))),i=Array.from(e)}t.current={loaded:"lazy"===n?Array.from(s):o.map((e=>e)),empty:i},r()})(ne.current,ue,re,null==P?void 0:P.type)}),[Ee]),Nt=e.useCallback((e=>{(null==D?void 0:D.clickTrigger)&&((e,t,r)=>{const n=e.target;if(!n.closest(t.selector))return;const o=n.closest(`[${O}]`);o&&o.classList.add("remove"),w((()=>{o&&o.classList.remove("remove"),r()}),t.delay||0)})(e,D.clickTrigger,Ft)}),[Oe,Ft]),It=e.useCallback((()=>{w((()=>{const e=le.current;e&&(null==E||E(e.scrollLeft,e.scrollTop),me.current=!0,null==M||M(!0),w((()=>{me.current=!1,null==M||M(!1),Ft()}),200),"slider"===c&&w((()=>Tt()),33),re())}),6)}),[E,M,c,Tt,Ft]),qt=k(ct,ft,Ze,pt({})),Bt=k((null===(Q=le.current)||void 0===Q?void 0:Q.scrollLeft)||0,gt,Qe[0],pt({xSize:!0})),$t=e.useCallback((e=>{const t="object"==typeof $.wheel&&"string"==typeof $.wheel.changeDirectionKey?$.wheel.changeDirectionKey:"KeyX";e.code!==t||"hybrid"!==u||fe.current||(e.stopPropagation(),fe.current=!0,re())}),[u,JSON.stringify($.wheel)]),Wt=e.useCallback((e=>{fe.current&&(e.stopPropagation(),fe.current=!1,re())}),[]);e.useEffect((()=>{(D||(null==P?void 0:P.type))&&(D||null===ue.current.empty||(ue.current.empty=null),Ft())}),[Oe,null==P?void 0:P.type,Ft]),e.useEffect((()=>{const e=de.current.animationFrameId;return((null==P?void 0:P.type)||M)&&M&&(M(!1),re()),Tt(),()=>{e&&cancelAnimationFrame(e),["timeout"].forEach((e=>j[e].clearAll()))}}),[]),e.useEffect((()=>{const e=le.current;if(!e)return;const t=e=>e.preventDefault(),r="hybrid"===u&&"object"==typeof $.wheel&&$.wheel.changeDirection?"x":u,n="hybrid"===u&&ot+Xe<=Ue[1]||fe.current?["hybrid","y"].includes(r)?"x":"y":r,o=$.wheel?e=>{t(e),function(e,t,r){const n=e.target.closest(".ms-element");n.matches(":focus")||n.focus(),t.animating||(t.targetScrollX=n.scrollLeft,t.targetScrollY=n.scrollTop),"x"===r?t.targetScrollX=h(t.targetScrollX+e.deltaY,0,n.scrollWidth-n.clientWidth+2):t.targetScrollY=h(t.targetScrollY+e.deltaY,0,n.scrollHeight-n.clientHeight+2),t.animating||(t.animating=!0,t.animationFrameId=requestAnimationFrame((function e(){let o=0;"x"===r?(n.scrollLeft+=.4*(t.targetScrollX-n.scrollLeft),o=Math.abs(n.scrollLeft-t.targetScrollX)):(n.scrollTop+=.4*(t.targetScrollY-n.scrollTop),o=Math.abs(n.scrollTop-t.targetScrollY)),o>2.5?t.animationFrameId=requestAnimationFrame(e):(t.animating=!1,null!==t.animationFrameId&&(cancelAnimationFrame(t.animationFrameId),t.animationFrameId=null))})))}(e,de.current,n)}:t;return e.addEventListener("wheel",o,{passive:!1}),()=>{e.removeEventListener("wheel",o)}}),[u,Me,ot,Ue[1],Xe,fe.current]),e.useEffect((()=>{if(!Ce.value)return;const e=[];return("hybrid"===u?["x","y"]:[u]).forEach((t=>{const r="x"===t?0:1;"end"===Ce.value[r]&&kt(t,"x"===t?gt:ft,e)})),()=>{e.forEach((e=>e()))}}),[u,Ce.value.join(),xe,ft,gt,st,lt]),e.useEffect((()=>{if(!Ce.value)return;const e=[];return("hybrid"===u?["x","y"]:[u]).forEach((t=>{const r="x"===t?0:1;"number"==typeof Ce.value[r]&&kt(t,Ce.value[r],e)})),()=>{e.forEach((e=>e()))}}),[xe,null==x?void 0:x.updater,u,kt,Ce.value.join()]);const Xt=e.useCallback(((t,r,n,o)=>{var l;const s=Object.assign({width:tt[0]?tt[0]+"px":void 0,height:tt[1]?tt[1]+"px":void 0},(null==P?void 0:P.type)&&Object.assign({position:"absolute",top:r+"px",left:n+"px"},!tt[0]&&1===rt[0]&&{transform:"translateX(-50%)"})),i=K?e.createElement(e.Suspense,{fallback:V},o):o,c=(null===(l=null==D?void 0:D.clickTrigger)||void 0===l?void 0:l.selector)&&Nt;return e.createElement("div",Object.assign({key:t},P||D?{[O]:""+t}:{},{className:"ms-object-box",style:s,onClick:c}),i)}),[K,!!V,tt.join(),Ee,Oe,rt[0],Nt]),Yt=e.useMemo((()=>[{positionType:"x"===u?"left":"top",visibility:at},{positionType:"x"===u?"right":"bottom",visibility:ut},..."hybrid"===u?[{positionType:"left",visibility:dt},{positionType:"right",visibility:mt}]:[]]),[at,ut,u,dt,mt]),Ht=e.useMemo((()=>({width:Ue[2]+"px",height:Ue[3]+"px"})),[Ue]),Pt=e.useMemo((()=>[{shouldRender:pt({withLimit:!1})<_e,direction:u,thumbSize:pt({}),thumbSpace:qt,objLengthPerSize:Et,progressReverseIndex:0},{shouldRender:"hybrid"===u&&pt({withLimit:!1,xSize:!0})<Qe[0],direction:"x",thumbSize:pt({xSize:!0}),thumbSpace:Bt,objLengthPerSize:xt[0],progressReverseIndex:1}].filter((({shouldRender:e})=>e))),[pt,Ze,u,Qe[0],qt,Bt,Et,xt]),Dt=e.useMemo((()=>{const e={position:"relative",width:Ue[0]+"px",height:Ue[1]+"px"};return $.arrows&&Fe.size&&("x"===u?e.left=Fe.size+"px":"y"===u?e.top=Fe.size+"px":(e.top=Fe.size+"px",e.left=Fe.size+"px")),e}),[Ue,Me,Fe.size,u]),Kt=e.useMemo((()=>{var e;return null!==(e={x:st>Ue[0]?"scroll hidden":"hidden",y:lt>Ue[1]?"hidden scroll":"hidden",hybrid:`${st>Ue[0]?"scroll":"hidden"} ${lt>Ue[1]?"scroll":"hidden"}`,hide:"hidden"}[$.wheel||$.content?u:"hide"])&&void 0!==e?e:"hidden"}),[st,lt,Ue[0],Ue[1],Me,u]),Vt=e.useMemo((()=>B?Yt.map((({positionType:t,visibility:r})=>e.createElement(a,{key:"edge-"+t,edgeGradient:Te,visibility:r,edgeType:t}))):null),[B,Yt,Te]),Ut=e.useMemo((()=>$.arrows?Yt.map((({positionType:t,visibility:r})=>e.createElement(d,{key:"arrow-"+t,activity:r,arrows:Fe,arrowType:t,handleArrow:Lt,size:"hybrid"===u?Ue[0]+2*Fe.size:Ue[0]}))):null),[$.arrows,Yt,Fe,Lt,Ue[0],u]),_t=e.useMemo((()=>$.progressElement&&!0!==$.progressElement?Pt.map((t=>{const r="boolean"==typeof W?W:W[t.progressReverseIndex];return e.createElement(i,{key:t.direction+"",type:c,direction:t.direction,progressReverse:r,size:Qe,progressTrigger:$,scrollBarOnHover:X,scrollBarEvent:"sliderMenu"===c?St:zt,thumbSize:t.thumbSize,thumbSpace:t.thumbSpace,objLengthPerSize:t.objLengthPerSize,sliderCheckLocal:Tt,duration:Ce.duration})})):null),[$.progressElement,Pt,c,W,Qe,$,X,St,zt,Tt,Ce.duration]),Gt=e.createElement("div",{className:"ms-objects-wrapper",ref:se,onMouseDown:Ct,style:Rt},Ie.map(((t,r)=>{var n,l,i;const c=e.Children.toArray(s).find((r=>e.isValidElement(r)&&r.key===t)),a=(null==P?void 0:P.stopLoadOnScroll)&&me.current&&!ue.current.loaded.includes(""+t)?V:(null===(n=ue.current.empty)||void 0===n?void 0:n.includes(t))?"object"==typeof(null==D?void 0:D.mode)?D.mode.fallback:V:c,d="number"==typeof et[0]&&"number"==typeof et[1]||"firstChild"!==et[0]&&"firstChild"!==et[1]||0!==r?a:e.createElement(o,{onResize:Ot},a);if(!(null==P?void 0:P.type))return Xt(t,0,0,d);{const{elementTop:e,elementBottom:n,left:o,right:s}=bt[r],c="x"===u?Ke:Ve,a=_e+c>("x"===u?o:e)-ct&&("x"===u?s:n)-ct>0-c,m="hybrid"!==u||Ue[0]+Ke>o-((null===(l=le.current)||void 0===l?void 0:l.scrollLeft)||0)&&s-((null===(i=le.current)||void 0===i?void 0:i.scrollLeft)||0)>0-Ke;if(a&&m)return Xt(t,e,o,d)}}))),Jt=e.createElement("div",{"morph-scroll":`〈♦${Z}〉`,className:n,ref:ne,style:Ht},e.createElement("div",{className:"ms-content",ref:oe,onMouseEnter:Mt,onMouseLeave:Mt,onTouchStart:Mt,onTouchEnd:Mt,style:Dt},e.createElement("div",{className:"ms-element",ref:le,onScroll:It,onKeyDown:$t,onKeyUp:Wt,style:Object.assign(Object.assign(Object.assign({width:"100%",height:"100%",outline:"none"},vt),{overflow:Kt}),"scroll"!==c||"boolean"!=typeof $.progressElement||!1===$.progressElement?{scrollbarWidth:"none"}:{})},tt[0]&&tt[1]?Gt:e.createElement(o,{onResize:wt,style:vt},Gt)),Vt,_t),Ut);return"auto"===A?e.createElement(o,{measure:"outer",onResize:jt},Jt):Jt};M.displayName="MorphScroll";const A={MorphScroll:M,ResizeTracker:o,IntersectionTracker:n};export{n as IntersectionTracker,M as MorphScroll,o as ResizeTracker,A as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "morphing-scroll",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "React library for custom object scrolling and scrollbar styling",
5
5
  "author": "Georg Schilin",
6
6
  "license": "MIT",