@cosmictraveler002/anim-kit 1.4.0 → 1.5.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/README.md +20 -11
- package/dist/anim-kit.standalone.js +1 -1
- package/dist/anim-kit.standalone.js.map +1 -1
- package/dist/core/smooth-scroll.d.ts +29 -1
- package/dist/core/smooth-scroll.d.ts.map +1 -1
- package/dist/core/smooth-scroll.js +23 -3
- package/dist/core/smooth-scroll.js.map +1 -1
- package/package.json +1 -1
- package/src/core/smooth-scroll.ts +44 -2
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
* Uses the canonical Lenis + GSAP recipe:
|
|
5
5
|
* lenis.on("scroll", ScrollTrigger.update)
|
|
6
6
|
* gsap.ticker.add(t => lenis.raf(t * 1000))
|
|
7
|
-
* gsap.ticker.lagSmoothing(0)
|
|
8
7
|
*
|
|
9
8
|
* Driving Lenis from GSAP's ticker (rather than its own rAF) keeps both
|
|
10
9
|
* clocks on the same frame, which is what stops ScrollTrigger from stuttering.
|
|
10
|
+
* Those ticker callbacks receive the *same* adjusted clock the tweens run on,
|
|
11
|
+
* so GSAP's lag smoothing is deliberately left on: a stalled frame (GC pause,
|
|
12
|
+
* buffer tick) advances one short step everywhere instead of snapping the
|
|
13
|
+
* scroll and every scroll-linked tween to a new time at once. See
|
|
14
|
+
* SmoothScrollOptions.lagSmoothing to retune it or restore the old opt-out.
|
|
11
15
|
*
|
|
12
16
|
* `useScrollerProxy: true` additionally proxies `document.documentElement`,
|
|
13
17
|
* matching kalakritico.in's setup — only needed if you scroll a nested
|
|
@@ -28,6 +32,30 @@ export interface SmoothScrollOptions extends CommonOptions {
|
|
|
28
32
|
initialScroll?: number;
|
|
29
33
|
/** Proxy documentElement through ScrollTrigger (nested scrollers). @default false */
|
|
30
34
|
useScrollerProxy?: boolean;
|
|
35
|
+
/** Touch-drag sensitivity — forwarded to Lenis `touchMultiplier`. @default 1 */
|
|
36
|
+
touchMultiplier?: number;
|
|
37
|
+
/** Mouse-wheel sensitivity — forwarded to Lenis `wheelMultiplier`. @default 1 */
|
|
38
|
+
wheelMultiplier?: number;
|
|
39
|
+
/**
|
|
40
|
+
* GSAP lag smoothing on the shared ticker: a frame longer than `threshold`
|
|
41
|
+
* advances only `adjustedLag` ms, so a hitch can't teleport the scroll and
|
|
42
|
+
* every scroll-linked tween in one jump.
|
|
43
|
+
*
|
|
44
|
+
* - `undefined` — leave GSAP's setup alone; its built-in compensation
|
|
45
|
+
* (500ms → 33ms) stays active.
|
|
46
|
+
* - `false` — disable lag smoothing (anim-kit ≤1.4 behaviour, what the
|
|
47
|
+
* Lenis README recipe asks for): timing stays exactly wall-clock, but
|
|
48
|
+
* every frame longer than the threshold snaps.
|
|
49
|
+
* - `{ threshold, adjustedLag }` — retune it. Lower the threshold (e.g.
|
|
50
|
+
* `150`) to smooth short mobile hitches; raise it if slow devices should
|
|
51
|
+
* keep real-time speed instead of briefly running slow-motion.
|
|
52
|
+
*
|
|
53
|
+
* `destroy()` restores GSAP's default (500/33) whenever this was set.
|
|
54
|
+
*/
|
|
55
|
+
lagSmoothing?: false | {
|
|
56
|
+
threshold?: number;
|
|
57
|
+
adjustedLag?: number;
|
|
58
|
+
};
|
|
31
59
|
}
|
|
32
60
|
export interface SmoothScrollHandle {
|
|
33
61
|
/** The Lenis instance, or null when smooth scrolling was skipped. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smooth-scroll.d.ts","sourceRoot":"","sources":["../../src/core/smooth-scroll.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"smooth-scroll.d.ts","sourceRoot":"","sources":["../../src/core/smooth-scroll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,WAAW,mBAAoB,SAAQ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
|
* Driving Lenis from GSAP's ticker (rather than its own rAF) keeps both
|
|
10
9
|
* clocks on the same frame, which is what stops ScrollTrigger from stuttering.
|
|
10
|
+
* Those ticker callbacks receive the *same* adjusted clock the tweens run on,
|
|
11
|
+
* so GSAP's lag smoothing is deliberately left on: a stalled frame (GC pause,
|
|
12
|
+
* buffer tick) advances one short step everywhere instead of snapping the
|
|
13
|
+
* scroll and every scroll-linked tween to a new time at once. See
|
|
14
|
+
* SmoothScrollOptions.lagSmoothing to retune it or restore the old opt-out.
|
|
11
15
|
*
|
|
12
16
|
* `useScrollerProxy: true` additionally proxies `document.documentElement`,
|
|
13
17
|
* matching kalakritico.in's setup — only needed if you scroll a nested
|
|
@@ -24,7 +28,7 @@ const INERT = {
|
|
|
24
28
|
};
|
|
25
29
|
export function smoothScroll(options = {}) {
|
|
26
30
|
initGSAP();
|
|
27
|
-
const { force = false, lerp = 0.08, smoothWheel = true, smoothTouch = false, orientation = "vertical", initialScroll = 0, useScrollerProxy = false, } = options;
|
|
31
|
+
const { force = false, lerp = 0.08, smoothWheel = true, smoothTouch = false, orientation = "vertical", initialScroll = 0, useScrollerProxy = false, touchMultiplier, wheelMultiplier, lagSmoothing, } = options;
|
|
28
32
|
if (typeof window === "undefined")
|
|
29
33
|
return INERT;
|
|
30
34
|
// Honour the OS-level preference: fall back to native scrolling.
|
|
@@ -36,6 +40,9 @@ export function smoothScroll(options = {}) {
|
|
|
36
40
|
syncTouch: smoothTouch,
|
|
37
41
|
orientation,
|
|
38
42
|
autoRaf: false,
|
|
43
|
+
// undefined falls through to Lenis's own defaults (1 / 1).
|
|
44
|
+
touchMultiplier,
|
|
45
|
+
wheelMultiplier,
|
|
39
46
|
});
|
|
40
47
|
if (initialScroll)
|
|
41
48
|
lenis.scrollTo(initialScroll, { immediate: true });
|
|
@@ -45,7 +52,18 @@ export function smoothScroll(options = {}) {
|
|
|
45
52
|
// 2. Run Lenis off GSAP's ticker so both share one frame clock.
|
|
46
53
|
const tick = (time) => lenis.raf(time * 1000);
|
|
47
54
|
gsap.ticker.add(tick);
|
|
48
|
-
|
|
55
|
+
// Lag smoothing drives *one* clock — the tweens' and this ticker's alike —
|
|
56
|
+
// so leaving GSAP's compensation on turns a stalled frame into one short
|
|
57
|
+
// step everywhere instead of a snap. Only touch the ticker when asked, so a
|
|
58
|
+
// host page's own setup is never clobbered.
|
|
59
|
+
let lagTouched = false;
|
|
60
|
+
if (lagSmoothing !== undefined) {
|
|
61
|
+
lagTouched = true;
|
|
62
|
+
if (lagSmoothing === false)
|
|
63
|
+
gsap.ticker.lagSmoothing(0);
|
|
64
|
+
else
|
|
65
|
+
gsap.ticker.lagSmoothing(lagSmoothing.threshold ?? 500, lagSmoothing.adjustedLag ?? 33);
|
|
66
|
+
}
|
|
49
67
|
// 3. Optional: proxy the scroller (for nested/element scrollers).
|
|
50
68
|
if (useScrollerProxy) {
|
|
51
69
|
ScrollTrigger.scrollerProxy(document.documentElement, {
|
|
@@ -81,6 +99,8 @@ export function smoothScroll(options = {}) {
|
|
|
81
99
|
window.removeEventListener("resize", onResize);
|
|
82
100
|
window.removeEventListener("load", refresh);
|
|
83
101
|
gsap.ticker.remove(tick);
|
|
102
|
+
if (lagTouched)
|
|
103
|
+
gsap.ticker.lagSmoothing(500, 33); // undo our change — GSAP's default
|
|
84
104
|
lenis.off("scroll", onScroll);
|
|
85
105
|
if (useScrollerProxy) {
|
|
86
106
|
ScrollTrigger.scrollerProxy(document.documentElement, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smooth-scroll.js","sourceRoot":"","sources":["../../src/core/smooth-scroll.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"smooth-scroll.js","sourceRoot":"","sources":["../../src/core/smooth-scroll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,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6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmictraveler002/anim-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Modular, framework-agnostic animation library — GSAP + ScrollTrigger + Lenis effects packaged as composable ES modules.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
* Uses the canonical Lenis + GSAP recipe:
|
|
5
5
|
* lenis.on("scroll", ScrollTrigger.update)
|
|
6
6
|
* gsap.ticker.add(t => lenis.raf(t * 1000))
|
|
7
|
-
* gsap.ticker.lagSmoothing(0)
|
|
8
7
|
*
|
|
9
8
|
* Driving Lenis from GSAP's ticker (rather than its own rAF) keeps both
|
|
10
9
|
* clocks on the same frame, which is what stops ScrollTrigger from stuttering.
|
|
10
|
+
* Those ticker callbacks receive the *same* adjusted clock the tweens run on,
|
|
11
|
+
* so GSAP's lag smoothing is deliberately left on: a stalled frame (GC pause,
|
|
12
|
+
* buffer tick) advances one short step everywhere instead of snapping the
|
|
13
|
+
* scroll and every scroll-linked tween to a new time at once. See
|
|
14
|
+
* SmoothScrollOptions.lagSmoothing to retune it or restore the old opt-out.
|
|
11
15
|
*
|
|
12
16
|
* `useScrollerProxy: true` additionally proxies `document.documentElement`,
|
|
13
17
|
* matching kalakritico.in's setup — only needed if you scroll a nested
|
|
@@ -31,6 +35,27 @@ export interface SmoothScrollOptions extends CommonOptions {
|
|
|
31
35
|
initialScroll?: number;
|
|
32
36
|
/** Proxy documentElement through ScrollTrigger (nested scrollers). @default false */
|
|
33
37
|
useScrollerProxy?: boolean;
|
|
38
|
+
/** Touch-drag sensitivity — forwarded to Lenis `touchMultiplier`. @default 1 */
|
|
39
|
+
touchMultiplier?: number;
|
|
40
|
+
/** Mouse-wheel sensitivity — forwarded to Lenis `wheelMultiplier`. @default 1 */
|
|
41
|
+
wheelMultiplier?: number;
|
|
42
|
+
/**
|
|
43
|
+
* GSAP lag smoothing on the shared ticker: a frame longer than `threshold`
|
|
44
|
+
* advances only `adjustedLag` ms, so a hitch can't teleport the scroll and
|
|
45
|
+
* every scroll-linked tween in one jump.
|
|
46
|
+
*
|
|
47
|
+
* - `undefined` — leave GSAP's setup alone; its built-in compensation
|
|
48
|
+
* (500ms → 33ms) stays active.
|
|
49
|
+
* - `false` — disable lag smoothing (anim-kit ≤1.4 behaviour, what the
|
|
50
|
+
* Lenis README recipe asks for): timing stays exactly wall-clock, but
|
|
51
|
+
* every frame longer than the threshold snaps.
|
|
52
|
+
* - `{ threshold, adjustedLag }` — retune it. Lower the threshold (e.g.
|
|
53
|
+
* `150`) to smooth short mobile hitches; raise it if slow devices should
|
|
54
|
+
* keep real-time speed instead of briefly running slow-motion.
|
|
55
|
+
*
|
|
56
|
+
* `destroy()` restores GSAP's default (500/33) whenever this was set.
|
|
57
|
+
*/
|
|
58
|
+
lagSmoothing?: false | { threshold?: number; adjustedLag?: number };
|
|
34
59
|
}
|
|
35
60
|
|
|
36
61
|
export interface SmoothScrollHandle {
|
|
@@ -61,6 +86,9 @@ export function smoothScroll(options: SmoothScrollOptions = {}): SmoothScrollHan
|
|
|
61
86
|
orientation = "vertical",
|
|
62
87
|
initialScroll = 0,
|
|
63
88
|
useScrollerProxy = false,
|
|
89
|
+
touchMultiplier,
|
|
90
|
+
wheelMultiplier,
|
|
91
|
+
lagSmoothing,
|
|
64
92
|
} = options;
|
|
65
93
|
|
|
66
94
|
if (typeof window === "undefined") return INERT;
|
|
@@ -74,6 +102,9 @@ export function smoothScroll(options: SmoothScrollOptions = {}): SmoothScrollHan
|
|
|
74
102
|
syncTouch: smoothTouch,
|
|
75
103
|
orientation,
|
|
76
104
|
autoRaf: false,
|
|
105
|
+
// undefined falls through to Lenis's own defaults (1 / 1).
|
|
106
|
+
touchMultiplier,
|
|
107
|
+
wheelMultiplier,
|
|
77
108
|
});
|
|
78
109
|
|
|
79
110
|
if (initialScroll) lenis.scrollTo(initialScroll, { immediate: true });
|
|
@@ -85,7 +116,17 @@ export function smoothScroll(options: SmoothScrollOptions = {}): SmoothScrollHan
|
|
|
85
116
|
// 2. Run Lenis off GSAP's ticker so both share one frame clock.
|
|
86
117
|
const tick = (time: number) => lenis.raf(time * 1000);
|
|
87
118
|
gsap.ticker.add(tick);
|
|
88
|
-
|
|
119
|
+
|
|
120
|
+
// Lag smoothing drives *one* clock — the tweens' and this ticker's alike —
|
|
121
|
+
// so leaving GSAP's compensation on turns a stalled frame into one short
|
|
122
|
+
// step everywhere instead of a snap. Only touch the ticker when asked, so a
|
|
123
|
+
// host page's own setup is never clobbered.
|
|
124
|
+
let lagTouched = false;
|
|
125
|
+
if (lagSmoothing !== undefined) {
|
|
126
|
+
lagTouched = true;
|
|
127
|
+
if (lagSmoothing === false) gsap.ticker.lagSmoothing(0);
|
|
128
|
+
else gsap.ticker.lagSmoothing(lagSmoothing.threshold ?? 500, lagSmoothing.adjustedLag ?? 33);
|
|
129
|
+
}
|
|
89
130
|
|
|
90
131
|
// 3. Optional: proxy the scroller (for nested/element scrollers).
|
|
91
132
|
if (useScrollerProxy) {
|
|
@@ -126,6 +167,7 @@ export function smoothScroll(options: SmoothScrollOptions = {}): SmoothScrollHan
|
|
|
126
167
|
window.removeEventListener("resize", onResize);
|
|
127
168
|
window.removeEventListener("load", refresh);
|
|
128
169
|
gsap.ticker.remove(tick);
|
|
170
|
+
if (lagTouched) gsap.ticker.lagSmoothing(500, 33); // undo our change — GSAP's default
|
|
129
171
|
lenis.off("scroll", onScroll);
|
|
130
172
|
if (useScrollerProxy) {
|
|
131
173
|
ScrollTrigger.scrollerProxy(document.documentElement, {} as never);
|