marquee-content 4.2.0 → 4.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/README.md CHANGED
@@ -1,8 +1,9 @@
1
- <br>
2
1
  <div align="center">
2
+ <br>
3
+
4
+ <h1>marquee-content</h1>
3
5
 
4
- # marquee-content
5
- A simple, lightweight library for creating the effect of running horizontal blocks of content, also known as a marquee or ticker. Uses GSAP and Resize Observer for better performance.
6
+ <p><sup>MarqueeContent provides a set of tools for creating dynamic and adaptive ticker animations on web pages using GSAP and ScrollTrigger. It offers seamless integration with media queries, automatic element cloning for continuous scrolling effects, and efficient handling of resize events. Additionally, it supports customizable animation directions and skew effects, ensuring smooth and visually appealing ticker animations across different screen sizes and orientations.</sup></p>
6
7
 
7
8
  [![npm](https://img.shields.io/npm/v/marquee-content.svg?colorB=brightgreen)](https://www.npmjs.com/package/marquee-content)
8
9
  [![GitHub package version](https://img.shields.io/github/package-json/v/ux-ui-pro/marquee-content.svg)](https://github.com/ux-ui-pro/marquee-content)
@@ -10,14 +11,13 @@ A simple, lightweight library for creating the effect of running horizontal bloc
10
11
 
11
12
  <sup>1kB gzipped</sup>
12
13
 
13
- ### <a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a>
14
+ <a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a>
14
15
 
15
16
  </div>
16
-
17
17
  <br>
18
18
 
19
19
  &#10148; **Install**
20
- ```
20
+ ```console
21
21
  yarn add gsap
22
22
  yarn add marquee-content
23
23
  ```
@@ -42,7 +42,7 @@ const marquee = new MarqueeContent({
42
42
 
43
43
  marquee.init();
44
44
  ```
45
- or
45
+ <sub>or</sub>
46
46
  ```javascript
47
47
  document.querySelectorAll('.marquee').forEach((element) => {
48
48
  const marquee = new MarqueeContent({
@@ -56,20 +56,20 @@ document.querySelectorAll('.marquee').forEach((element) => {
56
56
 
57
57
  &#10148; **Options**
58
58
 
59
- | Option | Type | Default | Description |
60
- |:----------|:-----------------------------:|:-----------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
61
- | `element` | `string` &vert; `HTMLElement` | `.marquee` | The option `element` defines the DOM element to which the animation will be applied. This option offers two ways to specify the target element:<br>**1.** As a string with a CSS selector. If `element` is given as a string, it is used to find the element in the DOM through the `document.querySelector` method. This allows for easy identification of elements by their id, class, or other selector.<br>**2.** As an HTMLElement object. If `element` is already an HTMLElement object, it is used directly, without the need for additional searching in the DOM. |
59
+ | Option | Type | Default | Description |
60
+ |:----------|:-----------------------:|:-----------:|:--------------------------------------------------------------------------------------------|
61
+ | `element` | `string \| HTMLElement` | `.marquee` | The DOM element for the animation. Can be a CSS selector (string) or an HTMLElement object. |
62
62
  <br>
63
63
 
64
64
  &#10148; **Settings**
65
65
 
66
- | Option | Default | Description |
67
- |:--------------------|:-------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
68
- | `data-mc-duration` | `20` | Sets the duration of content scrolling in seconds. It is acceptable to use decimals. |
69
- | `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. |
70
- | `data-mc-skew` | `null` | Transforms the component by tilting it along the Y axis (a positive or negative value is acceptable). |
71
- | `data-mc-min` | `null` | Sets the **minimum** width at which the animation will play (when the breakpoint intersects, the cloned elements are removed and the component styles are cleared). |
72
- | `data-mc-max` | `null` | Sets the **maximum** width. |
66
+ | data-* | Default | Description |
67
+ |:--------------------|:-------:|:------------------------------------------------------------------------------------------------------------------|
68
+ | `data-mc-duration` | `20` | Duration of the scrolling animation in seconds. Accepts decimal values. |
69
+ | `data-mc-direction` | `rtl` | Scroll direction. Options: `rtl` (default), `ltr` (left to right), `auto` (changes direction based on scrolling). |
70
+ | `data-mc-skew` | `null` | Tilts the component along the Y axis. Accepts positive or negative values. |
71
+ | `data-mc-min` | `null` | Minimum width for the animation to play. |
72
+ | `data-mc-max` | `null` | Maximum width for the animation to play. |
73
73
  <br>
74
74
 
75
75
  &#10148; **License**
@@ -0,0 +1,14 @@
1
+ interface MarqueeContentOptions {
2
+ element?: string | HTMLElement;
3
+ }
4
+ export default class MarqueeContent {
5
+ static gsap: never;
6
+ static ScrollTrigger: never;
7
+ constructor({ element }?: MarqueeContentOptions);
8
+ static registerGSAP(gsap: never, ScrollTrigger: never): void;
9
+ init: () => void;
10
+ destroy: () => void;
11
+ }
12
+ export default MarqueeContent;
13
+
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;IACE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAChC;AAED,qBAAM,cAAc;IAalB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC;IAEnB,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC;gBAEhB,EAAE,OAAoB,EAAE,GAAE,qBAA0B;IAYhE,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK;IA4B9C,IAAI,aAET;IAEK,OAAO,aAUZ;CAsGH;AAED,eAAe,cAAc,CAAC","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"interface MarqueeContentOptions {\n element?: string | HTMLElement;\n}\n\nclass MarqueeContent {\n private readonly gsap: never;\n\n private readonly MM: never;\n\n private timeline: never;\n\n private readonly element: HTMLElement | null;\n\n private resizeObserver: ResizeObserver;\n\n private animationFrame: number | null = null;\n\n static gsap: never;\n\n static ScrollTrigger: never;\n\n constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {\n this.gsap = MarqueeContent.gsap ?? (window as never).gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.element = typeof element === 'string' ? document.querySelector(element) : element;\n\n if (!this.element) return;\n\n this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));\n this.resizeObserver.observe(this.element);\n }\n\n static registerGSAP(gsap: never, ScrollTrigger: never) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n private commonInit = () => {\n if (this.element) {\n this.clearTimeline();\n this.cloneElements();\n this.setBreakpoints();\n this.applySkew();\n\n this.timeline = this.createAnimation();\n }\n };\n\n private update = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n this.animationFrame = requestAnimationFrame(() => {\n this.commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n public init = () => {\n this.commonInit();\n };\n\n public destroy = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n if (this.element) {\n this.clearTimeline();\n }\n\n this.resizeObserver?.disconnect();\n };\n\n private static debounce(func: (...args: never[]) => void) {\n let timer: number | null = null;\n\n return (...args: never[]) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n private createAnimation() {\n this.timeline?.kill();\n\n const timeline = this.gsap.timeline({\n scrollTrigger: {\n trigger: this.element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self: never) => {\n if (this.element?.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (this.element?.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.MM.add(this.element?.dataset.mcBreakpoint, () => {\n const duration = this.element?.dataset.mcDuration ? parseFloat(this.element?.dataset.mcDuration) : 20;\n\n timeline.to(this.element?.children, {\n duration,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n return timeline;\n }\n\n private setBreakpoints() {\n if (this.element!.dataset.mcMax) {\n this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;\n } else if (this.element!.dataset.mcMin) {\n this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;\n } else {\n this.element!.dataset.mcBreakpoint = '';\n }\n }\n\n private clearTimeline() {\n this.timeline?.kill();\n this.timeline = null;\n this.gsap.set(this.element!.children, { clearProps: 'all' });\n }\n\n private cloneElements() {\n const removingClones = () => {\n while (this.element!.childElementCount > 1) {\n this.element!.removeChild(this.element!.lastChild as ChildNode);\n }\n };\n\n removingClones();\n\n this.MM.add(this.element!.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);\n\n if (this.element!.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.element!.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n private applySkew() {\n if (!this.element?.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.element.dataset.mcSkew, 10));\n const { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -9,125 +9,127 @@ function $parcel$export(e, n, v, s) {
9
9
 
10
10
  $parcel$defineInteropFlag(module.exports);
11
11
 
12
- $parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
13
- const $4559ecf940edc78d$export$61fc7d43ac8f84b0 = function(func) {
14
- let timer;
15
- return (...args)=>{
16
- cancelAnimationFrame(timer);
17
- timer = requestAnimationFrame(()=>func(...args));
18
- };
19
- };
20
- const $4559ecf940edc78d$export$ecad260a8a5fef4f = function(element, gsap, MM, timeline, update) {
21
- timeline?.kill();
22
- timeline = gsap.timeline({
23
- scrollTrigger: {
24
- trigger: element,
25
- start: "top bottom",
26
- end: "bottom top",
27
- toggleActions: "resume pause resume pause",
28
- onUpdate: (self)=>{
29
- if (element.dataset.mcDirection === "ltr") timeline.timeScale(-1);
30
- else if (element.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
31
- }
32
- }
33
- });
34
- MM.add(element.dataset.mcBreakpoint, ()=>{
35
- timeline.to(element.children, {
36
- duration: element.dataset.mcDuration ?? 20,
37
- x: "-100%",
38
- repeat: -1,
39
- ease: "none"
40
- });
41
- timeline.totalProgress(0.5);
42
- return ()=>timeline?.kill();
43
- });
44
- update.timeline = timeline;
45
- return timeline;
46
- };
47
- const $4559ecf940edc78d$export$d07517a676ce386f = function(element) {
48
- element.dataset.mcBreakpoint = element.dataset.mcMax ? `(max-width: ${element.dataset.mcMax - 0.02}px)` : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : "";
49
- };
50
- const $4559ecf940edc78d$export$6a732ac1b1fdc86b = function(timeline, element, gsap) {
51
- timeline?.kill();
52
- timeline = null;
53
- gsap.set(element.children, {
54
- clearProps: "all"
55
- });
56
- };
57
- const $4559ecf940edc78d$export$7c4d14cd3c92bf0b = function(element, gsap, MM) {
58
- const removingClones = ()=>{
59
- while(element.childElementCount > 1)element.removeChild(element.lastChild);
60
- };
61
- removingClones();
62
- MM.add(element.dataset.mcBreakpoint, ()=>{
63
- const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
64
- if (element.childElementCount < requiredQuantity) {
65
- const fragment = document.createDocumentFragment();
66
- const clones = Array.from({
67
- length: requiredQuantity - 1
68
- }, ()=>element.firstElementChild.cloneNode(true));
69
- clones.forEach((clone)=>fragment.appendChild(clone));
70
- element.appendChild(fragment);
71
- }
72
- return removingClones;
73
- });
74
- };
75
- const $4559ecf940edc78d$export$3484d11c6bb42ecc = function(element) {
76
- if (!element.dataset.mcSkew) return;
77
- const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
78
- const { style: style } = element;
79
- style.transformOrigin = "center center";
80
- style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
81
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
82
- };
83
-
84
-
85
- class $4fa36e821943b400$var$MarqueeContent {
86
- #gsap;
87
- #MM;
88
- #timeline;
89
- #element;
90
- #resizeObserver;
91
- #animationFrame;
12
+ $parcel$export(module.exports, "default", function () { return $a196c1ed25598f0e$export$2e2bcd8739ae039; });
13
+ class $a196c1ed25598f0e$var$MarqueeContent {
14
+ gsap;
15
+ MM;
16
+ timeline;
17
+ element;
18
+ resizeObserver;
19
+ animationFrame = null;
92
20
  static gsap;
93
21
  static ScrollTrigger;
94
22
  constructor({ element: element = ".marquee" } = {}){
95
- this.#gsap = $4fa36e821943b400$var$MarqueeContent.gsap ?? window.gsap;
96
- this.#MM = this.#gsap.matchMedia();
97
- this.#timeline = null;
98
- this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
99
- if (!this.#element) return;
100
- this.#resizeObserver = new ResizeObserver($4559ecf940edc78d$export$61fc7d43ac8f84b0(()=>this.#update()));
101
- this.#resizeObserver.observe(this.#element);
23
+ this.gsap = $a196c1ed25598f0e$var$MarqueeContent.gsap ?? window.gsap;
24
+ this.MM = this.gsap.matchMedia();
25
+ this.timeline = null;
26
+ this.element = typeof element === "string" ? document.querySelector(element) : element;
27
+ if (!this.element) return;
28
+ this.resizeObserver = new ResizeObserver($a196c1ed25598f0e$var$MarqueeContent.debounce(this.update));
29
+ this.resizeObserver.observe(this.element);
102
30
  }
103
31
  static registerGSAP(gsap, ScrollTrigger) {
104
- $4fa36e821943b400$var$MarqueeContent.gsap = gsap;
105
- $4fa36e821943b400$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
32
+ $a196c1ed25598f0e$var$MarqueeContent.gsap = gsap;
33
+ $a196c1ed25598f0e$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
106
34
  }
107
- #commonInit = ()=>{
108
- $4559ecf940edc78d$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
109
- $4559ecf940edc78d$export$7c4d14cd3c92bf0b(this.#element, this.#gsap, this.#MM);
110
- $4559ecf940edc78d$export$d07517a676ce386f(this.#element);
111
- $4559ecf940edc78d$export$3484d11c6bb42ecc(this.#element);
112
- this.#timeline = $4559ecf940edc78d$export$ecad260a8a5fef4f(this.#element, this.#gsap, this.#MM, this.#timeline, this);
35
+ commonInit = ()=>{
36
+ if (this.element) {
37
+ this.clearTimeline();
38
+ this.cloneElements();
39
+ this.setBreakpoints();
40
+ this.applySkew();
41
+ this.timeline = this.createAnimation();
42
+ }
113
43
  };
114
- #update = ()=>{
115
- cancelAnimationFrame(this.#animationFrame);
116
- this.#animationFrame = requestAnimationFrame(()=>{
117
- this.#commonInit();
118
- $4fa36e821943b400$var$MarqueeContent.ScrollTrigger.refresh();
44
+ update = ()=>{
45
+ if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
46
+ this.animationFrame = requestAnimationFrame(()=>{
47
+ this.commonInit();
48
+ $a196c1ed25598f0e$var$MarqueeContent.ScrollTrigger.refresh();
119
49
  });
120
50
  };
121
51
  init = ()=>{
122
- this.#commonInit();
52
+ this.commonInit();
123
53
  };
124
54
  destroy = ()=>{
125
- cancelAnimationFrame(this.#animationFrame);
126
- $4559ecf940edc78d$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
127
- this.#resizeObserver?.disconnect();
55
+ if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
56
+ if (this.element) this.clearTimeline();
57
+ this.resizeObserver?.disconnect();
128
58
  };
59
+ static debounce(func) {
60
+ let timer = null;
61
+ return (...args)=>{
62
+ if (timer !== null) cancelAnimationFrame(timer);
63
+ timer = requestAnimationFrame(()=>func(...args));
64
+ };
65
+ }
66
+ createAnimation() {
67
+ this.timeline?.kill();
68
+ const timeline = this.gsap.timeline({
69
+ scrollTrigger: {
70
+ trigger: this.element,
71
+ start: "top bottom",
72
+ end: "bottom top",
73
+ toggleActions: "resume pause resume pause",
74
+ onUpdate: (self)=>{
75
+ if (this.element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
76
+ else if (this.element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
77
+ }
78
+ }
79
+ });
80
+ this.MM.add(this.element?.dataset.mcBreakpoint, ()=>{
81
+ const duration = this.element?.dataset.mcDuration ? parseFloat(this.element?.dataset.mcDuration) : 20;
82
+ timeline.to(this.element?.children, {
83
+ duration: duration,
84
+ x: "-100%",
85
+ repeat: -1,
86
+ ease: "none"
87
+ });
88
+ timeline.totalProgress(0.5);
89
+ return ()=>timeline?.kill();
90
+ });
91
+ return timeline;
92
+ }
93
+ setBreakpoints() {
94
+ if (this.element.dataset.mcMax) this.element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element.dataset.mcMax) - 0.02}px)`;
95
+ else if (this.element.dataset.mcMin) this.element.dataset.mcBreakpoint = `(min-width: ${this.element.dataset.mcMin}px)`;
96
+ else this.element.dataset.mcBreakpoint = "";
97
+ }
98
+ clearTimeline() {
99
+ this.timeline?.kill();
100
+ this.timeline = null;
101
+ this.gsap.set(this.element.children, {
102
+ clearProps: "all"
103
+ });
104
+ }
105
+ cloneElements() {
106
+ const removingClones = ()=>{
107
+ while(this.element.childElementCount > 1)this.element.removeChild(this.element.lastChild);
108
+ };
109
+ removingClones();
110
+ this.MM.add(this.element.dataset.mcBreakpoint, ()=>{
111
+ const requiredQuantity = Math.ceil(this.element.scrollWidth / this.element.firstElementChild.clientWidth + 2);
112
+ if (this.element.childElementCount < requiredQuantity) {
113
+ const fragment = document.createDocumentFragment();
114
+ const clones = Array.from({
115
+ length: requiredQuantity - 1
116
+ }, ()=>this.element.firstElementChild.cloneNode(true));
117
+ clones.forEach((clone)=>fragment.appendChild(clone));
118
+ this.element.appendChild(fragment);
119
+ }
120
+ return removingClones;
121
+ });
122
+ }
123
+ applySkew() {
124
+ if (!this.element?.dataset.mcSkew) return;
125
+ const abs = Math.abs(parseInt(this.element.dataset.mcSkew, 10));
126
+ const { style: style } = this.element;
127
+ style.transformOrigin = "center center";
128
+ style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
129
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
130
+ }
129
131
  }
130
- var $4fa36e821943b400$export$2e2bcd8739ae039 = $4fa36e821943b400$var$MarqueeContent;
132
+ var $a196c1ed25598f0e$export$2e2bcd8739ae039 = $a196c1ed25598f0e$var$MarqueeContent;
131
133
 
132
134
 
133
135
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;ACAO,MAAM,4CAAW,SAAS,IAAI;IACnC,IAAI;IAEJ,OAAO,CAAC,GAAG;QACT,qBAAqB;QAErB,QAAQ,sBAAsB,IAAM,QAAQ;IAC9C;AACF;AAEO,MAAM,4CAAY,SAAS,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM;IACnE,UAAU;IAEV,WAAW,KAAK,QAAQ,CAAC;QACvB,eAAe;YACb,SAAS;YACT,OAAO;YACP,KAAK;YACL,eAAe;YACf,UAAU,CAAC;gBACT,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,OAClC,SAAS,SAAS,CAAC;qBACd,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,QACzC,SAAS,SAAS,CAAC,KAAK,SAAS;YAErC;QACF;IACF;IAEA,GAAG,GAAG,CAAC,QAAQ,OAAO,CAAC,YAAY,EAAE;QACnC,SAAS,EAAE,CAAC,QAAQ,QAAQ,EAAE;YAC5B,UAAU,QAAQ,OAAO,CAAC,UAAU,IAAI;YACxC,GAAG;YACH,QAAQ;YACR,MAAM;QACR;QAEA,SAAS,aAAa,CAAC;QAEvB,OAAO,IAAM,UAAU;IACzB;IAEA,OAAO,QAAQ,GAAG;IAElB,OAAO;AACT;AAEO,MAAM,4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;QACjD,0CAAkB,IAAI,CAAC,CAAC,OAAO;QAC/B,0CAAa,IAAI,CAAC,CAAC,OAAO;QAE1B,IAAI,CAAC,CAAC,QAAQ,GAAG,0CAAgB,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI;IAC5F,EAAE;IAEF,CAAC,MAAM,GAAG;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAEhB,qCAAe,aAAa,CAAC,OAAO;QACtC;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QAEzC,0CAAoB,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QAE7D,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH;IAEA,2CAAe","sources":["src/index.js","src/utils.js"],"sourcesContent":["import * as Utils from './utils.js';\n\nclass MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n static gsap;\n\n static ScrollTrigger;\n\n constructor({element = '.marquee'} = {}) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = element instanceof HTMLElement ? element : document.querySelector(element);\n\n if (!this.#element) return;\n\n this.#resizeObserver = new ResizeObserver(Utils.debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap, ScrollTrigger) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n #commonInit = () => {\n Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);\n Utils.cloning(this.#element, this.#gsap, this.#MM);\n Utils.breakpoints(this.#element);\n Utils.skewed(this.#element);\n\n this.#timeline = Utils.animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);\n };\n\n #update = () => {\n cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = requestAnimationFrame(() => {\n this.#commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n\n Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);\n\n this.#resizeObserver?.disconnect();\n }\n}\n\nexport default MarqueeContent;\n","export const debounce = function(func) {\n let timer;\n\n return (...args) => {\n cancelAnimationFrame(timer);\n\n timer = requestAnimationFrame(() => func(...args));\n };\n};\n\nexport const animation = function(element, gsap, MM, timeline, update) {\n timeline?.kill();\n\n timeline = gsap.timeline({\n scrollTrigger: {\n trigger: element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (element.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (element.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n }\n });\n\n MM.add(element.dataset.mcBreakpoint, () => {\n timeline.to(element.children, {\n duration: element.dataset.mcDuration ?? 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n update.timeline = timeline;\n\n return timeline;\n};\n\nexport const breakpoints = function(element) {\n element.dataset.mcBreakpoint = element.dataset.mcMax\n ? `(max-width: ${element.dataset.mcMax - 0.02}px)`\n : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';\n};\n\nexport const clearTimeline = function(timeline, element, gsap) {\n timeline?.kill();\n timeline = null;\n\n gsap.set(element.children, { clearProps: 'all' });\n};\n\nexport const cloning = function(element, gsap, MM) {\n const removingClones = () => {\n while (element.childElementCount > 1) {\n element.removeChild(element.lastChild);\n }\n };\n\n removingClones();\n\n MM.add(element.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);\n\n if (element.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));\n\n clones.forEach(clone => fragment.appendChild(clone));\n\n element.appendChild(fragment);\n }\n\n return removingClones;\n });\n};\n\nexport const skewed = function(element) {\n if (!element.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));\n const { style } = element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n};\n"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;AAIA,MAAM;IACa,KAAY;IAEZ,GAAU;IAEnB,SAAgB;IAEP,QAA4B;IAErC,eAA+B;IAE/B,iBAAgC,KAAK;IAE7C,OAAO,KAAY;IAEnB,OAAO,cAAqB;IAE5B,YAAY,WAAE,UAAU,YAAmC,GAAG,CAAC,CAAC,CAAE;QAChE,IAAI,CAAC,IAAI,GAAG,qCAAe,IAAI,IAAI,AAAC,OAAiB,IAAI;QACzD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,YAAY,WAAW,SAAS,aAAa,CAAC,WAAW;QAE/E,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QAEnB,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,qCAAe,QAAQ,CAAC,IAAI,CAAC,MAAM;QAC5E,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO;IAC1C;IAEA,OAAO,aAAa,IAAW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I,CAAC,OAAO,CAAE,OAAO,CAAC,YAAY,EAAE;YAC9C,MAAM,mBAAmB,KAAK,IAAI,CAAC,IAAI,CAAC,OAAO,CAAE,WAAW,GAAG,IAAI,CAAC,OAAO,CAAE,iBAAiB,CAAE,WAAW,GAAG;YAE9G,IAAI,IAAI,CAAC,OAAO,CAAE,iBAAiB,GAAG,kBAAkB;gBACtD,MAAM,WAAW,SAAS,sBAAsB;gBAChD,MAAM,SAAS,MAAM,IAAI,CAAC;oBAAE,QAAQ,mBAAmB;gBAAE,GAAG,IAAM,IAAI,CAAC,OAAO,CAAE,iBAAiB,CAAE,SAAS,CAAC;gBAE7G,OAAO,OAAO,CAAC,CAAC,QAAU,SAAS,WAAW,CAAC;gBAE/C,IAAI,CAAC,OAAO,CAAE,WAAW,CAAC;YAC5B;YAEA,OAAO;QACT;IACF;IAEQ,YAAY;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,QAAQ;QAEnC,MAAM,MAAM,KAAK,GAAG,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;QAC3D,MAAM,SAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO;QAE9B,MAAM,eAAe,GAAG;QACxB,MAAM,SAAS,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;QACjE,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;IAC7D;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["interface MarqueeContentOptions {\n element?: string | HTMLElement;\n}\n\nclass MarqueeContent {\n private readonly gsap: never;\n\n private readonly MM: never;\n\n private timeline: never;\n\n private readonly element: HTMLElement | null;\n\n private resizeObserver: ResizeObserver;\n\n private animationFrame: number | null = null;\n\n static gsap: never;\n\n static ScrollTrigger: never;\n\n constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {\n this.gsap = MarqueeContent.gsap ?? (window as never).gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.element = typeof element === 'string' ? document.querySelector(element) : element;\n\n if (!this.element) return;\n\n this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));\n this.resizeObserver.observe(this.element);\n }\n\n static registerGSAP(gsap: never, ScrollTrigger: never) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n private commonInit = () => {\n if (this.element) {\n this.clearTimeline();\n this.cloneElements();\n this.setBreakpoints();\n this.applySkew();\n\n this.timeline = this.createAnimation();\n }\n };\n\n private update = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n this.animationFrame = requestAnimationFrame(() => {\n this.commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n public init = () => {\n this.commonInit();\n };\n\n public destroy = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n if (this.element) {\n this.clearTimeline();\n }\n\n this.resizeObserver?.disconnect();\n };\n\n private static debounce(func: (...args: never[]) => void) {\n let timer: number | null = null;\n\n return (...args: never[]) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n private createAnimation() {\n this.timeline?.kill();\n\n const timeline = this.gsap.timeline({\n scrollTrigger: {\n trigger: this.element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self: never) => {\n if (this.element?.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (this.element?.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.MM.add(this.element?.dataset.mcBreakpoint, () => {\n const duration = this.element?.dataset.mcDuration ? parseFloat(this.element?.dataset.mcDuration) : 20;\n\n timeline.to(this.element?.children, {\n duration,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n return timeline;\n }\n\n private setBreakpoints() {\n if (this.element!.dataset.mcMax) {\n this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;\n } else if (this.element!.dataset.mcMin) {\n this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;\n } else {\n this.element!.dataset.mcBreakpoint = '';\n }\n }\n\n private clearTimeline() {\n this.timeline?.kill();\n this.timeline = null;\n this.gsap.set(this.element!.children, { clearProps: 'all' });\n }\n\n private cloneElements() {\n const removingClones = () => {\n while (this.element!.childElementCount > 1) {\n this.element!.removeChild(this.element!.lastChild as ChildNode);\n }\n };\n\n removingClones();\n\n this.MM.add(this.element!.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);\n\n if (this.element!.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.element!.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n private applySkew() {\n if (!this.element?.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.element.dataset.mcSkew, 10));\n const { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -1,122 +1,124 @@
1
- const $f3ad94c9f84f4d57$export$61fc7d43ac8f84b0 = function(func) {
2
- let timer;
3
- return (...args)=>{
4
- cancelAnimationFrame(timer);
5
- timer = requestAnimationFrame(()=>func(...args));
6
- };
7
- };
8
- const $f3ad94c9f84f4d57$export$ecad260a8a5fef4f = function(element, gsap, MM, timeline, update) {
9
- timeline?.kill();
10
- timeline = gsap.timeline({
11
- scrollTrigger: {
12
- trigger: element,
13
- start: "top bottom",
14
- end: "bottom top",
15
- toggleActions: "resume pause resume pause",
16
- onUpdate: (self)=>{
17
- if (element.dataset.mcDirection === "ltr") timeline.timeScale(-1);
18
- else if (element.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
19
- }
20
- }
21
- });
22
- MM.add(element.dataset.mcBreakpoint, ()=>{
23
- timeline.to(element.children, {
24
- duration: element.dataset.mcDuration ?? 20,
25
- x: "-100%",
26
- repeat: -1,
27
- ease: "none"
28
- });
29
- timeline.totalProgress(0.5);
30
- return ()=>timeline?.kill();
31
- });
32
- update.timeline = timeline;
33
- return timeline;
34
- };
35
- const $f3ad94c9f84f4d57$export$d07517a676ce386f = function(element) {
36
- element.dataset.mcBreakpoint = element.dataset.mcMax ? `(max-width: ${element.dataset.mcMax - 0.02}px)` : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : "";
37
- };
38
- const $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b = function(timeline, element, gsap) {
39
- timeline?.kill();
40
- timeline = null;
41
- gsap.set(element.children, {
42
- clearProps: "all"
43
- });
44
- };
45
- const $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b = function(element, gsap, MM) {
46
- const removingClones = ()=>{
47
- while(element.childElementCount > 1)element.removeChild(element.lastChild);
48
- };
49
- removingClones();
50
- MM.add(element.dataset.mcBreakpoint, ()=>{
51
- const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
52
- if (element.childElementCount < requiredQuantity) {
53
- const fragment = document.createDocumentFragment();
54
- const clones = Array.from({
55
- length: requiredQuantity - 1
56
- }, ()=>element.firstElementChild.cloneNode(true));
57
- clones.forEach((clone)=>fragment.appendChild(clone));
58
- element.appendChild(fragment);
59
- }
60
- return removingClones;
61
- });
62
- };
63
- const $f3ad94c9f84f4d57$export$3484d11c6bb42ecc = function(element) {
64
- if (!element.dataset.mcSkew) return;
65
- const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
66
- const { style: style } = element;
67
- style.transformOrigin = "center center";
68
- style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
69
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
70
- };
71
-
72
-
73
- class $cf838c15c8b009ba$var$MarqueeContent {
74
- #gsap;
75
- #MM;
76
- #timeline;
77
- #element;
78
- #resizeObserver;
79
- #animationFrame;
1
+ class $643fcf18b2d2e76f$var$MarqueeContent {
2
+ gsap;
3
+ MM;
4
+ timeline;
5
+ element;
6
+ resizeObserver;
7
+ animationFrame = null;
80
8
  static gsap;
81
9
  static ScrollTrigger;
82
10
  constructor({ element: element = ".marquee" } = {}){
83
- this.#gsap = $cf838c15c8b009ba$var$MarqueeContent.gsap ?? window.gsap;
84
- this.#MM = this.#gsap.matchMedia();
85
- this.#timeline = null;
86
- this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
87
- if (!this.#element) return;
88
- this.#resizeObserver = new ResizeObserver($f3ad94c9f84f4d57$export$61fc7d43ac8f84b0(()=>this.#update()));
89
- this.#resizeObserver.observe(this.#element);
11
+ this.gsap = $643fcf18b2d2e76f$var$MarqueeContent.gsap ?? window.gsap;
12
+ this.MM = this.gsap.matchMedia();
13
+ this.timeline = null;
14
+ this.element = typeof element === "string" ? document.querySelector(element) : element;
15
+ if (!this.element) return;
16
+ this.resizeObserver = new ResizeObserver($643fcf18b2d2e76f$var$MarqueeContent.debounce(this.update));
17
+ this.resizeObserver.observe(this.element);
90
18
  }
91
19
  static registerGSAP(gsap, ScrollTrigger) {
92
- $cf838c15c8b009ba$var$MarqueeContent.gsap = gsap;
93
- $cf838c15c8b009ba$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
20
+ $643fcf18b2d2e76f$var$MarqueeContent.gsap = gsap;
21
+ $643fcf18b2d2e76f$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
94
22
  }
95
- #commonInit = ()=>{
96
- $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
97
- $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b(this.#element, this.#gsap, this.#MM);
98
- $f3ad94c9f84f4d57$export$d07517a676ce386f(this.#element);
99
- $f3ad94c9f84f4d57$export$3484d11c6bb42ecc(this.#element);
100
- this.#timeline = $f3ad94c9f84f4d57$export$ecad260a8a5fef4f(this.#element, this.#gsap, this.#MM, this.#timeline, this);
23
+ commonInit = ()=>{
24
+ if (this.element) {
25
+ this.clearTimeline();
26
+ this.cloneElements();
27
+ this.setBreakpoints();
28
+ this.applySkew();
29
+ this.timeline = this.createAnimation();
30
+ }
101
31
  };
102
- #update = ()=>{
103
- cancelAnimationFrame(this.#animationFrame);
104
- this.#animationFrame = requestAnimationFrame(()=>{
105
- this.#commonInit();
106
- $cf838c15c8b009ba$var$MarqueeContent.ScrollTrigger.refresh();
32
+ update = ()=>{
33
+ if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
34
+ this.animationFrame = requestAnimationFrame(()=>{
35
+ this.commonInit();
36
+ $643fcf18b2d2e76f$var$MarqueeContent.ScrollTrigger.refresh();
107
37
  });
108
38
  };
109
39
  init = ()=>{
110
- this.#commonInit();
40
+ this.commonInit();
111
41
  };
112
42
  destroy = ()=>{
113
- cancelAnimationFrame(this.#animationFrame);
114
- $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
115
- this.#resizeObserver?.disconnect();
43
+ if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
44
+ if (this.element) this.clearTimeline();
45
+ this.resizeObserver?.disconnect();
116
46
  };
47
+ static debounce(func) {
48
+ let timer = null;
49
+ return (...args)=>{
50
+ if (timer !== null) cancelAnimationFrame(timer);
51
+ timer = requestAnimationFrame(()=>func(...args));
52
+ };
53
+ }
54
+ createAnimation() {
55
+ this.timeline?.kill();
56
+ const timeline = this.gsap.timeline({
57
+ scrollTrigger: {
58
+ trigger: this.element,
59
+ start: "top bottom",
60
+ end: "bottom top",
61
+ toggleActions: "resume pause resume pause",
62
+ onUpdate: (self)=>{
63
+ if (this.element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
64
+ else if (this.element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
65
+ }
66
+ }
67
+ });
68
+ this.MM.add(this.element?.dataset.mcBreakpoint, ()=>{
69
+ const duration = this.element?.dataset.mcDuration ? parseFloat(this.element?.dataset.mcDuration) : 20;
70
+ timeline.to(this.element?.children, {
71
+ duration: duration,
72
+ x: "-100%",
73
+ repeat: -1,
74
+ ease: "none"
75
+ });
76
+ timeline.totalProgress(0.5);
77
+ return ()=>timeline?.kill();
78
+ });
79
+ return timeline;
80
+ }
81
+ setBreakpoints() {
82
+ if (this.element.dataset.mcMax) this.element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element.dataset.mcMax) - 0.02}px)`;
83
+ else if (this.element.dataset.mcMin) this.element.dataset.mcBreakpoint = `(min-width: ${this.element.dataset.mcMin}px)`;
84
+ else this.element.dataset.mcBreakpoint = "";
85
+ }
86
+ clearTimeline() {
87
+ this.timeline?.kill();
88
+ this.timeline = null;
89
+ this.gsap.set(this.element.children, {
90
+ clearProps: "all"
91
+ });
92
+ }
93
+ cloneElements() {
94
+ const removingClones = ()=>{
95
+ while(this.element.childElementCount > 1)this.element.removeChild(this.element.lastChild);
96
+ };
97
+ removingClones();
98
+ this.MM.add(this.element.dataset.mcBreakpoint, ()=>{
99
+ const requiredQuantity = Math.ceil(this.element.scrollWidth / this.element.firstElementChild.clientWidth + 2);
100
+ if (this.element.childElementCount < requiredQuantity) {
101
+ const fragment = document.createDocumentFragment();
102
+ const clones = Array.from({
103
+ length: requiredQuantity - 1
104
+ }, ()=>this.element.firstElementChild.cloneNode(true));
105
+ clones.forEach((clone)=>fragment.appendChild(clone));
106
+ this.element.appendChild(fragment);
107
+ }
108
+ return removingClones;
109
+ });
110
+ }
111
+ applySkew() {
112
+ if (!this.element?.dataset.mcSkew) return;
113
+ const abs = Math.abs(parseInt(this.element.dataset.mcSkew, 10));
114
+ const { style: style } = this.element;
115
+ style.transformOrigin = "center center";
116
+ style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
117
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
118
+ }
117
119
  }
118
- var $cf838c15c8b009ba$export$2e2bcd8739ae039 = $cf838c15c8b009ba$var$MarqueeContent;
120
+ var $643fcf18b2d2e76f$export$2e2bcd8739ae039 = $643fcf18b2d2e76f$var$MarqueeContent;
119
121
 
120
122
 
121
- export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
123
+ export {$643fcf18b2d2e76f$export$2e2bcd8739ae039 as default};
122
124
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"ACAO,MAAM,4CAAW,SAAS,IAAI;IACnC,IAAI;IAEJ,OAAO,CAAC,GAAG;QACT,qBAAqB;QAErB,QAAQ,sBAAsB,IAAM,QAAQ;IAC9C;AACF;AAEO,MAAM,4CAAY,SAAS,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM;IACnE,UAAU;IAEV,WAAW,KAAK,QAAQ,CAAC;QACvB,eAAe;YACb,SAAS;YACT,OAAO;YACP,KAAK;YACL,eAAe;YACf,UAAU,CAAC;gBACT,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,OAClC,SAAS,SAAS,CAAC;qBACd,IAAI,QAAQ,OAAO,CAAC,WAAW,KAAK,QACzC,SAAS,SAAS,CAAC,KAAK,SAAS;YAErC;QACF;IACF;IAEA,GAAG,GAAG,CAAC,QAAQ,OAAO,CAAC,YAAY,EAAE;QACnC,SAAS,EAAE,CAAC,QAAQ,QAAQ,EAAE;YAC5B,UAAU,QAAQ,OAAO,CAAC,UAAU,IAAI;YACxC,GAAG;YACH,QAAQ;YACR,MAAM;QACR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C,CAAC,IAAI;QAC7D,0CAAc,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE;QACjD,0CAAkB,IAAI,CAAC,CAAC,OAAO;QAC/B,0CAAa,IAAI,CAAC,CAAC,OAAO;QAE1B,IAAI,CAAC,CAAC,QAAQ,GAAG,0CAAgB,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI;IAC5F,EAAE;IAEF,CAAC,MAAM,GAAG;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAEhB,qCAAe,aAAa,CAAC,OAAO;QACtC;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QAEzC,0CAAoB,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QAE7D,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH;IAEA,2CAAe","sources":["src/index.js","src/utils.js"],"sourcesContent":["import * as Utils from './utils.js';\n\nclass MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n static gsap;\n\n static ScrollTrigger;\n\n constructor({element = '.marquee'} = {}) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = element instanceof HTMLElement ? element : document.querySelector(element);\n\n if (!this.#element) return;\n\n this.#resizeObserver = new ResizeObserver(Utils.debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap, ScrollTrigger) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n #commonInit = () => {\n Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);\n Utils.cloning(this.#element, this.#gsap, this.#MM);\n Utils.breakpoints(this.#element);\n Utils.skewed(this.#element);\n\n this.#timeline = Utils.animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);\n };\n\n #update = () => {\n cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = requestAnimationFrame(() => {\n this.#commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n\n Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);\n\n this.#resizeObserver?.disconnect();\n }\n}\n\nexport default MarqueeContent;\n","export const debounce = function(func) {\n let timer;\n\n return (...args) => {\n cancelAnimationFrame(timer);\n\n timer = requestAnimationFrame(() => func(...args));\n };\n};\n\nexport const animation = function(element, gsap, MM, timeline, update) {\n timeline?.kill();\n\n timeline = gsap.timeline({\n scrollTrigger: {\n trigger: element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (element.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (element.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n }\n });\n\n MM.add(element.dataset.mcBreakpoint, () => {\n timeline.to(element.children, {\n duration: element.dataset.mcDuration ?? 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n update.timeline = timeline;\n\n return timeline;\n};\n\nexport const breakpoints = function(element) {\n element.dataset.mcBreakpoint = element.dataset.mcMax\n ? `(max-width: ${element.dataset.mcMax - 0.02}px)`\n : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';\n};\n\nexport const clearTimeline = function(timeline, element, gsap) {\n timeline?.kill();\n timeline = null;\n\n gsap.set(element.children, { clearProps: 'all' });\n};\n\nexport const cloning = function(element, gsap, MM) {\n const removingClones = () => {\n while (element.childElementCount > 1) {\n element.removeChild(element.lastChild);\n }\n };\n\n removingClones();\n\n MM.add(element.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);\n\n if (element.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));\n\n clones.forEach(clone => fragment.appendChild(clone));\n\n element.appendChild(fragment);\n }\n\n return removingClones;\n });\n};\n\nexport const skewed = function(element) {\n if (!element.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));\n const { style } = element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n};\n"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"AAIA,MAAM;IACa,KAAY;IAEZ,GAAU;IAEnB,SAAgB;IAEP,QAA4B;IAErC,eAA+B;IAE/B,iBAAgC,KAAK;IAE7C,OAAO,KAAY;IAEnB,OAAO,cAAqB;IAE5B,YAAY,WAAE,UAAU,YAAmC,GAAG,CAAC,CAAC,CAAE;QAChE,IAAI,CAAC,IAAI,GAAG,qCAAe,IAAI,IAAI,AAAC,OAAiB,IAAI;QACzD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU;QAC9B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,YAAY,WAAW,SAAS,aAAa,CAAC,WAAW;QAE/E,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QAEnB,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,qCAAe,QAAQ,CAAC,IAAI,CA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,WAAW,CAAC,IAAI,CAAC,OAAO,CAAE,SAAS;QAErD;QAEA;QAEA,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAE,OAAO,CAAC,YAAY,EAAE;YAC9C,MAAM,mBAAmB,KAAK,IAAI,CAAC,IAAI,CAAC,OAAO,CAAE,WAAW,GAAG,IAAI,CAAC,OAAO,CAAE,iBAAiB,CAAE,WAAW,GAAG;YAE9G,IAAI,IAAI,CAAC,OAAO,CAAE,iBAAiB,GAAG,kBAAkB;gBACtD,MAAM,WAAW,SAAS,sBAAsB;gBAChD,MAAM,SAAS,MAAM,IAAI,CAAC;oBAAE,QAAQ,mBAAmB;gBAAE,GAAG,IAAM,IAAI,CAAC,OAAO,CAAE,iBAAiB,CAAE,SAAS,CAAC;gBAE7G,OAAO,OAAO,CAAC,CAAC,QAAU,SAAS,WAAW,CAAC;gBAE/C,IAAI,CAAC,OAAO,CAAE,WAAW,CAAC;YAC5B;YAEA,OAAO;QACT;IACF;IAEQ,YAAY;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,QAAQ;QAEnC,MAAM,MAAM,KAAK,GAAG,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;QAC3D,MAAM,SAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO;QAE9B,MAAM,eAAe,GAAG;QACxB,MAAM,SAAS,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;QACjE,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;IAC7D;AACF;IAEA,2CAAe","sources":["src/index.ts"],"sourcesContent":["interface MarqueeContentOptions {\n element?: string | HTMLElement;\n}\n\nclass MarqueeContent {\n private readonly gsap: never;\n\n private readonly MM: never;\n\n private timeline: never;\n\n private readonly element: HTMLElement | null;\n\n private resizeObserver: ResizeObserver;\n\n private animationFrame: number | null = null;\n\n static gsap: never;\n\n static ScrollTrigger: never;\n\n constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {\n this.gsap = MarqueeContent.gsap ?? (window as never).gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.element = typeof element === 'string' ? document.querySelector(element) : element;\n\n if (!this.element) return;\n\n this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));\n this.resizeObserver.observe(this.element);\n }\n\n static registerGSAP(gsap: never, ScrollTrigger: never) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n private commonInit = () => {\n if (this.element) {\n this.clearTimeline();\n this.cloneElements();\n this.setBreakpoints();\n this.applySkew();\n\n this.timeline = this.createAnimation();\n }\n };\n\n private update = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n this.animationFrame = requestAnimationFrame(() => {\n this.commonInit();\n\n MarqueeContent.ScrollTrigger.refresh();\n });\n };\n\n public init = () => {\n this.commonInit();\n };\n\n public destroy = () => {\n if (this.animationFrame !== null) {\n cancelAnimationFrame(this.animationFrame);\n }\n\n if (this.element) {\n this.clearTimeline();\n }\n\n this.resizeObserver?.disconnect();\n };\n\n private static debounce(func: (...args: never[]) => void) {\n let timer: number | null = null;\n\n return (...args: never[]) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n private createAnimation() {\n this.timeline?.kill();\n\n const timeline = this.gsap.timeline({\n scrollTrigger: {\n trigger: this.element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self: never) => {\n if (this.element?.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (this.element?.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.MM.add(this.element?.dataset.mcBreakpoint, () => {\n const duration = this.element?.dataset.mcDuration ? parseFloat(this.element?.dataset.mcDuration) : 20;\n\n timeline.to(this.element?.children, {\n duration,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n return timeline;\n }\n\n private setBreakpoints() {\n if (this.element!.dataset.mcMax) {\n this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;\n } else if (this.element!.dataset.mcMin) {\n this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;\n } else {\n this.element!.dataset.mcBreakpoint = '';\n }\n }\n\n private clearTimeline() {\n this.timeline?.kill();\n this.timeline = null;\n this.gsap.set(this.element!.children, { clearProps: 'all' });\n }\n\n private cloneElements() {\n const removingClones = () => {\n while (this.element!.childElementCount > 1) {\n this.element!.removeChild(this.element!.lastChild as ChildNode);\n }\n };\n\n removingClones();\n\n this.MM.add(this.element!.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);\n\n if (this.element!.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.element!.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n private applySkew() {\n if (!this.element?.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.element.dataset.mcSkew, 10));\n const { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "4.2.0",
4
- "description": "Class for creating the running content effect, also known as a marquee or ticker.",
3
+ "version": "4.3.0",
4
+ "description": "MarqueeContent provides a set of tools for creating dynamic and adaptive ticker animations on web pages using GSAP and ScrollTrigger.",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -11,29 +11,29 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ux-ui-pro/marquee-content/issues"
13
13
  },
14
- "main": "dist/index.js",
15
- "module": "dist/index.module.js",
16
- "targets": {
17
- "main": {
18
- "source": "src/index.js"
19
- },
20
- "module": {
21
- "source": "src/index.js"
22
- }
23
- },
14
+ "homepage": "https://github.com/ux-ui-pro/marquee-content",
15
+ "sideEffects": false,
24
16
  "scripts": {
25
17
  "clean": "rm -rf dist .parcel-cache",
26
- "serve": "parcel src/index.html --dist-dir dist --cache-dir .parcel --no-source-maps --open",
27
18
  "build": "yarn clean && parcel build",
28
- "lint:js": "eslint --ext .js",
19
+ "lint:js": "eslint **/*.{ts,js}",
29
20
  "lintfix": "yarn lint:js --fix"
30
21
  },
22
+ "browserslist": "> 0.5%, last 2 versions, not dead",
23
+ "source": "src/index.ts",
24
+ "main": "dist/index.js",
25
+ "module": "dist/index.module.js",
26
+ "types": "dist/index.d.ts",
31
27
  "devDependencies": {
32
- "eslint": "^8.57.0",
28
+ "@parcel/packager-ts": "2.12.0",
29
+ "@parcel/transformer-typescript-types": "2.12.0",
30
+ "@typescript-eslint/eslint-plugin": "^7.11.0",
31
+ "@typescript-eslint/parser": "^7.11.0",
32
+ "eslint": "^7.32.0 || ^8.57.0",
33
33
  "eslint-config-airbnb-base": "^15.0.0",
34
34
  "eslint-plugin-import": "^2.29.1",
35
35
  "parcel": "^2.12.0",
36
- "postcss-html": "^1.6.0"
36
+ "typescript": "^5.4.5"
37
37
  },
38
38
  "keywords": [
39
39
  "marquee",
@@ -49,6 +49,22 @@
49
49
  "filler",
50
50
  "css",
51
51
  "effects",
52
- "gsap"
52
+ "gsap",
53
+ "ResizeObserver",
54
+ "timeline",
55
+ "scrollTrigger",
56
+ "breakpoints",
57
+ "debounce",
58
+ "typescript",
59
+ "clone",
60
+ "skew",
61
+ "responsive",
62
+ "media queries",
63
+ "javascript",
64
+ "frontend",
65
+ "UX",
66
+ "performance",
67
+ "HTML",
68
+ "CSS"
53
69
  ]
54
70
  }
package/src/index.ts ADDED
@@ -0,0 +1,180 @@
1
+ interface MarqueeContentOptions {
2
+ element?: string | HTMLElement;
3
+ }
4
+
5
+ class MarqueeContent {
6
+ private readonly gsap: never;
7
+
8
+ private readonly MM: never;
9
+
10
+ private timeline: never;
11
+
12
+ private readonly element: HTMLElement | null;
13
+
14
+ private resizeObserver: ResizeObserver;
15
+
16
+ private animationFrame: number | null = null;
17
+
18
+ static gsap: never;
19
+
20
+ static ScrollTrigger: never;
21
+
22
+ constructor({ element = '.marquee' }: MarqueeContentOptions = {}) {
23
+ this.gsap = MarqueeContent.gsap ?? (window as never).gsap;
24
+ this.MM = this.gsap.matchMedia();
25
+ this.timeline = null;
26
+ this.element = typeof element === 'string' ? document.querySelector(element) : element;
27
+
28
+ if (!this.element) return;
29
+
30
+ this.resizeObserver = new ResizeObserver(MarqueeContent.debounce(this.update));
31
+ this.resizeObserver.observe(this.element);
32
+ }
33
+
34
+ static registerGSAP(gsap: never, ScrollTrigger: never) {
35
+ MarqueeContent.gsap = gsap;
36
+ MarqueeContent.ScrollTrigger = ScrollTrigger;
37
+ }
38
+
39
+ private commonInit = () => {
40
+ if (this.element) {
41
+ this.clearTimeline();
42
+ this.cloneElements();
43
+ this.setBreakpoints();
44
+ this.applySkew();
45
+
46
+ this.timeline = this.createAnimation();
47
+ }
48
+ };
49
+
50
+ private update = () => {
51
+ if (this.animationFrame !== null) {
52
+ cancelAnimationFrame(this.animationFrame);
53
+ }
54
+
55
+ this.animationFrame = requestAnimationFrame(() => {
56
+ this.commonInit();
57
+
58
+ MarqueeContent.ScrollTrigger.refresh();
59
+ });
60
+ };
61
+
62
+ public init = () => {
63
+ this.commonInit();
64
+ };
65
+
66
+ public destroy = () => {
67
+ if (this.animationFrame !== null) {
68
+ cancelAnimationFrame(this.animationFrame);
69
+ }
70
+
71
+ if (this.element) {
72
+ this.clearTimeline();
73
+ }
74
+
75
+ this.resizeObserver?.disconnect();
76
+ };
77
+
78
+ private static debounce(func: (...args: never[]) => void) {
79
+ let timer: number | null = null;
80
+
81
+ return (...args: never[]) => {
82
+ if (timer !== null) {
83
+ cancelAnimationFrame(timer);
84
+ }
85
+
86
+ timer = requestAnimationFrame(() => func(...args));
87
+ };
88
+ }
89
+
90
+ private createAnimation() {
91
+ this.timeline?.kill();
92
+
93
+ const timeline = this.gsap.timeline({
94
+ scrollTrigger: {
95
+ trigger: this.element,
96
+ start: 'top bottom',
97
+ end: 'bottom top',
98
+ toggleActions: 'resume pause resume pause',
99
+ onUpdate: (self: never) => {
100
+ if (this.element?.dataset.mcDirection === 'ltr') {
101
+ timeline.timeScale(-1);
102
+ } else if (this.element?.dataset.mcDirection === 'auto') {
103
+ timeline.timeScale(self.direction);
104
+ }
105
+ },
106
+ },
107
+ });
108
+
109
+ this.MM.add(this.element?.dataset.mcBreakpoint, () => {
110
+ const duration = this.element?.dataset.mcDuration ? parseFloat(this.element?.dataset.mcDuration) : 20;
111
+
112
+ timeline.to(this.element?.children, {
113
+ duration,
114
+ x: '-100%',
115
+ repeat: -1,
116
+ ease: 'none',
117
+ });
118
+
119
+ timeline.totalProgress(0.5);
120
+
121
+ return () => timeline?.kill();
122
+ });
123
+
124
+ return timeline;
125
+ }
126
+
127
+ private setBreakpoints() {
128
+ if (this.element!.dataset.mcMax) {
129
+ this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;
130
+ } else if (this.element!.dataset.mcMin) {
131
+ this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;
132
+ } else {
133
+ this.element!.dataset.mcBreakpoint = '';
134
+ }
135
+ }
136
+
137
+ private clearTimeline() {
138
+ this.timeline?.kill();
139
+ this.timeline = null;
140
+ this.gsap.set(this.element!.children, { clearProps: 'all' });
141
+ }
142
+
143
+ private cloneElements() {
144
+ const removingClones = () => {
145
+ while (this.element!.childElementCount > 1) {
146
+ this.element!.removeChild(this.element!.lastChild as ChildNode);
147
+ }
148
+ };
149
+
150
+ removingClones();
151
+
152
+ this.MM.add(this.element!.dataset.mcBreakpoint, () => {
153
+ const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);
154
+
155
+ if (this.element!.childElementCount < requiredQuantity) {
156
+ const fragment = document.createDocumentFragment();
157
+ const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);
158
+
159
+ clones.forEach((clone) => fragment.appendChild(clone));
160
+
161
+ this.element!.appendChild(fragment);
162
+ }
163
+
164
+ return removingClones;
165
+ });
166
+ }
167
+
168
+ private applySkew() {
169
+ if (!this.element?.dataset.mcSkew) return;
170
+
171
+ const abs = Math.abs(parseInt(this.element.dataset.mcSkew, 10));
172
+ const { style } = this.element;
173
+
174
+ style.transformOrigin = 'center center';
175
+ style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
176
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
177
+ }
178
+ }
179
+
180
+ export default MarqueeContent;
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "compilerOptions": {
3
+ "isolatedModules": true,
4
+ "target": "es2022"
5
+ }
6
+ }
package/src/index.js DELETED
@@ -1,68 +0,0 @@
1
- import * as Utils from './utils.js';
2
-
3
- class MarqueeContent {
4
- #gsap;
5
-
6
- #MM;
7
-
8
- #timeline;
9
-
10
- #element;
11
-
12
- #resizeObserver;
13
-
14
- #animationFrame;
15
-
16
- static gsap;
17
-
18
- static ScrollTrigger;
19
-
20
- constructor({element = '.marquee'} = {}) {
21
- this.#gsap = MarqueeContent.gsap ?? window.gsap;
22
- this.#MM = this.#gsap.matchMedia();
23
- this.#timeline = null;
24
- this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
25
-
26
- if (!this.#element) return;
27
-
28
- this.#resizeObserver = new ResizeObserver(Utils.debounce(() => this.#update()));
29
- this.#resizeObserver.observe(this.#element);
30
- }
31
-
32
- static registerGSAP(gsap, ScrollTrigger) {
33
- MarqueeContent.gsap = gsap;
34
- MarqueeContent.ScrollTrigger = ScrollTrigger;
35
- }
36
-
37
- #commonInit = () => {
38
- Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);
39
- Utils.cloning(this.#element, this.#gsap, this.#MM);
40
- Utils.breakpoints(this.#element);
41
- Utils.skewed(this.#element);
42
-
43
- this.#timeline = Utils.animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);
44
- };
45
-
46
- #update = () => {
47
- cancelAnimationFrame(this.#animationFrame);
48
- this.#animationFrame = requestAnimationFrame(() => {
49
- this.#commonInit();
50
-
51
- MarqueeContent.ScrollTrigger.refresh();
52
- });
53
- };
54
-
55
- init = () => {
56
- this.#commonInit();
57
- }
58
-
59
- destroy = () => {
60
- cancelAnimationFrame(this.#animationFrame);
61
-
62
- Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);
63
-
64
- this.#resizeObserver?.disconnect();
65
- }
66
- }
67
-
68
- export default MarqueeContent;
package/src/utils.js DELETED
@@ -1,95 +0,0 @@
1
- export const debounce = function(func) {
2
- let timer;
3
-
4
- return (...args) => {
5
- cancelAnimationFrame(timer);
6
-
7
- timer = requestAnimationFrame(() => func(...args));
8
- };
9
- };
10
-
11
- export const animation = function(element, gsap, MM, timeline, update) {
12
- timeline?.kill();
13
-
14
- timeline = gsap.timeline({
15
- scrollTrigger: {
16
- trigger: element,
17
- start: 'top bottom',
18
- end: 'bottom top',
19
- toggleActions: 'resume pause resume pause',
20
- onUpdate: (self) => {
21
- if (element.dataset.mcDirection === 'ltr') {
22
- timeline.timeScale(-1);
23
- } else if (element.dataset.mcDirection === 'auto') {
24
- timeline.timeScale(self.direction);
25
- }
26
- },
27
- }
28
- });
29
-
30
- MM.add(element.dataset.mcBreakpoint, () => {
31
- timeline.to(element.children, {
32
- duration: element.dataset.mcDuration ?? 20,
33
- x: '-100%',
34
- repeat: -1,
35
- ease: 'none',
36
- });
37
-
38
- timeline.totalProgress(0.5);
39
-
40
- return () => timeline?.kill();
41
- });
42
-
43
- update.timeline = timeline;
44
-
45
- return timeline;
46
- };
47
-
48
- export const breakpoints = function(element) {
49
- element.dataset.mcBreakpoint = element.dataset.mcMax
50
- ? `(max-width: ${element.dataset.mcMax - 0.02}px)`
51
- : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';
52
- };
53
-
54
- export const clearTimeline = function(timeline, element, gsap) {
55
- timeline?.kill();
56
- timeline = null;
57
-
58
- gsap.set(element.children, { clearProps: 'all' });
59
- };
60
-
61
- export const cloning = function(element, gsap, MM) {
62
- const removingClones = () => {
63
- while (element.childElementCount > 1) {
64
- element.removeChild(element.lastChild);
65
- }
66
- };
67
-
68
- removingClones();
69
-
70
- MM.add(element.dataset.mcBreakpoint, () => {
71
- const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
72
-
73
- if (element.childElementCount < requiredQuantity) {
74
- const fragment = document.createDocumentFragment();
75
- const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));
76
-
77
- clones.forEach(clone => fragment.appendChild(clone));
78
-
79
- element.appendChild(fragment);
80
- }
81
-
82
- return removingClones;
83
- });
84
- };
85
-
86
- export const skewed = function(element) {
87
- if (!element.dataset.mcSkew) return;
88
-
89
- const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
90
- const { style } = element;
91
-
92
- style.transformOrigin = 'center center';
93
- style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
94
- style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
95
- };