sticky-scroll-trigger 0.5.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
|
|
@@ -168,15 +170,71 @@ You can specify `onKill`, `invalidateOnRefresh`, and `onRefreshInit`; the module
|
|
|
168
170
|
|
|
169
171
|
Registers an overlap-scroll effect (`trigger` gets pinned while its siblings from `cover` onward scroll normally and rise up to cover it) and returns `ScrollTrigger.Vars`. No tween or dwell spacer is created. Since the return value only describes the freeze window, the effect works even without passing it to `ScrollTrigger.create()`, unless you need `markers` or callbacks.
|
|
170
172
|
|
|
171
|
-
| option | default | description
|
|
172
|
-
| ------------ | ---------------------------- |
|
|
173
|
-
| `trigger` | (required) | The element that gets pinned and covered. Must be inside the shared container,
|
|
174
|
-
| `cover` | `trigger.nextElementSibling` | The first element of the covering side; this and all following siblings cover together. Must share the same parent as `trigger`
|
|
175
|
-
| `start` | `'bottom bottom'` | Pinned position of `trigger`. See [position syntax](#position-syntax). Unlike `createStickyTrigger`'s `start`, this doesn't support an absolute scroll position (a bare number): it throws instead
|
|
176
|
-
| `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
|
-
| `endTrigger` | `trigger` | Reference element when `end` uses position-clause syntax
|
|
173
|
+
| option | default | description |
|
|
174
|
+
| ------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
175
|
+
| `trigger` | (required) | The element that gets pinned and covered. Must be inside the shared container; throws otherwise. Its own parent, which doesn't have to be the container itself, bounds how far the rise can run (see below) |
|
|
176
|
+
| `cover` | `trigger.nextElementSibling` | The first element of the covering side; this and all following siblings cover together. Must share the same parent as `trigger` |
|
|
177
|
+
| `start` | `'bottom bottom'` | Pinned position of `trigger`. See [position syntax](#position-syntax). Unlike `createStickyTrigger`'s `start`, this doesn't support an absolute scroll position (a bare number): it throws instead |
|
|
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" |
|
|
179
|
+
| `endTrigger` | `trigger` | Reference element when `end` uses position-clause syntax |
|
|
180
|
+
|
|
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.
|
|
184
|
+
|
|
185
|
+
#### Room for the rise
|
|
186
|
+
|
|
187
|
+
Pinning here is plain `position:sticky`, and the browser keeps a sticky element stuck only until its containing block's bottom edge catches up with it. That containing block is `trigger`'s own parent, not the shared container:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
trigger's parent's bottom edge - trigger's bottom edge >= end - start
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
With the auto `end`, that distance is where `cover`'s top edge sits when the freeze starts: `start`'s pinned offset, plus `trigger`'s own height, plus any gap between the two. Under the defaults (`start: 'bottom bottom'`, `cover` directly after `trigger`) it comes to one viewport height; a `trigger` taller than the viewport, pinned near the top, needs more.
|
|
194
|
+
|
|
195
|
+
With less room than that, the browser releases the wrapper mid-rise: `trigger` scrolls away before `cover` has covered it, at a point that moves with the window size, since the requirement scales with the viewport while the room doesn't. Content after `trigger`'s parent never counts, however long the page is. Add the missing height below `trigger` (a taller `cover`, or a spacer after it), or keep the sections that follow inside the same parent rather than wrapping `trigger` and `cover` in a box of their own.
|
|
196
|
+
|
|
197
|
+
#### Delaying the rise
|
|
198
|
+
|
|
199
|
+
`cover` starts rising as soon as the freeze window opens, so a scrubbed effect on `trigger` plays out underneath it. To let the effect finish first, put a Scene layer in front of the cover layer: freezing one freezes the whole shared container, `cover` included, and the scene's dwell doubles as the hold. Since the two layers can't share a trigger element, the cover layer gets a zero-height marker between the scene and `cover`:
|
|
200
|
+
|
|
201
|
+
```html
|
|
202
|
+
<div class="container__inner">
|
|
203
|
+
<section class="scene">...</section>
|
|
204
|
+
<div class="hold" style="height: 0"></div>
|
|
205
|
+
<section class="cover">...</section>
|
|
206
|
+
</div>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
gsap.fromTo(
|
|
211
|
+
".scene",
|
|
212
|
+
{ opacity: 0 },
|
|
213
|
+
{
|
|
214
|
+
opacity: 1,
|
|
215
|
+
scrollTrigger: sticky.createStickyTrigger({
|
|
216
|
+
trigger: ".scene",
|
|
217
|
+
start: "bottom bottom",
|
|
218
|
+
end: "+=800",
|
|
219
|
+
scrub: true,
|
|
220
|
+
}),
|
|
221
|
+
},
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
ScrollTrigger.create(
|
|
225
|
+
sticky.createOverlapScroll({
|
|
226
|
+
trigger: ".hold",
|
|
227
|
+
cover: ".cover",
|
|
228
|
+
start: "bottom bottom",
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
```
|
|
178
232
|
|
|
179
|
-
|
|
233
|
+
The rise picks up where the scrub ends, with no arithmetic on your side, because `refresh()` adds a Scene layer's dwell to the freeze window of every layer whose trigger comes later in DOM order. That is also why the marker goes after the scene rather than inside it.
|
|
234
|
+
|
|
235
|
+
The marker sits on the scene's bottom edge, so one `'bottom bottom'` describes both layers and nothing moves at the handover. The scene pins with that edge on the viewport's bottom, and `cover`, which begins there, stays just off screen for the whole hold. Pin the scene anywhere else and you have to reconcile the two clauses by hand, since a zero-height marker resolves any clause to a plain viewport position. Its `start` has to name wherever the scene's bottom edge sits while pinned, or `trigger` jumps.
|
|
236
|
+
|
|
237
|
+
The marker is the cover layer's `trigger`, so [the room](#room-for-the-rise) the rise needs is measured below it, not below the scene.
|
|
180
238
|
|
|
181
239
|
### `createStickyPin(options)`
|
|
182
240
|
|
|
@@ -212,7 +270,7 @@ sticky.refresh();
|
|
|
212
270
|
|
|
213
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.
|
|
214
272
|
|
|
215
|
-
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.
|
|
216
274
|
|
|
217
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.
|
|
218
276
|
|
|
@@ -321,7 +379,7 @@ If surviving layers' freeze windows change after kill, GSAP's cached `start`/`en
|
|
|
321
379
|
|
|
322
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()`.
|
|
323
381
|
|
|
324
|
-
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.
|
|
325
383
|
|
|
326
384
|
## Same-page links
|
|
327
385
|
|
|
@@ -330,7 +388,7 @@ Pinning decouples an element's position in the document from the scroll position
|
|
|
330
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.
|
|
331
389
|
|
|
332
390
|
```html
|
|
333
|
-
<!--
|
|
391
|
+
<!-- Lands correctly with no click handler and no scroll math. -->
|
|
334
392
|
<a href="#chapter3">Chapter 3</a>
|
|
335
393
|
```
|
|
336
394
|
|
|
@@ -372,9 +430,13 @@ A px/% offset needs the `=` when it follows a keyword or number (`top+=50`, `80-
|
|
|
372
430
|
|
|
373
431
|
A trailing `px` (`top 100px`, `center+=50px`) is accepted and ignored, the same idea as GSAP's own `_offsetToPx`, which only special-cases `%` and otherwise passes the value through `parseFloat`. This module isn't as lenient as GSAP toward other unrecognized suffixes, though: an actually-unsupported unit like `top 100vh` still throws, rather than silently behaving like `top 100`.
|
|
374
432
|
|
|
433
|
+
The table above is the whole accepted grammar. GSAP's `clamp()` wrapper (`start: 'clamp(top center)'`, which holds the resolved position inside the scroller's own range) is not part of it and throws. Nothing clamps the freeze window either, so a clause that resolves past the top of the document keeps its negative value: a Scene layer sitting at the very start of the container with `start: 'top bottom'` begins one viewport height before scroll 0. `end` is the exception, already clamped to `start`.
|
|
434
|
+
|
|
435
|
+
GSAP passes the `ScrollTrigger` instance to its own function-valued `start`/`end` (`start: (self) => ...`), and this module doesn't, so a function declaring that parameter is a TypeScript error. There is nothing to pass: this module's `refresh()` resolves these functions, and it runs whether or not the returned `ScrollTrigger.Vars` was ever handed to `ScrollTrigger.create()`. `self.start`/`self.end` would be circular anyway, since the freeze window they report is what `refresh()` is in the middle of computing.
|
|
436
|
+
|
|
375
437
|
### Absolute scroll position
|
|
376
438
|
|
|
377
|
-
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`.
|
|
378
440
|
|
|
379
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, ...)`.
|
|
380
442
|
|
|
@@ -382,7 +444,7 @@ If the entire value is just a number (a plain JS number, or a string that's noth
|
|
|
382
444
|
|
|
383
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.
|
|
384
446
|
|
|
385
|
-
> [`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.
|
|
386
448
|
|
|
387
449
|
## End syntax
|
|
388
450
|
|
|
@@ -429,17 +491,19 @@ sticky.createOverlapScroll({
|
|
|
429
491
|
}); // pin until the very bottom of the page
|
|
430
492
|
```
|
|
431
493
|
|
|
432
|
-
`'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.
|
|
433
495
|
|
|
434
496
|
## Constraints and caveats
|
|
435
497
|
|
|
436
498
|
- The structure directly under the shared container changes because of the added wrapper elements. Direct-child selectors like `.container__inner > .scene`, `:nth-child()`, adjacent-sibling selectors (`+`/`~`), and flex/grid layout on the shared container itself may break across the wrapper boundary
|
|
437
499
|
- `position:sticky` doesn't work if any ancestor of the pinned target has `overflow:hidden`/`clip`
|
|
438
500
|
- `createOverlapScroll`'s `trigger` and `cover` must be siblings sharing the same parent
|
|
501
|
+
- That shared parent also caps how far `cover` can rise: it needs `end - start` worth of content below `trigger`, or the browser releases the wrapper mid-rise, at a point that shifts with the window size (see [Room for the rise](#room-for-the-rise))
|
|
439
502
|
- `createStickyTrigger` and `createOverlapScroll` throw if `trigger` isn't inside the shared container. Both build their structure inside it, so a `trigger` elsewhere would wrap, move and style elements the instance doesn't own
|
|
440
503
|
- `createStickyPin` works on either side of the container, and throws only for a `trigger` that encloses it (the container itself, or an ancestor). A pin wraps `trigger` in a `height:0`, `contain:layout` box, which would pull the container and the layers' dwell padding out of the flow
|
|
441
504
|
- Selector strings for `trigger`/`endTrigger`/`cover`/`element` resolve against the whole document, as GSAP's own `trigger` does, rather than within the shared container; only the `trigger` rules above restrict where a match may land. Validate or scope these values yourself if they come from content you don't control
|
|
442
505
|
- ScrollTrigger's `pin`/`pinSpacing`/`anticipatePin` can't be used (pinning is handled by sticky; these are already excluded at the type level)
|
|
506
|
+
- GSAP's `clamp()` position wrapper isn't accepted, and a function-valued `start`/`end` is called with no arguments rather than with the `ScrollTrigger` instance GSAP passes (see [Position syntax](#position-syntax))
|
|
443
507
|
- A `createStickyTrigger` Scene layer can't point `endTrigger` at a registered layer later in DOM order; `createOverlapScroll`'s cover layer can, since it adds no padding (see [End syntax](#end-syntax))
|
|
444
508
|
- If a Scene layer's `end` uses a position clause, don't set `endTrigger` to an element that gets pushed down by that same scene's own dwell; the value won't converge
|
|
445
509
|
- If several layers' unregistered or cover-layer `endTrigger`s form a dependency cycle, `refresh()` throws instead of settling on a wrong value
|
|
@@ -447,7 +511,7 @@ sticky.createOverlapScroll({
|
|
|
447
511
|
- Using the same element as the `trigger` of two different `createStickyTrigger`/`createOverlapScroll`/`createStickyPin` calls throws
|
|
448
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))
|
|
449
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
|
|
450
|
-
- `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))
|
|
451
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
|
|
452
516
|
|
|
453
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
|
|
@@ -66,6 +66,14 @@ var StickyScrollTrigger = (function() {
|
|
|
66
66
|
el.style.position = "sticky";
|
|
67
67
|
el.style.top = `${topPx}px`;
|
|
68
68
|
};
|
|
69
|
+
const captureInlinePosition = (el) => ({
|
|
70
|
+
position: el.style.position,
|
|
71
|
+
top: el.style.top
|
|
72
|
+
});
|
|
73
|
+
const restoreInlinePosition = (el, saved) => {
|
|
74
|
+
el.style.position = saved.position;
|
|
75
|
+
el.style.top = saved.top;
|
|
76
|
+
};
|
|
69
77
|
const wrapScene = (inner) => {
|
|
70
78
|
if (!inner.parentNode) throw new Error(`StickyScrollTrigger: ${describeElement(inner)} is not attached to the document`);
|
|
71
79
|
const container = document.createElement("div");
|
|
@@ -115,31 +123,38 @@ var StickyScrollTrigger = (function() {
|
|
|
115
123
|
inner
|
|
116
124
|
};
|
|
117
125
|
};
|
|
118
|
-
const unwrapPin = (outer, trigger) => {
|
|
126
|
+
const unwrapPin = (outer, trigger, saved) => {
|
|
119
127
|
const parent = outer.parentNode;
|
|
120
|
-
|
|
128
|
+
restoreInlinePosition(trigger, saved);
|
|
121
129
|
if (parent) parent.insertBefore(trigger, outer);
|
|
122
130
|
outer.remove();
|
|
123
131
|
};
|
|
132
|
+
const LIFT_VALUES = {
|
|
133
|
+
position: "relative",
|
|
134
|
+
zIndex: "1"
|
|
135
|
+
};
|
|
124
136
|
const liftStates = new WeakMap();
|
|
125
137
|
const liftAboveStickyWrapper = (cover) => {
|
|
126
138
|
const lifted = [];
|
|
127
139
|
for (let node = cover; node; node = node.nextElementSibling) {
|
|
128
140
|
if (!(node instanceof HTMLElement)) continue;
|
|
129
|
-
const
|
|
141
|
+
const element = node;
|
|
142
|
+
const existing = liftStates.get(element);
|
|
130
143
|
if (existing) existing.count += 1;
|
|
131
144
|
else {
|
|
132
|
-
const computed = getComputedStyle(
|
|
133
|
-
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, {
|
|
134
153
|
count: 1,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
};
|
|
138
|
-
if (computed.position === "static") node.style.position = "relative";
|
|
139
|
-
if (computed.zIndex === "auto") node.style.zIndex = "1";
|
|
140
|
-
liftStates.set(node, state);
|
|
154
|
+
applied
|
|
155
|
+
});
|
|
141
156
|
}
|
|
142
|
-
lifted.push(
|
|
157
|
+
lifted.push(element);
|
|
143
158
|
}
|
|
144
159
|
return () => {
|
|
145
160
|
lifted.forEach((el) => {
|
|
@@ -147,8 +162,9 @@ var StickyScrollTrigger = (function() {
|
|
|
147
162
|
if (!state) return;
|
|
148
163
|
state.count -= 1;
|
|
149
164
|
if (state.count > 0) return;
|
|
150
|
-
|
|
151
|
-
|
|
165
|
+
state.applied.forEach((property) => {
|
|
166
|
+
if (el.style[property] === LIFT_VALUES[property]) el.style[property] = "";
|
|
167
|
+
});
|
|
152
168
|
liftStates.delete(el);
|
|
153
169
|
});
|
|
154
170
|
lifted.length = 0;
|
|
@@ -157,6 +173,8 @@ var StickyScrollTrigger = (function() {
|
|
|
157
173
|
const OFFSET_PROPERTY = "--sst-scroll-margin-top-offset";
|
|
158
174
|
let nextInstanceSuffix = 0;
|
|
159
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;
|
|
160
178
|
const buildStylesheet = (instanceId, scenes) => {
|
|
161
179
|
const declarations = [];
|
|
162
180
|
const animations = [];
|
|
@@ -177,7 +195,7 @@ var StickyScrollTrigger = (function() {
|
|
|
177
195
|
const instanceId = `sst${nextInstanceSuffix++}`;
|
|
178
196
|
const snapshots = new WeakMap();
|
|
179
197
|
let written = new Set();
|
|
180
|
-
let
|
|
198
|
+
let sheet = null;
|
|
181
199
|
let animationHost = null;
|
|
182
200
|
let jsRamps = [];
|
|
183
201
|
let jsHost = null;
|
|
@@ -189,14 +207,16 @@ var StickyScrollTrigger = (function() {
|
|
|
189
207
|
jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
|
|
190
208
|
});
|
|
191
209
|
};
|
|
192
|
-
if (!
|
|
210
|
+
if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
|
|
193
211
|
const restoreTarget = (target) => {
|
|
194
212
|
const snapshot = snapshots.get(target);
|
|
195
213
|
target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
|
|
196
214
|
};
|
|
197
215
|
const clearAnimation = () => {
|
|
198
|
-
|
|
199
|
-
|
|
216
|
+
if (sheet) {
|
|
217
|
+
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((one) => one !== sheet);
|
|
218
|
+
sheet = null;
|
|
219
|
+
}
|
|
200
220
|
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
201
221
|
animationHost = null;
|
|
202
222
|
jsRamps = [];
|
|
@@ -216,16 +236,17 @@ var StickyScrollTrigger = (function() {
|
|
|
216
236
|
animationHost = host;
|
|
217
237
|
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
218
238
|
}
|
|
219
|
-
if (!
|
|
239
|
+
if (!usesCssRamp) {
|
|
220
240
|
jsRamps = ramps;
|
|
221
241
|
jsHost = host;
|
|
222
242
|
applyJsRamp();
|
|
243
|
+
} else {
|
|
244
|
+
if (!sheet) {
|
|
245
|
+
sheet = new CSSStyleSheet();
|
|
246
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
247
|
+
}
|
|
248
|
+
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
223
249
|
}
|
|
224
|
-
if (!styleElement) {
|
|
225
|
-
styleElement = document.createElement("style");
|
|
226
|
-
document.head.appendChild(styleElement);
|
|
227
|
-
}
|
|
228
|
-
styleElement.textContent = buildStylesheet(instanceId, ramps);
|
|
229
250
|
const targets = Array.from(rootElement.querySelectorAll(targetSelector));
|
|
230
251
|
targets.forEach((target) => {
|
|
231
252
|
const existing = snapshots.get(target);
|
|
@@ -249,7 +270,7 @@ var StickyScrollTrigger = (function() {
|
|
|
249
270
|
written = next;
|
|
250
271
|
},
|
|
251
272
|
restore() {
|
|
252
|
-
if (!
|
|
273
|
+
if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
|
|
253
274
|
written.forEach(restoreTarget);
|
|
254
275
|
written = new Set();
|
|
255
276
|
clearAnimation();
|
|
@@ -330,8 +351,14 @@ var StickyScrollTrigger = (function() {
|
|
|
330
351
|
return resolved.trim() !== "" && !Number.isNaN(Number(resolved));
|
|
331
352
|
};
|
|
332
353
|
const resolveAbsolute = (resolved) => typeof resolved === "number" ? resolved : Number(resolved);
|
|
354
|
+
const CLAMP_PREFIX = "clamp(";
|
|
333
355
|
const resolveAnchorTop = (position, elementHeight, viewportHeight) => {
|
|
334
|
-
const
|
|
356
|
+
const trimmed = position.trim();
|
|
357
|
+
if (trimmed.startsWith(CLAMP_PREFIX)) {
|
|
358
|
+
const inner = trimmed.slice(6).replace(/\)$/, "").trim();
|
|
359
|
+
throw new Error(`StickyScrollTrigger: unsupported position clause "${trimmed}": GSAP's clamp() wrapper isn't supported here.` + (inner ? ` Did you mean "${inner}"?` : ""));
|
|
360
|
+
}
|
|
361
|
+
const [elementToken, viewportToken = "top"] = trimmed.split(/\s+/);
|
|
335
362
|
const elementClause = parseClauseToken(elementToken, elementHeight);
|
|
336
363
|
const viewportClause = parseClauseToken(viewportToken, viewportHeight);
|
|
337
364
|
return viewportHeight * viewportClause.fraction + viewportClause.offsetPx - (elementHeight * elementClause.fraction + elementClause.offsetPx);
|
|
@@ -585,21 +612,30 @@ var StickyScrollTrigger = (function() {
|
|
|
585
612
|
#captureScrollTriggerClass(self) {
|
|
586
613
|
this.#scrollTriggerClass = self.constructor;
|
|
587
614
|
}
|
|
588
|
-
#createAutoRefreshHandler(
|
|
615
|
+
#createAutoRefreshHandler(userOnRefreshInit) {
|
|
589
616
|
return (self) => {
|
|
590
617
|
this.#captureScrollTriggerClass(self);
|
|
591
|
-
|
|
592
|
-
|
|
618
|
+
const result = userOnRefreshInit?.(self);
|
|
619
|
+
this.refresh();
|
|
620
|
+
return result;
|
|
593
621
|
};
|
|
594
622
|
}
|
|
595
623
|
#wrapUnwrappedPins() {
|
|
596
624
|
this.#pinLayers.forEach((layer) => {
|
|
597
625
|
if (layer.outer) return;
|
|
626
|
+
layer.savedPosition = captureInlinePosition(layer.trigger);
|
|
598
627
|
const wrapped = wrapPin(layer.trigger);
|
|
599
628
|
layer.outer = wrapped.outer;
|
|
600
629
|
layer.inner = wrapped.inner;
|
|
601
630
|
});
|
|
602
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
|
+
}
|
|
603
639
|
#resetSceneCoverStickyState() {
|
|
604
640
|
const wrapperSnapshots = this.#layers.map((layer) => layer.wrapper).filter((wrapper) => wrapper !== null).map((wrapper) => ({
|
|
605
641
|
wrapper,
|
|
@@ -614,20 +650,37 @@ var StickyScrollTrigger = (function() {
|
|
|
614
650
|
});
|
|
615
651
|
};
|
|
616
652
|
}
|
|
653
|
+
#resetPinState() {
|
|
654
|
+
const snapshots = this.#pinLayers.map((layer) => ({
|
|
655
|
+
layer,
|
|
656
|
+
position: captureInlinePosition(layer.trigger),
|
|
657
|
+
height: layer.inner ? layer.inner.style.height : ""
|
|
658
|
+
}));
|
|
659
|
+
snapshots.forEach(({ layer }) => {
|
|
660
|
+
resetStickyPosition(layer.trigger);
|
|
661
|
+
if (layer.inner) layer.inner.style.height = "";
|
|
662
|
+
});
|
|
663
|
+
return () => {
|
|
664
|
+
snapshots.forEach(({ layer, position, height }) => {
|
|
665
|
+
restoreInlinePosition(layer.trigger, position);
|
|
666
|
+
if (layer.inner) layer.inner.style.height = height;
|
|
667
|
+
});
|
|
668
|
+
};
|
|
669
|
+
}
|
|
617
670
|
#refreshPins(viewportHeight) {
|
|
618
671
|
if (!this.#pinLayers.length) return;
|
|
619
672
|
const restoreSceneCoverStickyState = this.#resetSceneCoverStickyState();
|
|
673
|
+
const restorePinState = this.#resetPinState();
|
|
620
674
|
try {
|
|
621
675
|
this.#refreshPinLayers(viewportHeight);
|
|
676
|
+
} catch (error) {
|
|
677
|
+
restorePinState();
|
|
678
|
+
throw error;
|
|
622
679
|
} finally {
|
|
623
680
|
restoreSceneCoverStickyState();
|
|
624
681
|
}
|
|
625
682
|
}
|
|
626
683
|
#refreshPinLayers(viewportHeight) {
|
|
627
|
-
this.#pinLayers.forEach((layer) => {
|
|
628
|
-
resetStickyPosition(layer.trigger);
|
|
629
|
-
if (layer.inner) layer.inner.style.height = "";
|
|
630
|
-
});
|
|
631
684
|
this.#pinLayers.forEach((layer) => {
|
|
632
685
|
if (!layer.inner) return;
|
|
633
686
|
const resolvedEnd = resolveMaybeFn(layer.end);
|
|
@@ -688,12 +741,29 @@ var StickyScrollTrigger = (function() {
|
|
|
688
741
|
this.#unbuild();
|
|
689
742
|
this.#build();
|
|
690
743
|
}
|
|
691
|
-
this.#
|
|
744
|
+
this.#restoreCoverLifts();
|
|
745
|
+
try {
|
|
746
|
+
this.#wrapUnwrappedPins();
|
|
747
|
+
} finally {
|
|
748
|
+
this.#liftCovers();
|
|
749
|
+
}
|
|
692
750
|
const viewportHeight = this.#layers.length || this.#pinLayers.length ? measureViewportHeight() : 0;
|
|
693
751
|
this.#refreshScenesAndCovers(viewportHeight);
|
|
694
752
|
this.#refreshPins(viewportHeight);
|
|
695
753
|
this.#syncScrollMargins();
|
|
696
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
|
+
}
|
|
697
767
|
#syncScrollMargins() {
|
|
698
768
|
this.#scrollMarginSync.sync(this.#layers.filter((layer) => layer.kind === "scene").map(({ trigger, freezeStart, freezeEnd }) => ({
|
|
699
769
|
trigger,
|
|
@@ -738,7 +808,7 @@ var StickyScrollTrigger = (function() {
|
|
|
738
808
|
this.#scheduleRebuild();
|
|
739
809
|
onKill?.(self);
|
|
740
810
|
},
|
|
741
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
811
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
742
812
|
};
|
|
743
813
|
}
|
|
744
814
|
createStickyTrigger({ trigger: triggerInput, start = "0 0", end = "100% 0", endTrigger: endTriggerInput, onKill, ...rest }) {
|
|
@@ -779,11 +849,10 @@ var StickyScrollTrigger = (function() {
|
|
|
779
849
|
freezeEnd: 0
|
|
780
850
|
};
|
|
781
851
|
const vars = this.#registerLayer(layer, (self) => {
|
|
782
|
-
|
|
852
|
+
this.#coverRestoreByLayer.get(layer)?.();
|
|
783
853
|
onKill?.(self);
|
|
784
854
|
}, rest);
|
|
785
|
-
|
|
786
|
-
this.#coverRestoreByLayer.set(layer, restoreCoverStyles);
|
|
855
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
787
856
|
return vars;
|
|
788
857
|
}
|
|
789
858
|
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "top top", onKill, ...rest }) {
|
|
@@ -797,6 +866,7 @@ var StickyScrollTrigger = (function() {
|
|
|
797
866
|
this.#assertTriggerAvailable(this.#layers, trigger, `StickyScrollTrigger: ${describeElement(trigger)} 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.`);
|
|
798
867
|
const layer = {
|
|
799
868
|
trigger,
|
|
869
|
+
savedPosition: captureInlinePosition(trigger),
|
|
800
870
|
outer: null,
|
|
801
871
|
inner: null,
|
|
802
872
|
start: top === void 0 ? start ?? "top top" : topToStartClause(top),
|
|
@@ -811,14 +881,10 @@ var StickyScrollTrigger = (function() {
|
|
|
811
881
|
this.#captureScrollTriggerClass(self);
|
|
812
882
|
const index = this.#pinLayers.indexOf(layer);
|
|
813
883
|
if (index !== -1) this.#pinLayers.splice(index, 1);
|
|
814
|
-
if (layer
|
|
815
|
-
unwrapPin(layer.outer, layer.trigger);
|
|
816
|
-
layer.outer = null;
|
|
817
|
-
layer.inner = null;
|
|
818
|
-
}
|
|
884
|
+
if (this.#unwrapPinLayer(layer)) this.#scheduleRebuild();
|
|
819
885
|
onKill?.(self);
|
|
820
886
|
},
|
|
821
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
887
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
822
888
|
};
|
|
823
889
|
}
|
|
824
890
|
resolveScrollPosition(elementInput, position) {
|
|
@@ -860,15 +926,11 @@ var StickyScrollTrigger = (function() {
|
|
|
860
926
|
if (this.#destroyed) return;
|
|
861
927
|
this.#destroyed = true;
|
|
862
928
|
this.#scrollMarginSync.restore();
|
|
863
|
-
this.#
|
|
864
|
-
if (layer.kind === "cover") this.#coverRestoreByLayer.get(layer)?.();
|
|
865
|
-
});
|
|
929
|
+
this.#restoreCoverLifts();
|
|
866
930
|
this.#unbuild();
|
|
867
931
|
this.#layers.length = 0;
|
|
868
932
|
this.#builtLayers = [];
|
|
869
|
-
this.#pinLayers.forEach((layer) =>
|
|
870
|
-
if (layer.outer) unwrapPin(layer.outer, layer.trigger);
|
|
871
|
-
});
|
|
933
|
+
this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
|
|
872
934
|
this.#pinLayers.length = 0;
|
|
873
935
|
}
|
|
874
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=>{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}},d=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},f=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},p=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}},m=(e,t)=>{let n=e.parentNode;c(t),n&&n.insertBefore(t,e),e.remove()},h=new WeakMap,g=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=h.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`),h.set(n,t)}t.push(n)}return()=>{t.forEach(e=>{let t=h.get(e);t&&(--t.count,!(t.count>0)&&(e.style.position=t.position,e.style.zIndex=t.zIndex,h.delete(e)))}),t.length=0}},_=0,v=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),y=(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(``)},b=e=>{let t=`sst${_++}`,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`)})};v||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}`,``)),v||(o=h,c=p,l()),i||(i=document.createElement(`style`),document.head.appendChild(i)),i.textContent=y(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 b=new Set(g);r.forEach(e=>{b.has(e)||u(e)}),r=b},restore(){v||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},x=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},S=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=d(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=u(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},C=(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&&f(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},w=e=>typeof e==`function`?e():e,T={top:0,center:.5,bottom:1},E=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},D=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,O=(e,t)=>{let n=D.exec(e);if(!n||!n[1]&&!n[3])throw F.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 T,l=i===`%`;return{fraction:c?T[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?E(a,o,s,t):0)}},k=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),A=e=>typeof e==`number`?e:Number(e),j=(e,t,n)=>{let[r,i=`top`]=e.trim().split(/\s+/),a=O(r,t),o=O(i,n);return n*o.fraction+o.offsetPx-(t*a.fraction+a.offsetPx)},M=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,N=e=>typeof e==`string`&&M.test(e.trim()),P=(e,t)=>{let n=M.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return E(void 0,r,i,t)},F=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,I=e=>typeof e==`string`&&F.test(e.trim()),L=(e,t)=>{let n=F.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?E(r,i,a,t):0},R=(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},z=(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+R(e,s,a,l.end.rawTop,u):t}let r=j(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}},B=(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}=z(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=z(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},V=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],H=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(N(a))return{mode:`dwell`,distancePx:Math.max(0,P(a,t))};if(k(a))return{mode:`absolute`,value:A(a)};if(I(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:L(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}},U=(e,t,n,i)=>{if(!k(t))return{mode:`clause`,anchorOffset:j(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:A(t)}},W=(e,t,n,r,a)=>{let o=w(n.start),s=n.end===null?null:w(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=H(e,t,n,s,r,u),f=U(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}},G=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)},K=(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=b(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&&=(C(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=S(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),e[0]===t&&this.refresh(),n?.(r)}}#v(){this.#u.forEach(e=>{if(e.outer)return;let t=p(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(e){if(!this.#u.length)return;let t=this.#y();try{this.#x(e)}finally{t()}}#x(e){this.#u.forEach(e=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),this.#u.forEach(t=>{if(!t.inner)return;let n=w(t.end);if(I(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=w(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(k(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=j(r,o,e),c=(k(n)?A(n):i(t.endTrigger)-j(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#S(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.#C(e,t)}catch(e){throw n(),e}}#C(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)=>W(this.#e,e,t,n,r)),s=0,c=()=>B(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||x(this.#t))&&(this.#p(),this.#m()),this.#v();let e=this.#t.length||this.#u.length?a():0;this.#S(e),this.#b(e),this.#w()}#w(){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)}#T(e,t){let n=V.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.`)}#E(e,t,n){if(K(e,t))throw Error(n)}#D(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.`)}#O(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.`)}#k(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#E(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.#E(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.#T(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#D(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#k({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.#T(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#D(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.#k(p,e=>{h(),c?.(e)},l),h=g(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.#T(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`),u=t(a,`createStickyPin`);this.#O(l,`createStickyPin`),this.#E(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#E(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 d={trigger:l,outer:null,inner:null,start:i===void 0?n??`top top`:G(i),endTrigger:u,end:o};return this.#u.push(d),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(d);t!==-1&&this.#u.splice(t,1),d.outer&&(m(d.outer,d.trigger),d.outer=null,d.inner=null),s?.(e)},onRefreshInit:this.#_(this.#u,d,c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=w(n),l=a();if(I(c))return o(l)+L(c,l);if(k(c))return A(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=j(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.#T(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&&m(e.outer,e.trigger)}),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
|
|
@@ -65,6 +65,14 @@ const applyStickyPosition = (el, topPx) => {
|
|
|
65
65
|
el.style.position = "sticky";
|
|
66
66
|
el.style.top = `${topPx}px`;
|
|
67
67
|
};
|
|
68
|
+
const captureInlinePosition = (el) => ({
|
|
69
|
+
position: el.style.position,
|
|
70
|
+
top: el.style.top
|
|
71
|
+
});
|
|
72
|
+
const restoreInlinePosition = (el, saved) => {
|
|
73
|
+
el.style.position = saved.position;
|
|
74
|
+
el.style.top = saved.top;
|
|
75
|
+
};
|
|
68
76
|
const wrapScene = (inner) => {
|
|
69
77
|
if (!inner.parentNode) throw new Error(`StickyScrollTrigger: ${describeElement(inner)} is not attached to the document`);
|
|
70
78
|
const container = document.createElement("div");
|
|
@@ -114,31 +122,38 @@ const wrapPin = (trigger) => {
|
|
|
114
122
|
inner
|
|
115
123
|
};
|
|
116
124
|
};
|
|
117
|
-
const unwrapPin = (outer, trigger) => {
|
|
125
|
+
const unwrapPin = (outer, trigger, saved) => {
|
|
118
126
|
const parent = outer.parentNode;
|
|
119
|
-
|
|
127
|
+
restoreInlinePosition(trigger, saved);
|
|
120
128
|
if (parent) parent.insertBefore(trigger, outer);
|
|
121
129
|
outer.remove();
|
|
122
130
|
};
|
|
131
|
+
const LIFT_VALUES = {
|
|
132
|
+
position: "relative",
|
|
133
|
+
zIndex: "1"
|
|
134
|
+
};
|
|
123
135
|
const liftStates = new WeakMap();
|
|
124
136
|
const liftAboveStickyWrapper = (cover) => {
|
|
125
137
|
const lifted = [];
|
|
126
138
|
for (let node = cover; node; node = node.nextElementSibling) {
|
|
127
139
|
if (!(node instanceof HTMLElement)) continue;
|
|
128
|
-
const
|
|
140
|
+
const element = node;
|
|
141
|
+
const existing = liftStates.get(element);
|
|
129
142
|
if (existing) existing.count += 1;
|
|
130
143
|
else {
|
|
131
|
-
const computed = getComputedStyle(
|
|
132
|
-
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, {
|
|
133
152
|
count: 1,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
if (computed.position === "static") node.style.position = "relative";
|
|
138
|
-
if (computed.zIndex === "auto") node.style.zIndex = "1";
|
|
139
|
-
liftStates.set(node, state);
|
|
153
|
+
applied
|
|
154
|
+
});
|
|
140
155
|
}
|
|
141
|
-
lifted.push(
|
|
156
|
+
lifted.push(element);
|
|
142
157
|
}
|
|
143
158
|
return () => {
|
|
144
159
|
lifted.forEach((el) => {
|
|
@@ -146,8 +161,9 @@ const liftAboveStickyWrapper = (cover) => {
|
|
|
146
161
|
if (!state) return;
|
|
147
162
|
state.count -= 1;
|
|
148
163
|
if (state.count > 0) return;
|
|
149
|
-
|
|
150
|
-
|
|
164
|
+
state.applied.forEach((property) => {
|
|
165
|
+
if (el.style[property] === LIFT_VALUES[property]) el.style[property] = "";
|
|
166
|
+
});
|
|
151
167
|
liftStates.delete(el);
|
|
152
168
|
});
|
|
153
169
|
lifted.length = 0;
|
|
@@ -156,6 +172,8 @@ const liftAboveStickyWrapper = (cover) => {
|
|
|
156
172
|
const OFFSET_PROPERTY = "--sst-scroll-margin-top-offset";
|
|
157
173
|
let nextInstanceSuffix = 0;
|
|
158
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;
|
|
159
177
|
const buildStylesheet = (instanceId, scenes) => {
|
|
160
178
|
const declarations = [];
|
|
161
179
|
const animations = [];
|
|
@@ -176,7 +194,7 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
176
194
|
const instanceId = `sst${nextInstanceSuffix++}`;
|
|
177
195
|
const snapshots = new WeakMap();
|
|
178
196
|
let written = new Set();
|
|
179
|
-
let
|
|
197
|
+
let sheet = null;
|
|
180
198
|
let animationHost = null;
|
|
181
199
|
let jsRamps = [];
|
|
182
200
|
let jsHost = null;
|
|
@@ -188,14 +206,16 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
188
206
|
jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
|
|
189
207
|
});
|
|
190
208
|
};
|
|
191
|
-
if (!
|
|
209
|
+
if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
|
|
192
210
|
const restoreTarget = (target) => {
|
|
193
211
|
const snapshot = snapshots.get(target);
|
|
194
212
|
target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
|
|
195
213
|
};
|
|
196
214
|
const clearAnimation = () => {
|
|
197
|
-
|
|
198
|
-
|
|
215
|
+
if (sheet) {
|
|
216
|
+
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((one) => one !== sheet);
|
|
217
|
+
sheet = null;
|
|
218
|
+
}
|
|
199
219
|
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
200
220
|
animationHost = null;
|
|
201
221
|
jsRamps = [];
|
|
@@ -215,16 +235,17 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
215
235
|
animationHost = host;
|
|
216
236
|
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
217
237
|
}
|
|
218
|
-
if (!
|
|
238
|
+
if (!usesCssRamp) {
|
|
219
239
|
jsRamps = ramps;
|
|
220
240
|
jsHost = host;
|
|
221
241
|
applyJsRamp();
|
|
242
|
+
} else {
|
|
243
|
+
if (!sheet) {
|
|
244
|
+
sheet = new CSSStyleSheet();
|
|
245
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
246
|
+
}
|
|
247
|
+
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
222
248
|
}
|
|
223
|
-
if (!styleElement) {
|
|
224
|
-
styleElement = document.createElement("style");
|
|
225
|
-
document.head.appendChild(styleElement);
|
|
226
|
-
}
|
|
227
|
-
styleElement.textContent = buildStylesheet(instanceId, ramps);
|
|
228
249
|
const targets = Array.from(rootElement.querySelectorAll(targetSelector));
|
|
229
250
|
targets.forEach((target) => {
|
|
230
251
|
const existing = snapshots.get(target);
|
|
@@ -248,7 +269,7 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
248
269
|
written = next;
|
|
249
270
|
},
|
|
250
271
|
restore() {
|
|
251
|
-
if (!
|
|
272
|
+
if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
|
|
252
273
|
written.forEach(restoreTarget);
|
|
253
274
|
written = new Set();
|
|
254
275
|
clearAnimation();
|
|
@@ -329,8 +350,14 @@ const isAbsoluteFormat = (resolved) => {
|
|
|
329
350
|
return resolved.trim() !== "" && !Number.isNaN(Number(resolved));
|
|
330
351
|
};
|
|
331
352
|
const resolveAbsolute = (resolved) => typeof resolved === "number" ? resolved : Number(resolved);
|
|
353
|
+
const CLAMP_PREFIX = "clamp(";
|
|
332
354
|
const resolveAnchorTop = (position, elementHeight, viewportHeight) => {
|
|
333
|
-
const
|
|
355
|
+
const trimmed = position.trim();
|
|
356
|
+
if (trimmed.startsWith(CLAMP_PREFIX)) {
|
|
357
|
+
const inner = trimmed.slice(6).replace(/\)$/, "").trim();
|
|
358
|
+
throw new Error(`StickyScrollTrigger: unsupported position clause "${trimmed}": GSAP's clamp() wrapper isn't supported here.` + (inner ? ` Did you mean "${inner}"?` : ""));
|
|
359
|
+
}
|
|
360
|
+
const [elementToken, viewportToken = "top"] = trimmed.split(/\s+/);
|
|
334
361
|
const elementClause = parseClauseToken(elementToken, elementHeight);
|
|
335
362
|
const viewportClause = parseClauseToken(viewportToken, viewportHeight);
|
|
336
363
|
return viewportHeight * viewportClause.fraction + viewportClause.offsetPx - (elementHeight * elementClause.fraction + elementClause.offsetPx);
|
|
@@ -584,21 +611,30 @@ var StickyScrollTrigger = class {
|
|
|
584
611
|
#captureScrollTriggerClass(self) {
|
|
585
612
|
this.#scrollTriggerClass = self.constructor;
|
|
586
613
|
}
|
|
587
|
-
#createAutoRefreshHandler(
|
|
614
|
+
#createAutoRefreshHandler(userOnRefreshInit) {
|
|
588
615
|
return (self) => {
|
|
589
616
|
this.#captureScrollTriggerClass(self);
|
|
590
|
-
|
|
591
|
-
|
|
617
|
+
const result = userOnRefreshInit?.(self);
|
|
618
|
+
this.refresh();
|
|
619
|
+
return result;
|
|
592
620
|
};
|
|
593
621
|
}
|
|
594
622
|
#wrapUnwrappedPins() {
|
|
595
623
|
this.#pinLayers.forEach((layer) => {
|
|
596
624
|
if (layer.outer) return;
|
|
625
|
+
layer.savedPosition = captureInlinePosition(layer.trigger);
|
|
597
626
|
const wrapped = wrapPin(layer.trigger);
|
|
598
627
|
layer.outer = wrapped.outer;
|
|
599
628
|
layer.inner = wrapped.inner;
|
|
600
629
|
});
|
|
601
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
|
+
}
|
|
602
638
|
#resetSceneCoverStickyState() {
|
|
603
639
|
const wrapperSnapshots = this.#layers.map((layer) => layer.wrapper).filter((wrapper) => wrapper !== null).map((wrapper) => ({
|
|
604
640
|
wrapper,
|
|
@@ -613,20 +649,37 @@ var StickyScrollTrigger = class {
|
|
|
613
649
|
});
|
|
614
650
|
};
|
|
615
651
|
}
|
|
652
|
+
#resetPinState() {
|
|
653
|
+
const snapshots = this.#pinLayers.map((layer) => ({
|
|
654
|
+
layer,
|
|
655
|
+
position: captureInlinePosition(layer.trigger),
|
|
656
|
+
height: layer.inner ? layer.inner.style.height : ""
|
|
657
|
+
}));
|
|
658
|
+
snapshots.forEach(({ layer }) => {
|
|
659
|
+
resetStickyPosition(layer.trigger);
|
|
660
|
+
if (layer.inner) layer.inner.style.height = "";
|
|
661
|
+
});
|
|
662
|
+
return () => {
|
|
663
|
+
snapshots.forEach(({ layer, position, height }) => {
|
|
664
|
+
restoreInlinePosition(layer.trigger, position);
|
|
665
|
+
if (layer.inner) layer.inner.style.height = height;
|
|
666
|
+
});
|
|
667
|
+
};
|
|
668
|
+
}
|
|
616
669
|
#refreshPins(viewportHeight) {
|
|
617
670
|
if (!this.#pinLayers.length) return;
|
|
618
671
|
const restoreSceneCoverStickyState = this.#resetSceneCoverStickyState();
|
|
672
|
+
const restorePinState = this.#resetPinState();
|
|
619
673
|
try {
|
|
620
674
|
this.#refreshPinLayers(viewportHeight);
|
|
675
|
+
} catch (error) {
|
|
676
|
+
restorePinState();
|
|
677
|
+
throw error;
|
|
621
678
|
} finally {
|
|
622
679
|
restoreSceneCoverStickyState();
|
|
623
680
|
}
|
|
624
681
|
}
|
|
625
682
|
#refreshPinLayers(viewportHeight) {
|
|
626
|
-
this.#pinLayers.forEach((layer) => {
|
|
627
|
-
resetStickyPosition(layer.trigger);
|
|
628
|
-
if (layer.inner) layer.inner.style.height = "";
|
|
629
|
-
});
|
|
630
683
|
this.#pinLayers.forEach((layer) => {
|
|
631
684
|
if (!layer.inner) return;
|
|
632
685
|
const resolvedEnd = resolveMaybeFn(layer.end);
|
|
@@ -687,12 +740,29 @@ var StickyScrollTrigger = class {
|
|
|
687
740
|
this.#unbuild();
|
|
688
741
|
this.#build();
|
|
689
742
|
}
|
|
690
|
-
this.#
|
|
743
|
+
this.#restoreCoverLifts();
|
|
744
|
+
try {
|
|
745
|
+
this.#wrapUnwrappedPins();
|
|
746
|
+
} finally {
|
|
747
|
+
this.#liftCovers();
|
|
748
|
+
}
|
|
691
749
|
const viewportHeight = this.#layers.length || this.#pinLayers.length ? measureViewportHeight() : 0;
|
|
692
750
|
this.#refreshScenesAndCovers(viewportHeight);
|
|
693
751
|
this.#refreshPins(viewportHeight);
|
|
694
752
|
this.#syncScrollMargins();
|
|
695
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
|
+
}
|
|
696
766
|
#syncScrollMargins() {
|
|
697
767
|
this.#scrollMarginSync.sync(this.#layers.filter((layer) => layer.kind === "scene").map(({ trigger, freezeStart, freezeEnd }) => ({
|
|
698
768
|
trigger,
|
|
@@ -737,7 +807,7 @@ var StickyScrollTrigger = class {
|
|
|
737
807
|
this.#scheduleRebuild();
|
|
738
808
|
onKill?.(self);
|
|
739
809
|
},
|
|
740
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
810
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
741
811
|
};
|
|
742
812
|
}
|
|
743
813
|
createStickyTrigger({ trigger: triggerInput, start = "0 0", end = "100% 0", endTrigger: endTriggerInput, onKill, ...rest }) {
|
|
@@ -778,11 +848,10 @@ var StickyScrollTrigger = class {
|
|
|
778
848
|
freezeEnd: 0
|
|
779
849
|
};
|
|
780
850
|
const vars = this.#registerLayer(layer, (self) => {
|
|
781
|
-
|
|
851
|
+
this.#coverRestoreByLayer.get(layer)?.();
|
|
782
852
|
onKill?.(self);
|
|
783
853
|
}, rest);
|
|
784
|
-
|
|
785
|
-
this.#coverRestoreByLayer.set(layer, restoreCoverStyles);
|
|
854
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
786
855
|
return vars;
|
|
787
856
|
}
|
|
788
857
|
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "top top", onKill, ...rest }) {
|
|
@@ -796,6 +865,7 @@ var StickyScrollTrigger = class {
|
|
|
796
865
|
this.#assertTriggerAvailable(this.#layers, trigger, `StickyScrollTrigger: ${describeElement(trigger)} 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.`);
|
|
797
866
|
const layer = {
|
|
798
867
|
trigger,
|
|
868
|
+
savedPosition: captureInlinePosition(trigger),
|
|
799
869
|
outer: null,
|
|
800
870
|
inner: null,
|
|
801
871
|
start: top === void 0 ? start ?? "top top" : topToStartClause(top),
|
|
@@ -810,14 +880,10 @@ var StickyScrollTrigger = class {
|
|
|
810
880
|
this.#captureScrollTriggerClass(self);
|
|
811
881
|
const index = this.#pinLayers.indexOf(layer);
|
|
812
882
|
if (index !== -1) this.#pinLayers.splice(index, 1);
|
|
813
|
-
if (layer
|
|
814
|
-
unwrapPin(layer.outer, layer.trigger);
|
|
815
|
-
layer.outer = null;
|
|
816
|
-
layer.inner = null;
|
|
817
|
-
}
|
|
883
|
+
if (this.#unwrapPinLayer(layer)) this.#scheduleRebuild();
|
|
818
884
|
onKill?.(self);
|
|
819
885
|
},
|
|
820
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
886
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
821
887
|
};
|
|
822
888
|
}
|
|
823
889
|
resolveScrollPosition(elementInput, position) {
|
|
@@ -859,15 +925,11 @@ var StickyScrollTrigger = class {
|
|
|
859
925
|
if (this.#destroyed) return;
|
|
860
926
|
this.#destroyed = true;
|
|
861
927
|
this.#scrollMarginSync.restore();
|
|
862
|
-
this.#
|
|
863
|
-
if (layer.kind === "cover") this.#coverRestoreByLayer.get(layer)?.();
|
|
864
|
-
});
|
|
928
|
+
this.#restoreCoverLifts();
|
|
865
929
|
this.#unbuild();
|
|
866
930
|
this.#layers.length = 0;
|
|
867
931
|
this.#builtLayers = [];
|
|
868
|
-
this.#pinLayers.forEach((layer) =>
|
|
869
|
-
if (layer.outer) unwrapPin(layer.outer, layer.trigger);
|
|
870
|
-
});
|
|
932
|
+
this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
|
|
871
933
|
this.#pinLayers.length = 0;
|
|
872
934
|
}
|
|
873
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=>{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}},d=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},f=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},p=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}},m=(e,t)=>{let n=e.parentNode;c(t),n&&n.insertBefore(t,e),e.remove()},h=new WeakMap,g=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=h.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`),h.set(n,t)}t.push(n)}return()=>{t.forEach(e=>{let t=h.get(e);t&&(--t.count,!(t.count>0)&&(e.style.position=t.position,e.style.zIndex=t.zIndex,h.delete(e)))}),t.length=0}};let _=0;const v=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),y=(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(``)},b=e=>{let t=`sst${_++}`,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`)})};v||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}`,``)),v||(o=h,c=p,l()),i||(i=document.createElement(`style`),document.head.appendChild(i)),i.textContent=y(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 b=new Set(g);r.forEach(e=>{b.has(e)||u(e)}),r=b},restore(){v||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},x=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},S=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=d(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=u(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},C=(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&&f(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},w=e=>typeof e==`function`?e():e,T={top:0,center:.5,bottom:1},E=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},D=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,O=(e,t)=>{let n=D.exec(e);if(!n||!n[1]&&!n[3])throw F.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 T,l=i===`%`;return{fraction:c?T[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?E(a,o,s,t):0)}},k=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),A=e=>typeof e==`number`?e:Number(e),j=(e,t,n)=>{let[r,i=`top`]=e.trim().split(/\s+/),a=O(r,t),o=O(i,n);return n*o.fraction+o.offsetPx-(t*a.fraction+a.offsetPx)},M=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,N=e=>typeof e==`string`&&M.test(e.trim()),P=(e,t)=>{let n=M.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return E(void 0,r,i,t)},F=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,I=e=>typeof e==`string`&&F.test(e.trim()),L=(e,t)=>{let n=F.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?E(r,i,a,t):0},R=(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},z=(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+R(e,s,a,l.end.rawTop,u):t}let r=j(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}},B=(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}=z(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=z(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},V=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],H=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(N(a))return{mode:`dwell`,distancePx:Math.max(0,P(a,t))};if(k(a))return{mode:`absolute`,value:A(a)};if(I(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:L(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}},U=(e,t,n,i)=>{if(!k(t))return{mode:`clause`,anchorOffset:j(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:A(t)}},W=(e,t,n,r,a)=>{let o=w(n.start),s=n.end===null?null:w(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=H(e,t,n,s,r,u),f=U(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}},G=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)},K=(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=b(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&&=(C(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=S(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),e[0]===t&&this.refresh(),n?.(r)}}#v(){this.#u.forEach(e=>{if(e.outer)return;let t=p(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(e){if(!this.#u.length)return;let t=this.#y();try{this.#x(e)}finally{t()}}#x(e){this.#u.forEach(e=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),this.#u.forEach(t=>{if(!t.inner)return;let n=w(t.end);if(I(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=w(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(k(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=j(r,o,e),c=(k(n)?A(n):i(t.endTrigger)-j(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#S(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.#C(e,t)}catch(e){throw n(),e}}#C(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)=>W(this.#e,e,t,n,r)),s=0,c=()=>B(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||x(this.#t))&&(this.#p(),this.#m()),this.#v();let e=this.#t.length||this.#u.length?a():0;this.#S(e),this.#b(e),this.#w()}#w(){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)}#T(e,t){let n=V.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.`)}#E(e,t,n){if(K(e,t))throw Error(n)}#D(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.`)}#O(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.`)}#k(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#E(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.#E(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.#T(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#D(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#k({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.#T(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#D(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.#k(p,e=>{h(),c?.(e)},l),h=g(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.#T(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`),u=t(a,`createStickyPin`);this.#O(l,`createStickyPin`),this.#E(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#E(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 d={trigger:l,outer:null,inner:null,start:i===void 0?n??`top top`:G(i),endTrigger:u,end:o};return this.#u.push(d),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(d);t!==-1&&this.#u.splice(t,1),d.outer&&(m(d.outer,d.trigger),d.outer=null,d.inner=null),s?.(e)},onRefreshInit:this.#_(this.#u,d,c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=w(n),l=a();if(I(c))return o(l)+L(c,l);if(k(c))return A(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=j(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.#T(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&&m(e.outer,e.trigger)}),this.#u.length=0)}};export{q 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};
|