marquee-content 3.1.1 → 4.0.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 +1 @@
1
- {"mappings":"ACAA,SAAS;IACP,IAAI,CAAC,UAAU,GAAG;IAElB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EACpB,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC;SAC1D,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAC3B,IAAI,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;AAE5D;IAEA,2CAAe;;;ACVf,SAAS;IACP,MAAM,iBAAiB;QACrB,MAAO,IAAI,CAAC,iBAAiB,GAAG,EAC9B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS;IAEnC;IAEA;IAEA,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE;QAC3B,MAAM,mBAAmB,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,WAAW,GAAG;QAE3F,IAAI,IAAI,CAAC,iBAAiB,GAAG,kBAAkB;YAC7C,MAAM,SAAS,MAAM,IAAI,CAAC;gBAAE,QAAQ,mBAAmB;YAAE,GAAG,IAAM,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC;YACnG,IAAI,CAAC,MAAM,IAAI;QACjB;QAEA,OAAO;IACT;AACF;IAEA,2CAAe;;;ACrBf,SAAS;IACP,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;IAE1B,MAAM,MAAM,KAAK,GAAG,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;IACnD,MAAM,SAAE,KAAK,EAAE,GAAG,IAAI;IAEtB,IAAI,CAAC,EAA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AY,EAAE,IAAI,CAAC,IAAI;QAEvB,IAAI,IAAI,CAAC,cAAc,EACrB,IAAI,CAAC,cAAc,CAAC,UAAU;IAElC;IAEA,oBAAoB;QAClB,IAAI,CAAC,IAAI;IACX;IAEA,uBAAuB;QACrB,IAAI,CAAC,OAAO;IACd;AACF;AAEA,IAAI,CAAC,eAAe,GAAG,CAAC,oBACtB,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js","src/utils/breakpoints.js","src/utils/cloning.js","src/utils/skewed.js","src/utils/animation.js","src/utils/clearTimeline.js"],"sourcesContent":["import breakpoints from './utils/breakpoints';\nimport cloning from './utils/cloning';\nimport skewed from './utils/skewed';\nimport animation from './utils/animation';\nimport clearTimeline from './utils/clearTimeline';\n\nexport default class MarqueeContent extends HTMLElement {\n constructor() {\n super();\n\n this.gsap = MarqueeContent.gsap || window.gsap;\n this.MM = this.gsap.matchMedia();\n this.timeline = null;\n this.update = this.update.bind(this);\n this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));\n this.resizeObserver.observe(this);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n debounce = () => {\n let timer;\n\n return () => {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(this.update);\n };\n };\n\n update() {\n cancelAnimationFrame(this.af);\n\n if (this.firstElementChild) {\n this.af = requestAnimationFrame(() => {\n cloning.call(this);\n animation.call(this);\n });\n }\n }\n\n init() {\n breakpoints.call(this);\n skewed.call(this);\n cloning.call(this);\n animation.call(this);\n }\n\n destroy() {\n cancelAnimationFrame(this.af);\n\n clearTimeline.call(this);\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n }\n }\n\n connectedCallback() {\n this.init();\n }\n\n disconnectedCallback() {\n this.destroy();\n }\n}\n\nif (!customElements.get('marquee-content')) {\n customElements.define('marquee-content', MarqueeContent);\n}\n","function breakpoints() {\n this.breakpoint = '';\n\n if (this.dataset.mcMax) {\n this.breakpoint = `(max-width: ${this.dataset.mcMax - 0.02}px)`;\n } else if (this.dataset.mcMin) {\n this.breakpoint = `(min-width: ${this.dataset.mcMin}px)`;\n }\n};\n\nexport default breakpoints;\n","function cloning() {\n const removingClones = () => {\n while (this.childElementCount > 1) {\n this.removeChild(this.lastChild);\n }\n };\n\n removingClones();\n\n this.MM.add(this.breakpoint, () => {\n const requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);\n\n if (this.childElementCount < requiredQuantity) {\n const clones = Array.from({ length: requiredQuantity - 1 }, () => this.firstElementChild.cloneNode(true));\n this.append(...clones);\n }\n\n return removingClones;\n });\n}\n\nexport default cloning;\n","function skewed() {\n if (!this.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(this.dataset.mcSkew, 10));\n const { style } = this;\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${this.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n\n return () => {\n style.cssText = 'transform-origin: unset; transform: unset; min-height: unset;';\n };\n });\n}\n\nexport default skewed;\n","import clearTimeline from './clearTimeline';\n\nfunction animation() {\n if (this.timeline) {\n clearTimeline.call(this);\n }\n\n this.MM.add(this.breakpoint, () => {\n this.timeline = this.gsap.to(this.children, {\n duration: this.dataset.mcDuration || 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (this.dataset.mcDirection === 'ltr') {\n this.timeline.timeScale(-1);\n } else if (this.dataset.mcDirection === 'auto') {\n this.timeline.timeScale(self.direction);\n }\n },\n },\n });\n\n this.timeline.totalProgress(0.5);\n\n return () => {\n if (this.timeline) {\n clearTimeline.call(this);\n }\n };\n });\n}\n\nexport default animation;\n","function clearTimeline() {\n if (this.timeline) {\n this.timeline.kill();\n this.timeline = null;\n }\n\n this.gsap.set(this.children,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,sBAAsB;YAC3C,IAAI,CAAC,CAAC,UAAU;YAChB,cAAc,OAAO;QACvB;IACF,EAAE;IAEF,OAAO;QACL,IAAI,CAAC,CAAC,UAAU;IAClB,EAAC;IAED,UAAU;QACR,qBAAqB,IAAI,CAAC,CAAC,cAAc;QACzC,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI;QACvD,IAAI,CAAC,CAAC,cAAc,EAAE;IACxB,EAAC;AACH","sources":["src/index.js","src/utils.js"],"sourcesContent":["import {\n debounce,\n breakpoints,\n cloning,\n skewed,\n animation,\n clearTimeline,\n} from './utils.js';\n\nexport default class MarqueeContent {\n #gsap;\n\n #MM;\n\n #timeline;\n\n #element;\n\n #resizeObserver;\n\n #animationFrame;\n\n constructor(el) {\n this.#gsap = MarqueeContent.gsap ?? window.gsap;\n this.#MM = this.#gsap.matchMedia();\n this.#timeline = null;\n this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');\n if (!this.#element) throw new Error('Element not found');\n\n this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));\n this.#resizeObserver.observe(this.#element);\n }\n\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap;\n }\n\n #commonInit = () => {\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n cloning(this.#element, this.#gsap, this.#MM);\n breakpoints(this.#element);\n skewed(this.#element);\n this.#timeline = animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);\n };\n\n #update = () => {\n cancelAnimationFrame(this.#animationFrame);\n this.#animationFrame = requestAnimationFrame(() => {\n this.#commonInit();\n ScrollTrigger.refresh();\n });\n };\n\n init = () => {\n this.#commonInit();\n }\n\n destroy = () => {\n cancelAnimationFrame(this.#animationFrame);\n clearTimeline(this.#timeline, this.#element, this.#gsap);\n this.#resizeObserver?.disconnect();\n }\n}\n","export const debounce = function(func) {\n let timer;\n\n return (...args) => {\n cancelAnimationFrame(timer);\n\n timer = requestAnimationFrame(() => func(...args));\n };\n};\n\nexport const animation = function(element, gsap, MM, timeline, update) {\n timeline?.kill();\n\n timeline = gsap.timeline({\n scrollTrigger: {\n trigger: element,\n start: 'top bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n onUpdate: (self) => {\n if (element.dataset.mcDirection === 'ltr') {\n timeline.timeScale(-1);\n } else if (element.dataset.mcDirection === 'auto') {\n timeline.timeScale(self.direction);\n }\n },\n }\n });\n\n MM.add(element.dataset.mcBreakpoint, () => {\n timeline.to(element.children, {\n duration: element.dataset.mcDuration ?? 20,\n x: '-100%',\n repeat: -1,\n ease: 'none',\n });\n\n timeline.totalProgress(0.5);\n\n return () => timeline?.kill();\n });\n\n update.timeline = timeline;\n\n return timeline;\n};\n\nexport const breakpoints = function(element) {\n element.dataset.mcBreakpoint = element.dataset.mcMax\n ? `(max-width: ${element.dataset.mcMax - 0.02}px)`\n : element.dataset.mcMin ? `(min-width: ${element.dataset.mcMin}px)` : '';\n};\n\nexport const clearTimeline = function(timeline, element, gsap) {\n timeline?.kill();\n timeline = null;\n\n gsap.set(element.children, { clearProps: 'all' });\n};\n\nexport const cloning = function(element, gsap, MM) {\n const removingClones = () => {\n while (element.childElementCount > 1) {\n element.removeChild(element.lastChild);\n }\n };\n\n removingClones();\n\n MM.add(element.dataset.mcBreakpoint, () => {\n const requiredQuantity = Math.ceil(element.scrollWidth / element.firstElementChild.clientWidth + 2);\n\n if (element.childElementCount < requiredQuantity) {\n const fragment = document.createDocumentFragment();\n const clones = Array.from({ length: requiredQuantity - 1 }, () => element.firstElementChild.cloneNode(true));\n\n clones.forEach(clone => fragment.appendChild(clone));\n\n element.appendChild(fragment);\n }\n\n return removingClones;\n });\n};\n\nexport const skewed = function(element) {\n if (!element.dataset.mcSkew) return;\n\n const abs = Math.abs(parseInt(element.dataset.mcSkew, 10));\n const { style } = element;\n\n style.transformOrigin = 'center center';\n style.transform = `skew(0deg, ${element.dataset.mcSkew}deg)`;\n style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;\n};\n"],"names":[],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marquee-content",
3
- "version": "3.1.1",
3
+ "version": "4.0.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",
@@ -30,11 +30,11 @@
30
30
  "lintfix": "yarn lint:js --fix"
31
31
  },
