marquee-content 7.0.0-dev.2 → 7.0.0-dev.4
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 +102 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +102 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -17,7 +17,6 @@ interface MarqueeContentOptions {
|
|
|
17
17
|
mode?: MarqueeContentMode | null;
|
|
18
18
|
direction?: MarqueeContentDirection | null;
|
|
19
19
|
pauseOnHover?: boolean | string | null;
|
|
20
|
-
responsiveSpeed?: boolean | string | null;
|
|
21
20
|
}
|
|
22
21
|
interface DefineMarqueeContentOptions {
|
|
23
22
|
stylesheet?: MarqueeContentStyleInput;
|
|
@@ -59,6 +58,7 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
59
58
|
private reducedMotion;
|
|
60
59
|
private touchInput;
|
|
61
60
|
private isListeningToScroll;
|
|
61
|
+
private isListeningToTouch;
|
|
62
62
|
private distance;
|
|
63
63
|
private containerWidth;
|
|
64
64
|
private group;
|
|
@@ -75,6 +75,9 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
75
75
|
private scrollBoostStartedAt;
|
|
76
76
|
private lastScrollY;
|
|
77
77
|
private lastScrollTime;
|
|
78
|
+
private lastTouchY;
|
|
79
|
+
private touchScrollDirection;
|
|
80
|
+
private touchScrollResetTimer;
|
|
78
81
|
constructor();
|
|
79
82
|
connectedCallback(): void;
|
|
80
83
|
disconnectedCallback(): void;
|
|
@@ -87,8 +90,6 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
87
90
|
set direction(value: MarqueeContentDirection | null | undefined);
|
|
88
91
|
get pauseOnHover(): boolean;
|
|
89
92
|
set pauseOnHover(value: boolean | string | null | undefined);
|
|
90
|
-
get responsiveSpeed(): boolean;
|
|
91
|
-
set responsiveSpeed(value: boolean | string | null | undefined);
|
|
92
93
|
update(options?: MarqueeContentOptions): void;
|
|
93
94
|
refresh(): void;
|
|
94
95
|
private applyAllStyles;
|
|
@@ -103,6 +104,12 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
103
104
|
private handleIntersectionChange;
|
|
104
105
|
private handleReducedMotionChange;
|
|
105
106
|
private handleScroll;
|
|
107
|
+
private handleTouchStart;
|
|
108
|
+
private handleTouchMove;
|
|
109
|
+
private handleTouchEnd;
|
|
110
|
+
private handleScrollEnd;
|
|
111
|
+
private scheduleTouchScrollReset;
|
|
112
|
+
private resetTouchScroll;
|
|
106
113
|
private onScrollBoostChanged;
|
|
107
114
|
private updateScrollListener;
|
|
108
115
|
private scheduleRebuild;
|
|
@@ -141,7 +148,6 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
141
148
|
private getCurrentTimeScale;
|
|
142
149
|
private getDirectionFactor;
|
|
143
150
|
private getScrollBoost;
|
|
144
|
-
private getCurrentSpeed;
|
|
145
151
|
private resolveOptions;
|
|
146
152
|
private num;
|
|
147
153
|
private parseNumber;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ interface MarqueeContentOptions {
|
|
|
17
17
|
mode?: MarqueeContentMode | null;
|
|
18
18
|
direction?: MarqueeContentDirection | null;
|
|
19
19
|
pauseOnHover?: boolean | string | null;
|
|
20
|
-
responsiveSpeed?: boolean | string | null;
|
|
21
20
|
}
|
|
22
21
|
interface DefineMarqueeContentOptions {
|
|
23
22
|
stylesheet?: MarqueeContentStyleInput;
|
|
@@ -59,6 +58,7 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
59
58
|
private reducedMotion;
|
|
60
59
|
private touchInput;
|
|
61
60
|
private isListeningToScroll;
|
|
61
|
+
private isListeningToTouch;
|
|
62
62
|
private distance;
|
|
63
63
|
private containerWidth;
|
|
64
64
|
private group;
|
|
@@ -75,6 +75,9 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
75
75
|
private scrollBoostStartedAt;
|
|
76
76
|
private lastScrollY;
|
|
77
77
|
private lastScrollTime;
|
|
78
|
+
private lastTouchY;
|
|
79
|
+
private touchScrollDirection;
|
|
80
|
+
private touchScrollResetTimer;
|
|
78
81
|
constructor();
|
|
79
82
|
connectedCallback(): void;
|
|
80
83
|
disconnectedCallback(): void;
|
|
@@ -87,8 +90,6 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
87
90
|
set direction(value: MarqueeContentDirection | null | undefined);
|
|
88
91
|
get pauseOnHover(): boolean;
|
|
89
92
|
set pauseOnHover(value: boolean | string | null | undefined);
|
|
90
|
-
get responsiveSpeed(): boolean;
|
|
91
|
-
set responsiveSpeed(value: boolean | string | null | undefined);
|
|
92
93
|
update(options?: MarqueeContentOptions): void;
|
|
93
94
|
refresh(): void;
|
|
94
95
|
private applyAllStyles;
|
|
@@ -103,6 +104,12 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
103
104
|
private handleIntersectionChange;
|
|
104
105
|
private handleReducedMotionChange;
|
|
105
106
|
private handleScroll;
|
|
107
|
+
private handleTouchStart;
|
|
108
|
+
private handleTouchMove;
|
|
109
|
+
private handleTouchEnd;
|
|
110
|
+
private handleScrollEnd;
|
|
111
|
+
private scheduleTouchScrollReset;
|
|
112
|
+
private resetTouchScroll;
|
|
106
113
|
private onScrollBoostChanged;
|
|
107
114
|
private updateScrollListener;
|
|
108
115
|
private scheduleRebuild;
|
|
@@ -141,7 +148,6 @@ declare class MarqueeContent extends HTMLElementBase {
|
|
|
141
148
|
private getCurrentTimeScale;
|
|
142
149
|
private getDirectionFactor;
|
|
143
150
|
private getScrollBoost;
|
|
144
|
-
private getCurrentSpeed;
|
|
145
151
|
private resolveOptions;
|
|
146
152
|
private num;
|
|
147
153
|
private parseNumber;
|
package/dist/index.js
CHANGED
|
@@ -43,10 +43,6 @@ const DEFAULT_OPTIONS = {
|
|
|
43
43
|
speed: 90,
|
|
44
44
|
mode: "auto",
|
|
45
45
|
direction: "rtl",
|
|
46
|
-
responsiveSpeed: false,
|
|
47
|
-
referenceWidth: 1280,
|
|
48
|
-
minSpeedFactor: .55,
|
|
49
|
-
maxSpeedFactor: 1,
|
|
50
46
|
pauseOnHover: false,
|
|
51
47
|
pauseWhenOutOfView: true,
|
|
52
48
|
recalculateAfterFontsReady: true,
|
|
@@ -59,19 +55,19 @@ const OBSERVED_ATTRIBUTES = [
|
|
|
59
55
|
"speed",
|
|
60
56
|
"mode",
|
|
61
57
|
"direction",
|
|
62
|
-
"pause-on-hover"
|
|
63
|
-
"responsive-speed"
|
|
58
|
+
"pause-on-hover"
|
|
64
59
|
];
|
|
65
60
|
const OPTION_ATTRIBUTE_MAP = {
|
|
66
61
|
speed: "speed",
|
|
67
62
|
mode: "mode",
|
|
68
63
|
direction: "direction",
|
|
69
|
-
pauseOnHover: "pause-on-hover"
|
|
70
|
-
responsiveSpeed: "responsive-speed"
|
|
64
|
+
pauseOnHover: "pause-on-hover"
|
|
71
65
|
};
|
|
72
66
|
const MARQUEE_CONTENT_CSS_PROPS = ["--marquee-content-distance", "--marquee-content-duration"];
|
|
73
67
|
const SCROLL_TIME_SCALE_SMOOTHING_SECONDS = .12;
|
|
74
68
|
const TOUCH_INPUT_QUERY = "(hover: none) and (pointer: coarse)";
|
|
69
|
+
const TOUCH_SCROLL_EDGE_THRESHOLD = 1;
|
|
70
|
+
const TOUCH_SCROLL_IDLE_DELAY = 250;
|
|
75
71
|
const HTMLElementBase = globalThis.HTMLElement ?? class {};
|
|
76
72
|
const MARQUEE_CONTENT_RUNTIME_CSS = `
|
|
77
73
|
@keyframes marquee-content-auto {
|
|
@@ -151,6 +147,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
151
147
|
reducedMotion = false;
|
|
152
148
|
touchInput = false;
|
|
153
149
|
isListeningToScroll = false;
|
|
150
|
+
isListeningToTouch = false;
|
|
154
151
|
distance = 0;
|
|
155
152
|
containerWidth = 0;
|
|
156
153
|
group = null;
|
|
@@ -167,6 +164,9 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
167
164
|
scrollBoostStartedAt = 0;
|
|
168
165
|
lastScrollY = 0;
|
|
169
166
|
lastScrollTime = 0;
|
|
167
|
+
lastTouchY = null;
|
|
168
|
+
touchScrollDirection = 0;
|
|
169
|
+
touchScrollResetTimer = null;
|
|
170
170
|
constructor() {
|
|
171
171
|
if (typeof HTMLElement === "undefined") throw new Error("[MarqueeContent] Create elements in a browser, after client initialization.");
|
|
172
172
|
super();
|
|
@@ -257,12 +257,6 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
257
257
|
set pauseOnHover(value) {
|
|
258
258
|
this.setNullableAttribute("pause-on-hover", value);
|
|
259
259
|
}
|
|
260
|
-
get responsiveSpeed() {
|
|
261
|
-
return this.options.responsiveSpeed;
|
|
262
|
-
}
|
|
263
|
-
set responsiveSpeed(value) {
|
|
264
|
-
this.setNullableAttribute("responsive-speed", value);
|
|
265
|
-
}
|
|
266
260
|
update(options = {}) {
|
|
267
261
|
Object.entries(options).forEach(([key, value]) => {
|
|
268
262
|
const attributeName = OPTION_ATTRIBUTE_MAP[key];
|
|
@@ -374,9 +368,11 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
374
368
|
const deltaTime = Math.max((now - this.lastScrollTime) / 1e3, .016);
|
|
375
369
|
this.lastScrollY = currentScrollY;
|
|
376
370
|
this.lastScrollTime = now;
|
|
371
|
+
if (this.touchInput) this.scheduleTouchScrollReset();
|
|
377
372
|
if (Math.abs(deltaY) < .5) return;
|
|
378
373
|
const velocity = deltaY / deltaTime;
|
|
379
374
|
const direction = velocity >= 0 ? 1 : -1;
|
|
375
|
+
if (this.touchInput && (this.lastTouchY !== null && this.touchScrollDirection === 0 || this.touchScrollDirection !== 0 && direction !== this.touchScrollDirection)) return;
|
|
380
376
|
const directionChanged = direction !== this.scrollDirectionFactor;
|
|
381
377
|
this.scrollDirectionFactor = direction;
|
|
382
378
|
if (this.touchInput) {
|
|
@@ -390,6 +386,49 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
390
386
|
} else this.scrollBoostStartValue = 0;
|
|
391
387
|
this.onScrollBoostChanged();
|
|
392
388
|
};
|
|
389
|
+
handleTouchStart = (event) => {
|
|
390
|
+
this.resetTouchScroll();
|
|
391
|
+
const touch = event.touches.length === 1 ? event.touches[0] : null;
|
|
392
|
+
if (touch) this.lastTouchY = touch.clientY;
|
|
393
|
+
};
|
|
394
|
+
handleTouchMove = (event) => {
|
|
395
|
+
if (event.touches.length !== 1) {
|
|
396
|
+
this.resetTouchScroll();
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const touch = event.touches[0];
|
|
400
|
+
if (!touch || this.lastTouchY === null) return;
|
|
401
|
+
const deltaY = this.lastTouchY - touch.clientY;
|
|
402
|
+
if (Math.abs(deltaY) < .5) return;
|
|
403
|
+
this.lastTouchY = touch.clientY;
|
|
404
|
+
this.touchScrollDirection = deltaY > 0 ? 1 : -1;
|
|
405
|
+
};
|
|
406
|
+
handleTouchEnd = (event) => {
|
|
407
|
+
if (event.touches.length > 0) {
|
|
408
|
+
this.resetTouchScroll();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
this.lastTouchY = null;
|
|
412
|
+
this.scheduleTouchScrollReset();
|
|
413
|
+
};
|
|
414
|
+
handleScrollEnd = () => {
|
|
415
|
+
if (this.lastTouchY === null) this.resetTouchScroll();
|
|
416
|
+
};
|
|
417
|
+
scheduleTouchScrollReset() {
|
|
418
|
+
if (this.touchScrollResetTimer !== null) {
|
|
419
|
+
window.clearTimeout(this.touchScrollResetTimer);
|
|
420
|
+
this.touchScrollResetTimer = null;
|
|
421
|
+
}
|
|
422
|
+
if (this.lastTouchY === null && this.touchScrollDirection !== 0) this.touchScrollResetTimer = window.setTimeout(this.resetTouchScroll, TOUCH_SCROLL_IDLE_DELAY);
|
|
423
|
+
}
|
|
424
|
+
resetTouchScroll = () => {
|
|
425
|
+
if (this.touchScrollResetTimer !== null) {
|
|
426
|
+
window.clearTimeout(this.touchScrollResetTimer);
|
|
427
|
+
this.touchScrollResetTimer = null;
|
|
428
|
+
}
|
|
429
|
+
this.lastTouchY = null;
|
|
430
|
+
this.touchScrollDirection = 0;
|
|
431
|
+
};
|
|
393
432
|
onScrollBoostChanged() {
|
|
394
433
|
if (!this.mounted || this.getEffectiveMode() !== "scroll" || this.reducedMotion) return;
|
|
395
434
|
if (!this.canAnimate() || this.distance <= 0) return;
|
|
@@ -401,13 +440,44 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
401
440
|
this.startAnimationLoop();
|
|
402
441
|
}
|
|
403
442
|
updateScrollListener(shouldListen = this.mounted && this.options.mode === "scroll") {
|
|
404
|
-
if (shouldListen
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
443
|
+
if (shouldListen !== this.isListeningToScroll) {
|
|
444
|
+
if (shouldListen) {
|
|
445
|
+
this.lastScrollY = this.getScrollY();
|
|
446
|
+
this.lastScrollTime = performance.now();
|
|
447
|
+
window.addEventListener("scroll", this.handleScroll, { passive: true });
|
|
448
|
+
} else window.removeEventListener("scroll", this.handleScroll);
|
|
449
|
+
this.isListeningToScroll = shouldListen;
|
|
450
|
+
}
|
|
451
|
+
const shouldListenToTouch = shouldListen && this.touchInput;
|
|
452
|
+
if (shouldListenToTouch !== this.isListeningToTouch) {
|
|
453
|
+
if (shouldListenToTouch) {
|
|
454
|
+
window.addEventListener("touchstart", this.handleTouchStart, {
|
|
455
|
+
passive: true,
|
|
456
|
+
capture: true
|
|
457
|
+
});
|
|
458
|
+
window.addEventListener("touchmove", this.handleTouchMove, {
|
|
459
|
+
passive: true,
|
|
460
|
+
capture: true
|
|
461
|
+
});
|
|
462
|
+
window.addEventListener("touchend", this.handleTouchEnd, {
|
|
463
|
+
passive: true,
|
|
464
|
+
capture: true
|
|
465
|
+
});
|
|
466
|
+
window.addEventListener("touchcancel", this.handleTouchEnd, {
|
|
467
|
+
passive: true,
|
|
468
|
+
capture: true
|
|
469
|
+
});
|
|
470
|
+
window.addEventListener("scrollend", this.handleScrollEnd);
|
|
471
|
+
} else {
|
|
472
|
+
window.removeEventListener("touchstart", this.handleTouchStart, true);
|
|
473
|
+
window.removeEventListener("touchmove", this.handleTouchMove, true);
|
|
474
|
+
window.removeEventListener("touchend", this.handleTouchEnd, true);
|
|
475
|
+
window.removeEventListener("touchcancel", this.handleTouchEnd, true);
|
|
476
|
+
window.removeEventListener("scrollend", this.handleScrollEnd);
|
|
477
|
+
this.resetTouchScroll();
|
|
478
|
+
}
|
|
479
|
+
this.isListeningToTouch = shouldListenToTouch;
|
|
480
|
+
}
|
|
411
481
|
}
|
|
412
482
|
scheduleRebuild = () => {
|
|
413
483
|
if (!this.mounted) return;
|
|
@@ -425,7 +495,7 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
425
495
|
applyOptions() {
|
|
426
496
|
if (!this.mounted) return;
|
|
427
497
|
const progress = this.scrollAnimation ? this.getScrollAnimationProgress() : this.getAutoAnimation()?.effect?.getComputedTiming().progress ?? this.scrollProgress;
|
|
428
|
-
this.scrollBaseSpeed = this.
|
|
498
|
+
this.scrollBaseSpeed = this.options.speed;
|
|
429
499
|
const duration = this.distance / this.scrollBaseSpeed;
|
|
430
500
|
this.setAttribute("data-marquee-content-mode", this.options.mode);
|
|
431
501
|
this.toggleAttribute("data-marquee-content-pause-on-hover", this.options.pauseOnHover);
|
|
@@ -593,6 +663,8 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
593
663
|
handleTouchInputChange = (event) => {
|
|
594
664
|
if (!this.mounted || event.matches === this.touchInput) return;
|
|
595
665
|
this.touchInput = event.matches;
|
|
666
|
+
this.lastScrollY = this.getScrollY();
|
|
667
|
+
this.lastScrollTime = performance.now();
|
|
596
668
|
this.stopAnimationLoop();
|
|
597
669
|
this.cancelScrollAnimation();
|
|
598
670
|
this.scrollMotionActive = false;
|
|
@@ -785,19 +857,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
785
857
|
const easedProgress = this.easeOutCubic(progress);
|
|
786
858
|
return this.scrollBoostStartValue * (1 - easedProgress);
|
|
787
859
|
}
|
|
788
|
-
getCurrentSpeed(containerWidth) {
|
|
789
|
-
if (!this.options.responsiveSpeed) return this.options.speed;
|
|
790
|
-
const factor = this.clamp(containerWidth / this.options.referenceWidth, this.options.minSpeedFactor, this.options.maxSpeedFactor);
|
|
791
|
-
return this.options.speed * factor;
|
|
792
|
-
}
|
|
793
860
|
resolveOptions() {
|
|
794
861
|
return {
|
|
795
862
|
...DEFAULT_OPTIONS,
|
|
796
863
|
speed: this.num("speed", DEFAULT_OPTIONS.speed, 10, 500),
|
|
797
864
|
mode: this.parseMode(this.getAttribute("mode"), DEFAULT_OPTIONS.mode),
|
|
798
865
|
direction: this.parseDirection(this.getAttribute("direction"), DEFAULT_OPTIONS.direction),
|
|
799
|
-
pauseOnHover: this.parseBoolean(this.getAttribute("pause-on-hover"), DEFAULT_OPTIONS.pauseOnHover)
|
|
800
|
-
responsiveSpeed: this.parseBoolean(this.getAttribute("responsive-speed"), DEFAULT_OPTIONS.responsiveSpeed)
|
|
866
|
+
pauseOnHover: this.parseBoolean(this.getAttribute("pause-on-hover"), DEFAULT_OPTIONS.pauseOnHover)
|
|
801
867
|
};
|
|
802
868
|
}
|
|
803
869
|
num(attributeName, fallback, min, max) {
|
|
@@ -842,7 +908,13 @@ var MarqueeContent = class MarqueeContent extends HTMLElementBase {
|
|
|
842
908
|
this.setAttribute(name, String(value));
|
|
843
909
|
}
|
|
844
910
|
getScrollY() {
|
|
845
|
-
|
|
911
|
+
const scrollY = window.scrollY || window.pageYOffset || 0;
|
|
912
|
+
if (!this.touchInput) return scrollY;
|
|
913
|
+
const scroller = document.scrollingElement ?? document.documentElement;
|
|
914
|
+
const maxScroll = Math.max(0, scroller.scrollHeight - scroller.clientHeight);
|
|
915
|
+
if (scrollY <= TOUCH_SCROLL_EDGE_THRESHOLD) return 0;
|
|
916
|
+
if (scrollY >= maxScroll - TOUCH_SCROLL_EDGE_THRESHOLD) return maxScroll;
|
|
917
|
+
return scrollY;
|
|
846
918
|
}
|
|
847
919
|
clamp(value, min, max) {
|
|
848
920
|
return Math.min(Math.max(value, min), max);
|