Socket
Socket
Sign inDemoInstall

scroll-into-view-if-needed

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-into-view-if-needed - npm Package Compare versions

Comparing version 2.2.1 to 2.2.2

51

compute.js

@@ -7,15 +7,7 @@ "use strict";

var isElement = function isElement(el) {
return el != null && typeof el == 'object' && el.nodeType === 1;
return el != null && typeof el == 'object' && (el.nodeType === 1 || el.nodeType === 11);
};
var hasScrollableSpace = function hasScrollableSpace(el, axis) {
if (axis === 'Y') {
return el.clientHeight < el.scrollHeight;
}
if (axis === 'X') {
return el.clientWidth < el.scrollWidth;
}
return false;
return axis === 'X' ? el.clientWidth < el.scrollWidth : el.clientHeight < el.scrollHeight;
};

@@ -37,3 +29,3 @@

var alignNearest = function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, elementEdgeStart, elementEdgeEnd, elementSize) {
var alignNearest = function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, scrollingBorderStart, scrollingBorderEnd, elementEdgeStart, elementEdgeEnd, elementSize) {
if (elementEdgeStart < scrollingEdgeStart && elementEdgeEnd > scrollingEdgeEnd || elementEdgeStart > scrollingEdgeStart && elementEdgeEnd < scrollingEdgeEnd) {

@@ -44,7 +36,7 @@ return 0;

if (elementEdgeStart < scrollingEdgeStart && elementSize < scrollingSize || elementEdgeEnd > scrollingEdgeEnd && elementSize > scrollingSize) {
return elementEdgeStart - scrollingEdgeStart;
return elementEdgeStart - scrollingEdgeStart - scrollingBorderStart;
}
if (elementEdgeEnd > scrollingEdgeEnd && elementSize < scrollingSize || elementEdgeStart < scrollingEdgeStart && elementSize > scrollingSize) {
return elementEdgeEnd - scrollingEdgeEnd;
return elementEdgeEnd - scrollingEdgeEnd + scrollingBorderEnd;
}

@@ -83,3 +75,3 @@

while (isElement(parent = target.parentNode) && checkBoundary(target)) {
while (isElement(parent = target.parentNode || target.host) && checkBoundary(target)) {
if (isScrollable(parent, skipOverflowHiddenElements) || parent === viewport) {

@@ -131,2 +123,7 @@ frames.push(parent);

var frameRect = frame.getBoundingClientRect();
var frameStyle = getComputedStyle(frame);
var borderLeft = parseInt(frameStyle.borderLeftWidth, 10);
var borderTop = parseInt(frameStyle.borderTopWidth, 10);
var borderRight = parseInt(frameStyle.borderRightWidth, 10);
var borderBottom = parseInt(frameStyle.borderBottomWidth, 10);
var blockScroll = 0;

@@ -144,4 +141,3 @@ var inlineScroll = 0;

var offset = Math.min(targetBlock - frameRect.top, frame.scrollHeight - frame.clientHeight - frame.scrollTop);
blockScroll = frame.scrollTop + offset;
targetBlock -= blockScroll - frame.scrollTop;
blockScroll = frame.scrollTop + offset - borderTop;
}

@@ -161,3 +157,2 @@ }

blockScroll = frame.scrollTop + _offset;
targetBlock += frame.scrollTop - blockScroll;
}

@@ -176,4 +171,3 @@ }

blockScroll = frame.scrollTop + _offset2;
targetBlock += frame.scrollTop - blockScroll;
blockScroll = frame.scrollTop + _offset2 + borderBottom;
}

@@ -188,10 +182,9 @@ }

if (viewport === frame) {
var _offset3 = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, viewportY + targetBlock, viewportY + targetBlock + targetRect.height, targetRect.height);
var _offset3 = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, borderTop, borderBottom, viewportY + targetBlock, viewportY + targetBlock + targetRect.height, targetRect.height);
blockScroll = viewportY + _offset3;
} else {
var _offset4 = alignNearest(frameRect.top, frameRect.bottom, frameRect.height, targetBlock, targetBlock + targetRect.height, targetRect.height);
var _offset4 = alignNearest(frameRect.top, frameRect.bottom, frameRect.height, borderTop, borderBottom, targetBlock, targetBlock + targetRect.height, targetRect.height);
blockScroll = frame.scrollTop + _offset4;
targetBlock -= _offset4;
}

