scroll-into-view-if-needed
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -76,3 +76,3 @@ "use strict"; | ||
var targetRect = target.getBoundingClientRect(); | ||
var viewport = document.documentElement; | ||
var viewport = document.scrollingElement || document.documentElement; | ||
var frames = []; | ||
@@ -79,0 +79,0 @@ var parent; |
@@ -71,3 +71,3 @@ var isElement = function isElement(el) { | ||
var targetRect = target.getBoundingClientRect(); | ||
var viewport = document.documentElement; | ||
var viewport = document.scrollingElement || document.documentElement; | ||
var frames = []; | ||
@@ -74,0 +74,0 @@ var parent; |
import compute from './compute'; | ||
var supportsScrollBehavior; | ||
var scrollingElement; | ||
@@ -17,4 +18,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; | ||
} | ||
@@ -34,3 +39,3 @@ | ||
} else { | ||
if (el === document.documentElement) { | ||
if (el === scrollingElement) { | ||
window.scrollTo(left, top); | ||
@@ -37,0 +42,0 @@ } else { |
@@ -11,2 +11,3 @@ "use strict"; | ||
var supportsScrollBehavior; | ||
var scrollingElement; | ||
@@ -26,4 +27,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; | ||
} | ||
@@ -43,3 +48,3 @@ | ||
} else { | ||
if (el === document.documentElement) { | ||
if (el === scrollingElement) { | ||
window.scrollTo(left, top); | ||
@@ -46,0 +51,0 @@ } else { |
@@ -11,3 +11,3 @@ { | ||
}, | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"main": "index.js", | ||
@@ -49,3 +49,3 @@ "module": "es/index.js", | ||
"eslint-plugin-import": "2.11.0", | ||
"eslint-plugin-react": "7.7.0", | ||
"eslint-plugin-react": "7.8.1", | ||
"flowgen": "1.2.2", | ||
@@ -63,3 +63,3 @@ "husky": "0.14.3", | ||
"rollup-plugin-uglify": "3.0.0", | ||
"semantic-release": "15.4.0", | ||
"semantic-release": "15.4.1", | ||
"typescript": "2.8.3" | ||
@@ -66,0 +66,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import { ScrollBehavior, CustomScrollBehaviorCallback, Options as BaseOptions } from './types'; | ||
import { CustomScrollBehaviorCallback, Options as BaseOptions, ScrollBehavior } from './types'; | ||
export interface StandardBehaviorOptions extends BaseOptions { | ||
@@ -3,0 +3,0 @@ behavior?: ScrollBehavior; |
@@ -77,3 +77,3 @@ (function (global, factory) { | ||
var targetRect = target.getBoundingClientRect(); | ||
var viewport = document.documentElement; | ||
var viewport = document.scrollingElement || document.documentElement; | ||
var frames = []; | ||
@@ -265,2 +265,3 @@ var parent; | ||
var supportsScrollBehavior; | ||
var scrollingElement; | ||
@@ -280,4 +281,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; | ||
} | ||
@@ -297,3 +302,3 @@ | ||
} else { | ||
if (el === document.documentElement) { | ||
if (el === scrollingElement) { | ||
window.scrollTo(left, top); | ||
@@ -300,0 +305,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=function(t){return null!=t&&"object"==typeof t&&1===t.nodeType},o=function(t,e){return"Y"===e?t.clientHeight<t.scrollHeight:"X"===e&&t.clientWidth<t.scrollWidth},i=function(t,e,o){var i=getComputedStyle(t,null)["overflow"+e];return(!o||"hidden"!==i)&&("visible"!==i&&"clip"!==i)},n=function(t,e){return o(t,"Y")&&i(t,"Y",e)||o(t,"X")&&i(t,"X",e)},l=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},r=function(t,o){void 0===o&&(o={});var i=o,r=i.scrollMode,c=void 0===r?"always":r,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(!e(t))throw new Error("Element is required in scrollIntoView");for(var w,g=t.getBoundingClientRect(),m=document.documentElement,b=[];e(w=t.parentNode)&&v(t);)(n(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 r=0-Math.min(e.top+e.height/2-y,t.scrollTop);o=t.scrollTop+r,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=l(M,M+H,H,M+y,M+y+g.height,g.height);o=M+f}else{var u=l(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=l(E,E+L,L,E+T,E+T+g.width,g.width);i=E+v}else{var w=l(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}})},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 i=e.el,n=e.top,l=e.left;i.scroll&&t?i.scroll({top:n,left:l,behavior:o}):i===document.documentElement?window.scrollTo(l,n):(i.scrollTop=n,i.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"}:f(t)?t:{block:"start",inline:"nearest"}};return function(t,e){if(void 0===e&&(e=!0),f(e)&&c(e.behavior))return e.behavior(r(t,e));var o=u(e);return s(r(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,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)}}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65013
898