marquee-content 3.0.0 → 3.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/README.md CHANGED
@@ -46,13 +46,13 @@ MarqueeContent.registerGSAP(gsap);
46
46
 
47
47
  ➤ **Settings**
48
48
 
49
- | data- | Default | Description |
50
- |:--------------------|:-------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
51
- | `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
52
- | `data-mc-direction` | `rtl` | `rtl` &mdash; default value, no need to specify.<br>`ltr` &mdash; changes the scroll direction from left to right.<br>`auto` &mdash; automatically changes the direction of the animation when scrolling the page. |
53
- | `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (it is acceptable to use a positive or negative value). |
54
- | `data-mc-min` | `null` | Sets the minimum width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared). |
55
- | `data-mc-max` | `null` | Sets the maximum width at which the animation will be played (when the breakpoint intersects, the cloned elements will be removed and the component styles will be cleared). |
49
+ | Option | Default | Description |
50
+ |:--------------------|:-------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
51
+ | `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
52
+ | `data-mc-direction` | `rtl` | `rtl` &mdash; default value, no need to specify.<br>`ltr` &mdash; changes the scroll direction from left to right.<br>`auto` &mdash; auto changes the direction of the animation as the page is scrolled. |
53
+ | `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (a positive or negative value is acceptable). |
54
+ | `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
+ | `data-mc-max` | `null` | Sets the **maximum** width. |
56
56
 
57
57
  <br>
58
58
 
package/dist/index.js CHANGED
@@ -10,6 +10,90 @@ 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
+ function $fa2d7eec3b4b552b$var$breakpoints() {
14
+ this.breakpoint = "";
15
+ if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
16
+ else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
17
+ }
18
+ var $fa2d7eec3b4b552b$export$2e2bcd8739ae039 = $fa2d7eec3b4b552b$var$breakpoints;
19
+
20
+
21
+ function $66606e06234aec1c$var$cloning() {
22
+ const removingClones = ()=>{
23
+ while(this.childElementCount > 1)this.removeChild(this.lastChild);
24
+ };
25
+ removingClones();
26
+ this.MM.add(this.breakpoint, ()=>{
27
+ const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
28
+ if (this.childElementCount < requiredQuantity) {
29
+ const clones = Array.from({
30
+ length: requiredQuantity - 1
31
+ }, ()=>this.firstElementChild.cloneNode(true));
32
+ this.append(...clones);
33
+ }
34
+ return removingClones;
35
+ });
36
+ }
37
+ var $66606e06234aec1c$export$2e2bcd8739ae039 = $66606e06234aec1c$var$cloning;
38
+
39
+
40
+ function $8ce6f1187c98529f$var$skewed() {
41
+ if (!this.dataset.mcSkew) return;
42
+ const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
43
+ const { style: style } = this;
44
+ this.MM.add(this.breakpoint, ()=>{
45
+ style.transformOrigin = "center center";
46
+ style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
47
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
48
+ return ()=>{
49
+ style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
50
+ };
51
+ });
52
+ }
53
+ var $8ce6f1187c98529f$export$2e2bcd8739ae039 = $8ce6f1187c98529f$var$skewed;
54
+
55
+
56
+ function $26261098b528e5f4$var$clearTimeline() {
57
+ if (this.timeline) {
58
+ this.timeline.kill();
59
+ this.timeline = null;
60
+ }
61
+ this.gsap.set(this.children, {
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
+
13
97
  class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
14
98
  constructor(){
15
99
  super();
@@ -30,106 +114,29 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
30
114
  timer = requestAnimationFrame(this.update);
31
115
  };
32
116
  };
33
- breakpoints() {
34
- this.breakpoint = "";
35
- if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
36
- else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
37
- }
38
- templates() {
39
- const wrapper = document.createElement("div");
40
- wrapper.classList.add("marquee-wrapper");
41
- const inner = document.createElement("div");
42
- inner.classList.add("marquee-inner");
43
- inner.style.display = "inline-block";
44
- inner.style.whiteSpace = "nowrap";
45
- while(this.firstChild)inner.appendChild(this.firstChild);
46
- wrapper.appendChild(inner);
47
- this.appendChild(wrapper);
48
- }
49
- cloning() {
50
- const removingClones = ()=>{
51
- while(this.childElementCount > 1)this.removeChild(this.lastChild);
52
- };
53
- removingClones();
54
- this.MM.add(this.breakpoint, ()=>{
55
- const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
56
- if (this.childElementCount < requiredQuantity) {
57
- const clones = Array.from({
58
- length: requiredQuantity - 1
59
- }, ()=>this.firstElementChild.cloneNode(true));
60
- this.append(...clones);
61
- }
62
- return removingClones;
63
- });
64
- }
65
- skewed() {
66
- if (!this.dataset.mcSkew) return;
67
- const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
68
- const { style: style } = this;
69
- this.MM.add(this.breakpoint, ()=>{
70
- style.transformOrigin = "center center";
71
- style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
72
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
73
- return ()=>{
74
- style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
75
- };
76
- });
77
- }
78
- clearTimeline() {
79
- if (this.timeline) {
80
- this.timeline.kill();
81
- this.timeline = null;
82
- }
83
- this.gsap.set(this.children, {
84
- clearProps: true
85
- });
86
- }
87
- animation() {
88
- if (this.timeline) this.clearTimeline.call(this);
89
- this.MM.add(this.breakpoint, ()=>{
90
- this.timeline = this.gsap.to(this.children, {
91
- duration: this.dataset.mcDuration || 20,
92
- x: "-100%",
93
- ease: "none",
94
- repeat: -1,
95
- scrollTrigger: {
96
- trigger: this,
97
- start: "-=50% bottom",
98
- end: "bottom top",
99
- toggleActions: "resume pause resume pause",
100
- onUpdate: (self)=>{
101
- if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
102
- else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
103
- }
104
- }
105
- });
106
- this.timeline.totalProgress(0.5);
107
- return ()=>{
108
- if (this.timeline) this.clearTimeline.call(this);
109
- };
110
- });
111
- }
112
117
  update() {
113
118
  cancelAnimationFrame(this.af);
114
119
  if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
115
- this.cloning();
116
- this.animation();
120
+ (0, $66606e06234aec1c$export$2e2bcd8739ae039).call(this);
121
+ (0, $7206b27cbeabecb6$export$2e2bcd8739ae039).call(this);
117
122
  });
118
123
  }
119
124
  init() {
120
- this.breakpoints();
121
- this.templates();
122
- this.skewed();
123
- this.cloning();
124
- this.animation();
125
+ (0, $fa2d7eec3b4b552b$export$2e2bcd8739ae039).call(this);
126
+ (0, $8ce6f1187c98529f$export$2e2bcd8739ae039).call(this);
127
+ (0, $66606e06234aec1c$export$2e2bcd8739ae039).call(this);
128
+ (0, $7206b27cbeabecb6$export$2e2bcd8739ae039).call(this);
129
+ }
130
+ destroy() {
131
+ cancelAnimationFrame(this.af);
132
+ (0, $26261098b528e5f4$export$2e2bcd8739ae039).call(this);
133
+ if (this.resizeObserver) this.resizeObserver.disconnect();
125
134
  }
126
135
  connectedCallback() {
127
136
  this.init();
128
137
  }
129
138
  disconnectedCallback() {
130
- cancelAnimationFrame(this.af);
131
- this.clearTimeline();
132
- if (this.resizeObserver) this.resizeObserver.disconnect();
139
+ this.destroy();
133
140
  }
134
141
  }
135
142
  if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;AAAe,uDAA6B;IAC1C,aAAc;QACZ,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QACnC,IAA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n constructor() {\n super();\n\n this.gsap = MarqueeContent.gsap || window.gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce = () => {\n let timer;\n\n return () => {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(this.update);\n };\n };\n\n breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\n }\n }\n\n templates() {\n const wrapper = document.createElement('div');\n wrapper.classList.add('marquee-wrapper');\n\n const inner = document.createElement('div');\n inner.classList.add('marquee-inner');\n inner.style.display = 'inline-block';\n inner.style.whiteSpace = 'nowrap';\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild);\n }\n\n wrapper.appendChild(inner);\n this.appendChild(wrapper);\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild);\n }\n };\n\n removingClones();\n\n this.MM.add(this.breakpoint, () => {\n const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));\n this.append(...clones);\n }\n\n return removingClones;\n });\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));\n const { style } = this;\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';\n };\n });\n }\n\n clearTimeline() {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\n }\n\n animation() {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\n\n this.MM.add(this.breakpoint, () => {\n this.timeline = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (this.dataset.mcDirection === 'ltr') {\n this.timeline.timeScale(-1);\n } else if (this.dataset.mcDirection === 'auto') {\n this.timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.timeline.totalProgress(0.5);\n\n return () => {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\n };\n });\n }\n\n update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning();\n this.animation();\n });\n }\n }\n\n init() {\n this.breakpoints();\n this.templates();\n this.skewed();\n this.cloning();\n this.animation();\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af);\n\n this.clearTimeline();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;ACAA,SAAS;IACP,IAAI,CAAC,UAAU,GAAG;IAElB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EACpB,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC;SAC1D,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAC3B,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK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,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QAC5E,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IAClC;IAEA,OAAO,aAAa,IAAI,EAAE;QACxB,yCAAe,IAAI,GAAG;IACxB;IAEA,WAAW;QACT,IAAI;QAEJ,OAAO;YACL,qBAAqB;YACrB,QAAQ,sBAAsB,IAAI,CAAC,MAAM;QAC3C;IACF,EAAE;IAEF,SAAS;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,IAAI,CAAC,iBAAiB,EACxB,IAAI,CAAC,EAAE,GAAG,sBAAsB;YAC9B,CAAA,GAAA,wCAAM,EAAE,IAAI,CAAC,IAAI;YACjB,CAAA,GAAA,wCAAQ,EAAE,IAAI,CAAC,IAAI;QACrB;IAEJ;IAEA,OAAO;QACL,CAAA,GAAA,wCAAU,EAAE,IAAI,CAAC,IAAI;QACrB,CAAA,GAAA,wCAAK,EAAE,IAAI,CAAC,IAAI;QAChB,CAAA,GAAA,wCAAM,EAAE,IAAI,CAAC,IAAI;QACjB,CAAA,GAAA,wCAAQ,EAAE,IAAI,CAAC,IAAI;IACrB;IAEA,UAAU;QACR,qBAAqB,IAAI,CAAC,EAAE;QAE5B,CAAA,GAAA,wCAAY,EAAE,IAAI,CAAC,IAAI;QAEvB,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;IAElC;IAEA,oBAAoB;QAClB,IAAI,CAAC,IAAI;IACX;IAEA,uBAAuB;QACrB,IAAI,CAAC,OAAO;IACd;AACF;AAEA,IAAI,CAAC,eAAe,GAAG,CAAC,oBACtB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js","src/utils/breakpoints.js","src/utils/cloning.js","src/utils/skewed.js","src/utils/animation.js","src/utils/clearTimeline.js"],"sourcesContent":["import breakpoints from './utils/breakpoints';\nimport cloning from './utils/cloning';\nimport skewed from './utils/skewed';\nimport animation from './utils/animation';\nimport clearTimeline from './utils/clearTimeline';\n\nexport default class MarqueeContent extends HTMLElement {\n constructor() {\n super();\n\n this.gsap = MarqueeContent.gsap || window.gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce = () => {\n let timer;\n\n return () => {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(this.update);\n };\n };\n\n update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n cloning.call(this);\n animation.call(this);\n });\n }\n }\n\n init() {\n breakpoints.call(this);\n skewed.call(this);\n cloning.call(this);\n animation.call(this);\n }\n\n destroy() {\n cancelAnimationFrame(this.af);\n\n clearTimeline.call(this);\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n this.destroy();\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n","function breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\n }\n};\n\nexport default breakpoints;\n","function cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild);\n }\n };\n\n removingClones();\n\n this.MM.add(this.breakpoint, () => {\n const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));\n this.append(...clones);\n }\n\n return removingClones;\n });\n}\n\nexport default cloning;\n","function skewed() {\n if (!this.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));\n const { style } = this;\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';\n };\n });\n}\n\nexport default skewed;\n","import clearTimeline from './clearTimeline';\n\nfunction animation() {\n if (this.timeline) {\n clearTimeline.call(this);\n }\n\n this.MM.add(this.breakpoint, () => {\n this.timeline = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (this.dataset.mcDirection === 'ltr') {\n this.timeline.timeScale(-1);\n } else if (this.dataset.mcDirection === 'auto') {\n this.timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.timeline.totalProgress(0.5);\n\n return () => {\n if (this.timeline) {\n clearTimeline.call(this);\n }\n };\n });\n}\n\nexport default animation;\n","function clearTimeline() {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\n}\n\nexport default clearTimeline;\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -1,3 +1,87 @@
1
+ function $0247ba718e967cec$var$breakpoints() {
2
+ this.breakpoint = "";
3
+ if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
4
+ else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
5
+ }
6
+ var $0247ba718e967cec$export$2e2bcd8739ae039 = $0247ba718e967cec$var$breakpoints;
7
+
8
+
9
+ function $2b68722c48061d80$var$cloning() {
10
+ const removingClones = ()=>{
11
+ while(this.childElementCount > 1)this.removeChild(this.lastChild);
12
+ };
13
+ removingClones();
14
+ this.MM.add(this.breakpoint, ()=>{
15
+ const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
16
+ if (this.childElementCount < requiredQuantity) {
17
+ const clones = Array.from({
18
+ length: requiredQuantity - 1
19
+ }, ()=>this.firstElementChild.cloneNode(true));
20
+ this.append(...clones);
21
+ }
22
+ return removingClones;
23
+ });
24
+ }
25
+ var $2b68722c48061d80$export$2e2bcd8739ae039 = $2b68722c48061d80$var$cloning;
26
+
27
+
28
+ function $dfb0cb0db0a7e917$var$skewed() {
29
+ if (!this.dataset.mcSkew) return;
30
+ const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
31
+ const { style: style } = this;
32
+ this.MM.add(this.breakpoint, ()=>{
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;
42
+
43
+
44
+ function $44f92944fa78205a$var$clearTimeline() {
45
+ if (this.timeline) {
46
+ this.timeline.kill();
47
+ this.timeline = null;
48
+ }
49
+ this.gsap.set(this.children, {
50
+ clearProps: true
51
+ });
52
+ }
53
+ var $44f92944fa78205a$export$2e2bcd8739ae039 = $44f92944fa78205a$var$clearTimeline;
54
+
55
+
56
+ function $5138c3f25fef74d5$var$animation() {
57
+ if (this.timeline) (0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
58
+ this.MM.add(this.breakpoint, ()=>{
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
+
1
85
  class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
2
86
  constructor(){
3
87
  super();
@@ -18,106 +102,29 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
18
102
  timer = requestAnimationFrame(this.update);
19
103
  };
20
104
  };
21
- breakpoints() {
22
- this.breakpoint = "";
23
- if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
24
- else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
25
- }
26
- templates() {
27
- const wrapper = document.createElement("div");
28
- wrapper.classList.add("marquee-wrapper");
29
- const inner = document.createElement("div");
30
- inner.classList.add("marquee-inner");
31
- inner.style.display = "inline-block";
32
- inner.style.whiteSpace = "nowrap";
33
- while(this.firstChild)inner.appendChild(this.firstChild);
34
- wrapper.appendChild(inner);
35
- this.appendChild(wrapper);
36
- }
37
- cloning() {
38
- const removingClones = ()=>{
39
- while(this.childElementCount > 1)this.removeChild(this.lastChild);
40
- };
41
- removingClones();
42
- this.MM.add(this.breakpoint, ()=>{
43
- const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
44
- if (this.childElementCount < requiredQuantity) {
45
- const clones = Array.from({
46
- length: requiredQuantity - 1
47
- }, ()=>this.firstElementChild.cloneNode(true));
48
- this.append(...clones);
49
- }
50
- return removingClones;
51
- });
52
- }
53
- skewed() {
54
- if (!this.dataset.mcSkew) return;
55
- const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
56
- const { style: style } = this;
57
- this.MM.add(this.breakpoint, ()=>{
58
- style.transformOrigin = "center center";
59
- style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
60
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
61
- return ()=>{
62
- style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
63
- };
64
- });
65
- }
66
- clearTimeline() {
67
- if (this.timeline) {
68
- this.timeline.kill();
69
- this.timeline = null;
70
- }
71
- this.gsap.set(this.children, {
72
- clearProps: true
73
- });
74
- }
75
- animation() {
76
- if (this.timeline) this.clearTimeline.call(this);
77
- this.MM.add(this.breakpoint, ()=>{
78
- this.timeline = this.gsap.to(this.children, {
79
- duration: this.dataset.mcDuration || 20,
80
- x: "-100%",
81
- ease: "none",
82
- repeat: -1,
83
- scrollTrigger: {
84
- trigger: this,
85
- start: "-=50% bottom",
86
- end: "bottom top",
87
- toggleActions: "resume pause resume pause",
88
- onUpdate: (self)=>{
89
- if (this.dataset.mcDirection === "ltr") this.timeline.timeScale(-1);
90
- else if (this.dataset.mcDirection === "auto") this.timeline.timeScale(self.direction);
91
- }
92
- }
93
- });
94
- this.timeline.totalProgress(0.5);
95
- return ()=>{
96
- if (this.timeline) this.clearTimeline.call(this);
97
- };
98
- });
99
- }
100
105
  update() {
101
106
  cancelAnimationFrame(this.af);
102
107
  if (this.firstElementChild) this.af = requestAnimationFrame(()=>{
103
- this.cloning();
104
- this.animation();
108
+ (0, $2b68722c48061d80$export$2e2bcd8739ae039).call(this);
109
+ (0, $5138c3f25fef74d5$export$2e2bcd8739ae039).call(this);
105
110
  });
106
111
  }
107
112
  init() {
108
- this.breakpoints();
109
- this.templates();
110
- this.skewed();
111
- this.cloning();
112
- this.animation();
113
+ (0, $0247ba718e967cec$export$2e2bcd8739ae039).call(this);
114
+ (0, $dfb0cb0db0a7e917$export$2e2bcd8739ae039).call(this);
115
+ (0, $2b68722c48061d80$export$2e2bcd8739ae039).call(this);
116
+ (0, $5138c3f25fef74d5$export$2e2bcd8739ae039).call(this);
117
+ }
118
+ destroy() {
119
+ cancelAnimationFrame(this.af);
120
+ (0, $44f92944fa78205a$export$2e2bcd8739ae039).call(this);
121
+ if (this.resizeObserver) this.resizeObserver.disconnect();
113
122
  }
114
123
  connectedCallback() {
115
124
  this.init();
116
125
  }
117
126
  disconnectedCallback() {
118
- cancelAnimationFrame(this.af);
119
- this.clearTimeline();
120
- if (this.resizeObserver) this.resizeObserver.disconnect();
127
+ this.destroy();
121
128
  }
122
129
  }
123
130
  if (!customElements.get("marquee-content")) customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
@@ -1 +1 @@
1
- {"mappings":"AAAe,uDAA6B;IAC1C,aAAc;QACZ,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QACnC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QAC5E,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IAClC;IAEA,OAAO,aAAa,IAAI,EAAE;QACxB,yCAAe,IAAI,GAAG;IACxB;IAEA,WAAW;QACT,IAAI;QAEJ,OAAO;YACL,qBAAqB;YACrB,QAAQ,sBAAsB,IAAI,CAAC,MAAM;QAC3C;IACF,EAAE;IAEF,cAAc;QACZ,IAAI,CAAC,UAAU,GAAG;QAElB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EACpB,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OA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AAC,QAAQ,CAAC,aAAa,CAAC;YAE5B,OAAO;gBACL,IAAI,IAAI,CAAC,QAAQ,EACf,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI;YAEhC;QACF;IACF;IAEA,SAAS;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,IAAI,CAAC,iBAAiB,EACxB,IAAI,CAAC,EAAE,GAAG,sBAAsB;YAC9B,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAChB;IAEJ;IAEA,OAAO;QACL,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,SAAS;IAChB;IAEA,oBAAoB;QAClB,IAAI,CAAC,IAAI;IACX;IAEA,uBAAuB;QACrB,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;IAElC;AACF;AAEA,IAAI,CAAC,eAAe,GAAG,CAAC,oBACtB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor() {\n super();\n\n this.gsap = MarqueeContent.gsap || window.gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce = () => {\n let timer;\n\n return () => {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(this.update);\n };\n };\n\n breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\n }\n }\n\n templates() {\n const wrapper = document.createElement('div');\n wrapper.classList.add('marquee-wrapper');\n\n const inner = document.createElement('div');\n inner.classList.add('marquee-inner');\n inner.style.display = 'inline-block';\n inner.style.whiteSpace = 'nowrap';\n\n while (this.firstChild) {\n inner.appendChild(this.firstChild);\n }\n\n wrapper.appendChild(inner);\n this.appendChild(wrapper);\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild);\n }\n };\n\n removingClones();\n\n this.MM.add(this.breakpoint, () => {\n const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));\n this.append(...clones);\n }\n\n return removingClones;\n });\n }\n\n skewed() {\n if (!this.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));\n const { style } = this;\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';\n };\n });\n }\n\n clearTimeline() {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\n }\n\n animation() {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\n\n this.MM.add(this.breakpoint, () => {\n this.timeline = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (this.dataset.mcDirection === 'ltr') {\n this.timeline.timeScale(-1);\n } else if (this.dataset.mcDirection === 'auto') {\n this.timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.timeline.totalProgress(0.5);\n\n return () => {\n if (this.timeline) {\n this.clearTimeline.call(this);\n }\n };\n });\n }\n\n update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n this.cloning();\n this.animation();\n });\n }\n }\n\n init() {\n this.breakpoints();\n this.templates();\n this.skewed();\n this.cloning();\n this.animation();\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n cancelAnimationFrame(this.af);\n\n this.clearTimeline();\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"ACAA,SAAS;IACP,IAAI,CAAC,UAAU,GAAG;IAElB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EACpB,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC;SAC1D,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAC3B,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;AAE5D;IAEA,2CAAe;;;ACVf,SAAS;IACP,MAAM,iBAAiB;QACrB,MAAO,IAAI,CAAC,iBAAiB,GAAG,EAC9B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;IAEnC;IAEA;IAEA,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE;QAC3B,MAAM,mBAAmB,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,WAAW,GAAG;QAE3F,IAAI,IAAI,CAAC,iBAAiB,GAAG,kBAAkB;YAC7C,MAAM,SAAS,MAAM,IAAI,CAAC;gBAAE,QAAQ,mBAAmB;YAAE,GAAG,IAAM,IAAI,CAAC,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AI,CAAC,IAAI;QACrB;IAEJ;IAEA,OAAO;QACL,CAAA,GAAA,wCAAU,EAAE,IAAI,CAAC,IAAI;QACrB,CAAA,GAAA,wCAAK,EAAE,IAAI,CAAC,IAAI;QAChB,CAAA,GAAA,wCAAM,EAAE,IAAI,CAAC,IAAI;QACjB,CAAA,GAAA,wCAAQ,EAAE,IAAI,CAAC,IAAI;IACrB;IAEA,UAAU;QACR,qBAAqB,IAAI,CAAC,EAAE;QAE5B,CAAA,GAAA,wCAAY,EAAE,IAAI,CAAC,IAAI;QAEvB,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;IAElC;IAEA,oBAAoB;QAClB,IAAI,CAAC,IAAI;IACX;IAEA,uBAAuB;QACrB,IAAI,CAAC,OAAO;IACd;AACF;AAEA,IAAI,CAAC,eAAe,GAAG,CAAC,oBACtB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js","src/utils/breakpoints.js","src/utils/cloning.js","src/utils/skewed.js","src/utils/animation.js","src/utils/clearTimeline.js"],"sourcesContent":["import breakpoints from './utils/breakpoints';\nimport cloning from './utils/cloning';\nimport skewed from './utils/skewed';\nimport animation from './utils/animation';\nimport clearTimeline from './utils/clearTimeline';\n\nexport default class MarqueeContent extends HTMLElement {\n constructor() {\n super();\n\n this.gsap = MarqueeContent.gsap || window.gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce = () => {\n let timer;\n\n return () => {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(this.update);\n };\n };\n\n update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n cloning.call(this);\n animation.call(this);\n });\n }\n }\n\n init() {\n breakpoints.call(this);\n skewed.call(this);\n cloning.call(this);\n animation.call(this);\n }\n\n destroy() {\n cancelAnimationFrame(this.af);\n\n clearTimeline.call(this);\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n this.destroy();\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n","function breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\n }\n};\n\nexport default breakpoints;\n","function cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild);\n }\n };\n\n removingClones();\n\n this.MM.add(this.breakpoint, () => {\n const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));\n this.append(...clones);\n }\n\n return removingClones;\n });\n}\n\nexport default cloning;\n","function skewed() {\n if (!this.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));\n const { style } = this;\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';\n };\n });\n}\n\nexport default skewed;\n","import clearTimeline from './clearTimeline';\n\nfunction animation() {\n if (this.timeline) {\n clearTimeline.call(this);\n }\n\n this.MM.add(this.breakpoint, () => {\n this.timeline = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (this.dataset.mcDirection === 'ltr') {\n this.timeline.timeScale(-1);\n } else if (this.dataset.mcDirection === 'auto') {\n this.timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.timeline.totalProgress(0.5);\n\n return () => {\n if (this.timeline) {\n clearTimeline.call(this);\n }\n };\n });\n}\n\nexport default animation;\n","function clearTimeline() {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\n}\n\nexport default clearTimeline;\n"],"names":[],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Class for creating the running content effect, also known as a marquee or ticker.",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
@@ -23,17 +23,17 @@
23
23
  }
24
24
  },
25
25
  "scripts": {
26
- "serve": "parcel src/index.html --dist-dir dist --cache-dir .parcel --no-source-maps --open",
27
- "build": "parcel build",
28
26
  "clean": "rm -rf dist .parcel-cache",
29
- "lint:js": "eslint --ext .js,.vue .",
27
+ "serve": "parcel src/index.html --dist-dir dist --cache-dir .parcel --no-source-maps --open",
28
+ "build": "yarn clean && parcel build",
29
+ "lint:js": "eslint --ext .js",
30
30
  "lintfix": "yarn lint:js --fix"
31
31
  },
32
32
  "devDependencies": {
33
33
  "eslint": "^7.32.0 || ^8.52.0",
34
34
  "eslint-config-airbnb-base": "^15.0.0",
35
35
  "eslint-plugin-import": "^2.29.0",
36
- "parcel": "^2.10.1",
36
+ "parcel": "^2.10.2",
37
37
  "postcss-html": "^1.5.0"
38
38
  },
39
39
  "keywords": [
package/src/index.html CHANGED
@@ -41,7 +41,7 @@
41
41
  pointer-events: none;
42
42
  }
43
43
 
44
- .marquee-wrapper {
44
+ marquee-content > * {
45
45
  will-change: transform;
46
46
  }
47
47
 
@@ -141,6 +141,10 @@
141
141
 
142
142
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
143
143
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
144
- <script type="module" src="demo.js"></script>
144
+ <script type="module" src="index.js"></script>
145
+ <script>
146
+ gsap.registerPlugin(ScrollTrigger);
147
+ MarqueeContent.registerGSAP(gsap);
148
+ </script>
145
149
  </body>
146
150
  </html>
package/src/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ import breakpoints from './utils/breakpoints';
2
+ import cloning from './utils/cloning';
3
+ import skewed from './utils/skewed';
4
+ import animation from './utils/animation';
5
+ import clearTimeline from './utils/clearTimeline';
6
+
1
7
  export default class MarqueeContent extends HTMLElement {
2
8
  constructor() {
3
9
  super();
@@ -23,148 +29,41 @@ export default class MarqueeContent extends HTMLElement {
23
29
  };
24
30
  };
25
31
 
26
- breakpoints() {
27
- this.breakpoint = '';
28
-
29
- if (this.dataset.mcMax) {
30
- this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
31
- } else if (this.dataset.mcMin) {
32
- this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
33
- }
34
- }
35
-
36
- templates() {
37
- const wrapper = document.createElement('div');
38
- wrapper.classList.add('marquee-wrapper');
39
-
40
- const inner = document.createElement('div');
41
- inner.classList.add('marquee-inner');
42
- inner.style.display = 'inline-block';
43
- inner.style.whiteSpace = 'nowrap';
44
-
45
- while (this.firstChild) {
46
- inner.appendChild(this.firstChild);
47
- }
48
-
49
- wrapper.appendChild(inner);
50
- this.appendChild(wrapper);
51
- }
52
-
53
- cloning() {
54
- const removingClones = () => {
55
- while (this.childElementCount > 1) {
56
- this.removeChild(this.lastChild);
57
- }
58
- };
59
-
60
- removingClones();
61
-
62
- this.MM.add(this.breakpoint, () => {
63
- const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
64
-
65
- if (this.childElementCount < requiredQuantity) {
66
- const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));
67
- this.append(...clones);
68
- }
69
-
70
- return removingClones;
71
- });
72
- }
73
-
74
- skewed() {
75
- if (!this.dataset.mcSkew) return;
76
-
77
- const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
78
- const { style } = this;
79
-
80
- this.MM.add(this.breakpoint, () => {
81
- style.transformOrigin = 'center center';
82
- style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
83
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
84
-
85
- return () => {
86
- style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';
87
- };
88
- });
89
- }
90
-
91
- clearTimeline() {
92
- if (this.timeline) {
93
- this.timeline.kill();
94
- this.timeline = null;
95
- }
96
-
97
- this.gsap.set(this.children, { clearProps: true });
98
- }
99
-
100
- animation() {
101
- if (this.timeline) {
102
- this.clearTimeline.call(this);
103
- }
104
-
105
- this.MM.add(this.breakpoint, () => {
106
- this.timeline = this.gsap.to(this.children, {
107
- duration: this.dataset.mcDuration || 20,
108
- x: '-100%',
109
- ease: 'none',
110
- repeat: -1,
111
- scrollTrigger: {
112
- trigger: this,
113
- start: '-=50% bottom',
114
- end: 'bottom top',
115
- toggleActions: 'resume pause resume pause',
116
- onUpdate: (self) => {
117
- if (this.dataset.mcDirection === 'ltr') {
118
- this.timeline.timeScale(-1);
119
- } else if (this.dataset.mcDirection === 'auto') {
120
- this.timeline.timeScale(self.direction);
121
- }
122
- },
123
- },
124
- });
125
-
126
- this.timeline.totalProgress(0.5);
127
-
128
- return () => {
129
- if (this.timeline) {
130
- this.clearTimeline.call(this);
131
- }
132
- };
133
- });
134
- }
135
-
136
32
  update() {
137
33
  cancelAnimationFrame(this.af);
138
34
 
139
35
  if (this.firstElementChild) {
140
36
  this.af = requestAnimationFrame(() => {
141
- this.cloning();
142
- this.animation();
37
+ cloning.call(this);
38
+ animation.call(this);
143
39
  });
144
40
  }
145
41
  }
146
42
 
147
43
  init() {
148
- this.breakpoints();
149
- this.templates();
150
- this.skewed();
151
- this.cloning();
152
- this.animation();
44
+ breakpoints.call(this);
45
+ skewed.call(this);
46
+ cloning.call(this);
47
+ animation.call(this);
153
48
  }
154
49
 
155
- connectedCallback() {
156
- this.init();
157
- }
158
-
159
- disconnectedCallback() {
50
+ destroy() {
160
51
  cancelAnimationFrame(this.af);
161
52
 
162
- this.clearTimeline();
53
+ clearTimeline.call(this);
163
54
 
164
55
  if (this.resizeObserver) {
165
56
  this.resizeObserver.disconnect();
166
57
  }
167
58
  }
59
+
60
+ connectedCallback() {
61
+ this.init();
62
+ }
63
+
64
+ disconnectedCallback() {
65
+ this.destroy();
66
+ }
168
67
  }
169
68
 
170
69
  if (!customElements.get('marquee-content')) {
@@ -0,0 +1,39 @@
1
+ import clearTimeline from './clearTimeline';
2
+
3
+ function animation() {
4
+ if (this.timeline) {
5
+ clearTimeline.call(this);
6
+ }
7
+
8
+ this.MM.add(this.breakpoint, () => {
9
+ this.timeline = this.gsap.to(this.children, {
10
+ duration: this.dataset.mcDuration || 20,
11
+ x: '-100%',
12
+ repeat: -1,
13
+ ease: 'none',
14
+ scrollTrigger: {
15
+ trigger: this,
16
+ start: '-=50% bottom',
17
+ end: 'bottom top',
18
+ toggleActions: 'resume pause resume pause',
19
+ onUpdate: (self) => {
20
+ if (this.dataset.mcDirection === 'ltr') {
21
+ this.timeline.timeScale(-1);
22
+ } else if (this.dataset.mcDirection === 'auto') {
23
+ this.timeline.timeScale(self.direction);
24
+ }
25
+ },
26
+ },
27
+ });
28
+
29
+ this.timeline.totalProgress(0.5);
30
+
31
+ return () => {
32
+ if (this.timeline) {
33
+ clearTimeline.call(this);
34
+ }
35
+ };
36
+ });
37
+ }
38
+
39
+ export default animation;
@@ -0,0 +1,11 @@
1
+ function breakpoints() {
2
+ this.breakpoint = '';
3
+
4
+ if (this.dataset.mcMax) {
5
+ this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
6
+ } else if (this.dataset.mcMin) {
7
+ this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
8
+ }
9
+ };
10
+
11
+ export default breakpoints;
@@ -0,0 +1,10 @@
1
+ function clearTimeline() {
2
+ if (this.timeline) {
3
+ this.timeline.kill();
4
+ this.timeline = null;
5
+ }
6
+
7
+ this.gsap.set(this.children, { clearProps: true });
8
+ }
9
+
10
+ export default clearTimeline;
@@ -0,0 +1,22 @@
1
+ function cloning() {
2
+ const removingClones = () => {
3
+ while (this.childElementCount > 1) {
4
+ this.removeChild(this.lastChild);
5
+ }
6
+ };
7
+
8
+ removingClones();
9
+
10
+ this.MM.add(this.breakpoint, () => {
11
+ const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
12
+
13
+ if (this.childElementCount < requiredQuantity) {
14
+ const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));
15
+ this.append(...clones);
16
+ }
17
+
18
+ return removingClones;
19
+ });
20
+ }
21
+
22
+ export default cloning;
@@ -0,0 +1,18 @@
1
+ function skewed() {
2
+ if (!this.dataset.mcSkew) return;
3
+
4
+ const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));
5
+ const { style } = this;
6
+
7
+ this.MM.add(this.breakpoint, () => {
8
+ style.transformOrigin = 'center center';
9
+ style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;
10
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
11
+
12
+ return () => {
13
+ style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';
14
+ };
15
+ });
16
+ }
17
+
18
+ export default skewed;
@@ -0,0 +1,12 @@
1
+ function update() {
2
+ cancelAnimationFrame(this.af);
3
+
4
+ if (this.firstElementChild) {
5
+ this.af = requestAnimationFrame(() => {
6
+ cloning.call(this);
7
+ animation.call(this);
8
+ });
9
+ }
10
+ }
11
+
12
+ export default update;
package/src/demo.js DELETED
@@ -1,4 +0,0 @@
1
- import MarqueeContent from './index';
2
-
3
- gsap.registerPlugin(ScrollTrigger);
4
- MarqueeContent.registerGSAP(gsap);