marquee-content 2.2.0 → 2.3.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 +6 -3
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +6 -3
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +11 -8
package/dist/index.js
CHANGED
|
@@ -13,9 +13,6 @@ 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)`;
|
|
19
16
|
this.update = this.update.bind(this);
|
|
20
17
|
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
21
18
|
this.resizeObserver.observe(this);
|
|
@@ -23,6 +20,11 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
23
20
|
static registerGSAP(gsap) {
|
|
24
21
|
$4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
|
|
25
22
|
}
|
|
23
|
+
breakpoints() {
|
|
24
|
+
this.breakpoint = "";
|
|
25
|
+
if (this.dataset.mcMax) this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
26
|
+
else if (this.dataset.mcMin) this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
27
|
+
}
|
|
26
28
|
debounce(fn, delay) {
|
|
27
29
|
this.timer = null;
|
|
28
30
|
return (...args)=>{
|
|
@@ -130,6 +132,7 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
130
132
|
});
|
|
131
133
|
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AC9B;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.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 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.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}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -3,9 +3,6 @@ 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)`;
|
|
9
6
|
this.update = this.update.bind(this);
|
|
10
7
|
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
11
8
|
this.resizeObserver.observe(this);
|
|
@@ -13,6 +10,11 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
13
10
|
static registerGSAP(gsap) {
|
|
14
11
|
$cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
|
|
15
12
|
}
|
|
13
|
+
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
|
+
}
|
|
16
18
|
debounce(fn, delay) {
|
|
17
19
|
this.timer = null;
|
|
18
20
|
return (...args)=>{
|
|
@@ -120,6 +122,7 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 extends HTMLElement {
|
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
124
|
init() {
|
|
125
|
+
this.breakpoints();
|
|
123
126
|
this.templates();
|
|
124
127
|
this.skewed();
|
|
125
128
|
this.cloning();
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAe,uDAA6B;IACxC,aAAc;QACV,KAAK;QAEL,IAAI,CAAC,OAAO,yCAAe,QAAQ,OAAO;QAC1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M,eAAe;gBACjB,IAAI,CAAC,KAAK,GAAG,OAAO;oBAChB,WAAW;oBACX,WAAW;gBACf;YACJ;YAEA,MAAM,gBAAgB;gBAClB,IAAI,gBAAgB;gBACpB,IAAI,kBAAkB;gBAEtB,MAAM,eAAe;oBACjB,MAAM,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;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.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 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.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}\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
package/src/index.js
CHANGED
|
@@ -4,14 +4,6 @@ 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
|
-
|
|
15
7
|
this.update = this.update.bind(this);
|
|
16
8
|
this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this), 150));
|
|
17
9
|
this.resizeObserver.observe(this);
|
|
@@ -21,6 +13,16 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
21
13
|
MarqueeContent.gsap = gsap;
|
|
22
14
|
}
|
|
23
15
|
|
|
16
|
+
breakpoints() {
|
|
17
|
+
this.breakpoint = '';
|
|
18
|
+
|
|
19
|
+
if (this.dataset.mcMax) {
|
|
20
|
+
this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;
|
|
21
|
+
} else if (this.dataset.mcMin) {
|
|
22
|
+
this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
24
26
|
debounce(fn, delay) {
|
|
25
27
|
this.timer = null;
|
|
26
28
|
|
|
@@ -162,6 +164,7 @@ export default class MarqueeContent extends HTMLElement {
|
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
init() {
|
|
167
|
+
this.breakpoints();
|
|
165
168
|
this.templates();
|
|
166
169
|
this.skewed();
|
|
167
170
|
this.cloning();
|