scroll-snap-kit 1.1.0 → 2.0.0

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,34 +1,45 @@
1
1
  {
2
2
  "name": "scroll-snap-kit",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "Smooth scroll utilities and React hooks for modern web apps",
5
5
  "type": "module",
6
- "main": "./src/index.js",
7
- "module": "./src/index.js",
6
+ "main": "./dist/index.cjs.js",
7
+ "module": "./dist/index.esm.js",
8
+ "types": "./dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "import": "./src/index.js"
11
+ "import": "./dist/index.esm.js",
12
+ "require": "./dist/index.cjs.js",
13
+ "types": "./dist/index.d.ts"
11
14
  },
12
15
  "./utils": {
13
- "import": "./src/utils.js"
16
+ "import": "./src/utils.js",
17
+ "require": "./dist/index.cjs.js",
18
+ "types": "./dist/index.d.ts"
14
19
  },
15
20
  "./hooks": {
16
- "import": "./src/hooks.js"
21
+ "import": "./src/hooks.js",
22
+ "types": "./dist/index.d.ts"
17
23
  }
18
24
  },
19
25
  "files": [
20
- "src"
26
+ "src",
27
+ "dist"
21
28
  ],
22
29
  "scripts": {
23
- "test": "echo \"No tests yet\""
30
+ "build": "node build.js",
31
+ "prepublishOnly": "node build.js"
24
32
  },
25
33
  "keywords": [
26
34
  "scroll",
27
35
  "smooth-scroll",
28
- "scroll-hooks",
36
+ "parallax",
37
+ "scroll-spy",
38
+ "scroll-reveal",
39
+ "infinite-scroll",
29
40
  "react-hooks",
30
41
  "viewport",
31
- "scroll-position",
42
+ "scroll-animation",
32
43
  "frontend",
33
44
  "ui"
34
45
  ],
