marquee-content 3.1.1 → 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/LICENSE +1 -1
- package/README.md +30 -14
- package/dist/index.js +101 -116
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +99 -114
- package/dist/index.module.js.map +1 -1
- package/package.json +5 -6
- package/src/index.js +45 -53
- package/src/utils.js +95 -0
- package/dist/index.468c551c.js +0 -764
- package/dist/index.html +0 -262
- package/src/index.html +0 -150
- package/src/utils/animation.js +0 -39
- package/src/utils/breakpoints.js +0 -11
- package/src/utils/clearTimeline.js +0 -10
- package/src/utils/cloning.js +0 -22
- package/src/utils/skewed.js +0 -18
- package/src/utils/update.js +0 -15
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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,SA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AAE,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.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marquee-content",
|
|
3
|
-
"version": "
|
|
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": {
|
|
@@ -30,11 +29,11 @@
|
|
|
30
29
|
"lintfix": "yarn lint:js --fix"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"eslint": "^
|
|
32
|
+
"eslint": "^8.57.0",
|
|
34
33
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
35
|
-
"eslint-plugin-import": "^2.29.
|
|
36
|
-
"parcel": "^2.
|
|
37
|
-
"postcss-html": "^1.
|
|
34
|
+
"eslint-plugin-import": "^2.29.1",
|
|
35
|
+
"parcel": "^2.12.0",
|
|
36
|
+
"postcss-html": "^1.6.0"
|
|
38
37
|
},
|
|
39
38
|
"keywords": [
|
|
40
39
|
"marquee",
|
package/src/index.js
CHANGED
|
@@ -1,71 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import * as Utils from './utils.js';
|
|
2
|
+
|
|
3
|
+
class MarqueeContent {
|
|
4
|
+
#gsap;
|
|
5
|
+
|
|
6
|
+
#MM;
|
|
7
|
+
|
|
8
|
+
#timeline;
|
|
9
|
+
|
|
10
|
+
#element;
|
|
11
|
+
|
|
12
|
+
#resizeObserver;
|
|
13
|
+
|
|
14
|
+
#animationFrame;
|
|
15
|
+
|
|
16
|
+
constructor({element = '.marquee'} = {}) {
|
|
17
|
+
this.#gsap = MarqueeContent.gsap ?? window.gsap;
|
|
18
|
+
this.#MM = this.#gsap.matchMedia();
|
|
19
|
+
this.#timeline = null;
|
|
20
|
+
this.#element = element instanceof HTMLElement ? element : document.querySelector(element);
|
|
21
|
+
|
|
22
|
+
if (!this.#element) return;
|
|
23
|
+
|
|
24
|
+
this.#resizeObserver = new ResizeObserver(Utils.debounce(() => this.#update()));
|
|
25
|
+
this.#resizeObserver.observe(this.#element);
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
static registerGSAP(gsap) {
|
|
20
29
|
MarqueeContent.gsap = gsap;
|
|
21
30
|
}
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
#commonInit = () => {
|
|
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);
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
cancelAnimationFrame(timer);
|
|
28
|
-
timer = requestAnimationFrame(this.update);
|
|
29
|
-
};
|
|
38
|
+
this.#timeline = Utils.animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);
|
|
30
39
|
};
|
|
31
40
|
|
|
32
|
-
update() {
|
|
33
|
-
cancelAnimationFrame(this
|
|
41
|
+
#update = () => {
|
|
42
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
43
|
+
this.#animationFrame = requestAnimationFrame(() => {
|
|
44
|
+
this.#commonInit();
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
animation.call(this);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
46
|
+
ScrollTrigger.refresh();
|
|
47
|
+
});
|
|
48
|
+
};
|
|
42
49
|
|
|
43
|
-
init() {
|
|
44
|
-
|
|
45
|
-
skewed.call(this);
|
|
46
|
-
cloning.call(this);
|
|
47
|
-
animation.call(this);
|
|
50
|
+
init = () => {
|
|
51
|
+
this.#commonInit();
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
destroy() {
|
|
51
|
-
cancelAnimationFrame(this
|
|
52
|
-
|
|
53
|
-
clearTimeline.call(this);
|
|
54
|
+
destroy = () => {
|
|
55
|
+
cancelAnimationFrame(this.#animationFrame);
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
this.resizeObserver.disconnect();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
connectedCallback() {
|
|
61
|
-
this.init();
|
|
62
|
-
}
|
|
57
|
+
Utils.clearTimeline(this.#timeline, this.#element, this.#gsap);
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
this.destroy();
|
|
59
|
+
this.#resizeObserver?.disconnect();
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
|
|
70
|
-
customElements.define('marquee-content', MarqueeContent);
|
|
71
|
-
}
|
|
63
|
+
export default MarqueeContent;
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export const debounce = function(func) {
|
|
2
|
+
let timer;
|
|
3
|
+
|
|
4
|
+
return (...args) => {
|
|
5
|
+
cancelAnimationFrame(timer);
|
|
6
|
+
|
|
7
|
+
timer = requestAnimationFrame(() => func(...args));
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const animation = function(element, gsap, MM, timeline, update) {
|
|
12
|
+
timeline?.kill();
|
|
13
|
+
|
|
14
|
+
timeline = gsap.timeline({
|
|
15
|
+
scrollTrigger: {
|
|
16
|
+
trigger: element,
|
|
17
|
+
start: 'top bottom',
|
|
18
|
+
end: 'bottom top',
|
|
19
|
+
toggleActions: 'resume pause resume pause',
|
|
20
|
+
onUpdate: (self) => {
|
|
21
|
+
if (element.dataset.mcDirection === 'ltr') {
|
|
22
|
+
timeline.timeScale(-1);
|
|
23
|
+
} else if (element.dataset.mcDirection === 'auto') {
|
|
24
|
+
timeline.timeScale(self.direction);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
MM.add(element.dataset.mcBreakpoint, () => {
|
|
31
|
+
timeline.to(element.children, {
|
|
32
|
+
duration: element.dataset.mcDuration ?? 20,
|
|
33
|
+
x: '-100%',
|
|
34
|
+
repeat: -1,
|
|
35
|
+
ease: 'none',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
timeline.totalProgress(0.5);
|
|
39
|
+
|
|
40
|
+
return () => timeline?.kill();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
update.timeline = timeline;
|
|
44
|
+
|
|
45
|
+
return timeline;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const breakpoints = function(element) {
|
|
49
|
+
element.dataset.mcBreakpoint = element.dataset.mcMax
|
|
50
|
+
? `(max-width: ${element.dataset.mcMax - 0.02}px)`
|
|
51
|
+
: element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const clearTimeline = function(timeline, element, gsap) {
|
|
55
|
+
timeline?.kill();
|
|
56
|
+
timeline = null;
|
|
57
|
+
|
|
58
|
+
gsap.set(element.children, { clearProps: 'all' });
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const cloning = function(element, gsap, MM) {
|
|
62
|
+
const removingClones = () => {
|
|
63
|
+
while (element.childElementCount > 1) {
|
|
64
|
+
element.removeChild(element.lastChild);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
removingClones();
|
|
69
|
+
|
|
70
|
+
MM.add(element.dataset.mcBreakpoint, () => {
|
|
71
|
+
const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);
|
|
72
|
+
|
|
73
|
+
if (element.childElementCount < requiredQuantity) {
|
|
74
|
+
const fragment = document.createDocumentFragment();
|
|
75
|
+
const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));
|
|
76
|
+
|
|
77
|
+
clones.forEach(clone => fragment.appendChild(clone));
|
|
78
|
+
|
|
79
|
+
element.appendChild(fragment);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return removingClones;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const skewed = function(element) {
|
|
87
|
+
if (!element.dataset.mcSkew) return;
|
|
88
|
+
|
|
89
|
+
const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));
|
|
90
|
+
const { style } = element;
|
|
91
|
+
|
|
92
|
+
style.transformOrigin = 'center center';
|
|
93
|
+
style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;
|
|
94
|
+
style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
|
|
95
|
+
};
|