marquee-content 1.9.5 → 1.9.8

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/dist/index.js CHANGED
@@ -1,17 +1,34 @@
1
- class $4fa36e821943b400$var$MarqueeContent extends HTMLElement {
2
- static registerGSAP(gsap) {
3
- $4fa36e821943b400$var$MarqueeContent.gsap = gsap;
4
- }
1
+ function $parcel$defineInteropFlag(a) {
2
+ Object.defineProperty(a, '__esModule', {value: true, configurable: true});
3
+ }
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$defineInteropFlag(module.exports);
9
+
10
+ $parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
11
+ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
5
12
  constructor(query){
6
13
  super();
7
- this.gsap = $4fa36e821943b400$var$MarqueeContent.gsap || window.gsap;
14
+ this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
15
+ this.MM = this.gsap.matchMedia(query);
8
16
  this.dataSkew = this.dataset.mcSkew;
9
17
  this.dataDuration = this.dataset.mcDuration || 20;
10
18
  this.dataDirection = this.dataset.mcDirection;
11
19
  this.dataMaxWidth = this.dataset.mcMax;
12
20
  this.dataMinWidth = this.dataset.mcMin;
13
21
  this.breakpoint = this.dataMaxWidth ? `(max-width: ${this.dataMaxWidth - 0.02}px)` : this.dataMinWidth ? `(min-width: ${this.dataMinWidth}px)` : "";
14
- this.debounce();
22
+ }
23
+ static registerGSAP(gsap) {
24
+ $4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
25
+ }
26
+ static use(...plugins) {
27
+ plugins.forEach((plugin)=>{
28
+ const name = plugin.pluginName;
29
+ if (typeof name !== "string") throw new TypeError("Invalid plugin. Name is required.");
30
+ $4fa36e821943b400$export$2e2bcd8739ae039.plugins[name] = plugin;
31
+ });
15
32
  }
16
33
  debounce(fn, delay) {
17
34
  let timer;
@@ -32,30 +49,30 @@ class $4fa36e821943b400$var$MarqueeContent extends HTMLElement {
32
49
  while(this.childElementCount > 1)this.removeChild(this.lastChild);
33
50
  };
34
51
  removingClones();
35
- // gsap.matchMedia().add(this.breakpoint, () => {
36
- let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
37
- if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
38
- let cloned = this.firstElementChild;
39
- let clone = cloned.cloneNode(true);
40
- cloned.parentNode.append(clone);
41
- }
42
- return ()=>{
43
- removingClones();
44
- };
45
- // })
52
+ this.MM.add(this.breakpoint, ()=>{
53
+ let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
54
+ if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
55
+ let cloned = this.firstElementChild;
56
+ let clone = cloned.cloneNode(true);
57
+ cloned.parentNode.append(clone);
58
+ }
59
+ return ()=>{
60
+ removingClones();
61
+ };
62
+ });
46
63
  }
47
64
  skewed() {
48
65
  if (!this.dataSkew) return;
49
66
  const abs = Math.abs(parseInt(this.dataSkew));
50
67
  const style = this.style;
51
- // gsap.matchMedia().add(this.breakpoint, () => {
52
- style.transformOrigin = "center center";
53
- style.transform = `skew(0deg, ${this.dataSkew}deg)`;
54
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
55
- return ()=>{
56
- style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
57
- };
58
- // })
68
+ this.MM.add(this.breakpoint, ()=>{
69
+ style.transformOrigin = "center center";
70
+ style.transform = `skew(0deg, ${this.dataSkew}deg)`;
71
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
72
+ return ()=>{
73
+ style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
74
+ };
75
+ });
59
76
  }
