Comparing version 1.5.2 to 1.5.3
/** | ||
scrolldir - Vertical scroll direction in CSS | ||
@version v1.5.2 | ||
@version v1.5.3 | ||
@link https://github.com/yowainwright/scrolldir.git | ||
@@ -11,9 +11,7 @@ @author Patrick Fisher <patrick@pwfisher.com>, Jeffry Wainwright <yowainwright@gmail.com> | ||
factory(); | ||
}((function () { 'use strict'; | ||
})((function () { 'use strict'; | ||
var attribute = 'data-scrolldir'; | ||
var dir = 'down'; // 'up' or 'down' | ||
var thresholdPixels = 64; // Ignore moves smaller than this. | ||
var el = document.documentElement; | ||
@@ -23,21 +21,18 @@ var win = window; | ||
var historyLength = 32; // Ticks to keep in history. | ||
var historyMaxAge = 512; // History data time-to-live (ms). | ||
var history = Array(historyLength); | ||
var e; // last scroll event | ||
var pivot; // "high-water mark" | ||
var pivotTime = 0; | ||
function tick() { | ||
var y = win.scrollY || win.pageYOffset; | ||
var t = e.timeStamp; | ||
var furthest = dir === 'down' ? Math.max : Math.min; // Apply bounds to handle rubber banding | ||
var furthest = dir === 'down' ? Math.max : Math.min; | ||
// Apply bounds to handle rubber banding | ||
var yMax = body.scrollHeight - win.innerHeight; | ||
y = Math.max(0, y); | ||
y = Math.min(yMax, y); // Update history | ||
y = Math.min(yMax, y); | ||
// Update history | ||
history.unshift({ | ||
@@ -47,4 +42,5 @@ y: y, | ||
}); | ||
history.pop(); // Are we continuing in the same direction? | ||
history.pop(); | ||
// Are we continuing in the same direction? | ||
if (y === furthest(pivot, y)) { | ||
@@ -55,11 +51,9 @@ // Update "high-water mark" for current direction | ||
return; | ||
} // else we have backed off high-water mark | ||
} | ||
// else we have backed off high-water mark | ||
// Apply max age to find current reference point | ||
var cutoffTime = t - historyMaxAge; | ||
if (cutoffTime > pivotTime) { | ||
pivot = y; | ||
for (var i = 0; i < historyLength; i += 1) { | ||
@@ -69,5 +63,5 @@ if (!history[i] || history[i].t < cutoffTime) break; | ||
} | ||
} // Have we exceeded threshold? | ||
} | ||
// Have we exceeded threshold? | ||
if (Math.abs(y - pivot) > thresholdPixels) { | ||
@@ -80,3 +74,2 @@ pivot = y; | ||
} | ||
function handler(event) { | ||
@@ -86,3 +79,2 @@ e = event; | ||
} | ||
function scrollDir(opts) { | ||
@@ -94,6 +86,6 @@ if (opts) { | ||
if (opts.dir) dir = opts.dir; | ||
if (opts.thresholdPixels) thresholdPixels = opts.thresholdPixels; // If opts.off, turn it off | ||
if (opts.thresholdPixels) thresholdPixels = opts.thresholdPixels; | ||
// If opts.off, turn it off | ||
// - set html[data-scrolldir="off"] | ||
// - remove the event listener | ||
if (opts.off === true) { | ||
@@ -103,7 +95,7 @@ el.setAttribute(attribute, 'off'); | ||
} | ||
} // else, turn it on | ||
} | ||
// else, turn it on | ||
// - set html[data-scrolldir="down"] | ||
// - add the event listener | ||
pivot = win.scrollY || win.pageYOffset; | ||
@@ -116,2 +108,2 @@ el.setAttribute(attribute, dir); | ||
}))); | ||
})); |
/** | ||
scrolldir - Vertical scroll direction in CSS | ||
@version v1.5.2 | ||
@version v1.5.3 | ||
@link https://github.com/yowainwright/scrolldir.git | ||
@@ -5,0 +5,0 @@ @author Patrick Fisher <patrick@pwfisher.com>, Jeffry Wainwright <yowainwright@gmail.com> |
/** | ||
scrolldir - Vertical scroll direction in CSS | ||
@version v1.5.2 | ||
@version v1.5.3 | ||
@link https://github.com/yowainwright/scrolldir.git | ||
@@ -10,5 +10,3 @@ @author Patrick Fisher <patrick@pwfisher.com>, Jeffry Wainwright <yowainwright@gmail.com> | ||
var dir = 'down'; // 'up' or 'down' | ||
var thresholdPixels = 64; // Ignore moves smaller than this. | ||
var el = document.documentElement; | ||
@@ -18,21 +16,18 @@ var win = window; | ||
var historyLength = 32; // Ticks to keep in history. | ||
var historyMaxAge = 512; // History data time-to-live (ms). | ||
var history = Array(historyLength); | ||
var e; // last scroll event | ||
var pivot; // "high-water mark" | ||
var pivotTime = 0; | ||
function tick() { | ||
var y = win.scrollY || win.pageYOffset; | ||
var t = e.timeStamp; | ||
var furthest = dir === 'down' ? Math.max : Math.min; // Apply bounds to handle rubber banding | ||
var furthest = dir === 'down' ? Math.max : Math.min; | ||
// Apply bounds to handle rubber banding | ||
var yMax = body.scrollHeight - win.innerHeight; | ||
y = Math.max(0, y); | ||
y = Math.min(yMax, y); // Update history | ||
y = Math.min(yMax, y); | ||
// Update history | ||
history.unshift({ | ||
@@ -42,4 +37,5 @@ y: y, | ||
}); | ||
history.pop(); // Are we continuing in the same direction? | ||
history.pop(); | ||
// Are we continuing in the same direction? | ||
if (y === furthest(pivot, y)) { | ||
@@ -50,11 +46,9 @@ // Update "high-water mark" for current direction | ||
return; | ||
} // else we have backed off high-water mark | ||
} | ||
// else we have backed off high-water mark | ||
// Apply max age to find current reference point | ||
var cutoffTime = t - historyMaxAge; | ||
if (cutoffTime > pivotTime) { | ||
pivot = y; | ||
for (var i = 0; i < historyLength; i += 1) { | ||
@@ -64,5 +58,5 @@ if (!history[i] || history[i].t < cutoffTime) break; | ||
} | ||
} // Have we exceeded threshold? | ||
} | ||
// Have we exceeded threshold? | ||
if (Math.abs(y - pivot) > thresholdPixels) { | ||
@@ -75,3 +69,2 @@ pivot = y; | ||
} | ||
function handler(event) { | ||
@@ -81,3 +74,2 @@ e = event; | ||
} | ||
function scrollDir(opts) { | ||
@@ -89,6 +81,6 @@ if (opts) { | ||
if (opts.dir) dir = opts.dir; | ||
if (opts.thresholdPixels) thresholdPixels = opts.thresholdPixels; // If opts.off, turn it off | ||
if (opts.thresholdPixels) thresholdPixels = opts.thresholdPixels; | ||
// If opts.off, turn it off | ||
// - set html[data-scrolldir="off"] | ||
// - remove the event listener | ||
if (opts.off === true) { | ||
@@ -98,7 +90,7 @@ el.setAttribute(attribute, 'off'); | ||
} | ||
} // else, turn it on | ||
} | ||
// else, turn it on | ||
// - set html[data-scrolldir="down"] | ||
// - add the event listener | ||
pivot = win.scrollY || win.pageYOffset; | ||
@@ -109,2 +101,2 @@ el.setAttribute(attribute, dir); | ||
export default scrollDir; | ||
export { scrollDir as default }; |
/** | ||
scrolldir - Vertical scroll direction in CSS | ||
@version v1.5.2 | ||
@version v1.5.3 | ||
@link https://github.com/yowainwright/scrolldir.git | ||
@@ -11,10 +11,8 @@ @author Patrick Fisher <patrick@pwfisher.com>, Jeffry Wainwright <yowainwright@gmail.com> | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.scrollDir = factory()); | ||
}(this, (function () { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.scrollDir = factory()); | ||
})(this, (function () { 'use strict'; | ||
var attribute = 'data-scrolldir'; | ||
var dir = 'down'; // 'up' or 'down' | ||
var thresholdPixels = 64; // Ignore moves smaller than this. | ||
var el = document.documentElement; | ||
@@ -24,21 +22,18 @@ var win = window; | ||
var historyLength = 32; // Ticks to keep in history. | ||
var historyMaxAge = 512; // History data time-to-live (ms). | ||
var history = Array(historyLength); | ||
var e; // last scroll event | ||
var pivot; // "high-water mark" | ||
var pivotTime = 0; | ||
function tick() { | ||
var y = win.scrollY || win.pageYOffset; | ||
var t = e.timeStamp; | ||
var furthest = dir === 'down' ? Math.max : Math.min; // Apply bounds to handle rubber banding | ||
var furthest = dir === 'down' ? Math.max : Math.min; | ||
// Apply bounds to handle rubber banding | ||
var yMax = body.scrollHeight - win.innerHeight; | ||
y = Math.max(0, y); | ||
y = Math.min(yMax, y); // Update history | ||
y = Math.min(yMax, y); | ||
// Update history | ||
history.unshift({ | ||
@@ -48,4 +43,5 @@ y: y, | ||
}); | ||
history.pop(); // Are we continuing in the same direction? | ||
history.pop(); | ||
// Are we continuing in the same direction? | ||
if (y === furthest(pivot, y)) { | ||
@@ -56,11 +52,9 @@ // Update "high-water mark" for current direction | ||
return; | ||
} // else we have backed off high-water mark | ||
} | ||
// else we have backed off high-water mark | ||
// Apply max age to find current reference point | ||
var cutoffTime = t - historyMaxAge; | ||
if (cutoffTime > pivotTime) { | ||
pivot = y; | ||
for (var i = 0; i < historyLength; i += 1) { | ||
@@ -70,5 +64,5 @@ if (!history[i] || history[i].t < cutoffTime) break; | ||
} | ||
} // Have we exceeded threshold? | ||
} | ||
// Have we exceeded threshold? | ||
if (Math.abs(y - pivot) > thresholdPixels) { | ||
@@ -81,3 +75,2 @@ pivot = y; | ||
} | ||
function handler(event) { | ||
@@ -87,3 +80,2 @@ e = event; | ||
} | ||
function scrollDir(opts) { | ||
@@ -95,6 +87,6 @@ if (opts) { | ||
if (opts.dir) dir = opts.dir; | ||
if (opts.thresholdPixels) thresholdPixels = opts.thresholdPixels; // If opts.off, turn it off | ||
if (opts.thresholdPixels) thresholdPixels = opts.thresholdPixels; | ||
// If opts.off, turn it off | ||
// - set html[data-scrolldir="off"] | ||
// - remove the event listener | ||
if (opts.off === true) { | ||
@@ -104,7 +96,7 @@ el.setAttribute(attribute, 'off'); | ||
} | ||
} // else, turn it on | ||
} | ||
// else, turn it on | ||
// - set html[data-scrolldir="down"] | ||
// - add the event listener | ||
pivot = win.scrollY || win.pageYOffset; | ||
@@ -117,2 +109,2 @@ el.setAttribute(attribute, dir); | ||
}))); | ||
})); |
/** | ||
scrolldir - Vertical scroll direction in CSS | ||
@version v1.5.2 | ||
@version v1.5.3 | ||
@link https://github.com/yowainwright/scrolldir.git | ||
@@ -8,2 +8,2 @@ @author Patrick Fisher <patrick@pwfisher.com>, Jeffry Wainwright <yowainwright@gmail.com> | ||
**/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).scrollDir=e()}(this,function(){"use strict";var s,d,f="data-scrolldir",u="down",a=64,l=document.documentElement,c=window,m=document.body,h=32,p=512,b=Array(h),v=0;function e(){var t=c.scrollY||c.pageYOffset,e=s.timeStamp,n="down"===u?Math.max:Math.min,r=m.scrollHeight-c.innerHeight;if(t=Math.max(0,t),t=Math.min(r,t),b.unshift({y:t,t:e}),b.pop(),t===n(d,t))return v=e,void(d=t);var i=e-p;if(v<i){d=t;for(var o=0;o<h&&(b[o]&&!(b[o].t<i));o+=1)d=n(d,b[o].y)}Math.abs(t-d)>a&&(d=t,v=e,u="down"===u?"up":"down",l.setAttribute(f,u))}function n(t){return s=t,c.requestAnimationFrame(e)}return function(t){return t&&(t.attribute&&(f=t.attribute),t.el&&(l=t.el),t.win&&(c=t.win),t.dir&&(u=t.dir),t.thresholdPixels&&(a=t.thresholdPixels),!0===t.off)?(l.setAttribute(f,"off"),c.removeEventListener("scroll",n)):(d=c.scrollY||c.pageYOffset,l.setAttribute(f,u),c.addEventListener("scroll",n))}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).scrollDir=e()}(this,function(){"use strict";var s,d,f="data-scrolldir",l="down",a=64,u=document.documentElement,c=window,m=document.body,h=32,p=512,b=Array(h),v=0;function e(){var t=c.scrollY||c.pageYOffset,e=s.timeStamp,n="down"===l?Math.max:Math.min,i=m.scrollHeight-c.innerHeight;if(t=Math.max(0,t),t=Math.min(i,t),b.unshift({y:t,t:e}),b.pop(),t===n(d,t))return v=e,void(d=t);var o=e-p;if(v<o){d=t;for(var r=0;r<h&&(b[r]&&!(b[r].t<o));r+=1)d=n(d,b[r].y)}Math.abs(t-d)>a&&(d=t,v=e,l="down"===l?"up":"down",u.setAttribute(f,l))}function n(t){return s=t,c.requestAnimationFrame(e)}return function(t){return t&&(t.attribute&&(f=t.attribute),t.el&&(u=t.el),t.win&&(c=t.win),t.dir&&(l=t.dir),t.thresholdPixels&&(a=t.thresholdPixels),!0===t.off)?(u.setAttribute(f,"off"),c.removeEventListener("scroll",n)):(d=c.scrollY||c.pageYOffset,u.setAttribute(f,l),c.addEventListener("scroll",n))}}); |
{ | ||
"name": "scrolldir", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"description": "Vertical scroll direction in CSS", | ||
@@ -8,9 +8,11 @@ "main": "dist/scrolldir.js", | ||
"unpkg": "dist/scrolldir.min.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "npm run test:acceptance && npm run test:es-check", | ||
"build": "rollup --config rollup.config.mjs", | ||
"lint": "eslint src/*.js --fix", | ||
"prepublishOnly": "yarn build", | ||
"test": "yarn build && yarn test:acceptance && yarn test:es-check", | ||
"test:acceptance": "node ./scripts/run-tests.js", | ||
"test:es-check": "es-check es5 dist/scrolldir.auto.js dist/scrolldir.js dist/scrolldir.min.js dist/scrolldir.auto.min.js", | ||
"build": "rollup --config rollup.config.js", | ||
"lint": "eslint src/*.js --fix", | ||
"postpublish": "git tag $npm_package_version && git push origin --tags" | ||
"update": "codependence --update" | ||
}, | ||
@@ -37,15 +39,23 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0-beta.46", | ||
"@babel/preset-env": "^7.0.0-beta.46", | ||
"@heartly/eslint-config": "^0.0.2", | ||
"es-check": "^5.0.0", | ||
"eslint": "^6.0.0", | ||
"node-qunit-phantomjs": "^2.0.0", | ||
"qunit": "^2.6.2", | ||
"rollup": "^1.19.4", | ||
"rollup-plugin-babel": "^4.0.0-beta.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-uglify": "^6.0.0" | ||
"@babel/core": "7.20.12", | ||
"@babel/preset-env": "7.20.2", | ||
"codependence": "^0.2.6", | ||
"es-check": "7.1.0", | ||
"eslint": "8.34.0", | ||
"eslint-config-prettier": "8.6.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"node-qunit-phantomjs": "2.1.1", | ||
"prettier": "2.8.4", | ||
"qunit": "2.19.4", | ||
"rollup": "3.15.0", | ||
"rollup-plugin-babel": "4.4.0", | ||
"rollup-plugin-replace": "2.2.0", | ||
"rollup-plugin-uglify": "6.0.4" | ||
}, | ||
"prettier": "@heartly/eslint-config/dist/prettier" | ||
"prettier": "@heartly/eslint-config/dist/prettier", | ||
"release-it": { | ||
"git": { | ||
"commitMessage": "chore: release v%s" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
const qunit = require('node-qunit-phantomjs') | ||
import qunit from 'node-qunit-phantomjs' | ||
@@ -3,0 +3,0 @@ qunit('tests/auto/index.html') |
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
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
32913
31
496
Yes
14