sticky-scroll-trigger 0.11.0 → 0.12.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 +29 -7
- package/dist/StickyScrollTrigger.d.ts +4 -1
- package/dist/StickyScrollTrigger.global.js +604 -121
- package/dist/StickyScrollTrigger.global.min.js +2 -2
- package/dist/StickyScrollTrigger.js +604 -121
- package/dist/StickyScrollTrigger.min.js +2 -2
- package/package.json +12 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* StickyScrollTrigger v0.
|
|
3
|
+
* StickyScrollTrigger v0.12.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
|
|
@@ -99,6 +99,11 @@ var StickyScrollTrigger = (function() {
|
|
|
99
99
|
el.style.position = saved.position;
|
|
100
100
|
el.style.top = saved.top;
|
|
101
101
|
};
|
|
102
|
+
const stripStickyPositions = (elements) => {
|
|
103
|
+
const saved = elements.map(captureInlinePosition);
|
|
104
|
+
elements.forEach(resetStickyPosition);
|
|
105
|
+
return () => elements.forEach((el, i) => restoreInlinePosition(el, saved[i]));
|
|
106
|
+
};
|
|
102
107
|
const wrapScene = (inner, holdTrailingMargin) => {
|
|
103
108
|
if (!inner.parentNode) throw new Error(`StickyScrollTrigger: ${describeElement(inner)} is not attached to the document`);
|
|
104
109
|
const container = document.createElement("div");
|
|
@@ -201,6 +206,438 @@ var StickyScrollTrigger = (function() {
|
|
|
201
206
|
lifted.length = 0;
|
|
202
207
|
};
|
|
203
208
|
};
|
|
209
|
+
const AUTO_MIN_DEPTH = 7;
|
|
210
|
+
const MAX_CHAIN_IN_BAND = 4;
|
|
211
|
+
const BUFFER_FLOOR_PX = 325;
|
|
212
|
+
const BUFFER_STEP_PX = 25;
|
|
213
|
+
const isWebKit = () => typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("font", "-apple-system-body") || typeof navigator !== "undefined" && navigator.vendor === "Apple Computer, Inc." && !/\bjsdom\//.test(navigator.userAgent);
|
|
214
|
+
const mergeIntervals = (intervals) => {
|
|
215
|
+
const sorted = intervals.filter(([a, b]) => b > a).sort((x, y) => x[0] - y[0]);
|
|
216
|
+
const merged = [];
|
|
217
|
+
sorted.forEach(([a, b]) => {
|
|
218
|
+
const last = merged.at(-1);
|
|
219
|
+
if (last && a <= last[1]) last[1] = Math.max(last[1], b);
|
|
220
|
+
else merged.push([a, b]);
|
|
221
|
+
});
|
|
222
|
+
return merged;
|
|
223
|
+
};
|
|
224
|
+
const invertStuckUnion = (union, y, inclusive) => {
|
|
225
|
+
let scroll = y;
|
|
226
|
+
for (const [a, b] of union) if (inclusive ? a <= scroll : a < scroll) scroll += b - a;
|
|
227
|
+
else break;
|
|
228
|
+
return scroll;
|
|
229
|
+
};
|
|
230
|
+
const isTransformed = (style) => [
|
|
231
|
+
style.transform,
|
|
232
|
+
style.translate,
|
|
233
|
+
style.scale,
|
|
234
|
+
style.rotate
|
|
235
|
+
].some((value) => value !== void 0 && value !== "" && value !== "none");
|
|
236
|
+
const hasTransform = (el, memo) => {
|
|
237
|
+
if (!el) return false;
|
|
238
|
+
const known = memo.get(el);
|
|
239
|
+
if (known !== void 0) return known;
|
|
240
|
+
const result = isTransformed(getComputedStyle(el)) || hasTransform(el.parentElement, memo);
|
|
241
|
+
memo.set(el, result);
|
|
242
|
+
return result;
|
|
243
|
+
};
|
|
244
|
+
const scrolls = (style) => ![style.overflowX, style.overflowY].every((v) => v === "visible" || v === "clip");
|
|
245
|
+
const bodyScrolls = () => scrolls(getComputedStyle(document.documentElement)) && scrolls(getComputedStyle(document.body));
|
|
246
|
+
const isInsideScroller = (el, memo) => {
|
|
247
|
+
const node = el.parentElement;
|
|
248
|
+
if (!node || node === document.body || node === document.documentElement) return false;
|
|
249
|
+
const known = memo.get(node);
|
|
250
|
+
if (known !== void 0) return known;
|
|
251
|
+
const style = getComputedStyle(node);
|
|
252
|
+
const result = style.position === "fixed" || scrolls(style) || isInsideScroller(node, memo);
|
|
253
|
+
memo.set(node, result);
|
|
254
|
+
return result;
|
|
255
|
+
};
|
|
256
|
+
const ownedDepth = (owned, demoted) => {
|
|
257
|
+
const levels = new Map();
|
|
258
|
+
const levelsUpFrom = (node) => {
|
|
259
|
+
if (!node) return 0;
|
|
260
|
+
const known = levels.get(node);
|
|
261
|
+
if (known !== void 0) return known;
|
|
262
|
+
const level = (demoted.has(node) || getComputedStyle(node).position === "sticky" ? 1 : 0) + levelsUpFrom(node.parentElement);
|
|
263
|
+
levels.set(node, level);
|
|
264
|
+
return level;
|
|
265
|
+
};
|
|
266
|
+
const scrollerMemo = new Map();
|
|
267
|
+
let depth = 0;
|
|
268
|
+
for (const el of owned) {
|
|
269
|
+
if (!el.isConnected || isInsideScroller(el, scrollerMemo)) continue;
|
|
270
|
+
depth = Math.max(depth, 1 + levelsUpFrom(el.parentElement));
|
|
271
|
+
}
|
|
272
|
+
return depth;
|
|
273
|
+
};
|
|
274
|
+
const SIMPLE_TOP = /^-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(px|%)$/i;
|
|
275
|
+
const clients = new Set();
|
|
276
|
+
let records = [];
|
|
277
|
+
let buffer = 0;
|
|
278
|
+
let listening = false;
|
|
279
|
+
let scrollBeforeGsapRefresh = null;
|
|
280
|
+
let gsapPhase = "idle";
|
|
281
|
+
let adoptedMidRefresh = false;
|
|
282
|
+
let scannedThisTask = null;
|
|
283
|
+
const gsapClasses = new Set();
|
|
284
|
+
const gsapRefreshing = () => Array.from(gsapClasses).some((cls) => cls.isRefreshing === true);
|
|
285
|
+
const stateAt = (record, scroll) => {
|
|
286
|
+
if (!record.demotable) return "in";
|
|
287
|
+
if (scroll < record.lo - buffer) return "before";
|
|
288
|
+
return scroll > record.hi + buffer && !record.holdsAfter ? "after" : "in";
|
|
289
|
+
};
|
|
290
|
+
const promote = (record, afterMeasure = false) => {
|
|
291
|
+
const { style } = record.el;
|
|
292
|
+
const demoted = record.state !== "in";
|
|
293
|
+
const positionOurs = afterMeasure && style.position === "static" || demoted && style.position === "relative";
|
|
294
|
+
if (positionOurs) style.position = record.position;
|
|
295
|
+
if (demoted && positionOurs && style.top === record.demotedTop) style.top = record.top;
|
|
296
|
+
if (demoted && record.zIndexAuto && style.zIndex === "0") style.zIndex = record.zIndex;
|
|
297
|
+
if (demoted && record.willChangeAuto && style.willChange === "opacity") style.willChange = record.willChange;
|
|
298
|
+
record.state = "in";
|
|
299
|
+
};
|
|
300
|
+
const applyState = (record, state) => {
|
|
301
|
+
if (record.state === state) return;
|
|
302
|
+
if (state === "in") {
|
|
303
|
+
promote(record);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const { style } = record.el;
|
|
307
|
+
style.position = "relative";
|
|
308
|
+
style.top = `${state === "before" ? 0 : record.travel}px`;
|
|
309
|
+
record.demotedTop = style.top;
|
|
310
|
+
if (record.zIndexAuto) style.zIndex = "0";
|
|
311
|
+
if (record.willChangeAuto) style.willChange = "opacity";
|
|
312
|
+
record.state = state;
|
|
313
|
+
};
|
|
314
|
+
const update = (scroll) => {
|
|
315
|
+
records.forEach((record) => applyState(record, stateAt(record, scroll)));
|
|
316
|
+
};
|
|
317
|
+
const onScroll = () => update(window.scrollY);
|
|
318
|
+
const listen = (on) => {
|
|
319
|
+
if (on === listening) return;
|
|
320
|
+
listening = on;
|
|
321
|
+
if (on) window.addEventListener("scroll", onScroll, { passive: true });
|
|
322
|
+
else window.removeEventListener("scroll", onScroll);
|
|
323
|
+
};
|
|
324
|
+
const clearTable = () => {
|
|
325
|
+
records.forEach((record) => promote(record));
|
|
326
|
+
records = [];
|
|
327
|
+
listen(false);
|
|
328
|
+
};
|
|
329
|
+
const restoreAfterGsapMeasure = () => {
|
|
330
|
+
const scroll = scrollBeforeGsapRefresh;
|
|
331
|
+
if (gsapPhase !== "measuring" || scroll === null) return;
|
|
332
|
+
gsapPhase = "restored";
|
|
333
|
+
if (records.length) update(scroll);
|
|
334
|
+
};
|
|
335
|
+
const endGsapRefresh = () => {
|
|
336
|
+
gsapPhase = "idle";
|
|
337
|
+
scrollBeforeGsapRefresh = null;
|
|
338
|
+
adoptedMidRefresh = false;
|
|
339
|
+
};
|
|
340
|
+
const rebuildSafely = () => {
|
|
341
|
+
try {
|
|
342
|
+
rebuildDormancy(null);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
clearTable();
|
|
345
|
+
queueMicrotask(() => {
|
|
346
|
+
throw error;
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
const onGsapRefreshDone = () => {
|
|
351
|
+
const wasRefreshing = gsapPhase !== "idle";
|
|
352
|
+
endGsapRefresh();
|
|
353
|
+
if (wasRefreshing && liveClients().length) rebuildSafely();
|
|
354
|
+
};
|
|
355
|
+
const onGsapRefreshInit = () => {
|
|
356
|
+
if (gsapPhase === "idle") {
|
|
357
|
+
gsapPhase = "measuring";
|
|
358
|
+
scrollBeforeGsapRefresh = window.scrollY;
|
|
359
|
+
queueMicrotask(onGsapRefreshDone);
|
|
360
|
+
if (records.length) update(0);
|
|
361
|
+
}
|
|
362
|
+
return { render: restoreAfterGsapMeasure };
|
|
363
|
+
};
|
|
364
|
+
const adoptGsapClass = (cls) => {
|
|
365
|
+
if (gsapClasses.has(cls)) return;
|
|
366
|
+
if (cls.isRefreshing === true) adoptedMidRefresh = true;
|
|
367
|
+
gsapClasses.add(cls);
|
|
368
|
+
cls.addEventListener?.("refresh", onGsapRefreshDone);
|
|
369
|
+
cls.addEventListener?.("refreshInit", onGsapRefreshInit);
|
|
370
|
+
};
|
|
371
|
+
const dropGsapClassesLater = () => {
|
|
372
|
+
if (!gsapClasses.size) return;
|
|
373
|
+
queueMicrotask(() => {
|
|
374
|
+
if (liveClients().length) return;
|
|
375
|
+
gsapClasses.forEach((cls) => {
|
|
376
|
+
cls.removeEventListener?.("refresh", onGsapRefreshDone);
|
|
377
|
+
cls.removeEventListener?.("refreshInit", onGsapRefreshInit);
|
|
378
|
+
});
|
|
379
|
+
gsapClasses.clear();
|
|
380
|
+
});
|
|
381
|
+
};
|
|
382
|
+
const scanStickyElements = (owned) => {
|
|
383
|
+
const scrollerMemo = new Map();
|
|
384
|
+
const isWindowSticky = (el) => el.isConnected && getComputedStyle(el).position === "sticky" && !isInsideScroller(el, scrollerMemo);
|
|
385
|
+
if (scannedThisTask) return Array.from(new Set([
|
|
386
|
+
...scannedThisTask,
|
|
387
|
+
...records.map((r) => r.el),
|
|
388
|
+
...owned
|
|
389
|
+
])).filter(isWindowSticky);
|
|
390
|
+
const found = Array.from(document.querySelectorAll("*")).filter(isWindowSticky);
|
|
391
|
+
scannedThisTask = found;
|
|
392
|
+
queueMicrotask(() => {
|
|
393
|
+
scannedThisTask = null;
|
|
394
|
+
});
|
|
395
|
+
return found;
|
|
396
|
+
};
|
|
397
|
+
const maxChainInBand = (b, maxScroll) => {
|
|
398
|
+
const bands = records.flatMap((r) => {
|
|
399
|
+
const band = r.demotable ? [Math.max(0, r.lo - b), Math.min(maxScroll, r.hi + (r.holdsAfter ? Infinity : b))] : [0, maxScroll];
|
|
400
|
+
return band[1] >= band[0] ? [{
|
|
401
|
+
record: r,
|
|
402
|
+
start: band[0],
|
|
403
|
+
end: band[1]
|
|
404
|
+
}] : [];
|
|
405
|
+
});
|
|
406
|
+
let max = 0;
|
|
407
|
+
new Set([0, ...bands.filter(({ record }) => record.demotable).map(({ start }) => start)]).forEach((scroll) => {
|
|
408
|
+
const inBand = new Set(bands.filter(({ start, end }) => start <= scroll && scroll <= end).map(({ record }) => record));
|
|
409
|
+
inBand.forEach((r) => {
|
|
410
|
+
max = Math.max(max, 1 + r.ancestors.filter((a) => inBand.has(a)).length);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
return max;
|
|
414
|
+
};
|
|
415
|
+
const chooseBuffer = (viewportHeight, maxScroll) => {
|
|
416
|
+
let low = Math.ceil(BUFFER_FLOOR_PX / BUFFER_STEP_PX);
|
|
417
|
+
let high = Math.floor(viewportHeight / BUFFER_STEP_PX);
|
|
418
|
+
if (high < low || maxChainInBand(low * BUFFER_STEP_PX, maxScroll) > MAX_CHAIN_IN_BAND) return BUFFER_FLOOR_PX;
|
|
419
|
+
while (low < high) {
|
|
420
|
+
const mid = Math.ceil((low + high) / 2);
|
|
421
|
+
if (maxChainInBand(mid * BUFFER_STEP_PX, maxScroll) <= MAX_CHAIN_IN_BAND) low = mid;
|
|
422
|
+
else high = mid - 1;
|
|
423
|
+
}
|
|
424
|
+
return low * BUFFER_STEP_PX;
|
|
425
|
+
};
|
|
426
|
+
const liveClients = () => {
|
|
427
|
+
const live = [];
|
|
428
|
+
clients.forEach((ref) => {
|
|
429
|
+
const client = ref.deref();
|
|
430
|
+
if (!client) {
|
|
431
|
+
clients.delete(ref);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const owned = client.ownedElements();
|
|
435
|
+
if (owned.some((el) => el.isConnected)) live.push({
|
|
436
|
+
client,
|
|
437
|
+
owned
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
return live;
|
|
441
|
+
};
|
|
442
|
+
const measureStatic = (all, owned, unmodeled) => {
|
|
443
|
+
const scroll = window.scrollY;
|
|
444
|
+
const viewportHeight = document.documentElement.clientHeight || window.innerHeight;
|
|
445
|
+
const transformMemo = new Map();
|
|
446
|
+
const documentHeight = measureDocumentHeight();
|
|
447
|
+
all.forEach((record) => {
|
|
448
|
+
const { el } = record;
|
|
449
|
+
const rect = el.getBoundingClientRect();
|
|
450
|
+
const computed = getComputedStyle(el);
|
|
451
|
+
const parent = el.parentElement;
|
|
452
|
+
let containerBottom = rect.bottom + scroll;
|
|
453
|
+
if (parent) {
|
|
454
|
+
const parentStyle = getComputedStyle(parent);
|
|
455
|
+
containerBottom = parent.getBoundingClientRect().bottom + scroll - parseFloat(parentStyle.borderBottomWidth) - parseFloat(parentStyle.paddingBottom);
|
|
456
|
+
if (parentStyle.display === "contents" || parentStyle.display === "inline") unmodeled.add(record);
|
|
457
|
+
}
|
|
458
|
+
record.naturalTop = rect.top + scroll;
|
|
459
|
+
record.travel = Math.max(0, containerBottom - (record.naturalTop + rect.height + parseFloat(computed.marginBottom)));
|
|
460
|
+
record.overflowBottom = record.naturalTop + el.clientTop + el.scrollHeight;
|
|
461
|
+
if (computed.position !== "static" || hasTransform(el, transformMemo)) unmodeled.add(record);
|
|
462
|
+
if (computed.bottom !== "auto" || computed.left !== "auto" || computed.right !== "auto") unmodeled.add(record);
|
|
463
|
+
if (owned.has(el) && (!computed.top.endsWith("px") || Math.abs(parseFloat(computed.top) - parseFloat(el.style.top)) > .01)) unmodeled.add(record);
|
|
464
|
+
if (!owned.has(el) && computed.top === "auto") {
|
|
465
|
+
record.stickyTop = 0;
|
|
466
|
+
record.travel = 0;
|
|
467
|
+
} else if (!owned.has(el)) {
|
|
468
|
+
const unit = SIMPLE_TOP.exec(computed.top)?.[1];
|
|
469
|
+
if (!unit) unmodeled.add(record);
|
|
470
|
+
else if (unit === "%") record.stickyTop = parseFloat(computed.top) * viewportHeight / 100;
|
|
471
|
+
else record.stickyTop = parseFloat(computed.top);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
return {
|
|
475
|
+
scroll,
|
|
476
|
+
viewportHeight,
|
|
477
|
+
documentHeight
|
|
478
|
+
};
|
|
479
|
+
};
|
|
480
|
+
const teardown = () => {
|
|
481
|
+
clearTable();
|
|
482
|
+
endGsapRefresh();
|
|
483
|
+
dropGsapClassesLater();
|
|
484
|
+
};
|
|
485
|
+
const rebuildDormancy = (scrollTriggerClass) => {
|
|
486
|
+
const live = liveClients();
|
|
487
|
+
if (!live.length) {
|
|
488
|
+
teardown();
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (scrollTriggerClass) adoptGsapClass(scrollTriggerClass);
|
|
492
|
+
if (!gsapRefreshing()) endGsapRefresh();
|
|
493
|
+
if (!gsapClasses.size || bodyScrolls()) {
|
|
494
|
+
clearTable();
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const owned = new Map();
|
|
498
|
+
live.forEach(({ client, owned: elements }) => {
|
|
499
|
+
elements.forEach((el) => owned.set(el, client));
|
|
500
|
+
});
|
|
501
|
+
const autoOnly = live.every(({ client }) => client.mode === "auto");
|
|
502
|
+
const demoted = new Set(records.filter((r) => r.state !== "in").map((r) => r.el));
|
|
503
|
+
if (autoOnly && ownedDepth(owned.keys(), demoted) < AUTO_MIN_DEPTH) {
|
|
504
|
+
clearTable();
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
const sticky = scanStickyElements(owned.keys());
|
|
508
|
+
const stickySet = new Set(sticky);
|
|
509
|
+
const leftover = records.filter((r) => r.state !== "in" && !stickySet.has(r.el));
|
|
510
|
+
leftover.filter((r) => !r.el.isConnected).forEach((r) => promote(r));
|
|
511
|
+
const kept = leftover.filter((r) => r.el.isConnected);
|
|
512
|
+
const previous = new Map(records.map((r) => [r.el, r]));
|
|
513
|
+
const found = [...sticky.map((el) => {
|
|
514
|
+
const computed = getComputedStyle(el);
|
|
515
|
+
const before = previous.get(el);
|
|
516
|
+
if (before && before.state !== "in") return {
|
|
517
|
+
...before,
|
|
518
|
+
demotable: false,
|
|
519
|
+
position: el.style.position,
|
|
520
|
+
top: el.style.top,
|
|
521
|
+
stickyTop: parseFloat(el.style.top) || 0,
|
|
522
|
+
ancestors: [],
|
|
523
|
+
state: "before"
|
|
524
|
+
};
|
|
525
|
+
return {
|
|
526
|
+
el,
|
|
527
|
+
demotable: false,
|
|
528
|
+
position: el.style.position,
|
|
529
|
+
top: el.style.top,
|
|
530
|
+
zIndex: el.style.zIndex,
|
|
531
|
+
willChange: el.style.willChange,
|
|
532
|
+
zIndexAuto: computed.zIndex === "auto",
|
|
533
|
+
willChangeAuto: computed.willChange === "auto",
|
|
534
|
+
stickyTop: parseFloat(el.style.top) || 0,
|
|
535
|
+
naturalTop: 0,
|
|
536
|
+
travel: 0,
|
|
537
|
+
ancestors: [],
|
|
538
|
+
lo: 0,
|
|
539
|
+
hi: 0,
|
|
540
|
+
overflowBottom: 0,
|
|
541
|
+
holdsAfter: false,
|
|
542
|
+
state: "in",
|
|
543
|
+
demotedTop: ""
|
|
544
|
+
};
|
|
545
|
+
}), ...kept];
|
|
546
|
+
found.sort((a, b) => compareDocumentOrder(a.el, b.el));
|
|
547
|
+
found.forEach((record, index) => {
|
|
548
|
+
record.ancestors = found.slice(0, index).filter((a) => a.el.contains(record.el));
|
|
549
|
+
});
|
|
550
|
+
const holdsOwned = new Set();
|
|
551
|
+
found.forEach((record) => {
|
|
552
|
+
if (owned.has(record.el)) record.ancestors.forEach((a) => holdsOwned.add(a));
|
|
553
|
+
});
|
|
554
|
+
const all = found.filter((r) => owned.has(r.el) || holdsOwned.has(r) || r.state !== "in" || r.ancestors.some((a) => owned.has(a.el)));
|
|
555
|
+
const inTable = new Set(all);
|
|
556
|
+
all.forEach((record) => {
|
|
557
|
+
record.ancestors = record.ancestors.filter((a) => inTable.has(a));
|
|
558
|
+
});
|
|
559
|
+
const depths = new Map();
|
|
560
|
+
all.forEach((record) => {
|
|
561
|
+
const client = owned.get(record.el);
|
|
562
|
+
if (client) depths.set(client, Math.max(depths.get(client) ?? 0, record.ancestors.length + 1));
|
|
563
|
+
});
|
|
564
|
+
const active = new Set(live.map(({ client }) => client).filter((client) => client.mode === "always" || (depths.get(client) ?? 0) >= AUTO_MIN_DEPTH));
|
|
565
|
+
all.forEach((record) => {
|
|
566
|
+
const client = owned.get(record.el);
|
|
567
|
+
record.demotable = client !== void 0 && active.has(client);
|
|
568
|
+
});
|
|
569
|
+
records = all;
|
|
570
|
+
if (!all.some((r) => r.demotable)) {
|
|
571
|
+
clearTable();
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const toMeasure = all.filter((r) => owned.has(r.el) || holdsOwned.has(r) || r.state !== "in");
|
|
575
|
+
const authorStyle = new Map(toMeasure.filter((r) => !owned.has(r.el) && r.state === "in").map(({ el }) => [el, el.getAttribute("style")]));
|
|
576
|
+
const restorePositions = () => toMeasure.forEach((record) => {
|
|
577
|
+
if (!authorStyle.has(record.el)) {
|
|
578
|
+
promote(record, true);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const saved = authorStyle.get(record.el);
|
|
582
|
+
if (saved === null || saved === void 0) record.el.removeAttribute("style");
|
|
583
|
+
else record.el.setAttribute("style", saved);
|
|
584
|
+
});
|
|
585
|
+
toMeasure.forEach(({ el }) => {
|
|
586
|
+
el.style.position = "static";
|
|
587
|
+
});
|
|
588
|
+
const unmodeled = new Set();
|
|
589
|
+
let measured;
|
|
590
|
+
try {
|
|
591
|
+
measured = measureStatic(toMeasure, owned, unmodeled);
|
|
592
|
+
} finally {
|
|
593
|
+
restorePositions();
|
|
594
|
+
}
|
|
595
|
+
const { scroll, viewportHeight, documentHeight } = measured;
|
|
596
|
+
const maxScroll = Math.max(0, documentHeight - viewportHeight);
|
|
597
|
+
all.forEach((record) => {
|
|
598
|
+
const union = mergeIntervals(record.ancestors.map((a) => [a.lo, a.hi]));
|
|
599
|
+
const reach = record.naturalTop - record.stickyTop;
|
|
600
|
+
record.lo = invertStuckUnion(union, reach, true);
|
|
601
|
+
record.hi = invertStuckUnion(union, reach + record.travel, false);
|
|
602
|
+
if (unmodeled.has(record) || record.ancestors.some((a) => unmodeled.has(a))) record.demotable = false;
|
|
603
|
+
const carried = record.ancestors.filter((a) => a.demotable && !a.holdsAfter).reduce((sum, a) => sum + a.travel, 0);
|
|
604
|
+
record.holdsAfter = record.overflowBottom + record.travel + carried > documentHeight + 1;
|
|
605
|
+
});
|
|
606
|
+
buffer = chooseBuffer(viewportHeight, maxScroll);
|
|
607
|
+
update(gsapPhase === "measuring" ? 0 : (gsapPhase === "restored" ? scrollBeforeGsapRefresh : null) ?? scroll);
|
|
608
|
+
listen(true);
|
|
609
|
+
};
|
|
610
|
+
const takeGsapRefreshRestore = () => adoptedMidRefresh && gsapRefreshing() ? onGsapRefreshInit().render : null;
|
|
611
|
+
const clearDormancy = clearTable;
|
|
612
|
+
const releaseDormant = (elements) => {
|
|
613
|
+
const released = new Set(elements);
|
|
614
|
+
records = records.filter((record) => {
|
|
615
|
+
if (!released.has(record.el)) return true;
|
|
616
|
+
promote(record);
|
|
617
|
+
return false;
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
const registerDormancyClient = (client) => {
|
|
621
|
+
clients.add(new WeakRef(client));
|
|
622
|
+
};
|
|
623
|
+
let rebuildQueued = false;
|
|
624
|
+
const queueRebuild = () => {
|
|
625
|
+
if (rebuildQueued) return;
|
|
626
|
+
rebuildQueued = true;
|
|
627
|
+
queueMicrotask(() => {
|
|
628
|
+
rebuildQueued = false;
|
|
629
|
+
rebuildSafely();
|
|
630
|
+
});
|
|
631
|
+
};
|
|
632
|
+
const unregisterDormancyClient = (client) => {
|
|
633
|
+
clients.forEach((ref) => {
|
|
634
|
+
if (ref.deref() !== client) return;
|
|
635
|
+
clients.delete(ref);
|
|
636
|
+
releaseDormant(client.ownedElements());
|
|
637
|
+
});
|
|
638
|
+
if (liveClients().length) queueRebuild();
|
|
639
|
+
else teardown();
|
|
640
|
+
};
|
|
204
641
|
const resolveMaybeFn = (value) => typeof value === "function" ? value() : value;
|
|
205
642
|
const KEYWORD_FRACTIONS = {
|
|
206
643
|
top: 0,
|
|
@@ -241,19 +678,20 @@ var StickyScrollTrigger = (function() {
|
|
|
241
678
|
const inner = trimmed.slice(6).replace(/\)$/, "").trim();
|
|
242
679
|
throw new Error(`StickyScrollTrigger: unsupported position clause "${trimmed}": GSAP's clamp() wrapper isn't supported here.` + (inner ? ` Did you mean "${inner}"?` : ""));
|
|
243
680
|
};
|
|
244
|
-
const
|
|
681
|
+
const splitClause = (position) => {
|
|
245
682
|
const trimmed = position.trim();
|
|
246
683
|
assertNotClamped(trimmed);
|
|
247
|
-
|
|
248
|
-
return elementHeight * elementClause.fraction + elementClause.offsetPx;
|
|
684
|
+
return trimmed.split(/\s+/);
|
|
249
685
|
};
|
|
686
|
+
const anchorWithin = (token, size) => {
|
|
687
|
+
const { fraction, offsetPx } = parseClauseToken(token, size);
|
|
688
|
+
return size * fraction + offsetPx;
|
|
689
|
+
};
|
|
690
|
+
const resolveElementAnchor = (position, elementHeight) => anchorWithin(splitClause(position)[0], elementHeight);
|
|
250
691
|
const resolveElementFraction = (position) => resolveElementAnchor(position, 1) - resolveElementAnchor(position, 0);
|
|
251
692
|
const resolveAnchorTop = (position, elementHeight, viewportHeight) => {
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
const viewportToken = trimmed.split(/\s+/)[1] ?? "top";
|
|
255
|
-
const viewportClause = parseClauseToken(viewportToken, viewportHeight);
|
|
256
|
-
return viewportHeight * viewportClause.fraction + viewportClause.offsetPx - resolveElementAnchor(trimmed, elementHeight);
|
|
693
|
+
const [elementToken, viewportToken = "top"] = splitClause(position);
|
|
694
|
+
return anchorWithin(viewportToken, viewportHeight) - anchorWithin(elementToken, elementHeight);
|
|
257
695
|
};
|
|
258
696
|
const DWELL_RELATIVE_RE = /^\+=(\d+(?:\.\d*)?|\.\d+)(%|px)?$/;
|
|
259
697
|
const isDwellFormat = (resolved) => typeof resolved === "string" && DWELL_RELATIVE_RE.test(resolved.trim());
|
|
@@ -263,9 +701,7 @@ var StickyScrollTrigger = (function() {
|
|
|
263
701
|
if (!trimmedEnd.startsWith("+=") || !/\s/.test(trimmedEnd)) return endResolved;
|
|
264
702
|
const startResolved = resolveMaybeFn(start);
|
|
265
703
|
if (typeof startResolved !== "string") return endResolved;
|
|
266
|
-
const
|
|
267
|
-
assertNotClamped(trimmedStart);
|
|
268
|
-
const [elementToken] = trimmedStart.split(/\s+/);
|
|
704
|
+
const [elementToken] = splitClause(startResolved);
|
|
269
705
|
try {
|
|
270
706
|
parseClauseToken(elementToken, 0);
|
|
271
707
|
} catch (error) {
|
|
@@ -314,16 +750,18 @@ var StickyScrollTrigger = (function() {
|
|
|
314
750
|
};
|
|
315
751
|
const isHeldIn = (measurements, index, enclosedBy, anchorElement, order) => measurements[index].triggerEnclosedBy.some((m) => m !== index && measurements[m].kind === "scene" && order.isBefore(m, index) && !(enclosedBy.includes(m) && m !== anchorElement));
|
|
316
752
|
const nestedIn = (measurements, index) => measurements.flatMap(({ triggerEnclosedBy }, k) => k !== index && triggerEnclosedBy.includes(index) ? [k] : []);
|
|
317
|
-
const anchorShare = (measurements, world,
|
|
753
|
+
const anchorShare = ({ measurements, world, order, ownIndex }, index, freezeStart, box, reachedAt) => {
|
|
754
|
+
const { enclosedBy, anchorElement } = box;
|
|
318
755
|
const measurement = measurements[index];
|
|
319
756
|
if (enclosedBy.includes(index)) return (measurement.start.mode === "absolute" ? world.unpaddedStart(index, ownIndex, freezeStart) : measurement.triggerTop - measurement.start.anchorOffset) < reachedAt - .05 ? 1 : 0;
|
|
320
757
|
if (order && isHeldIn(measurements, index, enclosedBy, anchorElement, order)) return 0;
|
|
321
758
|
if (box.nests.includes(index)) return box.fraction;
|
|
322
759
|
return measurement.triggerTop + measurement.triggerHeight <= box.top + .05 ? 1 : 0;
|
|
323
760
|
};
|
|
324
|
-
const gapsBeforeEndAnchor = (
|
|
761
|
+
const gapsBeforeEndAnchor = (context, windows, box, reachedAt, counted) => windows.reduce((total, { index, freezeStart, freezeEnd }) => {
|
|
762
|
+
const { ownIndex, order } = context;
|
|
325
763
|
if (index === ownIndex || order && order.isBefore(ownIndex, index)) return total;
|
|
326
|
-
const weight = anchorShare(
|
|
764
|
+
const weight = anchorShare(context, index, freezeStart, box, reachedAt);
|
|
327
765
|
if (weight === 0) return total;
|
|
328
766
|
counted?.add(index);
|
|
329
767
|
return total + weight * (freezeEnd - freezeStart);
|
|
@@ -387,8 +825,64 @@ var StickyScrollTrigger = (function() {
|
|
|
387
825
|
runs: []
|
|
388
826
|
};
|
|
389
827
|
recounts.push(recount);
|
|
828
|
+
const context = {
|
|
829
|
+
measurements,
|
|
830
|
+
world,
|
|
831
|
+
order,
|
|
832
|
+
ownIndex: index
|
|
833
|
+
};
|
|
834
|
+
const gapsOf = (box, reachedAt) => {
|
|
835
|
+
const gaps = (w, counted) => gapsBeforeEndAnchor(context, w, box, reachedAt, counted);
|
|
836
|
+
recount.runs.push((w) => gaps(w, recount.counted));
|
|
837
|
+
return gaps(knownWindows());
|
|
838
|
+
};
|
|
390
839
|
const { start } = measurement;
|
|
391
840
|
const freezeStart = start.mode === "absolute" ? start.value : previous?.freezeStarts[index] ?? clauseFreezeStart(measurements, index, paddingOf);
|
|
841
|
+
const heldBack = (k) => order !== null && (order.isBefore(index, k) || isHeldIn(measurements, k, measurement.triggerEnclosedBy, index, order));
|
|
842
|
+
const selfClauseEnd = (end, anchorOffsetEnd) => {
|
|
843
|
+
const nests = nestedIn(measurements, index);
|
|
844
|
+
const weight = resolveElementFraction(end.clause) - (start.mode === "clause" ? start.elementFraction : 0);
|
|
845
|
+
const dwellInside = measurements.reduce((total, other, k) => {
|
|
846
|
+
if (weight === 0 || other.kind !== "scene" || !nests.includes(k) || heldBack(k)) return total;
|
|
847
|
+
recount.counted.add(k);
|
|
848
|
+
return total + weight * paddingOf(k);
|
|
849
|
+
}, 0);
|
|
850
|
+
if (start.mode === "clause") return freezeStart + Math.max(0, start.anchorOffset - anchorOffsetEnd + dwellInside);
|
|
851
|
+
const dwellAbove = measurements.reduce((total, other, k) => {
|
|
852
|
+
if (k === index || other.kind !== "scene" || nests.includes(k) || other.triggerTop + other.triggerHeight > measurement.triggerTop + .05 || heldBack(k)) return total;
|
|
853
|
+
recount.counted.add(k);
|
|
854
|
+
return total + paddingOf(k);
|
|
855
|
+
}, 0);
|
|
856
|
+
return Math.max(freezeStart, measurement.triggerTop - anchorOffsetEnd + dwellAbove + dwellInside);
|
|
857
|
+
};
|
|
858
|
+
const elementClauseEnd = (end, anchorOffsetEnd) => {
|
|
859
|
+
let endTop;
|
|
860
|
+
if (end.measureLive) endTop = measureLiveEndTriggerTop(index);
|
|
861
|
+
else {
|
|
862
|
+
const rawTop = measurement.endTrigger.index === null ? end.rawTop : measurements[measurement.endTrigger.index].triggerTop;
|
|
863
|
+
if (rawTop === null) endTop = 0;
|
|
864
|
+
else {
|
|
865
|
+
const box = {
|
|
866
|
+
top: rawTop,
|
|
867
|
+
fraction: resolveElementFraction(end.clause),
|
|
868
|
+
nests: measurement.endTrigger.nests,
|
|
869
|
+
enclosedBy: measurement.endTrigger.enclosedBy,
|
|
870
|
+
anchorElement: measurement.endTrigger.index
|
|
871
|
+
};
|
|
872
|
+
endTop = rawTop + gapsOf(box, rawTop - anchorOffsetEnd);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
let layoutStart;
|
|
876
|
+
if (start.mode === "absolute") layoutStart = start.value;
|
|
877
|
+
else layoutStart = measurement.triggerTop - start.anchorOffset + gapsOf({
|
|
878
|
+
top: measurement.triggerTop,
|
|
879
|
+
fraction: start.elementFraction,
|
|
880
|
+
nests: nestedIn(measurements, index),
|
|
881
|
+
enclosedBy: measurement.triggerEnclosedBy,
|
|
882
|
+
anchorElement: index
|
|
883
|
+
}, measurement.triggerTop - start.anchorOffset);
|
|
884
|
+
return freezeStart + Math.max(0, endTop - anchorOffsetEnd - layoutStart);
|
|
885
|
+
};
|
|
392
886
|
let freezeEnd;
|
|
393
887
|
switch (measurement.end.mode) {
|
|
394
888
|
case "dwell":
|
|
@@ -402,55 +896,8 @@ var StickyScrollTrigger = (function() {
|
|
|
402
896
|
case "auto":
|
|
403
897
|
case "max": throw new Error(`StickyScrollTrigger: internal error: a Scene layer reached '${measurement.end.mode}' end mode, which only a cover layer can have.`);
|
|
404
898
|
case "clause": {
|
|
405
|
-
const anchorOffsetEnd = resolveAnchorTop(measurement.end.clause, measurement.
|
|
406
|
-
|
|
407
|
-
const nests = nestedIn(measurements, index);
|
|
408
|
-
const weight = resolveElementFraction(measurement.end.clause) - (start.mode === "clause" ? start.elementFraction : 0);
|
|
409
|
-
const dwellInside = measurements.reduce((total, other, k) => {
|
|
410
|
-
if (weight === 0 || other.kind !== "scene" || !nests.includes(k) || order && (order.isBefore(index, k) || isHeldIn(measurements, k, measurement.triggerEnclosedBy, index, order))) return total;
|
|
411
|
-
recount.counted.add(k);
|
|
412
|
-
return total + weight * paddingOf(k);
|
|
413
|
-
}, 0);
|
|
414
|
-
if (start.mode === "clause") {
|
|
415
|
-
freezeEnd = freezeStart + Math.max(0, start.anchorOffset - anchorOffsetEnd + dwellInside);
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
|
-
const dwellAbove = measurements.reduce((total, other, k) => {
|
|
419
|
-
if (k === index || other.kind !== "scene" || nests.includes(k) || other.triggerTop + other.triggerHeight > measurement.triggerTop + .05 || order && (order.isBefore(index, k) || isHeldIn(measurements, k, measurement.triggerEnclosedBy, index, order))) return total;
|
|
420
|
-
recount.counted.add(k);
|
|
421
|
-
return total + paddingOf(k);
|
|
422
|
-
}, 0);
|
|
423
|
-
freezeEnd = Math.max(freezeStart, measurement.triggerTop - anchorOffsetEnd + dwellAbove + dwellInside);
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
let endTop;
|
|
427
|
-
if (measurement.end.measureLive) endTop = measureLiveEndTriggerTop(index);
|
|
428
|
-
else {
|
|
429
|
-
const rawTop = measurement.endTriggerIndex === null ? measurement.end.rawTop : measurements[measurement.endTriggerIndex].triggerTop;
|
|
430
|
-
if (rawTop === null) endTop = 0;
|
|
431
|
-
else {
|
|
432
|
-
const box = {
|
|
433
|
-
top: rawTop,
|
|
434
|
-
fraction: resolveElementFraction(measurement.end.clause),
|
|
435
|
-
nests: measurement.endTriggerNests
|
|
436
|
-
};
|
|
437
|
-
const gaps = (w, counted) => gapsBeforeEndAnchor(measurements, world, w, box, rawTop - anchorOffsetEnd, measurement.endTriggerEnclosedBy, index, measurement.endTriggerIndex, order, counted);
|
|
438
|
-
endTop = rawTop + gaps(knownWindows());
|
|
439
|
-
recount.runs.push((w) => gaps(w, recount.counted));
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
let layoutStart;
|
|
443
|
-
if (start.mode === "absolute") layoutStart = start.value;
|
|
444
|
-
else {
|
|
445
|
-
const gaps = (w, counted) => gapsBeforeEndAnchor(measurements, world, w, {
|
|
446
|
-
top: measurement.triggerTop,
|
|
447
|
-
fraction: start.elementFraction,
|
|
448
|
-
nests: nestedIn(measurements, index)
|
|
449
|
-
}, measurement.triggerTop - start.anchorOffset, measurement.triggerEnclosedBy, index, index, order, counted);
|
|
450
|
-
layoutStart = measurement.triggerTop - start.anchorOffset + gaps(knownWindows());
|
|
451
|
-
recount.runs.push((w) => gaps(w, recount.counted));
|
|
452
|
-
}
|
|
453
|
-
freezeEnd = freezeStart + Math.max(0, endTop - anchorOffsetEnd - layoutStart);
|
|
899
|
+
const anchorOffsetEnd = resolveAnchorTop(measurement.end.clause, measurement.endTrigger.height, viewportHeight);
|
|
900
|
+
freezeEnd = measurement.endTrigger.isSelf ? selfClauseEnd(measurement.end, anchorOffsetEnd) : elementClauseEnd(measurement.end, anchorOffsetEnd);
|
|
454
901
|
break;
|
|
455
902
|
}
|
|
456
903
|
}
|
|
@@ -492,9 +939,9 @@ var StickyScrollTrigger = (function() {
|
|
|
492
939
|
freezeEnd = documentMaxScroll + measurement.end.offsetPx;
|
|
493
940
|
break;
|
|
494
941
|
case "clause": {
|
|
495
|
-
const anchorOffsetEnd = resolveAnchorTop(measurement.end.clause, measurement.
|
|
942
|
+
const anchorOffsetEnd = resolveAnchorTop(measurement.end.clause, measurement.endTrigger.height, viewportHeight);
|
|
496
943
|
if (measurement.end.measureLive) freezeEnd = measureLiveEndTriggerTop(index) - anchorOffsetEnd;
|
|
497
|
-
else freezeEnd = reached((measurement.
|
|
944
|
+
else freezeEnd = reached((measurement.endTrigger.isSelf ? measurement.triggerTop : measurement.endTrigger.index === null ? measurement.end.rawTop ?? 0 : measurements[measurement.endTrigger.index].triggerTop) - anchorOffsetEnd);
|
|
498
945
|
break;
|
|
499
946
|
}
|
|
500
947
|
}
|
|
@@ -565,7 +1012,7 @@ var StickyScrollTrigger = (function() {
|
|
|
565
1012
|
const before = measurements.map(() => []);
|
|
566
1013
|
edges.forEach((movers, i) => {
|
|
567
1014
|
const measurement = measurements[i];
|
|
568
|
-
const enclosingAnchor = (measurement.end.mode === "clause" && !measurement.
|
|
1015
|
+
const enclosingAnchor = (measurement.end.mode === "clause" && !measurement.endTrigger.isSelf ? measurement.endTrigger.enclosedBy : measurement.triggerEnclosedBy).filter((m) => m !== measurement.endTrigger.index);
|
|
569
1016
|
movers.forEach((k) => {
|
|
570
1017
|
if (lengths[k] <= .05) return;
|
|
571
1018
|
before[i].push(k);
|
|
@@ -822,7 +1269,7 @@ var StickyScrollTrigger = (function() {
|
|
|
822
1269
|
const snapshot = snapshots.get(target);
|
|
823
1270
|
target.style.scrollMarginTop = snapshot ? snapshot.inline : "";
|
|
824
1271
|
};
|
|
825
|
-
const
|
|
1272
|
+
const stopRamps = () => {
|
|
826
1273
|
if (sheet) {
|
|
827
1274
|
document.adoptedStyleSheets = document.adoptedStyleSheets.filter((one) => one !== sheet);
|
|
828
1275
|
sheet = null;
|
|
@@ -832,31 +1279,37 @@ var StickyScrollTrigger = (function() {
|
|
|
832
1279
|
jsRamps = [];
|
|
833
1280
|
jsHost = null;
|
|
834
1281
|
};
|
|
1282
|
+
const startRamps = (ramps, host) => {
|
|
1283
|
+
if (animationHost !== host) {
|
|
1284
|
+
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
1285
|
+
animationHost = host;
|
|
1286
|
+
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
1287
|
+
}
|
|
1288
|
+
if (usesJsRamp) {
|
|
1289
|
+
jsRamps = ramps;
|
|
1290
|
+
jsHost = host;
|
|
1291
|
+
applyJsRamp();
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (!sheet) {
|
|
1295
|
+
sheet = new CSSStyleSheet();
|
|
1296
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
1297
|
+
}
|
|
1298
|
+
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
1299
|
+
};
|
|
1300
|
+
const release = () => {
|
|
1301
|
+
written.forEach(restoreTarget);
|
|
1302
|
+
written = new Set();
|
|
1303
|
+
stopRamps();
|
|
1304
|
+
};
|
|
835
1305
|
return {
|
|
836
1306
|
sync(scenes, host, measureNaturalTops) {
|
|
837
1307
|
const ramps = scenes.filter((scene) => scene.freezeEnd > scene.freezeStart).sort((a, b) => a.freezeStart - b.freezeStart);
|
|
838
1308
|
if (targetSelector === null || !ramps.length || !host) {
|
|
839
|
-
|
|
840
|
-
written = new Set();
|
|
841
|
-
clearAnimation();
|
|
1309
|
+
release();
|
|
842
1310
|
return;
|
|
843
1311
|
}
|
|
844
|
-
|
|
845
|
-
animationHost?.removeAttribute(`data-${instanceId}`);
|
|
846
|
-
animationHost = host;
|
|
847
|
-
animationHost.setAttribute(`data-${instanceId}`, "");
|
|
848
|
-
}
|
|
849
|
-
if (usesJsRamp) {
|
|
850
|
-
jsRamps = ramps;
|
|
851
|
-
jsHost = host;
|
|
852
|
-
applyJsRamp();
|
|
853
|
-
} else {
|
|
854
|
-
if (!sheet) {
|
|
855
|
-
sheet = new CSSStyleSheet();
|
|
856
|
-
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
857
|
-
}
|
|
858
|
-
sheet.replaceSync(buildStylesheet(instanceId, ramps));
|
|
859
|
-
}
|
|
1312
|
+
startRamps(ramps, host);
|
|
860
1313
|
const targets = Array.from(rootElement.querySelectorAll(targetSelector));
|
|
861
1314
|
const naturalTops = measureNaturalTops(targets);
|
|
862
1315
|
targets.forEach((target) => {
|
|
@@ -883,9 +1336,7 @@ var StickyScrollTrigger = (function() {
|
|
|
883
1336
|
},
|
|
884
1337
|
restore() {
|
|
885
1338
|
if (usesJsRamp) window.removeEventListener("scroll", applyJsRamp);
|
|
886
|
-
|
|
887
|
-
written = new Set();
|
|
888
|
-
clearAnimation();
|
|
1339
|
+
release();
|
|
889
1340
|
}
|
|
890
1341
|
};
|
|
891
1342
|
};
|
|
@@ -984,23 +1435,27 @@ var StickyScrollTrigger = (function() {
|
|
|
984
1435
|
const endResolved = layer.end === null ? null : prefixSpacedRelativeEnd(startResolved, resolveMaybeFn(layer.end));
|
|
985
1436
|
const elementHeight = measureUsedHeight(layer.trigger);
|
|
986
1437
|
const endTriggerIsSelf = layer.endTrigger === layer.trigger;
|
|
1438
|
+
const indicesWhere = (test) => [...indexByTrigger].filter(([trigger]) => test(trigger)).map(([, index]) => index);
|
|
987
1439
|
const endTriggerIndex = indexByTrigger.get(layer.endTrigger) ?? null;
|
|
988
1440
|
const end = resolveEndSpec(rootElement, viewportHeight, layer, endResolved, ownIndex, endTriggerIndex);
|
|
1441
|
+
const endTriggerInContainer = end.mode === "clause" && !end.measureLive && !endTriggerIsSelf;
|
|
989
1442
|
const start = resolveStartSpec(layer, startResolved, elementHeight, viewportHeight);
|
|
990
1443
|
return {
|
|
991
1444
|
kind: layer.kind,
|
|
992
1445
|
start,
|
|
993
1446
|
triggerTop: documentTop(layer.trigger),
|
|
994
1447
|
triggerHeight: elementHeight,
|
|
995
|
-
triggerEnclosedBy:
|
|
1448
|
+
triggerEnclosedBy: indicesWhere((trigger) => trigger.contains(layer.trigger)),
|
|
996
1449
|
wrapperTop: layer.wrapper ? documentTop(layer.wrapper) : 0,
|
|
997
1450
|
coverTop: layer.kind === "cover" ? documentTop(layer.cover) : 0,
|
|
998
1451
|
end,
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1452
|
+
endTrigger: {
|
|
1453
|
+
isSelf: endTriggerIsSelf,
|
|
1454
|
+
index: endTriggerIndex,
|
|
1455
|
+
height: end.mode === "clause" ? measureUsedHeight(layer.endTrigger) : 0,
|
|
1456
|
+
enclosedBy: endTriggerInContainer ? indicesWhere((trigger) => trigger.contains(layer.endTrigger)) : [],
|
|
1457
|
+
nests: endTriggerInContainer ? indicesWhere((other) => other !== layer.endTrigger && layer.endTrigger.contains(other)) : []
|
|
1458
|
+
}
|
|
1004
1459
|
};
|
|
1005
1460
|
};
|
|
1006
1461
|
const EXCLUDED_VAR_KEYS = [
|
|
@@ -1033,6 +1488,10 @@ var StickyScrollTrigger = (function() {
|
|
|
1033
1488
|
case "clause": return toScroll(endTrigger, documentTop(endTrigger) - resolveAnchorTop(classifiedEnd.value, measureUsedHeight(endTrigger), viewportHeight));
|
|
1034
1489
|
}
|
|
1035
1490
|
};
|
|
1491
|
+
const removeItem = (list, item) => {
|
|
1492
|
+
const index = list.indexOf(item);
|
|
1493
|
+
if (index !== -1) list.splice(index, 1);
|
|
1494
|
+
};
|
|
1036
1495
|
const hasDuplicateTrigger = (list, trigger) => list.some((existing) => existing.trigger === trigger);
|
|
1037
1496
|
var StickyScrollTrigger = class {
|
|
1038
1497
|
#rootElement;
|
|
@@ -1047,6 +1506,7 @@ var StickyScrollTrigger = (function() {
|
|
|
1047
1506
|
#scrollTriggerClass = null;
|
|
1048
1507
|
#pinLayers = [];
|
|
1049
1508
|
#scrollMarginSync;
|
|
1509
|
+
#dormancyClient = null;
|
|
1050
1510
|
constructor(root, options = {}) {
|
|
1051
1511
|
this.#rootElement = resolveRoot(root);
|
|
1052
1512
|
const scrollMarginTargets = options.scrollMarginTargets === void 0 ? "[id]" : options.scrollMarginTargets;
|
|
@@ -1055,7 +1515,26 @@ var StickyScrollTrigger = (function() {
|
|
|
1055
1515
|
} catch {
|
|
1056
1516
|
throw new Error(`StickyScrollTrigger: scrollMarginTargets "${scrollMarginTargets}" is not a valid CSS selector.`);
|
|
1057
1517
|
}
|
|
1518
|
+
const optimization = options.nestedStickyOptimization === void 0 ? "auto" : options.nestedStickyOptimization;
|
|
1519
|
+
if (![
|
|
1520
|
+
"auto",
|
|
1521
|
+
"always",
|
|
1522
|
+
"off"
|
|
1523
|
+
].includes(optimization)) throw new Error(`StickyScrollTrigger: nestedStickyOptimization must be 'auto', 'always' or 'off', got ${String(optimization)}.`);
|
|
1058
1524
|
this.#scrollMarginSync = createScrollMarginSync(this.#rootElement, scrollMarginTargets);
|
|
1525
|
+
if (optimization === "always" || optimization === "auto" && isWebKit()) {
|
|
1526
|
+
this.#dormancyClient = {
|
|
1527
|
+
mode: optimization,
|
|
1528
|
+
ownedElements: () => this.#ownedStickyElements()
|
|
1529
|
+
};
|
|
1530
|
+
registerDormancyClient(this.#dormancyClient);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
#ownedStickyElements() {
|
|
1534
|
+
return [...this.#builtLayers.flatMap((layer) => layer.wrapper ? [layer.wrapper] : []), ...this.#wrappedPinTriggers()];
|
|
1535
|
+
}
|
|
1536
|
+
#wrappedPinTriggers() {
|
|
1537
|
+
return this.#pinLayers.flatMap(({ trigger, inner }) => inner ? [trigger] : []);
|
|
1059
1538
|
}
|
|
1060
1539
|
#unbuild() {
|
|
1061
1540
|
if (!this.#built) return;
|
|
@@ -1094,7 +1573,12 @@ var StickyScrollTrigger = (function() {
|
|
|
1094
1573
|
throw error;
|
|
1095
1574
|
});
|
|
1096
1575
|
}
|
|
1097
|
-
|
|
1576
|
+
const restoreDormancy = takeGsapRefreshRestore();
|
|
1577
|
+
if (!restoreDormancy) return result;
|
|
1578
|
+
return { render: (time) => {
|
|
1579
|
+
result?.render?.(time);
|
|
1580
|
+
restoreDormancy();
|
|
1581
|
+
} };
|
|
1098
1582
|
};
|
|
1099
1583
|
}
|
|
1100
1584
|
#wrapUnwrappedPins() {
|
|
@@ -1126,34 +1610,17 @@ var StickyScrollTrigger = (function() {
|
|
|
1126
1610
|
}
|
|
1127
1611
|
#unwrapPinLayer(layer) {
|
|
1128
1612
|
if (!layer.outer) return false;
|
|
1613
|
+
releaseDormant([layer.trigger]);
|
|
1129
1614
|
unwrapPin(layer.outer, layer.trigger, layer.savedPosition);
|
|
1130
1615
|
layer.outer = null;
|
|
1131
1616
|
layer.inner = null;
|
|
1132
1617
|
return true;
|
|
1133
1618
|
}
|
|
1134
1619
|
#resetSceneCoverStickyState() {
|
|
1135
|
-
|
|
1136
|
-
wrapper,
|
|
1137
|
-
position: wrapper.style.position,
|
|
1138
|
-
top: wrapper.style.top
|
|
1139
|
-
}));
|
|
1140
|
-
wrapperSnapshots.forEach(({ wrapper }) => resetStickyPosition(wrapper));
|
|
1141
|
-
return () => {
|
|
1142
|
-
wrapperSnapshots.forEach(({ wrapper, position, top }) => {
|
|
1143
|
-
wrapper.style.position = position;
|
|
1144
|
-
wrapper.style.top = top;
|
|
1145
|
-
});
|
|
1146
|
-
};
|
|
1620
|
+
return stripStickyPositions(this.#layers.flatMap(({ wrapper }) => wrapper ? [wrapper] : []));
|
|
1147
1621
|
}
|
|
1148
1622
|
#resetPinStickyState() {
|
|
1149
|
-
|
|
1150
|
-
trigger,
|
|
1151
|
-
position: captureInlinePosition(trigger)
|
|
1152
|
-
}));
|
|
1153
|
-
snapshots.forEach(({ trigger }) => resetStickyPosition(trigger));
|
|
1154
|
-
return () => {
|
|
1155
|
-
snapshots.forEach(({ trigger, position }) => restoreInlinePosition(trigger, position));
|
|
1156
|
-
};
|
|
1623
|
+
return stripStickyPositions(this.#wrappedPinTriggers());
|
|
1157
1624
|
}
|
|
1158
1625
|
#resetStickyState() {
|
|
1159
1626
|
const restoreSceneCoverStickyState = this.#resetSceneCoverStickyState();
|
|
@@ -1261,6 +1728,23 @@ var StickyScrollTrigger = (function() {
|
|
|
1261
1728
|
}
|
|
1262
1729
|
refresh() {
|
|
1263
1730
|
if (this.#destroyed) return;
|
|
1731
|
+
let failure = null;
|
|
1732
|
+
try {
|
|
1733
|
+
this.#refreshLayout();
|
|
1734
|
+
} catch (error) {
|
|
1735
|
+
failure = { error };
|
|
1736
|
+
}
|
|
1737
|
+
try {
|
|
1738
|
+
rebuildDormancy(this.#scrollTriggerClass);
|
|
1739
|
+
} catch (error) {
|
|
1740
|
+
clearDormancy();
|
|
1741
|
+
queueMicrotask(() => {
|
|
1742
|
+
throw error;
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
if (failure) throw failure.error;
|
|
1746
|
+
}
|
|
1747
|
+
#refreshLayout() {
|
|
1264
1748
|
if (this.#dirty || !this.#built || isDomOrderStale(this.#layers)) {
|
|
1265
1749
|
this.#unbuild();
|
|
1266
1750
|
this.#build();
|
|
@@ -1329,8 +1813,7 @@ var StickyScrollTrigger = (function() {
|
|
|
1329
1813
|
invalidateOnRefresh: rest.invalidateOnRefresh ?? true,
|
|
1330
1814
|
onKill: (self) => {
|
|
1331
1815
|
this.#captureScrollTriggerClass(self);
|
|
1332
|
-
|
|
1333
|
-
if (index !== -1) this.#layers.splice(index, 1);
|
|
1816
|
+
removeItem(this.#layers, layer);
|
|
1334
1817
|
this.#dirty = true;
|
|
1335
1818
|
this.#scheduleRebuild();
|
|
1336
1819
|
onKill?.(self);
|
|
@@ -1410,8 +1893,7 @@ var StickyScrollTrigger = (function() {
|
|
|
1410
1893
|
trigger,
|
|
1411
1894
|
onKill: (self) => {
|
|
1412
1895
|
this.#captureScrollTriggerClass(self);
|
|
1413
|
-
|
|
1414
|
-
if (index !== -1) this.#pinLayers.splice(index, 1);
|
|
1896
|
+
removeItem(this.#pinLayers, layer);
|
|
1415
1897
|
if (this.#unwrapPinLayer(layer)) this.#scheduleRebuild();
|
|
1416
1898
|
onKill?.(self);
|
|
1417
1899
|
},
|
|
@@ -1475,6 +1957,7 @@ var StickyScrollTrigger = (function() {
|
|
|
1475
1957
|
destroy() {
|
|
1476
1958
|
if (this.#destroyed) return;
|
|
1477
1959
|
this.#destroyed = true;
|
|
1960
|
+
unregisterDormancyClient(this.#dormancyClient);
|
|
1478
1961
|
this.#scrollMarginSync.restore();
|
|
1479
1962
|
this.#restoreCoverLifts();
|
|
1480
1963
|
this.#unbuild();
|