marquee-content 7.0.0-dev.3 → 7.0.0-dev.5
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 +3 -34
- package/dist/index.cjs +129 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +129 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,8 +66,7 @@ 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`.
|
|
70
|
-
| `responsive-speed` / `responsiveSpeed` | `boolean` | `false` | Automatically reduces movement speed in narrow containers when enabled. |
|
|
69
|
+
| `speed` | `number` | `90` | Base speed in px/s, clamped to `10`–`500`. Independent of container width. |
|
|
71
70
|
| `mode` | `'auto' \| 'scroll'` | `'auto'` | `'auto'` for constant movement; `'scroll'` for page-scroll response and inertia. |
|
|
72
71
|
| `direction` | `'rtl' \| 'ltr'` | `'rtl'` | Base direction: right to left or left to right. |
|
|
73
72
|
| `pause-on-hover` / `pauseOnHover` | `boolean` | `false` | Pauses movement while the pointer is over the host. Items remain decorative and inert. |
|
|
@@ -85,7 +84,6 @@ marquee?.update({
|
|
|
85
84
|
mode: 'scroll',
|
|
86
85
|
direction: 'ltr',
|
|
87
86
|
speed: 120,
|
|
88
|
-
responsiveSpeed: false,
|
|
89
87
|
pauseOnHover: true,
|
|
90
88
|
});
|
|
91
89
|
|
|
@@ -110,38 +108,9 @@ On devices with a fine pointer, `scroll` listens to the window's vertical scroll
|
|
|
110
108
|
|
|
111
109
|
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
110
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
## Responsive speed
|
|
116
|
-
|
|
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.
|
|
118
|
-
|
|
119
|
-
Enable responsive speed to automatically slow movement in narrow containers:
|
|
120
|
-
|
|
121
|
-
```html
|
|
122
|
-
<marquee-content speed="90" responsive-speed>
|
|
123
|
-
<span>Slower movement in narrow containers</span>
|
|
124
|
-
</marquee-content>
|
|
125
|
-
```
|
|
111
|
+
Elastic rebound after scrolling beyond a page edge does not reverse the marquee. A deliberate reverse gesture can change direction during rebound. Moving a finger or scrolling a nested container without page movement does not change the marquee direction.
|
|
126
112
|
|
|
127
|
-
|
|
128
|
-
const marquee = document.querySelector('marquee-content');
|
|
129
|
-
|
|
130
|
-
if (marquee) {
|
|
131
|
-
marquee.responsiveSpeed = true;
|
|
132
|
-
// Equivalent: marquee.update({ responsiveSpeed: true });
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
When enabled, scaling uses the **component's width**, in CSS pixels:
|
|
137
|
-
|
|
138
|
-
```text
|
|
139
|
-
effective base speed = speed × clamp(component width / 1280, 0.55, 1)
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
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.
|
|
143
|
-
|
|
144
|
-
Remove the attribute or set `responsive-speed="false"` to disable scaling again.
|
|
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.
|
|
145
114
|
|
|
146
115
|
## Vue 3 with Vite
|
|
147
116
|
|
package/dist/index.cjs
CHANGED
|
@@ -45,10 +45,6 @@ const DEFAULT_OPTIONS = {
|
|
|
45
45
|
speed: 90,
|
|
46
46
|
mode: "auto",
|
|
47
47
|
direction: "rtl",
|
|
48
|
-
responsiveSpeed: false,
|
|
49
|
-
referenceWidth: 1280,
|
|
50
|
-
minSpeedFactor: .55,
|
|
51
|
-
maxSpeedFactor: 1,
|
|
52
48
|
pauseOnHover: false,
|
|
53
49
|
pauseWhenOutOfView: true,
|
|
54
50
|
recalculateAfterFontsReady: true,
|
|
@@ -61,20 +57,19 @@ const OBSERVED_ATTRIBUTES = [
|
|
|
61
57
|
"speed",
|
|
62
58
|
"mode",
|
|
63
59
|
"direction",
|
|
64
|
-
"pause-on-hover"
|
|
65
|
-
"responsive-speed"
|
|
60
|
+
"pause-on-hover"
|
|
66
61
|
];
|
|
67
62
|
const OPTION_ATTRIBUTE_MAP = {
|
|
68
63
|
speed: "speed",
|
|
69
64
|
mode: "mode",
|
|
70
65
|
direction: "direction",
|
|
71
|
-
pauseOnHover: "pause-on-hover"
|
|
72
|
-
responsiveSpeed: "responsive-speed"
|
|
66
|
+
pauseOnHover: "pause-on-hover"
|
|
73
67
|
};
|
|
74
68
|
const MARQUEE_CONTENT_CSS_PROPS = ["--marquee-content-distance", "--marquee-content-duration"];
|
|
75
69
|
const SCROLL_TIME_SCALE_SMOOTHING_SECONDS = .12;
|
|
76
70
|
const TOUCH_INPUT_QUERY = "(hover: none) and (pointer: coarse)";
|
|
77
71
|
const TOUCH_SCROLL_EDGE_THRESHOLD = 1;
|
|
72
|
+
const TOUCH_SCROLL_IDLE_DELAY = 250;
|
|
78
73
|
const HTMLElementBase = globalThis.HTMLElement ?? class {};
|
|
79
74
|
const MARQUEE_CONTENT_RUNTIME_CSS = `
|
|
80
75
|
@keyframes marquee-content-auto {
|
|
@@ -154,6 +149,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
154
149
|
reducedMotion = false;
|
|
155
150
|
touchInput = false;
|
|
156
151
|
isListeningToScroll = false;
|
|
152
|
+
isListeningToTouch = false;
|
|
157
153
|
distance = 0;
|
|
158
154
|
containerWidth = 0;
|
|
159
155
|
group = null;
|
|
@@ -170,6 +166,11 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
170
166
|
scrollBoostStartedAt = 0;
|
|
171
167
|
lastScrollY = 0;
|
|
172
168
|
lastScrollTime = 0;
|
|
169
|
+
lastTouchY = null;
|
|
170
|
+
touchScrollDirection = 0;
|
|
171
|
+
touchOverscrollDirection = 0;
|
|
172
|
+
pendingTouchScrollDirection = 0;
|
|
173
|
+
touchScrollResetTimer = null;
|
|
173
174
|
constructor() {
|
|
174
175
|
if (typeof HTMLElement === "undefined") throw new Error("[MarqueeContent] Create elements in a browser, after client initialization.");
|
|
175
176
|
super();
|
|
@@ -260,12 +261,6 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
260
261
|
set pauseOnHover(value) {
|
|
261
262
|
this.setNullableAttribute("pause-on-hover", value);
|
|
262
263
|
}
|
|
263
|
-
get responsiveSpeed() {
|
|
264
|
-
return this.options.responsiveSpeed;
|
|
265
|
-
}
|
|
266
|
-
set responsiveSpeed(value) {
|
|
267
|
-
this.setNullableAttribute("responsive-speed", value);
|
|
268
|
-
}
|
|
269
264
|
update(options = {}) {
|
|
270
265
|
Object.entries(options).forEach(([key, value]) => {
|
|
271
266
|
const attributeName = OPTION_ATTRIBUTE_MAP[key];
|
|
@@ -372,20 +367,33 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
372
367
|
handleScroll = () => {
|
|
373
368
|
if (this.options.mode !== "scroll") return;
|
|
374
369
|
const now = performance.now();
|
|
375
|
-
const
|
|
370
|
+
const rawScrollY = window.scrollY || window.pageYOffset || 0;
|
|
371
|
+
const currentScrollY = this.getScrollY(rawScrollY);
|
|
376
372
|
const deltaY = currentScrollY - this.lastScrollY;
|
|
377
373
|
const deltaTime = Math.max((now - this.lastScrollTime) / 1e3, .016);
|
|
378
374
|
this.lastScrollY = currentScrollY;
|
|
379
375
|
this.lastScrollTime = now;
|
|
376
|
+
if (this.touchInput) {
|
|
377
|
+
const overscroll = rawScrollY - currentScrollY;
|
|
378
|
+
if (Math.abs(overscroll) > TOUCH_SCROLL_EDGE_THRESHOLD && (this.lastTouchY !== null || this.touchScrollDirection !== 0)) {
|
|
379
|
+
const direction = overscroll > 0 ? 1 : -1;
|
|
380
|
+
if (this.touchScrollDirection !== -direction) this.touchOverscrollDirection = direction;
|
|
381
|
+
}
|
|
382
|
+
this.scheduleTouchScrollReset();
|
|
383
|
+
}
|
|
380
384
|
if (Math.abs(deltaY) < .5) return;
|
|
381
385
|
const velocity = deltaY / deltaTime;
|
|
382
386
|
const direction = velocity >= 0 ? 1 : -1;
|
|
383
|
-
|
|
384
|
-
|
|
387
|
+
if (this.touchInput && this.touchOverscrollDirection !== 0 && direction !== this.touchOverscrollDirection) {
|
|
388
|
+
this.pendingTouchScrollDirection = direction;
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
this.pendingTouchScrollDirection = 0;
|
|
385
392
|
if (this.touchInput) {
|
|
386
|
-
|
|
393
|
+
this.applyTouchScrollDirection(direction);
|
|
387
394
|
return;
|
|
388
395
|
}
|
|
396
|
+
this.scrollDirectionFactor = direction;
|
|
389
397
|
const extraSpeed = this.clamp(velocity / this.options.scrollVelocityFactor, -this.options.scrollMaxExtraSpeed, this.options.scrollMaxExtraSpeed);
|
|
390
398
|
if (Math.abs(extraSpeed) >= this.options.scrollMinExtraSpeed) {
|
|
391
399
|
this.scrollBoostStartValue = extraSpeed;
|
|
@@ -393,6 +401,66 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
393
401
|
} else this.scrollBoostStartValue = 0;
|
|
394
402
|
this.onScrollBoostChanged();
|
|
395
403
|
};
|
|
404
|
+
applyTouchScrollDirection(direction) {
|
|
405
|
+
if (direction !== this.scrollDirectionFactor) {
|
|
406
|
+
this.scrollDirectionFactor = direction;
|
|
407
|
+
this.applyOptions();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
handleTouchStart = (event) => {
|
|
411
|
+
const overscrollDirection = this.touchOverscrollDirection;
|
|
412
|
+
this.resetTouchScroll();
|
|
413
|
+
const touch = event.touches.length === 1 ? event.touches[0] : null;
|
|
414
|
+
if (touch) {
|
|
415
|
+
this.touchOverscrollDirection = overscrollDirection;
|
|
416
|
+
this.lastTouchY = touch.clientY;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
handleTouchMove = (event) => {
|
|
420
|
+
if (event.touches.length !== 1) {
|
|
421
|
+
this.resetTouchScroll();
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const touch = event.touches[0];
|
|
425
|
+
if (!touch || this.lastTouchY === null) return;
|
|
426
|
+
const deltaY = this.lastTouchY - touch.clientY;
|
|
427
|
+
if (Math.abs(deltaY) < .5) return;
|
|
428
|
+
this.lastTouchY = touch.clientY;
|
|
429
|
+
this.touchScrollDirection = deltaY > 0 ? 1 : -1;
|
|
430
|
+
if (this.touchScrollDirection === -this.touchOverscrollDirection) {
|
|
431
|
+
this.touchOverscrollDirection = 0;
|
|
432
|
+
if (this.pendingTouchScrollDirection === this.touchScrollDirection) this.applyTouchScrollDirection(this.touchScrollDirection);
|
|
433
|
+
this.pendingTouchScrollDirection = 0;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
handleTouchEnd = (event) => {
|
|
437
|
+
if (event.touches.length > 0) {
|
|
438
|
+
this.resetTouchScroll();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
this.lastTouchY = null;
|
|
442
|
+
this.scheduleTouchScrollReset();
|
|
443
|
+
};
|
|
444
|
+
handleScrollEnd = () => {
|
|
445
|
+
if (this.lastTouchY === null) this.resetTouchScroll();
|
|
446
|
+
};
|
|
447
|
+
scheduleTouchScrollReset() {
|
|
448
|
+
if (this.touchScrollResetTimer !== null) {
|
|
449
|
+
window.clearTimeout(this.touchScrollResetTimer);
|
|
450
|
+
this.touchScrollResetTimer = null;
|
|
451
|
+
}
|
|
452
|
+
if (this.lastTouchY === null && (this.touchScrollDirection !== 0 || this.touchOverscrollDirection !== 0)) this.touchScrollResetTimer = window.setTimeout(this.resetTouchScroll, TOUCH_SCROLL_IDLE_DELAY);
|
|
453
|
+
}
|
|
454
|
+
resetTouchScroll = () => {
|
|
455
|
+
if (this.touchScrollResetTimer !== null) {
|
|
456
|
+
window.clearTimeout(this.touchScrollResetTimer);
|
|
457
|
+
this.touchScrollResetTimer = null;
|
|
458
|
+
}
|
|
459
|
+
this.lastTouchY = null;
|
|
460
|
+
this.touchScrollDirection = 0;
|
|
461
|
+
this.touchOverscrollDirection = 0;
|
|
462
|
+
this.pendingTouchScrollDirection = 0;
|
|
463
|
+
};
|
|
396
464
|
onScrollBoostChanged() {
|
|
397
465
|
if (!this.mounted || this.getEffectiveMode() !== "scroll" || this.reducedMotion) return;
|
|
398
466
|
if (!this.canAnimate() || this.distance <= 0) return;
|
|
@@ -404,13 +472,44 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
404
472
|
this.startAnimationLoop();
|
|
405
473
|
}
|
|
406
474
|
updateScrollListener(shouldListen = this.mounted && this.options.mode === "scroll") {
|
|
407
|
-
if (shouldListen
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
475
|
+
if (shouldListen !== this.isListeningToScroll) {
|
|
476
|
+
if (shouldListen) {
|
|
477
|
+
this.lastScrollY = this.getScrollY();
|
|
478
|
+
this.lastScrollTime = performance.now();
|
|
479
|
+
window.addEventListener("scroll", this.handleScroll, { passive: true });
|
|
480
|
+
} else window.removeEventListener("scroll", this.handleScroll);
|
|
481
|
+
this.isListeningToScroll = shouldListen;
|
|
482
|
+
}
|
|
483
|
+
const shouldListenToTouch = shouldListen && this.touchInput;
|
|
484
|
+
if (shouldListenToTouch !== this.isListeningToTouch) {
|
|
485
|
+
if (shouldListenToTouch) {
|
|
486
|
+
window.addEventListener("touchstart", this.handleTouchStart, {
|
|
487
|
+
passive: true,
|
|
488
|
+
capture: true
|
|
489
|
+
});
|
|
490
|
+
window.addEventListener("touchmove", this.handleTouchMove, {
|
|
491
|
+
passive: true,
|
|
492
|
+
capture: true
|
|
493
|
+
});
|
|
494
|
+
window.addEventListener("touchend", this.handleTouchEnd, {
|
|
495
|
+
passive: true,
|
|
496
|
+
capture: true
|
|
497
|
+
});
|
|
498
|
+
window.addEventListener("touchcancel", this.handleTouchEnd, {
|
|
499
|
+
passive: true,
|
|
500
|
+
capture: true
|
|
501
|
+
});
|
|
502
|
+
window.addEventListener("scrollend", this.handleScrollEnd);
|
|
503
|
+
} else {
|
|
504
|
+
window.removeEventListener("touchstart", this.handleTouchStart, true);
|
|
505
|
+
window.removeEventListener("touchmove", this.handleTouchMove, true);
|
|
506
|
+
window.removeEventListener("touchend", this.handleTouchEnd, true);
|
|
507
|
+
window.removeEventListener("touchcancel", this.handleTouchEnd, true);
|
|
508
|
+
window.removeEventListener("scrollend", this.handleScrollEnd);
|
|
509
|
+
this.resetTouchScroll();
|
|
510
|
+
}
|
|
511
|
+
this.isListeningToTouch = shouldListenToTouch;
|
|
512
|
+
}
|
|
414
513
|
}
|
|
415
514
|
scheduleRebuild = () => {
|
|
416
515
|
if (!this.mounted) return;
|
|
@@ -428,7 +527,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
428
527
|
applyOptions() {
|
|
429
528
|
if (!this.mounted) return;
|
|
430
529
|
const progress = this.scrollAnimation ? this.getScrollAnimationProgress() : this.getAutoAnimation()?.effect?.getComputedTiming().progress ?? this.scrollProgress;
|
|
431
|
-
this.scrollBaseSpeed = this.
|
|
530
|
+
this.scrollBaseSpeed = this.options.speed;
|
|
432
531
|
const duration = this.distance / this.scrollBaseSpeed;
|
|
433
532
|
this.setAttribute("data-marquee-content-mode", this.options.mode);
|
|
434
533
|
this.toggleAttribute("data-marquee-content-pause-on-hover", this.options.pauseOnHover);
|
|
@@ -596,6 +695,8 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
596
695
|
handleTouchInputChange = (event) => {
|
|
597
696
|
if (!this.mounted || event.matches === this.touchInput) return;
|
|
598
697
|
this.touchInput = event.matches;
|
|
698
|
+
this.lastScrollY = this.getScrollY();
|
|
699
|
+
this.lastScrollTime = performance.now();
|
|
599
700
|
this.stopAnimationLoop();
|
|
600
701
|
this.cancelScrollAnimation();
|
|
601
702
|
this.scrollMotionActive = false;
|
|
@@ -788,19 +889,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
788
889
|
const easedProgress = this.easeOutCubic(progress);
|
|
789
890
|
return this.scrollBoostStartValue * (1 - easedProgress);
|
|
790
891
|
}
|
|
791
|
-
getCurrentSpeed(containerWidth) {
|
|
792
|
-
if (!this.options.responsiveSpeed) return this.options.speed;
|
|
793
|
-
const factor = this.clamp(containerWidth / this.options.referenceWidth, this.options.minSpeedFactor, this.options.maxSpeedFactor);
|
|
794
|
-
return this.options.speed * factor;
|
|
795
|
-
}
|
|
796
892
|
resolveOptions() {
|
|
797
893
|
return {
|
|
798
894
|
...DEFAULT_OPTIONS,
|
|
799
895
|
speed: this.num("speed", DEFAULT_OPTIONS.speed, 10, 500),
|
|
800
896
|
mode: this.parseMode(this.getAttribute("mode"), DEFAULT_OPTIONS.mode),
|
|
801
897
|
direction: this.parseDirection(this.getAttribute("direction"), DEFAULT_OPTIONS.direction),
|
|
802
|
-
pauseOnHover: this.parseBoolean(this.getAttribute("pause-on-hover"), DEFAULT_OPTIONS.pauseOnHover)
|
|
803
|
-
responsiveSpeed: this.parseBoolean(this.getAttribute("responsive-speed"), DEFAULT_OPTIONS.responsiveSpeed)
|
|
898
|
+
pauseOnHover: this.parseBoolean(this.getAttribute("pause-on-hover"), DEFAULT_OPTIONS.pauseOnHover)
|
|
804
899
|
};
|
|
805
900
|
}
|
|
806
901
|
num(attributeName, fallback, min, max) {
|
|
@@ -844,8 +939,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
844
939
|
}
|
|
845
940
|
this.setAttribute(name, String(value));
|
|
846
941
|
}
|
|
847
|
-
getScrollY() {
|
|
848
|
-
const scrollY = window.scrollY || window.pageYOffset || 0;
|
|
942
|
+
getScrollY(scrollY = window.scrollY || window.pageYOffset || 0) {
|
|
849
943
|
if (!this.touchInput) return scrollY;
|
|
850
944
|
const scroller = document.scrollingElement ?? document.documentElement;
|
|
851
945
|
const maxScroll = Math.max(0, scroller.scrollHeight - scroller.clientHeight);
|