seamless-scroll-polyfill
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -7,3 +7,3 @@ { | ||
"extends": ["akari", "akari/typescript"], | ||
"ignorePatterns": ["**/*.js"], | ||
"ignorePatterns": ["**/*.js", "**/*.d.ts"], | ||
"rules": { | ||
@@ -10,0 +10,0 @@ "default-case": "off", |
@@ -0,1 +1,8 @@ | ||
# [2.1.0](https://github.com/magic-akari/seamless-scroll-polyfill/compare/v2.0.2...v2.1.0) (2021-09-11) | ||
### Features | ||
* export universe scroll, scrollTo and scrollBy functions ([89a631a](https://github.com/magic-akari/seamless-scroll-polyfill/commit/89a631a41eb25c36b560152ef006fba5439e70e8)) | ||
## [2.0.2](https://github.com/magic-akari/seamless-scroll-polyfill/compare/v2.0.1...v2.0.2) (2021-09-07) | ||
@@ -2,0 +9,0 @@ |
@@ -64,2 +64,3 @@ (function (global, factory) { | ||
}; | ||
/* eslint-disable */ | ||
var getOriginalMethod = function (proto, method, fallback) { | ||
@@ -74,2 +75,3 @@ var _a; | ||
}; | ||
/* eslint-enable */ | ||
var isObject = function (value) { | ||
@@ -88,8 +90,10 @@ var type = typeof value; | ||
}; | ||
// https://drafts.csswg.org/cssom-view/#normalize-non-finite-values | ||
var nonFinite = function (value) { | ||
if (!isFinite(value)) { | ||
return 0; | ||
} | ||
return Number(value); | ||
/** | ||
* - On Chrome and Firefox, document.scrollingElement will return the <html> element. | ||
* - Safari, document.scrollingElement will return the <body> element. | ||
* - On Edge, document.scrollingElement will return the <body> element. | ||
* - IE11 does not support document.scrollingElement, but you can assume its <html>. | ||
*/ | ||
var scrollingElement = function (element) { | ||
return element.ownerDocument.scrollingElement || element.ownerDocument.documentElement; | ||
}; | ||
@@ -119,3 +123,10 @@ | ||
var elementScrollWithOptions = function (element, options, config) { | ||
// https://drafts.csswg.org/cssom-view/#normalize-non-finite-values | ||
var nonFinite = function (value) { | ||
if (!isFinite(value)) { | ||
return 0; | ||
} | ||
return Number(value); | ||
}; | ||
var scrollWithOptions = function (element, options, config) { | ||
var _a, _b; | ||
@@ -157,34 +168,31 @@ if (!element.isConnected) { | ||
}; | ||
var elementScroll = function (element, scrollOptions, config) { | ||
var options = scrollOptions !== null && scrollOptions !== void 0 ? scrollOptions : {}; | ||
if (!isObject(options)) { | ||
throw new TypeError(failedExecute("scroll", "Element")); | ||
} | ||
if (!checkBehavior(options.behavior)) { | ||
throw new TypeError(failedExecuteInvalidEnumValue("scroll", "Element", options.behavior)); | ||
} | ||
elementScrollWithOptions(element, options, config); | ||
var isWindow = function (obj) { return obj.window === obj; }; | ||
var createScroll = function (scrollName) { | ||
return function (target, scrollOptions, config) { | ||
var _a = __read(isWindow(target) | ||
? [scrollingElement(target.document.documentElement), "Window"] | ||
: [target, "Element"], 2), element = _a[0], scrollType = _a[1]; | ||
var options = scrollOptions !== null && scrollOptions !== void 0 ? scrollOptions : {}; | ||
if (!isObject(options)) { | ||
throw new TypeError(failedExecute(scrollName, scrollType)); | ||
} | ||
if (!checkBehavior(options.behavior)) { | ||
throw new TypeError(failedExecuteInvalidEnumValue(scrollName, scrollType, options.behavior)); | ||
} | ||
if (scrollName === "scrollBy") { | ||
options.left = nonFinite(options.left) + element.scrollLeft; | ||
options.top = nonFinite(options.top) + element.scrollTop; | ||
} | ||
scrollWithOptions(element, options, config); | ||
}; | ||
}; | ||
var elementScrollTo = function (element, scrollToOptions, config) { | ||
var options = scrollToOptions !== null && scrollToOptions !== void 0 ? scrollToOptions : {}; | ||
if (!isObject(options)) { | ||
throw new TypeError(failedExecute("scrollTo", "Element")); | ||
} | ||
if (!checkBehavior(options.behavior)) { | ||
throw new TypeError(failedExecuteInvalidEnumValue("scrollTo", "Element", options.behavior)); | ||
} | ||
elementScrollWithOptions(element, options, config); | ||
}; | ||
var elementScrollBy = function (element, scrollByOptions, config) { | ||
var options = scrollByOptions !== null && scrollByOptions !== void 0 ? scrollByOptions : {}; | ||
if (!isObject(options)) { | ||
throw new TypeError(failedExecute("scrollBy", "Element")); | ||
} | ||
if (!checkBehavior(options.behavior)) { | ||
throw new TypeError(failedExecuteInvalidEnumValue("scrollBy", "Element", options.behavior)); | ||
} | ||
var left = nonFinite(options.left) + element.scrollLeft; | ||
var top = nonFinite(options.top) + element.scrollTop; | ||
elementScrollWithOptions(element, __assign(__assign({}, options), { left: left, top: top }), config); | ||
}; | ||
var scroll = createScroll("scroll"); | ||
var scrollTo = createScroll("scrollTo"); | ||
var scrollBy = createScroll("scrollBy"); | ||
var elementScroll = scroll; | ||
var elementScrollTo = scrollTo; | ||
var elementScrollBy = scrollBy; | ||
var windowScroll = scroll; | ||
var windowScrollTo = scrollTo; | ||
var windowScrollBy = scrollBy; | ||
@@ -442,11 +450,2 @@ // https://drafts.csswg.org/css-writing-modes-4/#block-flow | ||
}; | ||
/** | ||
* - On Chrome and Firefox, document.scrollingElement will return the <html> element. | ||
* - Safari, document.scrollingElement will return the <body> element. | ||
* - On Edge, document.scrollingElement will return the <body> element. | ||
* - IE11 does not support document.scrollingElement, but you can assume its <html>. | ||
*/ | ||
var scrollingElement = function (element) { | ||
return element.ownerDocument.scrollingElement || element.ownerDocument.documentElement; | ||
}; | ||
var isScrollable = function (element, computedStyle) { | ||
@@ -586,3 +585,3 @@ if (element.clientHeight < element.scrollHeight || element.clientWidth < element.scrollWidth) { | ||
}; | ||
var elementScrollIntoView = function (element, scrollIntoViewOptions, config) { | ||
var scrollIntoView = function (element, scrollIntoViewOptions, config) { | ||
var options = scrollIntoViewOptions || {}; | ||
@@ -598,57 +597,38 @@ if (!checkBehavior(options.behavior)) { | ||
}; | ||
var elementScrollIntoView = scrollIntoView; | ||
var elementScrollPolyfill = function (config) { | ||
if (isScrollBehaviorSupported()) { | ||
return; | ||
} | ||
var originalFunc = getOriginalMethod(window.HTMLElement.prototype, "scroll", elementScrollXY); | ||
modifyPrototypes(function (prototype) { | ||
prototype.scroll = function scroll() { | ||
var args = arguments; | ||
if (args.length === 1) { | ||
elementScroll(this, args[0], config); | ||
return; | ||
} | ||
originalFunc.apply(this, args); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
markPolyfill(prototype.scroll); | ||
}); | ||
var createPolyfill = function (scrollName, patch) { | ||
return function (config) { | ||
if (isScrollBehaviorSupported()) { | ||
return; | ||
} | ||
var scrollMethod = { | ||
scroll: scroll, | ||
scrollTo: scrollTo, | ||
scrollBy: scrollBy, | ||
}[scrollName]; | ||
patch(function (prototype) { | ||
prototype[scrollName] = function () { | ||
var args = arguments; | ||
if (arguments.length === 1) { | ||
scrollMethod(this, args[0], config); | ||
return; | ||
} | ||
var left = args[0]; | ||
var top = args[1]; | ||
scrollMethod(this, { left: left, top: top }); | ||
}; | ||
markPolyfill(prototype[scrollName]); | ||
}); | ||
}; | ||
}; | ||
var elementScrollToPolyfill = function (config) { | ||
if (isScrollBehaviorSupported()) { | ||
return; | ||
} | ||
var originalFunc = getOriginalMethod(window.HTMLElement.prototype, "scrollTo", elementScrollXY); | ||
modifyPrototypes(function (prototype) { | ||
prototype.scrollTo = function scrollTo() { | ||
var args = arguments; | ||
if (args.length === 1) { | ||
elementScrollTo(this, args[0], config); | ||
return; | ||
} | ||
originalFunc.apply(this, args); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
markPolyfill(prototype.scrollTo); | ||
}); | ||
var elementScrollPolyfill = createPolyfill("scroll", modifyPrototypes); | ||
var elementScrollToPolyfill = createPolyfill("scrollTo", modifyPrototypes); | ||
var elementScrollByPolyfill = createPolyfill("scrollBy", modifyPrototypes); | ||
var modifyWindow = function (modification) { | ||
modification(window); | ||
}; | ||
var elementScrollByPolyfill = function (config) { | ||
if (isScrollBehaviorSupported()) { | ||
return; | ||
} | ||
modifyPrototypes(function (prototype) { | ||
prototype.scrollBy = function scrollBy() { | ||
var args = arguments; | ||
if (args.length === 1) { | ||
elementScrollBy(this, args[0], config); | ||
return; | ||
} | ||
var _a = __read(args, 2), left = _a[0], top = _a[1]; | ||
elementScrollBy(this, { left: left, top: top }, config); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
markPolyfill(prototype.scrollBy); | ||
}); | ||
}; | ||
var windowScrollPolyfill = createPolyfill("scroll", modifyWindow); | ||
var windowScrollToPolyfill = createPolyfill("scrollTo", modifyWindow); | ||
var windowScrollByPolyfill = createPolyfill("scrollBy", modifyWindow); | ||
@@ -675,114 +655,2 @@ var elementScrollIntoViewPolyfill = function (config) { | ||
var windowScrollWithOptions = function (currentWindow, options, config) { | ||
var _a, _b; | ||
var startX = currentWindow.scrollX || currentWindow.pageXOffset; | ||
var startY = currentWindow.scrollY || currentWindow.pageYOffset; | ||
var targetX = nonFinite((_a = options.left) !== null && _a !== void 0 ? _a : startX); | ||
var targetY = nonFinite((_b = options.top) !== null && _b !== void 0 ? _b : startY); | ||
if (targetX === startX && targetY === startY) { | ||
return; | ||
} | ||
var originalBoundFunc = getOriginalMethod(currentWindow, "scroll").bind(currentWindow); | ||
if (options.behavior !== "smooth") { | ||
originalBoundFunc(targetX, targetY); | ||
return; | ||
} | ||
var removeEventListener = function () { | ||
currentWindow.removeEventListener("wheel", cancelScroll); | ||
currentWindow.removeEventListener("touchmove", cancelScroll); | ||
}; | ||
var context = __assign(__assign({}, config), { timeStamp: now(), startX: startX, startY: startY, targetX: targetX, targetY: targetY, rafId: 0, method: originalBoundFunc, callback: removeEventListener }); | ||
var cancelScroll = function () { | ||
currentWindow.cancelAnimationFrame(context.rafId); | ||
removeEventListener(); | ||
}; | ||
currentWindow.addEventListener("wheel", cancelScroll, { | ||
passive: true, | ||
once: true, | ||
}); | ||
currentWindow.addEventListener("touchmove", cancelScroll, { | ||
passive: true, | ||
once: true, | ||
}); | ||
step(context); | ||
}; | ||
var windowScroll = function (currentWindow, scrollOptions, config) { | ||
var options = scrollOptions !== null && scrollOptions !== void 0 ? scrollOptions : {}; | ||
if (!isObject(options)) { | ||
throw new TypeError(failedExecute("scroll", "Window")); | ||
} | ||
if (!checkBehavior(options.behavior)) { | ||
throw new TypeError(failedExecuteInvalidEnumValue("scroll", "Window", options.behavior)); | ||
} | ||
windowScrollWithOptions(currentWindow, options, config); | ||
}; | ||
var windowScrollTo = function (currentWindow, scrollToOptions, config) { | ||
var options = scrollToOptions !== null && scrollToOptions !== void 0 ? scrollToOptions : {}; | ||
if (!isObject(options)) { | ||
throw new TypeError(failedExecute("scrollTo", "Window")); | ||
} | ||
if (!checkBehavior(options.behavior)) { | ||
throw new TypeError(failedExecuteInvalidEnumValue("scrollTo", "Window", options.behavior)); | ||
} | ||
windowScrollWithOptions(currentWindow, options, config); | ||
}; | ||
var windowScrollBy = function (currentWindow, scrollByOptions, config) { | ||
var options = scrollByOptions !== null && scrollByOptions !== void 0 ? scrollByOptions : {}; | ||
if (!isObject(options)) { | ||
throw new TypeError(failedExecute("scrollBy", "Window")); | ||
} | ||
if (!checkBehavior(options.behavior)) { | ||
throw new TypeError(failedExecuteInvalidEnumValue("scrollBy", "Window", options.behavior)); | ||
} | ||
var left = nonFinite(options.left) + (currentWindow.scrollX || currentWindow.pageXOffset); | ||
var top = nonFinite(options.top) + (currentWindow.scrollY || currentWindow.pageYOffset); | ||
windowScroll(currentWindow, __assign(__assign({}, options), { left: left, top: top }), config); | ||
}; | ||
var windowScrollPolyfill = function (config) { | ||
if (isScrollBehaviorSupported()) { | ||
return; | ||
} | ||
var originalFunc = getOriginalMethod(window, "scroll"); | ||
window.scroll = function scroll() { | ||
var args = arguments; | ||
if (args.length === 1) { | ||
windowScroll(this, args[0], config); | ||
return; | ||
} | ||
originalFunc.apply(this, args); | ||
}; | ||
markPolyfill(window.scroll); | ||
}; | ||
var windowScrollToPolyfill = function (config) { | ||
if (isScrollBehaviorSupported()) { | ||
return; | ||
} | ||
var originalFunc = getOriginalMethod(window, "scrollTo"); | ||
window.scrollTo = function scrollTo() { | ||
var args = arguments; | ||
if (args.length === 1) { | ||
windowScrollTo(this, args[0], config); | ||
return; | ||
} | ||
originalFunc.apply(this, args); | ||
}; | ||
markPolyfill(window.scrollTo); | ||
}; | ||
var windowScrollByPolyfill = function (config) { | ||
if (isScrollBehaviorSupported()) { | ||
return; | ||
} | ||
window.scrollBy = function scrollBy() { | ||
var args = arguments; | ||
if (args.length === 1) { | ||
windowScrollBy(this, args[0], config); | ||
return; | ||
} | ||
var _a = __read(args, 2), left = _a[0], top = _a[1]; | ||
windowScrollBy(this, { left: left, top: top }, config); | ||
}; | ||
markPolyfill(window.scrollBy); | ||
}; | ||
var polyfill = function (config) { | ||
@@ -810,2 +678,6 @@ if (isScrollBehaviorSupported()) { | ||
exports.polyfill = polyfill; | ||
exports.scroll = scroll; | ||
exports.scrollBy = scrollBy; | ||
exports.scrollIntoView = scrollIntoView; | ||
exports.scrollTo = scrollTo; | ||
exports.windowScroll = windowScroll; | ||
@@ -812,0 +684,0 @@ exports.windowScrollBy = windowScrollBy; |
@@ -15,3 +15,3 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).seamless={})}(this,(function(e){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var t=function(){return(t=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function o(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,r,l=o.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=l.next()).done;)i.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(o=l.return)&&o.call(l)}finally{if(r)throw r.error}}return i}var n=function(e){return void 0===e||"auto"===e||"instant"===e||"smooth"===e};function r(e,t){this.scrollLeft=e,this.scrollTop=t}var l=function(e,t,o){return void 0===o&&(o="cannot convert to dictionary."),"Failed to execute '"+e+"' on '"+t+"': "+o},i=function(e,t,o){return l(e,t,"The provided value '"+o+"' is not a valid enum value of type ScrollBehavior.")},c=function(e,t,o){var n,r="__seamless__$$"+t+"$$__backup__";if(e[r]||(e[r]=e[t]||(e[t]=o)),null===(n=e[r])||void 0===n?void 0:n.__isPolyfill)throw new Error("unexpected_method");return e[r]},a=function(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)},u=function(){return"scrollBehavior"in window.document.documentElement.style},f=function(e){Object.defineProperty(e,"__isPolyfill",{value:!0})},s=function(e){[HTMLElement.prototype,SVGElement.prototype,Element.prototype].forEach((function(t){e(t)}))},d=function(e){return isFinite(e)?Number(e):0},v=function(e){return.5*(1-Math.cos(Math.PI*e))},w=function(){var e,t,o;return null!==(o=null===(t=null===(e=window.performance)||void 0===e?void 0:e.now)||void 0===t?void 0:t.call(e))&&void 0!==o?o:window.Date.now()},h=function(e){var t=(w()-e.timeStamp)/(e.duration||500);if(t>1)return e.method(e.targetX,e.targetY),void e.callback();var o=(e.timingFunc||v)(t),n=e.startX+(e.targetX-e.startX)*o,r=e.startY+(e.targetY-e.startY)*o;e.method(n,r),e.rafId=window.requestAnimationFrame((function(){h(e)}))},p=function(e,o,n){var l,i;if(e.isConnected){var a=e.scrollLeft,u=e.scrollTop,f=d(null!==(l=o.left)&&void 0!==l?l:a),s=d(null!==(i=o.top)&&void 0!==i?i:u);if(f!==a||s!==u){var v=c(Object.getPrototypeOf(e),"scroll",r).bind(e);if("smooth"===o.behavior){var p=function(){window.removeEventListener("wheel",y),window.removeEventListener("touchmove",y)},m=t(t({},n),{timeStamp:w(),startX:a,startY:u,targetX:f,targetY:s,rafId:0,method:v,callback:p}),y=function(){window.cancelAnimationFrame(m.rafId),p()};window.addEventListener("wheel",y,{passive:!0,once:!0}),window.addEventListener("touchmove",y,{passive:!0,once:!0}),h(m)}else v(f,s)}}},m=function(e,t,o){var r=null!=t?t:{};if(!a(r))throw new TypeError(l("scroll","Element"));if(!n(r.behavior))throw new TypeError(i("scroll","Element",r.behavior));p(e,r,o)},y=function(e,t,o){var r=null!=t?t:{};if(!a(r))throw new TypeError(l("scrollTo","Element"));if(!n(r.behavior))throw new TypeError(i("scrollTo","Element",r.behavior));p(e,r,o)},g=function(e,o,r){var c=null!=o?o:{};if(!a(c))throw new TypeError(l("scrollBy","Element"));if(!n(c.behavior))throw new TypeError(i("scrollBy","Element",c.behavior));var u=d(c.left)+e.scrollLeft,f=d(c.top)+e.scrollTop;p(e,t(t({},c),{left:u,top:f}),r)},b=function(e){switch(e){case"horizontal-tb":case"lr":case"lr-tb":case"rl":case"rl-tb":return 0;case"vertical-rl":case"tb":case"tb-rl":return 1;case"vertical-lr":case"tb-lr":return 2;case"sideways-rl":return 3;case"sideways-lr":return 4}return 0},E=function(e,t,n,r){var l,i=0;switch(t||(i^=2),e){case 0:i=i>>1|(1&i)<<1,n=(l=o([r,n],2))[0],r=l[1];break;case 1:case 3:i^=1;break;case 4:i^=2}return[i,n,r]},T=function(e){return 1==(1&E(b(e.writingMode),"rtl"!==e.direction,void 0,void 0)[0])},S=function(e,t,o,n,r,l,i){return 0!==e?e:r<t&&l>o||r>t&&l<o?null:r<=t&&i<=n||l>=o&&i>=n?2:l>o&&i<n||r<t&&i>n?3:null},L=function(e){return"visible"!==e&&"clip"!==e},B=function(e){return e.ownerDocument.scrollingElement||e.ownerDocument.documentElement},P=function(e,t){return(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth)&&(L(t.overflowY)||L(t.overflowX)||e===B(e))},V=function(e){var t=e.parentNode,o=e.parentElement;if(null===o&&null!==t){if(11===t.nodeType)return t.host;if(9===t.nodeType)return function(e){var t;try{return(null===(t=e.ownerDocument.defaultView)||void 0===t?void 0:t.frameElement)||null}catch(e){return null}}(e)}return o},W=function(e,t,o){return e<t?t:e>o?o:e},_=function(e,t,o){switch(e){case 1:return(t+o)/2;case 3:return o;case 2:case 0:return t}},I=function(e,t){var n,r,l,i=null===(n=e.ownerDocument.defaultView)||void 0===n?void 0:n.visualViewport,c=o(e===B(e)?[0,0,null!==(r=null==i?void 0:i.width)&&void 0!==r?r:e.clientWidth,null!==(l=null==i?void 0:i.height)&&void 0!==l?l:e.clientHeight]:[t.left,t.top,e.clientWidth,e.clientHeight],4),a=c[0],u=c[1],f=c[2],s=c[3],d=a+e.clientLeft,v=u+e.clientTop;return[v,d+f,v+s,d]},M=function(e,t){var n=[],r=e.ownerDocument,l=r.defaultView;if(!l)return n;for(var i=window.getComputedStyle(e),c="rtl"!==i.direction,a=o(function(e,t,n){var r=o(E(t,n,e.block||"start",e.inline||"nearest"),3),l=r[0];return[r[1],r[2]].map((function(e,t){switch(e){case"center":return 1;case"nearest":return 0;default:return"start"===e==!(l>>t&1)?2:3}}))}(t,b(i.writingMode||i.getPropertyValue("-webkit-writing-mode")||i.getPropertyValue("-ms-writing-mode")),c),2),u=a[0],f=a[1],s=o(function(e,t,o){var n,r=t.top,l=t.right,i=t.bottom,c=t.left,a=(n=e.ownerDocument,["scroll-margin","scroll-snap-margin"].filter((function(e){return e in n.documentElement.style}))[0]);if(!a)return[r,l,i,c];var u=function(e){var t=o.getPropertyValue(a+"-"+e);return parseInt(t,10)||0};return[r-u("top"),l+u("right"),i+u("bottom"),c-u("left")]}(e,e.getBoundingClientRect(),i),4),d=s[0],v=s[1],w=s[2],h=s[3],p=V(e);null!==p;p=V(p)){if(r!==p.ownerDocument){if(!(l=(r=p.ownerDocument).defaultView))break;var m=p.getBoundingClientRect(),y=m.left,g=m.top;d+=g,v+=y,w+=g,h+=y}var L=l.getComputedStyle(p);if("fixed"===L.position)break;if(P(p,L)){var B=p.getBoundingClientRect(),M=o(I(p,B),4),X=M[0],Y=M[1],H=M[2],O=M[3],k=_(u,O,Y),x=_(f,X,H),D=S(u,O,Y,p.clientWidth,h,v,v-h),j=S(f,X,H,p.clientHeight,d,w,w-d),C=(null===D?k:_(D,h,v))-k,F=(null===j?x:_(j,d,w))-x,$=T(L)?W(C,-p.scrollWidth+p.clientWidth-p.scrollLeft,-p.scrollLeft):W(C,-p.scrollLeft,p.scrollWidth-p.clientWidth-p.scrollLeft),A=W(F,-p.scrollTop,p.scrollHeight-p.clientHeight-p.scrollTop);n.push([p,{left:p.scrollLeft+$,top:p.scrollTop+A,behavior:t.behavior}]),d=Math.max(d-A,X),v=Math.min(v-$,Y),w=Math.min(w-A,H),h=Math.max(h-$,O)}}return n},X=function(e,t,r){var l=t||{};if(!n(l.behavior))throw new TypeError(i("scrollIntoView","Element",l.behavior));M(e,l).forEach((function(e){var t=o(e,2),n=t[0],l=t[1];m(n,l,r)}))},Y=function(e){if(!u()){var t=c(window.HTMLElement.prototype,"scroll",r);s((function(o){o.scroll=function(){var o=arguments;1!==o.length?t.apply(this,o):m(this,o[0],e)},f(o.scroll)}))}},H=function(e){if(!u()){var t=c(window.HTMLElement.prototype,"scrollTo",r);s((function(o){o.scrollTo=function(){var o=arguments;1!==o.length?t.apply(this,o):y(this,o[0],e)},f(o.scrollTo)}))}},O=function(e){u()||s((function(t){t.scrollBy=function(){var t=arguments;if(1!==t.length){var n=o(t,2),r=n[0],l=n[1];g(this,{left:r,top:l},e)}else g(this,t[0],e)},f(t.scrollBy)}))},k=function(e){if(!u()){var t=c(window.HTMLElement.prototype,"scrollIntoView");s((function(o){o.scrollIntoView=function(){var o=arguments,n=o[0];1===o.length&&a(n)?X(this,n,e):t.apply(this,o)},f(o.scrollIntoView)}))}},x=function(e,o,n){var r,l,i=e.scrollX||e.pageXOffset,a=e.scrollY||e.pageYOffset,u=d(null!==(r=o.left)&&void 0!==r?r:i),f=d(null!==(l=o.top)&&void 0!==l?l:a);if(u!==i||f!==a){var s=c(e,"scroll").bind(e);if("smooth"===o.behavior){var v=function(){e.removeEventListener("wheel",m),e.removeEventListener("touchmove",m)},p=t(t({},n),{timeStamp:w(),startX:i,startY:a,targetX:u,targetY:f,rafId:0,method:s,callback:v}),m=function(){e.cancelAnimationFrame(p.rafId),v()};e.addEventListener("wheel",m,{passive:!0,once:!0}),e.addEventListener("touchmove",m,{passive:!0,once:!0}),h(p)}else s(u,f)}},D=function(e,t,o){var r=null!=t?t:{};if(!a(r))throw new TypeError(l("scroll","Window"));if(!n(r.behavior))throw new TypeError(i("scroll","Window",r.behavior));x(e,r,o)},j=function(e,t,o){var r=null!=t?t:{};if(!a(r))throw new TypeError(l("scrollTo","Window"));if(!n(r.behavior))throw new TypeError(i("scrollTo","Window",r.behavior));x(e,r,o)},C=function(e,o,r){var c=null!=o?o:{};if(!a(c))throw new TypeError(l("scrollBy","Window"));if(!n(c.behavior))throw new TypeError(i("scrollBy","Window",c.behavior));var u=d(c.left)+(e.scrollX||e.pageXOffset),f=d(c.top)+(e.scrollY||e.pageYOffset);D(e,t(t({},c),{left:u,top:f}),r)},F=function(e){if(!u()){var t=c(window,"scroll");window.scroll=function(){var o=arguments;1!==o.length?t.apply(this,o):D(this,o[0],e)},f(window.scroll)}},$=function(e){if(!u()){var t=c(window,"scrollTo");window.scrollTo=function(){var o=arguments;1!==o.length?t.apply(this,o):j(this,o[0],e)},f(window.scrollTo)}},A=function(e){u()||(window.scrollBy=function(){var t=arguments;if(1!==t.length){var n=o(t,2),r=n[0],l=n[1];C(this,{left:r,top:l},e)}else C(this,t[0],e)},f(window.scrollBy))};e.elementScroll=m,e.elementScrollBy=g,e.elementScrollByPolyfill=O,e.elementScrollIntoView=X,e.elementScrollIntoViewPolyfill=k,e.elementScrollPolyfill=Y,e.elementScrollTo=y,e.elementScrollToPolyfill=H,e.polyfill=function(e){u()||(Y(e),H(e),O(e),k(e),F(e),$(e),A(e))},e.windowScroll=D,e.windowScrollBy=C,e.windowScrollByPolyfill=A,e.windowScrollPolyfill=F,e.windowScrollTo=j,e.windowScrollToPolyfill=$,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
***************************************************************************** */var t=function(){return(t=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function n(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,l=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(o=l.next()).done;)i.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}return i}var o=function(e){return void 0===e||"auto"===e||"instant"===e||"smooth"===e};function r(e,t){this.scrollLeft=e,this.scrollTop=t}var l=function(e,t,n){return void 0===n&&(n="cannot convert to dictionary."),"Failed to execute '"+e+"' on '"+t+"': "+n},i=function(e,t,n){return l(e,t,"The provided value '"+n+"' is not a valid enum value of type ScrollBehavior.")},c=function(e,t,n){var o,r="__seamless__$$"+t+"$$__backup__";if(e[r]||(e[r]=e[t]||(e[t]=n)),null===(o=e[r])||void 0===o?void 0:o.__isPolyfill)throw new Error("unexpected_method");return e[r]},u=function(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)},a=function(){return"scrollBehavior"in window.document.documentElement.style},f=function(e){Object.defineProperty(e,"__isPolyfill",{value:!0})},s=function(e){[HTMLElement.prototype,SVGElement.prototype,Element.prototype].forEach((function(t){e(t)}))},d=function(e){return e.ownerDocument.scrollingElement||e.ownerDocument.documentElement},v=function(e){return.5*(1-Math.cos(Math.PI*e))},w=function(){var e,t,n;return null!==(n=null===(t=null===(e=window.performance)||void 0===e?void 0:e.now)||void 0===t?void 0:t.call(e))&&void 0!==n?n:window.Date.now()},h=function(e){var t=(w()-e.timeStamp)/(e.duration||500);if(t>1)return e.method(e.targetX,e.targetY),void e.callback();var n=(e.timingFunc||v)(t),o=e.startX+(e.targetX-e.startX)*n,r=e.startY+(e.targetY-e.startY)*n;e.method(o,r),e.rafId=window.requestAnimationFrame((function(){h(e)}))},m=function(e){return isFinite(e)?Number(e):0},p=function(e){return function(a,f,s){var v,p=n((v=a).window===v?[d(a.document.documentElement),"Window"]:[a,"Element"],2),y=p[0],g=p[1],b=null!=f?f:{};if(!u(b))throw new TypeError(l(e,g));if(!o(b.behavior))throw new TypeError(i(e,g,b.behavior));"scrollBy"===e&&(b.left=m(b.left)+y.scrollLeft,b.top=m(b.top)+y.scrollTop),function(e,n,o){var l,i;if(e.isConnected){var u=e.scrollLeft,a=e.scrollTop,f=m(null!==(l=n.left)&&void 0!==l?l:u),s=m(null!==(i=n.top)&&void 0!==i?i:a);if(f!==u||s!==a){var d=c(Object.getPrototypeOf(e),"scroll",r).bind(e);if("smooth"===n.behavior){var v=function(){window.removeEventListener("wheel",y),window.removeEventListener("touchmove",y)},p=t(t({},o),{timeStamp:w(),startX:u,startY:a,targetX:f,targetY:s,rafId:0,method:d,callback:v}),y=function(){window.cancelAnimationFrame(p.rafId),v()};window.addEventListener("wheel",y,{passive:!0,once:!0}),window.addEventListener("touchmove",y,{passive:!0,once:!0}),h(p)}else d(f,s)}}}(y,b,s)}},y=p("scroll"),g=p("scrollTo"),b=p("scrollBy"),T=y,E=g,S=b,P=y,V=g,B=b,L=function(e){switch(e){case"horizontal-tb":case"lr":case"lr-tb":case"rl":case"rl-tb":return 0;case"vertical-rl":case"tb":case"tb-rl":return 1;case"vertical-lr":case"tb-lr":return 2;case"sideways-rl":return 3;case"sideways-lr":return 4}return 0},_=function(e,t,o,r){var l,i=0;switch(t||(i^=2),e){case 0:i=i>>1|(1&i)<<1,o=(l=n([r,o],2))[0],r=l[1];break;case 1:case 3:i^=1;break;case 4:i^=2}return[i,o,r]},I=function(e){return 1==(1&_(L(e.writingMode),"rtl"!==e.direction,void 0,void 0)[0])},M=function(e,t,n,o,r,l,i){return 0!==e?e:r<t&&l>n||r>t&&l<n?null:r<=t&&i<=o||l>=n&&i>=o?2:l>n&&i<o||r<t&&i>o?3:null},W=function(e){return"visible"!==e&&"clip"!==e},k=function(e,t){return(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth)&&(W(t.overflowY)||W(t.overflowX)||e===d(e))},x=function(e){var t=e.parentNode,n=e.parentElement;if(null===n&&null!==t){if(11===t.nodeType)return t.host;if(9===t.nodeType)return function(e){var t;try{return(null===(t=e.ownerDocument.defaultView)||void 0===t?void 0:t.frameElement)||null}catch(e){return null}}(e)}return n},D=function(e,t,n){return e<t?t:e>n?n:e},H=function(e,t,n){switch(e){case 1:return(t+n)/2;case 3:return n;case 2:case 0:return t}},j=function(e,t){var o,r,l,i=null===(o=e.ownerDocument.defaultView)||void 0===o?void 0:o.visualViewport,c=n(e===d(e)?[0,0,null!==(r=null==i?void 0:i.width)&&void 0!==r?r:e.clientWidth,null!==(l=null==i?void 0:i.height)&&void 0!==l?l:e.clientHeight]:[t.left,t.top,e.clientWidth,e.clientHeight],4),u=c[0],a=c[1],f=c[2],s=c[3],v=u+e.clientLeft,w=a+e.clientTop;return[w,v+f,w+s,v]},O=function(e,t){var o=[],r=e.ownerDocument,l=r.defaultView;if(!l)return o;for(var i=window.getComputedStyle(e),c="rtl"!==i.direction,u=n(function(e,t,o){var r=n(_(t,o,e.block||"start",e.inline||"nearest"),3),l=r[0];return[r[1],r[2]].map((function(e,t){switch(e){case"center":return 1;case"nearest":return 0;default:return"start"===e==!(l>>t&1)?2:3}}))}(t,L(i.writingMode||i.getPropertyValue("-webkit-writing-mode")||i.getPropertyValue("-ms-writing-mode")),c),2),a=u[0],f=u[1],s=n(function(e,t,n){var o,r=t.top,l=t.right,i=t.bottom,c=t.left,u=(o=e.ownerDocument,["scroll-margin","scroll-snap-margin"].filter((function(e){return e in o.documentElement.style}))[0]);if(!u)return[r,l,i,c];var a=function(e){var t=n.getPropertyValue(u+"-"+e);return parseInt(t,10)||0};return[r-a("top"),l+a("right"),i+a("bottom"),c-a("left")]}(e,e.getBoundingClientRect(),i),4),d=s[0],v=s[1],w=s[2],h=s[3],m=x(e);null!==m;m=x(m)){if(r!==m.ownerDocument){if(!(l=(r=m.ownerDocument).defaultView))break;var p=m.getBoundingClientRect(),y=p.left,g=p.top;d+=g,v+=y,w+=g,h+=y}var b=l.getComputedStyle(m);if("fixed"===b.position)break;if(k(m,b)){var T=m.getBoundingClientRect(),E=n(j(m,T),4),S=E[0],P=E[1],V=E[2],B=E[3],W=H(a,B,P),O=H(f,S,V),X=M(a,B,P,m.clientWidth,h,v,v-h),Y=M(f,S,V,m.clientHeight,d,w,w-d),C=(null===X?W:H(X,h,v))-W,F=(null===Y?O:H(Y,d,w))-O,$=I(b)?D(C,-m.scrollWidth+m.clientWidth-m.scrollLeft,-m.scrollLeft):D(C,-m.scrollLeft,m.scrollWidth-m.clientWidth-m.scrollLeft),R=D(F,-m.scrollTop,m.scrollHeight-m.clientHeight-m.scrollTop);o.push([m,{left:m.scrollLeft+$,top:m.scrollTop+R,behavior:t.behavior}]),d=Math.max(d-R,S),v=Math.min(v-$,P),w=Math.min(w-R,V),h=Math.max(h-$,B)}}return o},X=function(e,t,r){var l=t||{};if(!o(l.behavior))throw new TypeError(i("scrollIntoView","Element",l.behavior));O(e,l).forEach((function(e){var t=n(e,2),o=t[0],l=t[1];T(o,l,r)}))},Y=X,C=function(e,t){return function(n){if(!a()){var o={scroll:y,scrollTo:g,scrollBy:b}[e];t((function(t){t[e]=function(){var e=arguments;if(1!==arguments.length){var t=e[0],r=e[1];o(this,{left:t,top:r})}else o(this,e[0],n)},f(t[e])}))}}},F=C("scroll",s),$=C("scrollTo",s),R=C("scrollBy",s),A=function(e){e(window)},N=C("scroll",A),q=C("scrollTo",A),z=C("scrollBy",A),G=function(e){if(!a()){var t=c(window.HTMLElement.prototype,"scrollIntoView");s((function(n){n.scrollIntoView=function(){var n=arguments,o=n[0];1===n.length&&u(o)?Y(this,o,e):t.apply(this,n)},f(n.scrollIntoView)}))}};e.elementScroll=T,e.elementScrollBy=S,e.elementScrollByPolyfill=R,e.elementScrollIntoView=Y,e.elementScrollIntoViewPolyfill=G,e.elementScrollPolyfill=F,e.elementScrollTo=E,e.elementScrollToPolyfill=$,e.polyfill=function(e){a()||(F(e),$(e),R(e),G(e),N(e),q(e),z(e))},e.scroll=y,e.scrollBy=b,e.scrollIntoView=X,e.scrollTo=g,e.windowScroll=P,e.windowScrollBy=B,e.windowScrollByPolyfill=z,e.windowScrollPolyfill=N,e.windowScrollTo=V,e.windowScrollToPolyfill=q,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=bundle.min.js.map |
@@ -1,6 +0,4 @@ | ||
export * from "../Element/index.js"; | ||
export * from "../Element/polyfill.js"; | ||
export * from "../Window/index.js"; | ||
export * from "../Window/polyfill.js"; | ||
export * from "./seamless-polyfill.js"; | ||
export * from "./scroll.js"; | ||
export * from "./scrollIntoView.js"; | ||
export * from "./polyfill.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,6 +0,4 @@ | ||
export * from "../Element/index.js"; | ||
export * from "../Element/polyfill.js"; | ||
export * from "../Window/index.js"; | ||
export * from "../Window/polyfill.js"; | ||
export * from "./seamless-polyfill.js"; | ||
export * from "./scroll.js"; | ||
export * from "./scrollIntoView.js"; | ||
export * from "./polyfill.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ { | ||
"description": "Smooth Scroll behavior polyfill", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"author": { | ||
@@ -38,4 +38,10 @@ "name": "Dustan Kasten", | ||
}, | ||
"main": "lib/bundle.js", | ||
"module": "lib/index.js", | ||
"type": "module", | ||
"main": "./lib/bundle.js", | ||
"browser": "./lib/bundle.min.js", | ||
"module": "./lib/index.js", | ||
"exports": { | ||
"import": "./lib/index.js", | ||
"default": "./lib/bundle.js" | ||
}, | ||
"types": "lib/index.d.ts", | ||
@@ -42,0 +48,0 @@ "sideEffects": false, |
@@ -6,3 +6,3 @@ import { terser } from "rollup-plugin-terser"; | ||
const rollupOptions = { | ||
input: "lib/index.ts", | ||
input: "src/index.ts", | ||
plugins: typescript({ | ||
@@ -9,0 +9,0 @@ useTsconfigDeclarationDir: true, |
{ | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib", | ||
"target": "es2021", | ||
@@ -14,4 +16,3 @@ "module": "esnext", | ||
"noUncheckedIndexedAccess": true | ||
}, | ||
"include": [".internal", "Element", "lib", "Window"] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Yes
417116
63
2221
1