marquee-content 7.0.0-dev.0 → 7.0.0-dev.2
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 +10 -2
- package/dist/index.cjs +100 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +100 -46
- package/dist/index.js.map +1 -1
- package/dist/marquee-content.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,11 +106,15 @@ To react to page scrolling:
|
|
|
106
106
|
</marquee-content>
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
`scroll` listens to the window's vertical scroll position. Its direction follows scrolling, and its speed boost decays after scrolling stops. A custom scroll container is not currently configurable.
|
|
109
|
+
On devices with a fine pointer, `scroll` listens to the window's vertical scroll position. Its direction follows scrolling, and its speed boost decays after scrolling stops. A custom scroll container is not currently configurable.
|
|
110
|
+
|
|
111
|
+
On touch devices matching `(hover: none) and (pointer: coarse)`, `scroll` follows the scrolling direction at the configured constant speed, without acceleration or decay. Movement continues in the last direction after scrolling stops. The `direction` option determines the base direction, as on desktop. Direction changes preserve the current position and use a native CSS animation without a JavaScript frame loop. The component responds to changes in the input capabilities.
|
|
112
|
+
|
|
113
|
+
While speed is changing on a fine-pointer device, `scroll` updates the track's transform on animation frames. Once speed settles, it returns to the Web Animations API and stops the JavaScript frame loop.
|
|
110
114
|
|
|
111
115
|
## Responsive speed
|
|
112
116
|
|
|
113
|
-
Responsive speed is disabled by default. In `auto` mode, `speed="90"` gives `90px/s` at any container width. In `scroll` mode, it sets the base speed; scrolling and inertia intentionally change it.
|
|
117
|
+
Responsive speed is disabled by default. In `auto` mode, `speed="90"` gives `90px/s` at any container width. In `scroll` mode, it sets the base speed; on fine-pointer devices, scrolling and inertia intentionally change it.
|
|
114
118
|
|
|
115
119
|
Enable responsive speed to automatically slow movement in narrow containers:
|
|
116
120
|
|
|
@@ -210,6 +214,8 @@ Rendered items live in Shadow DOM. Use the exposed parts to style them:
|
|
|
210
214
|
| `viewport` | The container that clips the moving row. |
|
|
211
215
|
| `track` | The animated carrier of the groups. |
|
|
212
216
|
|
|
217
|
+
The default stylesheet uses `will-change: transform` on repeated groups as a [Safari loop-flicker workaround](https://bugs.webkit.org/show_bug.cgi?id=269284); reduced motion clears this hint. Each group therefore creates a stacking context and a containing block for positioned descendants. Individual items do not receive this hint.
|
|
218
|
+
|
|
213
219
|
A source element's existing `part` tokens are preserved alongside `item`, so individual items can have their own styles:
|
|
214
220
|
|
|
215
221
|
```html
|
|
@@ -280,6 +286,8 @@ The module can be imported when browser globals are unavailable. Custom element
|
|
|
280
286
|
|
|
281
287
|
The component uses Custom Elements, Shadow DOM, constructable/adopted stylesheets, ResizeObserver, IntersectionObserver, and `inert`. The `scroll` mode also uses the Web Animations API. Use a browser that supports these APIs; legacy-browser fallbacks are not included.
|
|
282
288
|
|
|
289
|
+
Safari can [throttle animation-frame callbacks in cross-origin iframes until user interaction](https://bugs.webkit.org/show_bug.cgi?id=213344); a swipe may not release the limit. [CodePen Full Page uses an iframe](https://blog.codepen.io/documentation/full-page-view/), so compare `scroll` performance in Debug View or a standalone page with `<meta name="viewport" content="width=device-width, initial-scale=1">`.
|
|
290
|
+
|
|
283
291
|
## License
|
|
284
292
|
|
|
285
293
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
//#region src/marquee-content.css?inline
|
|
4
|
-
var marquee_content_default = ":host{--marquee-content-gap:2rem;--marquee-content-distance:0px;--marquee-content-duration:20s;width:100%;color:inherit;font:inherit;pointer-events:none;display:block;position:relative;overflow:hidden}:host([data-marquee-content-pause-on-hover]){pointer-events:auto}:host([hidden]){display:none}.marquee-content__viewport{width:100%;overflow:hidden}.marquee-content__track{-webkit-backface-visibility:hidden;backface-visibility:hidden;will-change:transform;width:max-content;display:flex;transform:translate(0,0)}.marquee-content__group{align-items:center;gap:var(--marquee-content-gap);white-space:nowrap;color:inherit;font:inherit;flex:none;padding-inline-end:var(--marquee-content-gap);display:flex}.marquee-content__group>*{flex:none}:host([data-marquee-content-reduced-motion]) .marquee-content__track{will-change:auto;width:100%}:host([data-marquee-content-reduced-motion]) .marquee-content__group{white-space:normal;overflow-wrap:anywhere;flex-wrap:wrap;flex:auto;width:100%;padding-inline-end:0}:host([data-marquee-content-reduced-motion]) .marquee-content__group>*{min-width:0;max-width:100%}\n";
|
|
4
|
+
var marquee_content_default = ":host{--marquee-content-gap:2rem;--marquee-content-distance:0px;--marquee-content-duration:20s;width:100%;color:inherit;font:inherit;pointer-events:none;display:block;position:relative;overflow:hidden}:host([data-marquee-content-pause-on-hover]){pointer-events:auto}:host([hidden]){display:none}.marquee-content__viewport{width:100%;overflow:hidden}.marquee-content__track{-webkit-backface-visibility:hidden;backface-visibility:hidden;will-change:transform;width:max-content;display:flex;transform:translate(0,0)}.marquee-content__group{align-items:center;gap:var(--marquee-content-gap);white-space:nowrap;color:inherit;font:inherit;will-change:transform;flex:none;padding-inline-end:var(--marquee-content-gap);display:flex}.marquee-content__group>*{flex:none}:host([data-marquee-content-reduced-motion]) .marquee-content__track{will-change:auto;width:100%}:host([data-marquee-content-reduced-motion]) .marquee-content__group{white-space:normal;overflow-wrap:anywhere;will-change:auto;flex-wrap:wrap;flex:auto;width:100%;padding-inline-end:0}:host([data-marquee-content-reduced-motion]) .marquee-content__group>*{min-width:0;max-width:100%}\n";
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/styles.ts
|
|
@@ -73,6 +73,7 @@ const OPTION_ATTRIBUTE_MAP = {
|
|
|
73
73
|
};
|
|
74
74
|
const MARQUEE_CONTENT_CSS_PROPS = ["--marquee-content-distance", "--marquee-content-duration"];
|
|
75
75
|
const SCROLL_TIME_SCALE_SMOOTHING_SECONDS = .12;
|
|
76
|
+
const TOUCH_INPUT_QUERY = "(hover: none) and (pointer: coarse)";
|
|
76
77
|
const HTMLElementBase = globalThis.HTMLElement ?? class {};
|
|
77
78
|
const MARQUEE_CONTENT_RUNTIME_CSS = `
|
|
78
79
|
@keyframes marquee-content-auto {
|
|
@@ -141,6 +142,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
141
142
|
intersectionObserver = null;
|
|
142
143
|
abortController = null;
|
|
143
144
|
reducedMotionMediaQuery = null;
|
|
145
|
+
touchInputMediaQuery = null;
|
|
144
146
|
animationFrameId = null;
|
|
145
147
|
rebuildFrameId = null;
|
|
146
148
|
lastFrameTime = null;
|
|
@@ -149,6 +151,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
149
151
|
isFocused = false;
|
|
150
152
|
isInViewport = true;
|
|
151
153
|
reducedMotion = false;
|
|
154
|
+
touchInput = false;
|
|
152
155
|
isListeningToScroll = false;
|
|
153
156
|
distance = 0;
|
|
154
157
|
containerWidth = 0;
|
|
@@ -158,6 +161,8 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
158
161
|
scrollAnimationDuration = 0;
|
|
159
162
|
scrollAnimationDistance = 0;
|
|
160
163
|
scrollProgress = 0;
|
|
164
|
+
scrollMotionActive = false;
|
|
165
|
+
scrollBaseSpeed = DEFAULT_OPTIONS.speed;
|
|
161
166
|
scrollDirectionFactor = 1;
|
|
162
167
|
currentTimeScale = 1;
|
|
163
168
|
scrollBoostStartValue = 0;
|
|
@@ -213,6 +218,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
213
218
|
this.intersectionObserver = new IntersectionObserver(this.handleIntersectionChange);
|
|
214
219
|
this.intersectionObserver.observe(this);
|
|
215
220
|
this.setupReducedMotionWatcher();
|
|
221
|
+
this.setupTouchInputWatcher();
|
|
216
222
|
this.watchSourceNodes();
|
|
217
223
|
this.updateScrollListener();
|
|
218
224
|
this.rebuild();
|
|
@@ -293,6 +299,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
293
299
|
this.mutationObserver?.disconnect();
|
|
294
300
|
this.intersectionObserver?.disconnect();
|
|
295
301
|
this.removeReducedMotionWatcher();
|
|
302
|
+
this.removeTouchInputWatcher();
|
|
296
303
|
this.abortController?.abort();
|
|
297
304
|
this.group = null;
|
|
298
305
|
this.layoutPending = false;
|
|
@@ -317,6 +324,8 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
317
324
|
this.scrollBoostStartValue = 0;
|
|
318
325
|
this.scrollBoostStartedAt = 0;
|
|
319
326
|
this.scrollProgress = 0;
|
|
327
|
+
this.scrollMotionActive = false;
|
|
328
|
+
this.scrollBaseSpeed = DEFAULT_OPTIONS.speed;
|
|
320
329
|
this.currentTimeScale = 1;
|
|
321
330
|
this.lastFrameTime = null;
|
|
322
331
|
}
|
|
@@ -355,7 +364,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
355
364
|
handleReducedMotionChange = (event) => {
|
|
356
365
|
this.reducedMotion = event.matches;
|
|
357
366
|
if (this.reducedMotion) this.track.style.transform = "none";
|
|
358
|
-
else if (this.
|
|
367
|
+
else if (this.getEffectiveMode() === "scroll") this.track.style.transform = "";
|
|
359
368
|
this.updateAnimationLoopState();
|
|
360
369
|
this.scheduleRebuild();
|
|
361
370
|
};
|
|
@@ -369,7 +378,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
369
378
|
this.lastScrollTime = now;
|
|
370
379
|
if (Math.abs(deltaY) < .5) return;
|
|
371
380
|
const velocity = deltaY / deltaTime;
|
|
372
|
-
|
|
381
|
+
const direction = velocity >= 0 ? 1 : -1;
|
|
382
|
+
const directionChanged = direction !== this.scrollDirectionFactor;
|
|
383
|
+
this.scrollDirectionFactor = direction;
|
|
384
|
+
if (this.touchInput) {
|
|
385
|
+
if (directionChanged) this.applyOptions();
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
373
388
|
const extraSpeed = this.clamp(velocity / this.options.scrollVelocityFactor, -this.options.scrollMaxExtraSpeed, this.options.scrollMaxExtraSpeed);
|
|
374
389
|
if (Math.abs(extraSpeed) >= this.options.scrollMinExtraSpeed) {
|
|
375
390
|
this.scrollBoostStartValue = extraSpeed;
|
|
@@ -378,10 +393,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
378
393
|
this.onScrollBoostChanged();
|
|
379
394
|
};
|
|
380
395
|
onScrollBoostChanged() {
|
|
381
|
-
if (!this.mounted || this.
|
|
382
|
-
this.
|
|
383
|
-
if (!this.
|
|
384
|
-
|
|
396
|
+
if (!this.mounted || this.getEffectiveMode() !== "scroll" || this.reducedMotion) return;
|
|
397
|
+
if (!this.canAnimate() || this.distance <= 0) return;
|
|
398
|
+
if (!this.scrollMotionActive) {
|
|
399
|
+
this.cancelScrollAnimation();
|
|
400
|
+
this.scrollMotionActive = true;
|
|
401
|
+
this.renderScrollProgress();
|
|
402
|
+
}
|
|
385
403
|
this.startAnimationLoop();
|
|
386
404
|
}
|
|
387
405
|
updateScrollListener(shouldListen = this.mounted && this.options.mode === "scroll") {
|
|
@@ -409,7 +427,8 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
409
427
|
applyOptions() {
|
|
410
428
|
if (!this.mounted) return;
|
|
411
429
|
const progress = this.scrollAnimation ? this.getScrollAnimationProgress() : this.getAutoAnimation()?.effect?.getComputedTiming().progress ?? this.scrollProgress;
|
|
412
|
-
|
|
430
|
+
this.scrollBaseSpeed = this.getCurrentSpeed(this.clientWidth);
|
|
431
|
+
const duration = this.distance / this.scrollBaseSpeed;
|
|
413
432
|
this.setAttribute("data-marquee-content-mode", this.options.mode);
|
|
414
433
|
this.toggleAttribute("data-marquee-content-pause-on-hover", this.options.pauseOnHover);
|
|
415
434
|
this.toggleAttribute("data-marquee-content-reduced-motion", this.reducedMotion);
|
|
@@ -419,9 +438,9 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
419
438
|
}
|
|
420
439
|
if (progress != null) this.scrollProgress = progress;
|
|
421
440
|
this.updateAnimationLoopState();
|
|
422
|
-
if (progress != null && this.
|
|
441
|
+
if (progress != null && this.getEffectiveMode() === "auto" && !this.reducedMotion) {
|
|
423
442
|
const animation = this.getAutoAnimation();
|
|
424
|
-
if (animation) animation.currentTime = duration * 1e3 * (this.
|
|
443
|
+
if (animation) animation.currentTime = duration * 1e3 * (this.track.style.animationDirection === "reverse" ? 1 - progress : progress);
|
|
425
444
|
}
|
|
426
445
|
}
|
|
427
446
|
getAutoAnimation() {
|
|
@@ -559,30 +578,66 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
559
578
|
this.reducedMotionMediaQuery.removeEventListener("change", this.handleReducedMotionChange);
|
|
560
579
|
this.reducedMotionMediaQuery = null;
|
|
561
580
|
}
|
|
581
|
+
getEffectiveMode() {
|
|
582
|
+
return this.touchInput ? "auto" : this.options.mode;
|
|
583
|
+
}
|
|
584
|
+
setupTouchInputWatcher() {
|
|
585
|
+
if (!("matchMedia" in window)) return;
|
|
586
|
+
this.touchInputMediaQuery = window.matchMedia(TOUCH_INPUT_QUERY);
|
|
587
|
+
this.touchInput = this.touchInputMediaQuery.matches;
|
|
588
|
+
this.touchInputMediaQuery.addEventListener("change", this.handleTouchInputChange, { signal: this.abortController?.signal });
|
|
589
|
+
}
|
|
590
|
+
removeTouchInputWatcher() {
|
|
591
|
+
this.touchInputMediaQuery?.removeEventListener("change", this.handleTouchInputChange);
|
|
592
|
+
this.touchInputMediaQuery = null;
|
|
593
|
+
this.touchInput = false;
|
|
594
|
+
}
|
|
595
|
+
handleTouchInputChange = (event) => {
|
|
596
|
+
if (!this.mounted || event.matches === this.touchInput) return;
|
|
597
|
+
this.touchInput = event.matches;
|
|
598
|
+
this.stopAnimationLoop();
|
|
599
|
+
this.cancelScrollAnimation();
|
|
600
|
+
this.scrollMotionActive = false;
|
|
601
|
+
this.scrollBoostStartValue = 0;
|
|
602
|
+
this.scrollBoostStartedAt = 0;
|
|
603
|
+
this.currentTimeScale = this.getDirectionFactor() * this.scrollDirectionFactor;
|
|
604
|
+
this.updateScrollListener();
|
|
605
|
+
this.applyOptions();
|
|
606
|
+
};
|
|
562
607
|
updateAnimationLoopState() {
|
|
563
608
|
if (!this.mounted || this.distance <= 0 || this.reducedMotion) {
|
|
564
609
|
this.stopAnimationLoop();
|
|
565
610
|
this.stopCssAnimation();
|
|
566
611
|
this.cancelScrollAnimation();
|
|
567
|
-
if (this.reducedMotion) this.
|
|
612
|
+
if (!this.mounted || this.getEffectiveMode() !== "scroll" || this.reducedMotion) this.scrollMotionActive = false;
|
|
613
|
+
this.track.style.transform = this.reducedMotion ? "none" : "";
|
|
568
614
|
return;
|
|
569
615
|
}
|
|
570
|
-
if (this.
|
|
616
|
+
if (this.getEffectiveMode() === "scroll") {
|
|
571
617
|
this.stopCssAnimation();
|
|
572
|
-
this.
|
|
618
|
+
if (this.scrollMotionActive) {
|
|
619
|
+
this.renderScrollProgress();
|
|
620
|
+
if (this.canAnimate()) this.startAnimationLoop();
|
|
621
|
+
else this.stopAnimationLoop();
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
this.currentTimeScale = this.getDirectionFactor() * this.scrollDirectionFactor;
|
|
573
625
|
this.ensureScrollAnimation();
|
|
574
626
|
if (!this.scrollAnimation || !this.canAnimate()) {
|
|
575
627
|
this.scrollAnimation?.pause();
|
|
576
628
|
this.stopAnimationLoop();
|
|
577
629
|
return;
|
|
578
630
|
}
|
|
579
|
-
this.
|
|
580
|
-
|
|
581
|
-
|
|
631
|
+
if (this.scrollBoostStartValue !== 0) this.onScrollBoostChanged();
|
|
632
|
+
else {
|
|
633
|
+
this.track.style.transform = "";
|
|
634
|
+
if (this.scrollAnimation.playState !== "running") this.scrollAnimation.play();
|
|
635
|
+
}
|
|
582
636
|
return;
|
|
583
637
|
}
|
|
584
638
|
this.stopAnimationLoop();
|
|
585
639
|
this.cancelScrollAnimation();
|
|
640
|
+
this.scrollMotionActive = false;
|
|
586
641
|
this.startCssAnimation();
|
|
587
642
|
this.track.style.animationPlayState = this.canAnimate() ? "running" : "paused";
|
|
588
643
|
}
|
|
@@ -607,7 +662,8 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
607
662
|
this.lastFrameTime = null;
|
|
608
663
|
}
|
|
609
664
|
startCssAnimation() {
|
|
610
|
-
const
|
|
665
|
+
const scrollDirection = this.touchInput && this.options.mode === "scroll" ? this.scrollDirectionFactor : 1;
|
|
666
|
+
const animationDirection = this.getDirectionFactor() * scrollDirection < 0 ? "reverse" : "normal";
|
|
611
667
|
this.track.style.transform = "";
|
|
612
668
|
if (this.track.style.animationName !== "marquee-content-auto") {
|
|
613
669
|
this.track.style.animationName = "marquee-content-auto";
|
|
@@ -627,34 +683,39 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
627
683
|
}
|
|
628
684
|
tick = (now) => {
|
|
629
685
|
this.animationFrameId = null;
|
|
630
|
-
if (!this.mounted || this.
|
|
631
|
-
if (
|
|
686
|
+
if (!this.mounted || this.getEffectiveMode() !== "scroll" || this.distance <= 0 || this.reducedMotion || !this.canAnimate() || !this.scrollMotionActive) return;
|
|
687
|
+
if (this.advanceScrollMotion(now)) {
|
|
688
|
+
this.scrollMotionActive = false;
|
|
689
|
+
this.ensureScrollAnimation();
|
|
690
|
+
this.track.style.transform = "";
|
|
691
|
+
this.lastFrameTime = null;
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
this.animationFrameId = requestAnimationFrame(this.tick);
|
|
632
695
|
};
|
|
633
696
|
ensureScrollAnimation() {
|
|
634
697
|
if (this.distance <= 0) {
|
|
635
698
|
this.cancelScrollAnimation();
|
|
636
699
|
return;
|
|
637
700
|
}
|
|
638
|
-
const currentSpeed = this.
|
|
701
|
+
const currentSpeed = this.scrollBaseSpeed;
|
|
639
702
|
const durationMs = currentSpeed > 0 ? this.distance / currentSpeed * 1e3 : 0;
|
|
703
|
+
const reversed = this.currentTimeScale < 0;
|
|
640
704
|
if (durationMs <= 0) {
|
|
641
705
|
this.cancelScrollAnimation();
|
|
642
706
|
return;
|
|
643
707
|
}
|
|
644
|
-
if (this.scrollAnimation && this.scrollAnimationDistance === this.distance && this.scrollAnimationDuration === durationMs) return;
|
|
708
|
+
if (this.scrollAnimation && this.scrollAnimationDistance === this.distance && this.scrollAnimationDuration === durationMs && this.scrollAnimation.effect?.getTiming().direction === (reversed ? "reverse" : "normal")) return;
|
|
645
709
|
const progress = this.getScrollAnimationProgress();
|
|
646
|
-
const hadAnimation = this.scrollAnimation !== null;
|
|
647
710
|
if (this.scrollAnimation) {
|
|
648
711
|
this.scrollAnimation.cancel();
|
|
649
712
|
this.scrollAnimation = null;
|
|
650
713
|
}
|
|
651
|
-
if (!hadAnimation) this.currentTimeScale = this.getDirectionFactor() * this.scrollDirectionFactor;
|
|
652
714
|
const animation = this.track.animate([{ transform: "translate3d(0px, 0, 0)" }, { transform: `translate3d(${-this.distance}px, 0, 0)` }], {
|
|
653
715
|
duration: durationMs,
|
|
654
716
|
iterations: Number.POSITIVE_INFINITY,
|
|
655
717
|
easing: "linear"
|
|
656
718
|
});
|
|
657
|
-
const reversed = this.currentTimeScale < 0;
|
|
658
719
|
animation.effect?.updateTiming({ direction: reversed ? "reverse" : "normal" });
|
|
659
720
|
animation.currentTime = durationMs * (reversed ? 1 - progress : progress);
|
|
660
721
|
animation.playbackRate = Math.abs(this.currentTimeScale);
|
|
@@ -682,35 +743,28 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
682
743
|
const normalized = fraction < 0 ? fraction + 1 : fraction;
|
|
683
744
|
return animation.effect?.getTiming().direction === "reverse" ? (1 - normalized) % 1 : normalized;
|
|
684
745
|
}
|
|
685
|
-
|
|
686
|
-
if (!this.scrollAnimation) return true;
|
|
746
|
+
advanceScrollMotion(now) {
|
|
687
747
|
const target = this.getCurrentTimeScale(now);
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
this.lastFrameTime = now;
|
|
695
|
-
const smoothingFactor = 1 - Math.exp(-deltaTime / SCROLL_TIME_SCALE_SMOOTHING_SECONDS);
|
|
696
|
-
this.currentTimeScale += (target - this.currentTimeScale) * smoothingFactor;
|
|
697
|
-
}
|
|
748
|
+
const previousTimeScale = this.currentTimeScale;
|
|
749
|
+
const previousTime = this.lastFrameTime ?? now;
|
|
750
|
+
const deltaTime = this.clamp((now - previousTime) / 1e3, 0, .064);
|
|
751
|
+
this.lastFrameTime = now;
|
|
752
|
+
const smoothingFactor = 1 - Math.exp(-deltaTime / SCROLL_TIME_SCALE_SMOOTHING_SECONDS);
|
|
753
|
+
this.currentTimeScale += (target - this.currentTimeScale) * smoothingFactor;
|
|
698
754
|
const settled = this.scrollBoostStartValue === 0 && Math.abs(target - this.currentTimeScale) < .001;
|
|
699
755
|
if (settled) this.currentTimeScale = target;
|
|
700
|
-
const
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
effect.updateTiming({ direction: reversed ? "reverse" : "normal" });
|
|
705
|
-
this.scrollAnimation.currentTime = this.scrollAnimationDuration * (reversed ? 1 - progress : progress);
|
|
706
|
-
}
|
|
707
|
-
const playbackRate = Math.abs(this.currentTimeScale);
|
|
708
|
-
if (this.scrollAnimation.playbackRate !== playbackRate) this.scrollAnimation.updatePlaybackRate(playbackRate);
|
|
756
|
+
const averageTimeScale = (previousTimeScale + this.currentTimeScale) / 2;
|
|
757
|
+
const progress = this.scrollProgress + this.scrollBaseSpeed * averageTimeScale * deltaTime / this.distance;
|
|
758
|
+
this.scrollProgress = (progress % 1 + 1) % 1;
|
|
759
|
+
this.renderScrollProgress();
|
|
709
760
|
return settled;
|
|
710
761
|
}
|
|
762
|
+
renderScrollProgress() {
|
|
763
|
+
this.track.style.transform = `translate3d(${-this.scrollProgress * this.distance}px, 0, 0)`;
|
|
764
|
+
}
|
|
711
765
|
getCurrentTimeScale(now) {
|
|
712
766
|
const directionFactor = this.getDirectionFactor();
|
|
713
|
-
if (this.
|
|
767
|
+
if (this.getEffectiveMode() !== "scroll") return directionFactor;
|
|
714
768
|
const boost = this.getScrollBoost(now);
|
|
715
769
|
const scrollTimeScale = this.scrollDirectionFactor + boost;
|
|
716
770
|
return this.clamp(directionFactor * scrollTimeScale, -1 - this.options.scrollMaxExtraSpeed, 1 + this.options.scrollMaxExtraSpeed);
|