marquee-content 4.4.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,123 +0,0 @@
1
- class $643fcf18b2d2e76f$var$MarqueeContent {
2
- gsap;
3
- MM;
4
- timeline;
5
- element;
6
- resizeObserver;
7
- animationFrame = null;
8
- static gsap;
9
- static ScrollTrigger;
10
- 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);
18
- }
19
- static registerGSAP(gsap, ScrollTrigger) {
20
- $643fcf18b2d2e76f$var$MarqueeContent.gsap = gsap;
21
- $643fcf18b2d2e76f$var$MarqueeContent.ScrollTrigger = ScrollTrigger;
22
- }
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) {
48
- let timer = null;
49
- return (...args)=>{
50
- if (timer !== null) cancelAnimationFrame(timer);
51
- timer = requestAnimationFrame(()=>func(...args));
52
- };
53
- }
54
- createAnimation() {
55
- this.timeline?.kill();
56
- const timeline = this.gsap.timeline({
57
- scrollTrigger: {
58
- trigger: this.element,
59
- start: "top bottom",
60
- end: "bottom top",
61
- toggleActions: "resume pause resume pause",
62
- onUpdate: (self)=>{
63
- if (this.element?.dataset.mcDirection === "ltr") timeline.timeScale(-1);
64
- else if (this.element?.dataset.mcDirection === "auto") timeline.timeScale(self.direction);
65
- }
66
- }
67
- });
68
- this.MM.add(this.element?.dataset.mcBreakpoint, ()=>{
69
- const mcSpeed = parseFloat(this.element?.dataset.mcSpeed || "20");
70
- const speed = mcSpeed;
71
- timeline.to(this.element.children, {
72
- duration: speed,
73
- x: "-100%",
74
- repeat: -1,
75
- ease: "none"
76
- });
77
- timeline.totalProgress(0.5);
78
- return ()=>timeline?.kill();
79
- });
80
- return timeline;
81
- }
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 = "";
86
- }
87
- clearTimeline() {
88
- this.timeline?.kill();
89
- this.timeline = null;
90
- this.gsap.set(this.element.children, {
91
- clearProps: "all"
92
- });
93
- }
94
- cloneElements() {
95
- const removingClones = ()=>{
96
- while(this.element.childElementCount > 1)this.element.removeChild(this.element.lastChild);
97
- };
98
- 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) {
102
- const fragment = document.createDocumentFragment();
103
- const clones = Array.from({
104
- length: requiredQuantity - 1
105
- }, ()=>this.element.firstElementChild.cloneNode(true));
106
- clones.forEach((clone)=>fragment.appendChild(clone));
107
- this.element.appendChild(fragment);
108
- }
109
- return removingClones;
110
- });
111
- }
112
- applySkew() {
113
- if (!this.element?.dataset.mcSkew) return;
114
- const { style: style } = this.element;
115
- style.transformOrigin = "center center";
116
- style.transform = `skew(0deg, ${this.element.dataset.mcSkew}deg)`;
117
- }
118
- }
119
- var $643fcf18b2d2e76f$export$2e2bcd8739ae039 = $643fcf18b2d2e76f$var$MarqueeContent;
120
-
121
-
122
- export {$643fcf18b2d2e76f$export$2e2bcd8739ae039 as default};
123
- //# sourceMappingURL=index.module.js.map
@@ -1 +0,0 @@
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;IAEQ,aAAa;QACnB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,aAAa;YAClB,IAAI,CAAC,aAAa;YAClB,IAAI,CAAC,cAAc;YACnB,IAAI,CAAC,SAAS;YAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe;QACtC;IACF,EAAE;IAEM,SAAS;QACf,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AAQ,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"}
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
- }