@@ -210,4 +203,3 @@ }

inlineScroll = frame.scrollLeft + _offset5;
targetInline -= inlineScroll - frame.scrollLeft;
inlineScroll = frame.scrollLeft + _offset5 - borderLeft;
}

@@ -227,3 +219,2 @@ }

inlineScroll = frame.scrollLeft + _offset6;
targetInline += frame.scrollLeft - inlineScroll;
}

@@ -242,4 +233,3 @@ }

inlineScroll = frame.scrollLeft + _offset7;
targetInline += frame.scrollLeft - inlineScroll;
inlineScroll = frame.scrollLeft + _offset7 + borderRight;
}

@@ -254,13 +244,14 @@ }

if (viewport === frame) {
var _offset8 = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, viewportX + targetInline, viewportX + targetInline + targetRect.width, targetRect.width);
var _offset8 = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, borderLeft, borderRight, viewportX + targetInline, viewportX + targetInline + targetRect.width, targetRect.width);
inlineScroll = viewportX + _offset8;
} else {
var _offset9 = alignNearest(frameRect.left, frameRect.right, frameRect.width, targetInline, targetInline + targetRect.width, targetRect.width);
var _offset9 = alignNearest(frameRect.left, frameRect.right, frameRect.width, borderLeft, borderRight, targetInline, targetInline + targetRect.width, targetRect.width);
inlineScroll = frame.scrollLeft + _offset9;
targetInline -= _offset9;
}
}
targetBlock += frame.scrollTop - blockScroll;
targetInline += frame.scrollLeft - inlineScroll;
return {

@@ -267,0 +258,0 @@ el: frame,

var isElement = function isElement(el) {
return el != null && typeof el == 'object' && el.nodeType === 1;
return el != null && typeof el == 'object' && (el.nodeType === 1 || el.nodeType === 11);
};
var hasScrollableSpace = function hasScrollableSpace(el, axis) {
if (axis === 'Y') {
return el.clientHeight < el.scrollHeight;
}
if (axis === 'X') {
return el.clientWidth < el.scrollWidth;
}
return false;
return axis === 'X' ? el.clientWidth < el.scrollWidth : el.clientHeight < el.scrollHeight;
};

@@ -31,3 +23,3 @@

var alignNearest = function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, elementEdgeStart, elementEdgeEnd, elementSize) {
var alignNearest = function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, scrollingBorderStart, scrollingBorderEnd, elementEdgeStart, elementEdgeEnd, elementSize) {
if (elementEdgeStart < scrollingEdgeStart && elementEdgeEnd > scrollingEdgeEnd || elementEdgeStart > scrollingEdgeStart && elementEdgeEnd < scrollingEdgeEnd) {

@@ -38,7 +30,7 @@ return 0;

if (elementEdgeStart < scrollingEdgeStart && elementSize < scrollingSize || elementEdgeEnd > scrollingEdgeEnd && elementSize > scrollingSize) {
return elementEdgeStart - scrollingEdgeStart;
return elementEdgeStart - scrollingEdgeStart - scrollingBorderStart;
}
if (elementEdgeEnd > scrollingEdgeEnd && elementSize < scrollingSize || elementEdgeStart < scrollingEdgeStart && elementSize > scrollingSize) {
return elementEdgeEnd - scrollingEdgeEnd;
return elementEdgeEnd - scrollingEdgeEnd + scrollingBorderEnd;
}

@@ -77,3 +69,3 @@

while (isElement(parent = target.parentNode) && checkBoundary(target)) {
while (isElement(parent = target.parentNode || target.host) && checkBoundary(target)) {
if (isScrollable(parent, skipOverflowHiddenElements) || parent === viewport) {

@@ -125,2 +117,7 @@ frames.push(parent);

var frameRect = frame.getBoundingClientRect();
var frameStyle = getComputedStyle(frame);
var borderLeft = parseInt(frameStyle.borderLeftWidth, 10);
var borderTop = parseInt(frameStyle.borderTopWidth, 10);
var borderRight = parseInt(frameStyle.borderRightWidth, 10);
var borderBottom = parseInt(frameStyle.borderBottomWidth, 10);
var blockScroll = 0;

@@ -138,4 +135,3 @@ var inlineScroll = 0;

var offset = Math.min(targetBlock - frameRect.top, frame.scrollHeight - frame.clientHeight - frame.scrollTop);
blockScroll = frame.scrollTop + offset;
targetBlock -= blockScroll - frame.scrollTop;
blockScroll = frame.scrollTop + offset - borderTop;
}

@@ -155,3 +151,2 @@ }

blockScroll = frame.scrollTop + _offset;
targetBlock += frame.scrollTop - blockScroll;
}

@@ -170,4 +165,3 @@ }

blockScroll = frame.scrollTop + _offset2;
targetBlock += frame.scrollTop - blockScroll;
blockScroll = frame.scrollTop + _offset2 + borderBottom;
}

