marquee-content 3.1.1 → 4.0.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/LICENSE +1 -1
- package/README.md +14 -17
- package/dist/index.js +99 -115
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +97 -113
- package/dist/index.module.js.map +1 -1
- package/package.json +5 -5
- package/src/demo.js +10 -0
- package/src/index.js +46 -54
- package/src/utils.js +95 -0
- package/dist/index.468c551c.js +0 -764
- package/dist/index.html +0 -262
- package/src/index.html +0 -150
- package/src/utils/animation.js +0 -39
- package/src/utils/breakpoints.js +0 -11
- package/src/utils/clearTimeline.js +0 -10
- package/src/utils/cloning.js +0 -22
- package/src/utils/skewed.js +0 -18
- package/src/utils/update.js +0 -15
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,46 +1,44 @@
|
|
|
1
1
|
<br>
|
|
2
|
-
<p align="center"><strong>marquee-content</strong></p>
|
|
3
|
-
|
|
4
2
|
<div align="center">
|
|
5
3
|
|
|
4
|
+
# marquee-content
|
|
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
|
+
|
|
6
7
|
[](https://www.npmjs.com/package/marquee-content)
|
|
7
8
|
[](https://github.com/ux-ui-pro/marquee-content)
|
|
8
9
|
[](https://www.npmjs.org/package/marquee-content)
|
|
9
10
|
|
|
11
|
+
<sup>1kB gzipped</sup>
|
|
12
|
+
|
|
13
|
+
### <a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a>
|
|
14
|
+
|
|
10
15
|
</div>
|
|
11
16
|
|
|
12
|
-
<p align="center">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.</p>
|
|
13
|
-
<p align="center"><sup>1kB gzipped</sup></p>
|
|
14
|
-
<p align="center"><a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a></p>
|
|
15
17
|
<br>
|
|
16
18
|
|
|
17
19
|
➤ **Install**
|
|
18
|
-
|
|
19
20
|
```
|
|
20
21
|
yarn add gsap
|
|
21
22
|
yarn add marquee-content
|
|
22
23
|
```
|
|
23
|
-
|
|
24
24
|
<br>
|
|
25
25
|
|
|
26
26
|
➤ **Import**
|
|
27
|
-
|
|
28
27
|
```javascript
|
|
29
|
-
import gsap from 'gsap';
|
|
28
|
+
import { gsap } from 'gsap';
|
|
30
29
|
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
|
31
30
|
import MarqueeContent from 'marquee-content';
|
|
32
|
-
|
|
33
|
-
gsap.registerPlugin(ScrollTrigger);
|
|
34
|
-
MarqueeContent.registerGSAP(gsap);
|
|
35
31
|
```
|
|
36
32
|
<br>
|
|
37
33
|
|
|
38
34
|
➤ **Usage**
|
|
35
|
+
```javascript
|
|
36
|
+
gsap.registerPlugin(ScrollTrigger);
|
|
37
|
+
MarqueeContent.registerGSAP(gsap);
|
|
38
|
+
|
|
39
|
+
const marqueeContent = new MarqueeContent();
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
<marquee-content data-mc-duration="30" role="marquee">
|
|
42
|
-
content
|
|
43
|
-
</marquee-content>
|
|
41
|
+
marqueeContent.init();
|
|
44
42
|
```
|
|
45
43
|
<br>
|
|
46
44
|
|
|
@@ -53,7 +51,6 @@ MarqueeContent.registerGSAP(gsap);
|
|
|
53
51
|
| `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (a positive or negative value is acceptable). |
|
|
54
52
|
| `data-mc-min` | `null` | Sets the **minimum** width at which the animation will play (when the breakpoint intersects, the cloned elements are removed and the component styles are cleared). |
|
|
55
53
|
| `data-mc-max` | `null` | Sets the **maximum** width. |
|
|
56
|
-
|
|
57
54
|
<br>
|
|
58
55
|
|
|
59
56
|
➤ **License**
|
package/dist/index.js
CHANGED
|
@@ -10,136 +10,120 @@ function $parcel$export(e, n, v, s) {
|
|
|
10
10
|
$parcel$defineInteropFlag(module.exports);
|
|
11
11
|
|
|
12
12
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
const $4559ecf940edc78d$export$61fc7d43ac8f84b0 = function(func) {
|
|
14
|
+
let timer;
|
|
15
|
+
return (...args)=>{
|
|
16
|
+
cancelAnimationFrame(timer);
|
|
17
|
+
timer = requestAnimationFrame(()=>func(...args));
|
|
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) {
|
|
22
58
|
const removingClones = ()=>{
|
|
23
|
-
while(
|
|
59
|
+
while(element.childElementCount > 1)element.removeChild(element.lastChild);
|
|
24
60
|
};
|
|
25
61
|
removingClones();
|
|
26
|
-
|
|
27
|
-
const requiredQuantity = Math.ceil(
|
|
28
|
-
if (
|
|
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();
|
|
29
66
|
const clones = Array.from({
|
|
30
67
|
length: requiredQuantity - 1
|
|
31
|
-
}, ()=>
|
|
32
|
-
|
|
68
|
+
}, ()=>element.firstElementChild.cloneNode(true));
|
|
69
|
+
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
70
|
+
element.appendChild(fragment);
|
|
33
71
|
}
|
|
34
72
|
return removingClones;
|
|
35
73
|
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
this
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
clearProps: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
var $26261098b528e5f4$export$2e2bcd8739ae039 = $26261098b528e5f4$var$clearTimeline;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function $7206b27cbeabecb6$var$animation() {
|
|
69
|
-
if (this.timeline) (0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
|
|
70
|
-
this.MM.add(this.breakpoint, ()=>{
|
|
71
|
-
this.timeline = this.gsap.to(this.children, {
|
|
72
|
-
duration: this.dataset.mcDuration || 20,
|
|
73
|
-
x: "-100%",
|
|
74
|
-
repeat: -1,
|
|
75
|
-
ease: "none",
|
|
76
|
-
scrollTrigger: {
|
|
77
|
-
trigger: this,
|
|
78
|
-
start: "-=50% bottom",
|
|
79
|
-
end: "bottom top",
|
|
80
|
-
toggleActions: "resume pause resume pause",
|
|
81
|
-
onUpdate: (self)=>{
|
|
82
|
-
if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
|
|
83
|
-
else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
this.timeline.totalProgress(0.5);
|
|
88
|
-
return ()=>{
|
|
89
|
-
if (this.timeline) (0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
var $7206b27cbeabecb6$export$2e2bcd8739ae039 = $7206b27cbeabecb6$var$animation;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
98
|
-
constructor(){
|
|
99
|
-
super();
|
|
100
|
-
this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
101
|
-
this.MM = this.gsap.matchMedia();
|
|
102
|
-
this.timeline = null;
|
|
103
|
-
this.update = this.update.bind(this);
|
|
104
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
105
|
-
this.resizeObserver.observe(this);
|
|
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$export$2e2bcd8739ae039 {
|
|
86
|
+
#gsap;
|
|
87
|
+
#MM;
|
|
88
|
+
#timeline;
|
|
89
|
+
#element;
|
|
90
|
+
#resizeObserver;
|
|
91
|
+
#animationFrame;
|
|
92
|
+
constructor(el){
|
|
93
|
+
this.#gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap ?? window.gsap;
|
|
94
|
+
this.#MM = this.#gsap.matchMedia();
|
|
95
|
+
this.#timeline = null;
|
|
96
|
+
this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? ".marquee");
|
|
97
|
+
if (!this.#element) throw new Error("Element not found");
|
|
98
|
+
this.#resizeObserver = new ResizeObserver((0, $4559ecf940edc78d$export$61fc7d43ac8f84b0)(()=>this.#update()));
|
|
99
|
+
this.#resizeObserver.observe(this.#element);
|
|
106
100
|
}
|
|
107
101
|
static registerGSAP(gsap) {
|
|
108
102
|
$4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
#commonInit = ()=>{
|
|
105
|
+
(0, $4559ecf940edc78d$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
106
|
+
(0, $4559ecf940edc78d$export$7c4d14cd3c92bf0b)(this.#element, this.#gsap, this.#MM);
|
|
107
|
+
(0, $4559ecf940edc78d$export$d07517a676ce386f)(this.#element);
|
|
108
|
+
(0, $4559ecf940edc78d$export$3484d11c6bb42ecc)(this.#element);
|
|
109
|
+
this.#timeline = (0, $4559ecf940edc78d$export$ecad260a8a5fef4f)(this.#element, this.#gsap, this.#MM, this.#timeline, this);
|
|
116
110
|
};
|
|
117
|
-
update()
|
|
118
|
-
cancelAnimationFrame(this
|
|
119
|
-
|
|
120
|
-
(
|
|
121
|
-
|
|
111
|
+
#update = ()=>{
|
|
112
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
113
|
+
this.#animationFrame = requestAnimationFrame(()=>{
|
|
114
|
+
this.#commonInit();
|
|
115
|
+
ScrollTrigger.refresh();
|
|
122
116
|
});
|
|
123
|
-
}
|
|
124
|
-
init()
|
|
125
|
-
(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
(0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
|
|
133
|
-
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
134
|
-
}
|
|
135
|
-
connectedCallback() {
|
|
136
|
-
this.init();
|
|
137
|
-
}
|
|
138
|
-
disconnectedCallback() {
|
|
139
|
-
this.destroy();
|
|
140
|
-
}
|
|
117
|
+
};
|
|
118
|
+
init = ()=>{
|
|
119
|
+
this.#commonInit();
|
|
120
|
+
};
|
|
121
|
+
destroy = ()=>{
|
|
122
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
123
|
+
(0, $4559ecf940edc78d$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
124
|
+
this.#resizeObserver?.disconnect();
|
|
125
|
+
};
|
|
141
126
|
}
|
|
142
|
-
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae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EF,CAAC,MAAM,GAAG;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAChB,cAAc,OAAO;QACvB;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QACvD,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH","sources":["src/index.js","src/utils.js"],"sourcesContent":["import {\n debounce,\n breakpoints,\n cloning,\n skewed,\n animation,\n clearTimeline,\n} from './utils.js';\n\nexport default class MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n constructor(el) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');\n if (!this.#element) throw new Error('Element not found');\n\n this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n #commonInit = () => {\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n cloning(this.#element, this.#gsap, this.#MM);\n breakpoints(this.#element);\n skewed(this.#element);\n this.#timeline = animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);\n };\n\n #update = () => {\n cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = requestAnimationFrame(() => {\n this.#commonInit();\n ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n this.#resizeObserver?.disconnect();\n }\n}\n","export const debounce = function(func) {\n let timer;\n\n return (...args) => {\n cancelAnimationFrame(timer);\n\n timer = requestAnimationFrame(() => func(...args));\n };\n};\n\nexport const animation = function(element, gsap, MM, timeline, update) {\n timeline?.kill();\n\n timeline = gsap.timeline({\n scrollTrigger: {\n trigger: element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (element.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (element.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n }\n });\n\n MM.add(element.dataset.mcBreakpoint, () => {\n timeline.to(element.children, {\n duration: element.dataset.mcDuration ?? 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n update.timeline = timeline;\n\n return timeline;\n};\n\nexport const breakpoints = function(element) {\n element.dataset.mcBreakpoint = element.dataset.mcMax\n ? `(max-width: ${element.dataset.mcMax - 0.02}px)`\n : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';\n};\n\nexport const clearTimeline = function(timeline, element, gsap) {\n timeline?.kill();\n timeline = null;\n\n gsap.set(element.children, { clearProps: 'all' });\n};\n\nexport const cloning = function(element, gsap, MM) {\n const removingClones = () => {\n while (element.childElementCount > 1) {\n element.removeChild(element.lastChild);\n }\n };\n\n removingClones();\n\n MM.add(element.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);\n\n if (element.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));\n\n clones.forEach(clone => fragment.appendChild(clone));\n\n element.appendChild(fragment);\n }\n\n return removingClones;\n });\n};\n\nexport const skewed = function(element) {\n if (!element.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));\n const { style } = element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n};\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,133 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const $f3ad94c9f84f4d57$export$61fc7d43ac8f84b0 = function(func) {
|
|
2
|
+
let timer;
|
|
3
|
+
return (...args)=>{
|
|
4
|
+
cancelAnimationFrame(timer);
|
|
5
|
+
timer = requestAnimationFrame(()=>func(...args));
|
|
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) {
|
|
10
46
|
const removingClones = ()=>{
|
|
11
|
-
while(
|
|
47
|
+
while(element.childElementCount > 1)element.removeChild(element.lastChild);
|
|
12
48
|
};
|
|
13
49
|
removingClones();
|
|
14
|
-
|
|
15
|
-
const requiredQuantity = Math.ceil(
|
|
16
|
-
if (
|
|
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();
|
|
17
54
|
const clones = Array.from({
|
|
18
55
|
length: requiredQuantity - 1
|
|
19
|
-
}, ()=>
|
|
20
|
-
|
|
56
|
+
}, ()=>element.firstElementChild.cloneNode(true));
|
|
57
|
+
clones.forEach((clone)=>fragment.appendChild(clone));
|
|
58
|
+
element.appendChild(fragment);
|
|
21
59
|
}
|
|
22
60
|
return removingClones;
|
|
23
61
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
style.transformOrigin = "center center";
|
|
34
|
-
style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
|
|
35
|
-
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
36
|
-
return ()=>{
|
|
37
|
-
style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
var $dfb0cb0db0a7e917$export$2e2bcd8739ae039 = $dfb0cb0db0a7e917$var$skewed;
|
|
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
|
+
};
|
|
42
71
|
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.timeline = this.gsap.to(this.children, {
|
|
60
|
-
duration: this.dataset.mcDuration || 20,
|
|
61
|
-
x: "-100%",
|
|
62
|
-
repeat: -1,
|
|
63
|
-
ease: "none",
|
|
64
|
-
scrollTrigger: {
|
|
65
|
-
trigger: this,
|
|
66
|
-
start: "-=50% bottom",
|
|
67
|
-
end: "bottom top",
|
|
68
|
-
toggleActions: "resume pause resume pause",
|
|
69
|
-
onUpdate: (self)=>{
|
|
70
|
-
if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
|
|
71
|
-
else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
this.timeline.totalProgress(0.5);
|
|
76
|
-
return ()=>{
|
|
77
|
-
if (this.timeline) (0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
var $5138c3f25fef74d5$export$2e2bcd8739ae039 = $5138c3f25fef74d5$var$animation;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
86
|
-
constructor(){
|
|
87
|
-
super();
|
|
88
|
-
this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
|
|
89
|
-
this.MM = this.gsap.matchMedia();
|
|
90
|
-
this.timeline = null;
|
|
91
|
-
this.update = this.update.bind(this);
|
|
92
|
-
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
|
|
93
|
-
this.resizeObserver.observe(this);
|
|
73
|
+
class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
|
|
74
|
+
#gsap;
|
|
75
|
+
#MM;
|
|
76
|
+
#timeline;
|
|
77
|
+
#element;
|
|
78
|
+
#resizeObserver;
|
|
79
|
+
#animationFrame;
|
|
80
|
+
constructor(el){
|
|
81
|
+
this.#gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap ?? window.gsap;
|
|
82
|
+
this.#MM = this.#gsap.matchMedia();
|
|
83
|
+
this.#timeline = null;
|
|
84
|
+
this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? ".marquee");
|
|
85
|
+
if (!this.#element) throw new Error("Element not found");
|
|
86
|
+
this.#resizeObserver = new ResizeObserver((0, $f3ad94c9f84f4d57$export$61fc7d43ac8f84b0)(()=>this.#update()));
|
|
87
|
+
this.#resizeObserver.observe(this.#element);
|
|
94
88
|
}
|
|
95
89
|
static registerGSAP(gsap) {
|
|
96
90
|
$cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
|
|
97
91
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
#commonInit = ()=>{
|
|
93
|
+
(0, $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
94
|
+
(0, $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b)(this.#element, this.#gsap, this.#MM);
|
|
95
|
+
(0, $f3ad94c9f84f4d57$export$d07517a676ce386f)(this.#element);
|
|
96
|
+
(0, $f3ad94c9f84f4d57$export$3484d11c6bb42ecc)(this.#element);
|
|
97
|
+
this.#timeline = (0, $f3ad94c9f84f4d57$export$ecad260a8a5fef4f)(this.#element, this.#gsap, this.#MM, this.#timeline, this);
|
|
104
98
|
};
|
|
105
|
-
update()
|
|
106
|
-
cancelAnimationFrame(this
|
|
107
|
-
|
|
108
|
-
(
|
|
109
|
-
|
|
99
|
+
#update = ()=>{
|
|
100
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
101
|
+
this.#animationFrame = requestAnimationFrame(()=>{
|
|
102
|
+
this.#commonInit();
|
|
103
|
+
ScrollTrigger.refresh();
|
|
110
104
|
});
|
|
111
|
-
}
|
|
112
|
-
init()
|
|
113
|
-
(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
(0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
|
|
121
|
-
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
122
|
-
}
|
|
123
|
-
connectedCallback() {
|
|
124
|
-
this.init();
|
|
125
|
-
}
|
|
126
|
-
disconnectedCallback() {
|
|
127
|
-
this.destroy();
|
|
128
|
-
}
|
|
105
|
+
};
|
|
106
|
+
init = ()=>{
|
|
107
|
+
this.#commonInit();
|
|
108
|
+
};
|
|
109
|
+
destroy = ()=>{
|
|
110
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
111
|
+
(0, $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
|
|
112
|
+
this.#resizeObserver?.disconnect();
|
|
113
|
+
};
|
|
129
114
|
}
|
|
130
|
-
if (!customElements.get("marquee-content")) customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
|
|
131
115
|
|
|
132
116
|
|
|
133
117
|
export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
|