marquee-content 6.0.1 → 7.0.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,8 +66,8 @@ Calling a registration helper is only needed for an additional tag or global sty
66
66
 
67
67
  | Option (HTML / JavaScript) | Type | Default | Description |
68
68
  | --- | --- | --- | --- |
69
- | `speed` | `number` | `90` | Base speed in px/s, clamped to `10`–`500` before responsive scaling. |
70
- | `responsive-speed` / `responsiveSpeed` | `boolean` | `true` | Scales the base speed with the component's width. Set to `false` to use the requested base px/s. |
69
+ | `speed` | `number` | `90` | Base speed in px/s, clamped to `10`–`500`. Used unchanged unless responsive speed is enabled. |
70
+ | `responsive-speed` / `responsiveSpeed` | `boolean` | `false` | Automatically reduces movement speed in narrow containers when enabled. |
71
71
  | `mode` | `'auto' \| 'scroll'` | `'auto'` | `'auto'` for constant movement; `'scroll'` for page-scroll response and inertia. |
72
72
  | `direction` | `'rtl' \| 'ltr'` | `'rtl'` | Base direction: right to left or left to right. |
73
73
  | `pause-on-hover` / `pauseOnHover` | `boolean` | `false` | Pauses movement while the pointer is over the host. Items remain decorative and inert. |
@@ -108,21 +108,17 @@ To react to page scrolling:
108
108
 
109
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.
110
110
 
111
- ## Speed on narrow screens
111
+ While speed is changing, `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.
112
112
 
113
- Responsive speed is enabled by default. It uses the **component's width**, in CSS pixels:
113
+ ## Responsive speed
114
114
 
115
- ```text
116
- effective speed = speed × clamp(component width / 1280, 0.55, 1)
117
- ```
118
-
119
- Below a component width of about `700px`, speed stays at 55% of the configured value — about `50px/s` with the default `speed="90"`. At `1280px` and above, it uses the configured speed without scaling.
115
+ 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.
120
116
 
121
- For the same base speed on mobile and desktop, disable scaling:
117
+ Enable responsive speed to automatically slow movement in narrow containers:
122
118
 
123
119
  ```html
124
- <marquee-content speed="90" responsive-speed="false">
125
- <span>Consistent speed across screen sizes</span>
120
+ <marquee-content speed="90" responsive-speed>
121
+ <span>Slower movement in narrow containers</span>
126
122
  </marquee-content>
127
123
  ```
128
124
 
@@ -130,13 +126,20 @@ For the same base speed on mobile and desktop, disable scaling:
130
126
  const marquee = document.querySelector('marquee-content');
131
127
 
132
128
  if (marquee) {
133
- marquee.responsiveSpeed = false;
134
- marquee.speed = 90;
135
- // Equivalent: marquee.update({ responsiveSpeed: false, speed: 90 });
129
+ marquee.responsiveSpeed = true;
130
+ // Equivalent: marquee.update({ responsiveSpeed: true });
136
131
  }
137
132
  ```
138
133
 
139
- In `auto` mode, this gives `90px/s`. In `scroll` mode, `90px/s` is the base speed; scrolling and inertia intentionally change it.
134
+ When enabled, scaling uses the **component's width**, in CSS pixels:
135
+
136
+ ```text
137
+ effective base speed = speed × clamp(component width / 1280, 0.55, 1)
138
+ ```
139
+
140
+ At widths up to `704px` (`1280 × 0.55`), speed stays at 55% of the configured value: `speed="90"` becomes `49.5px/s`. Between `704px` and `1280px`, it increases linearly. At `1280px` and above, it uses the configured speed without scaling.
141
+
142
+ Remove the attribute or set `responsive-speed="false"` to disable scaling again.
140
143
 
141
144
  ## Vue 3 with Vite
142
145
 
@@ -209,6 +212,8 @@ Rendered items live in Shadow DOM. Use the exposed parts to style them:
209
212
  | `viewport` | The container that clips the moving row. |
210
213
  | `track` | The animated carrier of the groups. |
211
214
 
215
+ 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.
216
+
212
217
  A source element's existing `part` tokens are preserved alongside `item`, so individual items can have their own styles:
213
218
 