@@ -182,10 +176,9 @@ }

if (viewport === frame) {
var _offset3 = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, viewportY + targetBlock, viewportY + targetBlock + targetRect.height, targetRect.height);
var _offset3 = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, borderTop, borderBottom, viewportY + targetBlock, viewportY + targetBlock + targetRect.height, targetRect.height);
blockScroll = viewportY + _offset3;
} else {
var _offset4 = alignNearest(frameRect.top, frameRect.bottom, frameRect.height, targetBlock, targetBlock + targetRect.height, targetRect.height);
var _offset4 = alignNearest(frameRect.top, frameRect.bottom, frameRect.height, borderTop, borderBottom, targetBlock, targetBlock + targetRect.height, targetRect.height);
blockScroll = frame.scrollTop + _offset4;
targetBlock -= _offset4;
}

@@ -204,4 +197,3 @@ }

inlineScroll = frame.scrollLeft + _offset5;
targetInline -= inlineScroll - frame.scrollLeft;
inlineScroll = frame.scrollLeft + _offset5 - borderLeft;
}

@@ -221,3 +213,2 @@ }

inlineScroll = frame.scrollLeft + _offset6;
targetInline += frame.scrollLeft - inlineScroll;
}

@@ -236,4 +227,3 @@ }

inlineScroll = frame.scrollLeft + _offset7;
targetInline += frame.scrollLeft - inlineScroll;
inlineScroll = frame.scrollLeft + _offset7 + borderRight;
}

@@ -248,13 +238,14 @@ }

if (viewport === frame) {
var _offset8 = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, viewportX + targetInline, viewportX + targetInline + targetRect.width, targetRect.width);
var _offset8 = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, borderLeft, borderRight, viewportX + targetInline, viewportX + targetInline + targetRect.width, targetRect.width);
inlineScroll = viewportX + _offset8;
} else {
var _offset9 = alignNearest(frameRect.left, frameRect.right, frameRect.width, targetInline, targetInline + targetRect.width, targetRect.width);
var _offset9 = alignNearest(frameRect.left, frameRect.right, frameRect.width, borderLeft, borderRight, targetInline, targetInline + targetRect.width, targetRect.width);
inlineScroll = frame.scrollLeft + _offset9;
targetInline -= _offset9;
}
}
targetBlock += frame.scrollTop - blockScroll;
targetInline += frame.scrollLeft - inlineScroll;
return {

@@ -261,0 +252,0 @@ el: frame,

@@ -11,3 +11,3 @@ {

},
"version": "2.2.1",
"version": "2.2.2",
"main": "index.js",

@@ -49,3 +49,3 @@ "module": "es/index.js",

"eslint-plugin-import": "2.11.0",
"eslint-plugin-react": "7.8.1",
"eslint-plugin-react": "7.8.2",
"flowgen": "1.2.2",

@@ -52,0 +52,0 @@ "husky": "0.14.3",

@@ -8,2 +8,5 @@ declare global {

}
interface Element {
host: any;
}
}