package/src/index.d.ts ADDED
@@ -0,0 +1,281 @@
1
+ // scroll-snap-kit — TypeScript declarations
2
+ // v2.0.0
3
+
4
+ // ─────────────────────────────────────────────
5
+ // Shared types
6
+ // ─────────────────────────────────────────────
7
+
8
+ export type ScrollBehaviorOption = 'smooth' | 'instant' | 'auto';
9
+ export type ScrollAxis = 'x' | 'y' | 'both';
10
+ export type RevealEffect =
11
+ | 'fade'
12
+ | 'slide-up'
13
+ | 'slide-down'
14
+ | 'slide-left'
15
+ | 'slide-right'
16
+ | 'scale'
17
+ | 'fade-scale';
18
+
19
+ export interface ScrollPosition {
20
+ x: number;
21
+ y: number;
22
+ percentX: number;
23
+ percentY: number;
24
+ }
25
+
26
+ export type CleanupFn = () => void;
27
+
28
+ // ─────────────────────────────────────────────
29
+ // Core utilities (v1.0)
30
+ // ─────────────────────────────────────────────
31
+
32
+ export interface ScrollToOptions {
33
+ behavior?: ScrollBehaviorOption;
34
+ block?: ScrollLogicalPosition;
35
+ offset?: number;
36
+ }
37
+
38
+ /** Smoothly scroll to a DOM element or a Y pixel value. */
39
+ export function scrollTo(target: Element | number, options?: ScrollToOptions): void;
40
+
41
+ /** Scroll to the top of the page. */
42
+ export function scrollToTop(options?: Pick<ScrollToOptions, 'behavior'>): void;
43
+
44
+ /** Scroll to the bottom of the page. */
45
+ export function scrollToBottom(options?: Pick<ScrollToOptions, 'behavior'>): void;
46
+
47
+ /** Returns current scroll position and percentage for the page or a container. */
48
+ export function getScrollPosition(container?: Element): ScrollPosition;
49
+
50
+ export interface OnScrollOptions {
51
+ throttle?: number;
52
+ container?: Element;
53
+ }
54
+
55
+ /** Throttled scroll listener. Returns a cleanup function. */
56
+ export function onScroll(
57
+ callback: (position: ScrollPosition) => void,
58
+ options?: OnScrollOptions
59
+ ): CleanupFn;
60
+
61
+ export interface InViewportOptions {
62
+ threshold?: number;
63
+ }
64
+
65
+ /** Check whether an element is currently visible in the viewport. */
66
+ export function isInViewport(element: Element, options?: InViewportOptions): boolean;
67
+
68
+ /** Lock the page scroll (e.g. when a modal is open). */
69
+ export function lockScroll(): void;
70
+
71
+ /** Unlock the page scroll and restore the saved position. */
72
+ export function unlockScroll(): void;
73
+
74
+ // ─────────────────────────────────────────────
75
+ // v1.1 utilities
76
+ // ─────────────────────────────────────────────
77
+
78
+ export interface ScrollSpyOptions {
79
+ offset?: number;
80
+ activeClass?: string;
81
+ }
82
+
83
+ /** Watch scroll and highlight nav links matching the current section. */
84
+ export function scrollSpy(
85
+ sectionsSelector: string,
86
+ linksSelector: string,
87
+ options?: ScrollSpyOptions
88
+ ): CleanupFn;
89
+
90
+ export interface OnScrollEndOptions {
91
+ delay?: number;
92
+ container?: Element;
93
+ }
94
+
95
+ /** Fire a callback once the user has stopped scrolling. */
96
+ export function onScrollEnd(
97
+ callback: (position: ScrollPosition) => void,
98
+ options?: OnScrollEndOptions
99
+ ): CleanupFn;
100
+
101
+ export interface ScrollIfNeededOptions {
102
+ threshold?: number;
103
+ offset?: number;
104
+ behavior?: ScrollBehaviorOption;
105
+ }
106
+
107
+ /** Scroll to an element only if it is outside the viewport. */
108
+ export function scrollIntoViewIfNeeded(element: Element, options?: ScrollIfNeededOptions): void;
109
+
110
+ // Easings
111
+ export type EasingFn = (t: number) => number;
112
+
113
+ export interface EasingsMap {
114
+ linear: EasingFn;
115
+ easeInQuad: EasingFn;
116
+ easeOutQuad: EasingFn;
117
+ easeInOutQuad: EasingFn;
118
+ easeInCubic: EasingFn;
119
+ easeOutCubic: EasingFn;
120
+ easeInOutCubic: EasingFn;
121
+ easeInQuart: EasingFn;
122
+ easeOutQuart: EasingFn;
123
+ easeOutElastic: EasingFn;
124
+ easeOutBounce: EasingFn;
125
+ }
126
+
127
+ /** Built-in easing functions for use with easeScroll. */
128
+ export declare const Easings: EasingsMap;
129
+
130
+ export interface EaseScrollOptions {
131
+ duration?: number;
132
+ easing?: EasingFn;
133
+ offset?: number;
134
+ }
135
+
136
+ /** Scroll with a custom easing curve. Returns a Promise that resolves on completion. */
137
+ export function easeScroll(
138
+ target: Element | string | number,
139
+ options?: EaseScrollOptions
140
+ ): Promise<void>;
141
+
142
+ // ─────────────────────────────────────────────
143
+ // v1.2 utilities
144
+ // ─────────────────────────────────────────────
145
+
146
+ export interface SequenceStep extends EaseScrollOptions {
147
+ target: Element | string | number;
148
+ pause?: number;
149
+ }
150
+
151
+ export interface ScrollSequenceResult {
152
+ promise: Promise<void>;
153
+ cancel: () => void;
154
+ }
155
+
156
+ /** Chain multiple easeScroll animations sequentially. */
157
+ export function scrollSequence(steps: SequenceStep[]): ScrollSequenceResult;
158
+
159
+ export interface ParallaxOptions {
160
+ speed?: number;
161
+ axis?: ScrollAxis;
162
+ container?: Element;
163
+ }
164
+
165
+ /** Attach a parallax scroll speed to one or more elements. */
166
+ export function parallax(
167
+ targets: string | Element | NodeList | Element[],
168
+ options?: ParallaxOptions
169
+ ): CleanupFn;
170
+
171
+ export interface ScrollProgressOptions {
172
+ offset?: number;
173
+ }
174
+
175
+ /** Track how far (0–1) the user has scrolled through a specific element. */
176
+ export function scrollProgress(
177
+ element: Element | string,
178
+ callback: (progress: number) => void,
179
+ options?: ScrollProgressOptions
180
+ ): CleanupFn;
181
+
182
+ export interface SnapToSectionOptions extends EaseScrollOptions {
183
+ delay?: number;
184
+ }
185
+
186
+ /** Auto-snap to the nearest section after scrolling stops. */
187
+ export function snapToSection(
188
+ sections: string | Element[],
189
+ options?: SnapToSectionOptions
190
+ ): CleanupFn;
191
+
192
+ // ─────────────────────────────────────────────
193
+ // v2.0 utilities
194
+ // ─────────────────────────────────────────────
195
+
196
+ export interface ScrollRevealOptions {
197
+ effect?: RevealEffect;
198
+ duration?: number;
199
+ delay?: number;
200
+ easing?: string;
201
+ threshold?: number;
202
+ once?: boolean;
203
+ distance?: string;
204
+ }
205
+
206
+ /** Animate elements in as they scroll into view. */
207
+ export function scrollReveal(
208
+ targets: string | Element | Element[],
209
+ options?: ScrollRevealOptions
210
+ ): CleanupFn;
211
+
212
+ export interface TimelineTrack {
213
+ property: string;
214
+ from: number;
215
+ to: number;
216
+ unit?: string;
217
+ scrollStart?: number;
218
+ scrollEnd?: number;
219
+ target?: Element | string;
220
+ }
221
+
222
+ /** Drive CSS custom properties from scroll position. */
223
+ export function scrollTimeline(tracks: TimelineTrack[]): CleanupFn;
224
+
225
+ export interface InfiniteScrollOptions {
226
+ threshold?: number;
227
+ cooldown?: number;
228
+ container?: Element;
229
+ }
230
+
231
+ /** Fire a callback when the user scrolls near the bottom. */
232
+ export function infiniteScroll(
233
+ callback: () => void | Promise<void>,
234
+ options?: InfiniteScrollOptions
235
+ ): CleanupFn;
236
+
237
+ export interface ScrollTrapOptions {
238
+ allowKeys?: boolean;
239
+ }
240
+
241
+ /** Contain scroll within an element, preventing background page scroll. */
242
+ export function scrollTrap(
243
+ element: Element | string,
244
+ options?: ScrollTrapOptions
245
+ ): CleanupFn;
246
+
247
+ // ─────────────────────────────────────────────
248
+ // React Hooks
249
+ // ─────────────────────────────────────────────
250
+
251
+ import { RefObject } from 'react';
252
+
253
+ export interface UseScrollPositionOptions {
254
+ throttle?: number;
255
+ container?: Element;
256
+ }
257
+
258
+ /** Returns live scroll position and percentage, updated on scroll. */
259
+ export function useScrollPosition(options?: UseScrollPositionOptions): ScrollPosition;
260
+
261
+ export interface UseInViewportOptions {
262
+ threshold?: number;
263
+ once?: boolean;
264
+ }
265
+
266
+ /** Returns [ref, inView] — tracks viewport visibility via IntersectionObserver. */
267
+ export function useInViewport<T extends Element = Element>(
268
+ options?: UseInViewportOptions
269
+ ): [RefObject<T>, boolean];
270
+
271
+ /** Returns [containerRef, scrollToFn] — scoped smooth scroll for a container. */
272
+ export function useScrollTo<T extends Element = Element>(): [
273
+ RefObject<T>,
274
+ (target: Element | number, options?: ScrollToOptions) => void
275
+ ];
276
+
277
+ /** Returns true once the user has scrolled past the given Y threshold. */
278
+ export function useScrolledPast(threshold?: number, options?: { container?: Element }): boolean;
279
+
280
+ /** Returns current scroll direction: 'up' | 'down' | null. */
281
+ export function useScrollDirection(options?: { throttle?: number }): 'up' | 'down' | null;
package/src/index.js CHANGED
@@ -17,6 +17,11 @@ export {
17
17
  scrollIntoViewIfNeeded,
18
18
  easeScroll,
19
19
  Easings,
20
+ // v1.2
21
+ scrollSequence,
22
+ parallax,
23
+ scrollProgress,
24
+ snapToSection,
20
25
  } from './utils.js';
21
26
 
22
27
  export {