214
219
  ```html
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
@@ -45,8 +45,7 @@ const DEFAULT_OPTIONS = {
45
45
  speed: 90,
46
46
  mode: "auto",
47
47
  direction: "rtl",
48
- minGroupWidthRatio: 1.05,
49
- responsiveSpeed: true,
48
+ responsiveSpeed: false,
50
49
  referenceWidth: 1280,
51
50
  minSpeedFactor: .55,
52
51
  maxSpeedFactor: 1,
@@ -133,6 +132,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
133
132
  }
134
133
  shadow;
135
134
  sourceSlot;
135
+ viewport;
136
136
  track;
137
137
  options = { ...DEFAULT_OPTIONS };
138
138
  sourceNodes = [];
@@ -153,11 +153,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
153
153
  distance = 0;
154
154
  containerWidth = 0;
155
155
  group = null;
156
- layoutPhase = null;
156
+ layoutPending = false;
157
157
  scrollAnimation = null;
158
158
  scrollAnimationDuration = 0;
159
159
  scrollAnimationDistance = 0;
160
160
  scrollProgress = 0;
161
+ scrollMotionActive = false;
162
+ scrollBaseSpeed = DEFAULT_OPTIONS.speed;
161
163
  scrollDirectionFactor = 1;
162
164
  currentTimeScale = 1;
163
165
  scrollBoostStartValue = 0;
@@ -173,10 +175,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
173
175
  template.innerHTML = TEMPLATE;
174
176
  this.shadow.appendChild(template.content.cloneNode(true));
175
177
  const sourceSlot = this.shadow.querySelector("slot.marquee-content__source");
178
+ const viewport = this.shadow.querySelector(".marquee-content__viewport");
176
179
  const track = this.shadow.querySelector(".marquee-content__track");
177
180
  if (!sourceSlot) throw new Error("[MarqueeContent] Source slot was not found.");
178
181
  if (!track) throw new Error("[MarqueeContent] Track element was not found.");
182
+ if (!viewport) throw new Error("[MarqueeContent] Viewport element was not found.");
179
183
  this.sourceSlot = sourceSlot;
184
+ this.viewport = viewport;
180
185
  this.track = track;
181
186
  }
182
187
  connectedCallback() {
@@ -206,6 +211,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
206
211
  window.addEventListener("orientationchange", this.scheduleRebuild, { signal: this.abortController.signal });
207
212
  this.resizeObserver = new ResizeObserver(this.handleResize);
208
213
  this.resizeObserver.observe(this);
214
+ this.resizeObserver.observe(this.viewport);
209
215
  this.intersectionObserver = new IntersectionObserver(this.handleIntersectionChange);
210
216
  this.intersectionObserver.observe(this);
211
217
  this.setupReducedMotionWatcher();
@@ -291,7 +297,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
291
297
  this.removeReducedMotionWatcher();
292
298
  this.abortController?.abort();
293
299
  this.group = null;
294
- this.layoutPhase = null;
300
+ this.layoutPending = false;
295
301
  this.containerWidth = 0;
296
302
  this.resizeObserver = null;
297
303
  this.mutationObserver = null;
@@ -313,11 +319,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
313
319
  this.scrollBoostStartValue = 0;
314
320
  this.scrollBoostStartedAt = 0;
315
321
  this.scrollProgress = 0;
322
+ this.scrollMotionActive = false;
323
+ this.scrollBaseSpeed = DEFAULT_OPTIONS.speed;
316
324
  this.currentTimeScale = 1;
317
325
  this.lastFrameTime = null;
318
326
  }
319
327
  handleResize = () => {
320
- if (this.clientWidth !== this.containerWidth || this.group && this.layoutPhase === null && Math.abs(this.measureGroup(this.group) - this.distance) > .01) this.scheduleRebuild();
328
+ if (this.measureViewportWidth() !== this.containerWidth || this.group && !this.layoutPending && Math.abs(this.measureGroup(this.group) - this.distance) > .01) this.scheduleRebuild();
321
329
  };
322
330
  handleSourceLoad = (event) => {
323
331
  if (event.target instanceof Node && event.target !== this && this.contains(event.target)) this.scheduleRebuild();
@@ -375,9 +383,12 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
375
383
  };
376
384
  onScrollBoostChanged() {
377
385
  if (!this.mounted || this.options.mode !== "scroll" || this.reducedMotion) return;
378
- this.ensureScrollAnimation();
379
- if (!this.scrollAnimation || !this.canAnimate()) return;
380
- this.scrollAnimation.play();
386
+ if (!this.canAnimate() || this.distance <= 0) return;
387
+ if (!this.scrollMotionActive) {
388
+ this.cancelScrollAnimation();
389
+ this.scrollMotionActive = true;
390
+ this.renderScrollProgress();
391
+ }
381
392
  this.startAnimationLoop();
382
393
  }
383
394
  updateScrollListener(shouldListen = this.mounted && this.options.mode === "scroll") {
@@ -405,7 +416,8 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
405
416
  applyOptions() {
406
417
  if (!this.mounted) return;
407
418
  const progress = this.scrollAnimation ? this.getScrollAnimationProgress() : this.getAutoAnimation()?.effect?.getComputedTiming().progress ?? this.scrollProgress;
408
- const duration = this.distance / this.getCurrentSpeed(this.clientWidth);
419
+ this.scrollBaseSpeed = this.getCurrentSpeed(this.clientWidth);
420
+ const duration = this.distance / this.scrollBaseSpeed;
409
421
  this.setAttribute("data-marquee-content-mode", this.options.mode);
410
422
  this.toggleAttribute("data-marquee-content-pause-on-hover", this.options.pauseOnHover);
411
423
  this.toggleAttribute("data-marquee-content-reduced-motion", this.reducedMotion);
@@ -430,11 +442,11 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
430
442
  const progress = this.scrollAnimation ? this.getScrollAnimationProgress() : this.getAutoAnimation()?.effect?.getComputedTiming().progress;
431
443
  if (progress != null) this.scrollProgress = progress;
432
444
  this.distance = 0;
433
- this.layoutPhase = null;
445
+ this.layoutPending = false;
434
446
  this.updateAnimationLoopState();
435
447
  this.removeAttribute("data-marquee-content-ready");
436
448
  this.toggleAttribute("data-marquee-content-reduced-motion", this.reducedMotion);
437
- this.containerWidth = this.clientWidth;
449
+ this.containerWidth = this.measureViewportWidth();
438
450
  if (this.group) {
439
451
  this.resizeObserver?.unobserve(this.group);
440
452
  this.group = null;
@@ -448,25 +460,21 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
448
460
  }
449
461
  this.group = this.createGroup();
450
462
  this.track.replaceChildren(this.group);
451
- this.layoutPhase = "source";
463
+ this.layoutPending = true;
452
464
  this.completeLayout();
453
465
  }
454
466
  completeLayout = () => {
455
467
  const group = this.group;
456
- if (!this.mounted || !group || this.layoutPhase === null) return;
468
+ if (!this.mounted || !group || !this.layoutPending) return;
457
469
  if (this.hasPendingImages(this.track)) return;
458
- if (this.layoutPhase === "source") {
459
- this.layoutPhase = "copies";
460
- if (!this.reducedMotion) {
461
- this.expandGroupToWidth(group, this.containerWidth * this.options.minGroupWidthRatio);
462
- this.track.appendChild(group.cloneNode(true));
463
- }
470
+ if (!this.reducedMotion) {
471
+ this.fillTrack(group);
464
472
  if (this.hasPendingImages(this.track)) return;
465
473
  }
466
- this.layoutPhase = null;
474
+ this.layoutPending = false;
467
475
  this.distance = this.measureGroup(group);
468
476
  this.resizeObserver?.observe(group);
469
- if (this.distance <= 0) {
477
+ if (!Number.isFinite(this.distance) || this.distance <= 0) {
470
478
  this.track.replaceChildren();
471
479
  this.applyOptions();
472
480
  return;
@@ -477,6 +485,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
477
485
  hasPendingImages(root) {
478
486
  return Array.from(root.querySelectorAll("img")).some((image) => !image.complete);
479
487
  }
488
+ measureViewportWidth() {
489
+ if (this.viewport.getClientRects().length === 0) return 0;
490
+ const style = getComputedStyle(this.viewport);
491
+ const width = Number.parseFloat(style.width);
492
+ if (!Number.isFinite(width)) return this.viewport.clientWidth;
493
+ return style.boxSizing === "border-box" ? width - Number.parseFloat(style.borderLeftWidth) - Number.parseFloat(style.borderRightWidth) : width + Number.parseFloat(style.paddingLeft) + Number.parseFloat(style.paddingRight);
494
+ }
480
495
  measureGroup(group) {
481
496
  const style = getComputedStyle(group);
482
497
  const width = Number.parseFloat(style.width);
@@ -491,11 +506,14 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
491
506
  this.appendSourceNodes(group);
492
507
  return group;
493
508
  }
494
- expandGroupToWidth(group, targetWidth) {
495
- const sourceSetWidth = this.measureGroup(group);
496
- if (sourceSetWidth <= 0) return;
497
- const repeatCount = Math.ceil(targetWidth / sourceSetWidth);
498
- for (let index = 1; index < repeatCount; index += 1) this.appendSourceNodes(group);
509
+ fillTrack(group) {
510
+ const period = this.measureGroup(group);
511
+ if (!Number.isFinite(period) || period <= 0) return;
512
+ const groupCount = Math.ceil(this.containerWidth / period) + 1;
513
+ while (this.track.childElementCount > groupCount) this.track.lastElementChild?.remove();
514
+ const fragment = document.createDocumentFragment();
515
+ for (let index = this.track.childElementCount; index < groupCount; index += 1) fragment.appendChild(group.cloneNode(true));
516
+ this.track.appendChild(fragment);
499
517
  }
500
518
  appendSourceNodes(target) {
501
519
  const fragment = document.createDocumentFragment();
@@ -554,25 +572,35 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
554
572
  this.stopAnimationLoop();
555
573
  this.stopCssAnimation();
556
574
  this.cancelScrollAnimation();
557
- if (this.reducedMotion) this.track.style.transform = "none";
575
+ if (!this.mounted || this.options.mode !== "scroll" || this.reducedMotion) this.scrollMotionActive = false;
576
+ this.track.style.transform = this.reducedMotion ? "none" : "";
558
577
  return;
559
578
  }
560
579
  if (this.options.mode === "scroll") {
561
580
  this.stopCssAnimation();
562
- this.track.style.transform = "";
581
+ if (this.scrollMotionActive) {
582
+ this.renderScrollProgress();
583
+ if (this.canAnimate()) this.startAnimationLoop();
584
+ else this.stopAnimationLoop();
585
+ return;
586
+ }
587
+ this.currentTimeScale = this.getDirectionFactor() * this.scrollDirectionFactor;
563
588
  this.ensureScrollAnimation();
564
589
  if (!this.scrollAnimation || !this.canAnimate()) {
565
590
  this.scrollAnimation?.pause();
566
591
  this.stopAnimationLoop();
567
592
  return;
568
593
  }
569
- this.scrollAnimation.play();
570
- this.updateScrollPlaybackRate(performance.now(), true);
571
- this.startAnimationLoop();
594
+ if (this.scrollBoostStartValue !== 0) this.onScrollBoostChanged();
595
+ else {
596
+ this.track.style.transform = "";
597
+ if (this.scrollAnimation.playState !== "running") this.scrollAnimation.play();
598
+ }
572
599
  return;
573
600
  }
574
601
  this.stopAnimationLoop();
575
602
  this.cancelScrollAnimation();
603
+ this.scrollMotionActive = false;
576
604
  this.startCssAnimation();
577
605
  this.track.style.animationPlayState = this.canAnimate() ? "running" : "paused";
578
606
  }
@@ -617,34 +645,39 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
617
645
  }
618
646
  tick = (now) => {
619
647
  this.animationFrameId = null;
620
- if (!this.mounted || this.options.mode !== "scroll" || this.distance <= 0 || this.reducedMotion || !this.canAnimate() || !this.scrollAnimation) return;
621
- if (!this.updateScrollPlaybackRate(now, false)) this.animationFrameId = requestAnimationFrame(this.tick);
648
+ if (!this.mounted || this.options.mode !== "scroll" || this.distance <= 0 || this.reducedMotion || !this.canAnimate() || !this.scrollMotionActive) return;
649
+ if (this.advanceScrollMotion(now)) {
650
+ this.scrollMotionActive = false;
651
+ this.ensureScrollAnimation();
652
+ this.track.style.transform = "";
653
+ this.lastFrameTime = null;
654
+ return;
655
+ }
656
+ this.animationFrameId = requestAnimationFrame(this.tick);
622
657
  };
623
658
  ensureScrollAnimation() {
624
659
  if (this.distance <= 0) {
625
660
  this.cancelScrollAnimation();
626
661
  return;
627
662
  }
628
- const currentSpeed = this.getCurrentSpeed(this.clientWidth);
663
+ const currentSpeed = this.scrollBaseSpeed;
629
664
  const durationMs = currentSpeed > 0 ? this.distance / currentSpeed * 1e3 : 0;
665
+ const reversed = this.currentTimeScale < 0;
630
666
  if (durationMs <= 0) {
631
667
  this.cancelScrollAnimation();
632
668
  return;
633
669
  }
634
- if (this.scrollAnimation && this.scrollAnimationDistance === this.distance && this.scrollAnimationDuration === durationMs) return;
670
+ if (this.scrollAnimation && this.scrollAnimationDistance === this.distance && this.scrollAnimationDuration === durationMs && this.scrollAnimation.effect?.getTiming().direction === (reversed ? "reverse" : "normal")) return;
635
671
  const progress = this.getScrollAnimationProgress();
636
- const hadAnimation = this.scrollAnimation !== null;
637
672
  if (this.scrollAnimation) {
638
673
  this.scrollAnimation.cancel();
639
674
  this.scrollAnimation = null;
640
675
  }
641
- if (!hadAnimation) this.currentTimeScale = this.getDirectionFactor() * this.scrollDirectionFactor;
642
676
  const animation = this.track.animate([{ transform: "translate3d(0px, 0, 0)" }, { transform: `translate3d(${-this.distance}px, 0, 0)` }], {
643
677
  duration: durationMs,
644
678
  iterations: Number.POSITIVE_INFINITY,
645
679
  easing: "linear"
646
680
  });
647
- const reversed = this.currentTimeScale < 0;
648
681
  animation.effect?.updateTiming({ direction: reversed ? "reverse" : "normal" });
649
682
  animation.currentTime = durationMs * (reversed ? 1 - progress : progress);
650
683
  animation.playbackRate = Math.abs(this.currentTimeScale);
@@ -664,38 +697,33 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
664
697
  getScrollAnimationProgress() {
665
698
  const animation = this.scrollAnimation;
666
699
  if (!animation || this.scrollAnimationDuration <= 0) return this.scrollProgress;
700
+ const progress = animation.effect?.getComputedTiming().progress;
701
+ if (progress != null) return progress % 1;
667
702
  const currentTime = animation.currentTime;
668
703
  if (typeof currentTime !== "number") return this.scrollProgress;
669
704
  const fraction = currentTime / this.scrollAnimationDuration % 1;
670
- const progress = fraction < 0 ? fraction + 1 : fraction;
671
- return animation.effect?.getTiming().direction === "reverse" ? (1 - progress) % 1 : progress;
705
+ const normalized = fraction < 0 ? fraction + 1 : fraction;
706
+ return animation.effect?.getTiming().direction === "reverse" ? (1 - normalized) % 1 : normalized;
672
707
  }
673
- updateScrollPlaybackRate(now, immediate) {
674
- if (!this.scrollAnimation) return true;
708
+ advanceScrollMotion(now) {
675
709
  const target = this.getCurrentTimeScale(now);
676
- if (immediate) {
677
- this.currentTimeScale = target;
678
- this.lastFrameTime = now;
679
- } else {
680
- const previousTime = this.lastFrameTime ?? now;
681
- const deltaTime = Math.min((now - previousTime) / 1e3, .064);
682
- this.lastFrameTime = now;
683
- const smoothingFactor = 1 - Math.exp(-deltaTime / SCROLL_TIME_SCALE_SMOOTHING_SECONDS);
684
- this.currentTimeScale += (target - this.currentTimeScale) * smoothingFactor;
685
- }
710
+ const previousTimeScale = this.currentTimeScale;
711
+ const previousTime = this.lastFrameTime ?? now;
712
+ const deltaTime = this.clamp((now - previousTime) / 1e3, 0, .064);
713
+ this.lastFrameTime = now;
714
+ const smoothingFactor = 1 - Math.exp(-deltaTime / SCROLL_TIME_SCALE_SMOOTHING_SECONDS);
715
+ this.currentTimeScale += (target - this.currentTimeScale) * smoothingFactor;
686
716
  const settled = this.scrollBoostStartValue === 0 && Math.abs(target - this.currentTimeScale) < .001;
687
717
  if (settled) this.currentTimeScale = target;
688
- const reversed = this.currentTimeScale < 0;
689
- const effect = this.scrollAnimation.effect;
690
- if (effect && effect.getTiming().direction === "reverse" !== reversed) {
691
- const progress = this.getScrollAnimationProgress();
692
- effect.updateTiming({ direction: reversed ? "reverse" : "normal" });
693
- this.scrollAnimation.currentTime = this.scrollAnimationDuration * (reversed ? 1 - progress : progress);
694
- }
695
- const playbackRate = Math.abs(this.currentTimeScale);
696
- if (this.scrollAnimation.playbackRate !== playbackRate) this.scrollAnimation.updatePlaybackRate(playbackRate);
718
+ const averageTimeScale = (previousTimeScale + this.currentTimeScale) / 2;
719
+ const progress = this.scrollProgress + this.scrollBaseSpeed * averageTimeScale * deltaTime / this.distance;
720
+ this.scrollProgress = (progress % 1 + 1) % 1;
721
+ this.renderScrollProgress();
697
722
  return settled;
698
723
  }
724
+ renderScrollProgress() {
725
+ this.track.style.transform = `translate3d(${-this.scrollProgress * this.distance}px, 0, 0)`;
726
+ }
699
727
  getCurrentTimeScale(now) {
700
728
  const directionFactor = this.getDirectionFactor();
701
729
  if (this.options.mode !== "scroll") return directionFactor;