sticky-scroll-trigger 0.13.0 → 0.14.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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @license
3
- * StickyScrollTrigger v0.13.0
3
+ * StickyScrollTrigger v0.14.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
@@ -86,10 +86,6 @@ const resetStickyPosition = (el) => {
86
86
  el.style.position = "";
87
87
  el.style.top = "";
88
88
  };
89
- const applyStickyPosition = (el, topPx) => {
90
- el.style.position = "sticky";
91
- el.style.top = `${topPx}px`;
92
- };
93
89
  const captureInlinePosition = (el) => ({
94
90
  position: el.style.position,
95
91
  top: el.style.top
@@ -103,6 +99,15 @@ const stripStickyPositions = (elements) => {
103
99
  elements.forEach(resetStickyPosition);
104
100
  return () => elements.forEach((el, i) => restoreInlinePosition(el, saved[i]));
105
101
  };
102
+ const insertSpacers = (spacers) => {
103
+ const inserted = spacers.map(({ after, height }) => {
104
+ const spacer = document.createElement("div");
105
+ spacer.style.cssText = `height:${height}px;margin:0;padding:0;border:0`;
106
+ after.after(spacer);
107
+ return spacer;
108
+ });
109
+ return () => inserted.forEach((spacer) => spacer.remove());
110
+ };
106
111
  const wrapScene = (inner, holdTrailingMargin) => {
107
112
  if (!inner.parentNode) throw new Error(`StickyScrollTrigger: ${describeElement(inner)} is not attached to the document`);
108
113
  const container = document.createElement("div");
@@ -205,6 +210,41 @@ const liftAboveStickyWrapper = (cover) => {
205
210
  lifted.length = 0;
206
211
  };
207
212
  };
213
+ const classOf = (self) => self.constructor;
214
+ const isRefreshing = (cls) => cls?.isRefreshing === true;
215
+ const isScrolling = (cls) => Boolean(cls?.isScrolling?.());
216
+ const isScrollingOrUpdating = (cls) => Boolean(cls?.isScrolling?.() || cls?.isUpdating === true);
217
+ const addGsapListener = (cls, type, callback) => {
218
+ cls?.addEventListener?.(type, callback);
219
+ };
220
+ const removeGsapListener = (cls, type, callback) => {
221
+ cls?.removeEventListener?.(type, callback);
222
+ };
223
+ const refreshAll = (cls) => {
224
+ if (typeof cls?.refresh === "function") cls.refresh();
225
+ };
226
+ const scrollRecord = (cls, zero = false) => {
227
+ if (!cls || !isRefreshing(cls)) return null;
228
+ const scrollFunc = cls.getScrollFunc?.(window);
229
+ if (!(scrollFunc && typeof scrollFunc.rec === "number" && (zero || scrollFunc.rec))) return null;
230
+ const record = scrollFunc;
231
+ return {
232
+ read: () => record.rec,
233
+ write: (value) => {
234
+ record.rec = value;
235
+ }
236
+ };
237
+ };
238
+ const syncScrollCache = (cls) => {
239
+ const scrollFunc = cls?.getScrollFunc?.(window);
240
+ if (typeof scrollFunc !== "function") return;
241
+ const cached = scrollFunc();
242
+ if (typeof cached !== "number" || Math.abs(cached - window.scrollY) >= .5) scrollFunc(window.scrollY);
243
+ };
244
+ const revertAfterMeasure = (restore, result) => ({ render: (time) => {
245
+ result?.render?.(time);
246
+ restore();
247
+ } });
208
248
  const AUTO_MIN_DEPTH = 7;
209
249
  const MAX_CHAIN_IN_BAND = 4;
210
250
  const BUFFER_FLOOR_PX = 325;
@@ -280,7 +320,7 @@ let gsapPhase = "idle";
280
320
  let adoptedMidRefresh = false;
281
321
  let scannedThisTask = null;
282
322
  const gsapClasses = new Set();
283
- const gsapRefreshing = () => Array.from(gsapClasses).some((cls) => cls.isRefreshing === true);
323
+ const gsapRefreshing = () => Array.from(gsapClasses).some((cls) => isRefreshing(cls));
284
324
  const stateAt = (record, scroll) => {
285
325
  if (!record.demotable) return "in";
286
326
  if (scroll < record.lo - buffer) return "before";
@@ -358,22 +398,22 @@ const onGsapRefreshInit = () => {
358
398
  queueMicrotask(onGsapRefreshDone);
359
399
  if (records.length) update(0);
360
400
  }
361
- return { render: restoreAfterGsapMeasure };
401
+ return revertAfterMeasure(restoreAfterGsapMeasure);
362
402
  };
363
403
  const adoptGsapClass = (cls) => {
364
404
  if (gsapClasses.has(cls)) return;
365
- if (cls.isRefreshing === true) adoptedMidRefresh = true;
405
+ if (isRefreshing(cls)) adoptedMidRefresh = true;
366
406
  gsapClasses.add(cls);
367
- cls.addEventListener?.("refresh", onGsapRefreshDone);
368
- cls.addEventListener?.("refreshInit", onGsapRefreshInit);
407
+ addGsapListener(cls, "refresh", onGsapRefreshDone);
408
+ addGsapListener(cls, "refreshInit", onGsapRefreshInit);
369
409
  };
370
410
  const dropGsapClassesLater = () => {
371
411
  if (!gsapClasses.size) return;
372
412
  queueMicrotask(() => {
373
413
  if (liveClients().length) return;
374
414
  gsapClasses.forEach((cls) => {
375
- cls.removeEventListener?.("refresh", onGsapRefreshDone);
376
- cls.removeEventListener?.("refreshInit", onGsapRefreshInit);
415
+ removeGsapListener(cls, "refresh", onGsapRefreshDone);
416
+ removeGsapListener(cls, "refreshInit", onGsapRefreshInit);
377
417
  });
378
418
  gsapClasses.clear();
379
419
  });
@@ -606,7 +646,14 @@ const rebuildDormancy = (scrollTriggerClass) => {
606
646
  update(gsapPhase === "measuring" ? 0 : (gsapPhase === "restored" ? scrollBeforeGsapRefresh : null) ?? scroll);
607
647
  listen(true);
608
648
  };
609
- const takeGsapRefreshRestore = () => adoptedMidRefresh && gsapRefreshing() ? onGsapRefreshInit().render : null;
649
+ const takeGsapRefreshRestore = () => {
650
+ if (!adoptedMidRefresh || !gsapRefreshing()) return null;
651
+ onGsapRefreshInit();
652
+ return restoreAfterGsapMeasure;
653
+ };
654
+ const setGsapRefreshReturn = (scroll) => {
655
+ if (gsapPhase !== "idle") scrollBeforeGsapRefresh = scroll;
656
+ };
610
657
  const clearDormancy = clearTable;
611
658
  const releaseDormant = (elements) => {
612
659
  const released = new Set(elements);
@@ -637,6 +684,24 @@ const unregisterDormancyClient = (client) => {
637
684
  if (liveClients().length) queueRebuild();
638
685
  else teardown();
639
686
  };
687
+ const commitSticky = (el, topPx) => {
688
+ el.style.position = "sticky";
689
+ el.style.top = `${topPx}px`;
690
+ };
691
+ const commitPosition = (el, saved) => {
692
+ el.style.position = saved.position;
693
+ el.style.top = saved.top;
694
+ };
695
+ const commitHeight = (el, height) => {
696
+ el.style.height = height;
697
+ };
698
+ const clearStickyForRead = (el) => {
699
+ el.style.position = "";
700
+ el.style.top = "";
701
+ };
702
+ const clearHeightForRead = (el) => {
703
+ el.style.height = "";
704
+ };
640
705
  const resolveMaybeFn = (value) => typeof value === "function" ? value() : value;
641
706
  const KEYWORD_FRACTIONS = {
642
707
  top: 0,
@@ -1301,6 +1366,7 @@ const createScrollMarginSync = (rootElement, targetSelector) => {
1301
1366
  stopRamps();
1302
1367
  };
1303
1368
  return {
1369
+ targets: () => targetSelector === null ? [] : Array.from(rootElement.querySelectorAll(targetSelector)),
1304
1370
  sync(scenes, host, measureNaturalTops) {
1305
1371
  const ramps = scenes.filter((scene) => scene.freezeEnd > scene.freezeStart).sort((a, b) => a.freezeStart - b.freezeStart);
1306
1372
  if (targetSelector === null || !ramps.length || !host) {
@@ -1444,6 +1510,8 @@ const measureLayer = (rootElement, viewportHeight, layer, ownIndex, indexByTrigg
1444
1510
  const end = resolveEndSpec(rootElement, viewportHeight, layer, endResolved, ownIndex, endTriggerIndex);
1445
1511
  const endTriggerInContainer = end.mode === "clause" && !end.measureLive && !endTriggerIsSelf;
1446
1512
  const start = resolveStartSpec(layer, startResolved, elementHeight, viewportHeight);
1513
+ const { end: endInput } = layer;
1514
+ const liveEnd = layer.kind === "scene" && typeof endInput === "function" && (end.mode === "dwell" || end.mode === "absolute") ? () => resolveEndSpec(rootElement, viewportHeight, layer, prefixSpacedRelativeEnd(startResolved, endInput()), ownIndex, endTriggerIndex) : void 0;
1447
1515
  return {
1448
1516
  kind: layer.kind,
1449
1517
  start,
@@ -1459,7 +1527,8 @@ const measureLayer = (rootElement, viewportHeight, layer, ownIndex, indexByTrigg
1459
1527
  height: end.mode === "clause" ? measureUsedHeight(layer.endTrigger) : 0,
1460
1528
  enclosedBy: endTriggerInContainer ? indicesWhere((trigger) => trigger.contains(layer.endTrigger)) : [],
1461
1529
  nests: endTriggerInContainer ? indicesWhere((other) => other !== layer.endTrigger && layer.endTrigger.contains(other)) : []
1462
- }
1530
+ },
1531
+ liveEnd
1463
1532
  };
1464
1533
  };
1465
1534
  const EXCLUDED_VAR_KEYS = [
@@ -1496,10 +1565,55 @@ const removeItem = (list, item) => {
1496
1565
  const index = list.indexOf(item);
1497
1566
  if (index !== -1) list.splice(index, 1);
1498
1567
  };
1568
+ const suspendLiveEvaluations = (evaluation, resolving) => {
1569
+ const resumes = [];
1570
+ for (let current = evaluation; current; current = current.outer) resumes.unshift(current.suspend(resolving && current === evaluation));
1571
+ return () => resumes.forEach((resume) => resume());
1572
+ };
1573
+ const liveEndValue = (spec) => {
1574
+ if (spec.mode === "dwell") return spec.distancePx;
1575
+ return spec.mode === "absolute" ? spec.value : 0;
1576
+ };
1577
+ const LIVE_END_ROUNDS = 6;
1578
+ const LIVE_END_TOLERANCE_PX = .5;
1499
1579
  const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
1500
1580
  const pendingDisarms = new Set();
1501
1581
  const pendingKeeps = new Set();
1582
+ const pendingCatchUps = new Map();
1502
1583
  let unbuildCount = 0;
1584
+ let refreshedInGsapRefresh = null;
1585
+ const armedInstances = new Set();
1586
+ let liveEvaluation = null;
1587
+ let layerHandlerDepth = 0;
1588
+ const scrollBackTo = (top) => {
1589
+ if (Math.abs(window.scrollY - top) >= .5) window.scrollTo({
1590
+ top,
1591
+ behavior: "instant"
1592
+ });
1593
+ };
1594
+ const holdLiveEvaluationForGsapRefresh = (cls) => {
1595
+ const evaluation = liveEvaluation;
1596
+ if (!evaluation) return;
1597
+ const resume = suspendLiveEvaluations(evaluation, false);
1598
+ const record = scrollRecord(cls, true);
1599
+ if (record && Math.abs(record.read() - evaluation.scroll) >= .5) {
1600
+ scrollBackTo(Math.round(evaluation.scroll));
1601
+ syncScrollCache(cls);
1602
+ record.write(window.scrollY);
1603
+ setGsapRefreshReturn(window.scrollY);
1604
+ }
1605
+ const depth = layerHandlerDepth - 1;
1606
+ let held = true;
1607
+ liveEvaluation = null;
1608
+ const onRefresh = () => {
1609
+ if (!held || layerHandlerDepth > depth) return;
1610
+ held = false;
1611
+ resume();
1612
+ if (!evaluation.ended) liveEvaluation = evaluation;
1613
+ };
1614
+ addGsapListener(cls, "refresh", onRefresh);
1615
+ queueMicrotask(() => removeGsapListener(cls, "refresh", onRefresh));
1616
+ };
1503
1617
  const REST_POLL_MS = 100;
1504
1618
  const runEach = (...steps) => {
1505
1619
  let failure = null;
@@ -1525,7 +1639,9 @@ var StickyScrollTrigger = class {
1525
1639
  #dirty = false;
1526
1640
  #outermostContainer = null;
1527
1641
  #destroyed = false;
1528
- #rebuildScheduled = false;
1642
+ #depth = 0;
1643
+ #refreshInitNestedUsed = false;
1644
+ #measureAgain = false;
1529
1645
  #keepContentPending = false;
1530
1646
  #deferredRun = null;
1531
1647
  #restTimer = null;
@@ -1536,6 +1652,7 @@ var StickyScrollTrigger = class {
1536
1652
  #scrollMarginTargets;
1537
1653
  #armed = false;
1538
1654
  #dispatchObserver = null;
1655
+ #readsPageHeight = false;
1539
1656
  #dormancyClient = null;
1540
1657
  constructor(root, options = {}) {
1541
1658
  this.#rootElement = resolveRoot(root);
@@ -1561,6 +1678,7 @@ var StickyScrollTrigger = class {
1561
1678
  if (pendingDisarms.delete(this)) this.#keepContentPending = false;
1562
1679
  if (this.#armed) return;
1563
1680
  this.#armed = true;
1681
+ armedInstances.add(this);
1564
1682
  pendingKeeps.forEach((keep) => {
1565
1683
  if (keep.owner.#overlaps(this)) keep.cancelled = true;
1566
1684
  });
@@ -1570,7 +1688,8 @@ var StickyScrollTrigger = class {
1570
1688
  #disarmIfEmpty() {
1571
1689
  if (this.#armed && !this.#destroyed && !this.#layers.length && !this.#pinLayers.length) {
1572
1690
  if (pendingDisarms.has(this)) return;
1573
- if (!this.#scrollTriggerClass?.isRefreshing && this.#scrolling()) {
1691
+ const cls = this.#scrollTriggerClass;
1692
+ if (!isRefreshing(cls) && isScrollingOrUpdating(cls)) {
1574
1693
  pendingDisarms.add(this);
1575
1694
  queueMicrotask(() => this.#settleWhenAtRest());
1576
1695
  return;
@@ -1584,16 +1703,12 @@ var StickyScrollTrigger = class {
1584
1703
  if (other !== this && other.#overlaps(this)) other.#flushPendingDisarmForRevert();
1585
1704
  });
1586
1705
  }
1587
- #scrolling() {
1588
- const cls = this.#scrollTriggerClass;
1589
- return Boolean(cls?.isScrolling?.() || cls?.isUpdating === true);
1590
- }
1591
1706
  #disarmKeepingContent(keepContent, onlyAtRest = false) {
1592
1707
  const position = keepContent && this.#built ? this.#naturalScrollTop(this.#builtLayers) : null;
1593
1708
  this.#keepContentPending = false;
1594
1709
  this.#disarm();
1595
1710
  if (!position) return;
1596
- if (this.#gsapScrollRecord()) {
1711
+ if (scrollRecord(this.#scrollTriggerClass)) {
1597
1712
  this.#keepContent(position);
1598
1713
  return;
1599
1714
  }
@@ -1613,7 +1728,7 @@ var StickyScrollTrigger = class {
1613
1728
  if (!keep) return;
1614
1729
  this.#pendingKeep = null;
1615
1730
  pendingKeeps.delete(keep);
1616
- if (keep.cancelled || keep.onlyAtRest && keep.cls?.isScrolling?.()) return;
1731
+ if (keep.cancelled || keep.onlyAtRest && isScrolling(keep.cls)) return;
1617
1732
  this.#keepContent(keep.position, keep.cls);
1618
1733
  }
1619
1734
  #overlaps(other) {
@@ -1621,7 +1736,7 @@ var StickyScrollTrigger = class {
1621
1736
  }
1622
1737
  #settleWhenAtRest() {
1623
1738
  if (this.#destroyed || this.#restTimer !== null) return;
1624
- if (this.#scrollTriggerClass?.isScrolling?.()) {
1739
+ if (isScrolling(this.#scrollTriggerClass)) {
1625
1740
  this.#restTimer = setTimeout(() => {
1626
1741
  this.#restTimer = null;
1627
1742
  this.#settleWhenAtRest();
@@ -1636,10 +1751,11 @@ var StickyScrollTrigger = class {
1636
1751
  if (pendingDisarms.delete(this) && !this.#destroyed && !this.#layers.length && !this.#pinLayers.length) this.#disarmKeepingContent(keepContent, onlyAtRest);
1637
1752
  }
1638
1753
  #flushPendingDisarmForRevert() {
1639
- this.#flushPendingDisarm(!this.#scrollTriggerClass?.isScrolling?.(), true);
1754
+ this.#flushPendingDisarm(!isScrolling(this.#scrollTriggerClass), true);
1640
1755
  }
1641
1756
  #disarm() {
1642
1757
  this.#armed = false;
1758
+ armedInstances.delete(this);
1643
1759
  unregisterDormancyClient(this.#dormancyClient);
1644
1760
  this.#scrollMarginSync?.restore();
1645
1761
  this.#scrollMarginSync = null;
@@ -1669,40 +1785,45 @@ var StickyScrollTrigger = class {
1669
1785
  }
1670
1786
  #catchUp() {
1671
1787
  this.#flushPendingDisarm();
1672
- this.refresh();
1788
+ this.#runRefresh();
1673
1789
  this.#applyPendingKeep();
1674
1790
  }
1675
1791
  #scheduleRebuild() {
1676
1792
  if (this.#destroyed) return;
1677
1793
  if (this.#built) this.#keepContentPending = true;
1678
- if (this.#rebuildScheduled) return;
1679
- this.#rebuildScheduled = true;
1794
+ if (pendingCatchUps.has(this)) return;
1680
1795
  const cls = this.#scrollTriggerClass;
1681
- const onRefreshInit = () => {
1682
- if (!this.#rebuildScheduled || this.#destroyed) return void 0;
1796
+ const pending = () => pendingCatchUps.get(this) === catchUpNow;
1797
+ const catchUpNow = () => {
1798
+ if (!pending()) return false;
1799
+ pendingCatchUps.delete(this);
1800
+ if (this.#destroyed) return false;
1683
1801
  try {
1684
1802
  this.#catchUp();
1685
1803
  } catch (error) {
1686
1804
  queueMicrotask(() => {
1687
1805
  throw error;
1688
1806
  });
1689
- } finally {
1690
- this.#rebuildScheduled = false;
1691
1807
  }
1808
+ return true;
1809
+ };
1810
+ pendingCatchUps.set(this, catchUpNow);
1811
+ const onRefreshInit = () => {
1812
+ if (!catchUpNow()) return void 0;
1692
1813
  const restoreDormancy = takeGsapRefreshRestore();
1693
- return restoreDormancy ? { render: () => restoreDormancy() } : void 0;
1814
+ return restoreDormancy ? revertAfterMeasure(restoreDormancy) : void 0;
1694
1815
  };
1695
- cls?.addEventListener?.("refreshInit", onRefreshInit);
1816
+ addGsapListener(cls, "refreshInit", onRefreshInit);
1696
1817
  const run = () => {
1697
- cls?.removeEventListener?.("refreshInit", onRefreshInit);
1698
- if (!this.#rebuildScheduled) return;
1699
- this.#rebuildScheduled = false;
1700
- if (this.#destroyed) return;
1701
- this.#catchUp();
1702
- if (typeof this.#scrollTriggerClass?.refresh === "function") this.#scrollTriggerClass.refresh();
1818
+ try {
1819
+ if (pending() && !this.#destroyed) refreshAll(this.#scrollTriggerClass);
1820
+ } finally {
1821
+ removeGsapListener(cls, "refreshInit", onRefreshInit);
1822
+ catchUpNow();
1823
+ }
1703
1824
  };
1704
1825
  queueMicrotask(() => {
1705
- if (this.#rebuildScheduled && !this.#destroyed && cls?.isScrolling?.()) {
1826
+ if (pending() && !this.#destroyed && isScrolling(cls)) {
1706
1827
  const earlier = this.#deferredRun;
1707
1828
  this.#deferredRun = earlier ? () => runEach(earlier, run) : run;
1708
1829
  this.#settleWhenAtRest();
@@ -1713,28 +1834,46 @@ var StickyScrollTrigger = class {
1713
1834
  }
1714
1835
  #captureScrollTriggerClass(self) {
1715
1836
  if (this.#destroyed) return;
1716
- this.#scrollTriggerClass = self.constructor;
1837
+ this.#scrollTriggerClass = classOf(self);
1717
1838
  }
1718
1839
  #createAutoRefreshHandler(userOnRefreshInit) {
1719
- return (self) => {
1840
+ const handle = (self) => {
1720
1841
  this.#captureScrollTriggerClass(self);
1842
+ if (isRefreshing(this.#scrollTriggerClass)) holdLiveEvaluationForGsapRefresh(this.#scrollTriggerClass);
1721
1843
  const result = userOnRefreshInit?.(self);
1722
- const inGsapRefresh = this.#scrollTriggerClass?.isRefreshing === true;
1723
- const unchanged = inGsapRefresh && !userOnRefreshInit && this.#dispatchObserver !== null && this.#dispatchObserver.takeRecords().length === 0;
1844
+ const inGsapRefresh = isRefreshing(this.#scrollTriggerClass);
1845
+ let caughtUp = false;
1846
+ let refreshed = false;
1847
+ if (inGsapRefresh) {
1848
+ [...pendingCatchUps].forEach(([owner, catchUpNow]) => owner !== this && catchUpNow());
1849
+ caughtUp = pendingCatchUps.get(this)?.() === true;
1850
+ if (caughtUp) this.#dispatchObserver?.takeRecords();
1851
+ }
1852
+ const unchanged = inGsapRefresh && !userOnRefreshInit && !this.#dirty && (caughtUp || this.#dispatchObserver !== null && this.#dispatchObserver.takeRecords().length === 0);
1724
1853
  try {
1725
- if (!unchanged) this.refresh();
1854
+ if (!unchanged) {
1855
+ refreshed = true;
1856
+ this.#refreshFrom(true);
1857
+ }
1726
1858
  } catch (error) {
1727
1859
  queueMicrotask(() => {
1728
1860
  throw error;
1729
1861
  });
1730
1862
  }
1731
- if (inGsapRefresh) this.#watchGsapRefresh();
1863
+ if (inGsapRefresh) {
1864
+ this.#watchGsapRefresh();
1865
+ if (refreshed || caughtUp) this.#remeasureEarlierInGsapRefresh();
1866
+ }
1732
1867
  const restoreDormancy = takeGsapRefreshRestore();
1733
- if (!restoreDormancy) return result;
1734
- return { render: (time) => {
1735
- result?.render?.(time);
1736
- restoreDormancy();
1737
- } };
1868
+ return restoreDormancy ? revertAfterMeasure(restoreDormancy, result) : result;
1869
+ };
1870
+ return (self) => {
1871
+ layerHandlerDepth += 1;
1872
+ try {
1873
+ return handle(self);
1874
+ } finally {
1875
+ layerHandlerDepth -= 1;
1876
+ }
1738
1877
  };
1739
1878
  }
1740
1879
  #watchGsapRefresh() {
@@ -1747,7 +1886,7 @@ var StickyScrollTrigger = class {
1747
1886
  const end = () => {
1748
1887
  observer.disconnect();
1749
1888
  if (this.#dispatchObserver === observer) this.#dispatchObserver = null;
1750
- queueMicrotask(() => cls?.removeEventListener?.("refresh", end));
1889
+ queueMicrotask(() => removeGsapListener(cls, "refresh", end));
1751
1890
  };
1752
1891
  observer.observe(document, {
1753
1892
  subtree: true,
@@ -1756,9 +1895,39 @@ var StickyScrollTrigger = class {
1756
1895
  characterData: true
1757
1896
  });
1758
1897
  this.#dispatchObserver = observer;
1759
- cls?.addEventListener?.("refresh", end);
1898
+ addGsapListener(cls, "refresh", end);
1760
1899
  queueMicrotask(end);
1761
1900
  }
1901
+ #remeasureEarlierInGsapRefresh() {
1902
+ const refreshed = refreshedInGsapRefresh ?? new Map();
1903
+ if (!refreshedInGsapRefresh) {
1904
+ refreshedInGsapRefresh = refreshed;
1905
+ queueMicrotask(() => {
1906
+ if (refreshedInGsapRefresh === refreshed) refreshedInGsapRefresh = null;
1907
+ });
1908
+ }
1909
+ refreshed.set(this, this.#outsideReads());
1910
+ refreshed.forEach((reads, other) => {
1911
+ if (other.#destroyed || reads === other.#outsideReads()) return;
1912
+ try {
1913
+ other.#refreshFrom(true);
1914
+ } catch (error) {
1915
+ queueMicrotask(() => {
1916
+ throw error;
1917
+ });
1918
+ }
1919
+ other.#dispatchObserver?.takeRecords();
1920
+ refreshed.set(other, other.#outsideReads());
1921
+ });
1922
+ }
1923
+ #outsideReads() {
1924
+ const reads = [documentTop(this.#rootElement)];
1925
+ if (this.#readsPageHeight) reads.push(measureDocumentHeightWithoutPinRanges());
1926
+ [...this.#layers, ...this.#pinLayers].forEach(({ endTrigger }) => {
1927
+ if (!this.#rootElement.contains(endTrigger)) reads.push(documentTop(endTrigger));
1928
+ });
1929
+ return reads.join(",");
1930
+ }
1762
1931
  #wrapUnwrappedPins() {
1763
1932
  this.#pinLayers.forEach((layer) => {
1764
1933
  if (layer.outer) return;
@@ -1775,16 +1944,14 @@ var StickyScrollTrigger = class {
1775
1944
  range: inner.style.height
1776
1945
  }] : []);
1777
1946
  wrapped.forEach(({ outer, inner }) => {
1778
- outer.style.height = "";
1779
- inner.style.height = "";
1947
+ clearHeightForRead(outer);
1948
+ clearHeightForRead(inner);
1780
1949
  });
1781
1950
  const reserved = wrapped.map(({ outer }) => measureUsedHeight(outer));
1782
1951
  wrapped.forEach(({ outer }, index) => {
1783
- outer.style.height = `${reserved[index]}px`;
1784
- });
1785
- wrapped.forEach(({ inner, range }) => {
1786
- inner.style.height = range;
1952
+ commitHeight(outer, `${reserved[index]}px`);
1787
1953
  });
1954
+ wrapped.forEach(({ inner, range }) => commitHeight(inner, range));
1788
1955
  }
1789
1956
  #unwrapPinLayer(layer) {
1790
1957
  if (!layer.outer) return false;
@@ -1798,7 +1965,13 @@ var StickyScrollTrigger = class {
1798
1965
  return stripStickyPositions(this.#builtLayers.flatMap(({ wrapper }) => wrapper ? [wrapper] : []));
1799
1966
  }
1800
1967
  #resetPinStickyState() {
1801
- return stripStickyPositions(this.#wrappedPinTriggers());
1968
+ const restores = this.#pinLayers.filter(({ inner }) => inner).map((layer) => ({
1969
+ layer,
1970
+ restore: stripStickyPositions([layer.trigger])
1971
+ }));
1972
+ return () => restores.forEach(({ layer, restore }) => {
1973
+ if (layer.inner) restore();
1974
+ });
1802
1975
  }
1803
1976
  #resetStickyState() {
1804
1977
  const restoreSceneCoverStickyState = this.#resetSceneCoverStickyState();
@@ -1808,39 +1981,59 @@ var StickyScrollTrigger = class {
1808
1981
  restoreSceneCoverStickyState();
1809
1982
  };
1810
1983
  }
1811
- #resetPinState() {
1812
- const snapshots = this.#pinLayers.map((layer) => ({
1984
+ #refreshGeometry(viewportHeight) {
1985
+ const active = this.#layers.filter((layer) => layer.wrapper !== null);
1986
+ const wrappers = active.flatMap(({ wrapper }) => wrapper ? [wrapper] : []);
1987
+ const savedWrappers = wrappers.map(captureInlinePosition);
1988
+ const pins = this.#pinLayers.map((layer) => ({
1813
1989
  layer,
1814
1990
  position: captureInlinePosition(layer.trigger),
1815
- height: layer.inner ? layer.inner.style.height : ""
1991
+ range: layer.inner ? layer.inner.style.height : ""
1816
1992
  }));
1817
- snapshots.forEach(({ layer }) => {
1818
- resetStickyPosition(layer.trigger);
1819
- if (layer.inner) layer.inner.style.height = "";
1820
- });
1821
- return () => {
1822
- snapshots.forEach(({ layer, position, height }) => {
1823
- restoreInlinePosition(layer.trigger, position);
1824
- if (layer.inner) layer.inner.style.height = height;
1993
+ wrappers.forEach(clearStickyForRead);
1994
+ pins.forEach(({ layer }) => clearStickyForRead(layer.trigger));
1995
+ let stickyTops;
1996
+ let marginTops;
1997
+ try {
1998
+ const measured = active.length ? this.#measureLayers(viewportHeight, active) : null;
1999
+ marginTops = this.#measureScrollMarginTargets(active);
2000
+ stickyTops = measured ? this.#planLayerPositions(viewportHeight, active, measured) : new Map();
2001
+ this.#readsPageHeight = pins.length > 0 || (measured?.measured.some(({ end }) => end.mode === "max") ?? false);
2002
+ } catch (error) {
2003
+ wrappers.forEach((wrapper, i) => commitPosition(wrapper, savedWrappers[i]));
2004
+ pins.forEach(({ layer, position }) => {
2005
+ if (layer.inner) commitPosition(layer.trigger, position);
1825
2006
  });
1826
- };
1827
- }
1828
- #refreshPins(viewportHeight) {
1829
- if (!this.#pinLayers.length) return;
1830
- const restoreSceneCoverStickyState = this.#resetSceneCoverStickyState();
1831
- const restorePinState = this.#resetPinState();
2007
+ throw error;
2008
+ }
2009
+ let plannedPins = [];
1832
2010
  try {
1833
- this.#refreshPinLayers(viewportHeight, measureDocumentHeightWithoutPinRanges());
2011
+ if (pins.length) {
2012
+ pins.forEach(({ layer }) => {
2013
+ if (layer.inner) clearHeightForRead(layer.inner);
2014
+ });
2015
+ plannedPins = this.#planPinLayers(viewportHeight, measureDocumentHeightWithoutPinRanges());
2016
+ }
1834
2017
  } catch (error) {
1835
- restorePinState();
2018
+ stickyTops.forEach((top, wrapper) => commitSticky(wrapper, top));
2019
+ pins.forEach(({ layer, position, range }) => {
2020
+ if (!layer.inner) return;
2021
+ commitPosition(layer.trigger, position);
2022
+ commitHeight(layer.inner, range);
2023
+ });
1836
2024
  throw error;
1837
- } finally {
1838
- restoreSceneCoverStickyState();
1839
2025
  }
1840
- }
1841
- #refreshPinLayers(viewportHeight, documentHeight) {
1842
- this.#pinLayers.forEach((layer) => {
2026
+ stickyTops.forEach((top, wrapper) => commitSticky(wrapper, top));
2027
+ plannedPins.forEach(({ layer, topPx, range }) => {
1843
2028
  if (!layer.inner) return;
2029
+ commitSticky(layer.trigger, topPx);
2030
+ commitHeight(layer.inner, `${range}px`);
2031
+ });
2032
+ this.#syncScrollMargins(marginTops);
2033
+ }
2034
+ #planPinLayers(viewportHeight, documentHeight) {
2035
+ return this.#pinLayers.flatMap((layer) => {
2036
+ if (!layer.inner) return [];
1844
2037
  const resolvedStart = resolveMaybeFn(layer.start);
1845
2038
  const resolvedEnd = prefixSpacedRelativeEnd(resolvedStart, resolveMaybeFn(layer.end));
1846
2039
  const classifiedEnd = classifyPosition(resolvedEnd);
@@ -1855,26 +2048,14 @@ var StickyScrollTrigger = class {
1855
2048
  const releaseScroll = resolvePinReleaseScroll(layer.endTrigger, classifiedEnd, toScroll(layer.trigger, triggerTop - topPx), viewportHeight, toScroll);
1856
2049
  const height = releaseScroll - (this.#rootElement.contains(layer.trigger) ? dwellConsumedAt(releaseScroll, this.#engagedWindows()) : 0) - triggerTop + topPx + triggerHeight + triggerMarginBottom;
1857
2050
  const room = documentHeight > 0 ? documentHeight - triggerTop : Infinity;
1858
- applyStickyPosition(layer.trigger, topPx);
1859
- layer.inner.style.height = `${Math.max(0, Math.min(height, room))}px`;
2051
+ return [{
2052
+ layer,
2053
+ topPx,
2054
+ range: Math.max(0, Math.min(height, room))
2055
+ }];
1860
2056
  });
1861
2057
  }
1862
- #refreshScenesAndCovers(viewportHeight) {
1863
- if (!this.#layers.length) return;
1864
- const active = this.#layers.filter((layer) => layer.wrapper !== null);
1865
- if (!active.length) return;
1866
- const restoreStickyState = this.#resetSceneCoverStickyState();
1867
- const restorePinStickyState = this.#resetPinStickyState();
1868
- try {
1869
- this.#planLayerPositions(viewportHeight, active);
1870
- } catch (error) {
1871
- restoreStickyState();
1872
- throw error;
1873
- } finally {
1874
- restorePinStickyState();
1875
- }
1876
- }
1877
- #planLayerPositions(viewportHeight, active) {
2058
+ #measureLayers(viewportHeight, active) {
1878
2059
  const structureTop = this.#outermostContainer ? documentTop(this.#outermostContainer) : 0;
1879
2060
  this.#measuredStructure = {
1880
2061
  top: structureTop,
@@ -1884,14 +2065,22 @@ var StickyScrollTrigger = class {
1884
2065
  active.forEach((layer, index) => {
1885
2066
  indexByTrigger.set(layer.trigger, index);
1886
2067
  });
1887
- const measured = active.map((layer, ownIndex) => measureLayer(this.#rootElement, viewportHeight, layer, ownIndex, indexByTrigger));
2068
+ return {
2069
+ structureTop,
2070
+ measured: active.map((layer, ownIndex) => measureLayer(this.#rootElement, viewportHeight, layer, ownIndex, indexByTrigger))
2071
+ };
2072
+ }
2073
+ #planLayerPositions(viewportHeight, active, { structureTop, measured }) {
2074
+ const needsLiveRemeasure = measured.some((measurement) => measurement.end.mode === "clause" && measurement.end.measureLive);
2075
+ const needsMaxRemeasure = measured.some((measurement) => measurement.end.mode === "max");
1888
2076
  let documentMaxScroll = 0;
2077
+ let measureLive = false;
1889
2078
  const stickyTops = new Map();
1890
2079
  const applyLayers = () => planLayers(measured, {
1891
2080
  viewportHeight,
1892
2081
  structureTop,
1893
2082
  documentMaxScroll,
1894
- measureLiveEndTriggerTop: (index) => documentTop(active[index].endTrigger),
2083
+ measureLiveEndTriggerTop: (index) => measureLive ? documentTop(active[index].endTrigger) : 0,
1895
2084
  onPlanned: (index, plan) => {
1896
2085
  const layer = active[index];
1897
2086
  layer.freezeStart = plan.freezeStart;
@@ -1900,25 +2089,137 @@ var StickyScrollTrigger = class {
1900
2089
  layer.engagedEnd = plan.engagedEnd;
1901
2090
  if (!layer.wrapper) return;
1902
2091
  stickyTops.set(layer.wrapper, plan.stickyTop);
1903
- if (layer.kind === "scene" && layer.padding && plan.paddingHeight !== null) layer.padding.style.height = `${plan.paddingHeight}px`;
2092
+ if (layer.kind === "scene" && layer.padding && plan.paddingHeight !== null) commitHeight(layer.padding, `${plan.paddingHeight}px`);
1904
2093
  }
1905
2094
  });
2095
+ this.#reevaluateLiveEnds(active, measured, () => {
2096
+ const heights = active.map(() => 0);
2097
+ planLayers(measured, {
2098
+ viewportHeight,
2099
+ structureTop,
2100
+ documentMaxScroll,
2101
+ measureLiveEndTriggerTop: () => 0,
2102
+ onPlanned: (index, plan) => {
2103
+ heights[index] = plan.paddingHeight ?? 0;
2104
+ }
2105
+ });
2106
+ return heights;
2107
+ });
1906
2108
  applyLayers();
1907
- const needsLiveRemeasure = measured.some((measurement) => measurement.end.mode === "clause" && measurement.end.measureLive);
1908
- const needsMaxRemeasure = measured.some((measurement) => measurement.end.mode === "max");
1909
- if (needsMaxRemeasure) documentMaxScroll = measureDocumentMaxScroll(viewportHeight);
2109
+ if (needsMaxRemeasure) documentMaxScroll = Math.max(0, measureDocumentHeightWithoutPinRanges() - viewportHeight);
2110
+ measureLive = true;
1910
2111
  if (needsLiveRemeasure || needsMaxRemeasure) applyLayers();
1911
- stickyTops.forEach((top, wrapper) => applyStickyPosition(wrapper, top));
2112
+ return stickyTops;
2113
+ }
2114
+ #reevaluateLiveEnds(active, measured, planPaddings) {
2115
+ const live = measured.flatMap(({ liveEnd }, index) => liveEnd ? [{
2116
+ index,
2117
+ liveEnd
2118
+ }] : []);
2119
+ if (!live.length) return;
2120
+ const scrollBefore = window.scrollY;
2121
+ try {
2122
+ for (let round = 0; round < LIVE_END_ROUNDS; round += 1) {
2123
+ const planned = planPaddings();
2124
+ let moved = false;
2125
+ live.forEach(({ index, liveEnd }) => {
2126
+ const next = this.#evaluateLiveEnd(active, planned, index, liveEnd, scrollBefore);
2127
+ const current = measured[index].end;
2128
+ if (!next || next.mode !== current.mode) return;
2129
+ if (Math.abs(liveEndValue(next) - liveEndValue(current)) <= LIVE_END_TOLERANCE_PX) return;
2130
+ measured[index] = {
2131
+ ...measured[index],
2132
+ end: next
2133
+ };
2134
+ moved = true;
2135
+ });
2136
+ if (!moved) break;
2137
+ }
2138
+ } finally {
2139
+ scrollBackTo(scrollBefore);
2140
+ }
2141
+ }
2142
+ #evaluateLiveEnd(active, planned, index, liveEnd, scroll) {
2143
+ const spacers = active.flatMap((layer, k) => k < index && layer.kind === "scene" && planned[k] ? [{
2144
+ after: layer.trigger,
2145
+ height: planned[k]
2146
+ }] : []);
2147
+ const setUp = () => {
2148
+ const later = [...armedInstances].filter((other) => other !== this && compareDocumentOrder(this.#rootElement, other.#rootElement) < 0);
2149
+ const paddings = [this, ...later].flatMap((instance) => instance.#layers.flatMap((layer) => layer.kind === "scene" && layer.padding ? [layer.padding] : []));
2150
+ const heights = paddings.map((padding) => padding.style.height);
2151
+ paddings.forEach((padding) => commitHeight(padding, "0px"));
2152
+ const removeSpacers = insertSpacers(spacers);
2153
+ return () => {
2154
+ removeSpacers();
2155
+ paddings.forEach((padding, k) => {
2156
+ if (padding.style.height === "0px") commitHeight(padding, heights[k]);
2157
+ });
2158
+ };
2159
+ };
2160
+ let takeDown = () => {};
2161
+ let holds = 0;
2162
+ const evaluation = {
2163
+ resolved: false,
2164
+ ended: false,
2165
+ outer: liveEvaluation,
2166
+ scroll: liveEvaluation?.scroll ?? scroll,
2167
+ suspend: (resolving) => {
2168
+ if (resolving) evaluation.resolved = true;
2169
+ holds += 1;
2170
+ if (holds === 1) {
2171
+ takeDown();
2172
+ takeDown = () => {};
2173
+ }
2174
+ return () => {
2175
+ holds -= 1;
2176
+ if (holds === 0 && !evaluation.ended) takeDown = setUp();
2177
+ };
2178
+ }
2179
+ };
2180
+ try {
2181
+ takeDown = setUp();
2182
+ liveEvaluation = evaluation;
2183
+ const next = liveEnd();
2184
+ return evaluation.resolved ? null : next;
2185
+ } finally {
2186
+ evaluation.ended = true;
2187
+ liveEvaluation = evaluation.outer;
2188
+ takeDown();
2189
+ }
1912
2190
  }
1913
2191
  refresh() {
2192
+ this.#refreshFrom(false);
2193
+ }
2194
+ #refreshFrom(refreshInit) {
2195
+ if (this.#depth > 0 && !this.#dirty) {
2196
+ if (!refreshInit) {
2197
+ this.#measureAgain = true;
2198
+ return;
2199
+ }
2200
+ if (this.#refreshInitNestedUsed) return;
2201
+ this.#refreshInitNestedUsed = true;
2202
+ }
2203
+ this.#runRefresh();
2204
+ }
2205
+ #runRefresh() {
2206
+ if (this.#depth > 0) this.#measureAgain = true;
1914
2207
  if (this.#destroyed || !this.#armed || pendingDisarms.has(this)) return;
1915
2208
  let failure = null;
1916
2209
  const position = this.#keepContentPending ? this.#naturalScrollTop(this.#builtLayers) : null;
1917
2210
  this.#keepContentPending = false;
2211
+ this.#depth += 1;
1918
2212
  try {
1919
2213
  this.#refreshLayout();
2214
+ if (this.#depth === 1 && this.#measureAgain && !this.#destroyed && this.#armed && !pendingDisarms.has(this)) this.#refreshLayout();
1920
2215
  } catch (error) {
1921
2216
  failure = { error };
2217
+ } finally {
2218
+ this.#depth -= 1;
2219
+ if (this.#depth === 0) {
2220
+ this.#refreshInitNestedUsed = false;
2221
+ this.#measureAgain = false;
2222
+ }
1922
2223
  }
1923
2224
  try {
1924
2225
  rebuildDormancy(this.#scrollTriggerClass);
@@ -1932,15 +2233,10 @@ var StickyScrollTrigger = class {
1932
2233
  if (!failure && position !== null) this.#keepContent(position);
1933
2234
  if (failure) throw failure.error;
1934
2235
  }
1935
- #gsapScrollRecord() {
1936
- if (!this.#scrollTriggerClass?.isRefreshing) return null;
1937
- const scrollFunc = this.#scrollTriggerClass.getScrollFunc?.(window);
1938
- return scrollFunc && typeof scrollFunc.rec === "number" && scrollFunc.rec ? scrollFunc : null;
1939
- }
1940
2236
  #naturalScrollTop(layers) {
1941
2237
  const measured = this.#measuredStructure;
1942
2238
  const moved = measured && this.#outermostContainer && measured.unbuilds !== unbuildCount ? documentTop(this.#outermostContainer) - measured.top : 0;
1943
- const scroll = (this.#gsapScrollRecord()?.rec ?? window.scrollY) - moved;
2239
+ const scroll = (scrollRecord(this.#scrollTriggerClass)?.read() ?? window.scrollY) - moved;
1944
2240
  const consumed = new Map();
1945
2241
  layers.forEach((layer) => {
1946
2242
  if (layer.kind !== "scene") return;
@@ -1953,20 +2249,17 @@ var StickyScrollTrigger = class {
1953
2249
  }
1954
2250
  #keepContent(position, cls = this.#scrollTriggerClass) {
1955
2251
  const target = this.#keptScrollTop(position);
1956
- const record = this.#gsapScrollRecord();
2252
+ const record = scrollRecord(this.#scrollTriggerClass);
1957
2253
  if (record) {
1958
- record.rec = target;
2254
+ record.write(target);
1959
2255
  return;
1960
2256
  }
1961
- if (cls?.isRefreshing) return;
2257
+ if (isRefreshing(cls)) return;
1962
2258
  if (Math.abs(window.scrollY - target) >= .5) window.scrollTo({
1963
2259
  top: Math.round(target),
1964
2260
  behavior: "instant"
1965
2261
  });
1966
- const scrollFunc = cls?.getScrollFunc?.(window);
1967
- if (typeof scrollFunc !== "function") return;
1968
- const cached = scrollFunc();
1969
- if (typeof cached !== "number" || Math.abs(cached - window.scrollY) >= .5) scrollFunc(window.scrollY);
2262
+ syncScrollCache(cls);
1970
2263
  }
1971
2264
  #keptScrollTop({ natural, consumed }) {
1972
2265
  let earlierDwell = 0;
@@ -1993,9 +2286,7 @@ var StickyScrollTrigger = class {
1993
2286
  this.#liftCovers();
1994
2287
  }
1995
2288
  const viewportHeight = this.#layers.length || this.#pinLayers.length ? measureViewportHeight() : 0;
1996
- this.#refreshScenesAndCovers(viewportHeight);
1997
- this.#refreshPins(viewportHeight);
1998
- this.#syncScrollMargins();
2289
+ this.#refreshGeometry(viewportHeight);
1999
2290
  }
2000
2291
  #coverLayers() {
2001
2292
  return this.#layers.filter((layer) => layer.kind === "cover");
@@ -2009,15 +2300,21 @@ var StickyScrollTrigger = class {
2009
2300
  this.#coverRestoreByLayer.set(layer, liftAboveStickyWrapper(pin?.outer ?? layer.cover));
2010
2301
  });
2011
2302
  }
2012
- #syncScrollMargins() {
2303
+ #syncScrollMargins(tops) {
2013
2304
  this.#scrollMarginSync?.sync(this.#engagedWindows(), this.#outermostContainer, (targets) => {
2014
- if (!targets.length) return [];
2015
- const restoreStickyState = this.#resetStickyState();
2016
- const tops = targets.map((target) => documentTop(target));
2017
- restoreStickyState();
2018
- return tops;
2305
+ const late = targets.filter((target) => !tops.has(target));
2306
+ if (late.length) {
2307
+ const restoreStickyState = this.#resetStickyState();
2308
+ late.forEach((target) => tops.set(target, documentTop(target)));
2309
+ restoreStickyState();
2310
+ }
2311
+ return targets.map((target) => tops.get(target));
2019
2312
  });
2020
2313
  }
2314
+ #measureScrollMarginTargets(active) {
2315
+ const targets = this.#scrollMarginSync && active.some(({ kind }) => kind === "scene") ? this.#scrollMarginSync.targets() : [];
2316
+ return new Map(targets.map((target) => [target, documentTop(target)]));
2317
+ }
2021
2318
  #assertNoExcludedVars(rest, context) {
2022
2319
  const found = EXCLUDED_VAR_KEYS.filter((key) => key in rest);
2023
2320
  if (found.length === 0) return;
@@ -2042,6 +2339,7 @@ var StickyScrollTrigger = class {
2042
2339
  this.#arm();
2043
2340
  this.#layers.push(layer);
2044
2341
  this.#dirty = true;
2342
+ if (this.#depth > 0) this.#measureAgain = true;
2045
2343
  return {
2046
2344
  ...rest,
2047
2345
  trigger: layer.trigger,
@@ -2050,6 +2348,10 @@ var StickyScrollTrigger = class {
2050
2348
  invalidateOnRefresh: rest.invalidateOnRefresh ?? true,
2051
2349
  onKill: (self) => {
2052
2350
  this.#captureScrollTriggerClass(self);
2351
+ if (!this.#layers.includes(layer)) {
2352
+ onKill?.(self);
2353
+ return;
2354
+ }
2053
2355
  removeItem(this.#layers, layer);
2054
2356
  this.#dirty = true;
2055
2357
  this.#scheduleRebuild();
@@ -2131,6 +2433,7 @@ var StickyScrollTrigger = class {
2131
2433
  };
2132
2434
  this.#arm();
2133
2435
  this.#pinLayers.push(layer);
2436
+ if (this.#depth > 0) this.#measureAgain = true;
2134
2437
  return {
2135
2438
  ...rest,
2136
2439
  trigger,
@@ -2145,6 +2448,14 @@ var StickyScrollTrigger = class {
2145
2448
  };
2146
2449
  }
2147
2450
  resolveScrollPosition(elementInput, position) {
2451
+ const resume = liveEvaluation && suspendLiveEvaluations(liveEvaluation, true);
2452
+ try {
2453
+ return this.#resolveScrollPosition(elementInput, position);
2454
+ } finally {
2455
+ resume?.();
2456
+ }
2457
+ }
2458
+ #resolveScrollPosition(elementInput, position) {
2148
2459
  const element = resolveElement(elementInput, "resolveScrollPosition");
2149
2460
  const resolved = resolveMaybeFn(position);
2150
2461
  const viewportHeight = measureViewportHeight();