🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

scroll-snap

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-snap - npm Package Compare versions

Comparing version

to
4.0.2

4

dist/esm/index.d.ts

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

interface ScrollSnapConfiguration {
interface Settings {
/**

@@ -30,3 +30,3 @@ * snap-destination for x and y axes

}
export default function createScrollSnap(element: HTMLElement, config: ScrollSnapConfiguration, callback: () => void): {
export default function createScrollSnap(element: HTMLElement, settings: Settings, callback: () => void): {
bind: () => void;

@@ -33,0 +33,0 @@ unbind: () => void;

@@ -11,4 +11,4 @@ function easeInOutQuad(t) {

var NOOP = function () { };
export default function createScrollSnap(element, config, callback) {
if (config === void 0) { config = {}; }
export default function createScrollSnap(element, settings, callback) {
if (settings === void 0) { settings = {}; }
var onAnimationEnd = typeof callback === 'function' ? callback : NOOP;

@@ -29,7 +29,7 @@ var listenerElement;

var animationFrame;
var snapDestinationX = config.snapDestinationX, snapDestinationY = config.snapDestinationY;
var snapDestinationX = settings.snapDestinationX, snapDestinationY = settings.snapDestinationY;
if (snapDestinationX &&
typeof snapDestinationX !== 'string' &&
typeof snapDestinationX !== 'number') {
throw new Error("Config property 'snapDestinationX' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationX).toUpperCase());
throw new Error("Settings property 'snapDestinationX' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationX).toUpperCase());
}

@@ -39,25 +39,26 @@ if (snapDestinationY &&

typeof snapDestinationY !== 'number') {
throw new Error("Config property 'snapDestinationY' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationY).toUpperCase());
throw new Error("Settings property 'snapDestinationY' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationY).toUpperCase());
}
if (config.timeout && (isNaN(config.timeout) || typeof config.timeout === 'boolean')) {
throw new Error("Optional config property 'timeout' is not valid, expected NUMBER but found " + (typeof config.timeout).toUpperCase());
if (settings.timeout && (isNaN(settings.timeout) || typeof settings.timeout === 'boolean')) {
throw new Error("Optional settings property 'timeout' is not valid, expected NUMBER but found " + (typeof settings.timeout).toUpperCase());
}
// any value less then TIMEOUT_MIN may cause weird bahaviour on some devices (especially on mobile with momentum scrolling)
var timeout = config.timeout && config.timeout >= TIMEOUT_MIN ? config.timeout : TIMEOUT_DEFAULT;
if (config.duration && (isNaN(config.duration) || typeof config.duration === 'boolean')) {
throw new Error("Optional config property 'duration' is not valid, expected NUMBER but found " + (typeof config.duration).toUpperCase());
var timeout = settings.timeout && settings.timeout >= TIMEOUT_MIN ? settings.timeout : TIMEOUT_DEFAULT;
if (settings.duration && (isNaN(settings.duration) || typeof settings.duration === 'boolean')) {
throw new Error("Optional settings property 'duration' is not valid, expected NUMBER but found " + (typeof settings.duration).toUpperCase());
}
var duration = config.duration || DURATION_DEFAULT;
if (config.threshold && (isNaN(config.threshold) || typeof config.threshold === 'boolean')) {
throw new Error("Optional config property 'threshold' is not valid, expected NUMBER but found " + (typeof config.threshold).toUpperCase());
var duration = settings.duration || DURATION_DEFAULT;
if (settings.threshold &&
(isNaN(settings.threshold) || typeof settings.threshold === 'boolean')) {
throw new Error("Optional settings property 'threshold' is not valid, expected NUMBER but found " + (typeof settings.threshold).toUpperCase());
}
var threshold = config.threshold || THRESHOLD_DEFAULT;
if (config.easing && typeof config.easing !== 'function') {
throw new Error("Optional config property 'easing' is not valid, expected FUNCTION but found " + (typeof config.easing).toUpperCase());
var threshold = settings.threshold || THRESHOLD_DEFAULT;
if (settings.easing && typeof settings.easing !== 'function') {
throw new Error("Optional settings property 'easing' is not valid, expected FUNCTION but found " + (typeof settings.easing).toUpperCase());
}
var easing = config.easing || EASING_DEFAULT;
if (config.snapStop && typeof config.snapStop !== 'boolean') {
throw new Error("Optional config property 'snapStop' is not valid, expected BOOLEAN but found " + (typeof config.snapStop).toUpperCase());
var easing = settings.easing || EASING_DEFAULT;
if (settings.snapStop && typeof settings.snapStop !== 'boolean') {
throw new Error("Optional settings property 'snapStop' is not valid, expected BOOLEAN but found " + (typeof settings.snapStop).toUpperCase());
}
var snapStop = config.snapStop || SNAPSTOP_DEFAULT;
var snapStop = settings.snapStop || SNAPSTOP_DEFAULT;
function checkScrollSpeed(value, axis) {

@@ -84,3 +85,3 @@ var clear = function () {

listenerElement.addEventListener('scroll', startAnimation, false);
snapLengthUnit = parseSnapCoordValue(snapDestinationX, snapDestinationY);
snapLengthUnit = parseSnapCoordinatesValue(snapDestinationX, snapDestinationY);
}

@@ -223,3 +224,3 @@ function unbindElement() {

}
function parseSnapCoordValue(x, y) {
function parseSnapCoordinatesValue(x, y) {
// regex to parse lengths

@@ -290,4 +291,4 @@ var regex = /([+-]?(?=\.\d|\d)(?:\d+)?(?:\.?\d*)(?:[eE][+-]?\d+)?)(px|%|vw|vh)/;

}
function isEdge(coords) {
return (coords.x === 0 && speedDeltaY === 0) || (coords.y === 0 && speedDeltaX === 0);
function isEdge(Coordinates) {
return (Coordinates.x === 0 && speedDeltaY === 0) || (Coordinates.y === 0 && speedDeltaX === 0);
}

@@ -294,0 +295,0 @@ function smoothScroll(obj, end, callback) {

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

interface ScrollSnapConfiguration {
interface Settings {
/**

@@ -30,3 +30,3 @@ * snap-destination for x and y axes

}
export default function createScrollSnap(element: HTMLElement, config: ScrollSnapConfiguration, callback: () => void): {
export default function createScrollSnap(element: HTMLElement, settings: Settings, callback: () => void): {
bind: () => void;

@@ -33,0 +33,0 @@ unbind: () => void;

@@ -22,4 +22,4 @@ (function (factory) {

var NOOP = function () { };
function createScrollSnap(element, config, callback) {
if (config === void 0) { config = {}; }
function createScrollSnap(element, settings, callback) {
if (settings === void 0) { settings = {}; }
var onAnimationEnd = typeof callback === 'function' ? callback : NOOP;

@@ -40,7 +40,7 @@ var listenerElement;

var animationFrame;
var snapDestinationX = config.snapDestinationX, snapDestinationY = config.snapDestinationY;
var snapDestinationX = settings.snapDestinationX, snapDestinationY = settings.snapDestinationY;
if (snapDestinationX &&
typeof snapDestinationX !== 'string' &&
typeof snapDestinationX !== 'number') {
throw new Error("Config property 'snapDestinationX' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationX).toUpperCase());
throw new Error("Settings property 'snapDestinationX' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationX).toUpperCase());
}

@@ -50,25 +50,26 @@ if (snapDestinationY &&

typeof snapDestinationY !== 'number') {
throw new Error("Config property 'snapDestinationY' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationY).toUpperCase());
throw new Error("Settings property 'snapDestinationY' is not valid, expected STRING or NUMBER but found " + (typeof snapDestinationY).toUpperCase());
}
if (config.timeout && (isNaN(config.timeout) || typeof config.timeout === 'boolean')) {
throw new Error("Optional config property 'timeout' is not valid, expected NUMBER but found " + (typeof config.timeout).toUpperCase());
if (settings.timeout && (isNaN(settings.timeout) || typeof settings.timeout === 'boolean')) {
throw new Error("Optional settings property 'timeout' is not valid, expected NUMBER but found " + (typeof settings.timeout).toUpperCase());
}
// any value less then TIMEOUT_MIN may cause weird bahaviour on some devices (especially on mobile with momentum scrolling)
var timeout = config.timeout && config.timeout >= TIMEOUT_MIN ? config.timeout : TIMEOUT_DEFAULT;
if (config.duration && (isNaN(config.duration) || typeof config.duration === 'boolean')) {
throw new Error("Optional config property 'duration' is not valid, expected NUMBER but found " + (typeof config.duration).toUpperCase());
var timeout = settings.timeout && settings.timeout >= TIMEOUT_MIN ? settings.timeout : TIMEOUT_DEFAULT;
if (settings.duration && (isNaN(settings.duration) || typeof settings.duration === 'boolean')) {
throw new Error("Optional settings property 'duration' is not valid, expected NUMBER but found " + (typeof settings.duration).toUpperCase());
}
var duration = config.duration || DURATION_DEFAULT;
if (config.threshold && (isNaN(config.threshold) || typeof config.threshold === 'boolean')) {
throw new Error("Optional config property 'threshold' is not valid, expected NUMBER but found " + (typeof config.threshold).toUpperCase());
var duration = settings.duration || DURATION_DEFAULT;
if (settings.threshold &&
(isNaN(settings.threshold) || typeof settings.threshold === 'boolean')) {
throw new Error("Optional settings property 'threshold' is not valid, expected NUMBER but found " + (typeof settings.threshold).toUpperCase());
}
var threshold = config.threshold || THRESHOLD_DEFAULT;
if (config.easing && typeof config.easing !== 'function') {
throw new Error("Optional config property 'easing' is not valid, expected FUNCTION but found " + (typeof config.easing).toUpperCase());
var threshold = settings.threshold || THRESHOLD_DEFAULT;
if (settings.easing && typeof settings.easing !== 'function') {
throw new Error("Optional settings property 'easing' is not valid, expected FUNCTION but found " + (typeof settings.easing).toUpperCase());
}
var easing = config.easing || EASING_DEFAULT;
if (config.snapStop && typeof config.snapStop !== 'boolean') {
throw new Error("Optional config property 'snapStop' is not valid, expected BOOLEAN but found " + (typeof config.snapStop).toUpperCase());
var easing = settings.easing || EASING_DEFAULT;
if (settings.snapStop && typeof settings.snapStop !== 'boolean') {
throw new Error("Optional settings property 'snapStop' is not valid, expected BOOLEAN but found " + (typeof settings.snapStop).toUpperCase());
}
var snapStop = config.snapStop || SNAPSTOP_DEFAULT;
var snapStop = settings.snapStop || SNAPSTOP_DEFAULT;
function checkScrollSpeed(value, axis) {

@@ -95,3 +96,3 @@ var clear = function () {

listenerElement.addEventListener('scroll', startAnimation, false);
snapLengthUnit = parseSnapCoordValue(snapDestinationX, snapDestinationY);
snapLengthUnit = parseSnapCoordinatesValue(snapDestinationX, snapDestinationY);
}

@@ -234,3 +235,3 @@ function unbindElement() {

}
function parseSnapCoordValue(x, y) {
function parseSnapCoordinatesValue(x, y) {
// regex to parse lengths

@@ -301,4 +302,4 @@ var regex = /([+-]?(?=\.\d|\d)(?:\d+)?(?:\.?\d*)(?:[eE][+-]?\d+)?)(px|%|vw|vh)/;

}
function isEdge(coords) {
return (coords.x === 0 && speedDeltaY === 0) || (coords.y === 0 && speedDeltaX === 0);
function isEdge(Coordinates) {
return (Coordinates.x === 0 && speedDeltaY === 0) || (Coordinates.y === 0 && speedDeltaX === 0);
}

@@ -305,0 +306,0 @@ function smoothScroll(obj, end, callback) {

{
"name": "scroll-snap",
"version": "4.0.1",
"version": "4.0.2",
"description": "Snap page when user stops scrolling, with a customizable configuration and a consistent cross browser behaviour",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -16,3 +16,3 @@ <p align="center">

- `requestAnimationFrame` for 60fps
- Customizable configuration (including easing functions)
- Customizable settings (including easing functions)
- No additional dependencies

@@ -32,3 +32,3 @@ - No extra stylesheet

```js
createScrollSnap(element, configuration, [callback])
createScrollSnap(element, settings, [callback])
```

@@ -42,3 +42,3 @@

### `configuration: ScrollSnapConfiguration`
### `settings: Settings`

@@ -45,0 +45,0 @@ A configuraiton object consisting of one or more of the following keys:

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet