marquee-content 4.5.0 → 4.5.1-dev.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.
@@ -1,120 +0,0 @@
1
- class $c38b013c361dbfdf$var$MarqueeContent {
2
- #gsap;
3
- #MM;
4
- #timeline;
5
- #element;
6
- #resizeObserver;
7
- #animationFrame;
8
- constructor({ element: element = ".marquee" } = {}){
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);
16
- }
17
- static registerGSAP(gsap, ScrollTrigger) {
18
- $c38b013c361dbfdf$var$MarqueeContent.gsap = gsap;
19
- $c38b013c361dbfdf$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
20
- }
21
- static #debounce(func) {
22
- let timer = null;
23
- return (...args)=>{
24
- if (timer !== null) cancelAnimationFrame(timer);
25
- timer = requestAnimationFrame(()=>func(...args));
26
- };
27
- }
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({
47
- scrollTrigger: {
48
- trigger: this.#element,
49
- start: "top bottom",
50
- end: "bottom top",
51
- toggleActions: "resume pause resume pause",
52
- onUpdate: (self)=>{
53
- if (this.#element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
54
- else if (this.#element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
55
- }
56
- }
57
- });
58
- this.#MM.add(this.#element?.dataset.mcBreakpoint, ()=>{
59
- const speed = parseFloat(this.#element?.dataset.mcSpeed || "20");
60
- timeline.to(this.#element.children, {
61
- duration: speed,
62
- x: "-100%",
63
- repeat: -1,
64
- ease: "none"
65
- });
66
- timeline.totalProgress(0.5);
67
- return ()=>timeline?.kill();
68
- });
69
- return timeline;
70
- }
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 = "";
75
- }
76
- #clearTimeline() {
77
- this.#timeline?.kill();
78
- this.#timeline = null;
79
- this.#gsap.set(this.#element.children, {
80
- clearProps: "all"
81
- });
82
- }
83
- #cloneElements() {
84
- const removingClones = ()=>{
85
- while(this.#element.childElementCount > 1)this.#element.removeChild(this.#element.lastChild);
86
- };
87
- removingClones();
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) {
91
- const fragment = document.createDocumentFragment();
92
- const clones = Array.from({
93
- length: requiredQuantity - 1
94
- }, ()=>this.#element.firstElementChild.cloneNode(true));
95
- clones.forEach((clone)=>fragment.appendChild(clone));
96
- this.#element.appendChild(fragment);
97
- }
98
- return removingClones;
99
- });
100
- }
101
- #applySkew() {
102
- if (!this.#element?.dataset.mcSkew) return;
103
- const { style: style } = this.#element;
104
- style.transformOrigin = "center center";
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();
114
- }
115
- }
116
- var $c38b013c361dbfdf$export$2e2bcd8739ae039 = $c38b013c361dbfdf$var$MarqueeContent;
117
-
118
-
119
- export {$c38b013c361dbfdf$export$2e2bcd8739ae039 as default};
120
- //# sourceMappingURL=index.module.js.map
@@ -1 +0,0 @@
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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AO,CAAC,iBAAiB,GAAG,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.module.js.map"}
package/src/index.js DELETED
@@ -1,170 +0,0 @@
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;