@algorisys/tinyfly 0.64.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/LICENSE +21 -0
- package/README.md +672 -0
- package/bin/tinyfly.mjs +59 -0
- package/lib/addons/adapters.js +756 -0
- package/lib/addons/dom-adapter-ChrbtkLC.js +243 -0
- package/lib/addons/drivers.js +72 -0
- package/lib/addons/export.js +1169 -0
- package/lib/addons/gsap-compat.js +2576 -0
- package/lib/addons/interaction.js +225 -0
- package/lib/addons/smooth-scroll-DaSacemU.js +671 -0
- package/lib/addons/teach.js +215 -0
- package/lib/browser/tinyfly.iife.js +2 -0
- package/lib/browser/tinyfly.js +6372 -0
- package/lib/browser/tinyfly.umd.js +2 -0
- package/lib/cli/tools.js +2325 -0
- package/lib/embed/tinyfly-embed.iife.js +18 -0
- package/lib/embed/tinyfly-embed.js +2316 -0
- package/lib/engine/tinyfly-engine.js +1972 -0
- package/lib/engine/tinyfly-engine.umd.cjs +2 -0
- package/lib/frameworks/react.js +32 -0
- package/lib/frameworks/solid.js +27 -0
- package/lib/frameworks/svelte.js +15 -0
- package/lib/frameworks/vue.js +29 -0
- package/lib/player/tinyfly-player.es.js +2306 -0
- package/lib/player/tinyfly-player.iife.js +2 -0
- package/lib/player/tinyfly-player.umd.js +2 -0
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +238 -0
- package/lib/types/adapters/canvas/index.d.ts +1 -0
- package/lib/types/adapters/dom/dom-adapter.d.ts +50 -0
- package/lib/types/adapters/dom/flip.d.ts +60 -0
- package/lib/types/adapters/dom/index.d.ts +2 -0
- package/lib/types/adapters/filter-utils.d.ts +32 -0
- package/lib/types/adapters/index.d.ts +5 -0
- package/lib/types/adapters/shine-utils.d.ts +26 -0
- package/lib/types/adapters/svg/index.d.ts +1 -0
- package/lib/types/adapters/svg/svg-adapter.d.ts +47 -0
- package/lib/types/adapters/svg-transform-box.d.ts +13 -0
- package/lib/types/adapters/text-content.d.ts +11 -0
- package/lib/types/adapters/webgl/index.d.ts +1 -0
- package/lib/types/adapters/webgl/webgl-adapter.d.ts +69 -0
- package/lib/types/browser/index.d.ts +41 -0
- package/lib/types/compat/gsap/custom-eases.d.ts +28 -0
- package/lib/types/compat/gsap/defaults.d.ts +19 -0
- package/lib/types/compat/gsap/draw-svg-vars.d.ts +36 -0
- package/lib/types/compat/gsap/ease-map.d.ts +51 -0
- package/lib/types/compat/gsap/image-sequence.d.ts +61 -0
- package/lib/types/compat/gsap/index.d.ts +65 -0
- package/lib/types/compat/gsap/inertia-vars.d.ts +39 -0
- package/lib/types/compat/gsap/keyframes-vars.d.ts +8 -0
- package/lib/types/compat/gsap/layout.d.ts +6 -0
- package/lib/types/compat/gsap/live-context.d.ts +87 -0
- package/lib/types/compat/gsap/live-draggable.d.ts +75 -0
- package/lib/types/compat/gsap/live-flip.d.ts +73 -0
- package/lib/types/compat/gsap/live-morph.d.ts +18 -0
- package/lib/types/compat/gsap/live-motion-path.d.ts +33 -0
- package/lib/types/compat/gsap/live-scroll-to.d.ts +52 -0
- package/lib/types/compat/gsap/live-scroll.d.ts +108 -0
- package/lib/types/compat/gsap/live-transition.d.ts +40 -0
- package/lib/types/compat/gsap/live.d.ts +341 -0
- package/lib/types/compat/gsap/morph-vars.d.ts +21 -0
- package/lib/types/compat/gsap/motion-path-vars.d.ts +38 -0
- package/lib/types/compat/gsap/playhead-crossings.d.ts +47 -0
- package/lib/types/compat/gsap/position.d.ts +37 -0
- package/lib/types/compat/gsap/quick-play.d.ts +38 -0
- package/lib/types/compat/gsap/split-text.d.ts +66 -0
- package/lib/types/compat/gsap/spring-vars.d.ts +34 -0
- package/lib/types/compat/gsap/stage.d.ts +182 -0
- package/lib/types/compat/gsap/stagger-grid.d.ts +30 -0
- package/lib/types/compat/gsap/text-vars.d.ts +39 -0
- package/lib/types/compat/gsap/timeline.d.ts +161 -0
- package/lib/types/compat/gsap/utils.d.ts +60 -0
- package/lib/types/compat/gsap/vars.d.ts +79 -0
- package/lib/types/drivers/index.d.ts +8 -0
- package/lib/types/drivers/scroll-driver.d.ts +218 -0
- package/lib/types/drivers/scroll-markers.d.ts +41 -0
- package/lib/types/drivers/scroll-math.d.ts +87 -0
- package/lib/types/drivers/scroll-pin.d.ts +45 -0
- package/lib/types/drivers/scroll-snap.d.ts +47 -0
- package/lib/types/drivers/smooth-scroll.d.ts +118 -0
- package/lib/types/drivers/types.d.ts +23 -0
- package/lib/types/drivers/visibility-driver.d.ts +56 -0
- package/lib/types/embed/controls.d.ts +46 -0
- package/lib/types/embed/index.d.ts +17 -0
- package/lib/types/embed/mount.d.ts +41 -0
- package/lib/types/embed/tools.d.ts +33 -0
- package/lib/types/engine/authoring/custom-ease.d.ts +49 -0
- package/lib/types/engine/authoring/index.d.ts +3 -0
- package/lib/types/engine/authoring/random.d.ts +38 -0
- package/lib/types/engine/authoring/resolve-values.d.ts +57 -0
- package/lib/types/engine/core/bake.d.ts +66 -0
- package/lib/types/engine/core/clock.d.ts +44 -0
- package/lib/types/engine/core/index.d.ts +8 -0
- package/lib/types/engine/core/inertia.d.ts +30 -0
- package/lib/types/engine/core/playhead-crossings.d.ts +47 -0
- package/lib/types/engine/core/spring.d.ts +132 -0
- package/lib/types/engine/core/stagger.d.ts +40 -0
- package/lib/types/engine/core/timeline.d.ts +203 -0
- package/lib/types/engine/core/track.d.ts +90 -0
- package/lib/types/engine/export/byte-writer.d.ts +36 -0
- package/lib/types/engine/export/css.d.ts +31 -0
- package/lib/types/engine/export/gif-decode.test-helper.d.ts +24 -0
- package/lib/types/engine/export/gif.d.ts +134 -0
- package/lib/types/engine/export/index.d.ts +9 -0
- package/lib/types/engine/export/lottie.d.ts +104 -0
- package/lib/types/engine/export/mp4.d.ts +64 -0
- package/lib/types/engine/export/quantize.d.ts +56 -0
- package/lib/types/engine/export/sprite-sheet.d.ts +46 -0
- package/lib/types/engine/export/video.d.ts +99 -0
- package/lib/types/engine/export/webp.d.ts +82 -0
- package/lib/types/engine/index.d.ts +7 -0
- package/lib/types/engine/interpolation/easing.d.ts +65 -0
- package/lib/types/engine/interpolation/index.d.ts +2 -0
- package/lib/types/engine/interpolation/interpolators.d.ts +25 -0
- package/lib/types/engine/path/index.d.ts +11 -0
- package/lib/types/engine/path/motion-path.d.ts +24 -0
- package/lib/types/engine/path/path-builders.d.ts +38 -0
- package/lib/types/engine/path/path-morph.d.ts +47 -0
- package/lib/types/engine/path/path-utils.d.ts +73 -0
- package/lib/types/engine/serialization/index.d.ts +1 -0
- package/lib/types/engine/serialization/json.d.ts +30 -0
- package/lib/types/engine/text/index.d.ts +2 -0
- package/lib/types/engine/text/text-value.d.ts +16 -0
- package/lib/types/engine/types.d.ts +401 -0
- package/lib/types/frameworks/react.d.ts +35 -0
- package/lib/types/frameworks/solid.d.ts +16 -0
- package/lib/types/frameworks/svelte.d.ts +19 -0
- package/lib/types/frameworks/vue.d.ts +27 -0
- package/lib/types/interaction/draggable.d.ts +133 -0
- package/lib/types/interaction/index.d.ts +3 -0
- package/lib/types/interaction/observer.d.ts +80 -0
- package/lib/types/interaction/snap.d.ts +30 -0
- package/lib/types/player/index.d.ts +7 -0
- package/lib/types/player/media-sync.d.ts +60 -0
- package/lib/types/player/player.d.ts +238 -0
- package/lib/types/player/sequence-types.d.ts +68 -0
- package/lib/types/player/sequencer.d.ts +91 -0
- package/lib/types/teach/diagrams.d.ts +137 -0
- package/lib/types/teach/index.d.ts +11 -0
- package/lib/types/teach/lesson.d.ts +55 -0
- package/package.json +170 -0
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
import { easeInOutCubic as M } from "@algorisys/tinyfly";
|
|
2
|
+
const S = {
|
|
3
|
+
top: 0,
|
|
4
|
+
left: 0,
|
|
5
|
+
start: 0,
|
|
6
|
+
center: 0.5,
|
|
7
|
+
centre: 0.5,
|
|
8
|
+
middle: 0.5,
|
|
9
|
+
bottom: 1,
|
|
10
|
+
right: 1,
|
|
11
|
+
end: 1
|
|
12
|
+
};
|
|
13
|
+
function b(r) {
|
|
14
|
+
const t = r.trim().toLowerCase();
|
|
15
|
+
if (t in S) return S[t];
|
|
16
|
+
if (t.endsWith("%")) {
|
|
17
|
+
const e = Number.parseFloat(t.slice(0, -1));
|
|
18
|
+
return Number.isNaN(e) ? void 0 : e / 100;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function k(r) {
|
|
22
|
+
if (typeof r == "number")
|
|
23
|
+
return { elementFraction: 0, viewportFraction: 0, offsetPx: 0, absolutePx: r };
|
|
24
|
+
let t = 0;
|
|
25
|
+
const s = r.replace(/([+-])=\s*(-?[\d.]+)/g, (o, l, a) => (t += (l === "-" ? -1 : 1) * Number.parseFloat(a), "")).trim().split(/\s+/).filter(Boolean);
|
|
26
|
+
if (s.length === 1 && /^-?[\d.]+$/.test(s[0]))
|
|
27
|
+
return {
|
|
28
|
+
elementFraction: 0,
|
|
29
|
+
viewportFraction: 0,
|
|
30
|
+
offsetPx: 0,
|
|
31
|
+
absolutePx: Number.parseFloat(s[0]) + t
|
|
32
|
+
};
|
|
33
|
+
const i = s[0] !== void 0 ? b(s[0]) : void 0, n = s[1] !== void 0 ? b(s[1]) : void 0;
|
|
34
|
+
return {
|
|
35
|
+
elementFraction: i ?? 0,
|
|
36
|
+
viewportFraction: n ?? 0,
|
|
37
|
+
offsetPx: t
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function y(r, t, e) {
|
|
41
|
+
const s = k(e), i = s.absolutePx !== void 0 ? r.top + s.absolutePx : r.top + r.height * s.elementFraction, n = t * s.viewportFraction;
|
|
42
|
+
return i - n + s.offsetPx;
|
|
43
|
+
}
|
|
44
|
+
function _(r, t, e, s) {
|
|
45
|
+
const i = y(r, t, e), o = y(r, t, s) - i;
|
|
46
|
+
return o <= 0 ? i <= 0 ? 1 : 0 : R(-i / o);
|
|
47
|
+
}
|
|
48
|
+
function R(r) {
|
|
49
|
+
return r < 0 ? 0 : r > 1 ? 1 : r === 0 ? 0 : r;
|
|
50
|
+
}
|
|
51
|
+
function z(r, t, e, s) {
|
|
52
|
+
if (e <= 0) return t;
|
|
53
|
+
const i = 1 - Math.exp(-(s / 1e3) / e);
|
|
54
|
+
return r + (t - r) * i;
|
|
55
|
+
}
|
|
56
|
+
function T(r, t, e, s, i) {
|
|
57
|
+
const n = (c) => y({ top: r + i(c), bottom: r + i(c) + t, height: t }, e, s), o = n(0), l = n(1);
|
|
58
|
+
if (Math.sign(o) === Math.sign(l) || o === 0 || l === 0)
|
|
59
|
+
return o === 0 ? 0 : l === 0 ? 1 : Math.abs(o) < Math.abs(l) ? 0 : 1;
|
|
60
|
+
let a = 0, h = 1;
|
|
61
|
+
for (let c = 0; c < 40; c++) {
|
|
62
|
+
const f = (a + h) / 2;
|
|
63
|
+
Math.sign(n(f)) === Math.sign(o) ? a = f : h = f;
|
|
64
|
+
}
|
|
65
|
+
return (a + h) / 2;
|
|
66
|
+
}
|
|
67
|
+
class A {
|
|
68
|
+
element;
|
|
69
|
+
spacer;
|
|
70
|
+
saved;
|
|
71
|
+
axis;
|
|
72
|
+
spacing;
|
|
73
|
+
constructor(t, e = {}) {
|
|
74
|
+
this.element = t, this.axis = e.axis ?? "y", this.spacing = e.spacing ?? !0;
|
|
75
|
+
const s = t.ownerDocument;
|
|
76
|
+
this.spacer = s.createElement("div"), this.spacer.className = "pin-spacer", this.saved = { position: t.style.position, top: t.style.top, left: t.style.left }, this.axis === "x" && (this.spacer.style.flexShrink = "0"), t.replaceWith(this.spacer), this.spacer.appendChild(t);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Put the element back in the flow for measuring: unstuck, at the top of its
|
|
80
|
+
* spacer, which is where it sits without pinning. The spacer keeps its height,
|
|
81
|
+
* so the page does not change length and the scroll position is not clamped.
|
|
82
|
+
*/
|
|
83
|
+
release() {
|
|
84
|
+
this.element.style.position = this.saved.position, this.element.style.top = this.saved.top, this.element.style.left = this.saved.left;
|
|
85
|
+
}
|
|
86
|
+
/** Stick at `topPx` from the scroller's top for `distancePx` of scrolling. */
|
|
87
|
+
apply(t, e) {
|
|
88
|
+
const s = Math.max(0, e);
|
|
89
|
+
this.element.style.position = "sticky", this.axis === "x" ? (this.spacer.style.width = `${this.element.offsetWidth + s}px`, this.spacer.style.marginRight = this.spacing ? "" : `-${s}px`, this.element.style.left = `${t}px`) : (this.spacer.style.height = `${this.element.offsetHeight + s}px`, this.spacer.style.marginBottom = this.spacing ? "" : `-${s}px`, this.element.style.top = `${t}px`);
|
|
90
|
+
}
|
|
91
|
+
/** Remove the spacer and restore the element's own styles. */
|
|
92
|
+
destroy() {
|
|
93
|
+
this.element.style.position = this.saved.position, this.element.style.top = this.saved.top, this.element.style.left = this.saved.left, this.spacer.parentNode && this.spacer.replaceWith(this.element);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const $ = 0.15;
|
|
97
|
+
function N(r) {
|
|
98
|
+
return typeof r == "object" && !Array.isArray(r) ? r : { snapTo: r };
|
|
99
|
+
}
|
|
100
|
+
function q(r, t, e) {
|
|
101
|
+
const s = w(r + t * $);
|
|
102
|
+
if (typeof e == "function") return w(e(s));
|
|
103
|
+
if (typeof e == "number")
|
|
104
|
+
return e <= 0 ? r : w(Math.round(s / e) * e);
|
|
105
|
+
if (e.length === 0) return r;
|
|
106
|
+
let i = e[0];
|
|
107
|
+
for (const n of e)
|
|
108
|
+
Math.abs(n - s) < Math.abs(i - s) && (i = n);
|
|
109
|
+
return w(i);
|
|
110
|
+
}
|
|
111
|
+
function B(r, t, e) {
|
|
112
|
+
const s = r.duration ?? { min: 0.2, max: 0.8 };
|
|
113
|
+
if (typeof s == "number") return s;
|
|
114
|
+
const i = Math.min(1, Math.abs(t) / Math.max(1, e));
|
|
115
|
+
return s.min + (s.max - s.min) * i;
|
|
116
|
+
}
|
|
117
|
+
class H {
|
|
118
|
+
rafId = null;
|
|
119
|
+
cancelEvents = ["wheel", "touchstart", "pointerdown", "keydown"];
|
|
120
|
+
onInterrupt = () => this.cancel();
|
|
121
|
+
write;
|
|
122
|
+
eventTarget;
|
|
123
|
+
constructor(t, e) {
|
|
124
|
+
this.write = t, this.eventTarget = e;
|
|
125
|
+
}
|
|
126
|
+
get active() {
|
|
127
|
+
return this.rafId !== null;
|
|
128
|
+
}
|
|
129
|
+
animate(t, e, s, i = M, n) {
|
|
130
|
+
if (this.cancel(), typeof requestAnimationFrame > "u" || s <= 0) {
|
|
131
|
+
this.write(e), n?.();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
for (const a of this.cancelEvents) this.eventTarget?.addEventListener(a, this.onInterrupt, { passive: !0 });
|
|
135
|
+
let o = null;
|
|
136
|
+
const l = (a) => {
|
|
137
|
+
o ??= a;
|
|
138
|
+
const h = Math.min(1, (a - o) / (s * 1e3));
|
|
139
|
+
this.write(t + (e - t) * i(h)), h < 1 ? this.rafId = requestAnimationFrame(l) : (this.rafId = null, this.detach(), n?.());
|
|
140
|
+
};
|
|
141
|
+
this.rafId = requestAnimationFrame(l);
|
|
142
|
+
}
|
|
143
|
+
cancel() {
|
|
144
|
+
this.rafId !== null && typeof cancelAnimationFrame < "u" && cancelAnimationFrame(this.rafId), this.rafId = null, this.detach();
|
|
145
|
+
}
|
|
146
|
+
detach() {
|
|
147
|
+
for (const t of this.cancelEvents) this.eventTarget?.removeEventListener(t, this.onInterrupt);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function w(r) {
|
|
151
|
+
return Math.max(0, Math.min(1, r));
|
|
152
|
+
}
|
|
153
|
+
class j {
|
|
154
|
+
options;
|
|
155
|
+
scroller;
|
|
156
|
+
nodes = [];
|
|
157
|
+
scrollerStart;
|
|
158
|
+
scrollerEnd;
|
|
159
|
+
start;
|
|
160
|
+
end;
|
|
161
|
+
constructor(t, e, s) {
|
|
162
|
+
this.options = s === !0 ? {} : s, this.scroller = e;
|
|
163
|
+
const { startColor: i = "#3ecf7a", endColor: n = "#ff5a5a", id: o } = this.options, l = o ? `${o} ` : "", a = (h, c, f) => {
|
|
164
|
+
const u = t.createElement("div");
|
|
165
|
+
return u.textContent = `${l}${h}`, u.setAttribute("aria-hidden", "true"), u.className = "scroll-marker", Object.assign(u.style, {
|
|
166
|
+
position: f ? "fixed" : "absolute",
|
|
167
|
+
right: `${this.options.indent ?? 0}px`,
|
|
168
|
+
zIndex: "2147483646",
|
|
169
|
+
pointerEvents: "none",
|
|
170
|
+
borderTop: `1px solid ${c}`,
|
|
171
|
+
color: c,
|
|
172
|
+
font: `${this.options.fontSize ?? "11px"} ui-monospace, monospace`,
|
|
173
|
+
padding: "2px 6px",
|
|
174
|
+
whiteSpace: "nowrap",
|
|
175
|
+
background: "rgba(0, 0, 0, 0.35)"
|
|
176
|
+
}), (e ?? t.body).appendChild(u), this.nodes.push(u), u;
|
|
177
|
+
};
|
|
178
|
+
this.scrollerStart = a("scroller-start", i, !e), this.scrollerEnd = a("scroller-end", n, !e), this.start = a("start", i, !1), this.end = a("end", n, !1), e && getComputedStyle(e).position === "static" && (e.style.position = "relative");
|
|
179
|
+
}
|
|
180
|
+
/** Place the markers for the latest measurement. */
|
|
181
|
+
place(t, e) {
|
|
182
|
+
this.start.style.top = `${t.startPage}px`, this.end.style.top = `${t.endPage}px`;
|
|
183
|
+
const s = this.scroller ? e : 0;
|
|
184
|
+
this.scrollerStart.style.top = `${s + t.startViewport}px`, this.scrollerEnd.style.top = `${s + t.endViewport}px`;
|
|
185
|
+
}
|
|
186
|
+
/** Keep the viewport lines in place inside a scrolling element. */
|
|
187
|
+
follow(t, e) {
|
|
188
|
+
this.scroller && this.place(t, e);
|
|
189
|
+
}
|
|
190
|
+
destroy() {
|
|
191
|
+
for (const t of this.nodes.splice(0)) t.remove();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const O = 120, d = [], m = /* @__PURE__ */ new Set();
|
|
195
|
+
let v = !1;
|
|
196
|
+
const W = () => {
|
|
197
|
+
v || m.size === 0 || (v = !0, queueMicrotask(() => {
|
|
198
|
+
v = !1;
|
|
199
|
+
for (const r of m) r.afterRefresh();
|
|
200
|
+
}));
|
|
201
|
+
}, I = () => {
|
|
202
|
+
for (const r of m) r.beforeRefresh();
|
|
203
|
+
for (const r of d) r.refresh();
|
|
204
|
+
for (const r of m) r.afterRefresh();
|
|
205
|
+
};
|
|
206
|
+
let p = { width: 0, height: 0 };
|
|
207
|
+
const F = () => {
|
|
208
|
+
const r = window.innerWidth, t = window.innerHeight, e = r === p.width && t !== p.height, s = Math.abs(t - p.height) < p.height * 0.25, i = typeof navigator < "u" && (navigator.maxTouchPoints ?? 0) > 0;
|
|
209
|
+
e && s && i || (p = { width: r, height: t }, I());
|
|
210
|
+
};
|
|
211
|
+
class L {
|
|
212
|
+
timeline;
|
|
213
|
+
options;
|
|
214
|
+
running = !1;
|
|
215
|
+
pin = null;
|
|
216
|
+
/** The range, as absolute scroll offsets. */
|
|
217
|
+
startPx = 0;
|
|
218
|
+
endPx = 0;
|
|
219
|
+
/** Progress the page is actually at */
|
|
220
|
+
targetProgress = 0;
|
|
221
|
+
/** Progress the playhead is showing (differs from target only while smoothing) */
|
|
222
|
+
displayProgress = 0;
|
|
223
|
+
zone = "before";
|
|
224
|
+
/** Until the first measurement, smoothing starts at the page's position rather than easing from 0. */
|
|
225
|
+
measured = !1;
|
|
226
|
+
lastScroll = null;
|
|
227
|
+
lastScrollTime = 0;
|
|
228
|
+
velocityPxPerSecond = 0;
|
|
229
|
+
idleTimer = null;
|
|
230
|
+
lastEmitted = null;
|
|
231
|
+
rafId = null;
|
|
232
|
+
lastFrameTime = null;
|
|
233
|
+
onScroll = () => this.update();
|
|
234
|
+
/** Speed when scrolling last stopped, for choosing a snap point */
|
|
235
|
+
releaseVelocity = 0;
|
|
236
|
+
snapper;
|
|
237
|
+
snapTimer = null;
|
|
238
|
+
markers = null;
|
|
239
|
+
markerGeometry = null;
|
|
240
|
+
constructor(t) {
|
|
241
|
+
this.timeline = t.timeline, this.options = t, this.snapper = new H((e) => this.scrollTo(e), typeof window < "u" ? window : null);
|
|
242
|
+
}
|
|
243
|
+
start() {
|
|
244
|
+
if (this.running) return;
|
|
245
|
+
this.running = !0, this.timeline?.pause();
|
|
246
|
+
const t = this.options.pin === !0 ? this.options.trigger : this.options.pin || null;
|
|
247
|
+
t && !this.options.container && (this.pin = new A(t, { axis: this.options.horizontal ? "x" : "y", spacing: this.options.pinSpacing !== !1 })), this.options.markers && !this.options.horizontal && typeof document < "u" && (this.markers = new j(document, this.options.scroller ?? null, this.options.markers)), this.scrollTarget()?.addEventListener("scroll", this.onScroll, { passive: !0 }), d.length === 0 && typeof window < "u" && (p = { width: window.innerWidth, height: window.innerHeight }, window.addEventListener("resize", F, { passive: !0 })), d.push(this), this.refresh();
|
|
248
|
+
}
|
|
249
|
+
stop() {
|
|
250
|
+
this.running && (this.running = !1, this.scrollTarget()?.removeEventListener("scroll", this.onScroll), d.splice(d.indexOf(this), 1), d.length === 0 && typeof window < "u" && window.removeEventListener("resize", F), this.stopSmoothing(), this.idleTimer !== null && clearTimeout(this.idleTimer), this.idleTimer = null, this.snapTimer !== null && clearTimeout(this.snapTimer), this.snapTimer = null, this.snapper.cancel());
|
|
251
|
+
}
|
|
252
|
+
/** Stop, and remove any pin spacer. */
|
|
253
|
+
destroy() {
|
|
254
|
+
this.stop(), this.pin?.destroy(), this.pin = null, this.markers?.destroy(), this.markers = null;
|
|
255
|
+
}
|
|
256
|
+
/** The range's start and end, as scroll offsets. */
|
|
257
|
+
get startOffset() {
|
|
258
|
+
return this.startPx;
|
|
259
|
+
}
|
|
260
|
+
get endOffset() {
|
|
261
|
+
return this.endPx;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Re-measure every started driver, in the order they started. Call after a
|
|
265
|
+
* layout change a resize would not catch (images or fonts loading).
|
|
266
|
+
*/
|
|
267
|
+
static refreshAll() {
|
|
268
|
+
I();
|
|
269
|
+
}
|
|
270
|
+
/** Be told around every re-measure; returns a function that stops it. */
|
|
271
|
+
static onRefresh(t) {
|
|
272
|
+
return m.add(t), () => m.delete(t);
|
|
273
|
+
}
|
|
274
|
+
/** Current scroll progress, 0..1. */
|
|
275
|
+
get progress() {
|
|
276
|
+
return this.targetProgress;
|
|
277
|
+
}
|
|
278
|
+
/** Scroll speed in pixels per second (0 once scrolling has stopped). */
|
|
279
|
+
get velocity() {
|
|
280
|
+
return this.velocityPxPerSecond;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Measure the page again and update. Resizes do this automatically (for every
|
|
284
|
+
* driver, in the order they started, so a pin above pushes the ones below);
|
|
285
|
+
* call it after changing layout yourself — images or fonts loading, content
|
|
286
|
+
* added above the trigger.
|
|
287
|
+
*/
|
|
288
|
+
refresh() {
|
|
289
|
+
if (!this.running) return;
|
|
290
|
+
this.measured && this.options.onRefresh?.();
|
|
291
|
+
const t = this.scrollPosition();
|
|
292
|
+
this.pin?.release();
|
|
293
|
+
const e = this.triggerRect();
|
|
294
|
+
if (e && this.options.container)
|
|
295
|
+
this.measureInContainer(this.options.container);
|
|
296
|
+
else if (e) {
|
|
297
|
+
const s = this.viewportHeight();
|
|
298
|
+
if (this.startPx = t + y(e, s, g(this.options.start) ?? "top bottom"), this.endPx = this.resolveEnd(e, s, t), this.pin) {
|
|
299
|
+
const i = this.relativeRect(this.pin.element.getBoundingClientRect());
|
|
300
|
+
this.pin.apply(i.top - (this.startPx - t), this.endPx - this.startPx);
|
|
301
|
+
}
|
|
302
|
+
this.markerGeometry = this.markers ? this.markersFor(s) : null;
|
|
303
|
+
}
|
|
304
|
+
this.markers && this.markerGeometry && this.markers.place(this.markerGeometry, t), this.lastScroll = null, this.updateFrom(t, !this.measured), this.measured = !0, W();
|
|
305
|
+
}
|
|
306
|
+
/** Same as `refresh()`. */
|
|
307
|
+
sample() {
|
|
308
|
+
this.refresh();
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Update from the current scroll position, or from `scrollPosition` when a
|
|
312
|
+
* smooth-scrolling library (or anything else) owns the scroll value. Costs no
|
|
313
|
+
* layout reads.
|
|
314
|
+
*/
|
|
315
|
+
update(t) {
|
|
316
|
+
this.running && this.updateFrom(t ?? this.scrollPosition(), !1);
|
|
317
|
+
}
|
|
318
|
+
// --- internals ----------------------------------------------------------
|
|
319
|
+
updateFrom(t, e) {
|
|
320
|
+
this.trackVelocity(t), this.markers && this.markerGeometry && this.markers.follow(this.markerGeometry, t);
|
|
321
|
+
const s = this.endPx - this.startPx, i = this.zone;
|
|
322
|
+
this.targetProgress = s > 0 ? R((t - this.startPx) / s) : t >= this.startPx ? 1 : 0, this.zone = s > 0 ? t <= this.startPx ? "before" : t >= this.endPx ? "after" : "active" : t >= this.startPx ? "after" : "before", this.fireBoundaryCallbacks(i, this.zone), e || this.smoothing() <= 0 ? (this.displayProgress = this.targetProgress, this.applyProgress()) : (this.emitUpdate(), this.startSmoothing());
|
|
323
|
+
}
|
|
324
|
+
/** Seconds of smoothing, or 0 for exact tracking. */
|
|
325
|
+
smoothing() {
|
|
326
|
+
const t = this.options.scrub;
|
|
327
|
+
return typeof t == "number" ? Math.max(0, t) : 0;
|
|
328
|
+
}
|
|
329
|
+
resolveEnd(t, e, s) {
|
|
330
|
+
const i = g(this.options.end) ?? "bottom top", n = typeof i == "string" ? i.trim().match(/^\+=\s*(-?[\d.]+)\s*(%|px)?$/) : null;
|
|
331
|
+
if (n) {
|
|
332
|
+
const o = Number.parseFloat(n[1]);
|
|
333
|
+
return this.startPx + (n[2] === "%" ? e * o / 100 : o);
|
|
334
|
+
}
|
|
335
|
+
return s + y(t, e, i);
|
|
336
|
+
}
|
|
337
|
+
applyProgress() {
|
|
338
|
+
const t = this.timeline?.duration ?? 0;
|
|
339
|
+
this.timeline && t > 0 && this.timeline.seek(this.displayProgress * t), this.emitUpdate();
|
|
340
|
+
}
|
|
341
|
+
emitUpdate() {
|
|
342
|
+
if (!this.options.onUpdate) return;
|
|
343
|
+
const t = [this.displayProgress, this.velocityPxPerSecond];
|
|
344
|
+
this.lastEmitted && this.lastEmitted[0] === t[0] && this.lastEmitted[1] === t[1] || (this.lastEmitted = t, this.options.onUpdate(t[0], t[1]));
|
|
345
|
+
}
|
|
346
|
+
trackVelocity(t) {
|
|
347
|
+
const e = typeof performance < "u" ? performance.now() : Date.now();
|
|
348
|
+
this.lastScroll !== null && e > this.lastScrollTime && t !== this.lastScroll && (this.velocityPxPerSecond = (t - this.lastScroll) / (e - this.lastScrollTime) * 1e3), (this.lastScroll === null || t !== this.lastScroll) && (this.lastScroll = t, this.lastScrollTime = e), !(this.velocityPxPerSecond === 0 || typeof setTimeout > "u") && (this.idleTimer !== null && clearTimeout(this.idleTimer), this.idleTimer = setTimeout(() => {
|
|
349
|
+
this.idleTimer = null, this.releaseVelocity = this.velocityPxPerSecond, this.velocityPxPerSecond = 0, this.emitUpdate(), this.scheduleSnap();
|
|
350
|
+
}, O));
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Emit enter/leave callbacks as the scroll position moves between zones. A jump
|
|
354
|
+
* straight across the range (a fast flick, or loading the page scrolled past
|
|
355
|
+
* it) fires both edges in order.
|
|
356
|
+
*/
|
|
357
|
+
fireBoundaryCallbacks(t, e) {
|
|
358
|
+
if (t === e) return;
|
|
359
|
+
const { onEnter: s, onLeave: i, onEnterBack: n, onLeaveBack: o } = this.options;
|
|
360
|
+
t === "before" ? (s?.(), e === "after" && i?.()) : t === "after" ? (n?.(), e === "before" && o?.()) : e === "after" ? i?.() : o?.();
|
|
361
|
+
}
|
|
362
|
+
/** Scrolling has stopped: settle on the nearest snap point, if there is one. */
|
|
363
|
+
scheduleSnap() {
|
|
364
|
+
const t = this.options.snap;
|
|
365
|
+
if (t === void 0 || this.snapper.active) return;
|
|
366
|
+
const e = N(t), s = () => {
|
|
367
|
+
this.snapTimer = null;
|
|
368
|
+
const i = this.endPx - this.startPx, n = this.scrollPosition();
|
|
369
|
+
if (!this.running || i <= 0 || n <= this.startPx || n >= this.endPx) return;
|
|
370
|
+
const o = (n - this.startPx) / i, l = this.startPx + q(o, this.releaseVelocity / i, e.snapTo) * i;
|
|
371
|
+
Math.abs(l - n) < 1 || this.snapper.animate(n, l, B(e, l - n, this.viewportHeight()), e.ease);
|
|
372
|
+
};
|
|
373
|
+
e.delay ? this.snapTimer = setTimeout(s, e.delay * 1e3) : s();
|
|
374
|
+
}
|
|
375
|
+
scrollTo(t) {
|
|
376
|
+
const e = this.options.scroller, s = this.options.horizontal ? { left: t } : { top: t };
|
|
377
|
+
e ? typeof e.scrollTo == "function" ? e.scrollTo({ ...s, behavior: "instant" }) : this.options.horizontal ? e.scrollLeft = t : e.scrollTop = t : typeof window < "u" && window.scrollTo({ ...s, behavior: "instant" });
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Resolve start and end for a trigger inside a horizontally moving container:
|
|
381
|
+
* find the container progress where each horizontal position fires, and turn
|
|
382
|
+
* it into the container's scroll offsets.
|
|
383
|
+
*/
|
|
384
|
+
measureInContainer(t) {
|
|
385
|
+
const e = this.options.trigger;
|
|
386
|
+
if (typeof e?.getBoundingClientRect != "function") return;
|
|
387
|
+
const s = e.getBoundingClientRect(), i = this.options.scroller?.getBoundingClientRect?.().left ?? 0, n = this.options.scroller ? this.options.scroller.clientWidth : typeof window < "u" ? window.innerWidth : 0, o = s.left - i - t.shiftAt(t.progress()), { start: l, end: a } = t.range(), h = (C) => l + C * (a - l), c = T(o, s.width, n, g(this.options.start) ?? "left right", t.shiftAt);
|
|
388
|
+
this.startPx = h(c);
|
|
389
|
+
const f = g(this.options.end) ?? "right left", u = typeof f == "string" ? f.trim().match(/^\+=\s*(-?[\d.]+)\s*(px)?$/) : null;
|
|
390
|
+
this.endPx = u ? this.startPx + Number.parseFloat(u[1]) : h(T(o, s.width, n, f, t.shiftAt)), this.markerGeometry = null;
|
|
391
|
+
}
|
|
392
|
+
/** Where the markers go: the element points on the page, and the viewport lines they meet. */
|
|
393
|
+
markersFor(t) {
|
|
394
|
+
const e = (n, o) => {
|
|
395
|
+
const l = g(n) ?? o;
|
|
396
|
+
if (typeof l == "number") return 0;
|
|
397
|
+
if (/^\s*\+=/.test(l)) return;
|
|
398
|
+
const a = k(l);
|
|
399
|
+
return t * a.viewportFraction - a.offsetPx;
|
|
400
|
+
}, s = e(this.options.start, "top bottom") ?? 0, i = e(this.options.end, "bottom top") ?? s;
|
|
401
|
+
return {
|
|
402
|
+
startViewport: s,
|
|
403
|
+
endViewport: i,
|
|
404
|
+
startPage: this.startPx + s,
|
|
405
|
+
endPage: this.endPx + i
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
startSmoothing() {
|
|
409
|
+
if (this.rafId !== null || typeof requestAnimationFrame > "u") return;
|
|
410
|
+
const t = (e) => {
|
|
411
|
+
if (this.rafId = null, !this.running) return;
|
|
412
|
+
const s = this.lastFrameTime === null ? 16.67 : e - this.lastFrameTime;
|
|
413
|
+
this.lastFrameTime = e, this.displayProgress = z(this.displayProgress, this.targetProgress, this.smoothing(), s);
|
|
414
|
+
const i = Math.abs(this.targetProgress - this.displayProgress) < 1e-4;
|
|
415
|
+
i && (this.displayProgress = this.targetProgress), this.applyProgress(), i ? this.lastFrameTime = null : this.rafId = requestAnimationFrame(t);
|
|
416
|
+
};
|
|
417
|
+
this.rafId = requestAnimationFrame(t);
|
|
418
|
+
}
|
|
419
|
+
stopSmoothing() {
|
|
420
|
+
this.rafId !== null && typeof cancelAnimationFrame < "u" && cancelAnimationFrame(this.rafId), this.rafId = null, this.lastFrameTime = null;
|
|
421
|
+
}
|
|
422
|
+
scrollTarget() {
|
|
423
|
+
return this.options.scroller ?? (typeof window < "u" ? window : null);
|
|
424
|
+
}
|
|
425
|
+
scrollPosition() {
|
|
426
|
+
const t = this.options.scroller, e = this.options.horizontal;
|
|
427
|
+
return t ? (e ? t.scrollLeft : t.scrollTop) ?? 0 : typeof window < "u" ? (e ? window.scrollX : window.scrollY) ?? 0 : 0;
|
|
428
|
+
}
|
|
429
|
+
triggerRect() {
|
|
430
|
+
const t = this.options.trigger;
|
|
431
|
+
return typeof t?.getBoundingClientRect != "function" ? null : this.relativeRect(t.getBoundingClientRect());
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* A viewport rect along the scroll axis, relative to the scroll container when
|
|
435
|
+
* there is one. Horizontal scrolling reports left / right / width as top / bottom / height.
|
|
436
|
+
*/
|
|
437
|
+
relativeRect(t) {
|
|
438
|
+
const e = this.options.horizontal, s = e ? t.left ?? 0 : t.top, i = e ? t.right ?? 0 : t.bottom, n = e ? t.width ?? 0 : t.height, o = this.options.scroller;
|
|
439
|
+
if (o && typeof o.getBoundingClientRect == "function") {
|
|
440
|
+
const l = o.getBoundingClientRect(), a = e ? l.left : l.top;
|
|
441
|
+
return { top: s - a, bottom: i - a, height: n };
|
|
442
|
+
}
|
|
443
|
+
return { top: s, bottom: i, height: n };
|
|
444
|
+
}
|
|
445
|
+
/** The viewport's size along the scroll axis. */
|
|
446
|
+
viewportHeight() {
|
|
447
|
+
const t = this.options.scroller, e = this.options.horizontal;
|
|
448
|
+
return t ? e ? t.clientWidth : t.clientHeight : typeof window < "u" ? e ? window.innerWidth : window.innerHeight : 0;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function g(r) {
|
|
452
|
+
return typeof r == "function" ? r() : r;
|
|
453
|
+
}
|
|
454
|
+
function Y(r) {
|
|
455
|
+
const t = new L(r);
|
|
456
|
+
return t.start(), t;
|
|
457
|
+
}
|
|
458
|
+
const P = /* @__PURE__ */ new Set(), V = 16, E = 0.5, D = 2;
|
|
459
|
+
class X {
|
|
460
|
+
options;
|
|
461
|
+
frames;
|
|
462
|
+
running = !1;
|
|
463
|
+
reduced = !1;
|
|
464
|
+
current = 0;
|
|
465
|
+
target = 0;
|
|
466
|
+
written = null;
|
|
467
|
+
velocityPxPerSecond = 0;
|
|
468
|
+
frameId = null;
|
|
469
|
+
lastTime = null;
|
|
470
|
+
journey = null;
|
|
471
|
+
pausedState = !1;
|
|
472
|
+
effects = [];
|
|
473
|
+
onWheel = (t) => this.wheel(t);
|
|
474
|
+
onScroll = () => this.nativeScroll();
|
|
475
|
+
onResize = () => this.refresh();
|
|
476
|
+
onLoad = () => this.refresh();
|
|
477
|
+
/** Scroll triggers measure with effect layers at rest, and effects measure after pins. */
|
|
478
|
+
stopListening = null;
|
|
479
|
+
constructor(t = {}) {
|
|
480
|
+
this.options = t, this.frames = t.frames ?? {
|
|
481
|
+
request: (e) => requestAnimationFrame(e),
|
|
482
|
+
cancel: (e) => cancelAnimationFrame(e)
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
start() {
|
|
486
|
+
if (this.running || typeof window > "u") return this;
|
|
487
|
+
this.running = !0, this.reduced = this.options.reducedMotion ?? (typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches), this.current = this.target = this.position();
|
|
488
|
+
const t = this.options.scroller ?? window;
|
|
489
|
+
return t.addEventListener("wheel", this.onWheel, { passive: !1 }), t.addEventListener("scroll", this.onScroll, { passive: !0 }), window.addEventListener("resize", this.onResize, { passive: !0 }), window.addEventListener("load", this.onLoad), P.add(this), this.stopListening = L.onRefresh({ beforeRefresh: () => this.rest(), afterRefresh: () => this.refresh() }), this.refresh(), this;
|
|
490
|
+
}
|
|
491
|
+
/** Re-measure every started smoother, after layout changes a resize would not catch. */
|
|
492
|
+
static refreshAll() {
|
|
493
|
+
for (const t of P) t.refresh();
|
|
494
|
+
}
|
|
495
|
+
stop() {
|
|
496
|
+
if (!this.running) return this;
|
|
497
|
+
this.running = !1;
|
|
498
|
+
const t = this.options.scroller ?? window;
|
|
499
|
+
return t.removeEventListener("wheel", this.onWheel), t.removeEventListener("scroll", this.onScroll), window.removeEventListener("resize", this.onResize), window.removeEventListener("load", this.onLoad), P.delete(this), this.stopListening?.(), this.stopListening = null, this.cancelFrame(), this.journey = null, this;
|
|
500
|
+
}
|
|
501
|
+
/** Stop, and put every effect element back where it was. */
|
|
502
|
+
destroy() {
|
|
503
|
+
this.stop();
|
|
504
|
+
for (const t of this.effects) x(t.element, t.saved);
|
|
505
|
+
this.effects = [];
|
|
506
|
+
}
|
|
507
|
+
/** GSAP's name for `destroy()`. */
|
|
508
|
+
kill() {
|
|
509
|
+
this.destroy();
|
|
510
|
+
}
|
|
511
|
+
get state() {
|
|
512
|
+
const t = this.limit();
|
|
513
|
+
return { scroll: this.current, target: this.target, progress: t > 0 ? this.current / t : 0, velocity: this.velocityPxPerSecond };
|
|
514
|
+
}
|
|
515
|
+
/** Stop responding to the wheel (e.g. while a modal is open); `paused(false)` resumes. */
|
|
516
|
+
paused(t) {
|
|
517
|
+
return t !== void 0 && (this.pausedState = t, t && (this.target = this.current, this.journey = null)), this.pausedState;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Scroll to an offset, an element or a selector, eased. Wheel input during the
|
|
521
|
+
* trip takes over from wherever it has got to.
|
|
522
|
+
*/
|
|
523
|
+
scrollTo(t, e = {}) {
|
|
524
|
+
if (!this.running) return;
|
|
525
|
+
const s = this.clamp(this.resolve(t) + (e.offset ?? 0)), i = Math.abs(s - this.current), n = this.reduced ? 0 : e.duration ?? Math.min(1.2, Math.max(0.4, i / 2500));
|
|
526
|
+
if (n <= 0) {
|
|
527
|
+
this.journey = null, this.current = this.target = s, this.write(s), this.applyEffects(0);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
this.target = s, this.journey = { from: this.current, to: s, ms: n * 1e3, ease: e.ease ?? M, elapsed: 0 }, this.requestFrame();
|
|
531
|
+
}
|
|
532
|
+
/** Re-measure the scrollable length and every effect element (resizes do this). */
|
|
533
|
+
refresh() {
|
|
534
|
+
if (!this.running) return;
|
|
535
|
+
this.rest(), this.effects = [];
|
|
536
|
+
const t = this.options.effects === !0 ? "[data-speed], [data-lag]" : this.options.effects || "";
|
|
537
|
+
if (t && !this.reduced) {
|
|
538
|
+
const e = this.options.scroller ?? document, s = this.position(), i = this.viewportHeight(), n = this.options.scroller?.getBoundingClientRect().top ?? 0;
|
|
539
|
+
for (const o of e.querySelectorAll(t)) {
|
|
540
|
+
const l = Number.parseFloat(o.dataset.speed ?? ""), a = Number.parseFloat(o.dataset.lag ?? ""), h = o.getBoundingClientRect(), c = h.top - n + s;
|
|
541
|
+
this.effects.push({
|
|
542
|
+
element: o,
|
|
543
|
+
speed: Number.isFinite(l) ? l : void 0,
|
|
544
|
+
lag: Number.isFinite(a) && a > 0 ? a : void 0,
|
|
545
|
+
centre: c + h.height / 2 - i / 2,
|
|
546
|
+
lagged: s,
|
|
547
|
+
shift: 0,
|
|
548
|
+
saved: o.style.getPropertyValue("translate")
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
this.current = this.target = this.clamp(this.position()), this.applyEffects(0);
|
|
553
|
+
}
|
|
554
|
+
/** Put effect elements at their natural place, for measuring. */
|
|
555
|
+
rest() {
|
|
556
|
+
for (const t of this.effects) x(t.element, t.saved);
|
|
557
|
+
}
|
|
558
|
+
// --- input ----------------------------------------------------------------
|
|
559
|
+
wheel(t) {
|
|
560
|
+
if (this.pausedState || this.reduced || (this.options.smooth ?? 0.8) <= 0 || t.ctrlKey || Math.abs(t.deltaX) > Math.abs(t.deltaY) || this.nestedScrollerTakes(t)) return;
|
|
561
|
+
const e = t.deltaMode === 1 ? V : t.deltaMode === 2 ? this.viewportHeight() : 1, s = t.deltaY * e * (this.options.wheelMultiplier ?? 1), i = this.clamp(this.target + s);
|
|
562
|
+
i === this.target && i === this.current || (t.preventDefault(), this.journey = null, this.target = i, this.requestFrame());
|
|
563
|
+
}
|
|
564
|
+
/** A scroll that this smoother did not write: follow it. */
|
|
565
|
+
nativeScroll() {
|
|
566
|
+
const t = this.position();
|
|
567
|
+
this.written !== null && Math.abs(t - this.written) <= D || (this.written = null, this.journey = null, this.cancelFrame(), this.current = this.target = t, this.requestFrame());
|
|
568
|
+
}
|
|
569
|
+
nestedScrollerTakes(t) {
|
|
570
|
+
const e = this.options.scroller ?? document.documentElement;
|
|
571
|
+
for (let s = t.target; s && s !== e && s !== document.body; s = s.parentElement) {
|
|
572
|
+
if (s.hasAttribute?.("data-smooth-ignore")) return !0;
|
|
573
|
+
const i = getComputedStyle(s);
|
|
574
|
+
if (!/(auto|scroll)/.test(i.overflowY) || s.scrollHeight <= s.clientHeight) continue;
|
|
575
|
+
if (t.deltaY < 0 ? s.scrollTop > 0 : s.scrollTop + s.clientHeight < s.scrollHeight - 1) return !0;
|
|
576
|
+
}
|
|
577
|
+
return !1;
|
|
578
|
+
}
|
|
579
|
+
// --- frames ---------------------------------------------------------------
|
|
580
|
+
requestFrame() {
|
|
581
|
+
this.frameId !== null || !this.running || (this.frameId = this.frames.request((t) => this.frame(t)));
|
|
582
|
+
}
|
|
583
|
+
cancelFrame() {
|
|
584
|
+
this.frameId !== null && this.frames.cancel(this.frameId), this.frameId = null, this.lastTime = null;
|
|
585
|
+
}
|
|
586
|
+
frame(t) {
|
|
587
|
+
this.frameId = null;
|
|
588
|
+
const e = this.lastTime === null ? 1e3 / 60 : Math.min(100, t - this.lastTime);
|
|
589
|
+
this.lastTime = t;
|
|
590
|
+
const s = this.current;
|
|
591
|
+
if (this.journey) {
|
|
592
|
+
const n = this.journey;
|
|
593
|
+
n.elapsed += e;
|
|
594
|
+
const o = Math.min(1, n.elapsed / n.ms);
|
|
595
|
+
this.current = n.from + (n.to - n.from) * n.ease(o), o >= 1 && (this.journey = null);
|
|
596
|
+
} else if (this.current !== this.target) {
|
|
597
|
+
const n = (this.options.smooth ?? 0.8) * 1e3 / 3;
|
|
598
|
+
this.current += (this.target - this.current) * (1 - Math.exp(-e / n)), Math.abs(this.target - this.current) < E && (this.current = this.target);
|
|
599
|
+
}
|
|
600
|
+
this.current !== s && this.write(this.current), this.velocityPxPerSecond = e > 0 ? (this.current - s) * 1e3 / e : 0;
|
|
601
|
+
const i = this.applyEffects(e);
|
|
602
|
+
this.current !== s && this.options.onUpdate?.(this.state), this.journey || this.current !== this.target || i ? this.requestFrame() : (this.lastTime = null, this.velocityPxPerSecond = 0);
|
|
603
|
+
}
|
|
604
|
+
/** Position every effect for the current scroll; true while a lag is still catching up. */
|
|
605
|
+
applyEffects(t) {
|
|
606
|
+
let e = !1;
|
|
607
|
+
const s = this.current;
|
|
608
|
+
for (const i of this.effects) {
|
|
609
|
+
let n = 0;
|
|
610
|
+
if (i.speed !== void 0 && (n += (s - i.centre) * (1 - i.speed)), i.lag !== void 0) {
|
|
611
|
+
const o = i.lag * 1e3 / 3;
|
|
612
|
+
i.lagged = t === 0 ? s : i.lagged + (s - i.lagged) * (1 - Math.exp(-t / o)), Math.abs(s - i.lagged) < E ? i.lagged = s : e = !0, n += s - i.lagged;
|
|
613
|
+
}
|
|
614
|
+
x(i.element, n === 0 ? i.saved : `0 ${G(n)}px`), i.shift = n;
|
|
615
|
+
}
|
|
616
|
+
return e;
|
|
617
|
+
}
|
|
618
|
+
// --- geometry -------------------------------------------------------------
|
|
619
|
+
write(t) {
|
|
620
|
+
const e = Math.round(t);
|
|
621
|
+
this.written = e;
|
|
622
|
+
const s = this.options.scroller;
|
|
623
|
+
s ? s.scrollTop = e : window.scrollTo({ top: e, behavior: "instant" });
|
|
624
|
+
}
|
|
625
|
+
position() {
|
|
626
|
+
const t = this.options.scroller;
|
|
627
|
+
return t ? t.scrollTop : window.scrollY;
|
|
628
|
+
}
|
|
629
|
+
viewportHeight() {
|
|
630
|
+
const t = this.options.scroller;
|
|
631
|
+
return t ? t.clientHeight : window.innerHeight;
|
|
632
|
+
}
|
|
633
|
+
limit() {
|
|
634
|
+
const t = this.options.scroller ?? document.documentElement;
|
|
635
|
+
return Math.max(0, t.scrollHeight - this.viewportHeight());
|
|
636
|
+
}
|
|
637
|
+
clamp(t) {
|
|
638
|
+
return Math.max(0, Math.min(this.limit(), t));
|
|
639
|
+
}
|
|
640
|
+
resolve(t) {
|
|
641
|
+
if (typeof t == "number") return t;
|
|
642
|
+
const e = this.options.scroller ?? document, s = typeof t == "string" ? e.querySelector(t) : t;
|
|
643
|
+
if (!s) return this.current;
|
|
644
|
+
const i = this.options.scroller?.getBoundingClientRect().top ?? 0, n = this.effects.find((o) => o.element === s)?.shift ?? 0;
|
|
645
|
+
return s.getBoundingClientRect().top - i + this.position() - n;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function x(r, t) {
|
|
649
|
+
t ? r.style.setProperty("translate", t) : r.style.removeProperty("translate");
|
|
650
|
+
}
|
|
651
|
+
function G(r) {
|
|
652
|
+
return Math.round(r * 100) / 100;
|
|
653
|
+
}
|
|
654
|
+
export {
|
|
655
|
+
H as S,
|
|
656
|
+
L as a,
|
|
657
|
+
j as b,
|
|
658
|
+
A as c,
|
|
659
|
+
X as d,
|
|
660
|
+
R as e,
|
|
661
|
+
T as f,
|
|
662
|
+
k as g,
|
|
663
|
+
Y as h,
|
|
664
|
+
z as i,
|
|
665
|
+
N as j,
|
|
666
|
+
B as k,
|
|
667
|
+
q as l,
|
|
668
|
+
b as p,
|
|
669
|
+
_ as s,
|
|
670
|
+
y as t
|
|
671
|
+
};
|