60
77
  animation() {
61
78
  let timeLine = this.gsap.timeline();
@@ -64,57 +81,57 @@ class $4fa36e821943b400$var$MarqueeContent extends HTMLElement {
64
81
  this.gsap.set(this.children, {
65
82
  clearProps: true
66
83
  });
67
- // gsap.matchMedia().add(this.breakpoint, () => {
68
- this.gsap.set(this.children, {
69
- "will-change": "transform"
70
- });
71
- const tween = this.gsap.to(this.children, {
72
- duration: this.dataDuration,
73
- x: "-100%",
74
- ease: "none",
75
- repeat: -1,
76
- scrollTrigger: {
77
- trigger: this,
78
- start: "-=50% bottom",
79
- end: "bottom top",
80
- toggleActions: "resume pause resume pause"
81
- }
82
- }).totalProgress(0.5);
83
- const ltrDirection = ()=>{
84
- this.gsap.to(tween, {
85
- timeScale: -1,
86
- overwrite: true
84
+ this.MM.add(this.breakpoint, ()=>{
85
+ this.gsap.set(this.children, {
86
+ "will-change": "transform"
87
87
  });
88
- };
89
- const autoDirection = ()=>{
90
- let previousScrollPosition = 0;
91
- const isScrollingDown = ()=>{
92
- const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
93
- let direction = false;
94
- if (scrollPosition > previousScrollPosition) direction = true;
95
- else if (scrollPosition < previousScrollPosition) direction = false;
96
- previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
97
- return direction;
98
- };
99
- addEventListener("scroll", this.debounce(()=>{
100
- const scrollDirection = isScrollingDown();
88
+ const tween = this.gsap.to(this.children, {
89
+ duration: this.dataDuration,
90
+ x: "-100%",
91
+ ease: "none",
92
+ repeat: -1,
93
+ scrollTrigger: {
94
+ trigger: this,
95
+ start: "-=50% bottom",
96
+ end: "bottom top",
97
+ toggleActions: "resume pause resume pause"
98
+ }
99
+ }).totalProgress(0.5);
100
+ const ltrDirection = ()=>{
101
101
  this.gsap.to(tween, {
102
- timeScale: scrollDirection ? 1 : -1,
102
+ timeScale: -1,
103
103
  overwrite: true
104
104
  });
105
- }, 50), {
106
- capture: true,
107
- passive: true
108
- });
109
- };
110
- if (this.dataDirection === "ltr") ltrDirection();
111
- else if (this.dataDirection === "auto") autoDirection();
112
- return ()=>{
113
- this.gsap.set(this.children, {
114
- clearProps: true
115
- });
116
- };
117
- // })
105
+ };
106
+ const autoDirection = ()=>{
107
+ let previousScrollPosition = 0;
108
+ const isScrollingDown = ()=>{
109
+ const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
110
+ let direction = false;
111
+ if (scrollPosition > previousScrollPosition) direction = true;
112
+ else if (scrollPosition < previousScrollPosition) direction = false;
113
+ previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
114
+ return direction;
115
+ };
116
+ addEventListener("scroll", this.debounce(()=>{
117
+ const scrollDirection = isScrollingDown();
118
+ this.gsap.to(tween, {
119
+ timeScale: scrollDirection ? 1 : -1,
120
+ overwrite: true
121
+ });
122
+ }, 50), {
123
+ capture: true,
124
+ passive: true
125
+ });
126
+ };
127
+ if (this.dataDirection === "ltr") ltrDirection();
128
+ else if (this.dataDirection === "auto") autoDirection();
129
+ return ()=>{
130
+ this.gsap.set(this.children, {
131
+ clearProps: true
132
+ });
133
+ };
134
+ });
118
135
  }
119
136
  onResize() {
120
137
  cancelAnimationFrame(this.af);
@@ -124,6 +141,7 @@ class $4fa36e821943b400$var$MarqueeContent extends HTMLElement {
124
141
  });
125
142
  }
126
143
  onUpdate() {
144
+ this.plugin = {};
127
145
  this.templates();
128
146
  this.cloning();
129
147
  this.skewed();
@@ -136,11 +154,11 @@ class $4fa36e821943b400$var$MarqueeContent extends HTMLElement {
136
154
  this.onUpdate();
137
155
  }
138
156
  disconnectedCallback() {
139
- // gsap.matchMedia().remove()
157
+ this.MM.remove();
140
158
  document.fonts.removeEventListener("loadingdone", this.onUpdate);
141
159
  }
142
160
  }
143
- customElements.define("marquee-content", $4fa36e821943b400$var$MarqueeContent);
161
+ customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
144
162
 
145
163
 
146
164
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"AAAA,MAAM,6CAAuB;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AM;QACX,IAAI,CAAC,SAAS;QAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,6BAA6B;QAE7B,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["class MarqueeContent extends HTMLElement {\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\n this.debounce()\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild)\n }\n }\n\n removingClones()\n\n // gsap.matchMedia().add(this.breakpoint, () => {\n let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n // })\n }\n\n skewed() {\n if (!this.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n // gsap.matchMedia().add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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 animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n // gsap.matchMedia().add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataDuration,\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 },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n // })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n // gsap.matchMedia().remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,YAAY,KAAK,CAAE;QACf,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI;QAC/C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,GAC7B,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,GAAG,KAAK,GAAG,CAAC,GAC5C,IAAI,CAAC,YAAY,GACb,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GACrC,EAAE;IAChB;IAEA,OAAO,aAAa,IAAI,EAAE;QACt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AC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,IAAI,CAAC,EAAE,CAAC,MAAM;QAEd,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia(query)\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n static use(...plugins) {\n plugins.forEach((plugin) => {\n const name = plugin.pluginName\n if (typeof name !== 'string') throw new TypeError('Invalid plugin. Name is required.')\n MarqueeContent.plugins[name] = plugin\n })\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\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 let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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 animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataDuration,\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 },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.plugin = {}\n\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n this.MM.remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.js.map"}
@@ -1,18 +1,24 @@
1
- var $cf838c15c8b009ba$exports = {};
2
- class $cf838c15c8b009ba$var$MarqueeContent extends HTMLElement {
3
- static registerGSAP(gsap) {
4
- $cf838c15c8b009ba$var$MarqueeContent.gsap = gsap;
5
- }
1
+ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
6
2
  constructor(query){
7
3
  super();
8
- this.gsap = $cf838c15c8b009ba$var$MarqueeContent.gsap || window.gsap;
4
+ this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
5
+ this.MM = this.gsap.matchMedia(query);
9
6
  this.dataSkew = this.dataset.mcSkew;
10
7
  this.dataDuration = this.dataset.mcDuration || 20;
11
8
  this.dataDirection = this.dataset.mcDirection;
12
9
  this.dataMaxWidth = this.dataset.mcMax;
13
10
  this.dataMinWidth = this.dataset.mcMin;
14
11
  this.breakpoint = this.dataMaxWidth ? `(max-width: ${this.dataMaxWidth - 0.02}px)` : this.dataMinWidth ? `(min-width: ${this.dataMinWidth}px)` : "";
15
- this.debounce();
12
+ }
13
+ static registerGSAP(gsap) {
14
+ $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
15
+ }
16
+ static use(...plugins) {
17
+ plugins.forEach((plugin)=>{
18
+ const name = plugin.pluginName;
19
+ if (typeof name !== "string") throw new TypeError("Invalid plugin. Name is required.");
20
+ $cf838c15c8b009ba$export$2e2bcd8739ae039.plugins[name] = plugin;
21
+ });
16
22
  }
17
23
  debounce(fn, delay) {
18
24
  let timer;
@@ -33,30 +39,30 @@ class $cf838c15c8b009ba$var$MarqueeContent extends HTMLElement {
33
39
  while(this.childElementCount > 1)this.removeChild(this.lastChild);
34
40
  };
35
41
  removingClones();
36
- // gsap.matchMedia().add(this.breakpoint, () => {
37
- let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
38
- if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
39
- let cloned = this.firstElementChild;
40
- let clone = cloned.cloneNode(true);
41
- cloned.parentNode.append(clone);
42
- }
43
- return ()=>{
44
- removingClones();
45
- };
46
- // })
42
+ this.MM.add(this.breakpoint, ()=>{
43
+ let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
44
+ if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
45
+ let cloned = this.firstElementChild;
46
+ let clone = cloned.cloneNode(true);
47
+ cloned.parentNode.append(clone);
48
+ }
49
+ return ()=>{
50
+ removingClones();
51
+ };
52
+ });
47
53
  }
