marquee-content 3.1.1 → 4.1.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 +30 -14
- package/dist/index.js +101 -116
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +99 -114
- package/dist/index.module.js.map +1 -1
- package/package.json +5 -6
- package/src/index.js +45 -53
- 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,32 +1,31 @@
|
|
|
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
31
|
|
|
@@ -36,14 +35,32 @@ MarqueeContent.registerGSAP(gsap);
|
|
|
36
35
|
<br>
|
|
37
36
|
|
|
38
37
|
➤ **Usage**
|
|
38
|
+
```javascript
|
|
39
|
+
const marquee = new MarqueeContent({
|
|
40
|
+
element: '.marquee',
|
|
41
|
+
});
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
marquee.init();
|
|
44
|
+
```
|
|
45
|
+
or
|
|
46
|
+
```javascript
|
|
47
|
+
document.querySelectorAll('.marquee').forEach((element) => {
|
|
48
|
+
const marquee = new MarqueeContent({
|
|
49
|
+
element,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
marquee.init();
|
|
53
|
+
});
|
|
44
54
|
```
|
|
45
55
|
<br>
|
|
46
56
|
|
|
57
|
+
➤ **Options**
|
|
58
|
+
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
|:----------|:-----------------------------:|:-----------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
61
|
+
| `element` | `string` | `HTMLElement` | `.marquee` | The option `element` defines the DOM element to which the animation will be applied. This option offers two ways to specify the target element:<br>**1.** As a string with a CSS selector. If `element` is given as a string, it is used to find the element in the DOM through the `document.querySelector` method. This allows for easy identification of elements by their id, class, or other selector.<br>**2.** As an HTMLElement object. If `element` is already an HTMLElement object, it is used directly, without the need for additional searching in the DOM. |
|
|
62
|
+
<br>
|
|
63
|
+
|
|
47
64
|
➤ **Settings**
|
|
48
65
|
|
|
49
66
|
| Option | Default | Description |
|
|
@@ -53,7 +70,6 @@ MarqueeContent.registerGSAP(gsap);
|
|
|
53
70
|
| `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (a positive or negative value is acceptable). |
|
|
54
71
|
| `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
72
|
| `data-mc-max` | `null` | Sets the **maximum** width. |
|
|
56
|
-
|
|
57
73
|
<br>
|
|
58
74
|
|
|
59
75
|
➤ **License**
|
package/dist/index.js
CHANGED
|
@@ -10,136 +10,121 @@ 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$var$MarqueeContent {
|
|
86
|
+
#gsap;
|
|
87
|
+
#MM;
|
|
88
|
+
#timeline;
|
|
89
|
+
#element;
|
|
90
|
+
#resizeObserver;
|
|
91
|
+
#animationFrame;
|
|
92
|
+
constructor({ element: element = ".marquee" } = {}){
|
|
93
|
+
this.#gsap = $4fa36e821943b400$var$MarqueeContent.gsap ?? window.gsap;
|
|
94
|
+
this.#MM = this.#gsap.matchMedia();
|
|
95
|
+
this.#timeline = null;
|
|
96
|
+
this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
|
|
97
|
+
if (!this.#element) return;
|
|
98
|
+
this.#resizeObserver = new ResizeObserver($4559ecf940edc78d$export$61fc7d43ac8f84b0(()=>this.#update()));
|
|
99
|
+
this.#resizeObserver.observe(this.#element);
|
|
106
100
|
}
|
|
107
101
|
static registerGSAP(gsap) {
|
|
108
|
-
$4fa36e821943b400$
|
|
102
|
+
$4fa36e821943b400$var$MarqueeContent.gsap = gsap;
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
#commonInit = ()=>{
|
|
105
|
+
$4559ecf940edc78d$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
|
|
106
|
+
$4559ecf940edc78d$export$7c4d14cd3c92bf0b(this.#element, this.#gsap, this.#MM);
|
|
107
|
+
$4559ecf940edc78d$export$d07517a676ce386f(this.#element);
|
|
108
|
+
$4559ecf940edc78d$export$3484d11c6bb42ecc(this.#element);
|
|
109
|
+
this.#timeline = $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
|
+
$4559ecf940edc78d$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
|
|
124
|
+
this.#resizeObserver?.disconnect();
|
|
125
|
+
};
|
|
141
126
|
}
|
|
142
|
-
|
|
127
|
+
var $4fa36e821943b400$export$2e2bcd8739ae039 = $4fa36e821943b400$var$MarqueeContent;
|
|
143
128
|
|
|
144
129
|
|
|
145
130
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;ACAO,MAAM,4CAAW,SAAS,IAAI;IACnC,IAAI;IAEJ,OAAO,CAAC,GAAG;QACT,qBAAqB;QAErB,QAAQ,sBAAsB,IAAM,QAAQ;IAC9C;AACF;AAEO,MAAM,4CAAY,SAAS,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM;IACnE,UAAU;IAEV,WAAW,KAAK,QAAQ,CAAC;QACvB,eAAe;YACb,SAAS;YACT,OAAO;YACP,KAAK;YACL,eAAe;YACf,UAAU,CAAC;gBACT,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,OAClC,SAAS,SAAS,CAAC;qBACd,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,QACzC,SAAS,SAAS,CAAC,KAAK,SAAS;YAErC;QACF;IACF;IAEA,G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AC,UAAU,GAAG;QACZ,0CAAoB,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QAC7D,0CAAc,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE;QACjD,0CAAkB,IAAI,CAAC,CAAC,OAAO;QAC/B,0CAAa,IAAI,CAAC,CAAC,OAAO;QAE1B,IAAI,CAAC,CAAC,QAAQ,GAAG,0CAAgB,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI;IAC5F,EAAE;IAEF,CAAC,MAAM,GAAG;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAEhB,cAAc,OAAO;QACvB;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QAEzC,0CAAoB,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QAE7D,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH;IAEA,2CAAe","sources":["src/index.js","src/utils.js"],"sourcesContent":["import * as Utils from './utils.js';\n\nclass MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n constructor({element = '.marquee'} = {}) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = element instanceof HTMLElement ? element : document.querySelector(element);\n\n if (!this.#element) return;\n\n this.#resizeObserver = new ResizeObserver(Utils.debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n #commonInit = () => {\n Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);\n Utils.cloning(this.#element, this.#gsap, this.#MM);\n Utils.breakpoints(this.#element);\n Utils.skewed(this.#element);\n\n this.#timeline = Utils.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\n ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n\n Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);\n\n this.#resizeObserver?.disconnect();\n }\n}\n\nexport default MarqueeContent;\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,118 @@
|
|
|
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$var$MarqueeContent {
|
|
74
|
+
#gsap;
|
|
75
|
+
#MM;
|
|
76
|
+
#timeline;
|
|
77
|
+
#element;
|
|
78
|
+
#resizeObserver;
|
|
79
|
+
#animationFrame;
|
|
80
|
+
constructor({ element: element = ".marquee" } = {}){
|
|
81
|
+
this.#gsap = $cf838c15c8b009ba$var$MarqueeContent.gsap ?? window.gsap;
|
|
82
|
+
this.#MM = this.#gsap.matchMedia();
|
|
83
|
+
this.#timeline = null;
|
|
84
|
+
this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
|
|
85
|
+
if (!this.#element) return;
|
|
86
|
+
this.#resizeObserver = new ResizeObserver($f3ad94c9f84f4d57$export$61fc7d43ac8f84b0(()=>this.#update()));
|
|
87
|
+
this.#resizeObserver.observe(this.#element);
|
|
94
88
|
}
|
|
95
89
|
static registerGSAP(gsap) {
|
|
96
|
-
$cf838c15c8b009ba$
|
|
90
|
+
$cf838c15c8b009ba$var$MarqueeContent.gsap = gsap;
|
|
97
91
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
#commonInit = ()=>{
|
|
93
|
+
$f3ad94c9f84f4d57$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
|
|
94
|
+
$f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b(this.#element, this.#gsap, this.#MM);
|
|
95
|
+
$f3ad94c9f84f4d57$export$d07517a676ce386f(this.#element);
|
|
96
|
+
$f3ad94c9f84f4d57$export$3484d11c6bb42ecc(this.#element);
|
|
97
|
+
this.#timeline = $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
|
+
$f3ad94c9f84f4d57$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
|
|
112
|
+
this.#resizeObserver?.disconnect();
|
|
113
|
+
};
|
|
129
114
|
}
|
|
130
|
-
|
|
115
|
+
var $cf838c15c8b009ba$export$2e2bcd8739ae039 = $cf838c15c8b009ba$var$MarqueeContent;
|
|
131
116
|
|
|
132
117
|
|
|
133
118
|
export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
|