1 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).computeScrollIntoView=t()}(this,function(){function e(e){return"object"==typeof e&&null!=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 i=getComputedStyle(e,null);return t(i.overflowY,n)||t(i.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 i(e,t,n,i,r,o,l,d){return o<e&&l>t||o>e&&l<t?0:o<=e&&d<=n||l>=t&&d>=n?o-e-i:l>t&&d<n||o<e&&d>n?l-t+r:0}return function(t,r){var o=window,l=r.scrollMode,d=r.block,u=r.inline,f=r.boundary,c=r.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.parentElement)===a){s.push(p);break}null!=p&&p===document.body&&n(p)&&!n(document.documentElement)||null!=p&&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(),y=b.height,W=b.width,H=b.top,E=b.right,M=b.bottom,V=b.left,x="start"===d||"nearest"===d?H:"end"===d?M:H+y/2,I="center"===u?V+W/2:"end"===u?E:V,T=[],C=0;C<s.length;C++){var k=s[C],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&&V>=0&&M<=g&&E<=m&&H>=R&&M<=X&&V>=Y&&E<=S)return T;var j=getComputedStyle(k),L=parseInt(j.borderLeftWidth,10),q=parseInt(j.borderTopWidth,10),z=parseInt(j.borderRightWidth,10),A=parseInt(j.borderBottomWidth,10),F=0,G=0,J="offsetWidth"in k?k.offsetWidth-k.clientWidth-L-z:0,K="offsetHeight"in k?k.offsetHeight-k.clientHeight-q-A:0;if(a===k)F="start"===d?x:"end"===d?x-g:"nearest"===d?i(v,v+g,g,q,A,v+x,v+x+y,y):x-g/2,G="start"===u?I:"center"===u?I-m/2:"end"===u?I-m:i(w,w+m,m,L,z,w+I,w+I+W,W),F=Math.max(0,F+v),G=Math.max(0,G+w);else{F="start"===d?x-R-q:"end"===d?x-X+A+K:"nearest"===d?i(R,X,D,q,A+K,x,x+y,y):x-(R+D/2)+K/2,G="start"===u?I-Y-L:"center"===u?I-(Y+O/2)+J/2:"end"===u?I-S+z+J:i(Y,S,O,L,z+J,I,I+W,W);var N=k.scrollLeft,P=k.scrollTop;x+=P-(F=Math.max(0,Math.min(P+F,k.scrollHeight-D+K))),I+=N-(G=Math.max(0,Math.min(N+G,k.scrollWidth-O+J)))}T.push({el:k,top:F,left:G})}return T}});
|