48
54
  skewed() {
49
55
  if (!this.dataSkew) return;
50
56
  const abs = Math.abs(parseInt(this.dataSkew));
51
57
  const style = this.style;
52
- // gsap.matchMedia().add(this.breakpoint, () => {
53
- style.transformOrigin = "center center";
54
- style.transform = `skew(0deg, ${this.dataSkew}deg)`;
55
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
56
- return ()=>{
57
- style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
58
- };
59
- // })
58
+ this.MM.add(this.breakpoint, ()=>{
59
+ style.transformOrigin = "center center";
60
+ style.transform = `skew(0deg, ${this.dataSkew}deg)`;
61
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
62
+ return ()=>{
63
+ style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
64
+ };
65
+ });
60
66
  }
61
67
  animation() {
62
68
  let timeLine = this.gsap.timeline();
@@ -65,57 +71,57 @@ class $cf838c15c8b009ba$var$MarqueeContent extends HTMLElement {
65
71
  this.gsap.set(this.children, {
66
72
  clearProps: true
67
73
  });
68
- // gsap.matchMedia().add(this.breakpoint, () => {
69
- this.gsap.set(this.children, {
70
- "will-change": "transform"
71
- });
72
- const tween = this.gsap.to(this.children, {
73
- duration: this.dataDuration,
74
- x: "-100%",
75
- ease: "none",
76
- repeat: -1,
77
- scrollTrigger: {
78
- trigger: this,
79
- start: "-=50% bottom",
80
- end: "bottom top",
81
- toggleActions: "resume pause resume pause"
82
- }
83
- }).totalProgress(0.5);
84
- const ltrDirection = ()=>{
85
- this.gsap.to(tween, {
86
- timeScale: -1,
87
- overwrite: true
74
+ this.MM.add(this.breakpoint, ()=>{
75
+ this.gsap.set(this.children, {
76
+ "will-change": "transform"
88
77
  });
89
- };
90
- const autoDirection = ()=>{
91
- let previousScrollPosition = 0;
92
- const isScrollingDown = ()=>{
93
- const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
94
- let direction = false;
95
- if (scrollPosition > previousScrollPosition) direction = true;
96
- else if (scrollPosition < previousScrollPosition) direction = false;
97
- previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
98
- return direction;
99
- };
100
- addEventListener("scroll", this.debounce(()=>{
101
- const scrollDirection = isScrollingDown();
78
+ const tween = this.gsap.to(this.children, {
79
+ duration: this.dataDuration,
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
+ }
89
+ }).totalProgress(0.5);
90
+ const ltrDirection = ()=>{
102
91
  this.gsap.to(tween, {
103
- timeScale: scrollDirection ? 1 : -1,
92
+ timeScale: -1,
104
93
  overwrite: true
105
94
  });
106
- }, 50), {
107
- capture: true,
108
- passive: true
109
- });
110
- };
111
- if (this.dataDirection === "ltr") ltrDirection();
112
- else if (this.dataDirection === "auto") autoDirection();
113
- return ()=>{
114
- this.gsap.set(this.children, {
115
- clearProps: true
116
- });
117
- };
118
- // })
95
+ };
96
+ const autoDirection = ()=>{
97
+ let previousScrollPosition = 0;
98
+ const isScrollingDown = ()=>{
99
+ const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
100
+ let direction = false;
101
+ if (scrollPosition > previousScrollPosition) direction = true;
102
+ else if (scrollPosition < previousScrollPosition) direction = false;
103
+ previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
104
+ return direction;
105
+ };
106
+ addEventListener("scroll", this.debounce(()=>{
107
+ const scrollDirection = isScrollingDown();
108
+ this.gsap.to(tween, {
109
+ timeScale: scrollDirection ? 1 : -1,
110
+ overwrite: true
111
+ });
112
+ }, 50), {
113
+ capture: true,
114
+ passive: true
115
+ });
116
+ };
117
+ if (this.dataDirection === "ltr") ltrDirection();
118
+ else if (this.dataDirection === "auto") autoDirection();
119
+ return ()=>{
120
+ this.gsap.set(this.children, {
121
+ clearProps: true
122
+ });
123
+ };
124
+ });
119
125
  }
120
126
  onResize() {
121
127
  cancelAnimationFrame(this.af);
@@ -125,6 +131,7 @@ class $cf838c15c8b009ba$var$MarqueeContent extends HTMLElement {
125
131
  });
126
132
  }
127
133
  onUpdate() {
134
+ this.plugin = {};
128
135
  this.templates();
129
136
  this.cloning();
130
137
  this.skewed();
@@ -137,12 +144,12 @@ class $cf838c15c8b009ba$var$MarqueeContent extends HTMLElement {
137
144
  this.onUpdate();
138
145
  }
139
146
  disconnectedCallback() {
140
- // gsap.matchMedia().remove()
147
+ this.MM.remove();
141
148
  document.fonts.removeEventListener("loadingdone", this.onUpdate);
142
149
  }
143
150
  }
144
- customElements.define("marquee-content", $cf838c15c8b009ba$var$MarqueeContent);
151
+ customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
145
152
 
146
153
 
147
- export {$cf838c15c8b009ba$exports as default};
154
+ export {$cf838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IAAI,CAAC,SAAS;QAClB;IACJ;IAEA,WAAW;QACP,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;QAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,6BAA6B;QAE7B,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["class MarqueeContent extends HTMLElement {\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\n this.debounce()\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\n }\n\n cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild)\n }\n }\n\n removingClones()\n\n // gsap.matchMedia().add(this.breakpoint, () => {\n let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n // })\n }\n\n skewed() {\n if (!this.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n // gsap.matchMedia().add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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 animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n // gsap.matchMedia().add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataDuration,\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 },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n // })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n // gsap.matchMedia().remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"AAAe,uDAA6B;IACxC,YAAY,KAAK,CAAE;QACf,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,yCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI;QAC/C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,GAC7B,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,GAAG,KAAK,GAAG,CAAC,GAC5C,IAAI,CAAC,YAAY,GACb,CAAC,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AAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,IAAI,CAAC,EAAE,CAAC,MAAM;QAEd,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["export default class MarqueeContent extends HTMLElement {\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia(query)\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n static use(...plugins) {\n plugins.forEach((plugin) => {\n const name = plugin.pluginName\n if (typeof name !== 'string') throw new TypeError('Invalid plugin. Name is required.')\n MarqueeContent.plugins[name] = plugin\n })\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\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 let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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 animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataDuration,\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 },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.plugin = {}\n\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n this.MM.remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"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": "1.9.5",
3
+ "version": "1.9.8",
4
4
  "description": "Infinite marquee animation with GSAP",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
package/src/index.js CHANGED
@@ -1,12 +1,9 @@
1
- class MarqueeContent extends HTMLElement {
2
- static registerGSAP(gsap) {
3
- MarqueeContent.gsap = gsap
4
- }
5
-
1
+ export default class MarqueeContent extends HTMLElement {
6
2
  constructor(query) {
7
3
  super()
8
4
 
9
5
  this.gsap = MarqueeContent.gsap || window.gsap
6
+ this.MM = this.gsap.matchMedia(query)
10
7
  this.dataSkew = this.dataset.mcSkew
11
8
  this.dataDuration = this.dataset.mcDuration || 20
12
9
  this.dataDirection = this.dataset.mcDirection
@@ -17,7 +14,18 @@ class MarqueeContent extends HTMLElement {
17
14
  : this.dataMinWidth
18
15
  ? `(min-width: ${this.dataMinWidth}px)`
19
16
  : ''
20
- this.debounce()
17
+ }
18
+
19
+ static registerGSAP(gsap) {
20
+ MarqueeContent.gsap = gsap
21
+ }
22
+
23
+ static use(...plugins) {
24
+ plugins.forEach((plugin) => {
25
+ const name = plugin.pluginName
26
+ if (typeof name !== 'string') throw new TypeError('Invalid plugin. Name is required.')
27
+ MarqueeContent.plugins[name] = plugin
28
+ })
21
29
  }
22
30
 
23
31
  debounce(fn, delay) {
@@ -51,21 +59,21 @@ class MarqueeContent extends HTMLElement {
51
59
 
52
60
  removingClones()
53
61
 
54
- // gsap.matchMedia().add(this.breakpoint, () => {
55
- let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)
62
+ this.MM.add(this.breakpoint, () => {
63
+ let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)
56
64
 
57
- if (this.childElementCount < requiredQuantity) {
58
- for (let i = 1; i < requiredQuantity; i++) {
59
- let cloned = this.firstElementChild
60
- let clone = cloned.cloneNode(true)
61
- cloned.parentNode.append(clone)
65
+ if (this.childElementCount < requiredQuantity) {
66
+ for (let i = 1; i < requiredQuantity; i++) {
67
+ let cloned = this.firstElementChild
68
+ let clone = cloned.cloneNode(true)
69
+ cloned.parentNode.append(clone)
70
+ }
62
71
  }
63
- }
64
72
 
65
- return () => {
66
- removingClones()
67
- }
68
- // })
73
+ return () => {
74
+ removingClones()
75
+ }
76
+ })
69
77
  }
70
78
 
71
79
  skewed() {
@@ -74,15 +82,15 @@ class MarqueeContent extends HTMLElement {
74
82
  const abs = Math.abs(parseInt(this.dataSkew))
75
83
  const style = this.style
76
84
 
77
- // gsap.matchMedia().add(this.breakpoint, () => {
78
- style.transformOrigin = 'center center'
79
- style.transform = `skew(0deg, ${this.dataSkew}deg)`
80
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
85
+ this.MM.add(this.breakpoint, () => {
86
+ style.transformOrigin = 'center center'
87
+ style.transform = `skew(0deg, ${this.dataSkew}deg)`
88
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`
81
89
 
82
- return () => {
83
- style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'
84
- }
85
- // })
90
+ return () => {
91
+ style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;'
92
+ }
93
+ })
86
94
  }
87
95
 
88
96
  animation() {
@@ -93,70 +101,70 @@ class MarqueeContent extends HTMLElement {
93
101
 
94
102
  this.gsap.set(this.children, { clearProps: true })
95
103
 
96
- // gsap.matchMedia().add(this.breakpoint, () => {
97
- this.gsap.set(this.children, { 'will-change': 'transform' })
98
-
99
- const tween = this.gsap.to(this.children, {
100
- duration: this.dataDuration,
101
- x: '-100%',
102
- ease: 'none',
103
- repeat: -1,
104
- scrollTrigger: {
105
- trigger: this,
106
- start: '-=50% bottom',
107
- end: 'bottom top',
108
- toggleActions: 'resume pause resume pause',
109
- },
110
- }).totalProgress(0.5)
111
-
112
- const ltrDirection = () => {
113
- this.gsap.to(tween, {
114
- timeScale: -1,
115
- overwrite: true
116
- })
117
- }
104
+ this.MM.add(this.breakpoint, () => {
105
+ this.gsap.set(this.children, { 'will-change': 'transform' })
106
+
107
+ const tween = this.gsap.to(this.children, {
108
+ duration: this.dataDuration,
109
+ x: '-100%',
110
+ ease: 'none',
111
+ repeat: -1,
112
+ scrollTrigger: {
113
+ trigger: this,
114
+ start: '-=50% bottom',
115
+ end: 'bottom top',
116
+ toggleActions: 'resume pause resume pause',
117
+ },
118
+ }).totalProgress(0.5)
119
+
120
+ const ltrDirection = () => {
121
+ this.gsap.to(tween, {
122
+ timeScale: -1,
123
+ overwrite: true
124
+ })
125
+ }
118
126
 
119
- const autoDirection = () => {
120
- let previousScrollPosition = 0
127
+ const autoDirection = () => {
128
+ let previousScrollPosition = 0
121
129
 
122
- const isScrollingDown = () => {
123
- const scrollPosition = window.pageYOffset || document.documentElement.scrollTop
130
+ const isScrollingDown = () => {
131
+ const scrollPosition = window.pageYOffset || document.documentElement.scrollTop
124
132
 
125
- let direction = false
133
+ let direction = false
126
134
 
127
- if (scrollPosition > previousScrollPosition) {
128
- direction = true
129
- } else if (scrollPosition < previousScrollPosition) {
130
- direction = false
131
- }
135
+ if (scrollPosition > previousScrollPosition) {
136
+ direction = true
137
+ } else if (scrollPosition < previousScrollPosition) {
138
+ direction = false
139
+ }
132
140
 
133
- previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition
141
+ previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition
134
142
 
135
- return direction
136
- }
143
+ return direction
144
+ }
137
145
 
138
- addEventListener('scroll', this.debounce(() => {
139
- const scrollDirection = isScrollingDown()
146
+ addEventListener('scroll', this.debounce(() => {
147
+ const scrollDirection = isScrollingDown()
140
148
 
141
- this.gsap.to(tween, {
142
- timeScale: scrollDirection ? 1 : -1,
143
- overwrite: true,
149
+ this.gsap.to(tween, {
150
+ timeScale: scrollDirection ? 1 : -1,
151
+ overwrite: true,
152
+ })
153
+ }, 50), {
154
+ capture: true, passive: true
144
155
  })
145
- }, 50), {
146
- capture: true, passive: true
147
- })
148
- }
156
+ }
149
157
 
150
- if (this.dataDirection === 'ltr') {
151
- ltrDirection()
152
- } else if (this.dataDirection === 'auto') {
153
- autoDirection()
154
- }
158
+ if (this.dataDirection === 'ltr') {
159
+ ltrDirection()
160
+ } else if (this.dataDirection === 'auto') {
161
+ autoDirection()
162
+ }
155
163
 
156
- return () => {
157
- this.gsap.set(this.children, { clearProps: true })
158
- }
159
- // })
164
+ return () => {
165
+ this.gsap.set(this.children, { clearProps: true })
166
+ }
167
+ })
160
168
  }
161
169
 
162
170
  onResize() {
@@ -169,6 +177,8 @@ class MarqueeContent extends HTMLElement {
169
177
  }
170
178
 
171
179
  onUpdate() {
180
+ this.plugin = {}
181
+
172
182
  this.templates()
173
183
  this.cloning()
174
184
  this.skewed()
@@ -184,7 +194,7 @@ class MarqueeContent extends HTMLElement {
184
194
  }
185
195
 
186
196
  disconnectedCallback() {
187
- // gsap.matchMedia().remove()
197
+ this.MM.remove()
188
198
 
189
199
  document.fonts.removeEventListener('loadingdone', this.onUpdate)
190
200
  }