32
32
  "devDependencies": {
33
- "eslint": "^7.32.0 || ^8.52.0",
33
+ "eslint": "^8.57.0",
34
34
  "eslint-config-airbnb-base": "^15.0.0",
35
- "eslint-plugin-import": "^2.29.0",
36
- "parcel": "^2.10.2",
37
- "postcss-html": "^1.5.0"
35
+ "eslint-plugin-import": "^2.29.1",
36
+ "parcel": "^2.12.0",
37
+ "postcss-html": "^1.6.0"
38
38
  },
39
39
  "keywords": [
40
40
  "marquee",
package/src/demo.js ADDED
@@ -0,0 +1,10 @@
1
+ import MarqueeContent from './index.js';
2
+
3
+ gsap.registerPlugin(ScrollTrigger);
4
+ MarqueeContent.registerGSAP(gsap);
5
+
6
+ document.querySelectorAll('.marquee').forEach((el) => {
7
+ const marquee = new MarqueeContent(el);
8
+
9
+ marquee.init();
10
+ });
package/src/index.js CHANGED
@@ -1,71 +1,63 @@
1
- import breakpoints from './utils/breakpoints';
2
- import cloning from './utils/cloning';
3
- import skewed from './utils/skewed';
4
- import animation from './utils/animation';
5
- import clearTimeline from './utils/clearTimeline';
1
+ import {
2
+ debounce,
3
+ breakpoints,
4
+ cloning,
5
+ skewed,
6
+ animation,
7
+ clearTimeline,
8
+ } from './utils.js';
6
9
 
7
- export default class MarqueeContent extends HTMLElement {
8
- constructor() {
9
- super();
10
+ export default class MarqueeContent {
11
+ #gsap;
10
12
 
11
- this.gsap = MarqueeContent.gsap || window.gsap;
12
- this.MM = this.gsap.matchMedia();
13
- this.timeline = null;
14
- this.update = this.update.bind(this);
15
- this.resizeObserver = new ResizeObserver(this.debounce(this.update.bind(this)));
16
- this.resizeObserver.observe(this);
17
- }
13
+ #MM;
18
14
 
19
- static registerGSAP(gsap) {
20
- MarqueeContent.gsap = gsap;
21
- }
15
+ #timeline;
22
16
 
23
- debounce = () => {
24
- let timer;
17
+ #element;
25
18
 
26
- return () => {
27
- cancelAnimationFrame(timer);
28
- timer = requestAnimationFrame(this.update);
29
- };
30
- };
19
+ #resizeObserver;
31
20
 
32
- update() {
33
- cancelAnimationFrame(this.af);
21
+ #animationFrame;
34
22
 
35
- if (this.firstElementChild) {
36
- this.af = requestAnimationFrame(() => {
37
- cloning.call(this);
38
- animation.call(this);
39
- });
40
- }
41
- }
23
+ constructor(el) {
24
+ this.#gsap = MarqueeContent.gsap ?? window.gsap;
25
+ this.#MM = this.#gsap.matchMedia();
26
+ this.#timeline = null;
27
+ this.#element = el instanceof HTMLElement ? el : document.querySelector(el ?? '.marquee');
28
+ if (!this.#element) throw new Error('Element not found');
42
29
 
43
- init() {
44
- breakpoints.call(this);
45
- skewed.call(this);
46
- cloning.call(this);
47
- animation.call(this);
30
+ this.#resizeObserver = new ResizeObserver(debounce(() => this.#update()));
31
+ this.#resizeObserver.observe(this.#element);
48
32
  }
49
33
 
50
- destroy() {
51
- cancelAnimationFrame(this.af);
34
+ static registerGSAP(gsap) {
35
+ MarqueeContent.gsap = gsap;
36
+ }
52
37
 
53
- clearTimeline.call(this);
38
+ #commonInit = () => {
39
+ clearTimeline(this.#timeline, this.#element, this.#gsap);
40
+ cloning(this.#element, this.#gsap, this.#MM);
41
+ breakpoints(this.#element);
42
+ skewed(this.#element);
43
+ this.#timeline = animation(this.#element, this.#gsap, this.#MM, this.#timeline, this);
44
+ };
54
45
 
55
- if (this.resizeObserver) {
56
- this.resizeObserver.disconnect();
57
- }
58
- }
46
+ #update = () => {
47
+ cancelAnimationFrame(this.#animationFrame);
48
+ this.#animationFrame = requestAnimationFrame(() => {
49
+ this.#commonInit();
50
+ ScrollTrigger.refresh();
51
+ });
52
+ };
59
53
 
60
- connectedCallback() {
61
- this.init();
54
+ init = () => {
55
+ this.#commonInit();
62
56
  }
63
57
 
64
- disconnectedCallback() {
65
- this.destroy();
58
+ destroy = () => {
59
+ cancelAnimationFrame(this.#animationFrame);
60
+ clearTimeline(this.#timeline, this.#element, this.#gsap);
61
+ this.#resizeObserver?.disconnect();
66
62
  }
67
63
  }
68
-
69
- if (!customElements.get('marquee-content')) {
70
- customElements.define('marquee-content', MarqueeContent);
71
- }
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
+ };