marquee-content 4.2.0 → 4.4.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 +17 -17
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +106 -105
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +106 -105
- package/dist/index.module.js.map +1 -1
- package/package.json +33 -17
- package/src/index.ts +179 -0
- package/tsconfig.json +6 -0
- package/src/index.js +0 -68
- package/src/utils.js +0 -95
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
<br>
|
|
2
1
|
<div align="center">
|
|
2
|
+
<br>
|
|
3
|
+
|
|
4
|
+
<h1>marquee-content</h1>
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
A simple, lightweight library for creating the effect of running horizontal blocks of content, also known as a marquee or ticker. Uses GSAP and Resize Observer for better performance.
|
|
6
|
+
<p><sup>MarqueeContent provides a set of tools for creating dynamic and adaptive ticker animations on web pages using GSAP and ScrollTrigger. It offers seamless integration with media queries, automatic element cloning for continuous scrolling effects, and efficient handling of resize events. Additionally, it supports customizable animation directions and skew effects, ensuring smooth and visually appealing ticker animations across different screen sizes and orientations.</sup></p>
|
|
6
7
|
|
|
7
8
|
[](https://www.npmjs.com/package/marquee-content)
|
|
8
9
|
[](https://github.com/ux-ui-pro/marquee-content)
|
|
@@ -10,14 +11,13 @@ A simple, lightweight library for creating the effect of running horizontal bloc
|
|
|
10
11
|
|
|
11
12
|
<sup>1kB gzipped</sup>
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
<a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a>
|
|
14
15
|
|
|
15
16
|
</div>
|
|
16
|
-
|
|
17
17
|
<br>
|
|
18
18
|
|
|
19
19
|
➤ **Install**
|
|
20
|
-
```
|
|
20
|
+
```console
|
|
21
21
|
yarn add gsap
|
|
22
22
|
yarn add marquee-content
|
|
23
23
|
```
|
|
@@ -42,7 +42,7 @@ const marquee = new MarqueeContent({
|
|
|
42
42
|
|
|
43
43
|
marquee.init();
|
|
44
44
|
```
|
|
45
|
-
or
|
|
45
|
+
<sub>or</sub>
|
|
46
46
|
```javascript
|
|
47
47
|
document.querySelectorAll('.marquee').forEach((element) => {
|
|
48
48
|
const marquee = new MarqueeContent({
|
|
@@ -56,20 +56,20 @@ document.querySelectorAll('.marquee').forEach((element) => {
|
|
|
56
56
|
|
|
57
57
|
➤ **Options**
|
|
58
58
|
|
|
59
|
-
| Option |
|
|
60
|
-
|
|
61
|
-
| `element` | `string
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
|:----------|:-----------------------:|:-----------:|:--------------------------------------------------------------------------------------------|
|
|
61
|
+
| `element` | `string \| HTMLElement` | `.marquee` | The DOM element for the animation. Can be a CSS selector (string) or an HTMLElement object. |
|
|
62
62
|
<br>
|
|
63
63
|
|
|
64
64
|
➤ **Settings**
|
|
65
65
|
|
|
66
|
-
|
|
|
67
|
-
|
|
68
|
-
| `data-mc-
|
|
69
|
-
| `data-mc-direction` | `rtl` | `rtl`
|
|
70
|
-
| `data-mc-skew` | `null` |
|
|
71
|
-
| `data-mc-min` | `null` |
|
|
72
|
-
| `data-mc-max` | `null` |
|
|
66
|
+
| data-* | Default | Description |
|
|
67
|
+
|:--------------------|:-------:|:----------------------------------------------------------------------------------------------------------------------|
|
|
68
|
+
| `data-mc-speed` | `20` | Sets the speed of the marquee animation. Lower values make the animation faster, while higher values make it slower. |
|
|
69
|
+
| `data-mc-direction` | `rtl` | Scroll direction. Options: `rtl` (default), `ltr` (left to right), `auto` (changes direction based on scrolling). |
|
|
70
|
+
| `data-mc-skew` | `null` | Tilts the component along the Y axis. Accepts positive or negative values. |
|
|
71
|
+
| `data-mc-min` | `null` | Minimum width for the animation to play. |
|
|
72
|
+
| `data-mc-max` | `null` | Maximum width for the animation to play. |
|
|
73
73
|
<br>
|
|
74
74
|
|
|
75
75
|
➤ **License**
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface MarqueeContentOptions {
|
|
2
|
+
element?: string | HTMLElement;
|
|
3
|
+
}
|
|
4
|
+
export default class MarqueeContent {
|
|
5
|
+
static gsap: never;
|
|
6
|
+
static ScrollTrigger: never;
|
|
7
|
+
constructor({ element }?: MarqueeContentOptions);
|
|
8
|
+
static registerGSAP(gsap: never, ScrollTrigger: never): void;
|
|
9
|
+
init: () => void;
|
|
10
|
+
destroy: () => void;
|
|
11
|
+
}
|
|
12
|
+
export default MarqueeContent;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA;IACE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAChC;AAED,qBAAM,cAAc;IAalB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC;IAEnB,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC;gBAEhB,EAAE,OAAoB,EAAE,GAAE,qBAA0B;IAYhE,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK;IA4B9C,IAAI,aAET;IAEK,OAAO,aAUZ;CAqGH;AAED,eAAe,cAAc,CAAC","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"interface MarqueeContentOptions {\n element?: string | HTMLElement;\n}\n\nclass MarqueeContent {\n private readonly gsap: never;\n\n private readonly MM: never;\n\n private timeline: never;\n\n private readonly element: HTMLElement | null;\n\n private resizeObserver: ResizeObserver;\n\n private animationFrame: number | null = null;\n\n static gsap: never;\n\n static ScrollTrigger: never;\n\n constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {\n this.gsap = MarqueeContent.gsap ?? (window as never).gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.element = typeof element === 'string' ? document.querySelector(element) : element;\n\n if (!this.element) return;\n\n this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));\n this.resizeObserver.observe(this.element);\n }\n\n static registerGSAP(gsap: never, ScrollTrigger: never) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n private commonInit = () => {\n if (this.element) {\n this.clearTimeline();\n this.cloneElements();\n this.setBreakpoints();\n this.applySkew();\n\n this.timeline = this.createAnimation();\n }\n };\n\n private update = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n this.animationFrame = requestAnimationFrame(() => {\n this.commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n public init = () => {\n this.commonInit();\n };\n\n public destroy = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n if (this.element) {\n this.clearTimeline();\n }\n\n this.resizeObserver?.disconnect();\n };\n\n private static debounce(func: (...args: never[]) => void) {\n let timer: number | null = null;\n\n return (...args: never[]) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n private createAnimation() {\n this.timeline?.kill();\n\n const timeline = this.gsap.timeline({\n scrollTrigger: {\n trigger: this.element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self: never) => {\n if (this.element?.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (this.element?.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.MM.add(this.element?.dataset.mcBreakpoint, () => {\n const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');\n const speed = mcSpeed;\n\n timeline.to(this.element!.children, {\n duration: speed,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n return timeline;\n }\n\n private setBreakpoints() {\n if (this.element!.dataset.mcMax) {\n this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;\n } else if (this.element!.dataset.mcMin) {\n this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;\n } else {\n this.element!.dataset.mcBreakpoint = '';\n }\n }\n\n private clearTimeline() {\n this.timeline?.kill();\n this.timeline = null;\n this.gsap.set(this.element!.children, { clearProps: 'all' });\n }\n\n private cloneElements() {\n const removingClones = () => {\n while (this.element!.childElementCount > 1) {\n this.element!.removeChild(this.element!.lastChild as ChildNode);\n }\n };\n\n removingClones();\n\n this.MM.add(this.element!.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);\n\n if (this.element!.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.element!.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n private applySkew() {\n if (!this.element?.dataset.mcSkew) return;\n\n const { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -9,125 +9,126 @@ function $parcel$export(e, n, v, s) {
|
|
|
9
9
|
|
|
10
10
|
$parcel$defineInteropFlag(module.exports);
|
|
11
11
|
|
|
12
|
-
$parcel$export(module.exports, "default", ()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const $4559ecf940edc78d$export$ecad260a8a5fef4f = function(element, gsap, MM, timeline, update) {
|
|
21
|
-
timeline?.kill();
|
|
22
|
-
timeline = gsap.timeline({
|
|
23
|
-
scrollTrigger: {
|
|
24
|
-
trigger: element,
|
|
25
|
-
start: "top bottom",
|
|
26
|
-
end: "bottom top",
|
|
27
|
-
toggleActions: "resume pause resume pause",
|
|
28
|
-
onUpdate: (self)=>{
|
|
29
|
-
if (element.dataset.mcDirection === "ltr") timeline.timeScale(-1);
|
|
30
|
-
else if (element.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
35
|
-
timeline.to(element.children, {
|
|
36
|
-
duration: element.dataset.mcDuration ?? 20,
|
|
37
|
-
x: "-100%",
|
|
38
|
-
repeat: -1,
|
|
39
|
-
ease: "none"
|
|
40
|
-
});
|
|
41
|
-
timeline.totalProgress(0.5);
|
|
42
|
-
return ()=>timeline?.kill();
|
|
43
|
-
});
|
|
44
|
-
update.timeline = timeline;
|
|
45
|
-
return timeline;
|
|
46
|
-
};
|
|
47
|
-
const $4559ecf940edc78d$export$d07517a676ce386f = function(element) {
|
|
48
|
-
element.dataset.mcBreakpoint = element.dataset.mcMax ? `(max-width: ${element.dataset.mcMax - 0.02}px)` : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : "";
|
|
49
|
-
};
|
|
50
|
-
const $4559ecf940edc78d$export$6a732ac1b1fdc86b = function(timeline, element, gsap) {
|
|
51
|
-
timeline?.kill();
|
|
52
|
-
timeline = null;
|
|
53
|
-
gsap.set(element.children, {
|
|
54
|
-
clearProps: "all"
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
const $4559ecf940edc78d$export$7c4d14cd3c92bf0b = function(element, gsap, MM) {
|
|
58
|
-
const removingClones = ()=>{
|
|
59
|
-
while(element.childElementCount > 1)element.removeChild(element.lastChild);
|
|
60
|
-
};
|
|
61
|
-
removingClones();
|
|
62
|
-
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
63
|
-
const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
|
|
64
|
-
if (element.childElementCount < requiredQuantity) {
|
|
65
|
-
const fragment = document.createDocumentFragment();
|
|
66
|
-
const clones = Array.from({
|
|
67
|
-
length: requiredQuantity - 1
|
|
68
|
-
}, ()=>element.firstElementChild.cloneNode(true));
|
|
69
|
-
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
70
|
-
element.appendChild(fragment);
|
|
71
|
-
}
|
|
72
|
-
return removingClones;
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
const $4559ecf940edc78d$export$3484d11c6bb42ecc = function(element) {
|
|
76
|
-
if (!element.dataset.mcSkew) return;
|
|
77
|
-
const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
|
|
78
|
-
const { style: style } = element;
|
|
79
|
-
style.transformOrigin = "center center";
|
|
80
|
-
style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
|
|
81
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
class $4fa36e821943b400$var$MarqueeContent {
|
|
86
|
-
#gsap;
|
|
87
|
-
#MM;
|
|
88
|
-
#timeline;
|
|
89
|
-
#element;
|
|
90
|
-
#resizeObserver;
|
|
91
|
-
#animationFrame;
|
|
12
|
+
$parcel$export(module.exports, "default", function () { return $a196c1ed25598f0e$export$2e2bcd8739ae039; });
|
|
13
|
+
class $a196c1ed25598f0e$var$MarqueeContent {
|
|
14
|
+
gsap;
|
|
15
|
+
MM;
|
|
16
|
+
timeline;
|
|
17
|
+
element;
|
|
18
|
+
resizeObserver;
|
|
19
|
+
animationFrame = null;
|
|
92
20
|
static gsap;
|
|
93
21
|
static ScrollTrigger;
|
|
94
22
|
constructor({ element: element = ".marquee" } = {}){
|
|
95
|
-
this
|
|
96
|
-
this
|
|
97
|
-
this
|
|
98
|
-
this
|
|
99
|
-
if (!this
|
|
100
|
-
this
|
|
101
|
-
this
|
|
23
|
+
this.gsap = $a196c1ed25598f0e$var$MarqueeContent.gsap ?? window.gsap;
|
|
24
|
+
this.MM = this.gsap.matchMedia();
|
|
25
|
+
this.timeline = null;
|
|
26
|
+
this.element = typeof element === "string" ? document.querySelector(element) : element;
|
|
27
|
+
if (!this.element) return;
|
|
28
|
+
this.resizeObserver = new ResizeObserver($a196c1ed25598f0e$var$MarqueeContent.debounce(this.update));
|
|
29
|
+
this.resizeObserver.observe(this.element);
|
|
102
30
|
}
|
|
103
31
|
static registerGSAP(gsap, ScrollTrigger) {
|
|
104
|
-
$
|
|
105
|
-
$
|
|
32
|
+
$a196c1ed25598f0e$var$MarqueeContent.gsap = gsap;
|
|
33
|
+
$a196c1ed25598f0e$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
|
|
106
34
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
35
|
+
commonInit = ()=>{
|
|
36
|
+
if (this.element) {
|
|
37
|
+
this.clearTimeline();
|
|
38
|
+
this.cloneElements();
|
|
39
|
+
this.setBreakpoints();
|
|
40
|
+
this.applySkew();
|
|
41
|
+
this.timeline = this.createAnimation();
|
|
42
|
+
}
|
|
113
43
|
};
|
|
114
|
-
|
|
115
|
-
cancelAnimationFrame(this
|
|
116
|
-
this
|
|
117
|
-
this
|
|
118
|
-
$
|
|
44
|
+
update = ()=>{
|
|
45
|
+
if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
|
|
46
|
+
this.animationFrame = requestAnimationFrame(()=>{
|
|
47
|
+
this.commonInit();
|
|
48
|
+
$a196c1ed25598f0e$var$MarqueeContent.ScrollTrigger.refresh();
|
|
119
49
|
});
|
|
120
50
|
};
|
|
121
51
|
init = ()=>{
|
|
122
|
-
this
|
|
52
|
+
this.commonInit();
|
|
123
53
|
};
|
|
124
54
|
destroy = ()=>{
|
|
125
|
-
cancelAnimationFrame(this
|
|
126
|
-
|
|
127
|
-
this
|
|
55
|
+
if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
|
|
56
|
+
if (this.element) this.clearTimeline();
|
|
57
|
+
this.resizeObserver?.disconnect();
|
|
128
58
|
};
|
|
59
|
+
static debounce(func) {
|
|
60
|
+
let timer = null;
|
|
61
|
+
return (...args)=>{
|
|
62
|
+
if (timer !== null) cancelAnimationFrame(timer);
|
|
63
|
+
timer = requestAnimationFrame(()=>func(...args));
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
createAnimation() {
|
|
67
|
+
this.timeline?.kill();
|
|
68
|
+
const timeline = this.gsap.timeline({
|
|
69
|
+
scrollTrigger: {
|
|
70
|
+
trigger: this.element,
|
|
71
|
+
start: "top bottom",
|
|
72
|
+
end: "bottom top",
|
|
73
|
+
toggleActions: "resume pause resume pause",
|
|
74
|
+
onUpdate: (self)=>{
|
|
75
|
+
if (this.element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
|
|
76
|
+
else if (this.element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
this.MM.add(this.element?.dataset.mcBreakpoint, ()=>{
|
|
81
|
+
const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || "20");
|
|
82
|
+
const speed = mcSpeed;
|
|
83
|
+
timeline.to(this.element.children, {
|
|
84
|
+
duration: speed,
|
|
85
|
+
x: "-100%",
|
|
86
|
+
repeat: -1,
|
|
87
|
+
ease: "none"
|
|
88
|
+
});
|
|
89
|
+
timeline.totalProgress(0.5);
|
|
90
|
+
return ()=>timeline?.kill();
|
|
91
|
+
});
|
|
92
|
+
return timeline;
|
|
93
|
+
}
|
|
94
|
+
setBreakpoints() {
|
|
95
|
+
if (this.element.dataset.mcMax) this.element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element.dataset.mcMax) - 0.02}px)`;
|
|
96
|
+
else if (this.element.dataset.mcMin) this.element.dataset.mcBreakpoint = `(min-width: ${this.element.dataset.mcMin}px)`;
|
|
97
|
+
else this.element.dataset.mcBreakpoint = "";
|
|
98
|
+
}
|
|
99
|
+
clearTimeline() {
|
|
100
|
+
this.timeline?.kill();
|
|
101
|
+
this.timeline = null;
|
|
102
|
+
this.gsap.set(this.element.children, {
|
|
103
|
+
clearProps: "all"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
cloneElements() {
|
|
107
|
+
const removingClones = ()=>{
|
|
108
|
+
while(this.element.childElementCount > 1)this.element.removeChild(this.element.lastChild);
|
|
109
|
+
};
|
|
110
|
+
removingClones();
|
|
111
|
+
this.MM.add(this.element.dataset.mcBreakpoint, ()=>{
|
|
112
|
+
const requiredQuantity = Math.ceil(this.element.scrollWidth / this.element.firstElementChild.clientWidth + 2);
|
|
113
|
+
if (this.element.childElementCount < requiredQuantity) {
|
|
114
|
+
const fragment = document.createDocumentFragment();
|
|
115
|
+
const clones = Array.from({
|
|
116
|
+
length: requiredQuantity - 1
|
|
117
|
+
}, ()=>this.element.firstElementChild.cloneNode(true));
|
|
118
|
+
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
119
|
+
this.element.appendChild(fragment);
|
|
120
|
+
}
|
|
121
|
+
return removingClones;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
applySkew() {
|
|
125
|
+
if (!this.element?.dataset.mcSkew) return;
|
|
126
|
+
const { style: style } = this.element;
|
|
127
|
+
style.transformOrigin = "center center";
|
|
128
|
+
style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
|
|
129
|
+
}
|
|
129
130
|
}
|
|
130
|
-
var $
|
|
131
|
+
var $a196c1ed25598f0e$export$2e2bcd8739ae039 = $a196c1ed25598f0e$var$MarqueeContent;
|
|
131
132
|
|
|
132
133
|
|
|
133
134
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAIA,MAAM;IACa,KAAY;IAEZ,GAAU;IAEnB,SAAgB;IAEP,QAA4B;IAErC,eAA+B;IAE/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;QACxB,MAAM,SAAS,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IACnE;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["interface MarqueeContentOptions {\n element?: string | HTMLElement;\n}\n\nclass MarqueeContent {\n private readonly gsap: never;\n\n private readonly MM: never;\n\n private timeline: never;\n\n private readonly element: HTMLElement | null;\n\n private resizeObserver: ResizeObserver;\n\n private animationFrame: number | null = null;\n\n static gsap: never;\n\n static ScrollTrigger: never;\n\n constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {\n this.gsap = MarqueeContent.gsap ?? (window as never).gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.element = typeof element === 'string' ? document.querySelector(element) : element;\n\n if (!this.element) return;\n\n this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));\n this.resizeObserver.observe(this.element);\n }\n\n static registerGSAP(gsap: never, ScrollTrigger: never) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n private commonInit = () => {\n if (this.element) {\n this.clearTimeline();\n this.cloneElements();\n this.setBreakpoints();\n this.applySkew();\n\n this.timeline = this.createAnimation();\n }\n };\n\n private update = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n this.animationFrame = requestAnimationFrame(() => {\n this.commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n public init = () => {\n this.commonInit();\n };\n\n public destroy = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n if (this.element) {\n this.clearTimeline();\n }\n\n this.resizeObserver?.disconnect();\n };\n\n private static debounce(func: (...args: never[]) => void) {\n let timer: number | null = null;\n\n return (...args: never[]) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n private createAnimation() {\n this.timeline?.kill();\n\n const timeline = this.gsap.timeline({\n scrollTrigger: {\n trigger: this.element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self: never) => {\n if (this.element?.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (this.element?.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.MM.add(this.element?.dataset.mcBreakpoint, () => {\n const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');\n const speed = mcSpeed;\n\n timeline.to(this.element!.children, {\n duration: speed,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n return timeline;\n }\n\n private setBreakpoints() {\n if (this.element!.dataset.mcMax) {\n this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;\n } else if (this.element!.dataset.mcMin) {\n this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;\n } else {\n this.element!.dataset.mcBreakpoint = '';\n }\n }\n\n private clearTimeline() {\n this.timeline?.kill();\n this.timeline = null;\n this.gsap.set(this.element!.children, { clearProps: 'all' });\n }\n\n private cloneElements() {\n const removingClones = () => {\n while (this.element!.childElementCount > 1) {\n this.element!.removeChild(this.element!.lastChild as ChildNode);\n }\n };\n\n removingClones();\n\n this.MM.add(this.element!.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);\n\n if (this.element!.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.element!.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n private applySkew() {\n if (!this.element?.dataset.mcSkew) return;\n\n const { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,122 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const $f3ad94c9f84f4d57$export$ecad260a8a5fef4f = function(element, gsap, MM, timeline, update) {
|
|
9
|
-
timeline?.kill();
|
|
10
|
-
timeline = gsap.timeline({
|
|
11
|
-
scrollTrigger: {
|
|
12
|
-
trigger: element,
|
|
13
|
-
start: "top bottom",
|
|
14
|
-
end: "bottom top",
|
|
15
|
-
toggleActions: "resume pause resume pause",
|
|
16
|
-
onUpdate: (self)=>{
|
|
17
|
-
if (element.dataset.mcDirection === "ltr") timeline.timeScale(-1);
|
|
18
|
-
else if (element.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
23
|
-
timeline.to(element.children, {
|
|
24
|
-
duration: element.dataset.mcDuration ?? 20,
|
|
25
|
-
x: "-100%",
|
|
26
|
-
repeat: -1,
|
|
27
|
-
ease: "none"
|
|
28
|
-
});
|
|
29
|
-
timeline.totalProgress(0.5);
|
|
30
|
-
return ()=>timeline?.kill();
|
|
31
|
-
});
|
|
32
|
-
update.timeline = timeline;
|
|
33
|
-
return timeline;
|
|
34
|
-
};
|
|
35
|
-
const $f3ad94c9f84f4d57$export$d07517a676ce386f = function(element) {
|
|
36
|
-
element.dataset.mcBreakpoint = element.dataset.mcMax ? `(max-width: ${element.dataset.mcMax - 0.02}px)` : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : "";
|
|
37
|
-
};
|
|
38
|
-
const $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b = function(timeline, element, gsap) {
|
|
39
|
-
timeline?.kill();
|
|
40
|
-
timeline = null;
|
|
41
|
-
gsap.set(element.children, {
|
|
42
|
-
clearProps: "all"
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b = function(element, gsap, MM) {
|
|
46
|
-
const removingClones = ()=>{
|
|
47
|
-
while(element.childElementCount > 1)element.removeChild(element.lastChild);
|
|
48
|
-
};
|
|
49
|
-
removingClones();
|
|
50
|
-
MM.add(element.dataset.mcBreakpoint, ()=>{
|
|
51
|
-
const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
|
|
52
|
-
if (element.childElementCount < requiredQuantity) {
|
|
53
|
-
const fragment = document.createDocumentFragment();
|
|
54
|
-
const clones = Array.from({
|
|
55
|
-
length: requiredQuantity - 1
|
|
56
|
-
}, ()=>element.firstElementChild.cloneNode(true));
|
|
57
|
-
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
58
|
-
element.appendChild(fragment);
|
|
59
|
-
}
|
|
60
|
-
return removingClones;
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
const $f3ad94c9f84f4d57$export$3484d11c6bb42ecc = function(element) {
|
|
64
|
-
if (!element.dataset.mcSkew) return;
|
|
65
|
-
const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
|
|
66
|
-
const { style: style } = element;
|
|
67
|
-
style.transformOrigin = "center center";
|
|
68
|
-
style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
|
|
69
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
class $cf838c15c8b009ba$var$MarqueeContent {
|
|
74
|
-
#gsap;
|
|
75
|
-
#MM;
|
|
76
|
-
#timeline;
|
|
77
|
-
#element;
|
|
78
|
-
#resizeObserver;
|
|
79
|
-
#animationFrame;
|
|
1
|
+
class $643fcf18b2d2e76f$var$MarqueeContent {
|
|
2
|
+
gsap;
|
|
3
|
+
MM;
|
|
4
|
+
timeline;
|
|
5
|
+
element;
|
|
6
|
+
resizeObserver;
|
|
7
|
+
animationFrame = null;
|
|
80
8
|
static gsap;
|
|
81
9
|
static ScrollTrigger;
|
|
82
10
|
constructor({ element: element = ".marquee" } = {}){
|
|
83
|
-
this
|
|
84
|
-
this
|
|
85
|
-
this
|
|
86
|
-
this
|
|
87
|
-
if (!this
|
|
88
|
-
this
|
|
89
|
-
this
|
|
11
|
+
this.gsap = $643fcf18b2d2e76f$var$MarqueeContent.gsap ?? window.gsap;
|
|
12
|
+
this.MM = this.gsap.matchMedia();
|
|
13
|
+
this.timeline = null;
|
|
14
|
+
this.element = typeof element === "string" ? document.querySelector(element) : element;
|
|
15
|
+
if (!this.element) return;
|
|
16
|
+
this.resizeObserver = new ResizeObserver($643fcf18b2d2e76f$var$MarqueeContent.debounce(this.update));
|
|
17
|
+
this.resizeObserver.observe(this.element);
|
|
90
18
|
}
|
|
91
19
|
static registerGSAP(gsap, ScrollTrigger) {
|
|
92
|
-
$
|
|
93
|
-
$
|
|
20
|
+
$643fcf18b2d2e76f$var$MarqueeContent.gsap = gsap;
|
|
21
|
+
$643fcf18b2d2e76f$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
|
|
94
22
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
23
|
+
commonInit = ()=>{
|
|
24
|
+
if (this.element) {
|
|
25
|
+
this.clearTimeline();
|
|
26
|
+
this.cloneElements();
|
|
27
|
+
this.setBreakpoints();
|
|
28
|
+
this.applySkew();
|
|
29
|
+
this.timeline = this.createAnimation();
|
|
30
|
+
}
|
|
101
31
|
};
|
|
102
|
-
|
|
103
|
-
cancelAnimationFrame(this
|
|
104
|
-
this
|
|
105
|
-
this
|
|
106
|
-
$
|
|
32
|
+
update = ()=>{
|
|
33
|
+
if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
|
|
34
|
+
this.animationFrame = requestAnimationFrame(()=>{
|
|
35
|
+
this.commonInit();
|
|
36
|
+
$643fcf18b2d2e76f$var$MarqueeContent.ScrollTrigger.refresh();
|
|
107
37
|
});
|
|
108
38
|
};
|
|
109
39
|
init = ()=>{
|
|
110
|
-
this
|
|
40
|
+
this.commonInit();
|
|
111
41
|
};
|
|
112
42
|
destroy = ()=>{
|
|
113
|
-
cancelAnimationFrame(this
|
|
114
|
-
|
|
115
|
-
this
|
|
43
|
+
if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
|
|
44
|
+
if (this.element) this.clearTimeline();
|
|
45
|
+
this.resizeObserver?.disconnect();
|
|
116
46
|
};
|
|
47
|
+
static debounce(func) {
|
|
48
|
+
let timer = null;
|
|
49
|
+
return (...args)=>{
|
|
50
|
+
if (timer !== null) cancelAnimationFrame(timer);
|
|
51
|
+
timer = requestAnimationFrame(()=>func(...args));
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
createAnimation() {
|
|
55
|
+
this.timeline?.kill();
|
|
56
|
+
const timeline = this.gsap.timeline({
|
|
57
|
+
scrollTrigger: {
|
|
58
|
+
trigger: this.element,
|
|
59
|
+
start: "top bottom",
|
|
60
|
+
end: "bottom top",
|
|
61
|
+
toggleActions: "resume pause resume pause",
|
|
62
|
+
onUpdate: (self)=>{
|
|
63
|
+
if (this.element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
|
|
64
|
+
else if (this.element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
this.MM.add(this.element?.dataset.mcBreakpoint, ()=>{
|
|
69
|
+
const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || "20");
|
|
70
|
+
const speed = mcSpeed;
|
|
71
|
+
timeline.to(this.element.children, {
|
|
72
|
+
duration: speed,
|
|
73
|
+
x: "-100%",
|
|
74
|
+
repeat: -1,
|
|
75
|
+
ease: "none"
|
|
76
|
+
});
|
|
77
|
+
timeline.totalProgress(0.5);
|
|
78
|
+
return ()=>timeline?.kill();
|
|
79
|
+
});
|
|
80
|
+
return timeline;
|
|
81
|
+
}
|
|
82
|
+
setBreakpoints() {
|
|
83
|
+
if (this.element.dataset.mcMax) this.element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element.dataset.mcMax) - 0.02}px)`;
|
|
84
|
+
else if (this.element.dataset.mcMin) this.element.dataset.mcBreakpoint = `(min-width: ${this.element.dataset.mcMin}px)`;
|
|
85
|
+
else this.element.dataset.mcBreakpoint = "";
|
|
86
|
+
}
|
|
87
|
+
clearTimeline() {
|
|
88
|
+
this.timeline?.kill();
|
|
89
|
+
this.timeline = null;
|
|
90
|
+
this.gsap.set(this.element.children, {
|
|
91
|
+
clearProps: "all"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
cloneElements() {
|
|
95
|
+
const removingClones = ()=>{
|
|
96
|
+
while(this.element.childElementCount > 1)this.element.removeChild(this.element.lastChild);
|
|
97
|
+
};
|
|
98
|
+
removingClones();
|
|
99
|
+
this.MM.add(this.element.dataset.mcBreakpoint, ()=>{
|
|
100
|
+
const requiredQuantity = Math.ceil(this.element.scrollWidth / this.element.firstElementChild.clientWidth + 2);
|
|
101
|
+
if (this.element.childElementCount < requiredQuantity) {
|
|
102
|
+
const fragment = document.createDocumentFragment();
|
|
103
|
+
const clones = Array.from({
|
|
104
|
+
length: requiredQuantity - 1
|
|
105
|
+
}, ()=>this.element.firstElementChild.cloneNode(true));
|
|
106
|
+
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
107
|
+
this.element.appendChild(fragment);
|
|
108
|
+
}
|
|
109
|
+
return removingClones;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
applySkew() {
|
|
113
|
+
if (!this.element?.dataset.mcSkew) return;
|
|
114
|
+
const { style: style } = this.element;
|
|
115
|
+
style.transformOrigin = "center center";
|
|
116
|
+
style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
|
|
117
|
+
}
|
|
117
118
|
}
|
|
118
|
-
var $
|
|
119
|
+
var $643fcf18b2d2e76f$export$2e2bcd8739ae039 = $643fcf18b2d2e76f$var$MarqueeContent;
|
|
119
120
|
|
|
120
121
|
|
|
121
|
-
export {$
|
|
122
|
+
export {$643fcf18b2d2e76f$export$2e2bcd8739ae039 as default};
|
|
122
123
|
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAIA,MAAM;IACa,KAAY;IAEZ,GAAU;IAEnB,SAAgB;IAEP,QAA4B;IAErC,eAA+B;IAE/B,iBAAgC,KAAK;IAE7C,OAAO,KAAY;IAEnB,OAAO,cAAqB;IAE5B,YAAY,WAAE,UAAU,YAAmC,GAAG,CAAC,CAAC,CAAE;QAChE,IAAI,CAAC,IAAI,GAAG,qCAAe,IAAI,IAAI,AAAC,OAAiB,IAAI;QACzD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,YAAY,WAAW,SAAS,aAAa,CAAC,WAAW;QAE/E,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QAEnB,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,qCAAe,QAAQ,CAAC,IAAI,CAAC,MAAM;QAC5E,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO;IAC1C;IAEA,OAAO,aAAa,IAAW,EAAE,aAAoB,EAAE;QACrD,qCAAe,IAAI,GAAG;QACtB,qCAAe,aAAa,GAAG;IACjC;IAEQ,aAAa;QACnB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,aAAa;YAClB,IAAI,CAAC,aAAa;YAClB,IAAI,CAAC,cAAc;YACnB,IAAI,CAAC,SAA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AAkB;gBACtD,MAAM,WAAW,SAAS,sBAAsB;gBAChD,MAAM,SAAS,MAAM,IAAI,CAAC;oBAAE,QAAQ,mBAAmB;gBAAE,GAAG,IAAM,IAAI,CAAC,OAAO,CAAE,iBAAiB,CAAE,SAAS,CAAC;gBAE7G,OAAO,OAAO,CAAC,CAAC,QAAU,SAAS,WAAW,CAAC;gBAE/C,IAAI,CAAC,OAAO,CAAE,WAAW,CAAC;YAC5B;YAEA,OAAO;QACT;IACF;IAEQ,YAAY;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,QAAQ;QAEnC,MAAM,SAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO;QAE9B,MAAM,eAAe,GAAG;QACxB,MAAM,SAAS,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IACnE;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["interface MarqueeContentOptions {\n element?: string | HTMLElement;\n}\n\nclass MarqueeContent {\n private readonly gsap: never;\n\n private readonly MM: never;\n\n private timeline: never;\n\n private readonly element: HTMLElement | null;\n\n private resizeObserver: ResizeObserver;\n\n private animationFrame: number | null = null;\n\n static gsap: never;\n\n static ScrollTrigger: never;\n\n constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {\n this.gsap = MarqueeContent.gsap ?? (window as never).gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.element = typeof element === 'string' ? document.querySelector(element) : element;\n\n if (!this.element) return;\n\n this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));\n this.resizeObserver.observe(this.element);\n }\n\n static registerGSAP(gsap: never, ScrollTrigger: never) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n private commonInit = () => {\n if (this.element) {\n this.clearTimeline();\n this.cloneElements();\n this.setBreakpoints();\n this.applySkew();\n\n this.timeline = this.createAnimation();\n }\n };\n\n private update = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n this.animationFrame = requestAnimationFrame(() => {\n this.commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n public init = () => {\n this.commonInit();\n };\n\n public destroy = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n if (this.element) {\n this.clearTimeline();\n }\n\n this.resizeObserver?.disconnect();\n };\n\n private static debounce(func: (...args: never[]) => void) {\n let timer: number | null = null;\n\n return (...args: never[]) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n private createAnimation() {\n this.timeline?.kill();\n\n const timeline = this.gsap.timeline({\n scrollTrigger: {\n trigger: this.element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self: never) => {\n if (this.element?.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (this.element?.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.MM.add(this.element?.dataset.mcBreakpoint, () => {\n const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');\n const speed = mcSpeed;\n\n timeline.to(this.element!.children, {\n duration: speed,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n return timeline;\n }\n\n private setBreakpoints() {\n if (this.element!.dataset.mcMax) {\n this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;\n } else if (this.element!.dataset.mcMin) {\n this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;\n } else {\n this.element!.dataset.mcBreakpoint = '';\n }\n }\n\n private clearTimeline() {\n this.timeline?.kill();\n this.timeline = null;\n this.gsap.set(this.element!.children, { clearProps: 'all' });\n }\n\n private cloneElements() {\n const removingClones = () => {\n while (this.element!.childElementCount > 1) {\n this.element!.removeChild(this.element!.lastChild as ChildNode);\n }\n };\n\n removingClones();\n\n this.MM.add(this.element!.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);\n\n if (this.element!.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.element!.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n private applySkew() {\n if (!this.element?.dataset.mcSkew) return;\n\n const { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marquee-content",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.4.0",
|
|
4
|
+
"description": "MarqueeContent provides a set of tools for creating dynamic and adaptive ticker animations on web pages using GSAP and ScrollTrigger.",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -11,29 +11,29 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ux-ui-pro/marquee-content/issues"
|
|
13
13
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"targets": {
|
|
17
|
-
"main": {
|
|
18
|
-
"source": "src/index.js"
|
|
19
|
-
},
|
|
20
|
-
"module": {
|
|
21
|
-
"source": "src/index.js"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
14
|
+
"homepage": "https://github.com/ux-ui-pro/marquee-content",
|
|
15
|
+
"sideEffects": false,
|
|
24
16
|
"scripts": {
|
|
25
17
|
"clean": "rm -rf dist .parcel-cache",
|
|
26
|
-
"serve": "parcel src/index.html --dist-dir dist --cache-dir .parcel --no-source-maps --open",
|
|
27
18
|
"build": "yarn clean && parcel build",
|
|
28
|
-
"lint:js": "eslint
|
|
19
|
+
"lint:js": "eslint **/*.{ts,js}",
|
|
29
20
|
"lintfix": "yarn lint:js --fix"
|
|
30
21
|
},
|
|
22
|
+
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
23
|
+
"source": "src/index.ts",
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"module": "dist/index.module.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
31
27
|
"devDependencies": {
|
|
32
|
-
"
|
|
28
|
+
"@parcel/packager-ts": "2.12.0",
|
|
29
|
+
"@parcel/transformer-typescript-types": "2.12.0",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^7.11.0",
|
|
31
|
+
"@typescript-eslint/parser": "^7.11.0",
|
|
32
|
+
"eslint": "^7.32.0 || ^8.57.0",
|
|
33
33
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
34
34
|
"eslint-plugin-import": "^2.29.1",
|
|
35
35
|
"parcel": "^2.12.0",
|
|
36
|
-
"
|
|
36
|
+
"typescript": "^5.4.5"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"marquee",
|
|
@@ -49,6 +49,22 @@
|
|
|
49
49
|
"filler",
|
|
50
50
|
"css",
|
|
51
51
|
"effects",
|
|
52
|
-
"gsap"
|
|
52
|
+
"gsap",
|
|
53
|
+
"ResizeObserver",
|
|
54
|
+
"timeline",
|
|
55
|
+
"scrollTrigger",
|
|
56
|
+
"breakpoints",
|
|
57
|
+
"debounce",
|
|
58
|
+
"typescript",
|
|
59
|
+
"clone",
|
|
60
|
+
"skew",
|
|
61
|
+
"responsive",
|
|
62
|
+
"media queries",
|
|
63
|
+
"javascript",
|
|
64
|
+
"frontend",
|
|
65
|
+
"UX",
|
|
66
|
+
"performance",
|
|
67
|
+
"HTML",
|
|
68
|
+
"CSS"
|
|
53
69
|
]
|
|
54
70
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
interface MarqueeContentOptions {
|
|
2
|
+
element?: string | HTMLElement;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
class MarqueeContent {
|
|
6
|
+
private readonly gsap: never;
|
|
7
|
+
|
|
8
|
+
private readonly MM: never;
|
|
9
|
+
|
|
10
|
+
private timeline: never;
|
|
11
|
+
|
|
12
|
+
private readonly element: HTMLElement | null;
|
|
13
|
+
|
|
14
|
+
private resizeObserver: ResizeObserver;
|
|
15
|
+
|
|
16
|
+
private animationFrame: number | null = null;
|
|
17
|
+
|
|
18
|
+
static gsap: never;
|
|
19
|
+
|
|
20
|
+
static ScrollTrigger: never;
|
|
21
|
+
|
|
22
|
+
constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {
|
|
23
|
+
this.gsap = MarqueeContent.gsap ?? (window as never).gsap;
|
|
24
|
+
this.MM = this.gsap.matchMedia();
|
|
25
|
+
this.timeline = null;
|
|
26
|
+
this.element = typeof element === 'string' ? document.querySelector(element) : element;
|
|
27
|
+
|
|
28
|
+
if (!this.element) return;
|
|
29
|
+
|
|
30
|
+
this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));
|
|
31
|
+
this.resizeObserver.observe(this.element);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static registerGSAP(gsap: never, ScrollTrigger: never) {
|
|
35
|
+
MarqueeContent.gsap = gsap;
|
|
36
|
+
MarqueeContent.ScrollTrigger = ScrollTrigger;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private commonInit = () => {
|
|
40
|
+
if (this.element) {
|
|
41
|
+
this.clearTimeline();
|
|
42
|
+
this.cloneElements();
|
|
43
|
+
this.setBreakpoints();
|
|
44
|
+
this.applySkew();
|
|
45
|
+
|
|
46
|
+
this.timeline = this.createAnimation();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
private update = () => {
|
|
51
|
+
if (this.animationFrame !== null) {
|
|
52
|
+
cancelAnimationFrame(this.animationFrame);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.animationFrame = requestAnimationFrame(() => {
|
|
56
|
+
this.commonInit();
|
|
57
|
+
|
|
58
|
+
MarqueeContent.ScrollTrigger.refresh();
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
public init = () => {
|
|
63
|
+
this.commonInit();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
public destroy = () => {
|
|
67
|
+
if (this.animationFrame !== null) {
|
|
68
|
+
cancelAnimationFrame(this.animationFrame);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (this.element) {
|
|
72
|
+
this.clearTimeline();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.resizeObserver?.disconnect();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
private static debounce(func: (...args: never[]) => void) {
|
|
79
|
+
let timer: number | null = null;
|
|
80
|
+
|
|
81
|
+
return (...args: never[]) => {
|
|
82
|
+
if (timer !== null) {
|
|
83
|
+
cancelAnimationFrame(timer);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
timer = requestAnimationFrame(() => func(...args));
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private createAnimation() {
|
|
91
|
+
this.timeline?.kill();
|
|
92
|
+
|
|
93
|
+
const timeline = this.gsap.timeline({
|
|
94
|
+
scrollTrigger: {
|
|
95
|
+
trigger: this.element,
|
|
96
|
+
start: 'top bottom',
|
|
97
|
+
end: 'bottom top',
|
|
98
|
+
toggleActions: 'resume pause resume pause',
|
|
99
|
+
onUpdate: (self: never) => {
|
|
100
|
+
if (this.element?.dataset.mcDirection === 'ltr') {
|
|
101
|
+
timeline.timeScale(-1);
|
|
102
|
+
} else if (this.element?.dataset.mcDirection === 'auto') {
|
|
103
|
+
timeline.timeScale(self.direction);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
this.MM.add(this.element?.dataset.mcBreakpoint, () => {
|
|
110
|
+
const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');
|
|
111
|
+
const speed = mcSpeed;
|
|
112
|
+
|
|
113
|
+
timeline.to(this.element!.children, {
|
|
114
|
+
duration: speed,
|
|
115
|
+
x: '-100%',
|
|
116
|
+
repeat: -1,
|
|
117
|
+
ease: 'none',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
timeline.totalProgress(0.5);
|
|
121
|
+
|
|
122
|
+
return () => timeline?.kill();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return timeline;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private setBreakpoints() {
|
|
129
|
+
if (this.element!.dataset.mcMax) {
|
|
130
|
+
this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;
|
|
131
|
+
} else if (this.element!.dataset.mcMin) {
|
|
132
|
+
this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;
|
|
133
|
+
} else {
|
|
134
|
+
this.element!.dataset.mcBreakpoint = '';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private clearTimeline() {
|
|
139
|
+
this.timeline?.kill();
|
|
140
|
+
this.timeline = null;
|
|
141
|
+
this.gsap.set(this.element!.children, { clearProps: 'all' });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private cloneElements() {
|
|
145
|
+
const removingClones = () => {
|
|
146
|
+
while (this.element!.childElementCount > 1) {
|
|
147
|
+
this.element!.removeChild(this.element!.lastChild as ChildNode);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
removingClones();
|
|
152
|
+
|
|
153
|
+
this.MM.add(this.element!.dataset.mcBreakpoint, () => {
|
|
154
|
+
const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);
|
|
155
|
+
|
|
156
|
+
if (this.element!.childElementCount < requiredQuantity) {
|
|
157
|
+
const fragment = document.createDocumentFragment();
|
|
158
|
+
const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);
|
|
159
|
+
|
|
160
|
+
clones.forEach((clone) => fragment.appendChild(clone));
|
|
161
|
+
|
|
162
|
+
this.element!.appendChild(fragment);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return removingClones;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private applySkew() {
|
|
170
|
+
if (!this.element?.dataset.mcSkew) return;
|
|
171
|
+
|
|
172
|
+
const { style } = this.element;
|
|
173
|
+
|
|
174
|
+
style.transformOrigin = 'center center';
|
|
175
|
+
style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export default MarqueeContent;
|
package/tsconfig.json
ADDED
package/src/index.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import * as Utils from './utils.js';
|
|
2
|
-
|
|
3
|
-
class MarqueeContent {
|
|
4
|
-
#gsap;
|
|
5
|
-
|
|
6
|
-
#MM;
|
|
7
|
-
|
|
8
|
-
#timeline;
|
|
9
|
-
|
|
10
|
-
#element;
|
|
11
|
-
|
|
12
|
-
#resizeObserver;
|
|
13
|
-
|
|
14
|
-
#animationFrame;
|
|
15
|
-
|
|
16
|
-
static gsap;
|
|
17
|
-
|
|
18
|
-
static ScrollTrigger;
|
|
19
|
-
|
|
20
|
-
constructor({element = '.marquee'} = {}) {
|
|
21
|
-
this.#gsap = MarqueeContent.gsap ?? window.gsap;
|
|
22
|
-
this.#MM = this.#gsap.matchMedia();
|
|
23
|
-
this.#timeline = null;
|
|
24
|
-
this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
|
|
25
|
-
|
|
26
|
-
if (!this.#element) return;
|
|
27
|
-
|
|
28
|
-
this.#resizeObserver = new ResizeObserver(Utils.debounce(() => this.#update()));
|
|
29
|
-
this.#resizeObserver.observe(this.#element);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static registerGSAP(gsap, ScrollTrigger) {
|
|
33
|
-
MarqueeContent.gsap = gsap;
|
|
34
|
-
MarqueeContent.ScrollTrigger = ScrollTrigger;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
#commonInit = () => {
|
|
38
|
-
Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);
|
|
39
|
-
Utils.cloning(this.#element, this.#gsap, this.#MM);
|
|
40
|
-
Utils.breakpoints(this.#element);
|
|
41
|
-
Utils.skewed(this.#element);
|
|
42
|
-
|
|
43
|
-
this.#timeline = Utils.animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
#update = () => {
|
|
47
|
-
cancelAnimationFrame(this.#animationFrame);
|
|
48
|
-
this.#animationFrame = requestAnimationFrame(() => {
|
|
49
|
-
this.#commonInit();
|
|
50
|
-
|
|
51
|
-
MarqueeContent.ScrollTrigger.refresh();
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
init = () => {
|
|
56
|
-
this.#commonInit();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
destroy = () => {
|
|
60
|
-
cancelAnimationFrame(this.#animationFrame);
|
|
61
|
-
|
|
62
|
-
Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);
|
|
63
|
-
|
|
64
|
-
this.#resizeObserver?.disconnect();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default MarqueeContent;
|
package/src/utils.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
export const debounce = function(func) {
|
|
2
|
-
let timer;
|
|
3
|
-
|
|
4
|
-
return (...args) => {
|
|
5
|
-
cancelAnimationFrame(timer);
|
|
6
|
-
|
|
7
|
-
timer = requestAnimationFrame(() => func(...args));
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const animation = function(element, gsap, MM, timeline, update) {
|
|
12
|
-
timeline?.kill();
|
|
13
|
-
|
|
14
|
-
timeline = gsap.timeline({
|
|
15
|
-
scrollTrigger: {
|
|
16
|
-
trigger: element,
|
|
17
|
-
start: 'top bottom',
|
|
18
|
-
end: 'bottom top',
|
|
19
|
-
toggleActions: 'resume pause resume pause',
|
|
20
|
-
onUpdate: (self) => {
|
|
21
|
-
if (element.dataset.mcDirection === 'ltr') {
|
|
22
|
-
timeline.timeScale(-1);
|
|
23
|
-
} else if (element.dataset.mcDirection === 'auto') {
|
|
24
|
-
timeline.timeScale(self.direction);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
MM.add(element.dataset.mcBreakpoint, () => {
|
|
31
|
-
timeline.to(element.children, {
|
|
32
|
-
duration: element.dataset.mcDuration ?? 20,
|
|
33
|
-
x: '-100%',
|
|
34
|
-
repeat: -1,
|
|
35
|
-
ease: 'none',
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
timeline.totalProgress(0.5);
|
|
39
|
-
|
|
40
|
-
return () => timeline?.kill();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
update.timeline = timeline;
|
|
44
|
-
|
|
45
|
-
return timeline;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const breakpoints = function(element) {
|
|
49
|
-
element.dataset.mcBreakpoint = element.dataset.mcMax
|
|
50
|
-
? `(max-width: ${element.dataset.mcMax - 0.02}px)`
|
|
51
|
-
: element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const clearTimeline = function(timeline, element, gsap) {
|
|
55
|
-
timeline?.kill();
|
|
56
|
-
timeline = null;
|
|
57
|
-
|
|
58
|
-
gsap.set(element.children, { clearProps: 'all' });
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const cloning = function(element, gsap, MM) {
|
|
62
|
-
const removingClones = () => {
|
|
63
|
-
while (element.childElementCount > 1) {
|
|
64
|
-
element.removeChild(element.lastChild);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
removingClones();
|
|
69
|
-
|
|
70
|
-
MM.add(element.dataset.mcBreakpoint, () => {
|
|
71
|
-
const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
|
|
72
|
-
|
|
73
|
-
if (element.childElementCount < requiredQuantity) {
|
|
74
|
-
const fragment = document.createDocumentFragment();
|
|
75
|
-
const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));
|
|
76
|
-
|
|
77
|
-
clones.forEach(clone => fragment.appendChild(clone));
|
|
78
|
-
|
|
79
|
-
element.appendChild(fragment);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return removingClones;
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const skewed = function(element) {
|
|
87
|
-
if (!element.dataset.mcSkew) return;
|
|
88
|
-
|
|
89
|
-
const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
|
|
90
|
-
const { style } = element;
|
|
91
|
-
|
|
92
|
-
style.transformOrigin = 'center center';
|
|
93
|
-
style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
|
|
94
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
95
|
-
};
|