sticky-scroll-trigger 0.8.0 → 0.9.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
@@ -36,7 +36,7 @@ npm install gsap sticky-scroll-trigger
36
36
  For plain `<script>` usage without a bundler, an IIFE build is also published, exposing `window.StickyScrollTrigger`:
37
37
 
38
38
  ```html
39
- <script src="https://cdn.jsdelivr.net/npm/sticky-scroll-trigger/dist/StickyScrollTrigger.global.min.js"></script>
39
+ <script src="https://cdn.jsdelivr.net/npm/sticky-scroll-trigger@0.9.0/dist/StickyScrollTrigger.global.min.js"></script>
40
40
  ```
41
41
 
42
42
  Consumers should only rely on the exports of `sticky-scroll-trigger` (or `window.StickyScrollTrigger` for the global build). The internal modules under `src/` are not part of the public API.
@@ -425,7 +425,7 @@ Pinning decouples an element's position in the document from the scroll position
425
425
  | token | example | meaning |
426
426
  | ----------- | --------------------------- | ------------------------------------------------------------- |
427
427
  | keyword | `top` / `center` / `bottom` | 0% / 50% / 100% |
428
- | bare number | `80` / `80px` | 80px from the reference point (matches GSAP: only `%` scales) |
428
+ | bare number | `80` / `80px` / `-50` | ± px from the reference point (matches GSAP: only `%` scales) |
429
429
  | percentage | `80%` | 80% of the target's height |
430
430
  | px offset | `center+=50` / `top-=20` | ± px from the reference point |
