sticky-scroll-trigger 0.7.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
|
@@ -147,6 +147,8 @@ Call them on the instance (`sticky.createStickyTrigger(...)`) rather than destru
|
|
|
147
147
|
|
|
148
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.
|
|
149
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
|
+
|
|
150
152
|
### `createStickyTrigger(options)`
|
|
151
153
|
|
|
152
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.
|
|
@@ -178,6 +180,8 @@ Registers an overlap-scroll effect (`trigger` gets pinned while its siblings fro
|
|
|
178
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" |
|
|
179
181
|
| `endTrigger` | `trigger` | Reference element when `end` uses position-clause syntax |
|
|
180
182
|
|
|
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
|
+
|
|
181
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.
|
|
182
186
|
|
|
183
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.
|
|
@@ -260,13 +264,13 @@ ScrollTrigger.create(
|
|
|
260
264
|
sticky.refresh();
|
|
261
265
|
```
|
|
262
266
|
|
|
263
|
-
| option | default
|
|
264
|
-
| ------------ |
|
|
265
|
-
| `trigger` | (required)
|
|
266
|
-
| `start` | `'top top'`
|
|
267
|
-
| `top` | `0`
|
|
268
|
-
| `endTrigger` |
|
|
269
|
-
| `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)) |
|
|
270
274
|
|
|
271
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.
|
|
272
276
|
|
|
@@ -274,6 +278,10 @@ That's why `start` throws on an [absolute scroll position](#absolute-scroll-posi
|
|
|
274
278
|
|
|
275
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.
|
|
276
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
|
+
|
|
277
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: ...`).
|
|
278
286
|
|
|
279
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.
|
|
@@ -296,12 +304,14 @@ gsap.to(plainBox, {
|
|
|
296
304
|
});
|
|
297
305
|
```
|
|
298
306
|
|
|
299
|
-
| option | default
|
|
300
|
-
| ------------ |
|
|
301
|
-
| `trigger` | (required)
|
|
302
|
-
| `start` |
|
|
303
|
-
| `end` |
|
|
304
|
-
| `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.
|
|
305
315
|
|
|
306
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`).
|
|
307
317
|
|
|
@@ -452,7 +462,7 @@ If the entire value is just a number (a plain JS number, or a string that's noth
|
|
|
452
462
|
|
|
453
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.
|
|
454
464
|
|
|
455
|
-
"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.
|
|
456
466
|
|
|
457
467
|
| example | meaning |
|
|
458
468
|
| -------------------------------- | ------------------------------------- |
|
|
@@ -500,7 +510,7 @@ sticky.createOverlapScroll({
|
|
|
500
510
|
- `createOverlapScroll`'s `trigger` and `cover` must be siblings sharing the same parent
|
|
501
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))
|
|
502
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
|
|
503
|
-
- `createStickyPin` works on either side of the container, and throws only for a `trigger` that encloses it (the container itself, or an ancestor). A pin
|
|
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
|
|
504
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
|
|
505
515
|
- ScrollTrigger's `pin`/`pinSpacing`/`anticipatePin` can't be used (pinning is handled by sticky; these are already excluded at the type level)
|
|
506
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))
|
|
@@ -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);
|
|
@@ -562,6 +562,11 @@ var StickyScrollTrigger = (function() {
|
|
|
562
562
|
};
|
|
563
563
|
return typeof top === "function" ? () => toClause(top()) : toClause(top);
|
|
564
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
|
+
};
|
|
565
570
|
const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
|
|
566
571
|
var StickyScrollTrigger = class {
|
|
567
572
|
#rootElement;
|
|
@@ -629,6 +634,24 @@ var StickyScrollTrigger = (function() {
|
|
|
629
634
|
layer.inner = wrapped.inner;
|
|
630
635
|
});
|
|
631
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
|
+
}
|
|
632
655
|
#unwrapPinLayer(layer) {
|
|
633
656
|
if (!layer.outer) return false;
|
|
634
657
|
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
@@ -690,7 +713,7 @@ var StickyScrollTrigger = (function() {
|
|
|
690
713
|
const triggerHeight = layer.trigger.offsetHeight;
|
|
691
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'.`);
|
|
692
715
|
const topPx = resolveAnchorTop(resolvedStart, triggerHeight, viewportHeight);
|
|
693
|
-
const height = (
|
|
716
|
+
const height = resolvePinReleaseTop(layer.endTrigger, resolvedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
|
|
694
717
|
applyStickyPosition(layer.trigger, topPx);
|
|
695
718
|
layer.inner.style.height = `${Math.max(0, height)}px`;
|
|
696
719
|
});
|
|
@@ -744,6 +767,7 @@ var StickyScrollTrigger = (function() {
|
|
|
744
767
|
this.#restoreCoverLifts();
|
|
745
768
|
try {
|
|
746
769
|
this.#wrapUnwrappedPins();
|
|
770
|
+
this.#reservePinSpace();
|
|
747
771
|
} finally {
|
|
748
772
|
this.#liftCovers();
|
|
749
773
|
}
|
|
@@ -786,7 +810,7 @@ var StickyScrollTrigger = (function() {
|
|
|
786
810
|
#assertTriggerNotEnclosingRoot(trigger, context) {
|
|
787
811
|
if (!trigger.contains(this.#rootElement)) return;
|
|
788
812
|
const relation = trigger === this.#rootElement ? "is the shared container itself" : "is an ancestor of the shared container";
|
|
789
|
-
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.`);
|
|
790
814
|
}
|
|
791
815
|
#registerLayer(layer, onKill, rest) {
|
|
792
816
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new layer after destroy() has been called.");
|
|
@@ -855,12 +879,12 @@ var StickyScrollTrigger = (function() {
|
|
|
855
879
|
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
856
880
|
return vars;
|
|
857
881
|
}
|
|
858
|
-
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "
|
|
882
|
+
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "bottom top", onKill, ...rest }) {
|
|
859
883
|
this.#assertNoExcludedVars(rest, "createStickyPin");
|
|
860
884
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new pin after destroy() has been called.");
|
|
861
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.");
|
|
862
886
|
const trigger = resolveElement(triggerInput, "createStickyPin");
|
|
863
|
-
const endTrigger =
|
|
887
|
+
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createStickyPin");
|
|
864
888
|
this.#assertTriggerNotEnclosingRoot(trigger, "createStickyPin");
|
|
865
889
|
this.#assertTriggerAvailable(this.#pinLayers, trigger, `StickyScrollTrigger: ${describeElement(trigger)} is already registered as a pin trigger.`);
|
|
866
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.`);
|
|
@@ -911,7 +935,7 @@ var StickyScrollTrigger = (function() {
|
|
|
911
935
|
if (owner) return owner.resolveScrollPosition(element, "top top");
|
|
912
936
|
return documentTop(element);
|
|
913
937
|
}
|
|
914
|
-
createResolvedTrigger({ trigger: triggerInput, start, end, endTrigger: endTriggerInput, ...rest }) {
|
|
938
|
+
createResolvedTrigger({ trigger: triggerInput, start = "top bottom", end = "bottom top", endTrigger: endTriggerInput, ...rest }) {
|
|
915
939
|
this.#assertNoExcludedVars(rest, "createResolvedTrigger");
|
|
916
940
|
const trigger = resolveElement(triggerInput, "createResolvedTrigger");
|
|
917
941
|
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createResolvedTrigger");
|
|
@@ -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()},_={position:`relative`,zIndex:`1`},v=new WeakMap,y=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=v.get(e);if(r)r.count+=1;else{let t=getComputedStyle(e),n=[];t.position===`static`&&n.push(`position`),t.zIndex===`auto`&&n.push(`zIndex`),n.forEach(t=>{e.style[t]=_[t]}),v.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=v.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===_[t]&&(e.style[t]=``)}),v.delete(e)))}),t.length=0}},b=0,x=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),S=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),C=x&&S,w=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},T=e=>{let t=`sst${b++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};C||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i&&=(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(e=>e!==i),null),a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),C?(i||(i=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,i]),i.replaceSync(w(t,h))):(o=h,c=p,l());let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){C||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},E=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},D=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},O=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},k=e=>typeof e==`function`?e():e,A={top:0,center:.5,bottom:1},j=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},M=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,N=(e,t)=>{let n=M.exec(e);if(!n||!n[1]&&!n[3])throw B.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in A,l=i===`%`;return{fraction:c?A[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?j(a,o,s,t):0)}},P=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),F=e=>typeof e==`number`?e:Number(e),I=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=N(i,t),s=N(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},L=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return j(void 0,r,i,t)},B=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,V=e=>typeof e==`string`&&B.test(e.trim()),H=(e,t)=>{let n=B.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?j(r,i,a,t):0},U=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},W=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+U(e,s,a,l.end.rawTop,u):t}let r=I(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},G=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=W(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=W(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},K=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],q=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(R(a))return{mode:`dwell`,distancePx:Math.max(0,z(a,t))};if(P(a))return{mode:`absolute`,value:F(a)};if(V(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:H(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},J=(e,t,n,i)=>{if(!P(t))return{mode:`clause`,anchorOffset:I(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:F(t)}},Y=(e,t,n,r,a)=>{let o=k(n.start),s=n.end===null?null:k(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=q(e,t,n,s,r,u),f=J(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},X=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},Z=(e,t)=>e.some(e=>e.trigger===t);return class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=T(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(O(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=D(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e){return t=>{this.#g(t);let n=e?.(t);return this.refresh(),n}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(e){return e.outer?(g(e.outer,e.trigger,e.savedPosition),e.outer=null,e.inner=null,!0):!1}#b(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#x(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#S(e){if(!this.#u.length)return;let t=this.#b(),n=this.#x();try{this.#C(e)}catch(e){throw n(),e}finally{t()}}#C(e){this.#u.forEach(t=>{if(!t.inner)return;let n=k(t.end);if(V(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=k(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(P(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=I(r,o,e),c=(P(n)?F(n):i(t.endTrigger)-I(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#w(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#b();try{this.#T(e,t)}catch(e){throw n(),e}}#T(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>Y(this.#e,e,t,n,r)),s=0,c=()=>G(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||E(this.#t))&&(this.#p(),this.#m()),this.#D();try{this.#v()}finally{this.#O()}let e=this.#t.length||this.#u.length?a():0;this.#w(e),this.#S(e),this.#k()}#E(){return this.#t.filter(e=>e.kind===`cover`)}#D(){this.#E().forEach(e=>this.#r.get(e)?.())}#O(){this.#E().forEach(e=>{let t=this.#u.find(({trigger:t})=>t===e.cover);this.#r.set(e,y(t?.outer??e.cover))})}#k(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#A(e,t){let n=K.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#j(e,t,n){if(Z(e,t))throw Error(n)}#M(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#N(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#P(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#j(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#j(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#A(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#M(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#P({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#A(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#M(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#P(p,e=>{this.#r.get(p)?.(),c?.(e)},l);return this.#r.set(p,y(f)),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#A(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#N(l,`createStickyPin`),this.#j(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#j(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:X(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),this.#y(f)&&this.#h(),s?.(e)},onRefreshInit:this.#_(c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=k(n),l=a();if(V(c))return o(l)+H(c,l);if(P(c))return F(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=I(c,r.offsetHeight,l),f=this.#b(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#A(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#D(),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#y(e)),this.#u.length=0)}}})();
|
|
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);
|
|
@@ -561,6 +561,11 @@ const topToStartClause = (top) => {
|
|
|
561
561
|
};
|
|
562
562
|
return typeof top === "function" ? () => toClause(top()) : toClause(top);
|
|
563
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
|
+
};
|
|
564
569
|
const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
|
|
565
570
|
var StickyScrollTrigger = class {
|
|
566
571
|
#rootElement;
|
|
@@ -628,6 +633,24 @@ var StickyScrollTrigger = class {
|
|
|
628
633
|
layer.inner = wrapped.inner;
|
|
629
634
|
});
|
|
630
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
|
+
}
|
|
631
654
|
#unwrapPinLayer(layer) {
|
|
632
655
|
if (!layer.outer) return false;
|
|
633
656
|
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
@@ -689,7 +712,7 @@ var StickyScrollTrigger = class {
|
|
|
689
712
|
const triggerHeight = layer.trigger.offsetHeight;
|
|
690
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'.`);
|
|
691
714
|
const topPx = resolveAnchorTop(resolvedStart, triggerHeight, viewportHeight);
|
|
692
|
-
const height = (
|
|
715
|
+
const height = resolvePinReleaseTop(layer.endTrigger, resolvedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
|
|
693
716
|
applyStickyPosition(layer.trigger, topPx);
|
|
694
717
|
layer.inner.style.height = `${Math.max(0, height)}px`;
|
|
695
718
|
});
|
|
@@ -743,6 +766,7 @@ var StickyScrollTrigger = class {
|
|
|
743
766
|
this.#restoreCoverLifts();
|
|
744
767
|
try {
|
|
745
768
|
this.#wrapUnwrappedPins();
|
|
769
|
+
this.#reservePinSpace();
|
|
746
770
|
} finally {
|
|
747
771
|
this.#liftCovers();
|
|
748
772
|
}
|
|
@@ -785,7 +809,7 @@ var StickyScrollTrigger = class {
|
|
|
785
809
|
#assertTriggerNotEnclosingRoot(trigger, context) {
|
|
786
810
|
if (!trigger.contains(this.#rootElement)) return;
|
|
787
811
|
const relation = trigger === this.#rootElement ? "is the shared container itself" : "is an ancestor of the shared container";
|
|
788
|
-
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.`);
|
|
789
813
|
}
|
|
790
814
|
#registerLayer(layer, onKill, rest) {
|
|
791
815
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new layer after destroy() has been called.");
|
|
@@ -854,12 +878,12 @@ var StickyScrollTrigger = class {
|
|
|
854
878
|
this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(coverElement));
|
|
855
879
|
return vars;
|
|
856
880
|
}
|
|
857
|
-
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "
|
|
881
|
+
createStickyPin({ trigger: triggerInput, start, top, endTrigger: endTriggerInput, end = "bottom top", onKill, ...rest }) {
|
|
858
882
|
this.#assertNoExcludedVars(rest, "createStickyPin");
|
|
859
883
|
if (this.#destroyed) throw new Error("StickyScrollTrigger: cannot register a new pin after destroy() has been called.");
|
|
860
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.");
|
|
861
885
|
const trigger = resolveElement(triggerInput, "createStickyPin");
|
|
862
|
-
const endTrigger =
|
|
886
|
+
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createStickyPin");
|
|
863
887
|
this.#assertTriggerNotEnclosingRoot(trigger, "createStickyPin");
|
|
864
888
|
this.#assertTriggerAvailable(this.#pinLayers, trigger, `StickyScrollTrigger: ${describeElement(trigger)} is already registered as a pin trigger.`);
|
|
865
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.`);
|
|
@@ -910,7 +934,7 @@ var StickyScrollTrigger = class {
|
|
|
910
934
|
if (owner) return owner.resolveScrollPosition(element, "top top");
|
|
911
935
|
return documentTop(element);
|
|
912
936
|
}
|
|
913
|
-
createResolvedTrigger({ trigger: triggerInput, start, end, endTrigger: endTriggerInput, ...rest }) {
|
|
937
|
+
createResolvedTrigger({ trigger: triggerInput, start = "top bottom", end = "bottom top", endTrigger: endTriggerInput, ...rest }) {
|
|
914
938
|
this.#assertNoExcludedVars(rest, "createResolvedTrigger");
|
|
915
939
|
const trigger = resolveElement(triggerInput, "createResolvedTrigger");
|
|
916
940
|
const endTrigger = resolveEndTrigger(trigger, endTriggerInput, "createResolvedTrigger");
|
|
@@ -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()},_={position:`relative`,zIndex:`1`},v=new WeakMap,y=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=v.get(e);if(r)r.count+=1;else{let t=getComputedStyle(e),n=[];t.position===`static`&&n.push(`position`),t.zIndex===`auto`&&n.push(`zIndex`),n.forEach(t=>{e.style[t]=_[t]}),v.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=v.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===_[t]&&(e.style[t]=``)}),v.delete(e)))}),t.length=0}};let b=0;const x=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),S=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),C=x&&S,w=(e,t)=>{let n=[],r=[],i=[],a=[];return t.forEach((t,o)=>{let s=`--${e}-c${o}`,c=`${e}-k${o}`;n.push(`@property ${s}{syntax:"<length>";inherits:true;initial-value:0px}`,`@keyframes ${c}{from{${s}:0px}to{${s}:${t.freezeEnd-t.freezeStart}px}}`),r.push(`${c} linear both`),i.push(`scroll(root block)`),a.push(`${t.freezeStart}px ${t.freezeEnd}px`)}),n.push(`@supports (animation-timeline: scroll()) {[data-${e}]{animation:${r.join(`,`)};animation-timeline:${i.join(`,`)};animation-range:${a.join(`,`)}}}`),n.join(``)},T=e=>{let t=`sst${b++}`,n=new WeakMap,r=new Set,i=null,a=null,o=[],c=null,l=()=>{if(!c)return;let e=window.scrollY;o.forEach((n,r)=>{let i=Math.min(Math.max(e-n.freezeStart,0),n.freezeEnd-n.freezeStart);c.style.setProperty(`--${t}-c${r}`,`${i}px`)})};C||window.addEventListener(`scroll`,l,{passive:!0});let u=e=>{let t=n.get(e);e.style.scrollMarginTop=t?t.inline:``},d=()=>{i&&=(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(e=>e!==i),null),a?.removeAttribute(`data-${t}`),a=null,o=[],c=null};return{sync(f,p,m){let h=f.filter(e=>e.freezeEnd>e.freezeStart);if(m===null||!h.length||!p){r.forEach(u),r=new Set,d();return}a!==p&&(a?.removeAttribute(`data-${t}`),a=p,a.setAttribute(`data-${t}`,``)),C?(i||(i=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,i]),i.replaceSync(w(t,h))):(o=h,c=p,l());let g=Array.from(e.querySelectorAll(m));g.forEach(e=>{let t=n.get(e);t?r.has(e)&&(e.style.scrollMarginTop=t.inline):n.set(e,{inline:e.style.scrollMarginTop})});let _=h.map((e,n)=>`var(--${t}-c${n}, 0px)`).join(` + `);g.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;h.forEach(t=>{s(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${_} - ${n}px)`});let v=new Set(g);r.forEach(e=>{v.has(e)||u(e)}),r=v},restore(){C||window.removeEventListener(`scroll`,l),r.forEach(u),r=new Set,d()}}},E=e=>{for(let t=1;t<e.length;t+=1)if(s(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},D=(e,t)=>{t.sort((e,t)=>s(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=p(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=f(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},O=(e,t,n)=>{n&&(n.parentNode?.insertBefore(e,n),n.remove());for(let e=t.length-1;e>=0;--e){let n=t[e];n.kind===`cover`&&n.wrapper&&m(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},k=e=>typeof e==`function`?e():e,A={top:0,center:.5,bottom:1},j=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},M=/^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,N=(e,t)=>{let n=M.exec(e);if(!n||!n[1]&&!n[3])throw B.test(e)?Error(`StickyScrollTrigger: unsupported position clause "${e}": 'max' is GSAP's end-only keyword for the scroller's maximum scroll position.`):Error(`StickyScrollTrigger: unsupported position clause "${e}"`);let[,r,i,a,o,s]=n;if(r!==void 0&&a&&!a.includes(`=`)){let t=`${r}${i??``}${a}=${o}${s??``}`;throw Error(`StickyScrollTrigger: unsupported position clause "${e}": a signed offset needs an explicit '=' when it follows a keyword or number (GSAP needs it to tell "${r}" from the offset). Did you mean "${t}"?`)}let c=r!==void 0&&r in A,l=i===`%`;return{fraction:c?A[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?j(a,o,s,t):0)}},P=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),F=e=>typeof e==`number`?e:Number(e),I=(e,t,n)=>{let r=e.trim();if(r.startsWith(`clamp(`)){let e=r.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${r}": GSAP's clamp() wrapper isn't supported here.`+(e?` Did you mean "${e}"?`:``))}let[i,a=`top`]=r.split(/\s+/),o=N(i,t),s=N(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},L=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,R=e=>typeof e==`string`&&L.test(e.trim()),z=(e,t)=>{let n=L.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return j(void 0,r,i,t)},B=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,V=e=>typeof e==`string`&&B.test(e.trim()),H=(e,t)=>{let n=B.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?j(r,i,a,t):0},U=(e,t,n,r,i)=>{let a=0;return e.forEach((e,o)=>{if(o===i||e.triggerTop>=r)return;let s=t[o]===void 0?n?n.paddings[o]:null:t[o];s!=null&&(a+=s)}),a},W=(e,{viewportHeight:t,structureTop:n,documentMaxScroll:r,measureLiveEndTriggerTop:i},a)=>{let o=[],s=[],c=0;return{plans:e.map((l,u)=>{let d=l.triggerTop+c,f=l.start.mode===`absolute`?l.start.value:d-l.start.anchorOffset,p;switch(l.end.mode){case`auto`:if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: an absolute start reached 'auto' end mode, which resolveStartSpec should have already rejected.`);p=f+Math.max(0,l.start.anchorOffset+(l.coverTop-l.triggerTop));break;case`dwell`:p=f+l.end.distancePx;break;case`absolute`:p=Math.max(f,l.end.value);break;case`max`:p=Math.max(f,r+l.end.offsetPx);break;case`clause`:{let n;if(l.endTriggerIsSelf)n=d;else{let t=l.endTriggerIndex===null?void 0:o[l.endTriggerIndex]===void 0?a?a.naturalTops[l.endTriggerIndex]:void 0:o[l.endTriggerIndex];n=t===void 0?l.end.measureLive?i(u):l.end.rawTop===null?0:l.end.rawTop+U(e,s,a,l.end.rawTop,u):t}let r=I(l.end.clause,l.endTriggerHeight,t);p=Math.max(f,n-r);break}}let m;if(l.kind===`cover`){if(l.start.mode!==`clause`)throw Error(`StickyScrollTrigger: internal error: a cover layer measurement carries an absolute start, which resolveStartSpec should have already rejected.`);m={freezeStart:f,freezeEnd:p,stickyTop:l.start.anchorOffset-(l.triggerTop-l.wrapperTop),paddingHeight:null}}else m={freezeStart:f,freezeEnd:p,stickyTop:n-f,paddingHeight:Math.max(0,p-f)};return m.paddingHeight!==null&&(c+=m.paddingHeight),o[u]=d,s[u]=m.paddingHeight,m}),naturalTops:o}},G=(e,t)=>{let n=e.some((e,t)=>e.end.mode!==`clause`||e.endTriggerIsSelf?!1:e.endTriggerIndex===null?e.end.rawTop!==null:e.endTriggerIndex>=t),r=new Map,i={...t,measureLiveEndTriggerTop:e=>{let n=r.get(e);if(n!==void 0)return n;let i=t.measureLiveEndTriggerTop(e);return r.set(e,i),i}},{plans:a,naturalTops:o}=W(e,i,null);if(n)for(let t=0;t<e.length;t+=1){let n={paddings:a.map(e=>e.paddingHeight),naturalTops:o},r=W(e,i,n),s=r.plans.every((e,t)=>e.paddingHeight===a[t].paddingHeight);if(a=r.plans,o=r.naturalTops,s)break;if(t===e.length-1)throw Error(`StickyScrollTrigger: could not resolve endTrigger positions: some endTrigger references form a circular structural dependency, each layer's end depending on a layer whose own end depends back on it. Point each endTrigger at a layer that doesn't depend on it.`)}return a.forEach((e,n)=>t.onPlanned(n,e)),a},K=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],q=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};if(R(a))return{mode:`dwell`,distancePx:Math.max(0,z(a,t))};if(P(a))return{mode:`absolute`,value:F(a)};if(V(a)){if(n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has end "${a}". GSAP's 'max' keyword isn't supported here: the layer's own dwell padding adds to the document's max scroll position, so the freeze window would depend on itself. Use createOverlapScroll, which adds no padding, or a dwell distance such as '+=500'.`);return{mode:`max`,offsetPx:H(a,t)}}if(n.kind!==`cover`&&s!==null&&s>o)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)}'s endTrigger (${r(n.endTrigger)}) refers to a layer positioned later in DOM order, which isn't supported: this layer's own dwell padding pushes that one down, so the freeze window would depend on its own dwell. Point endTrigger at a layer earlier in DOM order, or use a dwell distance such as '+=500'.`);let c=s===null,l=e.contains(n.endTrigger);if(c&&!l&&n.kind!==`cover`)throw Error(`StickyScrollTrigger: createStickyTrigger's trigger ${r(n.trigger)} has an endTrigger (${r(n.endTrigger)}) outside the shared container: the layer's own dwell keeps pushing it away, so the freeze window never settles. Point endTrigger at an element inside the container, or use a dwell distance such as '+=500'.`);return{mode:`clause`,clause:a,rawTop:c&&l?i(n.endTrigger):null,measureLive:c&&!l}},J=(e,t,n,i)=>{if(!P(t))return{mode:`clause`,anchorOffset:I(t,n,i)};if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:F(t)}},Y=(e,t,n,r,a)=>{let o=k(n.start),s=n.end===null?null:k(n.end),c=n.trigger.offsetHeight,l=n.endTrigger===n.trigger,u=a.get(n.endTrigger)??null,d=q(e,t,n,s,r,u),f=J(n,o,c,t);return{kind:n.kind,start:f,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:d,endTriggerIsSelf:l,endTriggerIndex:u,endTriggerHeight:d.mode===`clause`?n.endTrigger.offsetHeight:0}},X=e=>{let t=e=>{if(!Number.isFinite(e))throw Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${e}.`);return`top ${e}px`};return typeof e==`function`?()=>t(e()):t(e)},Z=(e,t)=>e.some(e=>e.trigger===t);var Q=class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;#f;constructor(t,n={}){if(this.#e=e(t),this.#d=T(this.#e),this.#f=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets,this.#f!==null)try{this.#e.querySelectorAll(this.#f)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${this.#f}" is not a valid CSS selector.`)}}#p(){this.#i&&=(O(this.#e,this.#n,this.#o),this.#o=null,!1)}#m(){this.#o=D(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#h(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#g(e){this.#l=e.constructor}#_(e){return t=>{this.#g(t);let n=e?.(t);return this.refresh(),n}}#v(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=u(e.trigger);let t=h(e.trigger);e.outer=t.outer,e.inner=t.inner})}#y(e){return e.outer?(g(e.outer,e.trigger,e.savedPosition),e.outer=null,e.inner=null,!0):!1}#b(){let e=this.#t.map(e=>e.wrapper).filter(e=>e!==null).map(e=>({wrapper:e,position:e.style.position,top:e.style.top}));return e.forEach(({wrapper:e})=>c(e)),()=>{e.forEach(({wrapper:e,position:t,top:n})=>{e.style.position=t,e.style.top=n})}}#x(){let e=this.#u.map(e=>({layer:e,position:u(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{c(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{d(e.trigger,t),e.inner&&(e.inner.style.height=n)})}}#S(e){if(!this.#u.length)return;let t=this.#b(),n=this.#x();try{this.#C(e)}catch(e){throw n(),e}finally{t()}}#C(e){this.#u.forEach(t=>{if(!t.inner)return;let n=k(t.end);if(V(n))throw Error(`StickyScrollTrigger: createStickyPin's end "${n}" uses GSAP's 'max' keyword, which isn't supported here: the pin's own spacer height adds to the document's max scroll position, so it would depend on itself. Use a position clause against endTrigger, such as 'top top'.`);let r=k(t.start),a=i(t.trigger),o=t.trigger.offsetHeight;if(P(r))throw Error(`StickyScrollTrigger: createStickyPin's start "${r}" is an absolute scroll position (GSAP reads any bare number this way). A pin can't act on one: it engages when position:sticky engages, so start says where trigger sits in the viewport while pinned. Use the top option (top: ${r}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let s=I(r,o,e),c=(P(n)?F(n):i(t.endTrigger)-I(n,t.endTrigger.offsetHeight,e))-a+s+o;l(t.trigger,s),t.inner.style.height=`${Math.max(0,c)}px`})}#w(e){if(!this.#t.length)return;let t=this.#t.filter(e=>e.wrapper!==null);if(!t.length)return;let n=this.#b();try{this.#T(e,t)}catch(e){throw n(),e}}#T(e,t){let n=this.#o?i(this.#o):0,r=new Map;t.forEach((e,t)=>{r.set(e.trigger,t)});let a=t.map((t,n)=>Y(this.#e,e,t,n,r)),s=0,c=()=>G(a,{viewportHeight:e,structureTop:n,documentMaxScroll:s,measureLiveEndTriggerTop:e=>i(t[e].endTrigger),onPlanned:(e,n)=>{let r=t[e];r.freezeStart=n.freezeStart,r.freezeEnd=n.freezeEnd,r.wrapper&&(l(r.wrapper,n.stickyTop),r.kind===`scene`&&r.padding&&n.paddingHeight!==null&&(r.padding.style.height=`${n.paddingHeight}px`))}});c();let u=a.some(e=>e.end.mode===`clause`&&e.end.measureLive),d=a.some(e=>e.end.mode===`max`);d&&(s=o(e)),(u||d)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||E(this.#t))&&(this.#p(),this.#m()),this.#D();try{this.#v()}finally{this.#O()}let e=this.#t.length||this.#u.length?a():0;this.#w(e),this.#S(e),this.#k()}#E(){return this.#t.filter(e=>e.kind===`cover`)}#D(){this.#E().forEach(e=>this.#r.get(e)?.())}#O(){this.#E().forEach(e=>{let t=this.#u.find(({trigger:t})=>t===e.cover);this.#r.set(e,y(t?.outer??e.cover))})}#k(){this.#d.sync(this.#t.filter(e=>e.kind===`scene`).map(({trigger:e,freezeStart:t,freezeEnd:n})=>({trigger:e,freezeStart:t,freezeEnd:n})),this.#o,this.#f)}#A(e,t){let n=K.filter(t=>t in e);if(n.length!==0)throw Error(`${t}: ${n.join(`, `)} ${n.length>1?`are`:`is`} not supported here; this module handles pinning and the scroll axis itself.`)}#j(e,t,n){if(Z(e,t))throw Error(n)}#M(e,t){if(e===this.#e)throw Error(`${t}: trigger ${r(e)} is the shared container itself. Point trigger at an element inside the container.`);if(!this.#e.contains(e))throw Error(`${t}: trigger ${r(e)} is outside the shared container. Point trigger at an element inside it, or use createStickyPin, which works on either side.`)}#N(e,t){if(!e.contains(this.#e))return;let n=e===this.#e?`is the shared container itself`:`is an ancestor of the shared container`;throw Error(`${t}: trigger ${r(e)} ${n}. A pin wraps trigger in a height:0, contain:layout box, which would pull the container and every layer's dwell padding out of the flow. Pin an element that doesn't contain the container.`)}#P(e,t,n){if(this.#s)throw Error(`StickyScrollTrigger: cannot register a new layer after destroy() has been called.`);return this.#j(this.#t,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a trigger for another layer. Each element can be used once per controller instance, across createStickyTrigger and createOverlapScroll: reusing one makes endTrigger resolution ambiguous.`),this.#j(this.#u,e.trigger,`StickyScrollTrigger: ${r(e.trigger)} is already registered as a pin trigger (createStickyPin). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`),this.#t.push(e),this.#a=!0,{...n,trigger:e.trigger,start:()=>e.freezeStart,end:()=>e.freezeEnd||.001,invalidateOnRefresh:n.invalidateOnRefresh??!0,onKill:n=>{this.#g(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#h(),t?.(n)},onRefreshInit:this.#_(n.onRefreshInit)}}createStickyTrigger({trigger:e,start:r=`0 0`,end:i=`100% 0`,endTrigger:a,onKill:o,...s}){this.#A(s,`createStickyTrigger`);let c=t(e,`createStickyTrigger`);this.#M(c,`createStickyTrigger`);let l=n(c,a,`createStickyTrigger`);return this.#P({kind:`scene`,trigger:c,endTrigger:l,container:null,wrapper:null,padding:null,start:r,end:i,freezeStart:0,freezeEnd:0},o,s)}createOverlapScroll({trigger:e,cover:i,start:a=`bottom bottom`,end:o=null,endTrigger:s,onKill:c,...l}){this.#A(l,`createOverlapScroll`);let u=t(e,`createOverlapScroll`);this.#M(u,`createOverlapScroll`);let d=n(u,s,`createOverlapScroll`),f=i===void 0?u.nextElementSibling:t(i,`createOverlapScroll`);if(!(f instanceof HTMLElement))throw Error(`createOverlapScroll: cover element (trigger.nextElementSibling) not found for trigger ${r(u)}`);if(f.parentNode!==u.parentNode)throw Error(`createOverlapScroll: cover ${r(f)} must be a sibling of trigger `+r(u));let p={kind:`cover`,trigger:u,endTrigger:d,cover:f,wrapper:null,start:a,end:o,freezeStart:0,freezeEnd:0},m=this.#P(p,e=>{this.#r.get(p)?.(),c?.(e)},l);return this.#r.set(p,y(f)),m}createStickyPin({trigger:e,start:n,top:i,endTrigger:a,end:o=`top top`,onKill:s,...c}){if(this.#A(c,`createStickyPin`),this.#s)throw Error(`StickyScrollTrigger: cannot register a new pin after destroy() has been called.`);if(n!==void 0&&i!==void 0)throw Error(`StickyScrollTrigger: createStickyPin accepts either start or top, not both (top: 20 is start: 'top 20px'). Use top for a plain px distance from the viewport's top edge, start for anything else.`);let l=t(e,`createStickyPin`),d=t(a,`createStickyPin`);this.#N(l,`createStickyPin`),this.#j(this.#u,l,`StickyScrollTrigger: ${r(l)} is already registered as a pin trigger.`),this.#j(this.#t,l,`StickyScrollTrigger: ${r(l)} is already registered as a trigger for another layer (createStickyTrigger/createOverlapScroll). Using the same element as both a Scene/Cover trigger and a pin trigger wraps it twice and produces conflicting position:sticky behavior.`);let f={trigger:l,savedPosition:u(l),outer:null,inner:null,start:i===void 0?n??`top top`:X(i),endTrigger:d,end:o};return this.#u.push(f),{...c,trigger:l,onKill:e=>{this.#g(e);let t=this.#u.indexOf(f);t!==-1&&this.#u.splice(t,1),this.#y(f)&&this.#h(),s?.(e)},onRefreshInit:this.#_(c.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),c=k(n),l=a();if(V(c))return o(l)+H(c,l);if(P(c))return F(c);let u=0;this.#t.forEach(e=>{e.kind===`scene`&&(s(e.trigger,r)>=0||(u+=e.freezeEnd-e.freezeStart))});let d=I(c,r.offsetHeight,l),f=this.#b(),p=i(r)+u-d;return f(),p}static getScrollTop(e,n){let r=t(e,`StickyScrollTrigger.getScrollTop`),a=n.find(e=>e.#e.contains(r));return a?a.resolveScrollPosition(r,`top top`):i(r)}createResolvedTrigger({trigger:e,start:r,end:i,endTrigger:a,...o}){this.#A(o,`createResolvedTrigger`);let s=t(e,`createResolvedTrigger`),c=n(s,a,`createResolvedTrigger`);return{...o,trigger:s,start:()=>this.resolveScrollPosition(s,r),end:()=>this.resolveScrollPosition(c,i)}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#D(),this.#p(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#y(e)),this.#u.length=0)}};export{Q as default};
|
|
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};
|