scroll-direction-manager 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scroll-direction-manager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A utility package that simplifies tracking the scroll direction (up, down, or initial) of a web page",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
|
-
"module": "dist/esm/index.mjs",
|
|
7
6
|
"types": "dist/cjs/index.d.ts",
|
|
8
7
|
"scripts": {
|
|
8
|
+
"clean": "rm -rf dist/esm",
|
|
9
9
|
"build:cjs": "tsc --project tsconfig.json",
|
|
10
|
-
"build
|
|
11
|
-
"build": "npm run build:cjs && npm run build:esm",
|
|
10
|
+
"build": "npm run build:cjs",
|
|
12
11
|
"test": "jest",
|
|
13
12
|
"test:watch": "jest --watch",
|
|
14
13
|
"test:coverage": "jest --coverage"
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type ScrollDirection = "initial" | "up" | "down";
|
|
2
|
-
type ScrollDirectionManagerOptions = {
|
|
3
|
-
initialOffset?: number;
|
|
4
|
-
onDirectionChange?: (direction: ScrollDirection) => void;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* @example
|
|
8
|
-
* const scrollDirection = new ScrollDirection({
|
|
9
|
-
* onDirectionChange: (direction) => {
|
|
10
|
-
* if (direction === "up") // do something if its up
|
|
11
|
-
* else if (direction === "initial") // do if its initial
|
|
12
|
-
* },
|
|
13
|
-
* treshold: 30
|
|
14
|
-
* })
|
|
15
|
-
*/
|
|
16
|
-
export declare class ScrollDirectionManager {
|
|
17
|
-
private readonly onDirectionChange;
|
|
18
|
-
private scrollPosition;
|
|
19
|
-
private scrollDirection;
|
|
20
|
-
private readonly initialOffset;
|
|
21
|
-
private readonly disposables;
|
|
22
|
-
constructor({ initialOffset, onDirectionChange }: ScrollDirectionManagerOptions);
|
|
23
|
-
private readonly setupSubscriptions;
|
|
24
|
-
private readonly handleScrollDirection;
|
|
25
|
-
dispose(): void;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { addEventListener } from "seng-disposable-event-listener";
|
|
2
|
-
import { DisposableManager } from "seng-disposable-manager";
|
|
3
|
-
/**
|
|
4
|
-
* @example
|
|
5
|
-
* const scrollDirection = new ScrollDirection({
|
|
6
|
-
* onDirectionChange: (direction) => {
|
|
7
|
-
* if (direction === "up") // do something if its up
|
|
8
|
-
* else if (direction === "initial") // do if its initial
|
|
9
|
-
* },
|
|
10
|
-
* treshold: 30
|
|
11
|
-
* })
|
|
12
|
-
*/
|
|
13
|
-
var ScrollDirectionManager = /** @class */ (function () {
|
|
14
|
-
function ScrollDirectionManager(_a) {
|
|
15
|
-
var initialOffset = _a.initialOffset, onDirectionChange = _a.onDirectionChange;
|
|
16
|
-
var _this = this;
|
|
17
|
-
this.onDirectionChange = undefined;
|
|
18
|
-
this.scrollDirection = "initial";
|
|
19
|
-
this.initialOffset = 120;
|
|
20
|
-
this.disposables = new DisposableManager();
|
|
21
|
-
this.setupSubscriptions = function () {
|
|
22
|
-
_this.disposables.add(addEventListener(window, "scroll", _this.handleScrollDirection));
|
|
23
|
-
};
|
|
24
|
-
this.handleScrollDirection = function () {
|
|
25
|
-
var _a;
|
|
26
|
-
var position = window.scrollY;
|
|
27
|
-
var direction = "initial";
|
|
28
|
-
if (position > _this.initialOffset) {
|
|
29
|
-
if (position < _this.scrollPosition) {
|
|
30
|
-
direction = "up";
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
direction = "down";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (direction !== _this.scrollDirection) {
|
|
37
|
-
(_a = _this.onDirectionChange) === null || _a === void 0 ? void 0 : _a.call(_this, direction);
|
|
38
|
-
}
|
|
39
|
-
_this.scrollPosition = position;
|
|
40
|
-
_this.scrollDirection = direction;
|
|
41
|
-
};
|
|
42
|
-
this.scrollPosition = 0;
|
|
43
|
-
if (initialOffset)
|
|
44
|
-
this.initialOffset = initialOffset;
|
|
45
|
-
this.onDirectionChange = onDirectionChange;
|
|
46
|
-
this.setupSubscriptions();
|
|
47
|
-
}
|
|
48
|
-
ScrollDirectionManager.prototype.dispose = function () {
|
|
49
|
-
this.disposables.dispose();
|
|
50
|
-
};
|
|
51
|
-
return ScrollDirectionManager;
|
|
52
|
-
}());
|
|
53
|
-
export { ScrollDirectionManager };
|
package/dist/esm/index.d.ts
DELETED
package/dist/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ScrollDirectionManager } from "./ScrollDirectionManager";
|
package/tsconfig.build.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES5",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"outDir": "./dist/esm",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["src/**/*"],
|
|
13
|
-
"exclude": ["node_modules", "**/__tests__/*"]
|
|
14
|
-
}
|