seitu 0.2.1 → 0.2.2
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/dist/react/hooks.d.ts +1 -1
- package/dist/web/scroll-state.d.ts +15 -7
- package/dist/web.js +23 -13
- package/package.json +1 -1
package/dist/react/hooks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Readable, Subscribable } from '../core/index';
|
|
2
2
|
export type ScrollDirection = 'vertical' | 'horizontal' | 'both';
|
|
3
3
|
export interface ScrollStateEdge {
|
|
4
|
-
|
|
4
|
+
reached: boolean;
|
|
5
5
|
remaining: number;
|
|
6
6
|
}
|
|
7
7
|
export interface ScrollStateValue {
|
|
@@ -10,6 +10,12 @@ export interface ScrollStateValue {
|
|
|
10
10
|
left: ScrollStateEdge;
|
|
11
11
|
right: ScrollStateEdge;
|
|
12
12
|
}
|
|
13
|
+
export interface ScrollStateThreshold {
|
|
14
|
+
top?: number;
|
|
15
|
+
bottom?: number;
|
|
16
|
+
left?: number;
|
|
17
|
+
right?: number;
|
|
18
|
+
}
|
|
13
19
|
export interface ScrollState extends Subscribable<ScrollStateValue>, Readable<ScrollStateValue> {
|
|
14
20
|
}
|
|
15
21
|
export interface ScrollStateOptions {
|
|
@@ -25,10 +31,12 @@ export interface ScrollStateOptions {
|
|
|
25
31
|
*/
|
|
26
32
|
direction?: ScrollDirection;
|
|
27
33
|
/**
|
|
28
|
-
* Number of pixels from each edge before it counts as "
|
|
34
|
+
* Number of pixels from each edge before it counts as "reached".
|
|
35
|
+
* Pass a single number to apply the same threshold to all edges,
|
|
36
|
+
* or an object with per-side values.
|
|
29
37
|
* @default 0
|
|
30
38
|
*/
|
|
31
|
-
threshold?: number;
|
|
39
|
+
threshold?: number | ScrollStateThreshold;
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* Creates a reactive handle that tracks scroll position of an element relative to each edge.
|
|
@@ -44,9 +52,9 @@ export interface ScrollStateOptions {
|
|
|
44
52
|
* })
|
|
45
53
|
*
|
|
46
54
|
* scroll.subscribe(state => {
|
|
47
|
-
* console.log(state.top.
|
|
55
|
+
* console.log(state.top.reached)
|
|
48
56
|
* console.log(state.top.remaining)
|
|
49
|
-
* console.log(state.bottom.
|
|
57
|
+
* console.log(state.bottom.reached)
|
|
50
58
|
* console.log(state.bottom.remaining)
|
|
51
59
|
* })
|
|
52
60
|
*
|
|
@@ -71,7 +79,7 @@ export interface ScrollStateOptions {
|
|
|
71
79
|
*
|
|
72
80
|
* return (
|
|
73
81
|
* <div ref={ref}>
|
|
74
|
-
* {state.top.
|
|
82
|
+
* {state.top.reached ? 'at the top' : 'scrolled'}
|
|
75
83
|
* </div>
|
|
76
84
|
* )
|
|
77
85
|
* }
|
|
@@ -94,7 +102,7 @@ export interface ScrollStateOptions {
|
|
|
94
102
|
*
|
|
95
103
|
* return (
|
|
96
104
|
* <div ref={setRef}>
|
|
97
|
-
* {state.top.
|
|
105
|
+
* {state.top.reached ? 'at the top' : 'scrolled'}
|
|
98
106
|
* </div>
|
|
99
107
|
* )
|
|
100
108
|
* }
|
package/dist/web.js
CHANGED
|
@@ -110,13 +110,23 @@ function s(e) {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
var c = {
|
|
113
|
-
|
|
113
|
+
reached: !1,
|
|
114
114
|
remaining: 0
|
|
115
115
|
};
|
|
116
116
|
function l(e) {
|
|
117
|
-
let { direction: t = "both", threshold: r = 0 } = e, { subscribe: i, notify: a } = n(), o =
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
let { direction: t = "both", threshold: r = 0 } = e, { subscribe: i, notify: a } = n(), o = typeof r == "number" ? {
|
|
118
|
+
top: r,
|
|
119
|
+
bottom: r,
|
|
120
|
+
left: r,
|
|
121
|
+
right: r
|
|
122
|
+
} : {
|
|
123
|
+
top: r.top ?? 0,
|
|
124
|
+
bottom: r.bottom ?? 0,
|
|
125
|
+
left: r.left ?? 0,
|
|
126
|
+
right: r.right ?? 0
|
|
127
|
+
}, s = () => typeof e.element == "function" ? e.element() : e.element, l = () => {
|
|
128
|
+
let e = s(), n = (e, t) => ({
|
|
129
|
+
reached: e,
|
|
120
130
|
remaining: Math.max(0, t)
|
|
121
131
|
});
|
|
122
132
|
if (!e) return {
|
|
@@ -125,20 +135,20 @@ function l(e) {
|
|
|
125
135
|
left: c,
|
|
126
136
|
right: c
|
|
127
137
|
};
|
|
128
|
-
let
|
|
138
|
+
let r = e.scrollTop, i = e.scrollHeight - e.scrollTop - e.clientHeight, a = e.scrollLeft, l = e.scrollWidth - e.scrollLeft - e.clientWidth;
|
|
129
139
|
return {
|
|
130
|
-
top: t === "horizontal" ? c : n(
|
|
131
|
-
bottom: t === "horizontal" ? c : n(
|
|
132
|
-
left: t === "vertical" ? c : n(
|
|
133
|
-
right: t === "vertical" ? c : n(l <=
|
|
140
|
+
top: t === "horizontal" ? c : n(r <= o.top, r),
|
|
141
|
+
bottom: t === "horizontal" ? c : n(i <= o.bottom, i),
|
|
142
|
+
left: t === "vertical" ? c : n(a <= o.left, a),
|
|
143
|
+
right: t === "vertical" ? c : n(l <= o.right, l)
|
|
134
144
|
};
|
|
135
145
|
};
|
|
136
146
|
return {
|
|
137
|
-
get:
|
|
147
|
+
get: l,
|
|
138
148
|
subscribe: (e) => {
|
|
139
|
-
let t =
|
|
140
|
-
if (!t) return e(
|
|
141
|
-
let n = i(() => e(
|
|
149
|
+
let t = s();
|
|
150
|
+
if (!t) return e(l()), () => {};
|
|
151
|
+
let n = i(() => e(l())), r = () => e(l());
|
|
142
152
|
return t.addEventListener("scroll", r, { passive: !0 }), () => {
|
|
143
153
|
n(), t.removeEventListener("scroll", r);
|
|
144
154
|
};
|