marquee-content 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,78 +9,67 @@ function $parcel$export(e, n, v, s) {
9
9
 
10
10
  $parcel$defineInteropFlag(module.exports);
11
11
 
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;
20
- static gsap;
21
- static ScrollTrigger;
12
+ $parcel$export(module.exports, "default", function () { return $6be4b30feeb09703$export$2e2bcd8739ae039; });
13
+ class $6be4b30feeb09703$var$MarqueeContent {
14
+ #gsap;
15
+ #MM;
16
+ #timeline;
17
+ #element;
18
+ #resizeObserver;
19
+ #animationFrame;
22
20
  constructor({ element: element = ".marquee" } = {}){
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);
21
+ this.#gsap = $6be4b30feeb09703$var$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
+ if (!this.#element) return;
26
+ this.#resizeObserver = new ResizeObserver($6be4b30feeb09703$var$MarqueeContent.#debounce(this.#update.bind(this)));
27
+ this.#resizeObserver.observe(this.#element);
30
28
  }
31
29
  static registerGSAP(gsap, ScrollTrigger) {
32
- $a196c1ed25598f0e$var$MarqueeContent.gsap = gsap;
33
- $a196c1ed25598f0e$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
30
+ $6be4b30feeb09703$var$MarqueeContent.gsap = gsap;
31
+ $6be4b30feeb09703$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
34
32
  }
35
- commonInit = ()=>{
36
- if (this.element) {
37
- this.clearTimeline();
38
- this.cloneElements();
39
- this.setBreakpoints();
40
- this.applySkew();
41
- this.timeline = this.createAnimation();
42
- }
43
- };
44
- update = ()=>{
45
- if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
46
- this.animationFrame = requestAnimationFrame(()=>{
47
- this.commonInit();
48
- $a196c1ed25598f0e$var$MarqueeContent.ScrollTrigger.refresh();
49
- });
50
- };
51
- init = ()=>{
52
- this.commonInit();
53
- };
54
- destroy = ()=>{
55
- if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
56
- if (this.element) this.clearTimeline();
57
- this.resizeObserver?.disconnect();
58
- };
59
- static debounce(func) {
33
+ static #debounce(func) {
60
34
  let timer = null;
61
35
  return (...args)=>{
62
36
  if (timer !== null) cancelAnimationFrame(timer);
63
37
  timer = requestAnimationFrame(()=>func(...args));
64
38
  };
65
39
  }
66
- createAnimation() {
67
- this.timeline?.kill();
68
- const timeline = this.gsap.timeline({
40
+ #commonInit() {
41
+ if (this.#element) {
42
+ this.#clearTimeline();
43
+ this.#cloneElements();
44
+ this.#setBreakpoints();
45
+ this.#applySkew();
46
+ this.#timeline = this.#createAnimation();
47
+ }
48
+ }
49
+ #update() {
50
+ if (this.#animationFrame !== null) cancelAnimationFrame(this.#animationFrame);
51
+ this.#animationFrame = requestAnimationFrame(()=>{
52
+ this.#commonInit();
53
+ $6be4b30feeb09703$var$MarqueeContent.ScrollTrigger.refresh();
54
+ });
55
+ }
56
+ #createAnimation() {
57
+ this.#timeline?.kill();
58
+ const timeline = this.#gsap.timeline({
69
59
  scrollTrigger: {
70
- trigger: this.element,
60
+ trigger: this.#element,
71
61
  start: "top bottom",
72
62
  end: "bottom top",
73
63
  toggleActions: "resume pause resume pause",
74
64
  onUpdate: (self)=>{
75
- if (this.element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
76
- else if (this.element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
65
+ if (this.#element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
66
+ else if (this.#element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
77
67
  }
78
68
  }
79
69
  });
80
- this.MM.add(this.element?.dataset.mcBreakpoint, ()=>{
81
- const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || "20");
82
- const speed = mcSpeed;
83
- timeline.to(this.element.children, {
70
+ this.#MM.add(this.#element?.dataset.mcBreakpoint, ()=>{
71
+ const speed = parseFloat(this.#element?.dataset.mcSpeed || "20");
72
+ timeline.to(this.#element.children, {
84
73
  duration: speed,
85
74
  x: "-100%",
86
75
  repeat: -1,
@@ -91,44 +80,52 @@ class $a196c1ed25598f0e$var$MarqueeContent {
91
80
  });
92
81
  return timeline;
93
82
  }
94
- setBreakpoints() {
95
- if (this.element.dataset.mcMax) this.element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element.dataset.mcMax) - 0.02}px)`;
96
- else if (this.element.dataset.mcMin) this.element.dataset.mcBreakpoint = `(min-width: ${this.element.dataset.mcMin}px)`;
97
- else this.element.dataset.mcBreakpoint = "";
83
+ #setBreakpoints() {
84
+ if (this.#element.dataset.mcMax) this.#element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.#element.dataset.mcMax) - 0.02}px)`;
85
+ else if (this.#element.dataset.mcMin) this.#element.dataset.mcBreakpoint = `(min-width: ${this.#element.dataset.mcMin}px)`;
86
+ else this.#element.dataset.mcBreakpoint = "";
98
87
  }
99
- clearTimeline() {
100
- this.timeline?.kill();
101
- this.timeline = null;
102
- this.gsap.set(this.element.children, {
88
+ #clearTimeline() {
89
+ this.#timeline?.kill();
90
+ this.#timeline = null;
91
+ this.#gsap.set(this.#element.children, {
103
92
  clearProps: "all"
104
93
  });
105
94
  }
106
- cloneElements() {
95
+ #cloneElements() {
107
96
  const removingClones = ()=>{
108
- while(this.element.childElementCount > 1)this.element.removeChild(this.element.lastChild);
97
+ while(this.#element.childElementCount > 1)this.#element.removeChild(this.#element.lastChild);
109
98
  };
110
99
  removingClones();
111
- this.MM.add(this.element.dataset.mcBreakpoint, ()=>{
112
- const requiredQuantity = Math.ceil(this.element.scrollWidth / this.element.firstElementChild.clientWidth + 2);
113
- if (this.element.childElementCount < requiredQuantity) {
100
+ this.#MM.add(this.#element.dataset.mcBreakpoint, ()=>{
101
+ const requiredQuantity = Math.ceil(this.#element.scrollWidth / this.#element.firstElementChild.clientWidth + 2);
102
+ if (this.#element.childElementCount < requiredQuantity) {
114
103
  const fragment = document.createDocumentFragment();
115
104
  const clones = Array.from({
116
105
  length: requiredQuantity - 1
117
- }, ()=>this.element.firstElementChild.cloneNode(true));
106
+ }, ()=>this.#element.firstElementChild.cloneNode(true));
118
107
  clones.forEach((clone)=>fragment.appendChild(clone));
119
- this.element.appendChild(fragment);
108
+ this.#element.appendChild(fragment);
120
109
  }
121
110
  return removingClones;
122
111
  });
123
112
  }
124
- applySkew() {
125
- if (!this.element?.dataset.mcSkew) return;
126
- const { style: style } = this.element;
113
+ #applySkew() {
114
+ if (!this.#element?.dataset.mcSkew) return;
115
+ const { style: style } = this.#element;
127
116
  style.transformOrigin = "center center";
128
- style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
117
+ style.transform = `skew(0deg, ${this.#element.dataset.mcSkew}deg)`;
118
+ }
119
+ init() {
120
+ this.#commonInit();
121
+ }
122
+ destroy() {
123
+ if (this.#animationFrame !== null) cancelAnimationFrame(this.#animationFrame);
124
+ if (this.#element) this.#clearTimeline();
125
+ this.#resizeObserver?.disconnect();
129
126
  }
130
127
  }
131
- var $a196c1ed25598f0e$export$2e2bcd8739ae039 = $a196c1ed25598f0e$var$MarqueeContent;
128
+ var $6be4b30feeb09703$export$2e2bcd8739ae039 = $6be4b30feeb09703$var$MarqueeContent;
132
129
 
133
130
 
134
131
  //# sourceMappingURL=index.js.map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YAAY;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,QAAQ;QAEnC,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;IACnE;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 mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');\n const speed = mcSpeed;\n\n timeline.to(this.element!.children, {\n duration: speed,\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 { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,CAAC,IAAI,CAAC;IAEN,CAAC,EAAE,CAAC;IAEJ,CAAC,QAAQ,CAAC;IAEV,CAAC,OAAO,CAAC;IAET,CAAC,cAAc,CAAC;IAEhB,CAAC,cAAc,CAAC;IAEhB,YAAY,WAAE,UAAU,YAAY,GAAG,CAAC,CAAC,CAAE;QACzC,IAAI,CAAC,CAAC,IAAI,GAAG,qCAAe,IAAI,IAAI,OAAO,IAAI;QAC/C,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU;QAChC,IAAI,CAAC,CAAC,QAAQ,GAAG;QACjB,IAAI,CAAC,CAAC,OAAO,GAAG,mBAAmB,cAAc,UAAU,SAAS,aAAa,CAAC;QAElF,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;QAEpB,IAAI,CAAC,CAAC,cAAc,GAAG,IAAI,eAAe,qCAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;QACzF,IAAI,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO;IAC5C;IAEA,OAAO,aAAa,IAAI,EAAE,aAAa,EAAE;QACvC,qCAAe,IAAI,GAAG;QACtB,qCAAe,aAAa,GAAG;IACjC;IAEA,OAAO,CAAC,QAAQ,CAAC,IAAI;QACnB,IAAI,QAAQ;QAEZ,OAAO,CAAC,GAAG;YACT,IAAI,UAAU,MACZ,qBAAqB;YAGvB,QAAQ,sBAAsB,IAA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AG,kBAAkB;gBACtD,MAAM,WAAW,SAAS,sBAAsB;gBAChD,MAAM,SAAS,MAAM,IAAI,CAAC;oBAAE,QAAQ,mBAAmB;gBAAE,GAAG,IAAM,IAAI,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC;gBAE5G,OAAO,OAAO,CAAC,CAAC,QAAU,SAAS,WAAW,CAAC;gBAE/C,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;YAC5B;YAEA,OAAO;QACT;IACF;IAEA,CAAC,SAAS;QACR,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,QAAQ;QAEpC,MAAM,SAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO;QAE/B,MAAM,eAAe,GAAG;QACxB,MAAM,SAAS,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;IACpE;IAEA,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB;IAEA,UAAU;QACR,IAAI,IAAI,CAAC,CAAC,cAAc,KAAK,MAC3B,qBAAqB,IAAI,CAAC,CAAC,cAAc;QAG3C,IAAI,IAAI,CAAC,CAAC,OAAO,EACf,IAAI,CAAC,CAAC,aAAa;QAGrB,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class 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(MarqueeContent.#debounce(this.#update.bind(this)));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap, ScrollTrigger) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n static #debounce(func) {\n let timer = null;\n\n return (...args) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n #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 #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 #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) => {\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 speed = parseFloat(this.#element?.dataset.mcSpeed || '20');\n\n timeline.to(this.#element.children, {\n duration: speed,\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 #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 #clearTimeline() {\n this.#timeline?.kill();\n this.#timeline = null;\n this.#gsap.set(this.#element.children, { clearProps: 'all' });\n }\n\n #cloneElements() {\n const removingClones = () => {\n while (this.#element.childElementCount > 1) {\n this.#element.removeChild(this.#element.lastChild);\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));\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.#element.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n #applySkew() {\n if (!this.#element?.dataset.mcSkew) return;\n\n const { style } = this.#element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.#element.dataset.mcSkew}deg)`;\n }\n\n init() {\n this.#commonInit();\n }\n\n 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\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -1,74 +1,63 @@
1
- class $643fcf18b2d2e76f$var$MarqueeContent {
2
- gsap;
3
- MM;
4
- timeline;
5
- element;
6
- resizeObserver;
7
- animationFrame = null;
8
- static gsap;
9
- static ScrollTrigger;
1
+ class $c38b013c361dbfdf$var$MarqueeContent {
2
+ #gsap;
3
+ #MM;
4
+ #timeline;
5
+ #element;
6
+ #resizeObserver;
7
+ #animationFrame;
10
8
  constructor({ element: element = ".marquee" } = {}){
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);
9
+ this.#gsap = $c38b013c361dbfdf$var$MarqueeContent.gsap || window.gsap;
10
+ this.#MM = this.#gsap.matchMedia();
11
+ this.#timeline = null;
12
+ this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
13
+ if (!this.#element) return;
14
+ this.#resizeObserver = new ResizeObserver($c38b013c361dbfdf$var$MarqueeContent.#debounce(this.#update.bind(this)));
15
+ this.#resizeObserver.observe(this.#element);
18
16
  }
19
17
  static registerGSAP(gsap, ScrollTrigger) {
20
- $643fcf18b2d2e76f$var$MarqueeContent.gsap = gsap;
21
- $643fcf18b2d2e76f$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
18
+ $c38b013c361dbfdf$var$MarqueeContent.gsap = gsap;
19
+ $c38b013c361dbfdf$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
22
20
  }
23
- commonInit = ()=>{
24
- if (this.element) {
25
- this.clearTimeline();
26
- this.cloneElements();
27
- this.setBreakpoints();
28
- this.applySkew();
29
- this.timeline = this.createAnimation();
30
- }
31
- };
32
- update = ()=>{
33
- if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
34
- this.animationFrame = requestAnimationFrame(()=>{
35
- this.commonInit();
36
- $643fcf18b2d2e76f$var$MarqueeContent.ScrollTrigger.refresh();
37
- });
38
- };
39
- init = ()=>{
40
- this.commonInit();
41
- };
42
- destroy = ()=>{
43
- if (this.animationFrame !== null) cancelAnimationFrame(this.animationFrame);
44
- if (this.element) this.clearTimeline();
45
- this.resizeObserver?.disconnect();
46
- };
47
- static debounce(func) {
21
+ static #debounce(func) {
48
22
  let timer = null;
49
23
  return (...args)=>{
50
24
  if (timer !== null) cancelAnimationFrame(timer);
51
25
  timer = requestAnimationFrame(()=>func(...args));
52
26
  };
53
27
  }
54
- createAnimation() {
55
- this.timeline?.kill();
56
- const timeline = this.gsap.timeline({
28
+ #commonInit() {
29
+ if (this.#element) {
30
+ this.#clearTimeline();
31
+ this.#cloneElements();
32
+ this.#setBreakpoints();
33
+ this.#applySkew();
34
+ this.#timeline = this.#createAnimation();
35
+ }
36
+ }
37
+ #update() {
38
+ if (this.#animationFrame !== null) cancelAnimationFrame(this.#animationFrame);
39
+ this.#animationFrame = requestAnimationFrame(()=>{
40
+ this.#commonInit();
41
+ $c38b013c361dbfdf$var$MarqueeContent.ScrollTrigger.refresh();
42
+ });
43
+ }
44
+ #createAnimation() {
45
+ this.#timeline?.kill();
46
+ const timeline = this.#gsap.timeline({
57
47
  scrollTrigger: {
58
- trigger: this.element,
48
+ trigger: this.#element,
59
49
  start: "top bottom",
60
50
  end: "bottom top",
61
51
  toggleActions: "resume pause resume pause",
62
52
  onUpdate: (self)=>{
63
- if (this.element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
64
- else if (this.element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
53
+ if (this.#element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
54
+ else if (this.#element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
65
55
  }
66
56
  }
67
57
  });
68
- this.MM.add(this.element?.dataset.mcBreakpoint, ()=>{
69
- const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || "20");
70
- const speed = mcSpeed;
71
- timeline.to(this.element.children, {
58
+ this.#MM.add(this.#element?.dataset.mcBreakpoint, ()=>{
59
+ const speed = parseFloat(this.#element?.dataset.mcSpeed || "20");
60
+ timeline.to(this.#element.children, {
72
61
  duration: speed,
73
62
  x: "-100%",
74
63
  repeat: -1,
@@ -79,45 +68,53 @@ class $643fcf18b2d2e76f$var$MarqueeContent {
79
68
  });
80
69
  return timeline;
81
70
  }
82
- setBreakpoints() {
83
- if (this.element.dataset.mcMax) this.element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element.dataset.mcMax) - 0.02}px)`;
84
- else if (this.element.dataset.mcMin) this.element.dataset.mcBreakpoint = `(min-width: ${this.element.dataset.mcMin}px)`;
85
- else this.element.dataset.mcBreakpoint = "";
71
+ #setBreakpoints() {
72
+ if (this.#element.dataset.mcMax) this.#element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.#element.dataset.mcMax) - 0.02}px)`;
73
+ else if (this.#element.dataset.mcMin) this.#element.dataset.mcBreakpoint = `(min-width: ${this.#element.dataset.mcMin}px)`;
74
+ else this.#element.dataset.mcBreakpoint = "";
86
75
  }
87
- clearTimeline() {
88
- this.timeline?.kill();
89
- this.timeline = null;
90
- this.gsap.set(this.element.children, {
76
+ #clearTimeline() {
77
+ this.#timeline?.kill();
78
+ this.#timeline = null;
79
+ this.#gsap.set(this.#element.children, {
91
80
  clearProps: "all"
92
81
  });
93
82
  }
94
- cloneElements() {
83
+ #cloneElements() {
95
84
  const removingClones = ()=>{
96
- while(this.element.childElementCount > 1)this.element.removeChild(this.element.lastChild);
85
+ while(this.#element.childElementCount > 1)this.#element.removeChild(this.#element.lastChild);
97
86
  };
98
87
  removingClones();
99
- this.MM.add(this.element.dataset.mcBreakpoint, ()=>{
100
- const requiredQuantity = Math.ceil(this.element.scrollWidth / this.element.firstElementChild.clientWidth + 2);
101
- if (this.element.childElementCount < requiredQuantity) {
88
+ this.#MM.add(this.#element.dataset.mcBreakpoint, ()=>{
89
+ const requiredQuantity = Math.ceil(this.#element.scrollWidth / this.#element.firstElementChild.clientWidth + 2);
90
+ if (this.#element.childElementCount < requiredQuantity) {
102
91
  const fragment = document.createDocumentFragment();
103
92
  const clones = Array.from({
104
93
  length: requiredQuantity - 1
105
- }, ()=>this.element.firstElementChild.cloneNode(true));
94
+ }, ()=>this.#element.firstElementChild.cloneNode(true));
106
95
  clones.forEach((clone)=>fragment.appendChild(clone));
107
- this.element.appendChild(fragment);
96
+ this.#element.appendChild(fragment);
108
97
  }
109
98
  return removingClones;
110
99
  });
111
100
  }
112
- applySkew() {
113
- if (!this.element?.dataset.mcSkew) return;
114
- const { style: style } = this.element;
101
+ #applySkew() {
102
+ if (!this.#element?.dataset.mcSkew) return;
103
+ const { style: style } = this.#element;
115
104
  style.transformOrigin = "center center";
116
- style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
105
+ style.transform = `skew(0deg, ${this.#element.dataset.mcSkew}deg)`;
106
+ }
107
+ init() {
108
+ this.#commonInit();
109
+ }
110
+ destroy() {
111
+ if (this.#animationFrame !== null) cancelAnimationFrame(this.#animationFrame);
112
+ if (this.#element) this.#clearTimeline();
113
+ this.#resizeObserver?.disconnect();
117
114
  }
118
115
  }
119
- var $643fcf18b2d2e76f$export$2e2bcd8739ae039 = $643fcf18b2d2e76f$var$MarqueeContent;
116
+ var $c38b013c361dbfdf$export$2e2bcd8739ae039 = $c38b013c361dbfdf$var$MarqueeContent;
120
117
 
121
118
 
122
- export {$643fcf18b2d2e76f$export$2e2bcd8739ae039 as default};
119
+ export {$c38b013c361dbfdf$export$2e2bcd8739ae039 as default};
123
120
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
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,EAAE,aAAoB,EAAE;QACrD,qCAAe,IAAI,GAAG;QACtB,qCAAe,aAAa,GAAG;IACjC;I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,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,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;IACnE;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 mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');\n const speed = mcSpeed;\n\n timeline.to(this.element!.children, {\n duration: speed,\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 { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"AAAA,MAAM;IACJ,CAAC,IAAI,CAAC;IAEN,CAAC,EAAE,CAAC;IAEJ,CAAC,QAAQ,CAAC;IAEV,CAAC,OAAO,CAAC;IAET,CAAC,cAAc,CAAC;IAEhB,CAAC,cAAc,CAAC;IAEhB,YAAY,WAAE,UAAU,YAAY,GAAG,CAAC,CAAC,CAAE;QACzC,IAAI,CAAC,CAAC,IAAI,GAAG,qCAAe,IAAI,IAAI,OAAO,IAAI;QAC/C,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU;QAChC,IAAI,CAAC,CAAC,QAAQ,GAAG;QACjB,IAAI,CAAC,CAAC,OAAO,GAAG,mBAAmB,cAAc,UAAU,SAAS,aAAa,CAAC;QAElF,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;QAE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AC,aAAa;QAGrB,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class 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(MarqueeContent.#debounce(this.#update.bind(this)));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap, ScrollTrigger) {\n MarqueeContent.gsap = gsap;\n MarqueeContent.ScrollTrigger = ScrollTrigger;\n }\n\n static #debounce(func) {\n let timer = null;\n\n return (...args) => {\n if (timer !== null) {\n cancelAnimationFrame(timer);\n }\n\n timer = requestAnimationFrame(() => func(...args));\n };\n }\n\n #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 #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 #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) => {\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 speed = parseFloat(this.#element?.dataset.mcSpeed || '20');\n\n timeline.to(this.#element.children, {\n duration: speed,\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 #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 #clearTimeline() {\n this.#timeline?.kill();\n this.#timeline = null;\n this.#gsap.set(this.#element.children, { clearProps: 'all' });\n }\n\n #cloneElements() {\n const removingClones = () => {\n while (this.#element.childElementCount > 1) {\n this.#element.removeChild(this.#element.lastChild);\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));\n\n clones.forEach((clone) => fragment.appendChild(clone));\n\n this.#element.appendChild(fragment);\n }\n\n return removingClones;\n });\n }\n\n #applySkew() {\n if (!this.#element?.dataset.mcSkew) return;\n\n const { style } = this.#element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.#element.dataset.mcSkew}deg)`;\n }\n\n init() {\n this.#commonInit();\n }\n\n 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\nexport default MarqueeContent;\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.4.0",
3
+ "version": "4.5.0",
4
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",
@@ -20,20 +20,14 @@
20
20
  "lintfix": "yarn lint:js --fix"
21
21
  },
22
22
  "browserslist": "> 0.5%, last 2 versions, not dead",
23
- "source": "src/index.ts",
23
+ "source": "src/index.js",
24
24
  "main": "dist/index.js",
25
25
  "module": "dist/index.module.js",
26
- "types": "dist/index.d.ts",
27
26
  "devDependencies": {
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
27
  "eslint": "^7.32.0 || ^8.57.0",
33
28
  "eslint-config-airbnb-base": "^15.0.0",
34
29
  "eslint-plugin-import": "^2.29.1",
35
- "parcel": "^2.12.0",
36
- "typescript": "^5.4.5"
30
+ "parcel": "^2.12.0"
37
31
  },
38
32
  "keywords": [
39
33
  "marquee",
@@ -55,7 +49,6 @@
55
49
  "scrollTrigger",
56
50
  "breakpoints",
57
51
  "debounce",
58
- "typescript",
59
52
  "clone",
60
53
  "skew",
61
54
  "responsive",
package/src/index.js ADDED
@@ -0,0 +1,170 @@
1
+ class MarqueeContent {
2
+ #gsap;
3
+
4
+ #MM;
5
+
6
+ #timeline;
7
+
8
+ #element;
9
+
10
+ #resizeObserver;
11
+
12
+ #animationFrame;
13
+
14
+ constructor({ element = '.marquee' } = {}) {
15
+ this.#gsap = MarqueeContent.gsap || window.gsap;
16
+ this.#MM = this.#gsap.matchMedia();
17
+ this.#timeline = null;
18
+ this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
19
+
20
+ if (!this.#element) return;
21
+
22
+ this.#resizeObserver = new ResizeObserver(MarqueeContent.#debounce(this.#update.bind(this)));
23
+ this.#resizeObserver.observe(this.#element);
24
+ }
25
+
26
+ static registerGSAP(gsap, ScrollTrigger) {
27
+ MarqueeContent.gsap = gsap;
28
+ MarqueeContent.ScrollTrigger = ScrollTrigger;
29
+ }
30
+
31
+ static #debounce(func) {
32
+ let timer = null;
33
+
34
+ return (...args) => {
35
+ if (timer !== null) {
36
+ cancelAnimationFrame(timer);
37
+ }
38
+
39
+ timer = requestAnimationFrame(() => func(...args));
40
+ };
41
+ }
42
+
43
+ #commonInit() {
44
+ if (this.#element) {
45
+ this.#clearTimeline();
46
+ this.#cloneElements();
47
+ this.#setBreakpoints();
48
+ this.#applySkew();
49
+
50
+ this.#timeline = this.#createAnimation();
51
+ }
52
+ }
53
+
54
+ #update() {
55
+ if (this.#animationFrame !== null) {
56
+ cancelAnimationFrame(this.#animationFrame);
57
+ }
58
+
59
+ this.#animationFrame = requestAnimationFrame(() => {
60
+ this.#commonInit();
61
+
62
+ MarqueeContent.ScrollTrigger.refresh();
63
+ });
64
+ }
65
+
66
+ #createAnimation() {
67
+ this.#timeline?.kill();
68
+
69
+ const timeline = this.#gsap.timeline({
70
+ scrollTrigger: {
71
+ trigger: this.#element,
72
+ start: 'top bottom',
73
+ end: 'bottom top',
74
+ toggleActions: 'resume pause resume pause',
75
+ onUpdate: (self) => {
76
+ if (this.#element?.dataset.mcDirection === 'ltr') {
77
+ timeline.timeScale(-1);
78
+ } else if (this.#element?.dataset.mcDirection === 'auto') {
79
+ timeline.timeScale(self.direction);
80
+ }
81
+ },
82
+ },
83
+ });
84
+
85
+ this.#MM.add(this.#element?.dataset.mcBreakpoint, () => {
86
+ const speed = parseFloat(this.#element?.dataset.mcSpeed || '20');
87
+
88
+ timeline.to(this.#element.children, {
89
+ duration: speed,
90
+ x: '-100%',
91
+ repeat: -1,
92
+ ease: 'none',
93
+ });
94
+
95
+ timeline.totalProgress(0.5);
96
+
97
+ return () => timeline?.kill();
98
+ });
99
+
100
+ return timeline;
101
+ }
102
+
103
+ #setBreakpoints() {
104
+ if (this.#element.dataset.mcMax) {
105
+ this.#element.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.#element.dataset.mcMax) - 0.02}px)`;
106
+ } else if (this.#element.dataset.mcMin) {
107
+ this.#element.dataset.mcBreakpoint = `(min-width: ${this.#element.dataset.mcMin}px)`;
108
+ } else {
109
+ this.#element.dataset.mcBreakpoint = '';
110
+ }
111
+ }
112
+
113
+ #clearTimeline() {
114
+ this.#timeline?.kill();
115
+ this.#timeline = null;
116
+ this.#gsap.set(this.#element.children, { clearProps: 'all' });
117
+ }
118
+
119
+ #cloneElements() {
120
+ const removingClones = () => {
121
+ while (this.#element.childElementCount > 1) {
122
+ this.#element.removeChild(this.#element.lastChild);
123
+ }
124
+ };
125
+
126
+ removingClones();
127
+
128
+ this.#MM.add(this.#element.dataset.mcBreakpoint, () => {
129
+ const requiredQuantity = Math.ceil(this.#element.scrollWidth / this.#element.firstElementChild.clientWidth + 2);
130
+
131
+ if (this.#element.childElementCount < requiredQuantity) {
132
+ const fragment = document.createDocumentFragment();
133
+ const clones = Array.from({ length: requiredQuantity - 1 }, () => this.#element.firstElementChild.cloneNode(true));
134
+
135
+ clones.forEach((clone) => fragment.appendChild(clone));
136
+
137
+ this.#element.appendChild(fragment);
138
+ }
139
+
140
+ return removingClones;
141
+ });
142
+ }
143
+
144
+ #applySkew() {
145
+ if (!this.#element?.dataset.mcSkew) return;
146
+
147
+ const { style } = this.#element;
148
+
149
+ style.transformOrigin = 'center center';
150
+ style.transform = `skew(0deg, ${this.#element.dataset.mcSkew}deg)`;
151
+ }
152
+
153
+ init() {
154
+ this.#commonInit();
155
+ }
156
+
157
+ destroy() {
158
+ if (this.#animationFrame !== null) {
159
+ cancelAnimationFrame(this.#animationFrame);
160
+ }
161
+
162
+ if (this.#element) {
163
+ this.#clearTimeline();
164
+ }
165
+
166
+ this.#resizeObserver?.disconnect();
167
+ }
168
+ }
169
+
170
+ export default MarqueeContent;
package/dist/index.d.ts DELETED
@@ -1,14 +0,0 @@
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
@@ -1 +0,0 @@
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;CAqGH;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 mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');\n const speed = mcSpeed;\n\n timeline.to(this.element!.children, {\n duration: speed,\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 { style } = this.element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;\n }\n}\n\nexport default MarqueeContent;\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/src/index.ts DELETED
@@ -1,179 +0,0 @@
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 mcSpeed = parseFloat(this.element?.dataset.mcSpeed || '20');
111
- const speed = mcSpeed;
112
-
113
- timeline.to(this.element!.children, {
114
- duration: speed,
115
- x: '-100%',
116
- repeat: -1,
117
- ease: 'none',
118
- });
119
-
120
- timeline.totalProgress(0.5);
121
-
122
- return () => timeline?.kill();
123
- });
124
-
125
- return timeline;
126
- }
127
-
128
- private setBreakpoints() {
129
- if (this.element!.dataset.mcMax) {
130
- this.element!.dataset.mcBreakpoint = `(max-width: ${parseFloat(this.element!.dataset.mcMax) - 0.02}px)`;
131
- } else if (this.element!.dataset.mcMin) {
132
- this.element!.dataset.mcBreakpoint = `(min-width: ${this.element!.dataset.mcMin}px)`;
133
- } else {
134
- this.element!.dataset.mcBreakpoint = '';
135
- }
136
- }
137
-
138
- private clearTimeline() {
139
- this.timeline?.kill();
140
- this.timeline = null;
141
- this.gsap.set(this.element!.children, { clearProps: 'all' });
142
- }
143
-
144
- private cloneElements() {
145
- const removingClones = () => {
146
- while (this.element!.childElementCount > 1) {
147
- this.element!.removeChild(this.element!.lastChild as ChildNode);
148
- }
149
- };
150
-
151
- removingClones();
152
-
153
- this.MM.add(this.element!.dataset.mcBreakpoint, () => {
154
- const requiredQuantity = Math.ceil(this.element!.scrollWidth / this.element!.firstElementChild!.clientWidth + 2);
155
-
156
- if (this.element!.childElementCount < requiredQuantity) {
157
- const fragment = document.createDocumentFragment();
158
- const clones = Array.from({ length: requiredQuantity - 1 }, () => this.element!.firstElementChild!.cloneNode(true) as HTMLElement);
159
-
160
- clones.forEach((clone) => fragment.appendChild(clone));
161
-
162
- this.element!.appendChild(fragment);
163
- }
164
-
165
- return removingClones;
166
- });
167
- }
168
-
169
- private applySkew() {
170
- if (!this.element?.dataset.mcSkew) return;
171
-
172
- const { style } = this.element;
173
-
174
- style.transformOrigin = 'center center';
175
- style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
176
- }
177
- }
178
-
179
- export default MarqueeContent;
package/tsconfig.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "isolatedModules": true,
4
- "target": "es2022"
5
- }
6
- }