marquee-content 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,20 +28,39 @@ yarn add marquee-content
28
28
  import { gsap } from 'gsap';
29
29
  import { ScrollTrigger } from 'gsap/ScrollTrigger';
30
30
  import MarqueeContent from 'marquee-content';
31
+
32
+ gsap.registerPlugin(ScrollTrigger);
33
+ MarqueeContent.registerGSAP(gsap);
31
34
  ```
32
35
  <br>
33
36
 
34
37
  &#10148; **Usage**
35
38
  ```javascript
36
- gsap.registerPlugin(ScrollTrigger);
37
- MarqueeContent.registerGSAP(gsap);
39
+ const marquee = new MarqueeContent({
40
+ element: '.marquee',
41
+ });
38
42
 
39
- const marqueeContent = new MarqueeContent();
43
+ marquee.init();
44
+ ```
45
+ or
46
+ ```javascript
47
+ document.querySelectorAll('.marquee').forEach((element) => {
48
+ const marquee = new MarqueeContent({
49
+ element,
50
+ });
40
51
 
41
- marqueeContent.init();
52
+ marquee.init();
53
+ });
42
54
  ```
43
55
  <br>
44
56
 
57
+ &#10148; **Options**
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. |
62
+ <br>
63
+
45
64
  &#10148; **Settings**
46
65
 
47
66
  | Option | Default | Description |
package/dist/index.js CHANGED
@@ -82,31 +82,31 @@ const $4559ecf940edc78d$export$3484d11c6bb42ecc = function(element) {
82
82
  };
83
83
 
84
84
 
85
- class $4fa36e821943b400$export$2e2bcd8739ae039 {
85
+ class $4fa36e821943b400$var$MarqueeContent {
86
86
  #gsap;
87
87
  #MM;
88
88
  #timeline;
89
89
  #element;
90
90
  #resizeObserver;
91
91
  #animationFrame;
92
- constructor(el){
93
- this.#gsap = $4fa36e821943b400$export$2e2bcd8739ae039.gsap ?? window.gsap;
92
+ constructor({ element: element = ".marquee" } = {}){
93
+ this.#gsap = $4fa36e821943b400$var$MarqueeContent.gsap ?? window.gsap;
94
94
  this.#MM = this.#gsap.matchMedia();
95
95
  this.#timeline = null;
96
- this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? ".marquee");
97
- if (!this.#element) throw new Error("Element not found");
98
- this.#resizeObserver = new ResizeObserver((0, $4559ecf940edc78d$export$61fc7d43ac8f84b0)(()=>this.#update()));
96
+ this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
97
+ if (!this.#element) return;
98
+ this.#resizeObserver = new ResizeObserver($4559ecf940edc78d$export$61fc7d43ac8f84b0(()=>this.#update()));
99
99
  this.#resizeObserver.observe(this.#element);
100
100
  }
101
101
  static registerGSAP(gsap) {
102
- $4fa36e821943b400$export$2e2bcd8739ae039.gsap = gsap;
102
+ $4fa36e821943b400$var$MarqueeContent.gsap = gsap;
103
103
  }
104
104
  #commonInit = ()=>{
105
- (0, $4559ecf940edc78d$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
106
- (0, $4559ecf940edc78d$export$7c4d14cd3c92bf0b)(this.#element, this.#gsap, this.#MM);
107
- (0, $4559ecf940edc78d$export$d07517a676ce386f)(this.#element);
108
- (0, $4559ecf940edc78d$export$3484d11c6bb42ecc)(this.#element);
109
- this.#timeline = (0, $4559ecf940edc78d$export$ecad260a8a5fef4f)(this.#element, this.#gsap, this.#MM, this.#timeline, this);
105
+ $4559ecf940edc78d$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
106
+ $4559ecf940edc78d$export$7c4d14cd3c92bf0b(this.#element, this.#gsap, this.#MM);
107
+ $4559ecf940edc78d$export$d07517a676ce386f(this.#element);
108
+ $4559ecf940edc78d$export$3484d11c6bb42ecc(this.#element);
109
+ this.#timeline = $4559ecf940edc78d$export$ecad260a8a5fef4f(this.#element, this.#gsap, this.#MM, this.#timeline, this);
110
110
  };
111
111
  #update = ()=>{
112
112
  cancelAnimationFrame(this.#animationFrame);
@@ -120,10 +120,11 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 {
120
120
  };
121
121
  destroy = ()=>{
122
122
  cancelAnimationFrame(this.#animationFrame);
123
- (0, $4559ecf940edc78d$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
123
+ $4559ecf940edc78d$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
124
124
  this.#resizeObserver?.disconnect();
125
125
  };
126
126
  }
127
+ var $4fa36e821943b400$export$2e2bcd8739ae039 = $4fa36e821943b400$var$MarqueeContent;
127
128
 
128
129
 
129
130
  //# 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,QAA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,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QACvD,CAAA,GAAA,yCAAM,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE;QAC3C,CAAA,GAAA,yCAAU,EAAE,IAAI,CAAC,CAAC,OAAO;QACzB,CAAA,GAAA,yCAAK,EAAE,IAAI,CAAC,CAAC,OAAO;QACpB,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAA,GAAA,yCAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI;IACtF,EAAE;IAEF,CAAC,MAAM,GAAG;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAChB,cAAc,OAAO;QACvB;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QACvD,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH","sources":["src/index.js","src/utils.js"],"sourcesContent":["import {\n debounce,\n breakpoints,\n cloning,\n skewed,\n animation,\n clearTimeline,\n} from './utils.js';\n\nexport default class MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n constructor(el) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');\n if (!this.#element) throw new Error('Element not found');\n\n this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n #commonInit = () => {\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n cloning(this.#element, this.#gsap, this.#MM);\n breakpoints(this.#element);\n skewed(this.#element);\n this.#timeline = 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 ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n this.#resizeObserver?.disconnect();\n }\n}\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":";;;;;;;;;;;;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,SAA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AAI,GAAG;IACxB;IAEA,CAAC,UAAU,GAAG;QACZ,0CAAoB,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,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,cAAc,OAAO;QACvB;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 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) {\n MarqueeContent.gsap = gsap;\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 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"}
@@ -70,31 +70,31 @@ const $f3ad94c9f84f4d57$export$3484d11c6bb42ecc = function(element) {
70
70
  };
71
71
 
72
72
 
73
- class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
73
+ class $cf838c15c8b009ba$var$MarqueeContent {
74
74
  #gsap;
75
75
  #MM;
76
76
  #timeline;
77
77
  #element;
78
78
  #resizeObserver;
79
79
  #animationFrame;
80
- constructor(el){
81
- this.#gsap = $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap ?? window.gsap;
80
+ constructor({ element: element = ".marquee" } = {}){
81
+ this.#gsap = $cf838c15c8b009ba$var$MarqueeContent.gsap ?? window.gsap;
82
82
  this.#MM = this.#gsap.matchMedia();
83
83
  this.#timeline = null;
84
- this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? ".marquee");
85
- if (!this.#element) throw new Error("Element not found");
86
- this.#resizeObserver = new ResizeObserver((0, $f3ad94c9f84f4d57$export$61fc7d43ac8f84b0)(()=>this.#update()));
84
+ this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
85
+ if (!this.#element) return;
86
+ this.#resizeObserver = new ResizeObserver($f3ad94c9f84f4d57$export$61fc7d43ac8f84b0(()=>this.#update()));
87
87
  this.#resizeObserver.observe(this.#element);
88
88
  }
89
89
  static registerGSAP(gsap) {
90
- $cf838c15c8b009ba$export$2e2bcd8739ae039.gsap = gsap;
90
+ $cf838c15c8b009ba$var$MarqueeContent.gsap = gsap;
91
91
  }
92
92
  #commonInit = ()=>{
93
- (0, $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
94
- (0, $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b)(this.#element, this.#gsap, this.#MM);
95
- (0, $f3ad94c9f84f4d57$export$d07517a676ce386f)(this.#element);
96
- (0, $f3ad94c9f84f4d57$export$3484d11c6bb42ecc)(this.#element);
97
- this.#timeline = (0, $f3ad94c9f84f4d57$export$ecad260a8a5fef4f)(this.#element, this.#gsap, this.#MM, this.#timeline, this);
93
+ $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
94
+ $f3ad94c9f84f4d57$export$7c4d14cd3c92bf0b(this.#element, this.#gsap, this.#MM);
95
+ $f3ad94c9f84f4d57$export$d07517a676ce386f(this.#element);
96
+ $f3ad94c9f84f4d57$export$3484d11c6bb42ecc(this.#element);
97
+ this.#timeline = $f3ad94c9f84f4d57$export$ecad260a8a5fef4f(this.#element, this.#gsap, this.#MM, this.#timeline, this);
98
98
  };
99
99
  #update = ()=>{
100
100
  cancelAnimationFrame(this.#animationFrame);
@@ -108,10 +108,11 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
108
108
  };
109
109
  destroy = ()=>{
110
110
  cancelAnimationFrame(this.#animationFrame);
111
- (0, $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b)(this.#timeline, this.#element, this.#gsap);
111
+ $f3ad94c9f84f4d57$export$6a732ac1b1fdc86b(this.#timeline, this.#element, this.#gsap);
112
112
  this.#resizeObserver?.disconnect();
113
113
  };
114
114
  }
115
+ var $cf838c15c8b009ba$export$2e2bcd8739ae039 = $cf838c15c8b009ba$var$MarqueeContent;
115
116
 
116
117
 
117
118
  export {$cf838c15c8b009ba$export$2e2bcd8739ae039 as default};
@@ -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,4CAAc,SAAS,OAAO;IACzC,QAAQ,OAAO,CAAC,YAAY,GAAG,QAAQ,OAAO,CAAC,KAAK,GAChD,CAAC,YAAY,EAAE,QAAQ,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAA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AC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI;IACtF,EAAE;IAEF,CAAC,MAAM,GAAG;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,IAAI,CAAC,CAAC,cAAc,GAAG,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAChB,cAAc,OAAO;QACvB;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QACvD,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH","sources":["src/index.js","src/utils.js"],"sourcesContent":["import {\n debounce,\n breakpoints,\n cloning,\n skewed,\n animation,\n clearTimeline,\n} from './utils.js';\n\nexport default class MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n constructor(el) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');\n if (!this.#element) throw new Error('Element not found');\n\n this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n #commonInit = () => {\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n cloning(this.#element, this.#gsap, this.#MM);\n breakpoints(this.#element);\n skewed(this.#element);\n this.#timeline = 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 ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n this.#resizeObserver?.disconnect();\n }\n}\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":"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,4CAAc,SAAS,OAAO;IACzC,QAAQ,OAAO,CAAC,YAAY,GAAG,QAAQ,OAAO,CAAC,KAAK,GAChD,CAAC,YAAY,EAAE,QAAQ,OAAO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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,cAAc,OAAO;QACvB;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 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) {\n MarqueeContent.gsap = gsap;\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 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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Class for creating the running content effect, also known as a marquee or ticker.",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
@@ -12,7 +12,6 @@
12
12
  "url": "https://github.com/ux-ui-pro/marquee-content/issues"
13
13
  },
14
14
  "main": "dist/index.js",
15
- "source": "dist/index.html",
16
15
  "module": "dist/index.module.js",
17
16
  "targets": {
18
17
  "main": {
package/src/index.js CHANGED
@@ -1,13 +1,6 @@
1
- import {
2
- debounce,
3
- breakpoints,
4
- cloning,
5
- skewed,
6
- animation,
7
- clearTimeline,
8
- } from './utils.js';
9
-
10
- export default class MarqueeContent {
1
+ import * as Utils from './utils.js';
2
+
3
+ class MarqueeContent {
11
4
  #gsap;
12
5
 
13
6
  #MM;
@@ -20,14 +13,15 @@ export default class MarqueeContent {
20
13
 
21
14
  #animationFrame;
22
15
 
23
- constructor(el) {
16
+ constructor({element = '.marquee'} = {}) {
24
17
  this.#gsap = MarqueeContent.gsap ?? window.gsap;
25
18
  this.#MM = this.#gsap.matchMedia();
26
19
  this.#timeline = null;
27
- this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');
28
- if (!this.#element) throw new Error('Element not found');
20
+ this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
21
+
22
+ if (!this.#element) return;
29
23
 
30
- this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));
24
+ this.#resizeObserver = new ResizeObserver(Utils.debounce(() => this.#update()));
31
25
  this.#resizeObserver.observe(this.#element);
32
26
  }
33
27
 
@@ -36,17 +30,19 @@ export default class MarqueeContent {
36
30
  }
37
31
 
38
32
  #commonInit = () => {
39
- clearTimeline(this.#timeline, this.#element, this.#gsap);
40
- cloning(this.#element, this.#gsap, this.#MM);
41
- breakpoints(this.#element);
42
- skewed(this.#element);
43
- this.#timeline = animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);
33
+ Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);
34
+ Utils.cloning(this.#element, this.#gsap, this.#MM);
35
+ Utils.breakpoints(this.#element);
36
+ Utils.skewed(this.#element);
37
+
38
+ this.#timeline = Utils.animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);
44
39
  };
45
40
 
46
41
  #update = () => {
47
42
  cancelAnimationFrame(this.#animationFrame);
48
43
  this.#animationFrame = requestAnimationFrame(() => {
49
44
  this.#commonInit();
45
+
50
46
  ScrollTrigger.refresh();
51
47
  });
52
48
  };
@@ -57,7 +53,11 @@ export default class MarqueeContent {
57
53
 
58
54
  destroy = () => {
59
55
  cancelAnimationFrame(this.#animationFrame);
60
- clearTimeline(this.#timeline, this.#element, this.#gsap);
56
+
57
+ Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);
58
+
61
59
  this.#resizeObserver?.disconnect();
62
60
  }
63
61
  }
62
+
63
+ export default MarqueeContent;
package/src/demo.js DELETED
@@ -1,10 +0,0 @@
1
- import MarqueeContent from './index.js';
2
-
3
- gsap.registerPlugin(ScrollTrigger);
4
- MarqueeContent.registerGSAP(gsap);
5
-
6
- document.querySelectorAll('.marquee').forEach((el) => {
7
- const marquee = new MarqueeContent(el);
8
-
9
- marquee.init();
10
- });