sticky-scroll-trigger 0.6.0 → 0.7.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
CHANGED
|
@@ -17,12 +17,14 @@ See the repository's `demo/index.html` + `demo/src/main.ts` for a live example,
|
|
|
17
17
|
|
|
18
18
|
| requirement | description |
|
|
19
19
|
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
20
|
-
| GSAP | 3.
|
|
20
|
+
| GSAP | `^3.15.0`, with the `ScrollTrigger` plugin already registered via `gsap.registerPlugin` |
|
|
21
21
|
| TypeScript | Optional. The published `.d.ts` uses GSAP's global types (`ScrollTrigger.Vars`); plain JavaScript projects can `import` the same `dist/` build without them |
|
|
22
22
|
| Browser | Must support `position:sticky` (no `overflow:hidden`/`clip` on any ancestor of a pinned element) |
|
|
23
23
|
| Scroll direction | Vertical scrolling only (`horizontal` is not supported) |
|
|
24
24
|
| Module system | ESM only (`import`) or a `<script>` tag via the global build; CommonJS (`require`) is not supported |
|
|
25
25
|
|
|
26
|
+
This module is tested against 3.15.0, and the notes below on what raw GSAP itself does were measured there. A later 3.x satisfies the peer range but is untested.
|
|
27
|
+
|
|
26
28
|
## Installation
|
|
27
29
|
|
|
28
30
|
```bash
|
|
@@ -176,7 +178,9 @@ Registers an overlap-scroll effect (`trigger` gets pinned while its siblings fro
|
|
|
176
178
|
| `end` | `null` (auto-computed) | End of the freeze window. When `null`, computed automatically as "the distance until `cover`'s top edge reaches the top of the viewport" |
|
|
177
179
|
| `endTrigger` | `trigger` | Reference element when `end` uses position-clause syntax |
|
|
178
180
|
|
|
179
|
-
`createOverlapScroll` adjusts `position`/`z-index` on the covering side only when needed, never overrides explicit values, and restores its changes on GSAP `kill()`.
|
|
181
|
+
`createOverlapScroll` adjusts `position`/`z-index` on the covering side only when needed, never overrides explicit values, and restores its changes on GSAP `kill()`. The restore clears a property only while it still holds the value the lift wrote, so a different value you set on the covering side afterwards (a `gsap.set()`, say) survives.
|
|
182
|
+
|
|
183
|
+
Every [`refresh()`](#refresh) runs that check again over the covering side as it stands: it raises an element added since, and hands back a property your own CSS has turned on in the meantime. Where the covering side holds a `createStickyPin` `trigger`, the pin's own wrapper rises in its place and the pinned element is left alone.
|
|
180
184
|
|
|
181
185
|
#### Room for the rise
|
|
182
186
|
|
|
@@ -266,7 +270,7 @@ sticky.refresh();
|
|
|
266
270
|
|
|
267
271
|
Here `start` means only where the element sits while pinned, not when pinning begins, as it does for the other methods. Pinning begins the moment `trigger` reaches that position naturally, which is CSS's decision rather than a separate number to set, so a pin's position and the scroll position it engages at are one setting.
|
|
268
272
|
|
|
269
|
-
That's why `start` throws on an [absolute scroll position](#absolute-scroll-position) (`start: 20`, which GSAP reads as scroll position 20) instead of
|
|
273
|
+
That's why `start` throws on an [absolute scroll position](#absolute-scroll-position) (`start: 20`, which GSAP reads as scroll position 20) instead of silently treating it as a px distance. `top` is its own option for the same reason: with the bare-number slot reserved for GSAP's meaning, `'top 20px'` would otherwise be a pin's only way to say "20px below the top of the viewport". `end` does take an absolute scroll position (`end: 3000` releases at scroll 3000), since a release point is a real thing to ask for on the scroll axis.
|
|
270
274
|
|
|
271
275
|
Clauses resolve exactly as they do elsewhere, including the one-token forms that name the element's own side: `'top 20px'` puts the element's top 20px below the viewport's top edge, while `'20px'` puts it 20px above.
|
|
272
276
|
|
|
@@ -375,7 +379,7 @@ If surviving layers' freeze windows change after kill, GSAP's cached `start`/`en
|
|
|
375
379
|
|
|
376
380
|
Tears down the controller, restores the original DOM layout, and reverts z-order changes from `createOverlapScroll`. This is also the only entry point that can clean up cover layers that were never passed to `ScrollTrigger.create()`.
|
|
377
381
|
|
|
378
|
-
It only cleans up DOM/styles managed by this module. You still need to kill active ScrollTrigger instances yourself. After `destroy()`, `createStickyTrigger
|
|
382
|
+
It only cleans up DOM/styles managed by this module. You still need to kill active ScrollTrigger instances yourself. After `destroy()`, `createStickyTrigger`, `createOverlapScroll` and `createStickyPin` throw and `refresh()` is a no-op. Calling `destroy()` twice is safe.
|
|
379
383
|
|
|
380
384
|
## Same-page links
|
|
381
385
|
|
|
@@ -384,7 +388,7 @@ Pinning decouples an element's position in the document from the scroll position
|
|
|
384
388
|
`refresh()` declares that difference to the browser by keeping `scroll-margin-top` in sync on every element inside the shared container that matches `scrollMarginTargets` (`'[id]'` by default). Nothing else is needed: plain `<a href="#target">` links, `scrollIntoView()`, `:target` and a `#hash` on load all land correctly as written.
|
|
385
389
|
|
|
386
390
|
```html
|
|
387
|
-
<!--
|
|
391
|
+
<!-- Lands correctly with no click handler and no scroll math. -->
|
|
388
392
|
<a href="#chapter3">Chapter 3</a>
|
|
389
393
|
```
|
|
390
394
|
|
|
@@ -432,7 +436,7 @@ GSAP passes the `ScrollTrigger` instance to its own function-valued `start`/`end
|
|
|
432
436
|
|
|
433
437
|
### Absolute scroll position
|
|
434
438
|
|
|
435
|
-
If the entire value is just a number (a plain JS number, or a string that's nothing but digits, with no keyword, second token, or `%`/`px` suffix), GSAP treats it as an absolute scroll position rather than a clause,
|
|
439
|
+
If the entire value is just a number (a plain JS number, or a string that's nothing but digits, with no keyword, second token, or `%`/`px` suffix), GSAP treats it as an absolute scroll position rather than a clause, and ignores the reference element entirely (`ScrollTrigger.js`'s `_parsePosition`: `isNaN(value) || (value = +value)`). This module follows the same rule for `start` and `end`, and for [`createStickyPin`](#createstickypinoptions)'s `end`, [`createResolvedTrigger`](#createresolvedtriggeroptions)'s `start`/`end`, and [`resolveScrollPosition`](#resolvescrollpositionelement-position)'s `position`.
|
|
436
440
|
|
|
437
441
|
`start: '500'` (or `start: 500`) freezes starting at absolute scroll position 500px, ignoring the trigger's natural position and any preceding dwell. `end: '500'` ends the freeze window at 500px the same way, clamped to `start` if that would put `end` before it, matching GSAP's own `end = Math.max(start, ...)`.
|
|
438
442
|
|
|
@@ -440,7 +444,7 @@ If the entire value is just a number (a plain JS number, or a string that's noth
|
|
|
440
444
|
|
|
441
445
|
> [`createOverlapScroll`](#createoverlapscrolloptions)'s `start` doesn't support absolute scroll positions: a cover layer's sticky position is always computed relative to its own wrapper (see the repository's `ARCHITECTURE.md`), which has no equivalent for one. It throws instead; use a position clause.
|
|
442
446
|
|
|
443
|
-
> [`createStickyPin`](#createstickypinoptions)'s `start` throws on one too, for a different reason than the cover layer above
|
|
447
|
+
> [`createStickyPin`](#createstickypinoptions)'s `start` throws on one too, for a different reason than the cover layer above. The scroll position a pin engages at follows from where it sits, so honoring an absolute value would mean inverting it back into a viewport position the caller never chose. A trigger 2000px down the document, asked to engage at scroll 500, would sit 1500px below the viewport's top edge, off-screen. Its `end` does take one.
|
|
444
448
|
|
|
445
449
|
## End syntax
|
|
446
450
|
|
|
@@ -487,7 +491,7 @@ sticky.createOverlapScroll({
|
|
|
487
491
|
}); // pin until the very bottom of the page
|
|
488
492
|
```
|
|
489
493
|
|
|
490
|
-
`'max'` is only supported by [`createOverlapScroll`](#createoverlapscrolloptions) and [`resolveScrollPosition`](#resolvescrollpositionelement-position)/[`createResolvedTrigger`](#createresolvedtriggeroptions). `createStickyTrigger` and `createStickyPin` throw on it, because their own dwell padding or pin spacer adds to the document height `'max'` measures: the freeze window would depend on itself, growing the page a little more on every `refresh()`. GSAP defines `'max'` for `end`, not `start
|
|
494
|
+
`'max'` is only supported by [`createOverlapScroll`](#createoverlapscrolloptions) and [`resolveScrollPosition`](#resolvescrollpositionelement-position)/[`createResolvedTrigger`](#createresolvedtriggeroptions). `createStickyTrigger` and `createStickyPin` throw on it, because their own dwell padding or pin spacer adds to the document height `'max'` measures: the freeze window would depend on itself, growing the page a little more on every `refresh()`. GSAP defines `'max'` for `end`, not `start`. In raw GSAP 3.15.0, `start: 'max'` silently resolves to `0` rather than the scroller's max, so this module rejects it for `start` instead of reproducing that.
|
|
491
495
|
|
|
492
496
|
## Constraints and caveats
|
|
493
497
|
|
|
@@ -507,7 +511,7 @@ sticky.createOverlapScroll({
|
|
|
507
511
|
- Using the same element as the `trigger` of two different `createStickyTrigger`/`createOverlapScroll`/`createStickyPin` calls throws
|
|
508
512
|
- You must call `refresh()` once manually after registration. Window resize/load recomputation is automatically wired to GSAP's own `refreshInit`, but for layout changes that don't involve those (e.g. content height changes), call `ScrollTrigger.refresh()` yourself (see [Calling refresh](#calling-refresh))
|
|
509
513
|
- Resizes from mobile browsers showing/hiding their address bar are absorbed automatically (see the repository's `ARCHITECTURE.md`, "Two-pass position measurement"), but other causes like `visualViewport` zoom are not handled
|
|
510
|
-
- `refresh()` writes an inline `scroll-margin-top` on every element matching `scrollMarginTargets` inside the shared container, and
|
|
514
|
+
- `refresh()` writes an inline `scroll-margin-top` on every element matching `scrollMarginTargets` inside the shared container, and, on engines that drive the correction's ramps in CSS, adopts one stylesheet of its own per instance. That sheet is a constructed one, so a Content Security Policy needs no `style-src` exception for it. Both are undone by `destroy()`. Pass `scrollMarginTargets: null` to opt out (see [Same-page links](#same-page-links))
|
|
511
515
|
- Don't nest one `StickyScrollTrigger` instance's shared container inside another's: once a target sits inside more than one, [`getScrollTop`](#stickyscrolltriggergetscrolltopelement-instances)'s ownership check picks whichever instance is listed first, and neither instance's own dwell alone is actually correct for it
|
|
512
516
|
|
|
513
517
|
## License
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.7.0
|
|
4
4
|
* Copyright (c) 2026 Kuninori Ogino
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
* https://github.com/kuninori-ogino/sticky-scroll-trigger
|
|
@@ -129,25 +129,32 @@ var StickyScrollTrigger = (function() {
|
|
|
129
129
|
if (parent) parent.insertBefore(trigger, outer);
|
|
130
130
|
outer.remove();
|
|
131
131
|
};
|
|
132
|
+
const LIFT_VALUES = {
|
|
133
|
+
position: "relative",
|
|
134
|
+
zIndex: "1"
|
|
135
|
+
};
|
|
132
136
|
const liftStates = new WeakMap();
|
|
133
137
|
const liftAboveStickyWrapper = (cover) => {
|
|
134
138
|
const lifted = [];
|
|
135
139
|
for (let node = cover; node; node = node.nextElementSibling) {
|
|
136
140
|
if (!(node instanceof HTMLElement)) continue;
|
|
137
|
-
const
|
|
141
|
+
const element = node;
|
|
142
|
+
const existing = liftStates.get(element);
|
|
138
143
|
if (existing) existing.count += 1;
|
|
139
144
|
else {
|
|
140
|
-
const computed = getComputedStyle(
|
|
141
|
-
const
|
|
145
|
+
const computed = getComputedStyle(element);
|
|
146
|
+
const applied = [];
|
|
147
|
+
if (computed.position === "static") applied.push("position");
|
|
148
|
+
if (computed.zIndex === "auto") applied.push("zIndex");
|
|
149
|
+
applied.forEach((property) => {
|
|
150
|
+
element.style[property] = LIFT_VALUES[property];
|
|
151
|
+
});
|
|
152
|
+
liftStates.set(element, {
|
|
142
153
|
count: 1,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
if (computed.position === "static") node.style.position = "relative";
|
|
147
|
-
if (computed.zIndex === "auto") node.style.zIndex = "1";
|
|
148
|
-
liftStates.set(node, state);
|
|
154
|
+
applied
|
|
155
|
+
});
|
|
149
156
|
}
|
|
150
|
-
lifted.push(
|
|
157
|
+
lifted.push(element);
|
|
151
158
|
}
|
|
152
159
|
return () => {
|
|
153
160
|
lifted.forEach((el) => {
|
|
@@ -155,8 +162,9 @@ var StickyScrollTrigger = (function() {
|
|
|
155
162
|
if (!state) return;
|
|
156
163
|
state.count -= 1;
|
|
157
164
|
if (state.count > 0) return;
|
|
158
|
-
|
|
159
|
-
|
|
165
|
+
state.applied.forEach((property) => {
|
|
166
|
+
if (el.style[property] === LIFT_VALUES[property]) el.style[property] = "";
|
|
167
|
+
});
|
|
160
168
|
liftStates.delete(el);
|
|
161
169
|
});
|
|
162
170
|
lifted.length = 0;
|
|
@@ -165,6 +173,8 @@ var StickyScrollTrigger = (function() {
|
|
|
165
173
|
const OFFSET_PROPERTY = "--sst-scroll-margin-top-offset";
|
|
166
174
|
let nextInstanceSuffix = 0;
|
|
167
175
|
const supportsScrollDrivenAnimations = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("animation-timeline", "scroll()");
|
|
176
|
+
const supportsConstructedStyleSheets = typeof CSSStyleSheet === "function" && typeof CSSStyleSheet.prototype.replaceSync === "function" && typeof document !== "undefined" && Array.isArray(document.adoptedStyleSheets);
|
|
177
|
+
const usesCssRamp = supportsScrollDrivenAnimations && supportsConstructedStyleSheets;
|
|
168
178
|
const buildStylesheet = (instanceId, scenes) => {
|
|
169
179
|
const declarations = [];
|
|
170
180
|
const animations = [];
|
|
@@ -185,7 +195,7 @@ var StickyScrollTrigger = (function() {
|
|
|
185
195
|
const instanceId = `sst${nextInstanceSuffix++}`;
|
|
186
196
|
const snapshots = new WeakMap();
|
|
187
197
|
let written = new Set();
|
|
188
|
-
let
|
|
198
|
+
let sheet = null;
|
|
189
199
|
let animationHost = null;
|
|
190
200
|
let jsRamps = [];
|
|
191
201
|
let jsHost = null;
|
|
@@ -197,14 +207,16 @@ var StickyScrollTrigger = (function() {
|
|
|
197
207
|
jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
|
|
198
208
|
});
|
|
199
209
|
};
|
|
200
|
-
if (!
|
|
210
|
+
if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
|
|
201
211
|
const restoreTarget = (target) => {
|
|
202
212
|
const snapshot = snapshots.get(target);
|
|
203
213
|
target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
|
|
204
214
|
};
|
|
205
215
|
const clearAnimation = () => {
|
|
206
|
-
|
|
207
|
-
|
|
216
|
+
if (sheet) {
|
|
217
|
+
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((one) => one !== sheet);
|
|
218
|
+
sheet = null;
|
|
219
|
+
}
|
|
208
220
|
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
209
221
|
animationHost = null;
|
|
210
222
|
jsRamps = [];
|
|
@@ -224,16 +236,17 @@ var StickyScrollTrigger = (function() {
|
|
|
224
236
|
animationHost = host;
|
|
225
237
|
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
226
238
|
}
|
|
227
|
-
if (!
|
|
239
|
+
if (!usesCssRamp) {
|
|
228
240
|
jsRamps = ramps;
|
|
229
241
|
jsHost = host;
|
|
230
242
|
applyJsRamp();
|
|
243
|
+
} else {
|
|
244
|
+
if (!sheet) {
|
|
245
|
+
sheet = new CSSStyleSheet();
|
|
246
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
247
|
+
}
|
|
248
|
+
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
231
249
|
}
|
|
232
|
-
if (!styleElement) {
|
|
233
|
-
styleElement = document.createElement("style");
|
|
234
|
-
document.head.appendChild(styleElement);
|
|
235
|
-
}
|
|
236
|
-
styleElement.textContent = buildStylesheet(instanceId, ramps);
|
|
237
250
|
const targets = Array.from(rootElement.querySelectorAll(targetSelector));
|
|
238
251
|
targets.forEach((target) => {
|
|
239
252
|
const existing = snapshots.get(target);
|
|
@@ -257,7 +270,7 @@ var StickyScrollTrigger = (function() {
|
|
|
257
270
|
written = next;
|
|
258
271
|
},
|
|
259
272
|
restore() {
|
|
260
|
-
if (!
|
|
273
|
+
if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
|
|
261
274
|
written.forEach(restoreTarget);
|
|
262
275
|
written = new Set();
|
|
263
276
|
clearAnimation();
|
|
@@ -599,11 +612,11 @@ var StickyScrollTrigger = (function() {
|
|
|
599
612
|
#captureScrollTriggerClass(self) {
|
|
600
613
|
this.#scrollTriggerClass = self.constructor;
|
|
601
614
|
}
|
|
602
|
-
#createAutoRefreshHandler(
|
|
615
|
+
#createAutoRefreshHandler(userOnRefreshInit) {
|
|
603
616
|
return (self) => {
|
|
604
617
|
this.#captureScrollTriggerClass(self);
|
|
605
618
|
const result = userOnRefreshInit?.(self);
|
|
606
|
-
|
|
619
|
+
this.refresh();
|
|
607
620
|
return result;
|
|
608
621
|
};
|
|
609
622
|
}
|
|
@@ -616,6 +629,13 @@ var StickyScrollTrigger = (function() {
|
|
|
616
629
|
layer.inner = wrapped.inner;
|
|
617
630
|
});
|
|
618
631
|
}
|
|
632
|
+
#unwrapPinLayer(layer) {
|
|
633
|
+
if (!layer.outer) return false;
|
|
634
|
+
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
635
|
+
layer.outer = null;
|
|
636
|
+
layer.inner = null;
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
619
639
|
#resetSceneCoverStickyState() {
|
|
620
640
|
const wrapperSnapshots = this.#layers.map((layer) => layer.wrapper).filter((wrapper) => wrapper !== null).map((wrapper) => ({
|
|
621
641
|
wrapper,
|
|
@@ -721,12 +741,29 @@ var StickyScrollTrigger = (function() {
|
|
|
721
741
|
this.#unbuild();
|
|
722
742
|
this.#build();
|
|
723
743
|
}
|
|
724
|
-
this.#
|
|
744
|
+
this.#restoreCoverLifts();
|
|
745
|
+
try {
|
|
746
|
+
this.#wrapUnwrappedPins();
|
|
747
|
+
} finally {
|
|
748
|
+
this.#liftCovers();
|
|
749
|
+
}
|
|
725
750
|
const viewportHeight = this.#layers.length || this.#pinLayers.length ? measureViewportHeight() : 0;
|
|
726
751
|
this.#refreshScenesAndCovers(viewportHeight);
|
|
727
752
|
this.#refreshPins(viewportHeight);
|
|
728
753
|
this.#syncScrollMargins();
|
|
729
754
|
}
|
|
755
|
+
#coverLayers() {
|
|
756
|
+
return this.#layers.filter((layer) => layer.kind === "cover");
|
|
757
|
+
}
|
|
758
|
+
#restoreCoverLifts() {
|
|
759
|
+
this.#coverLayers().forEach((layer) => this.#coverRestoreByLayer.get(layer)?.());
|
|
760
|
+
}
|
|
761
|
+
#liftCovers() {
|
|
762
|
+
this.#coverLayers().forEach((layer) => {
|
|
763
|
+
const pin = this.#pinLayers.find(({ trigger }) => trigger === layer.cover);
|
|
764
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(pin?.outer ?? layer.cover));
|
|
765
|
+
});
|
|
766
|
+
}
|
|
730
767
|
#syncScrollMargins() {
|
|
731
768
|
this.#scrollMarginSync.sync(this.#layers.filter((layer) => layer.kind === "scene").map(({ trigger, freezeStart, freezeEnd }) => ({
|
|
732
769
|
trigger,
|
|
@@ -771,7 +808,7 @@ var StickyScrollTrigger = (function() {
|
|
|
771
808
|
this.#scheduleRebuild();
|
|
772
809
|
onKill?.(self);
|
|
773
810
|
},
|
|
774
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
811
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
775
812
|
};
|
|
776
813
|
}
|
|
777
814
|
createStickyTrigger({ trigger: triggerInput, start = "0 0", end = "100% 0", endTrigger: endTriggerInput, onKill, ...rest }) {
|
|
@@ -812,11 +849,10 @@ var StickyScrollTrigger = (function() {
|
|
|
812
849
|
freezeEnd: 0
|
|
813
850
|
};
|
|
814
851
|
const vars = this.#registerLayer(layer, (self) => {
|
|
815
|
-
|
|
852
|
+
this.#coverRestoreByLayer.get(layer)?.();
|
|
816
853
|
onKill?.(self);
|
|
817
854
|
}, rest);
|
|
818
|
-
|
|
819
|
-
this.#coverRestoreByLayer.set(layer, restoreCoverStyles);
|
|
855
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
820
856
|
return vars;
|
|
821
857
|
}
|
|
822
858
|
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "top top", onKill, ...rest }) {
|
|
@@ -845,14 +881,10 @@ var StickyScrollTrigger = (function() {
|
|
|
845
881
|
this.#captureScrollTriggerClass(self);
|
|
846
882
|
const index = this.#pinLayers.indexOf(layer);
|
|
847
883
|
if (index !== -1) this.#pinLayers.splice(index, 1);
|
|
848
|
-
if (layer
|
|
849
|
-
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
850
|
-
layer.outer = null;
|
|
851
|
-
layer.inner = null;
|
|
852
|
-
}
|
|
884
|
+
if (this.#unwrapPinLayer(layer)) this.#scheduleRebuild();
|
|
853
885
|
onKill?.(self);
|
|
854
886
|
},
|
|
855
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
887
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
856
888
|
};
|
|
857
889
|
}
|
|
858
890
|
resolveScrollPosition(elementInput, position) {
|
|
@@ -894,15 +926,11 @@ var StickyScrollTrigger = (function() {
|
|
|
894
926
|
if (this.#destroyed) return;
|
|
895
927
|
this.#destroyed = true;
|
|
896
928
|
this.#scrollMarginSync.restore();
|
|
897
|
-
this.#
|
|
898
|
-
if (layer.kind === "cover") this.#coverRestoreByLayer.get(layer)?.();
|
|
899
|
-
});
|
|
929
|
+
this.#restoreCoverLifts();
|
|
900
930
|
this.#unbuild();
|
|
901
931
|
this.#layers.length = 0;
|
|
902
932
|
this.#builtLayers = [];
|
|
903
|
-
this.#pinLayers.forEach((layer) =>
|
|
904
|
-
if (layer.outer) unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
905
|
-
});
|
|
933
|
+
this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
|
|
906
934
|
this.#pinLayers.length = 0;
|
|
907
935
|
}
|
|
908
936
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.7.0
|
|
4
4
|
* Copyright (c) 2026 Kuninori Ogino
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
* https://github.com/kuninori-ogino/sticky-scroll-trigger
|
|
7
7
|
*/
|
|
8
|
-
var StickyScrollTrigger=(function(){let e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},c=e=>{e.style.position=``,e.style.top=``},l=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},u=e=>({position:e.style.position,top:e.style.top}),d=(e,t)=>{e.style.position=t.position,e.style.top=t.top},f=e=>{if(!e.parentNode)throw Error(`StickyScrollTrigger: ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`),i=document.createElement(`div`);return i.setAttribute(`aria-hidden`,`true`),i.style.pointerEvents=`none`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),t.appendChild(i),{container:t,wrapper:n,padding:i}},p=e=>{let t=e.parentNode;if(!t)throw Error(`createOverlapScroll: trigger ${r(e)} is not attached to the document`);let n=document.createElement(`div`);for(t.insertBefore(n,t.firstChild);n.nextSibling;){let t=n.nextSibling;if(n.appendChild(t),t===e)break}return n},m=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},h=e=>{if(!e.parentNode)throw Error(`createStickyPin: trigger ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`);return t.style.height=`0`,t.style.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},g=(e,t,n)=>{let r=e.parentNode;d(t,n),r&&r.insertBefore(t,e),e.remove()},_=new WeakMap,v=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=_.get(n);if(e)e.count+=1;else{let e=getComputedStyle(n),t={count:1,position:n.style.position,zIndex:n.style.zIndex};e.position===`static`&&(n.style.position=`relative`),e.zIndex===`auto`&&(n.style.zIndex=`1`),_.set(n,t)}t.push(n)}return()=>{t.forEach(e=>{let t=_.get(e);t&&(--t.count,!(t.count>0)&&(e.style.position=t.position,e.style.zIndex=t.zIndex,_.delete(e)))}),t.length=0}},y=0,b=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),x=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},S=e=>{let t=`sst${y++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};b||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i?.remove(),i=null,a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),b||(o=h,c=p,l()),i||(i=document.createElement(`style`),document.head.appendChild(i)),i.textContent=x(t,h);let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){b||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},C=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},w=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},T=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},E=e=>typeof e==`function`?e():e,D={top:0,center:.5,bottom:1},O=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},k=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,A=(e,t)=>{let n=k.exec(e);if(!n||!n[1]&&!n[3])throw L.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in D,l=i===`%`;return{fraction:c?D[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?O(a,o,s,t):0)}},j=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),M=e=>typeof e==`number`?e:Number(e),N=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=A(i,t),s=A(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},P=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,F=e=>typeof e==`string`&&P.test(e.trim()),I=(e,t)=>{let n=P.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return O(void 0,r,i,t)},L=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?O(r,i,a,t):0},B=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},V=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+B(e,s,a,l.end.rawTop,u):t}let r=N(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},H=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=V(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=V(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},U=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],W=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(F(a))return{mode:`dwell`,distancePx:Math.max(0,I(a,t))};if(j(a))return{mode:`absolute`,value:M(a)};if(R(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:z(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},G=(e,t,n,i)=>{if(!j(t))return{mode:`clause`,anchorOffset:N(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:M(t)}},K=(e,t,n,r,a)=>{let o=E(n.start),s=n.end===null?null:E(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=W(e,t,n,s,r,u),f=G(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},q=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},J=(e,t)=>e.some(e=>e.trigger===t);return class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=S(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(T(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=w(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e,t,n){return r=>{this.#g(r);let i=n?.(r);return e[0]===t&&this.refresh(),i}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#b(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#x(e){if(!this.#u.length)return;let t=this.#y(),n=this.#b();try{this.#S(e)}catch(e){throw n(),e}finally{t()}}#S(e){this.#u.forEach(t=>{if(!t.inner)return;let n=E(t.end);if(R(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=E(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(j(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=N(r,o,e),c=(j(n)?M(n):i(t.endTrigger)-N(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#C(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#y();try{this.#w(e,t)}catch(e){throw n(),e}}#w(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>K(this.#e,e,t,n,r)),s=0,c=()=>H(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||C(this.#t))&&(this.#p(),this.#m()),this.#v();let e=this.#t.length||this.#u.length?a():0;this.#C(e),this.#x(e),this.#T()}#T(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#E(e,t){let n=U.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#D(e,t,n){if(J(e,t))throw Error(n)}#O(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#k(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#A(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#D(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#D(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(this.#t,e,n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#E(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#O(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#A({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#E(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#O(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#A(p,e=>{h(),c?.(e)},l),h=v(f);return this.#r.set(p,h),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#E(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#k(l,`createStickyPin`),this.#D(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#D(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:q(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),f.outer&&(g(f.outer,f.trigger,f.savedPosition),f.outer=null,f.inner=null),s?.(e)},onRefreshInit:this.#_(this.#u,f,c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=E(n),l=a();if(R(c))return o(l)+z(c,l);if(j(c))return M(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=N(c,r.offsetHeight,l),f=this.#y(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#E(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#t.forEach(e=>{e.kind===`cover`&&this.#r.get(e)?.()}),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>{e.outer&&g(e.outer,e.trigger,e.savedPosition)}),this.#u.length=0)}}})();
|
|
8
|
+
var StickyScrollTrigger=(function(){let e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},c=e=>{e.style.position=``,e.style.top=``},l=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},u=e=>({position:e.style.position,top:e.style.top}),d=(e,t)=>{e.style.position=t.position,e.style.top=t.top},f=e=>{if(!e.parentNode)throw Error(`StickyScrollTrigger: ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`),i=document.createElement(`div`);return i.setAttribute(`aria-hidden`,`true`),i.style.pointerEvents=`none`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),t.appendChild(i),{container:t,wrapper:n,padding:i}},p=e=>{let t=e.parentNode;if(!t)throw Error(`createOverlapScroll: trigger ${r(e)} is not attached to the document`);let n=document.createElement(`div`);for(t.insertBefore(n,t.firstChild);n.nextSibling;){let t=n.nextSibling;if(n.appendChild(t),t===e)break}return n},m=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},h=e=>{if(!e.parentNode)throw Error(`createStickyPin: trigger ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`);return t.style.height=`0`,t.style.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},g=(e,t,n)=>{let r=e.parentNode;d(t,n),r&&r.insertBefore(t,e),e.remove()},_={position:`relative`,zIndex:`1`},v=new WeakMap,y=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=v.get(e);if(r)r.count+=1;else{let t=getComputedStyle(e),n=[];t.position===`static`&&n.push(`position`),t.zIndex===`auto`&&n.push(`zIndex`),n.forEach(t=>{e.style[t]=_[t]}),v.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=v.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===_[t]&&(e.style[t]=``)}),v.delete(e)))}),t.length=0}},b=0,x=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),S=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),C=x&&S,w=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},T=e=>{let t=`sst${b++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};C||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i&&=(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(e=>e!==i),null),a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),C?(i||(i=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,i]),i.replaceSync(w(t,h))):(o=h,c=p,l());let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){C||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},E=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},D=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},O=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},k=e=>typeof e==`function`?e():e,A={top:0,center:.5,bottom:1},j=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},M=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,N=(e,t)=>{let n=M.exec(e);if(!n||!n[1]&&!n[3])throw B.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in A,l=i===`%`;return{fraction:c?A[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?j(a,o,s,t):0)}},P=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),F=e=>typeof e==`number`?e:Number(e),I=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=N(i,t),s=N(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},L=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return j(void 0,r,i,t)},B=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,V=e=>typeof e==`string`&&B.test(e.trim()),H=(e,t)=>{let n=B.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?j(r,i,a,t):0},U=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},W=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+U(e,s,a,l.end.rawTop,u):t}let r=I(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},G=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=W(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=W(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},K=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],q=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(R(a))return{mode:`dwell`,distancePx:Math.max(0,z(a,t))};if(P(a))return{mode:`absolute`,value:F(a)};if(V(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:H(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},J=(e,t,n,i)=>{if(!P(t))return{mode:`clause`,anchorOffset:I(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:F(t)}},Y=(e,t,n,r,a)=>{let o=k(n.start),s=n.end===null?null:k(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=q(e,t,n,s,r,u),f=J(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},X=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},Z=(e,t)=>e.some(e=>e.trigger===t);return class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=T(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(O(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=D(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e){return t=>{this.#g(t);let n=e?.(t);return this.refresh(),n}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(e){return e.outer?(g(e.outer,e.trigger,e.savedPosition),e.outer=null,e.inner=null,!0):!1}#b(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#x(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#S(e){if(!this.#u.length)return;let t=this.#b(),n=this.#x();try{this.#C(e)}catch(e){throw n(),e}finally{t()}}#C(e){this.#u.forEach(t=>{if(!t.inner)return;let n=k(t.end);if(V(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=k(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(P(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=I(r,o,e),c=(P(n)?F(n):i(t.endTrigger)-I(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#w(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#b();try{this.#T(e,t)}catch(e){throw n(),e}}#T(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>Y(this.#e,e,t,n,r)),s=0,c=()=>G(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||E(this.#t))&&(this.#p(),this.#m()),this.#D();try{this.#v()}finally{this.#O()}let e=this.#t.length||this.#u.length?a():0;this.#w(e),this.#S(e),this.#k()}#E(){return this.#t.filter(e=>e.kind===`cover`)}#D(){this.#E().forEach(e=>this.#r.get(e)?.())}#O(){this.#E().forEach(e=>{let t=this.#u.find(({trigger:t})=>t===e.cover);this.#r.set(e,y(t?.outer??e.cover))})}#k(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#A(e,t){let n=K.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#j(e,t,n){if(Z(e,t))throw Error(n)}#M(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#N(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#P(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#j(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#j(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#A(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#M(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#P({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#A(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#M(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#P(p,e=>{this.#r.get(p)?.(),c?.(e)},l);return this.#r.set(p,y(f)),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#A(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#N(l,`createStickyPin`),this.#j(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#j(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:X(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),this.#y(f)&&this.#h(),s?.(e)},onRefreshInit:this.#_(c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=k(n),l=a();if(V(c))return o(l)+H(c,l);if(P(c))return F(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=I(c,r.offsetHeight,l),f=this.#b(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#A(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#D(),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#y(e)),this.#u.length=0)}}})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.7.0
|
|
4
4
|
* Copyright (c) 2026 Kuninori Ogino
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
* https://github.com/kuninori-ogino/sticky-scroll-trigger
|
|
@@ -128,25 +128,32 @@ const unwrapPin = (outer, trigger, saved) => {
|
|
|
128
128
|
if (parent) parent.insertBefore(trigger, outer);
|
|
129
129
|
outer.remove();
|
|
130
130
|
};
|
|
131
|
+
const LIFT_VALUES = {
|
|
132
|
+
position: "relative",
|
|
133
|
+
zIndex: "1"
|
|
134
|
+
};
|
|
131
135
|
const liftStates = new WeakMap();
|
|
132
136
|
const liftAboveStickyWrapper = (cover) => {
|
|
133
137
|
const lifted = [];
|
|
134
138
|
for (let node = cover; node; node = node.nextElementSibling) {
|
|
135
139
|
if (!(node instanceof HTMLElement)) continue;
|
|
136
|
-
const
|
|
140
|
+
const element = node;
|
|
141
|
+
const existing = liftStates.get(element);
|
|
137
142
|
if (existing) existing.count += 1;
|
|
138
143
|
else {
|
|
139
|
-
const computed = getComputedStyle(
|
|
140
|
-
const
|
|
144
|
+
const computed = getComputedStyle(element);
|
|
145
|
+
const applied = [];
|
|
146
|
+
if (computed.position === "static") applied.push("position");
|
|
147
|
+
if (computed.zIndex === "auto") applied.push("zIndex");
|
|
148
|
+
applied.forEach((property) => {
|
|
149
|
+
element.style[property] = LIFT_VALUES[property];
|
|
150
|
+
});
|
|
151
|
+
liftStates.set(element, {
|
|
141
152
|
count: 1,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
if (computed.position === "static") node.style.position = "relative";
|
|
146
|
-
if (computed.zIndex === "auto") node.style.zIndex = "1";
|
|
147
|
-
liftStates.set(node, state);
|
|
153
|
+
applied
|
|
154
|
+
});
|
|
148
155
|
}
|
|
149
|
-
lifted.push(
|
|
156
|
+
lifted.push(element);
|
|
150
157
|
}
|
|
151
158
|
return () => {
|
|
152
159
|
lifted.forEach((el) => {
|
|
@@ -154,8 +161,9 @@ const liftAboveStickyWrapper = (cover) => {
|
|
|
154
161
|
if (!state) return;
|
|
155
162
|
state.count -= 1;
|
|
156
163
|
if (state.count > 0) return;
|
|
157
|
-
|
|
158
|
-
|
|
164
|
+
state.applied.forEach((property) => {
|
|
165
|
+
if (el.style[property] === LIFT_VALUES[property]) el.style[property] = "";
|
|
166
|
+
});
|
|
159
167
|
liftStates.delete(el);
|
|
160
168
|
});
|
|
161
169
|
lifted.length = 0;
|
|
@@ -164,6 +172,8 @@ const liftAboveStickyWrapper = (cover) => {
|
|
|
164
172
|
const OFFSET_PROPERTY = "--sst-scroll-margin-top-offset";
|
|
165
173
|
let nextInstanceSuffix = 0;
|
|
166
174
|
const supportsScrollDrivenAnimations = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("animation-timeline", "scroll()");
|
|
175
|
+
const supportsConstructedStyleSheets = typeof CSSStyleSheet === "function" && typeof CSSStyleSheet.prototype.replaceSync === "function" && typeof document !== "undefined" && Array.isArray(document.adoptedStyleSheets);
|
|
176
|
+
const usesCssRamp = supportsScrollDrivenAnimations && supportsConstructedStyleSheets;
|
|
167
177
|
const buildStylesheet = (instanceId, scenes) => {
|
|
168
178
|
const declarations = [];
|
|
169
179
|
const animations = [];
|
|
@@ -184,7 +194,7 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
184
194
|
const instanceId = `sst${nextInstanceSuffix++}`;
|
|
185
195
|
const snapshots = new WeakMap();
|
|
186
196
|
let written = new Set();
|
|
187
|
-
let
|
|
197
|
+
let sheet = null;
|
|
188
198
|
let animationHost = null;
|
|
189
199
|
let jsRamps = [];
|
|
190
200
|
let jsHost = null;
|
|
@@ -196,14 +206,16 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
196
206
|
jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
|
|
197
207
|
});
|
|
198
208
|
};
|
|
199
|
-
if (!
|
|
209
|
+
if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
|
|
200
210
|
const restoreTarget = (target) => {
|
|
201
211
|
const snapshot = snapshots.get(target);
|
|
202
212
|
target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
|
|
203
213
|
};
|
|
204
214
|
const clearAnimation = () => {
|
|
205
|
-
|
|
206
|
-
|
|
215
|
+
if (sheet) {
|
|
216
|
+
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((one) => one !== sheet);
|
|
217
|
+
sheet = null;
|
|
218
|
+
}
|
|
207
219
|
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
208
220
|
animationHost = null;
|
|
209
221
|
jsRamps = [];
|
|
@@ -223,16 +235,17 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
223
235
|
animationHost = host;
|
|
224
236
|
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
225
237
|
}
|
|
226
|
-
if (!
|
|
238
|
+
if (!usesCssRamp) {
|
|
227
239
|
jsRamps = ramps;
|
|
228
240
|
jsHost = host;
|
|
229
241
|
applyJsRamp();
|
|
242
|
+
} else {
|
|
243
|
+
if (!sheet) {
|
|
244
|
+
sheet = new CSSStyleSheet();
|
|
245
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
246
|
+
}
|
|
247
|
+
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
230
248
|
}
|
|
231
|
-
if (!styleElement) {
|
|
232
|
-
styleElement = document.createElement("style");
|
|
233
|
-
document.head.appendChild(styleElement);
|
|
234
|
-
}
|
|
235
|
-
styleElement.textContent = buildStylesheet(instanceId, ramps);
|
|
236
249
|
const targets = Array.from(rootElement.querySelectorAll(targetSelector));
|
|
237
250
|
targets.forEach((target) => {
|
|
238
251
|
const existing = snapshots.get(target);
|
|
@@ -256,7 +269,7 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
256
269
|
written = next;
|
|
257
270
|
},
|
|
258
271
|
restore() {
|
|
259
|
-
if (!
|
|
272
|
+
if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
|
|
260
273
|
written.forEach(restoreTarget);
|
|
261
274
|
written = new Set();
|
|
262
275
|
clearAnimation();
|
|
@@ -598,11 +611,11 @@ var StickyScrollTrigger = class {
|
|
|
598
611
|
#captureScrollTriggerClass(self) {
|
|
599
612
|
this.#scrollTriggerClass = self.constructor;
|
|
600
613
|
}
|
|
601
|
-
#createAutoRefreshHandler(
|
|
614
|
+
#createAutoRefreshHandler(userOnRefreshInit) {
|
|
602
615
|
return (self) => {
|
|
603
616
|
this.#captureScrollTriggerClass(self);
|
|
604
617
|
const result = userOnRefreshInit?.(self);
|
|
605
|
-
|
|
618
|
+
this.refresh();
|
|
606
619
|
return result;
|
|
607
620
|
};
|
|
608
621
|
}
|
|
@@ -615,6 +628,13 @@ var StickyScrollTrigger = class {
|
|
|
615
628
|
layer.inner = wrapped.inner;
|
|
616
629
|
});
|
|
617
630
|
}
|
|
631
|
+
#unwrapPinLayer(layer) {
|
|
632
|
+
if (!layer.outer) return false;
|
|
633
|
+
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
634
|
+
layer.outer = null;
|
|
635
|
+
layer.inner = null;
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
618
638
|
#resetSceneCoverStickyState() {
|
|
619
639
|
const wrapperSnapshots = this.#layers.map((layer) => layer.wrapper).filter((wrapper) => wrapper !== null).map((wrapper) => ({
|
|
620
640
|
wrapper,
|
|
@@ -720,12 +740,29 @@ var StickyScrollTrigger = class {
|
|
|
720
740
|
this.#unbuild();
|
|
721
741
|
this.#build();
|
|
722
742
|
}
|
|
723
|
-
this.#
|
|
743
|
+
this.#restoreCoverLifts();
|
|
744
|
+
try {
|
|
745
|
+
this.#wrapUnwrappedPins();
|
|
746
|
+
} finally {
|
|
747
|
+
this.#liftCovers();
|
|
748
|
+
}
|
|
724
749
|
const viewportHeight = this.#layers.length || this.#pinLayers.length ? measureViewportHeight() : 0;
|
|
725
750
|
this.#refreshScenesAndCovers(viewportHeight);
|
|
726
751
|
this.#refreshPins(viewportHeight);
|
|
727
752
|
this.#syncScrollMargins();
|
|
728
753
|
}
|
|
754
|
+
#coverLayers() {
|
|
755
|
+
return this.#layers.filter((layer) => layer.kind === "cover");
|
|
756
|
+
}
|
|
757
|
+
#restoreCoverLifts() {
|
|
758
|
+
this.#coverLayers().forEach((layer) => this.#coverRestoreByLayer.get(layer)?.());
|
|
759
|
+
}
|
|
760
|
+
#liftCovers() {
|
|
761
|
+
this.#coverLayers().forEach((layer) => {
|
|
762
|
+
const pin = this.#pinLayers.find(({ trigger }) => trigger === layer.cover);
|
|
763
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(pin?.outer ?? layer.cover));
|
|
764
|
+
});
|
|
765
|
+
}
|
|
729
766
|
#syncScrollMargins() {
|
|
730
767
|
this.#scrollMarginSync.sync(this.#layers.filter((layer) => layer.kind === "scene").map(({ trigger, freezeStart, freezeEnd }) => ({
|
|
731
768
|
trigger,
|
|
@@ -770,7 +807,7 @@ var StickyScrollTrigger = class {
|
|
|
770
807
|
this.#scheduleRebuild();
|
|
771
808
|
onKill?.(self);
|
|
772
809
|
},
|
|
773
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
810
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
774
811
|
};
|
|
775
812
|
}
|
|
776
813
|
createStickyTrigger({ trigger: triggerInput, start = "0 0", end = "100% 0", endTrigger: endTriggerInput, onKill, ...rest }) {
|
|
@@ -811,11 +848,10 @@ var StickyScrollTrigger = class {
|
|
|
811
848
|
freezeEnd: 0
|
|
812
849
|
};
|
|
813
850
|
const vars = this.#registerLayer(layer, (self) => {
|
|
814
|
-
|
|
851
|
+
this.#coverRestoreByLayer.get(layer)?.();
|
|
815
852
|
onKill?.(self);
|
|
816
853
|
}, rest);
|
|
817
|
-
|
|
818
|
-
this.#coverRestoreByLayer.set(layer, restoreCoverStyles);
|
|
854
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
819
855
|
return vars;
|
|
820
856
|
}
|
|
821
857
|
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "top top", onKill, ...rest }) {
|
|
@@ -844,14 +880,10 @@ var StickyScrollTrigger = class {
|
|
|
844
880
|
this.#captureScrollTriggerClass(self);
|
|
845
881
|
const index = this.#pinLayers.indexOf(layer);
|
|
846
882
|
if (index !== -1) this.#pinLayers.splice(index, 1);
|
|
847
|
-
if (layer
|
|
848
|
-
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
849
|
-
layer.outer = null;
|
|
850
|
-
layer.inner = null;
|
|
851
|
-
}
|
|
883
|
+
if (this.#unwrapPinLayer(layer)) this.#scheduleRebuild();
|
|
852
884
|
onKill?.(self);
|
|
853
885
|
},
|
|
854
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
886
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
855
887
|
};
|
|
856
888
|
}
|
|
857
889
|
resolveScrollPosition(elementInput, position) {
|
|
@@ -893,15 +925,11 @@ var StickyScrollTrigger = class {
|
|
|
893
925
|
if (this.#destroyed) return;
|
|
894
926
|
this.#destroyed = true;
|
|
895
927
|
this.#scrollMarginSync.restore();
|
|
896
|
-
this.#
|
|
897
|
-
if (layer.kind === "cover") this.#coverRestoreByLayer.get(layer)?.();
|
|
898
|
-
});
|
|
928
|
+
this.#restoreCoverLifts();
|
|
899
929
|
this.#unbuild();
|
|
900
930
|
this.#layers.length = 0;
|
|
901
931
|
this.#builtLayers = [];
|
|
902
|
-
this.#pinLayers.forEach((layer) =>
|
|
903
|
-
if (layer.outer) unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
904
|
-
});
|
|
932
|
+
this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
|
|
905
933
|
this.#pinLayers.length = 0;
|
|
906
934
|
}
|
|
907
935
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.7.0
|
|
4
4
|
* Copyright (c) 2026 Kuninori Ogino
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
* https://github.com/kuninori-ogino/sticky-scroll-trigger
|
|
7
7
|
*/
|
|
8
|
-
const e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},c=e=>{e.style.position=``,e.style.top=``},l=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},u=e=>({position:e.style.position,top:e.style.top}),d=(e,t)=>{e.style.position=t.position,e.style.top=t.top},f=e=>{if(!e.parentNode)throw Error(`StickyScrollTrigger: ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`),i=document.createElement(`div`);return i.setAttribute(`aria-hidden`,`true`),i.style.pointerEvents=`none`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),t.appendChild(i),{container:t,wrapper:n,padding:i}},p=e=>{let t=e.parentNode;if(!t)throw Error(`createOverlapScroll: trigger ${r(e)} is not attached to the document`);let n=document.createElement(`div`);for(t.insertBefore(n,t.firstChild);n.nextSibling;){let t=n.nextSibling;if(n.appendChild(t),t===e)break}return n},m=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},h=e=>{if(!e.parentNode)throw Error(`createStickyPin: trigger ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`);return t.style.height=`0`,t.style.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},g=(e,t,n)=>{let r=e.parentNode;d(t,n),r&&r.insertBefore(t,e),e.remove()},_=new WeakMap,v=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=_.get(n);if(e)e.count+=1;else{let e=getComputedStyle(n),t={count:1,position:n.style.position,zIndex:n.style.zIndex};e.position===`static`&&(n.style.position=`relative`),e.zIndex===`auto`&&(n.style.zIndex=`1`),_.set(n,t)}t.push(n)}return()=>{t.forEach(e=>{let t=_.get(e);t&&(--t.count,!(t.count>0)&&(e.style.position=t.position,e.style.zIndex=t.zIndex,_.delete(e)))}),t.length=0}};let y=0;const b=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),x=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},S=e=>{let t=`sst${y++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};b||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i?.remove(),i=null,a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),b||(o=h,c=p,l()),i||(i=document.createElement(`style`),document.head.appendChild(i)),i.textContent=x(t,h);let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){b||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},C=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},w=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},T=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},E=e=>typeof e==`function`?e():e,D={top:0,center:.5,bottom:1},O=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},k=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,A=(e,t)=>{let n=k.exec(e);if(!n||!n[1]&&!n[3])throw L.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in D,l=i===`%`;return{fraction:c?D[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?O(a,o,s,t):0)}},j=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),M=e=>typeof e==`number`?e:Number(e),N=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=A(i,t),s=A(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},P=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,F=e=>typeof e==`string`&&P.test(e.trim()),I=(e,t)=>{let n=P.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return O(void 0,r,i,t)},L=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?O(r,i,a,t):0},B=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},V=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+B(e,s,a,l.end.rawTop,u):t}let r=N(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},H=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=V(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=V(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},U=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],W=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(F(a))return{mode:`dwell`,distancePx:Math.max(0,I(a,t))};if(j(a))return{mode:`absolute`,value:M(a)};if(R(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:z(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},G=(e,t,n,i)=>{if(!j(t))return{mode:`clause`,anchorOffset:N(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:M(t)}},K=(e,t,n,r,a)=>{let o=E(n.start),s=n.end===null?null:E(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=W(e,t,n,s,r,u),f=G(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},q=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},J=(e,t)=>e.some(e=>e.trigger===t);var Y=class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=S(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(T(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=w(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e,t,n){return r=>{this.#g(r);let i=n?.(r);return e[0]===t&&this.refresh(),i}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#b(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#x(e){if(!this.#u.length)return;let t=this.#y(),n=this.#b();try{this.#S(e)}catch(e){throw n(),e}finally{t()}}#S(e){this.#u.forEach(t=>{if(!t.inner)return;let n=E(t.end);if(R(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=E(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(j(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=N(r,o,e),c=(j(n)?M(n):i(t.endTrigger)-N(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#C(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#y();try{this.#w(e,t)}catch(e){throw n(),e}}#w(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>K(this.#e,e,t,n,r)),s=0,c=()=>H(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||C(this.#t))&&(this.#p(),this.#m()),this.#v();let e=this.#t.length||this.#u.length?a():0;this.#C(e),this.#x(e),this.#T()}#T(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#E(e,t){let n=U.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#D(e,t,n){if(J(e,t))throw Error(n)}#O(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#k(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#A(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#D(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#D(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(this.#t,e,n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#E(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#O(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#A({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#E(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#O(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#A(p,e=>{h(),c?.(e)},l),h=v(f);return this.#r.set(p,h),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#E(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#k(l,`createStickyPin`),this.#D(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#D(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:q(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),f.outer&&(g(f.outer,f.trigger,f.savedPosition),f.outer=null,f.inner=null),s?.(e)},onRefreshInit:this.#_(this.#u,f,c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=E(n),l=a();if(R(c))return o(l)+z(c,l);if(j(c))return M(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=N(c,r.offsetHeight,l),f=this.#y(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#E(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#t.forEach(e=>{e.kind===`cover`&&this.#r.get(e)?.()}),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>{e.outer&&g(e.outer,e.trigger,e.savedPosition)}),this.#u.length=0)}};export{Y as default};
|
|
8
|
+
const e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},c=e=>{e.style.position=``,e.style.top=``},l=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},u=e=>({position:e.style.position,top:e.style.top}),d=(e,t)=>{e.style.position=t.position,e.style.top=t.top},f=e=>{if(!e.parentNode)throw Error(`StickyScrollTrigger: ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`),i=document.createElement(`div`);return i.setAttribute(`aria-hidden`,`true`),i.style.pointerEvents=`none`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),t.appendChild(i),{container:t,wrapper:n,padding:i}},p=e=>{let t=e.parentNode;if(!t)throw Error(`createOverlapScroll: trigger ${r(e)} is not attached to the document`);let n=document.createElement(`div`);for(t.insertBefore(n,t.firstChild);n.nextSibling;){let t=n.nextSibling;if(n.appendChild(t),t===e)break}return n},m=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},h=e=>{if(!e.parentNode)throw Error(`createStickyPin: trigger ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`);return t.style.height=`0`,t.style.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},g=(e,t,n)=>{let r=e.parentNode;d(t,n),r&&r.insertBefore(t,e),e.remove()},_={position:`relative`,zIndex:`1`},v=new WeakMap,y=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=v.get(e);if(r)r.count+=1;else{let t=getComputedStyle(e),n=[];t.position===`static`&&n.push(`position`),t.zIndex===`auto`&&n.push(`zIndex`),n.forEach(t=>{e.style[t]=_[t]}),v.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=v.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===_[t]&&(e.style[t]=``)}),v.delete(e)))}),t.length=0}};let b=0;const x=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),S=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),C=x&&S,w=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},T=e=>{let t=`sst${b++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};C||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i&&=(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(e=>e!==i),null),a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),C?(i||(i=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,i]),i.replaceSync(w(t,h))):(o=h,c=p,l());let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){C||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},E=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},D=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},O=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},k=e=>typeof e==`function`?e():e,A={top:0,center:.5,bottom:1},j=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},M=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,N=(e,t)=>{let n=M.exec(e);if(!n||!n[1]&&!n[3])throw B.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in A,l=i===`%`;return{fraction:c?A[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?j(a,o,s,t):0)}},P=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),F=e=>typeof e==`number`?e:Number(e),I=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=N(i,t),s=N(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},L=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return j(void 0,r,i,t)},B=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,V=e=>typeof e==`string`&&B.test(e.trim()),H=(e,t)=>{let n=B.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?j(r,i,a,t):0},U=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},W=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+U(e,s,a,l.end.rawTop,u):t}let r=I(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},G=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=W(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=W(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},K=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],q=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(R(a))return{mode:`dwell`,distancePx:Math.max(0,z(a,t))};if(P(a))return{mode:`absolute`,value:F(a)};if(V(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:H(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},J=(e,t,n,i)=>{if(!P(t))return{mode:`clause`,anchorOffset:I(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:F(t)}},Y=(e,t,n,r,a)=>{let o=k(n.start),s=n.end===null?null:k(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=q(e,t,n,s,r,u),f=J(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},X=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},Z=(e,t)=>e.some(e=>e.trigger===t);var Q=class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=T(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(O(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=D(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e){return t=>{this.#g(t);let n=e?.(t);return this.refresh(),n}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(e){return e.outer?(g(e.outer,e.trigger,e.savedPosition),e.outer=null,e.inner=null,!0):!1}#b(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#x(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#S(e){if(!this.#u.length)return;let t=this.#b(),n=this.#x();try{this.#C(e)}catch(e){throw n(),e}finally{t()}}#C(e){this.#u.forEach(t=>{if(!t.inner)return;let n=k(t.end);if(V(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=k(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(P(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=I(r,o,e),c=(P(n)?F(n):i(t.endTrigger)-I(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#w(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#b();try{this.#T(e,t)}catch(e){throw n(),e}}#T(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>Y(this.#e,e,t,n,r)),s=0,c=()=>G(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||E(this.#t))&&(this.#p(),this.#m()),this.#D();try{this.#v()}finally{this.#O()}let e=this.#t.length||this.#u.length?a():0;this.#w(e),this.#S(e),this.#k()}#E(){return this.#t.filter(e=>e.kind===`cover`)}#D(){this.#E().forEach(e=>this.#r.get(e)?.())}#O(){this.#E().forEach(e=>{let t=this.#u.find(({trigger:t})=>t===e.cover);this.#r.set(e,y(t?.outer??e.cover))})}#k(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#A(e,t){let n=K.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#j(e,t,n){if(Z(e,t))throw Error(n)}#M(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#N(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#P(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#j(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#j(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#A(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#M(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#P({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#A(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#M(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#P(p,e=>{this.#r.get(p)?.(),c?.(e)},l);return this.#r.set(p,y(f)),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#A(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#N(l,`createStickyPin`),this.#j(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#j(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:X(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),this.#y(f)&&this.#h(),s?.(e)},onRefreshInit:this.#_(c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=k(n),l=a();if(V(c))return o(l)+H(c,l);if(P(c))return F(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=I(c,r.offsetHeight,l),f=this.#b(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#A(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#D(),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#y(e)),this.#u.length=0)}};export{Q as default};
|