compute-scroll-into-view.min.js 2.63 KB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).computeScrollIntoView=t()}(this,function(){function e(e){return null!=e&&"object"==typeof e&&1===e.nodeType}function t(e,t){return(!t||"hidden"!==e)&&"visible"!==e&&"clip"!==e}function n(e,n){if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){var r=getComputedStyle(e,null);return t(r.overflowY,n)||t(r.overflowX,n)||function(e){var t=function(e){if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch(e){return null}}(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)}(e)}return!1}function r(e,t,n,r,i,o,l,d){return o<e&&l>t||o>e&&l<t?0:o<=e&&d<=n||l>=t&&d>=n?o-e-r:l>t&&d<n||o<e&&d>n?l-t+i:0}return function(t,i){var o=window,l=i.scrollMode,d=i.block,u=i.inline,f=i.boundary,c=i.skipOverflowHiddenElements,h="function"==typeof f?f:function(e){return e!==f};if(!e(t))throw new TypeError("Invalid target");for(var a=document.scrollingElement||document.documentElement,s=[],p=t;e(p)&&h(p);){if((p=p.parentNode)===a){s.push(p);break}p===document.body&&n(p)&&!n(document.documentElement)||n(p,c)&&s.push(p)}for(var m=o.visualViewport?o.visualViewport.width:innerWidth,g=o.visualViewport?o.visualViewport.height:innerHeight,w=window.scrollX||pageXOffset,v=window.scrollY||pageYOffset,b=t.getBoundingClientRect(),W=b.height,y=b.width,H=b.top,M=b.right,V=b.bottom,x=b.left,E="start"===d||"nearest"===d?H:"end"===d?V:H+W/2,I="center"===u?x+y/2:"end"===u?M:x,C=[],T=0;T<s.length;T++){var k=s[T],B=k.getBoundingClientRect(),D=B.height,O=B.width,R=B.top,S=B.right,X=B.bottom,Y=B.left;if("if-needed"===l&&H>=0&&x>=0&&V<=g&&M<=m&&H>=R&&V<=X&&x>=Y&&M<=S)return C;var j=getComputedStyle(k),L=parseInt(j.borderLeftWidth,10),N=parseInt(j.borderTopWidth,10),q=parseInt(j.borderRightWidth,10),z=parseInt(j.borderBottomWidth,10),A=0,F=0,G="offsetWidth"in k?k.offsetWidth-k.clientWidth-L-q:0,J="offsetHeight"in k?k.offsetHeight-k.clientHeight-N-z:0;if(a===k)A="start"===d?E:"end"===d?E-g:"nearest"===d?r(v,v+g,g,N,z,v+E,v+E+W,W):E-g/2,F="start"===u?I:"center"===u?I-m/2:"end"===u?I-m:r(w,w+m,m,L,q,w+I,w+I+y,y),A=Math.max(0,A+v),F=Math.max(0,F+w);else{A="start"===d?E-R-N:"end"===d?E-X+z+J:"nearest"===d?r(R,X,D,N,z+J,E,E+W,W):E-(R+D/2)+J/2,F="start"===u?I-Y-L:"center"===u?I-(Y+O/2)+G/2:"end"===u?I-S+q+G:r(Y,S,O,L,q+G,I,I+y,y);var K=k.scrollLeft,P=k.scrollTop;E+=P-(A=Math.max(0,Math.min(P+A,k.scrollHeight-D+J))),I+=K-(F=Math.max(0,Math.min(K+F,k.scrollWidth-O+G)))}C.push({el:k,top:A,left:F})}return C}});
//# sourceMappingURL=compute-scroll-into-view.min.js.map