marquee-content 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -13,9 +13,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
13
13
  super();
14
14
  this.gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap || window.gsap;
15
15
  this.MM = this.gsap.matchMedia();
16
- this.breakpoint = "";
17
- if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
18
- else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
16
+ this.timeline = null;
19
17
  this.update = this.update.bind(this);
20
18
  this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
21
19
  this.resizeObserver.observe(this);
@@ -23,6 +21,11 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
23
21
  static registerGSAP(gsap) {
24
22
  $4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
25
23
  }
24
+ breakpoints() {
25
+ this.breakpoint = "";
26
+ if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
27
+ else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
28
+ }
26
29
  debounce(fn, delay) {
27
30
  this.timer = null;
28
31
  return (...args)=>{
@@ -72,11 +75,15 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
72
75
  });
73
76
  }
74
77
  animation() {
78
+ if (this.timeline) {
79
+ this.timeline.kill();
80
+ this.timeline = null;
81
+ }
75
82
  this.gsap.set(this.children, {
76
83
  clearProps: true
77
84
  });
78
85
  this.MM.add(this.breakpoint, ()=>{
79
- const tween = this.gsap.to(this.children, {
86
+ this.timeline = this.gsap.to(this.children, {
80
87
  duration: this.dataset.mcDuration || 20,
81
88
  x: "-100%",
82
89
  ease: "none",
@@ -89,7 +96,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
89
96
  }
90
97
  }).totalProgress(0.5);
91
98
  const ltrDirection = ()=>{
92
- this.gsap.to(tween, {
99
+ this.gsap.to(this.timeline, {
93
100
  timeScale: -1,
94
101
  overwrite: true
95
102
  });
@@ -100,7 +107,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
100
107
  const handleScroll = ()=>{
101
108
  const orientation = window.scrollY > currentScroll ? 1 : -1;
102
109
  if (orientation !== scrollDirection) {
103
- this.gsap.to(tween, {
110
+ this.gsap.to(this.timeline, {
104
111
  timeScale: orientation,
105
112
  overwrite: true
106
113
  });
@@ -116,6 +123,10 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
116
123
  if (this.dataset.mcDirection === "ltr") ltrDirection();
117
124
  else if (this.dataset.mcDirection === "auto") autoDirection();
118
125
  return ()=>{
126
+ if (this.timeline) {
127
+ this.timeline.kill();
128
+ this.timeline = null;
129
+ }
119
130
  this.gsap.set(this.children, {
120
131
  clearProps: true
121
132
  });
@@ -130,6 +141,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
130
141
  });
131
142
  }
132
143
  init() {
144
+ this.breakpoints();
133
145
  this.templates();
134
146
  this.skewed();
135
147
  this.cloning();
@@ -140,6 +152,10 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
140
152
  }
141
153
  disconnectedCallback() {
142
154
  cancelAnimationFrame(this.af);
155
+ if (this.timeline) {
156
+ this.timeline.kill();
157
+ this.timeline = null;
158
+ }
143
159
  }
144
160
  }
145
161
  if (!customElements.get("marquee-content")) customElements.define("marquee-content", $4fa36e821943b400$export$2e2bcd8739ae039);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QA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,cAAc,AAAC,OAAO,UAAU,gBAAiB,IAAI;oBAE3D,IAAI,gBAAgB,iBAAiB;wBACjC,IAAI,CAAC,KAAK,GAAG,OAAO;4BAChB,WAAW;4BACX,WAAW;wBACf;wBAEA,kBAAkB;oBACtB;oBAEA,gBAAgB,OAAO;gBAC3B;gBAEA,OAAO,iBAAiB,UAAU,cAAc;oBAAE,SAAS;oBAAM,SAAS;gBAAK;YACnF;YAEA,IAAI,IAAI,CAAC,QAAQ,gBAAgB,OAC7B;iBACG,IAAI,IAAI,CAAC,QAAQ,gBAAgB,QACpC;YAGJ,OAAO;gBACH,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU;oBACzB,YAAY;gBAChB;YACJ;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,OAAO;QACH,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,oBAAoB;QAChB,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;IAC9B;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,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.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 this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce(fn, delay) {\n this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\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 for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const 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.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 animation() {\n this.gsap.set(this.children, { clearProps: true });\n\n this.MM.add(this.breakpoint, () => {\n const tween = 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 },\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 currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\n this.gsap.set(this.children, {\n clearProps: true,\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.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}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,cAAc;QACV,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,QAAQ,OACb,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ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AC,QAAQ,gBAAgB,OAC7B;iBACG,IAAI,IAAI,CAAC,QAAQ,gBAAgB,QACpC;YAGJ,OAAO;gBACH,IAAI,IAAI,CAAC,UAAU;oBACf,IAAI,CAAC,SAAS;oBACd,IAAI,CAAC,WAAW;gBACpB;gBAEA,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU;oBAAE,YAAY;gBAAK;YACpD;QACJ;IACJ;IAEA,SAAS;QACL,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,mBACL,IAAI,CAAC,KAAK,sBAAsB;YAC5B,IAAI,CAAC;YACL,IAAI,CAAC;QACT;IAER;IAEA,OAAO;QACH,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,oBAAoB;QAChB,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,UAAU;YACf,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,WAAW;QACpB;IACJ;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,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), 150));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\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 debounce(fn, delay) {\n this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\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 for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const 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.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 animation() {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\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 },\n }).totalProgress(0.5);\n\n const ltrDirection = () => {\n this.gsap.to(this.timeline, {\n timeScale: -1,\n overwrite: true,\n });\n };\n\n const autoDirection = () => {\n let currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(this.timeline, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\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 }\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 if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -3,9 +3,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
3
3
  super();
4
4
  this.gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap || window.gsap;
5
5
  this.MM = this.gsap.matchMedia();
6
- this.breakpoint = "";
7
- if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
8
- else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
6
+ this.timeline = null;
9
7
  this.update = this.update.bind(this);
10
8
  this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
11
9
  this.resizeObserver.observe(this);
@@ -13,6 +11,11 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
13
11
  static registerGSAP(gsap) {
14
12
  $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
15
13
  }
14
+ breakpoints() {
15
+ this.breakpoint = "";
16
+ if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
17
+ else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
18
+ }
16
19
  debounce(fn, delay) {
17
20
  this.timer = null;
18
21
  return (...args)=>{
@@ -62,11 +65,15 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
62
65
  });
63
66
  }
64
67
  animation() {
68
+ if (this.timeline) {
69
+ this.timeline.kill();
70
+ this.timeline = null;
71
+ }
65
72
  this.gsap.set(this.children, {
66
73
  clearProps: true
67
74
  });
68
75
  this.MM.add(this.breakpoint, ()=>{
69
- const tween = this.gsap.to(this.children, {
76
+ this.timeline = this.gsap.to(this.children, {
70
77
  duration: this.dataset.mcDuration || 20,
71
78
  x: "-100%",
72
79
  ease: "none",
@@ -79,7 +86,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
79
86
  }
80
87
  }).totalProgress(0.5);
81
88
  const ltrDirection = ()=>{
82
- this.gsap.to(tween, {
89
+ this.gsap.to(this.timeline, {
83
90
  timeScale: -1,
84
91
  overwrite: true
85
92
  });
@@ -90,7 +97,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
90
97
  const handleScroll = ()=>{
91
98
  const orientation = window.scrollY > currentScroll ? 1 : -1;
92
99
  if (orientation !== scrollDirection) {
93
- this.gsap.to(tween, {
100
+ this.gsap.to(this.timeline, {
94
101
  timeScale: orientation,
95
102
  overwrite: true
96
103
  });
@@ -106,6 +113,10 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
106
113
  if (this.dataset.mcDirection === "ltr") ltrDirection();
107
114
  else if (this.dataset.mcDirection === "auto") autoDirection();
108
115
  return ()=>{
116
+ if (this.timeline) {
117
+ this.timeline.kill();
118
+ this.timeline = null;
119
+ }
109
120
  this.gsap.set(this.children, {
110
121
  clearProps: true
111
122
  });
@@ -120,6 +131,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
120
131
  });
121
132
  }
122
133
  init() {
134
+ this.breakpoints();
123
135
  this.templates();
124
136
  this.skewed();
125
137
  this.cloning();
@@ -130,6 +142,10 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
130
142
  }
131
143
  disconnectedCallback() {
132
144
  cancelAnimationFrame(this.af);
145
+ if (this.timeline) {
146
+ this.timeline.kill();
147
+ this.timeline = null;
148
+ }
133
149
  }
134
150
  }
135
151
  if (!customElements.get("marquee-content")) customElements.define("marquee-content", $cf838c15c8b009ba$export$2e2bcd8739ae039);
@@ -1 +1 @@
1
- {"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,QAAQ,OACb,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,QAAQ,KAAK,GAAG,CAAC;aAC5D,IAAI,IAAI,CAAC,QAAQ,OACpB,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,MAAM,GAAG,CAAC;QAG5D,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,SAAS,EAAE,EAAE,KAAK,EAAE;QAChB,IAAI,CAAC,QA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IAEA,OAAO;QACH,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;QACL,IAAI,CAAC;IACT;IAEA,oBAAoB;QAChB,IAAI,CAAC;IACT;IAEA,uBAAuB;QACnB,qBAAqB,IAAI,CAAC;IAC9B;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,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.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 this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce(fn, delay) {\n this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\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 for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const 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.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 animation() {\n this.gsap.set(this.children, { clearProps: true });\n\n this.MM.add(this.breakpoint, () => {\n const tween = 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 },\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 currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(tween, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\n this.gsap.set(this.children, {\n clearProps: true,\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.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}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK;QACpB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI;QACnC,IAAI,CAAC,iBAAiB,IAAI,eAAe,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG;QAC/E,IAAI,CAAC,eAAe,QAAQ,IAAI;IACpC;IAEA,OAAO,aAAa,IAAI,EAAE;QACtB,yCAAe,OAAO;IAC1B;IAEA,cAAc;QACV,IAAI,CAAC,aAAa;QAElB,IAAI,IAAI,CAAC,QAAQ,OACb,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,QAAQ,KAAK,GAAG,CAAC;aAC5D,IAAI,IAAI,CAAC,QAAQ,OACpB,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,MAAM,GAAG,CAAC;IAEhE;IAEA,SAAS,EAAE,EAAE,KAAK,EAAE;QAChB,IAAI,CAAC,QAAQ;QAEb,OAAO,CAAC,GAAG;YACP,IAAI,IAAI,CAAC,OAAO,aAAa,IAAI,CAAC;YAClC,IAAI,CAAC,QAAQ,WAAW,IAAM,MAAM,OAAO;QAC/C;IACJ;IAEA,YAAY;QACR,MAAM,UAAU,SAAS,cAAc;QACvC,QAAQ,UAAU,IAAI;QAEtB,MAAM,QAAQ,SAAS,cAAc;QACrC,MAAM,UAAU,IAAI;QACpB,MAAM,MAAM,UAAU;QACtB,MAAM,MAAM,aAAa;QAEzB,MAAO,IAAI,CAAC,WACR,MAAM,YAAY,IAAI,CAAC;QAG3B,QAAQ,YAAY;QACpB,IAAI,CAAC,YAA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U;YACf,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,WAAW;QACpB;IACJ;AACJ;AAEA,IAAI,CAAC,eAAe,IAAI,oBACpB,eAAe,OAAO,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), 150));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\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 debounce(fn, delay) {\n this.timer = null;\n\n return (...args) => {\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => fn(...args), delay);\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 for (let i = 1; i < requiredQuantity; i += 1) {\n const cloned = this.firstElementChild;\n const 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.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 animation() {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children, { clearProps: true });\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 },\n }).totalProgress(0.5);\n\n const ltrDirection = () => {\n this.gsap.to(this.timeline, {\n timeScale: -1,\n overwrite: true,\n });\n };\n\n const autoDirection = () => {\n let currentScroll = 0;\n let scrollDirection = 1;\n\n const handleScroll = () => {\n const orientation = (window.scrollY > currentScroll) ? 1 : -1;\n\n if (orientation !== scrollDirection) {\n this.gsap.to(this.timeline, {\n timeScale: orientation,\n overwrite: true,\n });\n\n scrollDirection = orientation;\n }\n\n currentScroll = window.scrollY;\n };\n\n window.addEventListener('scroll', handleScroll, { capture: true, passive: true });\n };\n\n if (this.dataset.mcDirection === 'ltr') {\n ltrDirection();\n } else if (this.dataset.mcDirection === 'auto') {\n autoDirection();\n }\n\n return () => {\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 }\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 if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "2.2.0",
3
+ "version": "2.4.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",
package/src/index.js CHANGED
@@ -4,14 +4,7 @@ export default class MarqueeContent extends HTMLElement {
4
4
 
5
5
  this.gsap = MarqueeContent.gsap || window.gsap;
6
6
  this.MM = this.gsap.matchMedia();
7
- this.breakpoint = '';
8
-
9
- if (this.dataset.mcMax) {
10
- this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
11
- } else if (this.dataset.mcMin) {
12
- this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
13
- }
14
-
7
+ this.timeline = null;
15
8
  this.update = this.update.bind(this);
16
9
  this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
17
10
  this.resizeObserver.observe(this);
@@ -21,6 +14,16 @@ export default class MarqueeContent extends HTMLElement {
21
14
  MarqueeContent.gsap = gsap;
22
15
  }
23
16
 
17
+ breakpoints() {
18
+ this.breakpoint = '';
19
+
20
+ if (this.dataset.mcMax) {
21
+ this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
22
+ } else if (this.dataset.mcMin) {
23
+ this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
24
+ }
25
+ }
26
+
24
27
  debounce(fn, delay) {
25
28
  this.timer = null;
26
29
 
@@ -91,10 +94,15 @@ export default class MarqueeContent extends HTMLElement {
91
94
  }
92
95
 
93
96
  animation() {
97
+ if (this.timeline) {
98
+ this.timeline.kill();
99
+ this.timeline = null;
100
+ }
101
+
94
102
  this.gsap.set(this.children, { clearProps: true });
95
103
 
96
104
  this.MM.add(this.breakpoint, () => {
97
- const tween = this.gsap.to(this.children, {
105
+ this.timeline = this.gsap.to(this.children, {
98
106
  duration: this.dataset.mcDuration || 20,
99
107
  x: '-100%',
100
108
  ease: 'none',
@@ -108,7 +116,7 @@ export default class MarqueeContent extends HTMLElement {
108
116
  }).totalProgress(0.5);
109
117
 
110
118
  const ltrDirection = () => {
111
- this.gsap.to(tween, {
119
+ this.gsap.to(this.timeline, {
112
120
  timeScale: -1,
113
121
  overwrite: true,
114
122
  });
@@ -122,7 +130,7 @@ export default class MarqueeContent extends HTMLElement {
122
130
  const orientation = (window.scrollY > currentScroll) ? 1 : -1;
123
131
 
124
132
  if (orientation !== scrollDirection) {
125
- this.gsap.to(tween, {
133
+ this.gsap.to(this.timeline, {
126
134
  timeScale: orientation,
127
135
  overwrite: true,
128
136
  });
@@ -143,9 +151,12 @@ export default class MarqueeContent extends HTMLElement {
143
151
  }
144
152
 
145
153
  return () => {
146
- this.gsap.set(this.children, {
147
- clearProps: true,
148
- });
154
+ if (this.timeline) {
155
+ this.timeline.kill();
156
+ this.timeline = null;
157
+ }
158
+
159
+ this.gsap.set(this.children, { clearProps: true });
149
160
  };
150
161
  });
151
162
  }
@@ -162,6 +173,7 @@ export default class MarqueeContent extends HTMLElement {
162
173
  }
163
174
 
164
175
  init() {
176
+ this.breakpoints();
165
177
  this.templates();
166
178
  this.skewed();
167
179
  this.cloning();
@@ -174,6 +186,11 @@ export default class MarqueeContent extends HTMLElement {
174
186
 
175
187
  disconnectedCallback() {
176
188
  cancelAnimationFrame(this.af);
189
+
190
+ if (this.timeline) {
191
+ this.timeline.kill();
192
+ this.timeline = null;
193
+ }
177
194
  }
178
195
  }
179
196