@@ -10,0 +13,0 @@ import { CustomScrollAction, Options } from './types';

@@ -8,15 +8,7 @@ (function (global, factory) {

var isElement = function isElement(el) {
return el != null && typeof el == 'object' && el.nodeType === 1;
return el != null && typeof el == 'object' && (el.nodeType === 1 || el.nodeType === 11);
};
var hasScrollableSpace = function hasScrollableSpace(el, axis) {
if (axis === 'Y') {
return el.clientHeight < el.scrollHeight;
}
if (axis === 'X') {
return el.clientWidth < el.scrollWidth;
}
return false;
return axis === 'X' ? el.clientWidth < el.scrollWidth : el.clientHeight < el.scrollHeight;
};

@@ -38,3 +30,3 @@

var alignNearest = function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, elementEdgeStart, elementEdgeEnd, elementSize) {
var alignNearest = function alignNearest(scrollingEdgeStart, scrollingEdgeEnd, scrollingSize, scrollingBorderStart, scrollingBorderEnd, elementEdgeStart, elementEdgeEnd, elementSize) {
if (elementEdgeStart < scrollingEdgeStart && elementEdgeEnd > scrollingEdgeEnd || elementEdgeStart > scrollingEdgeStart && elementEdgeEnd < scrollingEdgeEnd) {

@@ -45,7 +37,7 @@ return 0;

if (elementEdgeStart < scrollingEdgeStart && elementSize < scrollingSize || elementEdgeEnd > scrollingEdgeEnd && elementSize > scrollingSize) {
return elementEdgeStart - scrollingEdgeStart;
return elementEdgeStart - scrollingEdgeStart - scrollingBorderStart;
}
if (elementEdgeEnd > scrollingEdgeEnd && elementSize < scrollingSize || elementEdgeStart < scrollingEdgeStart && elementSize > scrollingSize) {
return elementEdgeEnd - scrollingEdgeEnd;
return elementEdgeEnd - scrollingEdgeEnd + scrollingBorderEnd;
}

@@ -84,3 +76,3 @@

while (isElement(parent = target.parentNode) && checkBoundary(target)) {
while (isElement(parent = target.parentNode || target.host) && checkBoundary(target)) {
if (isScrollable(parent, skipOverflowHiddenElements) || parent === viewport) {

@@ -132,2 +124,7 @@ frames.push(parent);

var frameRect = frame.getBoundingClientRect();
var frameStyle = getComputedStyle(frame);
var borderLeft = parseInt(frameStyle.borderLeftWidth, 10);
var borderTop = parseInt(frameStyle.borderTopWidth, 10);
var borderRight = parseInt(frameStyle.borderRightWidth, 10);
var borderBottom = parseInt(frameStyle.borderBottomWidth, 10);
var blockScroll = 0;

@@ -145,4 +142,3 @@ var inlineScroll = 0;

var offset = Math.min(targetBlock - frameRect.top, frame.scrollHeight - frame.clientHeight - frame.scrollTop);
blockScroll = frame.scrollTop + offset;
targetBlock -= blockScroll - frame.scrollTop;
blockScroll = frame.scrollTop + offset - borderTop;
}

@@ -162,3 +158,2 @@ }

blockScroll = frame.scrollTop + _offset;
targetBlock += frame.scrollTop - blockScroll;
}

@@ -177,4 +172,3 @@ }

blockScroll = frame.scrollTop + _offset2;
targetBlock += frame.scrollTop - blockScroll;
blockScroll = frame.scrollTop + _offset2 + borderBottom;
}

@@ -189,10 +183,9 @@ }

if (viewport === frame) {
var _offset3 = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, viewportY + targetBlock, viewportY + targetBlock + targetRect.height, targetRect.height);
var _offset3 = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, borderTop, borderBottom, viewportY + targetBlock, viewportY + targetBlock + targetRect.height, targetRect.height);
blockScroll = viewportY + _offset3;
} else {
var _offset4 = alignNearest(frameRect.top, frameRect.bottom, frameRect.height, targetBlock, targetBlock + targetRect.height, targetRect.height);
var _offset4 = alignNearest(frameRect.top, frameRect.bottom, frameRect.height, borderTop, borderBottom, targetBlock, targetBlock + targetRect.height, targetRect.height);
blockScroll = frame.scrollTop + _offset4;
targetBlock -= _offset4;
}