431
431
  | % offset | `top+=10%` | ± (relative to the target's height) |
@@ -436,7 +436,9 @@ Pinning decouples an element's position in the document from the scroll position
436
436
  start: () => `center center+=${getHeaderHeight() / 2}`,
437
437
  ```
438
438
 
439
- A px/% offset needs the `=` when it follows a keyword or number (`top+=50`, `80-=10%`), because GSAP uses the `=` itself to split the base from the offset. `top+50` isn't recognized syntax: GSAP silently resolves it to 0, treating the whole string as unparseable, while this module throws instead. Without a base, the `=` is optional (`+=500` and `+500` are equivalent), since there's nothing to split it from.
439
+ A px/% offset needs the `=` when it follows a keyword or number (`top+=50`, `80-=10%`), because GSAP uses the `=` itself to split the base from the offset. `top+50` isn't recognized syntax: GSAP silently resolves it to 0, treating the whole string as unparseable, while this module throws instead. Without a base, the `=` is optional (`+=500` and `+500` are equivalent), since there's nothing to split it from. A signed number is a base like any other and can carry an offset of its own: `-50+=100` is 50px from the reference point, because GSAP splits at the `=` and reads everything before it with `parseFloat`.
440
+
441
+ A token carrying `%` on both the base and the offset (`'50%+=10%'`) is one deliberate divergence. GSAP scales the offset only when the token's first `%` sits after the `=`, so a `%` base hides the offset's own and leaves it a plain px value: against a 400px element, GSAP reads `'50%+=10%'` as 210 where this module reads 240. Both units are honored here rather than reproducing that.
440
442
 
441
443
  A trailing `px` (`top 100px`, `center+=50px`) is accepted and ignored, the same idea as GSAP's own `_offsetToPx`, which only special-cases `%` and otherwise passes the value through `parseFloat`. This module isn't as lenient as GSAP toward other unrecognized suffixes, though: an actually-unsupported unit like `top 100vh` still throws, rather than silently behaving like `top 100`.
442
444
 
@@ -446,7 +448,7 @@ GSAP passes the `ScrollTrigger` instance to its own function-valued `start`/`end
446
448
 
447
449
  ### Absolute scroll position
448
450
 
449
- If the entire value is just a number (a plain JS number, or a string that's nothing but digits, with no keyword, second token, or `%`/`px` suffix), GSAP treats it as an absolute scroll position rather than a clause, and ignores the reference element entirely (`ScrollTrigger.js`'s `_parsePosition`: `isNaN(value) || (value = +value)`). This module follows the same rule for `start` and `end`, and for [`createStickyPin`](#createstickypinoptions)'s `end`, [`createResolvedTrigger`](#createresolvedtriggeroptions)'s `start`/`end`, and [`resolveScrollPosition`](#resolvescrollpositionelement-position)'s `position`.
451
+ GSAP treats a value as an absolute scroll position rather than a clause whenever it's just a number: a plain JS number, or a string `Number()` converts on its own with no keyword, second token, or `%`/`px` suffix, `'-50'` and `'1e3'` included. It ignores the reference element entirely in that case (`ScrollTrigger.js`'s `_parsePosition`: `isNaN(value) || (value = +value)`). This module follows the same rule for `start` and `end`, and for [`createStickyPin`](#createstickypinoptions)'s `end`, [`createResolvedTrigger`](#createresolvedtriggeroptions)'s `start`/`end`, and [`resolveScrollPosition`](#resolvescrollpositionelement-position)'s `position`.
450
452
 
451
453
  `start: '500'` (or `start: 500`) freezes starting at absolute scroll position 500px, ignoring the trigger's natural position and any preceding dwell. `end: '500'` ends the freeze window at 500px the same way, clamped to `start` if that would put `end` before it, matching GSAP's own `end = Math.max(start, ...)`.
452
454
 
@@ -462,7 +464,7 @@ If the entire value is just a number (a plain JS number, or a string that's noth
462
464
 
463
465
  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.
464
466
 
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.
467
+ "Dwell distance": how many px to keep pinning after the freeze starts. Matching GSAP, only a string starting with the literal `'+='` prefix and holding no space counts (or a `%`-suffixed `'+=...'`, resolved against the viewport height). A leading `-=`/`+`/`-` without `=`, or a `%` without `+=`, is a position clause instead (see below), as is a `'+='` value with a space in it. A dwell `end` never consults `endTrigger`, again matching GSAP: the distance runs from wherever the freeze starts, or from the resolved `start` in [`createResolvedTrigger`](#createresolvedtriggeroptions), which has no freeze window.
466
468
 
467
469
  | example | meaning |
468
470
  | -------------------------------- | ------------------------------------- |
@@ -481,6 +483,10 @@ sticky.createStickyTrigger({
481
483
  });
482
484
  ```
483
485
 
486
+ A `'+='` value with a space in it (`'+=100 bottom'`) is a position clause too, and GSAP gives it a base before resolving it: the element token from `start`. So `start: 'bottom bottom'` with `end: '+=100 bottom'` reads as `'bottom+=100 bottom'`, 100px past `endTrigger`'s own bottom edge. A `'top'` or `'0'` element token contributes nothing, which covers the `start` defaults of [`createStickyTrigger`](#createstickytriggeroptions) (`'0 0'`), [`createStickyPin`](#createstickypinoptions) (`'top top'`) and [`createResolvedTrigger`](#createresolvedtriggeroptions) (`'top bottom'`). [`createOverlapScroll`](#createoverlapscrolloptions) is the exception: its `'bottom bottom'` default puts a full `endTrigger` height into this `end` form even when the caller never passes `start`. Every method that takes a `start` and an `end` does this prefixing itself, since it resolves both sides into numbers before GSAP ever sees them.
487
+
488
+ One pair can't compose: a `start` whose element token already carries an offset (`'top+=50 bottom'`) throws. GSAP splits a token at its first `=`, so it would keep the `50` and silently discard the `end`'s own offset. A signed number (`'-50 top'`) composes normally, matching GSAP.
489
+
484
490
  If `endTrigger` points to another registered layer, its position is resolved using the same computation this module already does for that layer. A forward reference (pointing to a layer later in DOM order) only works from `createOverlapScroll`'s cover layer, which adds no padding and so doesn't depend on its own dwell. A `createStickyTrigger` Scene layer throws immediately instead: its own dwell padding pushes down everything after it, so the reference would depend on that dwell and never converge.
485
491
 
486
492
  For an unregistered `endTrigger`, its raw DOM position is measured directly, then adjusted by the dwell of every registered Scene layer structurally positioned before it, including ones registered after this call, if their `trigger` sits between this layer's `trigger` and `endTrigger`.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @license
3
- * StickyScrollTrigger v0.8.0
3
+ * StickyScrollTrigger v0.9.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
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @license
3
- * StickyScrollTrigger v0.8.0
3
+ * StickyScrollTrigger v0.9.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,7 +52,15 @@ 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
+ const measureBorderWidth = (borderStyle, width) => borderStyle === "none" || borderStyle === "hidden" ? 0 : parseFloat(width);
56
+ const measureUsedHeight = (el) => {
57
+ const rounded = el.offsetHeight;
58
+ const style = getComputedStyle(el);
59
+ const height = parseFloat(style.height);
60
+ if (!Number.isFinite(height)) return rounded;
61
+ const measured = style.boxSizing === "border-box" ? height : height + parseFloat(style.paddingTop) + parseFloat(style.paddingBottom) + measureBorderWidth(style.borderTopStyle, style.borderTopWidth) + measureBorderWidth(style.borderBottomStyle, style.borderBottomWidth);
62
+ return rounded > 0 && Math.abs(measured - rounded) >= 1 ? rounded : measured;
63
+ };
56
64
  const compareDocumentOrder = (a, b) => {
57
65
  const position = a.compareDocumentPosition(b);
58
66
  if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
@@ -191,8 +199,9 @@ var StickyScrollTrigger = (function() {
191
199
  declarations.push(`@supports (animation-timeline: scroll()) {[data-${instanceId}]{animation:${animations.join(",")};animation-timeline:${timelines.join(",")};animation-range:${ranges.join(",")}}}`);
192
200
  return declarations.join("");
193
201
  };
194
- const createScrollMarginSync = (rootElement) => {
202
+ const createScrollMarginSync = (rootElement, targetSelector) => {
195
203
  const instanceId = `sst${nextInstanceSuffix++}`;
204
+ const usesJsRamp = !usesCssRamp && targetSelector !== null;
196
205
  const snapshots = new WeakMap();
197
206
  let written = new Set();
198
207
  let sheet = null;
@@ -207,7 +216,7 @@ var StickyScrollTrigger = (function() {
207
216
  jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
208
217
  });
209
218
  };
210
- if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
219
+ if (usesJsRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
211
220
  const restoreTarget = (target) => {
212
221
  const snapshot = snapshots.get(target);
213
222
  target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
@@ -223,7 +232,7 @@ var StickyScrollTrigger = (function() {
223
232
  jsHost = null;
224
233
  };
225
234
  return {
226
- sync(scenes, host, targetSelector) {
235
+ sync(scenes, host) {
227
236
  const ramps = scenes.filter((scene) => scene.freezeEnd > scene.freezeStart);
228
237
  if (targetSelector === null || !ramps.length || !host) {
229
238
  written.forEach(restoreTarget);
@@ -236,7 +245,7 @@ var StickyScrollTrigger = (function() {
236
245
  animationHost = host;
237
246
  animationHost.setAttribute(`data-${instanceId}`, "");
238
247
  }
239
- if (!usesCssRamp) {
248
+ if (usesJsRamp) {
240
249
  jsRamps = ramps;
241
250
  jsHost = host;
242
251
  applyJsRamp();
@@ -270,7 +279,7 @@ var StickyScrollTrigger = (function() {
270
279
  written = next;
271
280
  },
272
281
  restore() {
273
- if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
282
+ if (usesJsRamp) window.removeEventListener("scroll", applyJsRamp);
274
283
  written.forEach(restoreTarget);
275
284
  written = new Set();
276
285
  clearAnimation();
@@ -327,7 +336,7 @@ var StickyScrollTrigger = (function() {
327
336
  const magnitude = unit === "%" ? parseFloat(value) / 100 * refSize : parseFloat(value);
328
337
  return sign?.startsWith("-") ? -magnitude : magnitude;
329
338
  };
330
- const CLAUSE_TOKEN_RE = /^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/;
339
+ const CLAUSE_TOKEN_RE = /^(top|center|bottom|[+-]?(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/;
331
340
  const parseClauseToken = (token, refSize) => {
332
341
  const match = CLAUSE_TOKEN_RE.exec(token);
333
342
  if (!match || !match[1] && !match[3]) {
@@ -352,12 +361,14 @@ var StickyScrollTrigger = (function() {
352
361
  };
353
362
  const resolveAbsolute = (resolved) => typeof resolved === "number" ? resolved : Number(resolved);
354
363
  const CLAMP_PREFIX = "clamp(";
364
+ const assertNotClamped = (trimmed) => {
365
+ if (!trimmed.startsWith(CLAMP_PREFIX)) return;
366
+ const inner = trimmed.slice(6).replace(/\)$/, "").trim();
367
+ throw new Error(`StickyScrollTrigger: unsupported position clause "${trimmed}": GSAP's clamp() wrapper isn't supported here.` + (inner ? ` Did you mean "${inner}"?` : ""));
368
+ };
355
369
  const resolveAnchorTop = (position, elementHeight, viewportHeight) => {
356
370
  const trimmed = position.trim();
357
- if (trimmed.startsWith(CLAMP_PREFIX)) {
358
- const inner = trimmed.slice(6).replace(/\)$/, "").trim();
359
- throw new Error(`StickyScrollTrigger: unsupported position clause "${trimmed}": GSAP's clamp() wrapper isn't supported here.` + (inner ? ` Did you mean "${inner}"?` : ""));
360
- }
371
+ assertNotClamped(trimmed);
361
372
  const [elementToken, viewportToken = "top"] = trimmed.split(/\s+/);
362
373
  const elementClause = parseClauseToken(elementToken, elementHeight);
363
374
  const viewportClause = parseClauseToken(viewportToken, viewportHeight);
@@ -365,6 +376,25 @@ var StickyScrollTrigger = (function() {
365
376
  };
366
377
  const DWELL_RELATIVE_RE = /^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/;
367
378
  const isDwellFormat = (resolved) => typeof resolved === "string" && DWELL_RELATIVE_RE.test(resolved.trim());
379
+ const prefixSpacedRelativeEnd = (start, endResolved) => {
380
+ if (typeof endResolved !== "string") return endResolved;
381
+ const trimmedEnd = endResolved.trim();
382
+ if (!trimmedEnd.startsWith("+=") || !/\s/.test(trimmedEnd)) return endResolved;
383
+ const startResolved = resolveMaybeFn(start);
384
+ if (typeof startResolved !== "string") return endResolved;
385
+ const trimmedStart = startResolved.trim();
386
+ assertNotClamped(trimmedStart);
387
+ const [elementToken] = trimmedStart.split(/\s+/);
388
+ try {
389
+ parseClauseToken(elementToken, 0);
390
+ } catch (error) {
391
+ if (!isAbsoluteFormat(startResolved)) throw error;
392
+ return endResolved;
393
+ }
394
+ parseClauseToken(trimmedEnd.split(/\s+/)[0], 0);
395
+ if (elementToken.includes("=")) throw new Error(`StickyScrollTrigger: end "${endResolved}" can't be resolved against start "${startResolved}": GSAP reads an end that starts with '+=' and holds a space by prefixing it with the start clause's element token, and "${elementToken}" carries an offset of its own, which GSAP resolves by discarding the end's. Give end a complete position clause instead, such as 'top+=100 bottom'.`);
396
+ return elementToken + trimmedEnd;
397
+ };
368
398
  const resolveDwell = (resolved, viewportHeight) => {
369
399
  const match = DWELL_RELATIVE_RE.exec(String(resolved).trim());
370
400
  if (!match) throw new Error(`StickyScrollTrigger: unsupported end format "${resolved}"`);
@@ -379,6 +409,28 @@ var StickyScrollTrigger = (function() {
379
409
  const [, sign, value, unit] = match;
380
410
  return sign ? signedPx(sign, value, unit, viewportHeight) : 0;
381
411
  };
412
+ const classifyPosition = (resolved) => {
413
+ if (typeof resolved === "number") return {
414
+ kind: "absolute",
415
+ value: resolved
416
+ };
417
+ if (isDwellFormat(resolved)) return {
418
+ kind: "dwell",
419
+ value: resolved
420
+ };
421
+ if (isMaxFormat(resolved)) return {
422
+ kind: "max",
423
+ value: resolved
424
+ };
425
+ if (isAbsoluteFormat(resolved)) return {
426
+ kind: "absolute",
427
+ value: resolveAbsolute(resolved)
428
+ };
429
+ return {
430
+ kind: "clause",
431
+ value: resolved
432
+ };
433
+ };
382
434
  const gapsBeforeRawPosition = (measurements, paddingHeightsSoFar, previous, rawPosition, ownIndex) => {
383
435
  let total = 0;
384
436
  measurements.forEach((measurement, i) => {
@@ -480,65 +532,59 @@ var StickyScrollTrigger = (function() {
480
532
  plans.forEach((plan, index) => deps.onPlanned(index, plan));
481
533
  return plans;
482
534
  };
483
- const EXCLUDED_VAR_KEYS = [
484
- "trigger",
485
- "start",
486
- "end",
487
- "endTrigger",
488
- "pin",
489
- "pinSpacing",
490
- "anticipatePin",
491
- "pinnedContainer",
492
- "pinReparent",
493
- "pinSpacer",
494
- "pinType",
495
- "horizontal",
496
- "scroller",
497
- "containerAnimation"
498
- ];
499
535
  const resolveEndSpec = (rootElement, viewportHeight, layer, endResolved, ownIndex, endTriggerIndex) => {
500
536
  if (endResolved === null) return { mode: "auto" };
501
- if (isDwellFormat(endResolved)) return {
502
- mode: "dwell",
503
- distancePx: Math.max(0, resolveDwell(endResolved, viewportHeight))
504
- };
505
- if (isAbsoluteFormat(endResolved)) return {
506
- mode: "absolute",
507
- value: resolveAbsolute(endResolved)
508
- };
509
- if (isMaxFormat(endResolved)) {
510
- if (layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has end "${endResolved}". 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'.`);
511
- return {
512
- mode: "max",
513
- offsetPx: resolveMaxOffset(endResolved, viewportHeight)
537
+ const classified = classifyPosition(endResolved);
538
+ switch (classified.kind) {
539
+ case "dwell": return {
540
+ mode: "dwell",
541
+ distancePx: Math.max(0, resolveDwell(classified.value, viewportHeight))
542
+ };
543
+ case "absolute": return {
544
+ mode: "absolute",
545
+ value: classified.value
514
546
  };
547
+ case "max":
548
+ if (layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has end "${endResolved}". 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'.`);
549
+ return {
550
+ mode: "max",
551
+ offsetPx: resolveMaxOffset(classified.value, viewportHeight)
552
+ };
553
+ case "clause": {
554
+ if (layer.kind !== "cover" && endTriggerIndex !== null && endTriggerIndex > ownIndex) throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)}'s endTrigger (${describeElement(layer.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'.`);
555
+ const unregistered = endTriggerIndex === null;
556
+ const insideRoot = rootElement.contains(layer.endTrigger);
557
+ if (unregistered && !insideRoot && layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has an endTrigger (${describeElement(layer.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'.`);
558
+ return {
559
+ mode: "clause",
560
+ clause: classified.value,
561
+ rawTop: unregistered && insideRoot ? documentTop(layer.endTrigger) : null,
562
+ measureLive: unregistered && !insideRoot
563
+ };
564
+ }
515
565
  }
516
- if (layer.kind !== "cover" && endTriggerIndex !== null && endTriggerIndex > ownIndex) throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)}'s endTrigger (${describeElement(layer.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'.`);
517
- const unregistered = endTriggerIndex === null;
518
- const insideRoot = rootElement.contains(layer.endTrigger);
519
- if (unregistered && !insideRoot && layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has an endTrigger (${describeElement(layer.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'.`);
520
- return {
521
- mode: "clause",
522
- clause: endResolved,
523
- rawTop: unregistered && insideRoot ? documentTop(layer.endTrigger) : null,
524
- measureLive: unregistered && !insideRoot
525
- };
526
566
  };
527
567
  const resolveStartSpec = (layer, startResolved, elementHeight, viewportHeight) => {
528
- if (!isAbsoluteFormat(startResolved)) return {
529
- mode: "clause",
530
- anchorOffset: resolveAnchorTop(startResolved, elementHeight, viewportHeight)
531
- };
532
- if (layer.kind === "cover") throw new Error(`StickyScrollTrigger: createOverlapScroll's trigger ${describeElement(layer.trigger)} has start "${startResolved}", 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'.`);
533
- return {
534
- mode: "absolute",
535
- value: resolveAbsolute(startResolved)
536
- };
568
+ const classified = classifyPosition(startResolved);
569
+ switch (classified.kind) {
570
+ case "absolute":
571
+ if (layer.kind === "cover") throw new Error(`StickyScrollTrigger: createOverlapScroll's trigger ${describeElement(layer.trigger)} has start "${startResolved}", 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'.`);
572
+ return {
573
+ mode: "absolute",
574
+ value: classified.value
575
+ };
576
+ case "max":
577
+ case "dwell":
578
+ case "clause": return {
579
+ mode: "clause",
580
+ anchorOffset: resolveAnchorTop(classified.value, elementHeight, viewportHeight)
581
+ };
582
+ }
537
583
  };
538
584
  const measureLayer = (rootElement, viewportHeight, layer, ownIndex, indexByTrigger) => {
539
585
  const startResolved = resolveMaybeFn(layer.start);
540
- const endResolved = layer.end === null ? null : resolveMaybeFn(layer.end);
541
- const elementHeight = layer.trigger.offsetHeight;
586
+ const endResolved = layer.end === null ? null : prefixSpacedRelativeEnd(startResolved, resolveMaybeFn(layer.end));
587
+ const elementHeight = measureUsedHeight(layer.trigger);
542
588
  const endTriggerIsSelf = layer.endTrigger === layer.trigger;
543
589
  const endTriggerIndex = indexByTrigger.get(layer.endTrigger) ?? null;
544
590
  const end = resolveEndSpec(rootElement, viewportHeight, layer, endResolved, ownIndex, endTriggerIndex);
@@ -552,9 +598,25 @@ var StickyScrollTrigger = (function() {
552
598
  end,
553
599
  endTriggerIsSelf,
554
600
  endTriggerIndex,
555
- endTriggerHeight: end.mode === "clause" ? layer.endTrigger.offsetHeight : 0
601
+ endTriggerHeight: end.mode === "clause" ? measureUsedHeight(layer.endTrigger) : 0
556
602
  };
557
603
  };
604
+ const EXCLUDED_VAR_KEYS = [
605
+ "trigger",
606
+ "start",
607
+ "end",
608
+ "endTrigger",
609
+ "pin",
610
+ "pinSpacing",
611
+ "anticipatePin",
612
+ "pinnedContainer",
613
+ "pinReparent",
614
+ "pinSpacer",
615
+ "pinType",
616
+ "horizontal",
617
+ "scroller",
618
+ "containerAnimation"
619
+ ];
558
620
  const topToStartClause = (top) => {
559
621
  const toClause = (value) => {
560
622
  if (!Number.isFinite(value)) throw new Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${value}.`);
@@ -562,10 +624,12 @@ var StickyScrollTrigger = (function() {
562
624
  };
563
625
  return typeof top === "function" ? () => toClause(top()) : toClause(top);
564
626
  };
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);
627
+ const resolvePinReleaseTop = (endTrigger, classifiedEnd, engageTop, viewportHeight) => {
628
+ switch (classifiedEnd.kind) {
629
+ case "dwell": return engageTop + resolveDwell(classifiedEnd.value, viewportHeight);
630
+ case "absolute": return classifiedEnd.value;
631
+ case "clause": return documentTop(endTrigger) - resolveAnchorTop(classifiedEnd.value, measureUsedHeight(endTrigger), viewportHeight);
632
+ }
569
633
  };
570
634
  const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
571
635
  var StickyScrollTrigger = class {
@@ -581,16 +645,15 @@ var StickyScrollTrigger = (function() {
581
645
  #scrollTriggerClass = null;
582
646
  #pinLayers = [];
583
647
  #scrollMarginSync;
584
- #scrollMarginTargets;
585
648
  constructor(root, options = {}) {
586
649
  this.#rootElement = resolveRoot(root);
587
- this.#scrollMarginSync = createScrollMarginSync(this.#rootElement);
588
- this.#scrollMarginTargets = options.scrollMarginTargets === void 0 ? "[id]" : options.scrollMarginTargets;
589
- if (this.#scrollMarginTargets !== null) try {
590
- this.#rootElement.querySelectorAll(this.#scrollMarginTargets);
650
+ const scrollMarginTargets = options.scrollMarginTargets === void 0 ? "[id]" : options.scrollMarginTargets;
651
+ if (scrollMarginTargets !== null) try {
652
+ this.#rootElement.querySelectorAll(scrollMarginTargets);
591
653
  } catch {
592
- throw new Error(`StickyScrollTrigger: scrollMarginTargets "${this.#scrollMarginTargets}" is not a valid CSS selector.`);
654
+ throw new Error(`StickyScrollTrigger: scrollMarginTargets "${scrollMarginTargets}" is not a valid CSS selector.`);
593
655
  }
656
+ this.#scrollMarginSync = createScrollMarginSync(this.#rootElement, scrollMarginTargets);
594
657
  }
595
658
  #unbuild() {
596
659
  if (!this.#built) return;
@@ -615,13 +678,20 @@ var StickyScrollTrigger = (function() {
615
678
  });
616
679
  }
617
680
  #captureScrollTriggerClass(self) {
681
+ if (this.#destroyed) return;
618
682
  this.#scrollTriggerClass = self.constructor;
619
683
  }
620
684
  #createAutoRefreshHandler(userOnRefreshInit) {
621
685
  return (self) => {
622
686
  this.#captureScrollTriggerClass(self);
623
687
  const result = userOnRefreshInit?.(self);
624
- this.refresh();
688
+ try {
689
+ this.refresh();
690
+ } catch (error) {
691
+ queueMicrotask(() => {
692
+ throw error;
693
+ });
694
+ }
625
695
  return result;
626
696
  };
627
697
  }
@@ -706,14 +776,16 @@ var StickyScrollTrigger = (function() {
706
776
  #refreshPinLayers(viewportHeight) {
707
777
  this.#pinLayers.forEach((layer) => {
708
778
  if (!layer.inner) return;
709
- const resolvedEnd = resolveMaybeFn(layer.end);
710
- if (isMaxFormat(resolvedEnd)) throw new Error(`StickyScrollTrigger: createStickyPin's end "${resolvedEnd}" 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'.`);
711
779
  const resolvedStart = resolveMaybeFn(layer.start);
780
+ const resolvedEnd = prefixSpacedRelativeEnd(resolvedStart, resolveMaybeFn(layer.end));
781
+ const classifiedEnd = classifyPosition(resolvedEnd);
782
+ if (classifiedEnd.kind === "max") throw new Error(`StickyScrollTrigger: createStickyPin's end "${resolvedEnd}" 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'.`);
712
783
  const triggerTop = documentTop(layer.trigger);
713
- const triggerHeight = layer.trigger.offsetHeight;
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'.`);
715
- const topPx = resolveAnchorTop(resolvedStart, triggerHeight, viewportHeight);
716
- const height = resolvePinReleaseTop(layer.endTrigger, resolvedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
784
+ const triggerHeight = measureUsedHeight(layer.trigger);
785
+ const classifiedStart = classifyPosition(resolvedStart);
786
+ if (classifiedStart.kind === "absolute") 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'.`);
787
+ const topPx = resolveAnchorTop(classifiedStart.value, triggerHeight, viewportHeight);
788
+ const height = resolvePinReleaseTop(layer.endTrigger, classifiedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
717
789
  applyStickyPosition(layer.trigger, topPx);
718
790
  layer.inner.style.height = `${Math.max(0, height)}px`;
719
791
  });
@@ -793,7 +865,7 @@ var StickyScrollTrigger = (function() {
793
865
  trigger,
794
866
  freezeStart,
795
867
  freezeEnd
796
- })), this.#outermostContainer, this.#scrollMarginTargets);
868
+ })), this.#outermostContainer);
797
869
  }
798
870
  #assertNoExcludedVars(rest, context) {
799
871
  const found = EXCLUDED_VAR_KEYS.filter((key) => key in rest);
@@ -915,15 +987,22 @@ var StickyScrollTrigger = (function() {
915
987
  const element = resolveElement(elementInput, "resolveScrollPosition");
916
988
  const resolved = resolveMaybeFn(position);
917
989
  const viewportHeight = measureViewportHeight();
918
- if (isMaxFormat(resolved)) return measureDocumentMaxScroll(viewportHeight) + resolveMaxOffset(resolved, viewportHeight);
919
- if (isAbsoluteFormat(resolved)) return resolveAbsolute(resolved);
990
+ const classified = classifyPosition(resolved);
991
+ switch (classified.kind) {
992
+ case "max": return measureDocumentMaxScroll(viewportHeight) + resolveMaxOffset(classified.value, viewportHeight);
993
+ case "absolute": return classified.value;
994
+ case "dwell":
995
+ case "clause": return this.#resolveClauseScrollPosition(element, classified.value, viewportHeight);
996
+ }
997
+ }
998
+ #resolveClauseScrollPosition(element, clause, viewportHeight) {
920
999
  let gap = 0;
921
1000
  this.#layers.forEach((layer) => {
922
1001
  if (layer.kind !== "scene") return;
923
1002
  if (compareDocumentOrder(layer.trigger, element) >= 0) return;
924
1003
  gap += layer.freezeEnd - layer.freezeStart;
925
1004
  });
926
- const anchorOffset = resolveAnchorTop(resolved, element.offsetHeight, viewportHeight);
1005
+ const anchorOffset = resolveAnchorTop(clause, measureUsedHeight(element), viewportHeight);
927
1006
  const restoreSceneCoverStickyState = this.#resetSceneCoverStickyState();
928
1007
  const result = documentTop(element) + gap - anchorOffset;
929
1008
  restoreSceneCoverStickyState();
@@ -943,7 +1022,12 @@ var StickyScrollTrigger = (function() {
943
1022
  ...rest,
944
1023
  trigger,
945
1024
  start: () => this.resolveScrollPosition(trigger, start),
946
- end: () => this.resolveScrollPosition(endTrigger, end)
1025
+ end: () => {
1026
+ const resolvedEnd = resolveMaybeFn(end);
1027
+ const classifiedEnd = classifyPosition(resolvedEnd);
1028
+ if (classifiedEnd.kind === "dwell") return this.resolveScrollPosition(trigger, start) + resolveDwell(classifiedEnd.value, measureViewportHeight());
1029
+ return this.resolveScrollPosition(endTrigger, prefixSpacedRelativeEnd(start, resolvedEnd));
1030
+ }
947
1031
  };
948
1032
  }
949
1033
  destroy() {
@@ -956,6 +1040,7 @@ var StickyScrollTrigger = (function() {
956
1040
  this.#builtLayers = [];
957
1041
  this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
958
1042
  this.#pinLayers.length = 0;
1043
+ this.#scrollTriggerClass = null;
959
1044
  }
960
1045
  };
961
1046
  return StickyScrollTrigger;
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @license
3
- * StickyScrollTrigger v0.8.0
3
+ * StickyScrollTrigger v0.9.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=>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)}}})();
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)=>e===`none`||e===`hidden`?0:parseFloat(t),c=e=>{let t=e.offsetHeight,n=getComputedStyle(e),r=parseFloat(n.height);if(!Number.isFinite(r))return t;let i=n.boxSizing===`border-box`?r:r+parseFloat(n.paddingTop)+parseFloat(n.paddingBottom)+s(n.borderTopStyle,n.borderTopWidth)+s(n.borderBottomStyle,n.borderBottomWidth);return t>0&&Math.abs(i-t)>=1?t:i},l=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},u=e=>{e.style.position=``,e.style.top=``},d=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},f=e=>({position:e.style.position,top:e.style.top}),p=(e,t)=>{e.style.position=t.position,e.style.top=t.top},m=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}},h=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},g=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},_=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}},v=(e,t,n)=>{let r=e.parentNode;p(t,n),r&&r.insertBefore(t,e),e.remove()},y={position:`relative`,zIndex:`1`},b=new WeakMap,x=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=b.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]=y[t]}),b.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=b.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===y[t]&&(e.style[t]=``)}),b.delete(e)))}),t.length=0}},S=0,C=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),w=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),T=C&&w,E=(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(``)},D=(e,t)=>{let n=`sst${S++}`,r=!T&&t!==null,i=new WeakMap,a=new Set,o=null,s=null,c=[],u=null,d=()=>{if(!u)return;let e=window.scrollY;c.forEach((t,r)=>{let i=Math.min(Math.max(e-t.freezeStart,0),t.freezeEnd-t.freezeStart);u.style.setProperty(`--${n}-c${r}`,`${i}px`)})};r&&window.addEventListener(`scroll`,d,{passive:!0});let f=e=>{let t=i.get(e);e.style.scrollMarginTop=t?t.inline:``},p=()=>{o&&=(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(e=>e!==o),null),s?.removeAttribute(`data-${n}`),s=null,c=[],u=null};return{sync(m,h){let g=m.filter(e=>e.freezeEnd>e.freezeStart);if(t===null||!g.length||!h){a.forEach(f),a=new Set,p();return}s!==h&&(s?.removeAttribute(`data-${n}`),s=h,s.setAttribute(`data-${n}`,``)),r?(c=g,u=h,d()):(o||(o=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,o]),o.replaceSync(E(n,g)));let _=Array.from(e.querySelectorAll(t));_.forEach(e=>{let t=i.get(e);t?a.has(e)&&(e.style.scrollMarginTop=t.inline):i.set(e,{inline:e.style.scrollMarginTop})});let v=g.map((e,t)=>`var(--${n}-c${t}, 0px)`).join(` + `);_.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;g.forEach(t=>{l(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${v} - ${n}px)`});let y=new Set(_);a.forEach(e=>{y.has(e)||f(e)}),a=y},restore(){r&&window.removeEventListener(`scroll`,d),a.forEach(f),a=new Set,p()}}},O=e=>{for(let t=1;t<e.length;t+=1)if(l(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},k=(e,t)=>{t.sort((e,t)=>l(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=h(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=m(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},A=(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&&g(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},j=e=>typeof e==`function`?e():e,M={top:0,center:.5,bottom:1},N=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},P=/^(top|center|bottom|[+-]?(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,F=(e,t)=>{let n=P.exec(e);if(!n||!n[1]&&!n[3])throw W.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 M,l=i===`%`;return{fraction:c?M[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?N(a,o,s,t):0)}},I=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),L=e=>typeof e==`number`?e:Number(e),R=e=>{if(!e.startsWith(`clamp(`))return;let t=e.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${e}": GSAP's clamp() wrapper isn't supported here.`+(t?` Did you mean "${t}"?`:``))},z=(e,t,n)=>{let r=e.trim();R(r);let[i,a=`top`]=r.split(/\s+/),o=F(i,t),s=F(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},B=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,V=e=>typeof e==`string`&&B.test(e.trim()),H=(e,t)=>{if(typeof t!=`string`)return t;let n=t.trim();if(!n.startsWith(`+=`)||!/\s/.test(n))return t;let r=j(e);if(typeof r!=`string`)return t;let i=r.trim();R(i);let[a]=i.split(/\s+/);try{F(a,0)}catch(e){if(!I(r))throw e;return t}if(F(n.split(/\s+/)[0],0),a.includes(`=`))throw Error(`StickyScrollTrigger: end "${t}" can't be resolved against start "${r}": GSAP reads an end that starts with '+=' and holds a space by prefixing it with the start clause's element token, and "${a}" carries an offset of its own, which GSAP resolves by discarding the end's. Give end a complete position clause instead, such as 'top+=100 bottom'.`);return a+n},U=(e,t)=>{let n=B.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return N(void 0,r,i,t)},W=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,G=e=>typeof e==`string`&&W.test(e.trim()),K=(e,t)=>{let n=W.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?N(r,i,a,t):0},q=e=>typeof e==`number`?{kind:`absolute`,value:e}:V(e)?{kind:`dwell`,value:e}:G(e)?{kind:`max`,value:e}:I(e)?{kind:`absolute`,value:L(e)}:{kind:`clause`,value:e},J=(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},Y=(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+J(e,s,a,l.end.rawTop,u):t}let r=z(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}},X=(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}=Y(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=Y(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},Z=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};let c=q(a);switch(c.kind){case`dwell`:return{mode:`dwell`,distancePx:Math.max(0,U(c.value,t))};case`absolute`:return{mode:`absolute`,value:c.value};case`max`: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:K(c.value,t)};case`clause`:{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 t=s===null,a=e.contains(n.endTrigger);if(t&&!a&&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:c.value,rawTop:t&&a?i(n.endTrigger):null,measureLive:t&&!a}}}},Q=(e,t,n,i)=>{let a=q(t);switch(a.kind){case`absolute`:if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:a.value};case`max`:case`dwell`:case`clause`:return{mode:`clause`,anchorOffset:z(a.value,n,i)}}},$=(e,t,n,r,a)=>{let o=j(n.start),s=n.end===null?null:H(o,j(n.end)),l=c(n.trigger),u=n.endTrigger===n.trigger,d=a.get(n.endTrigger)??null,f=Z(e,t,n,s,r,d),p=Q(n,o,l,t);return{kind:n.kind,start:p,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:f,endTriggerIsSelf:u,endTriggerIndex:d,endTriggerHeight:f.mode===`clause`?c(n.endTrigger):0}},ee=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],te=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)},ne=(e,t,n,r)=>{switch(t.kind){case`dwell`:return n+U(t.value,r);case`absolute`:return t.value;case`clause`:return i(e)-z(t.value,c(e),r)}},re=(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;constructor(t,n={}){this.#e=e(t);let r=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets;if(r!==null)try{this.#e.querySelectorAll(r)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${r}" is not a valid CSS selector.`)}this.#d=D(this.#e,r)}#f(){this.#i&&=(A(this.#e,this.#n,this.#o),this.#o=null,!1)}#p(){this.#o=k(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#m(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#h(e){this.#s||(this.#l=e.constructor)}#g(e){return t=>{this.#h(t);let n=e?.(t);try{this.refresh()}catch(e){queueMicrotask(()=>{throw e})}return n}}#_(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=f(e.trigger);let t=_(e.trigger);e.outer=t.outer,e.inner=t.inner})}#v(){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})=>c(e));e.forEach(({outer:e},n)=>{e.style.height=`${t[n]}px`}),e.forEach(({inner:e,range:t})=>{e.style.height=t})}#y(e){return e.outer?(v(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})=>u(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:f(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{u(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{p(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=j(t.start),r=H(n,j(t.end)),a=q(r);if(a.kind===`max`)throw Error(`StickyScrollTrigger: createStickyPin's end "${r}" 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 o=i(t.trigger),s=c(t.trigger),l=q(n);if(l.kind===`absolute`)throw Error(`StickyScrollTrigger: createStickyPin's start "${n}" 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: ${n}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let u=z(l.value,s,e),f=ne(t.endTrigger,a,o-u,e)-o+u+s;d(t.trigger,u),t.inner.style.height=`${Math.max(0,f)}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)=>$(this.#e,e,t,n,r)),s=0,c=()=>X(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&&(d(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),u=a.some(e=>e.end.mode===`max`);u&&(s=o(e)),(l||u)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||O(this.#t))&&(this.#f(),this.#p()),this.#D();try{this.#_(),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,x(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)}#A(e,t){let n=ee.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(re(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 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.`)}#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.#h(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#m(),t?.(n)},onRefreshInit:this.#g(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,x(f)),m}createStickyPin({trigger:e,start:i,top:a,endTrigger:o,end:s=`bottom top`,onKill:c,...l}){if(this.#A(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`),d=n(u,o,`createStickyPin`);this.#N(u,`createStickyPin`),this.#j(this.#u,u,`StickyScrollTrigger: ${r(u)} is already registered as a pin trigger.`),this.#j(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:f(u),outer:null,inner:null,start:a===void 0?i??`top top`:te(a),endTrigger:d,end:s};return this.#u.push(p),{...l,trigger:u,onKill:e=>{this.#h(e);let t=this.#u.indexOf(p);t!==-1&&this.#u.splice(t,1),this.#y(p)&&this.#m(),c?.(e)},onRefreshInit:this.#g(l.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),i=j(n),s=a(),c=q(i);switch(c.kind){case`max`:return o(s)+K(c.value,s);case`absolute`:return c.value;case`dwell`:case`clause`:return this.#F(r,c.value,s)}}#F(e,t,n){let r=0;this.#t.forEach(t=>{t.kind===`scene`&&(l(t.trigger,e)>=0||(r+=t.freezeEnd-t.freezeStart))});let a=z(t,c(e),n),o=this.#b(),s=i(e)+r-a;return o(),s}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:o,...s}){this.#A(s,`createResolvedTrigger`);let c=t(e,`createResolvedTrigger`),l=n(c,o,`createResolvedTrigger`);return{...s,trigger:c,start:()=>this.resolveScrollPosition(c,r),end:()=>{let e=j(i),t=q(e);return t.kind===`dwell`?this.resolveScrollPosition(c,r)+U(t.value,a()):this.resolveScrollPosition(l,H(r,e))}}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#D(),this.#f(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#y(e)),this.#u.length=0,this.#l=null)}}})();
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @license
3
- * StickyScrollTrigger v0.8.0
3
+ * StickyScrollTrigger v0.9.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,7 +51,15 @@ 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
+ const measureBorderWidth = (borderStyle, width) => borderStyle === "none" || borderStyle === "hidden" ? 0 : parseFloat(width);
55
+ const measureUsedHeight = (el) => {
56
+ const rounded = el.offsetHeight;
57
+ const style = getComputedStyle(el);
58
+ const height = parseFloat(style.height);
59
+ if (!Number.isFinite(height)) return rounded;
60
+ const measured = style.boxSizing === "border-box" ? height : height + parseFloat(style.paddingTop) + parseFloat(style.paddingBottom) + measureBorderWidth(style.borderTopStyle, style.borderTopWidth) + measureBorderWidth(style.borderBottomStyle, style.borderBottomWidth);
61
+ return rounded > 0 && Math.abs(measured - rounded) >= 1 ? rounded : measured;
62
+ };
55
63
  const compareDocumentOrder = (a, b) => {
56
64
  const position = a.compareDocumentPosition(b);
57
65
  if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
@@ -190,8 +198,9 @@ const buildStylesheet = (instanceId, scenes) => {
190
198
  declarations.push(`@supports (animation-timeline: scroll()) {[data-${instanceId}]{animation:${animations.join(",")};animation-timeline:${timelines.join(",")};animation-range:${ranges.join(",")}}}`);
191
199
  return declarations.join("");
192
200
  };
193
- const createScrollMarginSync = (rootElement) => {
201
+ const createScrollMarginSync = (rootElement, targetSelector) => {
194
202
  const instanceId = `sst${nextInstanceSuffix++}`;
203
+ const usesJsRamp = !usesCssRamp && targetSelector !== null;
195
204
  const snapshots = new WeakMap();
196
205
  let written = new Set();
197
206
  let sheet = null;
@@ -206,7 +215,7 @@ const createScrollMarginSync = (rootElement) => {
206
215
  jsHost.style.setProperty(`--${instanceId}-c${index}`, `${consumed}px`);
207
216
  });
208
217
  };
209
- if (!usesCssRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
218
+ if (usesJsRamp) window.addEventListener("scroll", applyJsRamp, { passive: true });
210
219
  const restoreTarget = (target) => {
211
220
  const snapshot = snapshots.get(target);
212
221
  target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
@@ -222,7 +231,7 @@ const createScrollMarginSync = (rootElement) => {
222
231
  jsHost = null;
223
232
  };
224
233
  return {
225
- sync(scenes, host, targetSelector) {
234
+ sync(scenes, host) {
226
235
  const ramps = scenes.filter((scene) => scene.freezeEnd > scene.freezeStart);
227
236
  if (targetSelector === null || !ramps.length || !host) {
228
237
  written.forEach(restoreTarget);
@@ -235,7 +244,7 @@ const createScrollMarginSync = (rootElement) => {
235
244
  animationHost = host;
236
245
  animationHost.setAttribute(`data-${instanceId}`, "");
237
246
  }
238
- if (!usesCssRamp) {
247
+ if (usesJsRamp) {
239
248
  jsRamps = ramps;
240
249
  jsHost = host;
241
250
  applyJsRamp();
@@ -269,7 +278,7 @@ const createScrollMarginSync = (rootElement) => {
269
278
  written = next;
270
279
  },
271
280
  restore() {
272
- if (!usesCssRamp) window.removeEventListener("scroll", applyJsRamp);
281
+ if (usesJsRamp) window.removeEventListener("scroll", applyJsRamp);
273
282
  written.forEach(restoreTarget);
274
283
  written = new Set();
275
284
  clearAnimation();
@@ -326,7 +335,7 @@ const signedPx = (sign, value, unit, refSize) => {
326
335
  const magnitude = unit === "%" ? parseFloat(value) / 100 * refSize : parseFloat(value);
327
336
  return sign?.startsWith("-") ? -magnitude : magnitude;
328
337
  };
329
- const CLAUSE_TOKEN_RE = /^(top|center|bottom|(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/;
338
+ const CLAUSE_TOKEN_RE = /^(top|center|bottom|[+-]?(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/;
330
339
  const parseClauseToken = (token, refSize) => {
331
340
  const match = CLAUSE_TOKEN_RE.exec(token);
332
341
  if (!match || !match[1] && !match[3]) {
@@ -351,12 +360,14 @@ const isAbsoluteFormat = (resolved) => {
351
360
  };
352
361
  const resolveAbsolute = (resolved) => typeof resolved === "number" ? resolved : Number(resolved);
353
362
  const CLAMP_PREFIX = "clamp(";
363
+ const assertNotClamped = (trimmed) => {
364
+ if (!trimmed.startsWith(CLAMP_PREFIX)) return;
365
+ const inner = trimmed.slice(6).replace(/\)$/, "").trim();
366
+ throw new Error(`StickyScrollTrigger: unsupported position clause "${trimmed}": GSAP's clamp() wrapper isn't supported here.` + (inner ? ` Did you mean "${inner}"?` : ""));
367
+ };
354
368
  const resolveAnchorTop = (position, elementHeight, viewportHeight) => {
355
369
  const trimmed = position.trim();
356
- if (trimmed.startsWith(CLAMP_PREFIX)) {
357
- const inner = trimmed.slice(6).replace(/\)$/, "").trim();
358
- throw new Error(`StickyScrollTrigger: unsupported position clause "${trimmed}": GSAP's clamp() wrapper isn't supported here.` + (inner ? ` Did you mean "${inner}"?` : ""));
359
- }
370
+ assertNotClamped(trimmed);
360
371
  const [elementToken, viewportToken = "top"] = trimmed.split(/\s+/);
361
372
  const elementClause = parseClauseToken(elementToken, elementHeight);
362
373
  const viewportClause = parseClauseToken(viewportToken, viewportHeight);
@@ -364,6 +375,25 @@ const resolveAnchorTop = (position, elementHeight, viewportHeight) => {
364
375
  };
365
376
  const DWELL_RELATIVE_RE = /^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/;
366
377
  const isDwellFormat = (resolved) => typeof resolved === "string" && DWELL_RELATIVE_RE.test(resolved.trim());
378
+ const prefixSpacedRelativeEnd = (start, endResolved) => {
379
+ if (typeof endResolved !== "string") return endResolved;
380
+ const trimmedEnd = endResolved.trim();
381
+ if (!trimmedEnd.startsWith("+=") || !/\s/.test(trimmedEnd)) return endResolved;
382
+ const startResolved = resolveMaybeFn(start);
383
+ if (typeof startResolved !== "string") return endResolved;
384
+ const trimmedStart = startResolved.trim();
385
+ assertNotClamped(trimmedStart);
386
+ const [elementToken] = trimmedStart.split(/\s+/);
387
+ try {
388
+ parseClauseToken(elementToken, 0);
389
+ } catch (error) {
390
+ if (!isAbsoluteFormat(startResolved)) throw error;
391
+ return endResolved;
392
+ }
393
+ parseClauseToken(trimmedEnd.split(/\s+/)[0], 0);
394
+ if (elementToken.includes("=")) throw new Error(`StickyScrollTrigger: end "${endResolved}" can't be resolved against start "${startResolved}": GSAP reads an end that starts with '+=' and holds a space by prefixing it with the start clause's element token, and "${elementToken}" carries an offset of its own, which GSAP resolves by discarding the end's. Give end a complete position clause instead, such as 'top+=100 bottom'.`);
395
+ return elementToken + trimmedEnd;
396
+ };
367
397
  const resolveDwell = (resolved, viewportHeight) => {
368
398
  const match = DWELL_RELATIVE_RE.exec(String(resolved).trim());
369
399
  if (!match) throw new Error(`StickyScrollTrigger: unsupported end format "${resolved}"`);
@@ -378,6 +408,28 @@ const resolveMaxOffset = (resolved, viewportHeight) => {
378
408
  const [, sign, value, unit] = match;
379
409
  return sign ? signedPx(sign, value, unit, viewportHeight) : 0;
380
410
  };
411
+ const classifyPosition = (resolved) => {
412
+ if (typeof resolved === "number") return {
413
+ kind: "absolute",
414
+ value: resolved
415
+ };
416
+ if (isDwellFormat(resolved)) return {
417
+ kind: "dwell",
418
+ value: resolved
419
+ };
420
+ if (isMaxFormat(resolved)) return {
421
+ kind: "max",
422
+ value: resolved
423
+ };
424
+ if (isAbsoluteFormat(resolved)) return {
425
+ kind: "absolute",
426
+ value: resolveAbsolute(resolved)
427
+ };
428
+ return {
429
+ kind: "clause",
430
+ value: resolved
431
+ };
432
+ };
381
433
  const gapsBeforeRawPosition = (measurements, paddingHeightsSoFar, previous, rawPosition, ownIndex) => {
382
434
  let total = 0;
383
435
  measurements.forEach((measurement, i) => {
@@ -479,65 +531,59 @@ const planLayers = (measurements, deps) => {
479
531
  plans.forEach((plan, index) => deps.onPlanned(index, plan));
480
532
  return plans;
481
533
  };
482
- const EXCLUDED_VAR_KEYS = [
483
- "trigger",
484
- "start",
485
- "end",
486
- "endTrigger",
487
- "pin",
488
- "pinSpacing",
489
- "anticipatePin",
490
- "pinnedContainer",
491
- "pinReparent",
492
- "pinSpacer",
493
- "pinType",
494
- "horizontal",
495
- "scroller",
496
- "containerAnimation"
497
- ];
498
534
  const resolveEndSpec = (rootElement, viewportHeight, layer, endResolved, ownIndex, endTriggerIndex) => {
499
535
  if (endResolved === null) return { mode: "auto" };
500
- if (isDwellFormat(endResolved)) return {
501
- mode: "dwell",
502
- distancePx: Math.max(0, resolveDwell(endResolved, viewportHeight))
503
- };
504
- if (isAbsoluteFormat(endResolved)) return {
505
- mode: "absolute",
506
- value: resolveAbsolute(endResolved)
507
- };
508
- if (isMaxFormat(endResolved)) {
509
- if (layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has end "${endResolved}". 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'.`);
510
- return {
511
- mode: "max",
512
- offsetPx: resolveMaxOffset(endResolved, viewportHeight)
536
+ const classified = classifyPosition(endResolved);
537
+ switch (classified.kind) {
538
+ case "dwell": return {
539
+ mode: "dwell",
540
+ distancePx: Math.max(0, resolveDwell(classified.value, viewportHeight))
541
+ };
542
+ case "absolute": return {
543
+ mode: "absolute",
544
+ value: classified.value
513
545
  };
546
+ case "max":
547
+ if (layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has end "${endResolved}". 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'.`);
548
+ return {
549
+ mode: "max",
550
+ offsetPx: resolveMaxOffset(classified.value, viewportHeight)
551
+ };
552
+ case "clause": {
553
+ if (layer.kind !== "cover" && endTriggerIndex !== null && endTriggerIndex > ownIndex) throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)}'s endTrigger (${describeElement(layer.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'.`);
554
+ const unregistered = endTriggerIndex === null;
555
+ const insideRoot = rootElement.contains(layer.endTrigger);
556
+ if (unregistered && !insideRoot && layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has an endTrigger (${describeElement(layer.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'.`);
557
+ return {
558
+ mode: "clause",
559
+ clause: classified.value,
560
+ rawTop: unregistered && insideRoot ? documentTop(layer.endTrigger) : null,
561
+ measureLive: unregistered && !insideRoot
562
+ };
563
+ }
514
564
  }
515
- if (layer.kind !== "cover" && endTriggerIndex !== null && endTriggerIndex > ownIndex) throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)}'s endTrigger (${describeElement(layer.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'.`);
516
- const unregistered = endTriggerIndex === null;
517
- const insideRoot = rootElement.contains(layer.endTrigger);
518
- if (unregistered && !insideRoot && layer.kind !== "cover") throw new Error(`StickyScrollTrigger: createStickyTrigger's trigger ${describeElement(layer.trigger)} has an endTrigger (${describeElement(layer.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'.`);
519
- return {
520
- mode: "clause",
521
- clause: endResolved,
522
- rawTop: unregistered && insideRoot ? documentTop(layer.endTrigger) : null,
523
- measureLive: unregistered && !insideRoot
524
- };
525
565
  };
526
566
  const resolveStartSpec = (layer, startResolved, elementHeight, viewportHeight) => {
527
- if (!isAbsoluteFormat(startResolved)) return {
528
- mode: "clause",
529
- anchorOffset: resolveAnchorTop(startResolved, elementHeight, viewportHeight)
530
- };
531
- if (layer.kind === "cover") throw new Error(`StickyScrollTrigger: createOverlapScroll's trigger ${describeElement(layer.trigger)} has start "${startResolved}", 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'.`);
532
- return {
533
- mode: "absolute",
534
- value: resolveAbsolute(startResolved)
535
- };
567
+ const classified = classifyPosition(startResolved);
568
+ switch (classified.kind) {
569
+ case "absolute":
570
+ if (layer.kind === "cover") throw new Error(`StickyScrollTrigger: createOverlapScroll's trigger ${describeElement(layer.trigger)} has start "${startResolved}", 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'.`);
571
+ return {
572
+ mode: "absolute",
573
+ value: classified.value
574
+ };
575
+ case "max":
576
+ case "dwell":
577
+ case "clause": return {
578
+ mode: "clause",
579
+ anchorOffset: resolveAnchorTop(classified.value, elementHeight, viewportHeight)
580
+ };
581
+ }
536
582
  };
537
583
  const measureLayer = (rootElement, viewportHeight, layer, ownIndex, indexByTrigger) => {
538
584
  const startResolved = resolveMaybeFn(layer.start);
539
- const endResolved = layer.end === null ? null : resolveMaybeFn(layer.end);
540
- const elementHeight = layer.trigger.offsetHeight;
585
+ const endResolved = layer.end === null ? null : prefixSpacedRelativeEnd(startResolved, resolveMaybeFn(layer.end));
586
+ const elementHeight = measureUsedHeight(layer.trigger);
541
587
  const endTriggerIsSelf = layer.endTrigger === layer.trigger;
542
588
  const endTriggerIndex = indexByTrigger.get(layer.endTrigger) ?? null;
543
589
  const end = resolveEndSpec(rootElement, viewportHeight, layer, endResolved, ownIndex, endTriggerIndex);
@@ -551,9 +597,25 @@ const measureLayer = (rootElement, viewportHeight, layer, ownIndex, indexByTrigg
551
597
  end,
552
598
  endTriggerIsSelf,
553
599
  endTriggerIndex,
554
- endTriggerHeight: end.mode === "clause" ? layer.endTrigger.offsetHeight : 0
600
+ endTriggerHeight: end.mode === "clause" ? measureUsedHeight(layer.endTrigger) : 0
555
601
  };
556
602
  };
603
+ const EXCLUDED_VAR_KEYS = [
604
+ "trigger",
605
+ "start",
606
+ "end",
607
+ "endTrigger",
608
+ "pin",
609
+ "pinSpacing",
610
+ "anticipatePin",
611
+ "pinnedContainer",
612
+ "pinReparent",
613
+ "pinSpacer",
614
+ "pinType",
615
+ "horizontal",
616
+ "scroller",
617
+ "containerAnimation"
618
+ ];
557
619
  const topToStartClause = (top) => {
558
620
  const toClause = (value) => {
559
621
  if (!Number.isFinite(value)) throw new Error(`StickyScrollTrigger: createStickyPin's top must be a finite number, got ${value}.`);
@@ -561,10 +623,12 @@ const topToStartClause = (top) => {
561
623
  };
562
624
  return typeof top === "function" ? () => toClause(top()) : toClause(top);
563
625
  };
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);
626
+ const resolvePinReleaseTop = (endTrigger, classifiedEnd, engageTop, viewportHeight) => {
627
+ switch (classifiedEnd.kind) {
628
+ case "dwell": return engageTop + resolveDwell(classifiedEnd.value, viewportHeight);
629
+ case "absolute": return classifiedEnd.value;
630
+ case "clause": return documentTop(endTrigger) - resolveAnchorTop(classifiedEnd.value, measureUsedHeight(endTrigger), viewportHeight);
631
+ }
568
632
  };
569
633
  const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
570
634
  var StickyScrollTrigger = class {
@@ -580,16 +644,15 @@ var StickyScrollTrigger = class {
580
644
  #scrollTriggerClass = null;
581
645
  #pinLayers = [];
582
646
  #scrollMarginSync;
583
- #scrollMarginTargets;
584
647
  constructor(root, options = {}) {
585
648
  this.#rootElement = resolveRoot(root);
586
- this.#scrollMarginSync = createScrollMarginSync(this.#rootElement);
587
- this.#scrollMarginTargets = options.scrollMarginTargets === void 0 ? "[id]" : options.scrollMarginTargets;
588
- if (this.#scrollMarginTargets !== null) try {
589
- this.#rootElement.querySelectorAll(this.#scrollMarginTargets);
649
+ const scrollMarginTargets = options.scrollMarginTargets === void 0 ? "[id]" : options.scrollMarginTargets;
650
+ if (scrollMarginTargets !== null) try {
651
+ this.#rootElement.querySelectorAll(scrollMarginTargets);
590
652
  } catch {
591
- throw new Error(`StickyScrollTrigger: scrollMarginTargets "${this.#scrollMarginTargets}" is not a valid CSS selector.`);
653
+ throw new Error(`StickyScrollTrigger: scrollMarginTargets "${scrollMarginTargets}" is not a valid CSS selector.`);
592
654
  }
655
+ this.#scrollMarginSync = createScrollMarginSync(this.#rootElement, scrollMarginTargets);
593
656
  }
594
657
  #unbuild() {
595
658
  if (!this.#built) return;
@@ -614,13 +677,20 @@ var StickyScrollTrigger = class {
614
677
  });
615
678
  }
616
679
  #captureScrollTriggerClass(self) {
680
+ if (this.#destroyed) return;
617
681
  this.#scrollTriggerClass = self.constructor;
618
682
  }
619
683
  #createAutoRefreshHandler(userOnRefreshInit) {
620
684
  return (self) => {
621
685
  this.#captureScrollTriggerClass(self);
622
686
  const result = userOnRefreshInit?.(self);
623
- this.refresh();
687
+ try {
688
+ this.refresh();
689
+ } catch (error) {
690
+ queueMicrotask(() => {
691
+ throw error;
692
+ });
693
+ }
624
694
  return result;
625
695
  };
626
696
  }
@@ -705,14 +775,16 @@ var StickyScrollTrigger = class {
705
775
  #refreshPinLayers(viewportHeight) {
706
776
  this.#pinLayers.forEach((layer) => {
707
777
  if (!layer.inner) return;
708
- const resolvedEnd = resolveMaybeFn(layer.end);
709
- if (isMaxFormat(resolvedEnd)) throw new Error(`StickyScrollTrigger: createStickyPin's end "${resolvedEnd}" 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'.`);
710
778
  const resolvedStart = resolveMaybeFn(layer.start);
779
+ const resolvedEnd = prefixSpacedRelativeEnd(resolvedStart, resolveMaybeFn(layer.end));
780
+ const classifiedEnd = classifyPosition(resolvedEnd);
781
+ if (classifiedEnd.kind === "max") throw new Error(`StickyScrollTrigger: createStickyPin's end "${resolvedEnd}" 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'.`);
711
782
  const triggerTop = documentTop(layer.trigger);
712
- const triggerHeight = layer.trigger.offsetHeight;
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'.`);
714
- const topPx = resolveAnchorTop(resolvedStart, triggerHeight, viewportHeight);
715
- const height = resolvePinReleaseTop(layer.endTrigger, resolvedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
783
+ const triggerHeight = measureUsedHeight(layer.trigger);
784
+ const classifiedStart = classifyPosition(resolvedStart);
785
+ if (classifiedStart.kind === "absolute") 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'.`);
786
+ const topPx = resolveAnchorTop(classifiedStart.value, triggerHeight, viewportHeight);
787
+ const height = resolvePinReleaseTop(layer.endTrigger, classifiedEnd, triggerTop - topPx, viewportHeight) - triggerTop + topPx + triggerHeight;
716
788
  applyStickyPosition(layer.trigger, topPx);
717
789
  layer.inner.style.height = `${Math.max(0, height)}px`;
718
790
  });
@@ -792,7 +864,7 @@ var StickyScrollTrigger = class {
792
864
  trigger,
793
865
  freezeStart,
794
866
  freezeEnd
795
- })), this.#outermostContainer, this.#scrollMarginTargets);
867
+ })), this.#outermostContainer);
796
868
  }
797
869
  #assertNoExcludedVars(rest, context) {
798
870
  const found = EXCLUDED_VAR_KEYS.filter((key) => key in rest);
@@ -914,15 +986,22 @@ var StickyScrollTrigger = class {
914
986
  const element = resolveElement(elementInput, "resolveScrollPosition");
915
987
  const resolved = resolveMaybeFn(position);
916
988
  const viewportHeight = measureViewportHeight();
917
- if (isMaxFormat(resolved)) return measureDocumentMaxScroll(viewportHeight) + resolveMaxOffset(resolved, viewportHeight);
918
- if (isAbsoluteFormat(resolved)) return resolveAbsolute(resolved);
989
+ const classified = classifyPosition(resolved);
990
+ switch (classified.kind) {
991
+ case "max": return measureDocumentMaxScroll(viewportHeight) + resolveMaxOffset(classified.value, viewportHeight);
992
+ case "absolute": return classified.value;
993
+ case "dwell":
994
+ case "clause": return this.#resolveClauseScrollPosition(element, classified.value, viewportHeight);
995
+ }
996
+ }
997
+ #resolveClauseScrollPosition(element, clause, viewportHeight) {
919
998
  let gap = 0;
920
999
  this.#layers.forEach((layer) => {
921
1000
  if (layer.kind !== "scene") return;
922
1001
  if (compareDocumentOrder(layer.trigger, element) >= 0) return;
923
1002
  gap += layer.freezeEnd - layer.freezeStart;
924
1003
  });
925
- const anchorOffset = resolveAnchorTop(resolved, element.offsetHeight, viewportHeight);
1004
+ const anchorOffset = resolveAnchorTop(clause, measureUsedHeight(element), viewportHeight);
926
1005
  const restoreSceneCoverStickyState = this.#resetSceneCoverStickyState();
927
1006
  const result = documentTop(element) + gap - anchorOffset;
928
1007
  restoreSceneCoverStickyState();
@@ -942,7 +1021,12 @@ var StickyScrollTrigger = class {
942
1021
  ...rest,
943
1022
  trigger,
944
1023
  start: () => this.resolveScrollPosition(trigger, start),
945
- end: () => this.resolveScrollPosition(endTrigger, end)
1024
+ end: () => {
1025
+ const resolvedEnd = resolveMaybeFn(end);
1026
+ const classifiedEnd = classifyPosition(resolvedEnd);
1027
+ if (classifiedEnd.kind === "dwell") return this.resolveScrollPosition(trigger, start) + resolveDwell(classifiedEnd.value, measureViewportHeight());
1028
+ return this.resolveScrollPosition(endTrigger, prefixSpacedRelativeEnd(start, resolvedEnd));
1029
+ }
946
1030
  };
947
1031
  }
948
1032
  destroy() {
@@ -955,6 +1039,7 @@ var StickyScrollTrigger = class {
955
1039
  this.#builtLayers = [];
956
1040
  this.#pinLayers.forEach((layer) => this.#unwrapPinLayer(layer));
957
1041
  this.#pinLayers.length = 0;
1042
+ this.#scrollTriggerClass = null;
958
1043
  }
959
1044
  };
960
1045
  export { StickyScrollTrigger as default };
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @license
3
- * StickyScrollTrigger v0.8.0
3
+ * StickyScrollTrigger v0.9.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=>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};
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)=>e===`none`||e===`hidden`?0:parseFloat(t),c=e=>{let t=e.offsetHeight,n=getComputedStyle(e),r=parseFloat(n.height);if(!Number.isFinite(r))return t;let i=n.boxSizing===`border-box`?r:r+parseFloat(n.paddingTop)+parseFloat(n.paddingBottom)+s(n.borderTopStyle,n.borderTopWidth)+s(n.borderBottomStyle,n.borderBottomWidth);return t>0&&Math.abs(i-t)>=1?t:i},l=(e,t)=>{let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0},u=e=>{e.style.position=``,e.style.top=``},d=(e,t)=>{e.style.position=`sticky`,e.style.top=`${t}px`},f=e=>({position:e.style.position,top:e.style.top}),p=(e,t)=>{e.style.position=t.position,e.style.top=t.top},m=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}},h=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},g=e=>{let t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);e.remove()}},_=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}},v=(e,t,n)=>{let r=e.parentNode;p(t,n),r&&r.insertBefore(t,e),e.remove()},y={position:`relative`,zIndex:`1`},b=new WeakMap,x=e=>{let t=[];for(let n=e;n;n=n.nextElementSibling){if(!(n instanceof HTMLElement))continue;let e=n,r=b.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]=y[t]}),b.set(e,{count:1,applied:n})}t.push(e)}return()=>{t.forEach(e=>{let t=b.get(e);t&&(--t.count,!(t.count>0)&&(t.applied.forEach(t=>{e.style[t]===y[t]&&(e.style[t]=``)}),b.delete(e)))}),t.length=0}};let S=0;const C=typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`animation-timeline`,`scroll()`),w=typeof CSSStyleSheet==`function`&&typeof CSSStyleSheet.prototype.replaceSync==`function`&&typeof document<`u`&&Array.isArray(document.adoptedStyleSheets),T=C&&w,E=(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(``)},D=(e,t)=>{let n=`sst${S++}`,r=!T&&t!==null,i=new WeakMap,a=new Set,o=null,s=null,c=[],u=null,d=()=>{if(!u)return;let e=window.scrollY;c.forEach((t,r)=>{let i=Math.min(Math.max(e-t.freezeStart,0),t.freezeEnd-t.freezeStart);u.style.setProperty(`--${n}-c${r}`,`${i}px`)})};r&&window.addEventListener(`scroll`,d,{passive:!0});let f=e=>{let t=i.get(e);e.style.scrollMarginTop=t?t.inline:``},p=()=>{o&&=(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(e=>e!==o),null),s?.removeAttribute(`data-${n}`),s=null,c=[],u=null};return{sync(m,h){let g=m.filter(e=>e.freezeEnd>e.freezeStart);if(t===null||!g.length||!h){a.forEach(f),a=new Set,p();return}s!==h&&(s?.removeAttribute(`data-${n}`),s=h,s.setAttribute(`data-${n}`,``)),r?(c=g,u=h,d()):(o||(o=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,o]),o.replaceSync(E(n,g)));let _=Array.from(e.querySelectorAll(t));_.forEach(e=>{let t=i.get(e);t?a.has(e)&&(e.style.scrollMarginTop=t.inline):i.set(e,{inline:e.style.scrollMarginTop})});let v=g.map((e,t)=>`var(--${n}-c${t}, 0px)`).join(` + `);_.forEach(e=>{let t=parseFloat(getComputedStyle(e).scrollMarginTop)||0,n=0;g.forEach(t=>{l(t.trigger,e)>=0||(n+=t.freezeEnd-t.freezeStart)}),e.style.scrollMarginTop=`calc(${t}px + var(--sst-scroll-margin-top-offset, 0px) + ${v} - ${n}px)`});let y=new Set(_);a.forEach(e=>{y.has(e)||f(e)}),a=y},restore(){r&&window.removeEventListener(`scroll`,d),a.forEach(f),a=new Set,p()}}},O=e=>{for(let t=1;t<e.length;t+=1)if(l(e[t-1].trigger,e[t].trigger)>0)return!0;return!1},k=(e,t)=>{t.sort((e,t)=>l(e.trigger,t.trigger));for(let e of t)e.kind===`cover`&&(e.wrapper=h(e.trigger));let n=e,r=null;for(let e of t){if(e.kind!==`scene`)continue;let t=m(n);e.container=t.container,e.wrapper=t.wrapper,e.padding=t.padding,n=t.container,r=t.container}return r},A=(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&&g(n.wrapper)}t.forEach(e=>{e.wrapper=null,e.kind===`scene`&&(e.container=null,e.padding=null)})},j=e=>typeof e==`function`?e():e,M={top:0,center:.5,bottom:1},N=(e,t,n,r)=>{let i=n===`%`?parseFloat(t)/100*r:parseFloat(t);return e?.startsWith(`-`)?-i:i},P=/^(top|center|bottom|[+-]?(?:\d+(?:\.\d*)?|\.\d+))?(%|px)?(?:([+-]=?)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,F=(e,t)=>{let n=P.exec(e);if(!n||!n[1]&&!n[3])throw W.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 M,l=i===`%`;return{fraction:c?M[r]:l?parseFloat(r)/100:0,offsetPx:(!c&&!l&&r!==void 0?parseFloat(r):0)+(a?N(a,o,s,t):0)}},I=e=>typeof e==`number`||e.trim()!==``&&!Number.isNaN(Number(e)),L=e=>typeof e==`number`?e:Number(e),R=e=>{if(!e.startsWith(`clamp(`))return;let t=e.slice(6).replace(/\)$/,``).trim();throw Error(`StickyScrollTrigger: unsupported position clause "${e}": GSAP's clamp() wrapper isn't supported here.`+(t?` Did you mean "${t}"?`:``))},z=(e,t,n)=>{let r=e.trim();R(r);let[i,a=`top`]=r.split(/\s+/),o=F(i,t),s=F(a,n);return n*s.fraction+s.offsetPx-(t*o.fraction+o.offsetPx)},B=/^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/,V=e=>typeof e==`string`&&B.test(e.trim()),H=(e,t)=>{if(typeof t!=`string`)return t;let n=t.trim();if(!n.startsWith(`+=`)||!/\s/.test(n))return t;let r=j(e);if(typeof r!=`string`)return t;let i=r.trim();R(i);let[a]=i.split(/\s+/);try{F(a,0)}catch(e){if(!I(r))throw e;return t}if(F(n.split(/\s+/)[0],0),a.includes(`=`))throw Error(`StickyScrollTrigger: end "${t}" can't be resolved against start "${r}": GSAP reads an end that starts with '+=' and holds a space by prefixing it with the start clause's element token, and "${a}" carries an offset of its own, which GSAP resolves by discarding the end's. Give end a complete position clause instead, such as 'top+=100 bottom'.`);return a+n},U=(e,t)=>{let n=B.exec(String(e).trim());if(!n)throw Error(`StickyScrollTrigger: unsupported end format "${e}"`);let[,r,i]=n;return N(void 0,r,i,t)},W=/^max(?:([+-]=)(\d+(?:\.\d*)?|\.\d+)(%|px)?)?$/,G=e=>typeof e==`string`&&W.test(e.trim()),K=(e,t)=>{let n=W.exec(e.trim());if(!n)throw Error(`StickyScrollTrigger: unsupported max-position format "${e}"`);let[,r,i,a]=n;return r?N(r,i,a,t):0},q=e=>typeof e==`number`?{kind:`absolute`,value:e}:V(e)?{kind:`dwell`,value:e}:G(e)?{kind:`max`,value:e}:I(e)?{kind:`absolute`,value:L(e)}:{kind:`clause`,value:e},J=(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},Y=(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+J(e,s,a,l.end.rawTop,u):t}let r=z(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}},X=(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}=Y(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=Y(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},Z=(e,t,n,a,o,s)=>{if(a===null)return{mode:`auto`};let c=q(a);switch(c.kind){case`dwell`:return{mode:`dwell`,distancePx:Math.max(0,U(c.value,t))};case`absolute`:return{mode:`absolute`,value:c.value};case`max`: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:K(c.value,t)};case`clause`:{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 t=s===null,a=e.contains(n.endTrigger);if(t&&!a&&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:c.value,rawTop:t&&a?i(n.endTrigger):null,measureLive:t&&!a}}}},Q=(e,t,n,i)=>{let a=q(t);switch(a.kind){case`absolute`:if(e.kind===`cover`)throw Error(`StickyScrollTrigger: createOverlapScroll's trigger ${r(e.trigger)} has start "${t}", an absolute scroll position (GSAP reads any bare number this way). That isn't supported here: a cover layer's sticky position is computed relative to its own wrapper, so start must be a position clause such as 'bottom bottom'.`);return{mode:`absolute`,value:a.value};case`max`:case`dwell`:case`clause`:return{mode:`clause`,anchorOffset:z(a.value,n,i)}}},$=(e,t,n,r,a)=>{let o=j(n.start),s=n.end===null?null:H(o,j(n.end)),l=c(n.trigger),u=n.endTrigger===n.trigger,d=a.get(n.endTrigger)??null,f=Z(e,t,n,s,r,d),p=Q(n,o,l,t);return{kind:n.kind,start:p,triggerTop:i(n.trigger),wrapperTop:n.wrapper?i(n.wrapper):0,coverTop:n.kind===`cover`?i(n.cover):0,end:f,endTriggerIsSelf:u,endTriggerIndex:d,endTriggerHeight:f.mode===`clause`?c(n.endTrigger):0}},ee=[`trigger`,`start`,`end`,`endTrigger`,`pin`,`pinSpacing`,`anticipatePin`,`pinnedContainer`,`pinReparent`,`pinSpacer`,`pinType`,`horizontal`,`scroller`,`containerAnimation`],te=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)},ne=(e,t,n,r)=>{switch(t.kind){case`dwell`:return n+U(t.value,r);case`absolute`:return t.value;case`clause`:return i(e)-z(t.value,c(e),r)}},re=(e,t)=>e.some(e=>e.trigger===t);var ie=class{#e;#t=[];#n=[];#r=new WeakMap;#i=!1;#a=!1;#o=null;#s=!1;#c=!1;#l=null;#u=[];#d;constructor(t,n={}){this.#e=e(t);let r=n.scrollMarginTargets===void 0?`[id]`:n.scrollMarginTargets;if(r!==null)try{this.#e.querySelectorAll(r)}catch{throw Error(`StickyScrollTrigger: scrollMarginTargets "${r}" is not a valid CSS selector.`)}this.#d=D(this.#e,r)}#f(){this.#i&&=(A(this.#e,this.#n,this.#o),this.#o=null,!1)}#p(){this.#o=k(this.#e,this.#t),this.#n=[...this.#t],this.#i=!0,this.#a=!1}#m(){this.#c||this.#s||(this.#c=!0,queueMicrotask(()=>{this.#c=!1,!this.#s&&(this.refresh(),typeof this.#l?.refresh==`function`&&this.#l.refresh())}))}#h(e){this.#s||(this.#l=e.constructor)}#g(e){return t=>{this.#h(t);let n=e?.(t);try{this.refresh()}catch(e){queueMicrotask(()=>{throw e})}return n}}#_(){this.#u.forEach(e=>{if(e.outer)return;e.savedPosition=f(e.trigger);let t=_(e.trigger);e.outer=t.outer,e.inner=t.inner})}#v(){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})=>c(e));e.forEach(({outer:e},n)=>{e.style.height=`${t[n]}px`}),e.forEach(({inner:e,range:t})=>{e.style.height=t})}#y(e){return e.outer?(v(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})=>u(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:f(e.trigger),height:e.inner?e.inner.style.height:``}));return e.forEach(({layer:e})=>{u(e.trigger),e.inner&&(e.inner.style.height=``)}),()=>{e.forEach(({layer:e,position:t,height:n})=>{p(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=j(t.start),r=H(n,j(t.end)),a=q(r);if(a.kind===`max`)throw Error(`StickyScrollTrigger: createStickyPin's end "${r}" 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 o=i(t.trigger),s=c(t.trigger),l=q(n);if(l.kind===`absolute`)throw Error(`StickyScrollTrigger: createStickyPin's start "${n}" 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: ${n}) for a px distance from the viewport's top edge, or a position clause such as 'top top'.`);let u=z(l.value,s,e),f=ne(t.endTrigger,a,o-u,e)-o+u+s;d(t.trigger,u),t.inner.style.height=`${Math.max(0,f)}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)=>$(this.#e,e,t,n,r)),s=0,c=()=>X(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&&(d(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),u=a.some(e=>e.end.mode===`max`);u&&(s=o(e)),(l||u)&&c()}refresh(){if(this.#s)return;(this.#a||!this.#i||O(this.#t))&&(this.#f(),this.#p()),this.#D();try{this.#_(),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,x(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)}#A(e,t){let n=ee.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(re(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 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.`)}#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.#h(n);let r=this.#t.indexOf(e);r!==-1&&this.#t.splice(r,1),this.#a=!0,this.#m(),t?.(n)},onRefreshInit:this.#g(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,x(f)),m}createStickyPin({trigger:e,start:i,top:a,endTrigger:o,end:s=`bottom top`,onKill:c,...l}){if(this.#A(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`),d=n(u,o,`createStickyPin`);this.#N(u,`createStickyPin`),this.#j(this.#u,u,`StickyScrollTrigger: ${r(u)} is already registered as a pin trigger.`),this.#j(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:f(u),outer:null,inner:null,start:a===void 0?i??`top top`:te(a),endTrigger:d,end:s};return this.#u.push(p),{...l,trigger:u,onKill:e=>{this.#h(e);let t=this.#u.indexOf(p);t!==-1&&this.#u.splice(t,1),this.#y(p)&&this.#m(),c?.(e)},onRefreshInit:this.#g(l.onRefreshInit)}}resolveScrollPosition(e,n){let r=t(e,`resolveScrollPosition`),i=j(n),s=a(),c=q(i);switch(c.kind){case`max`:return o(s)+K(c.value,s);case`absolute`:return c.value;case`dwell`:case`clause`:return this.#F(r,c.value,s)}}#F(e,t,n){let r=0;this.#t.forEach(t=>{t.kind===`scene`&&(l(t.trigger,e)>=0||(r+=t.freezeEnd-t.freezeStart))});let a=z(t,c(e),n),o=this.#b(),s=i(e)+r-a;return o(),s}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:o,...s}){this.#A(s,`createResolvedTrigger`);let c=t(e,`createResolvedTrigger`),l=n(c,o,`createResolvedTrigger`);return{...s,trigger:c,start:()=>this.resolveScrollPosition(c,r),end:()=>{let e=j(i),t=q(e);return t.kind===`dwell`?this.resolveScrollPosition(c,r)+U(t.value,a()):this.resolveScrollPosition(l,H(r,e))}}}destroy(){this.#s||(this.#s=!0,this.#d.restore(),this.#D(),this.#f(),this.#t.length=0,this.#n=[],this.#u.forEach(e=>this.#y(e)),this.#u.length=0,this.#l=null)}};export{ie as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sticky-scroll-trigger",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A ScrollTrigger helper that uses native CSS position:sticky instead of GSAP pinning",
5
5
  "license": "MIT",
6
6
  "author": "Kuninori Ogino",