Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smooth-scroll-into-view-if-needed

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 1.1.1 to 1.1.2

10

package.json

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

},
"version": "1.1.1",
"version": "1.1.2",
"main": "index.js",

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

"peerDependencies": {
"scroll-into-view-if-needed": ">=2.1.6"
"scroll-into-view-if-needed": "^2.2.1"
},

@@ -51,3 +51,3 @@ "devDependencies": {

"eslint-plugin-import": "2.11.0",
"eslint-plugin-react": "7.7.0",
"eslint-plugin-react": "7.8.1",
"husky": "0.14.3",

@@ -64,4 +64,4 @@ "lint-staged": "7.1.0",

"rollup-plugin-uglify": "3.0.0",
"scroll-into-view-if-needed": "2.1.7",
"semantic-release": "15.3.1",
"scroll-into-view-if-needed": "2.2.1",
"semantic-release": "15.4.1",
"typescript": "2.8.3"

@@ -68,0 +68,0 @@ },

@@ -23,9 +23,14 @@ (function (global, factory) {

var canOverflow = function canOverflow(el, axis) {
var canOverflow = function canOverflow(el, axis, skipOverflowHiddenElements) {
var overflowValue = getComputedStyle(el, null)['overflow' + axis];
if (skipOverflowHiddenElements && overflowValue === 'hidden') {
return false;
}
return overflowValue !== 'visible' && overflowValue !== 'clip';
};
var isScrollable = function isScrollable(el) {
return hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y') || hasScrollableSpace(el, 'X') && canOverflow(el, 'X');
var isScrollable = function isScrollable(el, skipOverflowHiddenElements) {
return hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y', skipOverflowHiddenElements) || hasScrollableSpace(el, 'X') && canOverflow(el, 'X', skipOverflowHiddenElements);
};

@@ -61,3 +66,5 @@

inline = _options$inline === void 0 ? 'nearest' : _options$inline,
boundary = _options.boundary;
boundary = _options.boundary,
_options$skipOverflow = _options.skipOverflowHiddenElements,
skipOverflowHiddenElements = _options$skipOverflow === void 0 ? false : _options$skipOverflow;
var checkBoundary = typeof boundary == 'function' ? boundary : function (parent) {

@@ -72,3 +79,3 @@ return parent !== boundary;

var targetRect = target.getBoundingClientRect();
var viewport = document.documentElement;
var viewport = document.scrollingElement || document.documentElement;
var frames = [];

@@ -78,3 +85,3 @@ var parent;

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

@@ -261,2 +268,3 @@ }

var supportsScrollBehavior;
var scrollingElement;

@@ -276,4 +284,8 @@ var isFunction = function isFunction(arg) {

if (!scrollingElement) {
scrollingElement = document.scrollingElement || document.documentElement;
}
if (supportsScrollBehavior === undefined) {
supportsScrollBehavior = 'scrollBehavior' in document.documentElement.style;
supportsScrollBehavior = 'scrollBehavior' in scrollingElement.style;
}

@@ -293,3 +305,3 @@

} else {
if (el === document.documentElement) {
if (el === scrollingElement) {
window.scrollTo(left, top);

@@ -296,0 +308,0 @@ } else {

@@ -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},n=function(t,e){return"Y"===e?t.clientHeight<t.scrollHeight:"X"===e&&t.clientWidth<t.scrollWidth},r=function(t,e){var o=getComputedStyle(t,null)["overflow"+e];return"visible"!==o&&"clip"!==o},i=function(t,e,o,n,r,i){return n<t&&r>e||n>t&&r<e?0:n<t&&i<o||r>e&&i>o?n-t:r>e&&i<o||n<t&&i>o?r-e:0},l=function(t,e){void 0===e&&(e={});var l=e,c=l.scrollMode,f=void 0===c?"always":c,s=l.block,u=void 0===s?"center":s,a=l.inline,d=void 0===a?"nearest":a,h=l.boundary,w="function"==typeof h?h:function(t){return t!==h};if(!o(t))throw new Error("Element is required in scrollIntoView");for(var p,v,m=t.getBoundingClientRect(),g=document.documentElement,b=[];o(p=t.parentNode)&&w(t);)(n(v=p,"Y")&&r(v,"Y")||n(v,"X")&&r(v,"X")||p===g)&&b.push(p),t=p;var y,T,L=window.visualViewport?window.visualViewport.width:g.clientWidth,M=window.visualViewport?window.visualViewport.height:g.clientHeight,X=window.scrollX||window.pageXOffset,Y=window.scrollY||window.pageYOffset;if("if-needed"===f&&b.every(function(t){var e=t.getBoundingClientRect();if(m.top<e.top)return!1;if(m.bottom>e.bottom)return!1;if(t===g){if(m.bottom>M)return!1;if(m.left>L)return!1}return!0}))return[];return b.map(function(t){var e=t.getBoundingClientRect(),o=0,n=0;if("start"===u)if(y||(y=m.top),g===t)o=Y+y;else{var r=Math.min(y-e.top,t.scrollHeight-t.clientHeight-t.scrollTop);o=t.scrollTop+r,y-=o-t.scrollTop}if("center"===u)if(y||(y=m.top+m.height/2),g===t)o=Y+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"===u)if(y||(y=m.bottom),g===t)o=Y+y-t.clientHeight;else{var c=0-Math.min(e.bottom-y,t.scrollTop);o=t.scrollTop+c,y+=t.scrollTop-o}if("nearest"===u)if(y||(y=m.top),g===t){var f=i(Y,Y+M,M,Y+y,Y+y+m.height,m.height);o=Y+f}else{var s=i(e.top,e.bottom,e.height,y,y+m.height,m.height);o=t.scrollTop+s,y-=s}if("start"===d)if(T||(T=m.left),g===t)n=X+T;else{var a=Math.min(T-e.left,t.scrollHeight-t.clientLeft-t.scrollLeft);n=t.scrollLeft+a,T-=n-t.scrollLeft}if("center"===d)if(T||(T=m.left+m.width/2),g===t)n=X+T-t.clientWidth/2;else{var h=0-Math.min(e.left+e.width/2-T,t.scrollLeft);n=t.scrollLeft+h,T+=t.scrollLeft-n}if("end"===d)if(T||(T=m.right),g===t)n=X+T-t.clientWidth;else{var w=0-Math.min(e.right-T,t.scrollLeft);n=t.scrollLeft+w,T+=t.scrollLeft-n}if("nearest"===d)if(T||(T=m.left),g===t){var p=i(X,X+L,L,X+T,X+T+m.width,m.width);n=X+p}else{var v=i(e.left,e.right,e.width,T,T+m.width,m.width);n=t.scrollLeft+v,T-=v}return{el:t,top:o,left:n}})},c=function(t){return"function"==typeof t},f=function(t){return t===Object(t)&&0!==Object.keys(t).length},s=function(e,o){void 0===o&&(o="auto"),void 0===t&&(t="scrollBehavior"in document.documentElement.style),e.forEach(function(e){var n=e.el,r=e.top,i=e.left;n.scroll&&t?n.scroll({top:r,left:i,behavior:o}):n===document.documentElement?window.scrollTo(i,r):(n.scrollTop=r,n.scrollLeft=i)})},u=function(t){return void 0===t&&(t=!0),!0===t||null===t?{block:"start",inline:"nearest"}:!1===t?{block:"end",inline:"nearest"}:f(t)?t:{block:"start",inline:"nearest"}};function a(t,e){if(void 0===e&&(e=!0),f(e)&&c(e.behavior))return e.behavior(l(t,e));var o=u(e);return s(l(t,o),o.behavior)}var d=function(){return e||(e="performance"in window?performance.now.bind(performance):Date.now),e()};function h(t,e,o,n,r,i){var l,c,f,s;void 0===n&&(n=300),void 0===r&&(r=function(t){return.5*(1-Math.cos(Math.PI*t))}),t===document.documentElement?(l=window,c=window.scrollX||window.pageXOffset,f=window.scrollY||window.pageYOffset,s=function(t,e){return window.scroll(t,e)}):(l=t,c=t.scrollLeft,f=t.scrollTop,s=function(e,o){t.scrollLeft=e,t.scrollTop=o}),function t(e){var o=d(),n=Math.min((o-e.startTime)/e.duration,1),r=e.ease(n),i=e.startX+(e.x-e.startX)*r,l=e.startY+(e.y-e.startY)*r;e.method(i,l),i===e.x&&l===e.y||requestAnimationFrame(function(){return t(e)})}({scrollable:l,method:s,startTime:d(),startX:c,startY:f,x:e,y:o,duration:n,ease:r,cb:i})}var w=function(t){return t&&!t.behavior||"smooth"===t.behavior};return function(t,e){if(w(e)){var o=e||{};return a(t,{block:o.block,inline:o.inline,scrollMode:o.scrollMode,boundary:o.boundary,behavior:function(t){return Promise.all(t.map(function(t){var e=t.el,n=t.left,r=t.top;return new Promise(function(t){return h(e,n,r,o.duration,o.ease,function(){return t()})})}))}})}return a(t,e)}});
!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,n=function(t){return null!=t&&"object"==typeof t&&1===t.nodeType},r=function(t,e){return"Y"===e?t.clientHeight<t.scrollHeight:"X"===e&&t.clientWidth<t.scrollWidth},i=function(t,e,o){var n=getComputedStyle(t,null)["overflow"+e];return(!o||"hidden"!==n)&&("visible"!==n&&"clip"!==n)},l=function(t,e){return r(t,"Y")&&i(t,"Y",e)||r(t,"X")&&i(t,"X",e)},c=function(t,e,o,n,r,i){return n<t&&r>e||n>t&&r<e?0:n<t&&i<o||r>e&&i>o?n-t:r>e&&i<o||n<t&&i>o?r-e:0},f=function(t,e){void 0===e&&(e={});var o=e,r=o.scrollMode,i=void 0===r?"always":r,f=o.block,s=void 0===f?"center":f,u=o.inline,a=void 0===u?"nearest":u,d=o.boundary,h=o.skipOverflowHiddenElements,w=void 0!==h&&h,p="function"==typeof d?d:function(t){return t!==d};if(!n(t))throw new Error("Element is required in scrollIntoView");for(var v,m=t.getBoundingClientRect(),g=document.scrollingElement||document.documentElement,b=[];n(v=t.parentNode)&&p(t);)(l(v,w)||v===g)&&b.push(v),t=v;var y,T,L=window.visualViewport?window.visualViewport.width:g.clientWidth,M=window.visualViewport?window.visualViewport.height:g.clientHeight,X=window.scrollX||window.pageXOffset,Y=window.scrollY||window.pageYOffset;if("if-needed"===i&&b.every(function(t){var e=t.getBoundingClientRect();if(m.top<e.top)return!1;if(m.bottom>e.bottom)return!1;if(t===g){if(m.bottom>M)return!1;if(m.left>L)return!1}return!0}))return[];return b.map(function(t){var e=t.getBoundingClientRect(),o=0,n=0;if("start"===s)if(y||(y=m.top),g===t)o=Y+y;else{var r=Math.min(y-e.top,t.scrollHeight-t.clientHeight-t.scrollTop);o=t.scrollTop+r,y-=o-t.scrollTop}if("center"===s)if(y||(y=m.top+m.height/2),g===t)o=Y+y-t.clientHeight/2;else{var i=0-Math.min(e.top+e.height/2-y,t.scrollTop);o=t.scrollTop+i,y+=t.scrollTop-o}if("end"===s)if(y||(y=m.bottom),g===t)o=Y+y-t.clientHeight;else{var l=0-Math.min(e.bottom-y,t.scrollTop);o=t.scrollTop+l,y+=t.scrollTop-o}if("nearest"===s)if(y||(y=m.top),g===t){var f=c(Y,Y+M,M,Y+y,Y+y+m.height,m.height);o=Y+f}else{var u=c(e.top,e.bottom,e.height,y,y+m.height,m.height);o=t.scrollTop+u,y-=u}if("start"===a)if(T||(T=m.left),g===t)n=X+T;else{var d=Math.min(T-e.left,t.scrollHeight-t.clientLeft-t.scrollLeft);n=t.scrollLeft+d,T-=n-t.scrollLeft}if("center"===a)if(T||(T=m.left+m.width/2),g===t)n=X+T-t.clientWidth/2;else{var h=0-Math.min(e.left+e.width/2-T,t.scrollLeft);n=t.scrollLeft+h,T+=t.scrollLeft-n}if("end"===a)if(T||(T=m.right),g===t)n=X+T-t.clientWidth;else{var w=0-Math.min(e.right-T,t.scrollLeft);n=t.scrollLeft+w,T+=t.scrollLeft-n}if("nearest"===a)if(T||(T=m.left),g===t){var p=c(X,X+L,L,X+T,X+T+m.width,m.width);n=X+p}else{var v=c(e.left,e.right,e.width,T,T+m.width,m.width);n=t.scrollLeft+v,T-=v}return{el:t,top:o,left:n}})},s=function(t){return"function"==typeof t},u=function(t){return t===Object(t)&&0!==Object.keys(t).length},a=function(o,n){void 0===n&&(n="auto"),e||(e=document.scrollingElement||document.documentElement),void 0===t&&(t="scrollBehavior"in e.style),o.forEach(function(o){var r=o.el,i=o.top,l=o.left;r.scroll&&t?r.scroll({top:i,left:l,behavior:n}):r===e?window.scrollTo(l,i):(r.scrollTop=i,r.scrollLeft=l)})},d=function(t){return void 0===t&&(t=!0),!0===t||null===t?{block:"start",inline:"nearest"}:!1===t?{block:"end",inline:"nearest"}:u(t)?t:{block:"start",inline:"nearest"}};function h(t,e){if(void 0===e&&(e=!0),u(e)&&s(e.behavior))return e.behavior(f(t,e));var o=d(e);return a(f(t,o),o.behavior)}var w=function(){return o||(o="performance"in window?performance.now.bind(performance):Date.now),o()};function p(t,e,o,n,r,i){var l,c,f,s;void 0===n&&(n=300),void 0===r&&(r=function(t){return.5*(1-Math.cos(Math.PI*t))}),t===document.documentElement?(l=window,c=window.scrollX||window.pageXOffset,f=window.scrollY||window.pageYOffset,s=function(t,e){return window.scroll(t,e)}):(l=t,c=t.scrollLeft,f=t.scrollTop,s=function(e,o){t.scrollLeft=e,t.scrollTop=o}),function t(e){var o=w(),n=Math.min((o-e.startTime)/e.duration,1),r=e.ease(n),i=e.startX+(e.x-e.startX)*r,l=e.startY+(e.y-e.startY)*r;e.method(i,l),i===e.x&&l===e.y||requestAnimationFrame(function(){return t(e)})}({scrollable:l,method:s,startTime:w(),startX:c,startY:f,x:e,y:o,duration:n,ease:r,cb:i})}var v=function(t){return t&&!t.behavior||"smooth"===t.behavior};return function(t,e){if(v(e)){var o=e||{};return h(t,{block:o.block,inline:o.inline,scrollMode:o.scrollMode,boundary:o.boundary,behavior:function(t){return Promise.all(t.map(function(t){var e=t.el,n=t.left,r=t.top;return new Promise(function(t){return p(e,n,r,o.duration,o.ease,function(){return t()})})}))}})}return h(t,e)}});
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