sticky-scroll-trigger 0.6.0 → 0.8.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
|
|
@@ -145,6 +147,8 @@ Call them on the instance (`sticky.createStickyTrigger(...)`) rather than destru
|
|
|
145
147
|
|
|
146
148
|
Like `root`, every `trigger`/`endTrigger`/`cover` option below also accepts a CSS selector string (in addition to an `HTMLElement`), resolved via `document.querySelector`, the same as GSAP ScrollTrigger's own `trigger`/`endTrigger`. Throws an error if the selector matches no elements.
|
|
147
149
|
|
|
150
|
+
`trigger` is required by every method here, unlike GSAP's own: a plain ScrollTrigger can leave it out and take its range from `start`/`end` alone. Every method here either wraps `trigger` or measures from it, so there is nothing to work from without one.
|
|
151
|
+
|
|
148
152
|
### `createStickyTrigger(options)`
|
|
149
153
|
|
|
150
154
|
Registers a layer that pins a scene and advances its effect, and returns `ScrollTrigger.Vars`. Pass the return value as a tween's `scrollTrigger`. ScrollTrigger options (`scrub`, `markers`, `onUpdate`, etc.) pass through as-is, except for the exclusions in the table below.
|
|
@@ -176,7 +180,11 @@ Registers an overlap-scroll effect (`trigger` gets pinned while its siblings fro
|
|
|
176
180
|
| `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
181
|
| `endTrigger` | `trigger` | Reference element when `end` uses position-clause syntax |
|
|
178
182
|
|
|
179
|
-
`
|
|
183
|
+
`start` and `end` are the two defaults this module doesn't take from GSAP, which pins at `'top top'` and ends at `'bottom top'`. The rise needs `cover` to begin off screen: pinned at the viewport's top, a `trigger` shorter than the viewport leaves the covering side already showing underneath it. `'bottom bottom'` rests `trigger` against the viewport's bottom edge instead, and the auto `end` measures the rise from there.
|
|
184
|
+
|
|
185
|
+
`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.
|
|
186
|
+
|
|
187
|
+
Every [`refresh()`](#refresh) runs that check again over the covering side as it stands: it raises an element added since, and hands back a property your own CSS has turned on in the meantime. Where the covering side holds a `createStickyPin` `trigger`, the pin's own wrapper rises in its place and the pinned element is left alone.
|
|
180
188
|
|
|
181
189
|
#### Room for the rise
|
|
182
190
|
|
|
@@ -256,20 +264,24 @@ ScrollTrigger.create(
|
|
|
256
264
|
sticky.refresh();
|
|
257
265
|
```
|
|
258
266
|
|
|
259
|
-
| option | default
|
|
260
|
-
| ------------ |
|
|
261
|
-
| `trigger` | (required)
|
|
262
|
-
| `start` | `'top top'`
|
|
263
|
-
| `top` | `0`
|
|
264
|
-
| `endTrigger` |
|
|
265
|
-
| `end` | `'
|
|
267
|
+
| option | default | description |
|
|
268
|
+
| ------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
269
|
+
| `trigger` | (required) | The element to pin and show |
|
|
270
|
+
| `start` | `'top top'` | Where `trigger` lands in the viewport while pinned, in [position syntax](#position-syntax), so the element's own side counts too (`'bottom bottom'` rests it against the viewport's bottom edge) |
|
|
271
|
+
| `top` | `0` | A px distance from the viewport's top edge, as a plain number. `top: 20` is `start: 'top 20px'` |
|
|
272
|
+
| `endTrigger` | `trigger` | Reference element for releasing the pin |
|
|
273
|
+
| `end` | `'bottom top'` | Which clause of `endTrigger` releases the pin (standard GSAP [position syntax](#position-syntax)) |
|
|
266
274
|
|
|
267
275
|
Here `start` means only where the element sits while pinned, not when pinning begins, as it does for the other methods. Pinning begins the moment `trigger` reaches that position naturally, which is CSS's decision rather than a separate number to set, so a pin's position and the scroll position it engages at are one setting.
|
|
268
276
|
|
|
269
|
-
That's why `start` throws on an [absolute scroll position](#absolute-scroll-position) (`start: 20`, which GSAP reads as scroll position 20) instead of
|
|
277
|
+
That's why `start` throws on an [absolute scroll position](#absolute-scroll-position) (`start: 20`, which GSAP reads as scroll position 20) instead of silently treating it as a px distance. `top` is its own option for the same reason: with the bare-number slot reserved for GSAP's meaning, `'top 20px'` would otherwise be a pin's only way to say "20px below the top of the viewport". `end` does take an absolute scroll position (`end: 3000` releases at scroll 3000), since a release point is a real thing to ask for on the scroll axis.
|
|
270
278
|
|
|
271
279
|
Clauses resolve exactly as they do elsewhere, including the one-token forms that name the element's own side: `'top 20px'` puts the element's top 20px below the viewport's top edge, while `'20px'` puts it 20px above.
|
|
272
280
|
|
|
281
|
+
`endTrigger` and `end` both default to GSAP's own values. `'bottom top'` releases the pin once `endTrigger`'s bottom edge reaches the viewport's top edge, so naming an `endTrigger` and leaving `end` alone holds the pin for that element's own height past its top. Omit both and `trigger` pins against itself, held for its own height, the duration GSAP's `pin: true` gives.
|
|
282
|
+
|
|
283
|
+
`trigger` keeps its own space in the page: every [`refresh()`](#refresh) sizes its wrapper to `trigger`'s margin box, so registering a pin doesn't shorten the document or move what follows. The wrapping does change margin collapsing, though. `trigger`'s vertical margins stop at that wrapper instead of collapsing with its siblings', and no sizing can give that back, since the collapsing partner sits outside it. A `margin-bottom: 30px` above a `trigger` with `margin-top: 20px` occupies 30px unpinned and 50px pinned.
|
|
284
|
+
|
|
273
285
|
Internally, the element wrapping `trigger` renders beyond its own section's bounds, into the visual area of following elements. Make sure the ancestor section containing `trigger` isn't hidden behind a later section in DOM order (e.g. via `position: relative; z-index: ...`).
|
|
274
286
|
|
|
275
287
|
See the repository's `ARCHITECTURE.md` ("Why `createStickyPin` is unaffected by nested-sticky lag") for why the lag never applies here, and why `trigger` needs two nested wrapper divs.
|
|
@@ -292,12 +304,14 @@ gsap.to(plainBox, {
|
|
|
292
304
|
});
|
|
293
305
|
```
|
|
294
306
|
|
|
295
|
-
| option | default
|
|
296
|
-
| ------------ |
|
|
297
|
-
| `trigger` | (required)
|
|
298
|
-
| `start` |
|
|
299
|
-
| `end` |
|
|
300
|
-
| `endTrigger` | `trigger`
|
|
307
|
+
| option | default | description |
|
|
308
|
+
| ------------ | -------------- | ------------------------------------------------------------------------------------------ |
|
|
309
|
+
| `trigger` | (required) | Reference element for `start`. Also passed through as-is to GSAP's `scrollTrigger.trigger` |
|
|
310
|
+
| `start` | `'top bottom'` | [Position syntax](#position-syntax), resolved relative to `trigger` |
|
|
311
|
+
| `end` | `'bottom top'` | [Position syntax](#position-syntax), resolved relative to `endTrigger` |
|
|
312
|
+
| `endTrigger` | `trigger` | Reference element for `end` (same idea as GSAP's standard `trigger`/`endTrigger` split) |
|
|
313
|
+
|
|
314
|
+
Omit `start` and `end` and the range runs from `trigger`'s top edge entering the viewport at the bottom to `endTrigger`'s bottom edge leaving it at the top, GSAP's own defaults for a trigger that doesn't pin.
|
|
301
315
|
|
|
302
316
|
This does not register a layer, so `refresh()` does not manage it. It shares the same rejected-option table as [`createStickyTrigger`](#createstickytriggeroptions) (no pin-family options, no `horizontal`/`scroller`/`containerAnimation`).
|
|
303
317
|
|
|
@@ -375,7 +389,7 @@ If surviving layers' freeze windows change after kill, GSAP's cached `start`/`en
|
|
|
375
389
|
|
|
376
390
|
Tears down the controller, restores the original DOM layout, and reverts z-order changes from `createOverlapScroll`. This is also the only entry point that can clean up cover layers that were never passed to `ScrollTrigger.create()`.
|
|
377
391
|
|
|
378
|
-
It only cleans up DOM/styles managed by this module. You still need to kill active ScrollTrigger instances yourself. After `destroy()`, `createStickyTrigger
|
|
392
|
+
It only cleans up DOM/styles managed by this module. You still need to kill active ScrollTrigger instances yourself. After `destroy()`, `createStickyTrigger`, `createOverlapScroll` and `createStickyPin` throw and `refresh()` is a no-op. Calling `destroy()` twice is safe.
|
|
379
393
|
|
|
380
394
|
## Same-page links
|
|
381
395
|
|
|
@@ -384,7 +398,7 @@ Pinning decouples an element's position in the document from the scroll position
|
|
|
384
398
|
`refresh()` declares that difference to the browser by keeping `scroll-margin-top` in sync on every element inside the shared container that matches `scrollMarginTargets` (`'[id]'` by default). Nothing else is needed: plain `<a href="#target">` links, `scrollIntoView()`, `:target` and a `#hash` on load all land correctly as written.
|
|
385
399
|
|
|
386
400
|
```html
|
|
387
|
-
<!--
|
|
401
|
+
<!-- Lands correctly with no click handler and no scroll math. -->
|
|
388
402
|
<a href="#chapter3">Chapter 3</a>
|
|
389
403
|
```
|
|
390
404
|
|
|
@@ -432,7 +446,7 @@ GSAP passes the `ScrollTrigger` instance to its own function-valued `start`/`end
|
|
|
432
446
|
|
|
433
447
|
### Absolute scroll position
|
|
434
448
|
|
|
435
|
-
If the entire value is just a number (a plain JS number, or a string that's nothing but digits, with no keyword, second token, or `%`/`px` suffix), GSAP treats it as an absolute scroll position rather than a clause,
|
|
449
|
+
If the entire value is just a number (a plain JS number, or a string that's nothing but digits, with no keyword, second token, or `%`/`px` suffix), GSAP treats it as an absolute scroll position rather than a clause, and ignores the reference element entirely (`ScrollTrigger.js`'s `_parsePosition`: `isNaN(value) || (value = +value)`). This module follows the same rule for `start` and `end`, and for [`createStickyPin`](#createstickypinoptions)'s `end`, [`createResolvedTrigger`](#createresolvedtriggeroptions)'s `start`/`end`, and [`resolveScrollPosition`](#resolvescrollpositionelement-position)'s `position`.
|
|
436
450
|
|
|
437
451
|
`start: '500'` (or `start: 500`) freezes starting at absolute scroll position 500px, ignoring the trigger's natural position and any preceding dwell. `end: '500'` ends the freeze window at 500px the same way, clamped to `start` if that would put `end` before it, matching GSAP's own `end = Math.max(start, ...)`.
|
|
438
452
|
|
|
@@ -440,7 +454,7 @@ If the entire value is just a number (a plain JS number, or a string that's noth
|
|
|
440
454
|
|
|
441
455
|
> [`createOverlapScroll`](#createoverlapscrolloptions)'s `start` doesn't support absolute scroll positions: a cover layer's sticky position is always computed relative to its own wrapper (see the repository's `ARCHITECTURE.md`), which has no equivalent for one. It throws instead; use a position clause.
|
|
442
456
|
|
|
443
|
-
> [`createStickyPin`](#createstickypinoptions)'s `start` throws on one too, for a different reason than the cover layer above
|
|
457
|
+
> [`createStickyPin`](#createstickypinoptions)'s `start` throws on one too, for a different reason than the cover layer above. The scroll position a pin engages at follows from where it sits, so honoring an absolute value would mean inverting it back into a viewport position the caller never chose. A trigger 2000px down the document, asked to engage at scroll 500, would sit 1500px below the viewport's top edge, off-screen. Its `end` does take one.
|
|
444
458
|
|
|
445
459
|
## End syntax
|
|
446
460
|
|
|
@@ -448,7 +462,7 @@ If the entire value is just a number (a plain JS number, or a string that's noth
|
|
|
448
462
|
|
|
449
463
|
A bare number (or numeric string with no sign/`%`/`px`) is an absolute scroll position; see [Absolute scroll position](#absolute-scroll-position) above. `end` follows the same rule `start` uses, matching GSAP.
|
|
450
464
|
|
|
451
|
-
"Dwell distance": how many px to keep pinning after the freeze starts. Matching GSAP, only a string starting with the literal `'+='` prefix counts (or a `%`-suffixed `'+=...'`, resolved against the viewport height). A leading `-=`/`+`/`-` without `=`, or a `%` without `+=`, is a position clause instead (see below).
|
|
465
|
+
"Dwell distance": how many px to keep pinning after the freeze starts. Matching GSAP, only a string starting with the literal `'+='` prefix counts (or a `%`-suffixed `'+=...'`, resolved against the viewport height). A leading `-=`/`+`/`-` without `=`, or a `%` without `+=`, is a position clause instead (see below). A dwell `end` never consults `endTrigger`, again matching GSAP: the distance runs from wherever the freeze starts.
|
|
452
466
|
|
|
453
467
|
| example | meaning |
|
|
454
468
|
| -------------------------------- | ------------------------------------- |
|
|
@@ -487,7 +501,7 @@ sticky.createOverlapScroll({
|
|
|
487
501
|
}); // pin until the very bottom of the page
|
|
488
502
|
```
|
|
489
503
|
|
|
490
|
-
`'max'` is only supported by [`createOverlapScroll`](#createoverlapscrolloptions) and [`resolveScrollPosition`](#resolvescrollpositionelement-position)/[`createResolvedTrigger`](#createresolvedtriggeroptions). `createStickyTrigger` and `createStickyPin` throw on it, because their own dwell padding or pin spacer adds to the document height `'max'` measures: the freeze window would depend on itself, growing the page a little more on every `refresh()`. GSAP defines `'max'` for `end`, not `start
|
|
504
|
+
`'max'` is only supported by [`createOverlapScroll`](#createoverlapscrolloptions) and [`resolveScrollPosition`](#resolvescrollpositionelement-position)/[`createResolvedTrigger`](#createresolvedtriggeroptions). `createStickyTrigger` and `createStickyPin` throw on it, because their own dwell padding or pin spacer adds to the document height `'max'` measures: the freeze window would depend on itself, growing the page a little more on every `refresh()`. GSAP defines `'max'` for `end`, not `start`. In raw GSAP 3.15.0, `start: 'max'` silently resolves to `0` rather than the scroller's max, so this module rejects it for `start` instead of reproducing that.
|
|
491
505
|
|
|
492
506
|
## Constraints and caveats
|
|
493
507
|
|
|
@@ -496,7 +510,7 @@ sticky.createOverlapScroll({
|
|
|
496
510
|
- `createOverlapScroll`'s `trigger` and `cover` must be siblings sharing the same parent
|
|
497
511
|
- 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))
|
|
498
512
|
- `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
|
|
499
|
-
- `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
|
|
513
|
+
- `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 makes `trigger` itself `position:sticky` inside a box holding the pin range, which would pin the container and the layers' dwell padding along with it
|
|
500
514
|
- 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
|
|
501
515
|
- ScrollTrigger's `pin`/`pinSpacing`/`anticipatePin` can't be used (pinning is handled by sticky; these are already excluded at the type level)
|
|
502
516
|
- 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))
|
|
@@ -507,7 +521,7 @@ sticky.createOverlapScroll({
|
|
|
507
521
|
- Using the same element as the `trigger` of two different `createStickyTrigger`/`createOverlapScroll`/`createStickyPin` calls throws
|
|
508
522
|
- You must call `refresh()` once manually after registration. Window resize/load recomputation is automatically wired to GSAP's own `refreshInit`, but for layout changes that don't involve those (e.g. content height changes), call `ScrollTrigger.refresh()` yourself (see [Calling refresh](#calling-refresh))
|
|
509
523
|
- Resizes from mobile browsers showing/hiding their address bar are absorbed automatically (see the repository's `ARCHITECTURE.md`, "Two-pass position measurement"), but other causes like `visualViewport` zoom are not handled
|
|
510
|
-
- `refresh()` writes an inline `scroll-margin-top` on every element matching `scrollMarginTargets` inside the shared container, and
|
|
524
|
+
- `refresh()` writes an inline `scroll-margin-top` on every element matching `scrollMarginTargets` inside the shared container, and, on engines that drive the correction's ramps in CSS, adopts one stylesheet of its own per instance. That sheet is a constructed one, so a Content Security Policy needs no `style-src` exception for it. Both are undone by `destroy()`. Pass `scrollMarginTargets: null` to opt out (see [Same-page links](#same-page-links))
|
|
511
525
|
- Don't nest one `StickyScrollTrigger` instance's shared container inside another's: once a target sits inside more than one, [`getScrollTop`](#stickyscrolltriggergetscrolltopelement-instances)'s ownership check picks whichever instance is listed first, and neither instance's own dwell alone is actually correct for it
|
|
512
526
|
|
|
513
527
|
## License
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.8.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
|
|
@@ -17,8 +17,8 @@ export declare interface CreateOverlapScrollOptions extends PassThroughVars {
|
|
|
17
17
|
|
|
18
18
|
export declare interface CreateResolvedTriggerOptions extends PassThroughVars {
|
|
19
19
|
trigger: string | HTMLElement;
|
|
20
|
-
start
|
|
21
|
-
end
|
|
20
|
+
start?: PositionInput;
|
|
21
|
+
end?: PositionInput;
|
|
22
22
|
endTrigger?: string | HTMLElement;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -26,7 +26,7 @@ export declare interface CreateStickyPinOptions extends PassThroughVars {
|
|
|
26
26
|
trigger: string | HTMLElement;
|
|
27
27
|
start?: PositionInput;
|
|
28
28
|
top?: number | (() => number);
|
|
29
|
-
endTrigger
|
|
29
|
+
endTrigger?: string | HTMLElement;
|
|
30
30
|
end?: PositionInput;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.8.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
|
|
@@ -52,6 +52,7 @@ var StickyScrollTrigger = (function() {
|
|
|
52
52
|
const doc = document.documentElement;
|
|
53
53
|
return Math.max(0, (doc.scrollHeight || document.body.scrollHeight) - viewportHeight);
|
|
54
54
|
};
|
|
55
|
+
const measureUsedHeight = (el) => parseFloat(getComputedStyle(el).height) || 0;
|
|
55
56
|
const compareDocumentOrder = (a, b) => {
|
|
56
57
|
const position = a.compareDocumentPosition(b);
|
|
57
58
|
if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
@@ -113,7 +114,6 @@ var StickyScrollTrigger = (function() {
|
|
|
113
114
|
if (!trigger.parentNode) throw new Error(`createStickyPin: trigger ${describeElement(trigger)} is not attached to the document`);
|
|
114
115
|
const outer = document.createElement("div");
|
|
115
116
|
const inner = document.createElement("div");
|
|
116
|
-
outer.style.height = "0";
|
|
117
117
|
outer.style.contain = "layout";
|
|
118
118
|
trigger.parentNode.insertBefore(outer, trigger);
|
|
119
119
|
outer.appendChild(inner);
|
|
@@ -129,25 +129,32 @@ var StickyScrollTrigger = (function() {
|
|
|
129
129
|
if (parent) parent.insertBefore(trigger, outer);
|
|
130
130
|
outer.remove();
|
|
131
131
|
};
|
|
132
|
+
const LIFT_VALUES = {
|
|
133
|
+
position: "relative",
|
|
134
|
+
zIndex: "1"
|
|
135
|
+
};
|
|
132
136
|
const liftStates = new WeakMap();
|
|
133
137
|
const liftAboveStickyWrapper = (cover) => {
|
|
134
138
|
const lifted = [];
|
|
135
139
|
for (let node = cover; node; node = node.nextElementSibling) {
|
|
136
140
|
if (!(node instanceof HTMLElement)) continue;
|
|
137
|
-
const
|
|
141
|
+
const element = node;
|
|
142
|
+
const existing = liftStates.get(element);
|
|
138
143
|
if (existing) existing.count += 1;
|
|
139
144
|
else {
|
|
140
|
-
const computed = getComputedStyle(
|
|
141
|
-
const
|
|
145
|
+
const computed = getComputedStyle(element);
|
|
146
|
+
const applied = [];
|
|
147
|
+
if (computed.position === "static") applied.push("position");
|
|
148
|
+
if (computed.zIndex === "auto") applied.push("zIndex");
|
|
149
|
+
applied.forEach((property) => {
|
|
150
|
+
element.style[property] = LIFT_VALUES[property];
|
|
151
|
+
});
|
|
152
|
+
liftStates.set(element, {
|
|
142
153
|
count: 1,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
if (computed.position === "static") node.style.position = "relative";
|
|
147
|
-
if (computed.zIndex === "auto") node.style.zIndex = "1";
|
|
148
|
-
liftStates.set(node, state);
|
|
154
|
+
applied
|
|
155
|
+
});
|
|
149
156
|
}
|
|
150
|
-
lifted.push(
|
|
157
|
+
lifted.push(element);
|
|
151
158
|
}
|
|
152
159
|
return () => {
|
|
153
160
|
lifted.forEach((el) => {
|
|
@@ -155,8 +162,9 @@ var StickyScrollTrigger = (function() {
|
|
|
155
162
|
if (!state) return;
|
|
156
163
|
state.count -= 1;
|
|
157
164
|
if (state.count > 0) return;
|
|
158
|
-
|
|
159
|
-
|
|
165
|
+
state.applied.forEach((property) => {
|
|
166
|
+
if (el.style[property] === LIFT_VALUES[property]) el.style[property] = "";
|
|
167
|
+
});
|
|
160
168
|
liftStates.delete(el);
|
|
161
169
|
});
|
|
162
170
|
lifted.length = 0;
|
|
@@ -165,6 +173,8 @@ var StickyScrollTrigger = (function() {
|
|
|
165
173
|
const OFFSET_PROPERTY = "--sst-scroll-margin-top-offset";
|
|
166
174
|
let nextInstanceSuffix = 0;
|
|
167
175
|
const supportsScrollDrivenAnimations = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("animation-timeline", "scroll()");
|
|
176
|
+
const supportsConstructedStyleSheets = typeof CSSStyleSheet === "function" && typeof CSSStyleSheet.prototype.replaceSync === "function" && typeof document !== "undefined" && Array.isArray(document.adoptedStyleSheets);
|
|
177
|
+
const usesCssRamp = supportsScrollDrivenAnimations && supportsConstructedStyleSheets;
|
|
168
178
|
const buildStylesheet = (instanceId, scenes) => {
|
|
169
179
|
const declarations = [];
|
|
170
180
|
const animations = [];
|
|
@@ -185,7 +195,7 @@ var StickyScrollTrigger = (function() {
|
|
|
185
195
|
const instanceId = `sst${nextInstanceSuffix++}`;
|
|
186
196
|
const snapshots = new WeakMap();
|
|
187
197
|
let written = new Set();
|
|
188
|
-
let
|
|
198
|
+
let sheet = null;
|
|
189
199
|
let animationHost = null;
|
|
190
200
|
let jsRamps = [];
|
|
191
201
|
let jsHost = null;
|
|
@@ -197,14 +207,16 @@ var StickyScrollTrigger = (function() {
|
|
|
197
207
|
jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
|
|
198
208
|
});
|
|
199
209
|
};
|
|
200
|
-
if (!
|
|
210
|
+
if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
|
|
201
211
|
const restoreTarget = (target) => {
|
|
202
212
|
const snapshot = snapshots.get(target);
|
|
203
213
|
target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
|
|
204
214
|
};
|
|
205
215
|
const clearAnimation = () => {
|
|
206
|
-
|
|
207
|
-
|
|
216
|
+
if (sheet) {
|
|
217
|
+
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((one) => one !== sheet);
|
|
218
|
+
sheet = null;
|
|
219
|
+
}
|
|
208
220
|
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
209
221
|
animationHost = null;
|
|
210
222
|
jsRamps = [];
|
|
@@ -224,16 +236,17 @@ var StickyScrollTrigger = (function() {
|
|
|
224
236
|
animationHost = host;
|
|
225
237
|
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
226
238
|
}
|
|
227
|
-
if (!
|
|
239
|
+
if (!usesCssRamp) {
|
|
228
240
|
jsRamps = ramps;
|
|
229
241
|
jsHost = host;
|
|
230
242
|
applyJsRamp();
|
|
243
|
+
} else {
|
|
244
|
+
if (!sheet) {
|
|
245
|
+
sheet = new CSSStyleSheet();
|
|
246
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
247
|
+
}
|
|
248
|
+
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
231
249
|
}
|
|
232
|
-
if (!styleElement) {
|
|
233
|
-
styleElement = document.createElement("style");
|
|
234
|
-
document.head.appendChild(styleElement);
|
|
235
|
-
}
|
|
236
|
-
styleElement.textContent = buildStylesheet(instanceId, ramps);
|
|
237
250
|
const targets = Array.from(rootElement.querySelectorAll(targetSelector));
|
|
238
251
|
targets.forEach((target) => {
|
|
239
252
|
const existing = snapshots.get(target);
|
|
@@ -257,7 +270,7 @@ var StickyScrollTrigger = (function() {
|
|
|
257
270
|
written = next;
|
|
258
271
|
},
|
|
259
272
|
restore() {
|
|
260
|
-
if (!
|
|
273
|
+
if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
|
|
261
274
|
written.forEach(restoreTarget);
|
|
262
275
|
written = new Set();
|
|
263
276
|
clearAnimation();
|
|
@@ -549,6 +562,11 @@ var StickyScrollTrigger = (function() {
|
|
|
549
562
|
};
|
|
550
563
|
return typeof top === "function" ? () => toClause(top()) : toClause(top);
|
|
551
564
|
};
|
|
565
|
+
const resolvePinReleaseTop = (endTrigger, resolvedEnd, engageTop, viewportHeight) => {
|
|
566
|
+
if (isDwellFormat(resolvedEnd)) return engageTop + resolveDwell(resolvedEnd, viewportHeight);
|
|
567
|
+
if (isAbsoluteFormat(resolvedEnd)) return resolveAbsolute(resolvedEnd);
|
|
568
|
+
return documentTop(endTrigger) - resolveAnchorTop(resolvedEnd, endTrigger.offsetHeight, viewportHeight);
|
|
569
|
+
};
|
|
552
570
|
const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
|
|
553
571
|
var StickyScrollTrigger = class {
|
|
554
572
|
#rootElement;
|
|
@@ -599,11 +617,11 @@ var StickyScrollTrigger = (function() {
|
|
|
599
617
|
#captureScrollTriggerClass(self) {
|
|
600
618
|
this.#scrollTriggerClass = self.constructor;
|
|
601
619
|
}
|
|
602
|
-
#createAutoRefreshHandler(
|
|
620
|
+
#createAutoRefreshHandler(userOnRefreshInit) {
|
|
603
621
|
return (self) => {
|
|
604
622
|
this.#captureScrollTriggerClass(self);
|
|
605
623
|
const result = userOnRefreshInit?.(self);
|
|
606
|
-
|
|
624
|
+
this.refresh();
|
|
607
625
|
return result;
|
|
608
626
|
};
|
|
609
627
|
}
|
|
@@ -616,6 +634,31 @@ var StickyScrollTrigger = (function() {
|
|
|
616
634
|
layer.inner = wrapped.inner;
|
|
617
635
|
});
|
|
618
636
|
}
|
|
637
|
+
#reservePinSpace() {
|
|
638
|
+
const wrapped = this.#pinLayers.flatMap(({ outer, inner }) => outer && inner ? [{
|
|
639
|
+
outer,
|
|
640
|
+
inner,
|
|
641
|
+
range: inner.style.height
|
|
642
|
+
}] : []);
|
|
643
|
+
wrapped.forEach(({ outer, inner }) => {
|
|
644
|
+
outer.style.height = "";
|
|
645
|
+
inner.style.height = "";
|
|
646
|
+
});
|
|
647
|
+
const reserved = wrapped.map(({ outer }) => measureUsedHeight(outer));
|
|
648
|
+
wrapped.forEach(({ outer }, index) => {
|
|
649
|
+
outer.style.height = `${reserved[index]}px`;
|
|
650
|
+
});
|
|
651
|
+
wrapped.forEach(({ inner, range }) => {
|
|
652
|
+
inner.style.height = range;
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
#unwrapPinLayer(layer) {
|
|
656
|
+
if (!layer.outer) return false;
|
|
657
|
+
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
658
|
+
layer.outer = null;
|
|
659
|
+
layer.inner = null;
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
619
662
|
#resetSceneCoverStickyState() {
|
|
620
663
|
const wrapperSnapshots = this.#layers.map((layer) => layer.wrapper).filter((wrapper) => wrapper !== null).map((wrapper) => ({
|
|
621
664
|
wrapper,
|
|
@@ -670,7 +713,7 @@ var StickyScrollTrigger = (function() {
|
|
|
670
713
|
const triggerHeight = layer.trigger.offsetHeight;
|
|
671
714
|
if (isAbsoluteFormat(resolvedStart)) throw new Error(`StickyScrollTrigger: createStickyPin's start "${resolvedStart}" 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: ${resolvedStart}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);
|
|
672
715
|
const topPx = resolveAnchorTop(resolvedStart, triggerHeight, viewportHeight);
|
|
673
|
-
const height = (
|
|
716
|
+
const height = resolvePinReleaseTop(layer.endTrigger, resolvedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
|
|
674
717
|
applyStickyPosition(layer.trigger, topPx);
|
|
675
718
|
layer.inner.style.height = `${Math.max(0, height)}px`;
|
|
676
719
|
});
|
|
@@ -721,12 +764,30 @@ var StickyScrollTrigger = (function() {
|
|
|
721
764
|
this.#unbuild();
|
|
722
765
|
this.#build();
|
|
723
766
|
}
|
|
724
|
-
this.#
|
|
767
|
+
this.#restoreCoverLifts();
|
|
768
|
+
try {
|
|
769
|
+
this.#wrapUnwrappedPins();
|
|
770
|
+
this.#reservePinSpace();
|
|
771
|
+
} finally {
|
|
772
|
+
this.#liftCovers();
|
|
773
|
+
}
|
|
725
774
|
const viewportHeight = this.#layers.length || this.#pinLayers.length ? measureViewportHeight() : 0;
|
|
726
775
|
this.#refreshScenesAndCovers(viewportHeight);
|
|
727
776
|
this.#refreshPins(viewportHeight);
|
|
728
777
|
this.#syncScrollMargins();
|
|
729
778
|
}
|
|
779
|
+
#coverLayers() {
|
|
780
|
+
return this.#layers.filter((layer) => layer.kind === "cover");
|
|
781
|
+
}
|
|
782
|
+
#restoreCoverLifts() {
|
|
783
|
+
this.#coverLayers().forEach((layer) => this.#coverRestoreByLayer.get(layer)?.());
|
|
784
|
+
}
|
|
785
|
+
#liftCovers() {
|
|
786
|
+
this.#coverLayers().forEach((layer) => {
|
|
787
|
+
const pin = this.#pinLayers.find(({ trigger }) => trigger === layer.cover);
|
|
788
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(pin?.outer ?? layer.cover));
|
|
789
|
+
});
|
|
790
|
+
}
|
|
730
791
|
#syncScrollMargins() {
|
|
731
792
|
this.#scrollMarginSync.sync(this.#layers.filter((layer) => layer.kind === "scene").map(({ trigger, freezeStart, freezeEnd }) => ({
|
|
732
793
|
trigger,
|
|
@@ -749,7 +810,7 @@ var StickyScrollTrigger = (function() {
|
|
|
749
810
|
#assertTriggerNotEnclosingRoot(trigger, context) {
|
|
750
811
|
if (!trigger.contains(this.#rootElement)) return;
|
|
751
812
|
const relation = trigger === this.#rootElement ? "is the shared container itself" : "is an ancestor of the shared container";
|
|
752
|
-
throw new Error(`${context}: trigger ${describeElement(trigger)} ${relation}. A pin
|
|
813
|
+
throw new Error(`${context}: trigger ${describeElement(trigger)} ${relation}. A pin makes trigger itself position:sticky inside a box holding the pin range, so the container and every layer's dwell padding would be pinned along with it. Pin an element that doesn't contain the container.`);
|
|
753
814
|
}
|
|
754
815
|
#registerLayer(layer, onKill, rest) {
|
|
755
816
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new layer after destroy() has been called.");
|
|
@@ -771,7 +832,7 @@ var StickyScrollTrigger = (function() {
|
|
|
771
832
|
this.#scheduleRebuild();
|
|
772
833
|
onKill?.(self);
|
|
773
834
|
},
|
|
774
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
835
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
775
836
|
};
|
|
776
837
|
}
|
|
777
838
|
createStickyTrigger({ trigger: triggerInput, start = "0 0", end = "100% 0", endTrigger: endTriggerInput, onKill, ...rest }) {
|
|
@@ -812,19 +873,18 @@ var StickyScrollTrigger = (function() {
|
|
|
812
873
|
freezeEnd: 0
|
|
813
874
|
};
|
|
814
875
|
const vars = this.#registerLayer(layer, (self) => {
|
|
815
|
-
|
|
876
|
+
this.#coverRestoreByLayer.get(layer)?.();
|
|
816
877
|
onKill?.(self);
|
|
817
878
|
}, rest);
|
|
818
|
-
|
|
819
|
-
this.#coverRestoreByLayer.set(layer, restoreCoverStyles);
|
|
879
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
820
880
|
return vars;
|
|
821
881
|
}
|
|
822
|
-
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "
|
|
882
|
+
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "bottom top", onKill, ...rest }) {
|
|
823
883
|
this.#assertNoExcludedVars(rest, "createStickyPin");
|
|
824
884
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new pin after destroy() has been called.");
|
|
825
885
|
if (start !== void 0 && top !== void 0) throw new 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.");
|
|
826
886
|
const trigger = resolveElement(triggerInput, "createStickyPin");
|
|
827
|
-
const endTrigger =
|
|
887
|
+
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createStickyPin");
|
|
828
888
|
this.#assertTriggerNotEnclosingRoot(trigger, "createStickyPin");
|
|
829
889
|
this.#assertTriggerAvailable(this.#pinLayers, trigger, `StickyScrollTrigger: ${describeElement(trigger)} is already registered as a pin trigger.`);
|
|
830
890
|
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.`);
|
|
@@ -845,14 +905,10 @@ var StickyScrollTrigger = (function() {
|
|
|
845
905
|
this.#captureScrollTriggerClass(self);
|
|
846
906
|
const index = this.#pinLayers.indexOf(layer);
|
|
847
907
|
if (index !== -1) this.#pinLayers.splice(index, 1);
|
|
848
|
-
if (layer
|
|
849
|
-
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
850
|
-
layer.outer = null;
|
|
851
|
-
layer.inner = null;
|
|
852
|
-
}
|
|
908
|
+
if (this.#unwrapPinLayer(layer)) this.#scheduleRebuild();
|
|
853
909
|
onKill?.(self);
|
|
854
910
|
},
|
|
855
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
911
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
856
912
|
};
|
|
857
913
|
}
|
|
858
914
|
resolveScrollPosition(elementInput, position) {
|
|
@@ -879,7 +935,7 @@ var StickyScrollTrigger = (function() {
|
|
|
879
935
|
if (owner) return owner.resolveScrollPosition(element, "top top");
|
|
880
936
|
return documentTop(element);
|
|
881
937
|
}
|
|
882
|
-
createResolvedTrigger({ trigger: triggerInput, start, end, endTrigger: endTriggerInput, ...rest }) {
|
|
938
|
+
createResolvedTrigger({ trigger: triggerInput, start = "top bottom", end = "bottom top", endTrigger: endTriggerInput, ...rest }) {
|
|
883
939
|
this.#assertNoExcludedVars(rest, "createResolvedTrigger");
|
|
884
940
|
const trigger = resolveElement(triggerInput, "createResolvedTrigger");
|
|
885
941
|
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createResolvedTrigger");
|
|
@@ -894,15 +950,11 @@ var StickyScrollTrigger = (function() {
|
|
|
894
950
|
if (this.#destroyed) return;
|
|
895
951
|
this.#destroyed = true;
|
|
896
952
|
this.#scrollMarginSync.restore();
|
|
897
|
-
this.#
|
|
898
|
-
if (layer.kind === "cover") this.#coverRestoreByLayer.get(layer)?.();
|
|
899
|
-
});
|
|
953
|
+
this.#restoreCoverLifts();
|
|
900
954
|
this.#unbuild();
|
|
901
955
|
this.#layers.length = 0;
|
|
902
956
|
this.#builtLayers = [];
|
|
903
|
-
this.#pinLayers.forEach((layer) =>
|
|
904
|
-
if (layer.outer) unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
905
|
-
});
|
|
957
|
+
this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
|
|
906
958
|
this.#pinLayers.length = 0;
|
|
907
959
|
}
|
|
908
960
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.8.0
|
|
4
4
|
* Copyright (c) 2026 Kuninori Ogino
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
* https://github.com/kuninori-ogino/sticky-scroll-trigger
|
|
7
7
|
*/
|
|
8
|
-
var StickyScrollTrigger=(function(){let e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},c=e=>{e.style.position=``,e.style.top=``},l=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},u=e=>({position:e.style.position,top:e.style.top}),d=(e,t)=>{e.style.position=t.position,e.style.top=t.top},f=e=>{if(!e.parentNode)throw Error(`StickyScrollTrigger: ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`),i=document.createElement(`div`);return i.setAttribute(`aria-hidden`,`true`),i.style.pointerEvents=`none`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),t.appendChild(i),{container:t,wrapper:n,padding:i}},p=e=>{let t=e.parentNode;if(!t)throw Error(`createOverlapScroll: trigger ${r(e)} is not attached to the document`);let n=document.createElement(`div`);for(t.insertBefore(n,t.firstChild);n.nextSibling;){let t=n.nextSibling;if(n.appendChild(t),t===e)break}return n},m=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},h=e=>{if(!e.parentNode)throw Error(`createStickyPin: trigger ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`);return t.style.height=`0`,t.style.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},g=(e,t,n)=>{let r=e.parentNode;d(t,n),r&&r.insertBefore(t,e),e.remove()},_=new WeakMap,v=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=_.get(n);if(e)e.count+=1;else{let e=getComputedStyle(n),t={count:1,position:n.style.position,zIndex:n.style.zIndex};e.position===`static`&&(n.style.position=`relative`),e.zIndex===`auto`&&(n.style.zIndex=`1`),_.set(n,t)}t.push(n)}return()=>{t.forEach(e=>{let t=_.get(e);t&&(--t.count,!(t.count>0)&&(e.style.position=t.position,e.style.zIndex=t.zIndex,_.delete(e)))}),t.length=0}},y=0,b=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),x=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},S=e=>{let t=`sst${y++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};b||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i?.remove(),i=null,a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),b||(o=h,c=p,l()),i||(i=document.createElement(`style`),document.head.appendChild(i)),i.textContent=x(t,h);let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){b||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},C=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},w=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},T=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},E=e=>typeof e==`function`?e():e,D={top:0,center:.5,bottom:1},O=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},k=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,A=(e,t)=>{let n=k.exec(e);if(!n||!n[1]&&!n[3])throw L.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in D,l=i===`%`;return{fraction:c?D[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?O(a,o,s,t):0)}},j=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),M=e=>typeof e==`number`?e:Number(e),N=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=A(i,t),s=A(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},P=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,F=e=>typeof e==`string`&&P.test(e.trim()),I=(e,t)=>{let n=P.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return O(void 0,r,i,t)},L=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?O(r,i,a,t):0},B=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},V=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+B(e,s,a,l.end.rawTop,u):t}let r=N(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},H=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=V(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=V(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},U=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],W=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(F(a))return{mode:`dwell`,distancePx:Math.max(0,I(a,t))};if(j(a))return{mode:`absolute`,value:M(a)};if(R(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:z(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},G=(e,t,n,i)=>{if(!j(t))return{mode:`clause`,anchorOffset:N(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:M(t)}},K=(e,t,n,r,a)=>{let o=E(n.start),s=n.end===null?null:E(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=W(e,t,n,s,r,u),f=G(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},q=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},J=(e,t)=>e.some(e=>e.trigger===t);return class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=S(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(T(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=w(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e,t,n){return r=>{this.#g(r);let i=n?.(r);return e[0]===t&&this.refresh(),i}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#b(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#x(e){if(!this.#u.length)return;let t=this.#y(),n=this.#b();try{this.#S(e)}catch(e){throw n(),e}finally{t()}}#S(e){this.#u.forEach(t=>{if(!t.inner)return;let n=E(t.end);if(R(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=E(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(j(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=N(r,o,e),c=(j(n)?M(n):i(t.endTrigger)-N(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#C(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#y();try{this.#w(e,t)}catch(e){throw n(),e}}#w(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>K(this.#e,e,t,n,r)),s=0,c=()=>H(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||C(this.#t))&&(this.#p(),this.#m()),this.#v();let e=this.#t.length||this.#u.length?a():0;this.#C(e),this.#x(e),this.#T()}#T(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#E(e,t){let n=U.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#D(e,t,n){if(J(e,t))throw Error(n)}#O(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#k(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#A(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#D(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#D(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(this.#t,e,n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#E(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#O(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#A({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#E(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#O(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#A(p,e=>{h(),c?.(e)},l),h=v(f);return this.#r.set(p,h),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#E(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#k(l,`createStickyPin`),this.#D(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#D(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:q(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),f.outer&&(g(f.outer,f.trigger,f.savedPosition),f.outer=null,f.inner=null),s?.(e)},onRefreshInit:this.#_(this.#u,f,c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=E(n),l=a();if(R(c))return o(l)+z(c,l);if(j(c))return M(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=N(c,r.offsetHeight,l),f=this.#y(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#E(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#t.forEach(e=>{e.kind===`cover`&&this.#r.get(e)?.()}),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>{e.outer&&g(e.outer,e.trigger,e.savedPosition)}),this.#u.length=0)}}})();
|
|
8
|
+
var StickyScrollTrigger=(function(){let e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=e=>parseFloat(getComputedStyle(e).height)||0,c=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},l=e=>{e.style.position=``,e.style.top=``},u=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},d=e=>({position:e.style.position,top:e.style.top}),f=(e,t)=>{e.style.position=t.position,e.style.top=t.top},p=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}},m=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},h=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},g=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.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},_=(e,t,n)=>{let r=e.parentNode;f(t,n),r&&r.insertBefore(t,e),e.remove()},v={position:`relative`,zIndex:`1`},y=new WeakMap,b=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=y.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]=v[t]}),y.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=y.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===v[t]&&(e.style[t]=``)}),y.delete(e)))}),t.length=0}},x=0,S=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),C=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),w=S&&C,T=(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(``)},E=e=>{let t=`sst${x++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],s=null,l=()=>{if(!s)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);s.style.setProperty(`--${t}-c${r}`,`${i}px`)})};w||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=[],s=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}`,``)),w?(i||(i=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,i]),i.replaceSync(T(t,h))):(o=h,s=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=>{c(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(){w||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},D=e=>{for(let t=1;t<e.length;t+=1)if(c(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},O=(e,t)=>{t.sort((e,t)=>c(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=m(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=p(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},k=(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&&h(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},A=e=>typeof e==`function`?e():e,j={top:0,center:.5,bottom:1},M=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},N=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,P=(e,t)=>{let n=N.exec(e);if(!n||!n[1]&&!n[3])throw V.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 j,l=i===`%`;return{fraction:c?j[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?M(a,o,s,t):0)}},F=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),I=e=>typeof e==`number`?e:Number(e),L=(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=P(i,t),s=P(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},R=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,z=e=>typeof e==`string`&&R.test(e.trim()),B=(e,t)=>{let n=R.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return M(void 0,r,i,t)},V=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,H=e=>typeof e==`string`&&V.test(e.trim()),U=(e,t)=>{let n=V.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?M(r,i,a,t):0},W=(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},G=(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+W(e,s,a,l.end.rawTop,u):t}let r=L(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}},K=(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}=G(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=G(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},q=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],J=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(z(a))return{mode:`dwell`,distancePx:Math.max(0,B(a,t))};if(F(a))return{mode:`absolute`,value:I(a)};if(H(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:U(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}},Y=(e,t,n,i)=>{if(!F(t))return{mode:`clause`,anchorOffset:L(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:I(t)}},X=(e,t,n,r,a)=>{let o=A(n.start),s=n.end===null?null:A(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=J(e,t,n,s,r,u),f=Y(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}},Z=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)},Q=(e,t,n,r)=>z(t)?n+B(t,r):F(t)?I(t):i(e)-L(t,e.offsetHeight,r),$=(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=E(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&&=(k(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=O(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=d(e.trigger);let t=g(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(){let e=this.#u.flatMap(({outer:e,inner:t})=>e&&t?[{outer:e,inner:t,range:t.style.height}]:[]);e.forEach(({outer:e,inner:t})=>{e.style.height=``,t.style.height=``});let t=e.map(({outer:e})=>s(e));e.forEach(({outer:e},n)=>{e.style.height=`${t[n]}px`}),e.forEach(({inner:e,range:t})=>{e.style.height=t})}#b(e){return e.outer?(_(e.outer,e.trigger,e.savedPosition),e.outer=null,e.inner=null,!0):!1}#x(){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})=>l(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#S(){let e=this.#u.map(e=>({layer:e,position:d(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{l(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{f(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#C(e){if(!this.#u.length)return;let t=this.#x(),n=this.#S();try{this.#w(e)}catch(e){throw n(),e}finally{t()}}#w(e){this.#u.forEach(t=>{if(!t.inner)return;let n=A(t.end);if(H(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=A(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(F(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=L(r,o,e),c=Q(t.endTrigger,n,a-s,e)-a+s+o;u(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#T(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#x();try{this.#E(e,t)}catch(e){throw n(),e}}#E(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)=>X(this.#e,e,t,n,r)),s=0,c=()=>K(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&&(u(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let l=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(l||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||D(this.#t))&&(this.#p(),this.#m()),this.#O();try{this.#v(),this.#y()}finally{this.#k()}let e=this.#t.length||this.#u.length?a():0;this.#T(e),this.#C(e),this.#A()}#D(){return this.#t.filter(e=>e.kind===`cover`)}#O(){this.#D().forEach(e=>this.#r.get(e)?.())}#k(){this.#D().forEach(e=>{let t=this.#u.find(({trigger:t})=>t===e.cover);this.#r.set(e,b(t?.outer??e.cover))})}#A(){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)}#j(e,t){let n=q.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.`)}#M(e,t,n){if($(e,t))throw Error(n)}#N(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.`)}#P(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 makes trigger itself position:sticky inside a box holding the pin range, so the container and every layer's dwell padding would be pinned along with it. Pin an element that doesn't contain the container.`)}#F(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#M(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.#M(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.#j(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#N(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#F({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.#j(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#N(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.#F(p,e=>{this.#r.get(p)?.(),c?.(e)},l);return this.#r.set(p,b(f)),m}createStickyPin({trigger:e,start:i,top:a,endTrigger:o,end:s=`bottom top`,onKill:c,...l}){if(this.#j(l,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(i!==void 0&&a!==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 u=t(e,`createStickyPin`),f=n(u,o,`createStickyPin`);this.#P(u,`createStickyPin`),this.#M(this.#u,u,`StickyScrollTrigger: ${r(u)} is already registered as a pin trigger.`),this.#M(this.#t,u,`StickyScrollTrigger: ${r(u)} 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 p={trigger:u,savedPosition:d(u),outer:null,inner:null,start:a===void 0?i??`top top`:Z(a),endTrigger:f,end:s};return this.#u.push(p),{...l,trigger:u,onKill:e=>{this.#g(e);let t=this.#u.indexOf(p);t!==-1&&this.#u.splice(t,1),this.#b(p)&&this.#h(),c?.(e)},onRefreshInit:this.#_(l.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),s=A(n),l=a();if(H(s))return o(l)+U(s,l);if(F(s))return I(s);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(c(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=L(s,r.offsetHeight,l),f=this.#x(),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=`top bottom`,end:i=`bottom top`,endTrigger:a,...o}){this.#j(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.#O(),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#b(e)),this.#u.length=0)}}})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.8.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
|
|
@@ -51,6 +51,7 @@ const measureDocumentMaxScroll = (viewportHeight) => {
|
|
|
51
51
|
const doc = document.documentElement;
|
|
52
52
|
return Math.max(0, (doc.scrollHeight || document.body.scrollHeight) - viewportHeight);
|
|
53
53
|
};
|
|
54
|
+
const measureUsedHeight = (el) => parseFloat(getComputedStyle(el).height) || 0;
|
|
54
55
|
const compareDocumentOrder = (a, b) => {
|
|
55
56
|
const position = a.compareDocumentPosition(b);
|
|
56
57
|
if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
@@ -112,7 +113,6 @@ const wrapPin = (trigger) => {
|
|
|
112
113
|
if (!trigger.parentNode) throw new Error(`createStickyPin: trigger ${describeElement(trigger)} is not attached to the document`);
|
|
113
114
|
const outer = document.createElement("div");
|
|
114
115
|
const inner = document.createElement("div");
|
|
115
|
-
outer.style.height = "0";
|
|
116
116
|
outer.style.contain = "layout";
|
|
117
117
|
trigger.parentNode.insertBefore(outer, trigger);
|
|
118
118
|
outer.appendChild(inner);
|
|
@@ -128,25 +128,32 @@ const unwrapPin = (outer, trigger, saved) => {
|
|
|
128
128
|
if (parent) parent.insertBefore(trigger, outer);
|
|
129
129
|
outer.remove();
|
|
130
130
|
};
|
|
131
|
+
const LIFT_VALUES = {
|
|
132
|
+
position: "relative",
|
|
133
|
+
zIndex: "1"
|
|
134
|
+
};
|
|
131
135
|
const liftStates = new WeakMap();
|
|
132
136
|
const liftAboveStickyWrapper = (cover) => {
|
|
133
137
|
const lifted = [];
|
|
134
138
|
for (let node = cover; node; node = node.nextElementSibling) {
|
|
135
139
|
if (!(node instanceof HTMLElement)) continue;
|
|
136
|
-
const
|
|
140
|
+
const element = node;
|
|
141
|
+
const existing = liftStates.get(element);
|
|
137
142
|
if (existing) existing.count += 1;
|
|
138
143
|
else {
|
|
139
|
-
const computed = getComputedStyle(
|
|
140
|
-
const
|
|
144
|
+
const computed = getComputedStyle(element);
|
|
145
|
+
const applied = [];
|
|
146
|
+
if (computed.position === "static") applied.push("position");
|
|
147
|
+
if (computed.zIndex === "auto") applied.push("zIndex");
|
|
148
|
+
applied.forEach((property) => {
|
|
149
|
+
element.style[property] = LIFT_VALUES[property];
|
|
150
|
+
});
|
|
151
|
+
liftStates.set(element, {
|
|
141
152
|
count: 1,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
if (computed.position === "static") node.style.position = "relative";
|
|
146
|
-
if (computed.zIndex === "auto") node.style.zIndex = "1";
|
|
147
|
-
liftStates.set(node, state);
|
|
153
|
+
applied
|
|
154
|
+
});
|
|
148
155
|
}
|
|
149
|
-
lifted.push(
|
|
156
|
+
lifted.push(element);
|
|
150
157
|
}
|
|
151
158
|
return () => {
|
|
152
159
|
lifted.forEach((el) => {
|
|
@@ -154,8 +161,9 @@ const liftAboveStickyWrapper = (cover) => {
|
|
|
154
161
|
if (!state) return;
|
|
155
162
|
state.count -= 1;
|
|
156
163
|
if (state.count > 0) return;
|
|
157
|
-
|
|
158
|
-
|
|
164
|
+
state.applied.forEach((property) => {
|
|
165
|
+
if (el.style[property] === LIFT_VALUES[property]) el.style[property] = "";
|
|
166
|
+
});
|
|
159
167
|
liftStates.delete(el);
|
|
160
168
|
});
|
|
161
169
|
lifted.length = 0;
|
|
@@ -164,6 +172,8 @@ const liftAboveStickyWrapper = (cover) => {
|
|
|
164
172
|
const OFFSET_PROPERTY = "--sst-scroll-margin-top-offset";
|
|
165
173
|
let nextInstanceSuffix = 0;
|
|
166
174
|
const supportsScrollDrivenAnimations = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("animation-timeline", "scroll()");
|
|
175
|
+
const supportsConstructedStyleSheets = typeof CSSStyleSheet === "function" && typeof CSSStyleSheet.prototype.replaceSync === "function" && typeof document !== "undefined" && Array.isArray(document.adoptedStyleSheets);
|
|
176
|
+
const usesCssRamp = supportsScrollDrivenAnimations && supportsConstructedStyleSheets;
|
|
167
177
|
const buildStylesheet = (instanceId, scenes) => {
|
|
168
178
|
const declarations = [];
|
|
169
179
|
const animations = [];
|
|
@@ -184,7 +194,7 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
184
194
|
const instanceId = `sst${nextInstanceSuffix++}`;
|
|
185
195
|
const snapshots = new WeakMap();
|
|
186
196
|
let written = new Set();
|
|
187
|
-
let
|
|
197
|
+
let sheet = null;
|
|
188
198
|
let animationHost = null;
|
|
189
199
|
let jsRamps = [];
|
|
190
200
|
let jsHost = null;
|
|
@@ -196,14 +206,16 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
196
206
|
jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
|
|
197
207
|
});
|
|
198
208
|
};
|
|
199
|
-
if (!
|
|
209
|
+
if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
|
|
200
210
|
const restoreTarget = (target) => {
|
|
201
211
|
const snapshot = snapshots.get(target);
|
|
202
212
|
target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
|
|
203
213
|
};
|
|
204
214
|
const clearAnimation = () => {
|
|
205
|
-
|
|
206
|
-
|
|
215
|
+
if (sheet) {
|
|
216
|
+
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((one) => one !== sheet);
|
|
217
|
+
sheet = null;
|
|
218
|
+
}
|
|
207
219
|
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
208
220
|
animationHost = null;
|
|
209
221
|
jsRamps = [];
|
|
@@ -223,16 +235,17 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
223
235
|
animationHost = host;
|
|
224
236
|
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
225
237
|
}
|
|
226
|
-
if (!
|
|
238
|
+
if (!usesCssRamp) {
|
|
227
239
|
jsRamps = ramps;
|
|
228
240
|
jsHost = host;
|
|
229
241
|
applyJsRamp();
|
|
242
|
+
} else {
|
|
243
|
+
if (!sheet) {
|
|
244
|
+
sheet = new CSSStyleSheet();
|
|
245
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
246
|
+
}
|
|
247
|
+
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
230
248
|
}
|
|
231
|
-
if (!styleElement) {
|
|
232
|
-
styleElement = document.createElement("style");
|
|
233
|
-
document.head.appendChild(styleElement);
|
|
234
|
-
}
|
|
235
|
-
styleElement.textContent = buildStylesheet(instanceId, ramps);
|
|
236
249
|
const targets = Array.from(rootElement.querySelectorAll(targetSelector));
|
|
237
250
|
targets.forEach((target) => {
|
|
238
251
|
const existing = snapshots.get(target);
|
|
@@ -256,7 +269,7 @@ const createScrollMarginSync = (rootElement) => {
|
|
|
256
269
|
written = next;
|
|
257
270
|
},
|
|
258
271
|
restore() {
|
|
259
|
-
if (!
|
|
272
|
+
if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
|
|
260
273
|
written.forEach(restoreTarget);
|
|
261
274
|
written = new Set();
|
|
262
275
|
clearAnimation();
|
|
@@ -548,6 +561,11 @@ const topToStartClause = (top) => {
|
|
|
548
561
|
};
|
|
549
562
|
return typeof top === "function" ? () => toClause(top()) : toClause(top);
|
|
550
563
|
};
|
|
564
|
+
const resolvePinReleaseTop = (endTrigger, resolvedEnd, engageTop, viewportHeight) => {
|
|
565
|
+
if (isDwellFormat(resolvedEnd)) return engageTop + resolveDwell(resolvedEnd, viewportHeight);
|
|
566
|
+
if (isAbsoluteFormat(resolvedEnd)) return resolveAbsolute(resolvedEnd);
|
|
567
|
+
return documentTop(endTrigger) - resolveAnchorTop(resolvedEnd, endTrigger.offsetHeight, viewportHeight);
|
|
568
|
+
};
|
|
551
569
|
const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
|
|
552
570
|
var StickyScrollTrigger = class {
|
|
553
571
|
#rootElement;
|
|
@@ -598,11 +616,11 @@ var StickyScrollTrigger = class {
|
|
|
598
616
|
#captureScrollTriggerClass(self) {
|
|
599
617
|
this.#scrollTriggerClass = self.constructor;
|
|
600
618
|
}
|
|
601
|
-
#createAutoRefreshHandler(
|
|
619
|
+
#createAutoRefreshHandler(userOnRefreshInit) {
|
|
602
620
|
return (self) => {
|
|
603
621
|
this.#captureScrollTriggerClass(self);
|
|
604
622
|
const result = userOnRefreshInit?.(self);
|
|
605
|
-
|
|
623
|
+
this.refresh();
|
|
606
624
|
return result;
|
|
607
625
|
};
|
|
608
626
|
}
|
|
@@ -615,6 +633,31 @@ var StickyScrollTrigger = class {
|
|
|
615
633
|
layer.inner = wrapped.inner;
|
|
616
634
|
});
|
|
617
635
|
}
|
|
636
|
+
#reservePinSpace() {
|
|
637
|
+
const wrapped = this.#pinLayers.flatMap(({ outer, inner }) => outer && inner ? [{
|
|
638
|
+
outer,
|
|
639
|
+
inner,
|
|
640
|
+
range: inner.style.height
|
|
641
|
+
}] : []);
|
|
642
|
+
wrapped.forEach(({ outer, inner }) => {
|
|
643
|
+
outer.style.height = "";
|
|
644
|
+
inner.style.height = "";
|
|
645
|
+
});
|
|
646
|
+
const reserved = wrapped.map(({ outer }) => measureUsedHeight(outer));
|
|
647
|
+
wrapped.forEach(({ outer }, index) => {
|
|
648
|
+
outer.style.height = `${reserved[index]}px`;
|
|
649
|
+
});
|
|
650
|
+
wrapped.forEach(({ inner, range }) => {
|
|
651
|
+
inner.style.height = range;
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
#unwrapPinLayer(layer) {
|
|
655
|
+
if (!layer.outer) return false;
|
|
656
|
+
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
657
|
+
layer.outer = null;
|
|
658
|
+
layer.inner = null;
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
618
661
|
#resetSceneCoverStickyState() {
|
|
619
662
|
const wrapperSnapshots = this.#layers.map((layer) => layer.wrapper).filter((wrapper) => wrapper !== null).map((wrapper) => ({
|
|
620
663
|
wrapper,
|
|
@@ -669,7 +712,7 @@ var StickyScrollTrigger = class {
|
|
|
669
712
|
const triggerHeight = layer.trigger.offsetHeight;
|
|
670
713
|
if (isAbsoluteFormat(resolvedStart)) throw new Error(`StickyScrollTrigger: createStickyPin's start "${resolvedStart}" 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: ${resolvedStart}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);
|
|
671
714
|
const topPx = resolveAnchorTop(resolvedStart, triggerHeight, viewportHeight);
|
|
672
|
-
const height = (
|
|
715
|
+
const height = resolvePinReleaseTop(layer.endTrigger, resolvedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
|
|
673
716
|
applyStickyPosition(layer.trigger, topPx);
|
|
674
717
|
layer.inner.style.height = `${Math.max(0, height)}px`;
|
|
675
718
|
});
|
|
@@ -720,12 +763,30 @@ var StickyScrollTrigger = class {
|
|
|
720
763
|
this.#unbuild();
|
|
721
764
|
this.#build();
|
|
722
765
|
}
|
|
723
|
-
this.#
|
|
766
|
+
this.#restoreCoverLifts();
|
|
767
|
+
try {
|
|
768
|
+
this.#wrapUnwrappedPins();
|
|
769
|
+
this.#reservePinSpace();
|
|
770
|
+
} finally {
|
|
771
|
+
this.#liftCovers();
|
|
772
|
+
}
|
|
724
773
|
const viewportHeight = this.#layers.length || this.#pinLayers.length ? measureViewportHeight() : 0;
|
|
725
774
|
this.#refreshScenesAndCovers(viewportHeight);
|
|
726
775
|
this.#refreshPins(viewportHeight);
|
|
727
776
|
this.#syncScrollMargins();
|
|
728
777
|
}
|
|
778
|
+
#coverLayers() {
|
|
779
|
+
return this.#layers.filter((layer) => layer.kind === "cover");
|
|
780
|
+
}
|
|
781
|
+
#restoreCoverLifts() {
|
|
782
|
+
this.#coverLayers().forEach((layer) => this.#coverRestoreByLayer.get(layer)?.());
|
|
783
|
+
}
|
|
784
|
+
#liftCovers() {
|
|
785
|
+
this.#coverLayers().forEach((layer) => {
|
|
786
|
+
const pin = this.#pinLayers.find(({ trigger }) => trigger === layer.cover);
|
|
787
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(pin?.outer ?? layer.cover));
|
|
788
|
+
});
|
|
789
|
+
}
|
|
729
790
|
#syncScrollMargins() {
|
|
730
791
|
this.#scrollMarginSync.sync(this.#layers.filter((layer) => layer.kind === "scene").map(({ trigger, freezeStart, freezeEnd }) => ({
|
|
731
792
|
trigger,
|
|
@@ -748,7 +809,7 @@ var StickyScrollTrigger = class {
|
|
|
748
809
|
#assertTriggerNotEnclosingRoot(trigger, context) {
|
|
749
810
|
if (!trigger.contains(this.#rootElement)) return;
|
|
750
811
|
const relation = trigger === this.#rootElement ? "is the shared container itself" : "is an ancestor of the shared container";
|
|
751
|
-
throw new Error(`${context}: trigger ${describeElement(trigger)} ${relation}. A pin
|
|
812
|
+
throw new Error(`${context}: trigger ${describeElement(trigger)} ${relation}. A pin makes trigger itself position:sticky inside a box holding the pin range, so the container and every layer's dwell padding would be pinned along with it. Pin an element that doesn't contain the container.`);
|
|
752
813
|
}
|
|
753
814
|
#registerLayer(layer, onKill, rest) {
|
|
754
815
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new layer after destroy() has been called.");
|
|
@@ -770,7 +831,7 @@ var StickyScrollTrigger = class {
|
|
|
770
831
|
this.#scheduleRebuild();
|
|
771
832
|
onKill?.(self);
|
|
772
833
|
},
|
|
773
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
834
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
774
835
|
};
|
|
775
836
|
}
|
|
776
837
|
createStickyTrigger({ trigger: triggerInput, start = "0 0", end = "100% 0", endTrigger: endTriggerInput, onKill, ...rest }) {
|
|
@@ -811,19 +872,18 @@ var StickyScrollTrigger = class {
|
|
|
811
872
|
freezeEnd: 0
|
|
812
873
|
};
|
|
813
874
|
const vars = this.#registerLayer(layer, (self) => {
|
|
814
|
-
|
|
875
|
+
this.#coverRestoreByLayer.get(layer)?.();
|
|
815
876
|
onKill?.(self);
|
|
816
877
|
}, rest);
|
|
817
|
-
|
|
818
|
-
this.#coverRestoreByLayer.set(layer, restoreCoverStyles);
|
|
878
|
+
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
819
879
|
return vars;
|
|
820
880
|
}
|
|
821
|
-
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "
|
|
881
|
+
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "bottom top", onKill, ...rest }) {
|
|
822
882
|
this.#assertNoExcludedVars(rest, "createStickyPin");
|
|
823
883
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new pin after destroy() has been called.");
|
|
824
884
|
if (start !== void 0 && top !== void 0) throw new 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.");
|
|
825
885
|
const trigger = resolveElement(triggerInput, "createStickyPin");
|
|
826
|
-
const endTrigger =
|
|
886
|
+
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createStickyPin");
|
|
827
887
|
this.#assertTriggerNotEnclosingRoot(trigger, "createStickyPin");
|
|
828
888
|
this.#assertTriggerAvailable(this.#pinLayers, trigger, `StickyScrollTrigger: ${describeElement(trigger)} is already registered as a pin trigger.`);
|
|
829
889
|
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.`);
|
|
@@ -844,14 +904,10 @@ var StickyScrollTrigger = class {
|
|
|
844
904
|
this.#captureScrollTriggerClass(self);
|
|
845
905
|
const index = this.#pinLayers.indexOf(layer);
|
|
846
906
|
if (index !== -1) this.#pinLayers.splice(index, 1);
|
|
847
|
-
if (layer
|
|
848
|
-
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
849
|
-
layer.outer = null;
|
|
850
|
-
layer.inner = null;
|
|
851
|
-
}
|
|
907
|
+
if (this.#unwrapPinLayer(layer)) this.#scheduleRebuild();
|
|
852
908
|
onKill?.(self);
|
|
853
909
|
},
|
|
854
|
-
onRefreshInit: this.#createAutoRefreshHandler(
|
|
910
|
+
onRefreshInit: this.#createAutoRefreshHandler(rest.onRefreshInit)
|
|
855
911
|
};
|
|
856
912
|
}
|
|
857
913
|
resolveScrollPosition(elementInput, position) {
|
|
@@ -878,7 +934,7 @@ var StickyScrollTrigger = class {
|
|
|
878
934
|
if (owner) return owner.resolveScrollPosition(element, "top top");
|
|
879
935
|
return documentTop(element);
|
|
880
936
|
}
|
|
881
|
-
createResolvedTrigger({ trigger: triggerInput, start, end, endTrigger: endTriggerInput, ...rest }) {
|
|
937
|
+
createResolvedTrigger({ trigger: triggerInput, start = "top bottom", end = "bottom top", endTrigger: endTriggerInput, ...rest }) {
|
|
882
938
|
this.#assertNoExcludedVars(rest, "createResolvedTrigger");
|
|
883
939
|
const trigger = resolveElement(triggerInput, "createResolvedTrigger");
|
|
884
940
|
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createResolvedTrigger");
|
|
@@ -893,15 +949,11 @@ var StickyScrollTrigger = class {
|
|
|
893
949
|
if (this.#destroyed) return;
|
|
894
950
|
this.#destroyed = true;
|
|
895
951
|
this.#scrollMarginSync.restore();
|
|
896
|
-
this.#
|
|
897
|
-
if (layer.kind === "cover") this.#coverRestoreByLayer.get(layer)?.();
|
|
898
|
-
});
|
|
952
|
+
this.#restoreCoverLifts();
|
|
899
953
|
this.#unbuild();
|
|
900
954
|
this.#layers.length = 0;
|
|
901
955
|
this.#builtLayers = [];
|
|
902
|
-
this.#pinLayers.forEach((layer) =>
|
|
903
|
-
if (layer.outer) unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
904
|
-
});
|
|
956
|
+
this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
|
|
905
957
|
this.#pinLayers.length = 0;
|
|
906
958
|
}
|
|
907
959
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.8.0
|
|
4
4
|
* Copyright (c) 2026 Kuninori Ogino
|
|
5
5
|
* Released under the MIT License
|
|
6
6
|
* https://github.com/kuninori-ogino/sticky-scroll-trigger
|
|
7
7
|
*/
|
|
8
|
-
const e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},c=e=>{e.style.position=``,e.style.top=``},l=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},u=e=>({position:e.style.position,top:e.style.top}),d=(e,t)=>{e.style.position=t.position,e.style.top=t.top},f=e=>{if(!e.parentNode)throw Error(`StickyScrollTrigger: ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`),i=document.createElement(`div`);return i.setAttribute(`aria-hidden`,`true`),i.style.pointerEvents=`none`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),t.appendChild(i),{container:t,wrapper:n,padding:i}},p=e=>{let t=e.parentNode;if(!t)throw Error(`createOverlapScroll: trigger ${r(e)} is not attached to the document`);let n=document.createElement(`div`);for(t.insertBefore(n,t.firstChild);n.nextSibling;){let t=n.nextSibling;if(n.appendChild(t),t===e)break}return n},m=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},h=e=>{if(!e.parentNode)throw Error(`createStickyPin: trigger ${r(e)} is not attached to the document`);let t=document.createElement(`div`),n=document.createElement(`div`);return t.style.height=`0`,t.style.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},g=(e,t,n)=>{let r=e.parentNode;d(t,n),r&&r.insertBefore(t,e),e.remove()},_=new WeakMap,v=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=_.get(n);if(e)e.count+=1;else{let e=getComputedStyle(n),t={count:1,position:n.style.position,zIndex:n.style.zIndex};e.position===`static`&&(n.style.position=`relative`),e.zIndex===`auto`&&(n.style.zIndex=`1`),_.set(n,t)}t.push(n)}return()=>{t.forEach(e=>{let t=_.get(e);t&&(--t.count,!(t.count>0)&&(e.style.position=t.position,e.style.zIndex=t.zIndex,_.delete(e)))}),t.length=0}};let y=0;const b=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),x=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},S=e=>{let t=`sst${y++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};b||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i?.remove(),i=null,a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),b||(o=h,c=p,l()),i||(i=document.createElement(`style`),document.head.appendChild(i)),i.textContent=x(t,h);let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){b||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},C=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},w=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},T=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},E=e=>typeof e==`function`?e():e,D={top:0,center:.5,bottom:1},O=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},k=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,A=(e,t)=>{let n=k.exec(e);if(!n||!n[1]&&!n[3])throw L.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in D,l=i===`%`;return{fraction:c?D[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?O(a,o,s,t):0)}},j=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),M=e=>typeof e==`number`?e:Number(e),N=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=A(i,t),s=A(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},P=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,F=e=>typeof e==`string`&&P.test(e.trim()),I=(e,t)=>{let n=P.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return O(void 0,r,i,t)},L=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?O(r,i,a,t):0},B=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},V=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+B(e,s,a,l.end.rawTop,u):t}let r=N(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},H=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=V(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=V(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},U=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],W=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(F(a))return{mode:`dwell`,distancePx:Math.max(0,I(a,t))};if(j(a))return{mode:`absolute`,value:M(a)};if(R(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:z(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},G=(e,t,n,i)=>{if(!j(t))return{mode:`clause`,anchorOffset:N(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:M(t)}},K=(e,t,n,r,a)=>{let o=E(n.start),s=n.end===null?null:E(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=W(e,t,n,s,r,u),f=G(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},q=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},J=(e,t)=>e.some(e=>e.trigger===t);var Y=class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=S(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(T(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=w(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e,t,n){return r=>{this.#g(r);let i=n?.(r);return e[0]===t&&this.refresh(),i}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#b(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#x(e){if(!this.#u.length)return;let t=this.#y(),n=this.#b();try{this.#S(e)}catch(e){throw n(),e}finally{t()}}#S(e){this.#u.forEach(t=>{if(!t.inner)return;let n=E(t.end);if(R(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=E(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(j(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=N(r,o,e),c=(j(n)?M(n):i(t.endTrigger)-N(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#C(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#y();try{this.#w(e,t)}catch(e){throw n(),e}}#w(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>K(this.#e,e,t,n,r)),s=0,c=()=>H(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||C(this.#t))&&(this.#p(),this.#m()),this.#v();let e=this.#t.length||this.#u.length?a():0;this.#C(e),this.#x(e),this.#T()}#T(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#E(e,t){let n=U.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#D(e,t,n){if(J(e,t))throw Error(n)}#O(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#k(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#A(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#D(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#D(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(this.#t,e,n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#E(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#O(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#A({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#E(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#O(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#A(p,e=>{h(),c?.(e)},l),h=v(f);return this.#r.set(p,h),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#E(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#k(l,`createStickyPin`),this.#D(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#D(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:q(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),f.outer&&(g(f.outer,f.trigger,f.savedPosition),f.outer=null,f.inner=null),s?.(e)},onRefreshInit:this.#_(this.#u,f,c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=E(n),l=a();if(R(c))return o(l)+z(c,l);if(j(c))return M(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=N(c,r.offsetHeight,l),f=this.#y(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#E(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#t.forEach(e=>{e.kind===`cover`&&this.#r.get(e)?.()}),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>{e.outer&&g(e.outer,e.trigger,e.savedPosition)}),this.#u.length=0)}};export{Y as default};
|
|
8
|
+
const e=e=>{let t=typeof e==`string`?document.querySelector(e):e;if(!t){let t=typeof e==`string`?`"${e}"`:String(e);throw Error(`StickyScrollTrigger: root ${t} not found`)}return t},t=(e,t)=>{let n=typeof e==`string`?document.querySelector(e):e;if(!n){let n=typeof e==`string`?`"${e}"`:String(e);throw Error(`${t}: element ${n} not found`)}return n},n=(e,n,r)=>n===void 0?e:t(n,r),r=e=>{let t=e.id?`#${e.id}`:``,n=e.classList.length>0?`.${Array.from(e.classList).join(`.`)}`:``;return`<${e.tagName.toLowerCase()}${t}${n}>`},i=e=>{let t=0,n=e;for(;n;){t+=n.offsetTop;let e=n.offsetParent;e&&(t+=e.clientTop),n=e}return t},a=()=>{let e=document.createElement(`div`);e.style.height=`100vh`,e.style.position=`absolute`,document.body.appendChild(e);let t=e.offsetHeight||window.innerHeight;return e.remove(),t},o=e=>{let t=document.documentElement;return Math.max(0,(t.scrollHeight||document.body.scrollHeight)-e)},s=e=>parseFloat(getComputedStyle(e).height)||0,c=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},l=e=>{e.style.position=``,e.style.top=``},u=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},d=e=>({position:e.style.position,top:e.style.top}),f=(e,t)=>{e.style.position=t.position,e.style.top=t.top},p=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}},m=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},h=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},g=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.contain=`layout`,e.parentNode.insertBefore(t,e),t.appendChild(n),n.appendChild(e),{outer:t,inner:n}},_=(e,t,n)=>{let r=e.parentNode;f(t,n),r&&r.insertBefore(t,e),e.remove()},v={position:`relative`,zIndex:`1`},y=new WeakMap,b=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=y.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]=v[t]}),y.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=y.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===v[t]&&(e.style[t]=``)}),y.delete(e)))}),t.length=0}};let x=0;const S=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),C=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),w=S&&C,T=(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(``)},E=e=>{let t=`sst${x++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],s=null,l=()=>{if(!s)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);s.style.setProperty(`--${t}-c${r}`,`${i}px`)})};w||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=[],s=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}`,``)),w?(i||(i=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,i]),i.replaceSync(T(t,h))):(o=h,s=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=>{c(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(){w||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},D=e=>{for(let t=1;t<e.length;t+=1)if(c(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},O=(e,t)=>{t.sort((e,t)=>c(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=m(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=p(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},k=(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&&h(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},A=e=>typeof e==`function`?e():e,j={top:0,center:.5,bottom:1},M=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},N=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,P=(e,t)=>{let n=N.exec(e);if(!n||!n[1]&&!n[3])throw V.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 j,l=i===`%`;return{fraction:c?j[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?M(a,o,s,t):0)}},F=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),I=e=>typeof e==`number`?e:Number(e),L=(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=P(i,t),s=P(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},R=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,z=e=>typeof e==`string`&&R.test(e.trim()),B=(e,t)=>{let n=R.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return M(void 0,r,i,t)},V=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,H=e=>typeof e==`string`&&V.test(e.trim()),U=(e,t)=>{let n=V.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?M(r,i,a,t):0},W=(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},G=(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+W(e,s,a,l.end.rawTop,u):t}let r=L(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}},K=(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}=G(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=G(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},q=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],J=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(z(a))return{mode:`dwell`,distancePx:Math.max(0,B(a,t))};if(F(a))return{mode:`absolute`,value:I(a)};if(H(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:U(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}},Y=(e,t,n,i)=>{if(!F(t))return{mode:`clause`,anchorOffset:L(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:I(t)}},X=(e,t,n,r,a)=>{let o=A(n.start),s=n.end===null?null:A(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=J(e,t,n,s,r,u),f=Y(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}},Z=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)},Q=(e,t,n,r)=>z(t)?n+B(t,r):F(t)?I(t):i(e)-L(t,e.offsetHeight,r),$=(e,t)=>e.some(e=>e.trigger===t);var ee=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=E(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&&=(k(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=O(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=d(e.trigger);let t=g(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(){let e=this.#u.flatMap(({outer:e,inner:t})=>e&&t?[{outer:e,inner:t,range:t.style.height}]:[]);e.forEach(({outer:e,inner:t})=>{e.style.height=``,t.style.height=``});let t=e.map(({outer:e})=>s(e));e.forEach(({outer:e},n)=>{e.style.height=`${t[n]}px`}),e.forEach(({inner:e,range:t})=>{e.style.height=t})}#b(e){return e.outer?(_(e.outer,e.trigger,e.savedPosition),e.outer=null,e.inner=null,!0):!1}#x(){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})=>l(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#S(){let e=this.#u.map(e=>({layer:e,position:d(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{l(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{f(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#C(e){if(!this.#u.length)return;let t=this.#x(),n=this.#S();try{this.#w(e)}catch(e){throw n(),e}finally{t()}}#w(e){this.#u.forEach(t=>{if(!t.inner)return;let n=A(t.end);if(H(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=A(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(F(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=L(r,o,e),c=Q(t.endTrigger,n,a-s,e)-a+s+o;u(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#T(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#x();try{this.#E(e,t)}catch(e){throw n(),e}}#E(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)=>X(this.#e,e,t,n,r)),s=0,c=()=>K(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&&(u(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let l=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(l||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||D(this.#t))&&(this.#p(),this.#m()),this.#O();try{this.#v(),this.#y()}finally{this.#k()}let e=this.#t.length||this.#u.length?a():0;this.#T(e),this.#C(e),this.#A()}#D(){return this.#t.filter(e=>e.kind===`cover`)}#O(){this.#D().forEach(e=>this.#r.get(e)?.())}#k(){this.#D().forEach(e=>{let t=this.#u.find(({trigger:t})=>t===e.cover);this.#r.set(e,b(t?.outer??e.cover))})}#A(){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)}#j(e,t){let n=q.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.`)}#M(e,t,n){if($(e,t))throw Error(n)}#N(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.`)}#P(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 makes trigger itself position:sticky inside a box holding the pin range, so the container and every layer's dwell padding would be pinned along with it. Pin an element that doesn't contain the container.`)}#F(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#M(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.#M(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.#j(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#N(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#F({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.#j(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#N(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.#F(p,e=>{this.#r.get(p)?.(),c?.(e)},l);return this.#r.set(p,b(f)),m}createStickyPin({trigger:e,start:i,top:a,endTrigger:o,end:s=`bottom top`,onKill:c,...l}){if(this.#j(l,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(i!==void 0&&a!==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 u=t(e,`createStickyPin`),f=n(u,o,`createStickyPin`);this.#P(u,`createStickyPin`),this.#M(this.#u,u,`StickyScrollTrigger: ${r(u)} is already registered as a pin trigger.`),this.#M(this.#t,u,`StickyScrollTrigger: ${r(u)} 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 p={trigger:u,savedPosition:d(u),outer:null,inner:null,start:a===void 0?i??`top top`:Z(a),endTrigger:f,end:s};return this.#u.push(p),{...l,trigger:u,onKill:e=>{this.#g(e);let t=this.#u.indexOf(p);t!==-1&&this.#u.splice(t,1),this.#b(p)&&this.#h(),c?.(e)},onRefreshInit:this.#_(l.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),s=A(n),l=a();if(H(s))return o(l)+U(s,l);if(F(s))return I(s);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(c(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=L(s,r.offsetHeight,l),f=this.#x(),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=`top bottom`,end:i=`bottom top`,endTrigger:a,...o}){this.#j(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.#O(),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#b(e)),this.#u.length=0)}};export{ee as default};
|