@@ -211,4 +204,3 @@ }

inlineScroll = frame.scrollLeft + _offset5;
targetInline -= inlineScroll - frame.scrollLeft;
inlineScroll = frame.scrollLeft + _offset5 - borderLeft;
}

@@ -228,3 +220,2 @@ }

inlineScroll = frame.scrollLeft + _offset6;
targetInline += frame.scrollLeft - inlineScroll;
}

@@ -243,4 +234,3 @@ }

inlineScroll = frame.scrollLeft + _offset7;
targetInline += frame.scrollLeft - inlineScroll;
inlineScroll = frame.scrollLeft + _offset7 + borderRight;
}

@@ -255,13 +245,14 @@ }

if (viewport === frame) {
var _offset8 = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, viewportX + targetInline, viewportX + targetInline + targetRect.width, targetRect.width);
var _offset8 = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, borderLeft, borderRight, viewportX + targetInline, viewportX + targetInline + targetRect.width, targetRect.width);
inlineScroll = viewportX + _offset8;
} else {
var _offset9 = alignNearest(frameRect.left, frameRect.right, frameRect.width, targetInline, targetInline + targetRect.width, targetRect.width);
var _offset9 = alignNearest(frameRect.left, frameRect.right, frameRect.width, borderLeft, borderRight, targetInline, targetInline + targetRect.width, targetRect.width);
inlineScroll = frame.scrollLeft + _offset9;
targetInline -= _offset9;
}
}
targetBlock += frame.scrollTop - blockScroll;
targetInline += frame.scrollLeft - inlineScroll;
return {

@@ -268,0 +259,0 @@ el: frame,

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.scrollIntoView=e()}(this,function(){"use strict";var t,e,o=function(t){return null!=t&&"object"==typeof t&&1===t.nodeType},i=function(t,e){return"Y"===e?t.clientHeight<t.scrollHeight:"X"===e&&t.clientWidth<t.scrollWidth},n=function(t,e,o){var i=getComputedStyle(t,null)["overflow"+e];return(!o||"hidden"!==i)&&("visible"!==i&&"clip"!==i)},l=function(t,e){return i(t,"Y")&&n(t,"Y",e)||i(t,"X")&&n(t,"X",e)},r=function(t,e,o,i,n,l){return i<t&&n>e||i>t&&n<e?0:i<t&&l<o||n>e&&l>o?i-t:n>e&&l<o||i<t&&l>o?n-e:0},c=function(t,e){void 0===e&&(e={});var i=e,n=i.scrollMode,c=void 0===n?"always":n,f=i.block,s=void 0===f?"center":f,u=i.inline,d=void 0===u?"nearest":u,h=i.boundary,a=i.skipOverflowHiddenElements,p=void 0!==a&&a,v="function"==typeof h?h:function(t){return t!==h};if(!o(t))throw new Error("Element is required in scrollIntoView");for(var w,g=t.getBoundingClientRect(),m=document.scrollingElement||document.documentElement,b=[];o(w=t.parentNode)&&v(t);)(l(w,p)||w===m)&&b.push(w),t=w;var y,T,L=window.visualViewport?window.visualViewport.width:m.clientWidth,H=window.visualViewport?window.visualViewport.height:m.clientHeight,E=window.scrollX||window.pageXOffset,M=window.scrollY||window.pageYOffset;if("if-needed"===c&&b.every(function(t){var e=t.getBoundingClientRect();if(g.top<e.top)return!1;if(g.bottom>e.bottom)return!1;if(t===m){if(g.bottom>H)return!1;if(g.left>L)return!1}return!0}))return[];return b.map(function(t){var e=t.getBoundingClientRect(),o=0,i=0;if("start"===s)if(y||(y=g.top),m===t)o=M+y;else{var n=Math.min(y-e.top,t.scrollHeight-t.clientHeight-t.scrollTop);o=t.scrollTop+n,y-=o-t.scrollTop}if("center"===s)if(y||(y=g.top+g.height/2),m===t)o=M+y-t.clientHeight/2;else{var l=0-Math.min(e.top+e.height/2-y,t.scrollTop);o=t.scrollTop+l,y+=t.scrollTop-o}if("end"===s)if(y||(y=g.bottom),m===t)o=M+y-t.clientHeight;else{var c=0-Math.min(e.bottom-y,t.scrollTop);o=t.scrollTop+c,y+=t.scrollTop-o}if("nearest"===s)if(y||(y=g.top),m===t){var f=r(M,M+H,H,M+y,M+y+g.height,g.height);o=M+f}else{var u=r(e.top,e.bottom,e.height,y,y+g.height,g.height);o=t.scrollTop+u,y-=u}if("start"===d)if(T||(T=g.left),m===t)i=E+T;else{var h=Math.min(T-e.left,t.scrollHeight-t.clientLeft-t.scrollLeft);i=t.scrollLeft+h,T-=i-t.scrollLeft}if("center"===d)if(T||(T=g.left+g.width/2),m===t)i=E+T-t.clientWidth/2;else{var a=0-Math.min(e.left+e.width/2-T,t.scrollLeft);i=t.scrollLeft+a,T+=t.scrollLeft-i}if("end"===d)if(T||(T=g.right),m===t)i=E+T-t.clientWidth;else{var p=0-Math.min(e.right-T,t.scrollLeft);i=t.scrollLeft+p,T+=t.scrollLeft-i}if("nearest"===d)if(T||(T=g.left),m===t){var v=r(E,E+L,L,E+T,E+T+g.width,g.width);i=E+v}else{var w=r(e.left,e.right,e.width,T,T+g.width,g.width);i=t.scrollLeft+w,T-=w}return{el:t,top:o,left:i}})},f=function(t){return"function"==typeof t},s=function(t){return t===Object(t)&&0!==Object.keys(t).length},u=function(o,i){void 0===i&&(i="auto"),e||(e=document.scrollingElement||document.documentElement),void 0===t&&(t="scrollBehavior"in e.style),o.forEach(function(o){var n=o.el,l=o.top,r=o.left;n.scroll&&t?n.scroll({top:l,left:r,behavior:i}):n===e?window.scrollTo(r,l):(n.scrollTop=l,n.scrollLeft=r)})},d=function(t){return void 0===t&&(t=!0),!0===t||null===t?{block:"start",inline:"nearest"}:!1===t?{block:"end",inline:"nearest"}:s(t)?t:{block:"start",inline:"nearest"}};return function(t,e){if(void 0===e&&(e=!0),s(e)&&f(e.behavior))return e.behavior(c(t,e));var o=d(e);return u(c(t,o),o.behavior)}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.scrollIntoView=e()}(this,function(){"use strict";var t,e,i=function(t){return null!=t&&"object"==typeof t&&(1===t.nodeType||11===t.nodeType)},o=function(t,e){return"X"===e?t.clientWidth<t.scrollWidth:t.clientHeight<t.scrollHeight},n=function(t,e,i){var o=getComputedStyle(t,null)["overflow"+e];return(!i||"hidden"!==o)&&("visible"!==o&&"clip"!==o)},r=function(t,e){return o(t,"Y")&&n(t,"Y",e)||o(t,"X")&&n(t,"X",e)},l=function(t,e,i,o,n,r,l,c){return r<t&&l>e||r>t&&l<e?0:r<t&&c<i||l>e&&c>i?r-t-o:l>e&&c<i||r<t&&c>i?l-e+n:0},c=function(t,e){void 0===e&&(e={});var o=e,n=o.scrollMode,c=void 0===n?"always":n,f=o.block,s=void 0===f?"center":f,d=o.inline,u=void 0===d?"nearest":d,h=o.boundary,a=o.skipOverflowHiddenElements,p=void 0!==a&&a,v="function"==typeof h?h:function(t){return t!==h};if(!i(t))throw new Error("Element is required in scrollIntoView");for(var w,g=t.getBoundingClientRect(),m=document.scrollingElement||document.documentElement,b=[];i(w=t.parentNode||t.host)&&v(t);)(r(w,p)||w===m)&&b.push(w),t=w;var y,T,L=window.visualViewport?window.visualViewport.width:m.clientWidth,H=window.visualViewport?window.visualViewport.height:m.clientHeight,W=window.scrollX||window.pageXOffset,E=window.scrollY||window.pageYOffset;if("if-needed"===c&&b.every(function(t){var e=t.getBoundingClientRect();if(g.top<e.top)return!1;if(g.bottom>e.bottom)return!1;if(t===m){if(g.bottom>H)return!1;if(g.left>L)return!1}return!0}))return[];return b.map(function(t){var e=t.getBoundingClientRect(),i=getComputedStyle(t),o=parseInt(i.borderLeftWidth,10),n=parseInt(i.borderTopWidth,10),r=parseInt(i.borderRightWidth,10),c=parseInt(i.borderBottomWidth,10),f=0,d=0;if("start"===s)if(y||(y=g.top),m===t)f=E+y;else{var h=Math.min(y-e.top,t.scrollHeight-t.clientHeight-t.scrollTop);f=t.scrollTop+h-n}if("center"===s)if(y||(y=g.top+g.height/2),m===t)f=E+y-t.clientHeight/2;else{var a=0-Math.min(e.top+e.height/2-y,t.scrollTop);f=t.scrollTop+a}if("end"===s)if(y||(y=g.bottom),m===t)f=E+y-t.clientHeight;else{var p=0-Math.min(e.bottom-y,t.scrollTop);f=t.scrollTop+p+c}if("nearest"===s)if(y||(y=g.top),m===t){var v=l(E,E+H,H,n,c,E+y,E+y+g.height,g.height);f=E+v}else{var w=l(e.top,e.bottom,e.height,n,c,y,y+g.height,g.height);f=t.scrollTop+w}if("start"===u)if(T||(T=g.left),m===t)d=W+T;else{var b=Math.min(T-e.left,t.scrollHeight-t.clientLeft-t.scrollLeft);d=t.scrollLeft+b-o}if("center"===u)if(T||(T=g.left+g.width/2),m===t)d=W+T-t.clientWidth/2;else{var M=0-Math.min(e.left+e.width/2-T,t.scrollLeft);d=t.scrollLeft+M}if("end"===u)if(T||(T=g.right),m===t)d=W+T-t.clientWidth;else{var k=0-Math.min(e.right-T,t.scrollLeft);d=t.scrollLeft+k+r}if("nearest"===u)if(T||(T=g.left),m===t){var I=l(W,W+L,L,o,r,W+T,W+T+g.width,g.width);d=W+I}else{var V=l(e.left,e.right,e.width,o,r,T,T+g.width,g.width);d=t.scrollLeft+V}return y+=t.scrollTop-f,T+=t.scrollLeft-d,{el:t,top:f,left:d}})},f=function(t){return"function"==typeof t},s=function(t){return t===Object(t)&&0!==Object.keys(t).length},d=function(i,o){void 0===o&&(o="auto"),e||(e=document.scrollingElement||document.documentElement),void 0===t&&(t="scrollBehavior"in e.style),i.forEach(function(i){var n=i.el,r=i.top,l=i.left;n.scroll&&t?n.scroll({top:r,left:l,behavior:o}):n===e?window.scrollTo(l,r):(n.scrollTop=r,n.scrollLeft=l)})},u=function(t){return void 0===t&&(t=!0),!0===t||null===t?{block:"start",inline:"nearest"}:!1===t?{block:"end",inline:"nearest"}:s(t)?t:{block:"start",inline:"nearest"}};return function(t,e){if(void 0===e&&(e=!0),s(e)&&f(e.behavior))return e.behavior(c(t,e));var i=u(e);return d(c(t,i),i.behavior)}});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc