marquee-content 1.9.0 → 1.9.2

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/README.md CHANGED
@@ -9,17 +9,19 @@
9
9
  [![GitHub package version](https://img.shields.io/github/package-json/v/ux-ui-pro/marquee-content.svg)](https://github.com/ux-ui-pro/marquee-content)
10
10
  [![NPM Downloads](https://img.shields.io/npm/dm/marquee-content.svg?style=flat)](https://www.npmjs.org/package/marquee-content)
11
11
 
12
- <h3><a href="https://ux-ui-pro.github.io/marquee-content/dist/">Demo</a></h3>
12
+ <h3><a href="https://codepen.io/ux-ui/full/dygzqYm">Demo</a></h3>
13
13
 
14
14
  </div>
15
15
  <br>
16
16
 
17
17
  ### Installation
18
18
  ```javascript
19
+ $ yarn add gsap
19
20
  $ yarn add marquee-content
20
21
  ```
21
22
  <sup>or</sup>
22
23
  ```javascript
24
+ $ npm i gsap
23
25
  $ npm i marquee-content
24
26
  ```
25
27
 
@@ -27,15 +29,21 @@ $ npm i marquee-content
27
29
 
28
30
  ### Import
29
31
  ```javascript
30
- import { MarqueeContent } from 'marquee-content'
32
+ import gsap from 'gsap'
33
+ import MarqueeContent from 'marquee-content'
34
+
35
+ gsap.registerPlugin(ScrollTrigger)
36
+ MarqueeContent.registerGSAP(gsap)
37
+
38
+ new MarqueeContent()
31
39
  ```
32
40
  <br>
33
41
 
34
42
  ### Usage
35
43
  ```HTML
36
- <div class="marquee-content" data-mc-duration="30" role="marquee">
44
+ <marquee-content data-mc-duration="30" role="marquee">
37
45
  content
38
- </div>
46
+ </marquee-content>
39
47
  ```
40
48
  <br>
41
49
 
@@ -0,0 +1,37 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, ethnicity, level of experience, nationality, personal appearance, race, or religion.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+
16
+ Examples of unacceptable behavior by participants include:
17
+
18
+ * Trolling, insulting/derogatory comments, and personal or political attacks
19
+ * Public or private harassment
20
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
21
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
22
+
23
+ ## Our Responsibilities
24
+
25
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
26
+
27
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
28
+
29
+ ## Scope
30
+
31
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
32
+
33
+ ## Enforcement
34
+
35
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident.
36
+
37
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
package/dist/index.js ADDED
@@ -0,0 +1,147 @@
1
+ class $4fa36e821943b400$var$MarqueeContent extends HTMLElement {
2
+ static registerGSAP(gsap) {
3
+ $4fa36e821943b400$var$MarqueeContent.gsap = gsap;
4
+ }
5
+ constructor(query){
6
+ super();
7
+ this.gsap = $4fa36e821943b400$var$MarqueeContent.gsap || window.gsap;
8
+ this.MM = this.gsap.matchMedia(query);
9
+ this.dataSkew = this.dataset.mcSkew;
10
+ this.dataDuration = this.dataset.mcDuration || 20;
11
+ this.dataDirection = this.dataset.mcDirection;
12
+ this.dataMaxWidth = this.dataset.mcMax;
13
+ this.dataMinWidth = this.dataset.mcMin;
14
+ this.breakpoint = this.dataMaxWidth ? `(max-width: ${this.dataMaxWidth - 0.02}px)` : this.dataMinWidth ? `(min-width: ${this.dataMinWidth}px)` : "";
15
+ this.debounce();
16
+ }
17
+ debounce(fn, delay) {
18
+ let timer;
19
+ return (...args)=>{
20
+ if (timer) clearTimeout(timer);
21
+ timer = setTimeout(()=>fn(...args), delay);
22
+ };
23
+ }
24
+ templates() {
25
+ const div = document.createElement("div");
26
+ div.style.display = "inline-block";
27
+ div.style.whiteSpace = "nowrap";
28
+ while(this.firstChild)div.appendChild(this.firstChild);
29
+ this.appendChild(div);
30
+ }
31
+ cloning() {
32
+ const removingClones = ()=>{
33
+ while(this.childElementCount > 1)this.removeChild(this.lastChild);
34
+ };
35
+ removingClones();
36
+ this.MM.add(this.breakpoint, ()=>{
37
+ let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
38
+ if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
39
+ let cloned = this.firstElementChild;
40
+ let clone = cloned.cloneNode(true);
41
+ cloned.parentNode.append(clone);
42
+ }
43
+ return ()=>{
44
+ removingClones();
45
+ };
46
+ });
47
+ }
48
+ skewed() {
49
+ if (!this.dataSkew) return;
50
+ const abs = Math.abs(parseInt(this.dataSkew));
51
+ const style = this.style;
52
+ this.MM.add(this.breakpoint, ()=>{
53
+ style.transformOrigin = "center center";
54
+ style.transform = `skew(0deg, ${this.dataSkew}deg)`;
55
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
56
+ return ()=>{
57
+ style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
58
+ };
59
+ });
60
+ }
61
+ animation() {
62
+ let timeLine = this.gsap.timeline();
63
+ timeLine.kill();
64
+ timeLine = null;
65
+ this.gsap.set(this.children, {
66
+ clearProps: true
67
+ });
68
+ this.MM.add(this.breakpoint, ()=>{
69
+ this.gsap.set(this.children, {
70
+ "will-change": "transform"
71
+ });
72
+ const tween = this.gsap.to(this.children, {
73
+ duration: this.dataDuration,
74
+ x: "-100%",
75
+ ease: "none",
76
+ repeat: -1,
77
+ scrollTrigger: {
78
+ trigger: this,
79
+ start: "-=50% bottom",
80
+ end: "bottom top",
81
+ toggleActions: "resume pause resume pause"
82
+ }
83
+ }).totalProgress(0.5);
84
+ const ltrDirection = ()=>{
85
+ this.gsap.to(tween, {
86
+ timeScale: -1,
87
+ overwrite: true
88
+ });
89
+ };
90
+ const autoDirection = ()=>{
91
+ let previousScrollPosition = 0;
92
+ const isScrollingDown = ()=>{
93
+ const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
94
+ let direction = false;
95
+ if (scrollPosition > previousScrollPosition) direction = true;
96
+ else if (scrollPosition < previousScrollPosition) direction = false;
97
+ previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
98
+ return direction;
99
+ };
100
+ addEventListener("scroll", this.debounce(()=>{
101
+ const scrollDirection = isScrollingDown();
102
+ this.gsap.to(tween, {
103
+ timeScale: scrollDirection ? 1 : -1,
104
+ overwrite: true
105
+ });
106
+ }, 50), {
107
+ capture: true,
108
+ passive: true
109
+ });
110
+ };
111
+ if (this.dataDirection === "ltr") ltrDirection();
112
+ else if (this.dataDirection === "auto") autoDirection();
113
+ return ()=>{
114
+ this.gsap.set(this.children, {
115
+ clearProps: true
116
+ });
117
+ };
118
+ });
119
+ }
120
+ onResize() {
121
+ cancelAnimationFrame(this.af);
122
+ this.af = requestAnimationFrame(()=>{
123
+ this.cloning();
124
+ this.animation();
125
+ });
126
+ }
127
+ onUpdate() {
128
+ this.templates();
129
+ this.cloning();
130
+ this.skewed();
131
+ this.animation();
132
+ this.onResize = this.onResize.bind(this);
133
+ this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150));
134
+ this.resizeObserver.observe(this);
135
+ }
136
+ connectedCallback() {
137
+ this.onUpdate();
138
+ }
139
+ disconnectedCallback() {
140
+ this.MM.remove();
141
+ document.fonts.removeEventListener("loadingdone", this.onUpdate);
142
+ }
143
+ }
144
+ customElements.define("marquee-content", $4fa36e821943b400$var$MarqueeContent);
145
+
146
+
147
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA,MAAM,6CAAuB;IACzB,OAAO,aAAa,IAAI,EAAE;QACtB,qCAAe,IAAI,GAAG;IAC1B;IAEA,YAAY,KAAK,CAAE;QACf,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,qCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI;QAC/C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,GAC7B,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,GAAG,KAAK,GAAG,CAAC,GAC5C,IAAI,CAAC,YAAY,GACb,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GACrC,EAAE;QACZ,IAAI,CAAC,QAAQ;IACjB;IAEA,SAAS,EAAE,EAAE,KAAK,EAAE;QAChB,IAAI;QAEJ,OAAO,CAAC,GAAG,OAAS;YAChB,IAAI,OAAO,aAAa;YACxB,QAAQ,WAAW,IAAM,MAAM,OAAO;QAC1C;IACJ;IAEA,YAAY;QACR,MAAM,MAAM,SAAS,aAAa,CAAC;QAEnC,IAAI,KAAK,CAAC,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AS,IAAI;oBAAE,SAAS,IAAI;gBAChC;YACJ;YAEA,IAAI,IAAI,CAAC,aAAa,KAAK,OACvB;iBACG,IAAI,IAAI,CAAC,aAAa,KAAK,QAC9B;YAGJ,OAAO,IAAM;gBACT,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAAE,YAAY,IAAI;gBAAC;YACpD;QACJ;IACJ;IAEA,WAAW;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,CAAC,EAAE,GAAG,sBAAsB,IAAM;YAClC,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAClB;IACJ;IAEA,WAAW;QACP,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;QAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,IAAI,CAAC,EAAE,CAAC,MAAM;QAEd,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["class MarqueeContent extends HTMLElement {\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia(query)\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\n this.debounce()\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\n }\n\n 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 let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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\n animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataDuration,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n this.MM.remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"names":[],"version":3,"file":"index.js.map"}
@@ -0,0 +1,149 @@
1
+ var $cf838c15c8b009ba$exports = {};
2
+ class $cf838c15c8b009ba$var$MarqueeContent extends HTMLElement {
3
+ static registerGSAP(gsap) {
4
+ $cf838c15c8b009ba$var$MarqueeContent.gsap = gsap;
5
+ }
6
+ constructor(query){
7
+ super();
8
+ this.gsap = $cf838c15c8b009ba$var$MarqueeContent.gsap || window.gsap;
9
+ this.MM = this.gsap.matchMedia(query);
10
+ this.dataSkew = this.dataset.mcSkew;
11
+ this.dataDuration = this.dataset.mcDuration || 20;
12
+ this.dataDirection = this.dataset.mcDirection;
13
+ this.dataMaxWidth = this.dataset.mcMax;
14
+ this.dataMinWidth = this.dataset.mcMin;
15
+ this.breakpoint = this.dataMaxWidth ? `(max-width: ${this.dataMaxWidth - 0.02}px)` : this.dataMinWidth ? `(min-width: ${this.dataMinWidth}px)` : "";
16
+ this.debounce();
17
+ }
18
+ debounce(fn, delay) {
19
+ let timer;
20
+ return (...args)=>{
21
+ if (timer) clearTimeout(timer);
22
+ timer = setTimeout(()=>fn(...args), delay);
23
+ };
24
+ }
25
+ templates() {
26
+ const div = document.createElement("div");
27
+ div.style.display = "inline-block";
28
+ div.style.whiteSpace = "nowrap";
29
+ while(this.firstChild)div.appendChild(this.firstChild);
30
+ this.appendChild(div);
31
+ }
32
+ cloning() {
33
+ const removingClones = ()=>{
34
+ while(this.childElementCount > 1)this.removeChild(this.lastChild);
35
+ };
36
+ removingClones();
37
+ this.MM.add(this.breakpoint, ()=>{
38
+ let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2);
39
+ if (this.childElementCount < requiredQuantity) for(let i = 1; i < requiredQuantity; i++){
40
+ let cloned = this.firstElementChild;
41
+ let clone = cloned.cloneNode(true);
42
+ cloned.parentNode.append(clone);
43
+ }
44
+ return ()=>{
45
+ removingClones();
46
+ };
47
+ });
48
+ }
49
+ skewed() {
50
+ if (!this.dataSkew) return;
51
+ const abs = Math.abs(parseInt(this.dataSkew));
52
+ const style = this.style;
53
+ this.MM.add(this.breakpoint, ()=>{
54
+ style.transformOrigin = "center center";
55
+ style.transform = `skew(0deg, ${this.dataSkew}deg)`;
56
+ style.minHeight = `calc(${abs * 1.25}vh + ${abs * 1.25}vw)`;
57
+ return ()=>{
58
+ style.cssText = "transform-origin: unset; transform: unset; min-height: unset;";
59
+ };
60
+ });
61
+ }
62
+ animation() {
63
+ let timeLine = this.gsap.timeline();
64
+ timeLine.kill();
65
+ timeLine = null;
66
+ this.gsap.set(this.children, {
67
+ clearProps: true
68
+ });
69
+ this.MM.add(this.breakpoint, ()=>{
70
+ this.gsap.set(this.children, {
71
+ "will-change": "transform"
72
+ });
73
+ const tween = this.gsap.to(this.children, {
74
+ duration: this.dataDuration,
75
+ x: "-100%",
76
+ ease: "none",
77
+ repeat: -1,
78
+ scrollTrigger: {
79
+ trigger: this,
80
+ start: "-=50% bottom",
81
+ end: "bottom top",
82
+ toggleActions: "resume pause resume pause"
83
+ }
84
+ }).totalProgress(0.5);
85
+ const ltrDirection = ()=>{
86
+ this.gsap.to(tween, {
87
+ timeScale: -1,
88
+ overwrite: true
89
+ });
90
+ };
91
+ const autoDirection = ()=>{
92
+ let previousScrollPosition = 0;
93
+ const isScrollingDown = ()=>{
94
+ const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
95
+ let direction = false;
96
+ if (scrollPosition > previousScrollPosition) direction = true;
97
+ else if (scrollPosition < previousScrollPosition) direction = false;
98
+ previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition;
99
+ return direction;
100
+ };
101
+ addEventListener("scroll", this.debounce(()=>{
102
+ const scrollDirection = isScrollingDown();
103
+ this.gsap.to(tween, {
104
+ timeScale: scrollDirection ? 1 : -1,
105
+ overwrite: true
106
+ });
107
+ }, 50), {
108
+ capture: true,
109
+ passive: true
110
+ });
111
+ };
112
+ if (this.dataDirection === "ltr") ltrDirection();
113
+ else if (this.dataDirection === "auto") autoDirection();
114
+ return ()=>{
115
+ this.gsap.set(this.children, {
116
+ clearProps: true
117
+ });
118
+ };
119
+ });
120
+ }
121
+ onResize() {
122
+ cancelAnimationFrame(this.af);
123
+ this.af = requestAnimationFrame(()=>{
124
+ this.cloning();
125
+ this.animation();
126
+ });
127
+ }
128
+ onUpdate() {
129
+ this.templates();
130
+ this.cloning();
131
+ this.skewed();
132
+ this.animation();
133
+ this.onResize = this.onResize.bind(this);
134
+ this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150));
135
+ this.resizeObserver.observe(this);
136
+ }
137
+ connectedCallback() {
138
+ this.onUpdate();
139
+ }
140
+ disconnectedCallback() {
141
+ this.MM.remove();
142
+ document.fonts.removeEventListener("loadingdone", this.onUpdate);
143
+ }
144
+ }
145
+ customElements.define("marquee-content", $cf838c15c8b009ba$var$MarqueeContent);
146
+
147
+
148
+ export {$cf838c15c8b009ba$exports as default};
149
+ //# sourceMappingURL=index.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAAA,MAAM,6CAAuB;IACzB,OAAO,aAAa,IAAI,EAAE;QACtB,qCAAe,IAAI,GAAG;IAC1B;IAEA,YAAY,KAAK,CAAE;QACf,KAAK;QAEL,IAAI,CAAC,IAAI,GAAG,qCAAe,IAAI,IAAI,OAAO,IAAI;QAC9C,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI;QAC/C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,GAC7B,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,GAAG,KAAK,GAAG,CAAC,GAC5C,IAAI,CAAC,YAAY,GACb,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GACrC,EAAE;QACZ,IAAI,CAAC,QAAQ;IACjB;IAEA,SAAS,EAAE,EAAE,KAAK,EAAE;QAChB,IAAI;QAEJ,OAAO,CAAC,GAAG,OAAS;YAChB,IAAI,OAAO,aAAa;YACxB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AAI,CAAC,EAAE,CAAC,OAAO;wBAChB,WAAW,kBAAkB,IAAI,EAAE;wBACnC,WAAW,IAAI;oBACnB;gBACJ,GAAG,KAAK;oBACJ,SAAS,IAAI;oBAAE,SAAS,IAAI;gBAChC;YACJ;YAEA,IAAI,IAAI,CAAC,aAAa,KAAK,OACvB;iBACG,IAAI,IAAI,CAAC,aAAa,KAAK,QAC9B;YAGJ,OAAO,IAAM;gBACT,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAAE,YAAY,IAAI;gBAAC;YACpD;QACJ;IACJ;IAEA,WAAW;QACP,qBAAqB,IAAI,CAAC,EAAE;QAE5B,IAAI,CAAC,EAAE,GAAG,sBAAsB,IAAM;YAClC,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,SAAS;QAClB;IACJ;IAEA,WAAW;QACP,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,SAAS;QAEd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG;QACjF,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI;IACpC;IAEA,oBAAoB;QAChB,IAAI,CAAC,QAAQ;IACjB;IAEA,uBAAuB;QACnB,IAAI,CAAC,EAAE,CAAC,MAAM;QAEd,SAAS,KAAK,CAAC,mBAAmB,CAAC,eAAe,IAAI,CAAC,QAAQ;IACnE;AACJ;AAEA,eAAe,MAAM,CAAC,mBAAmB","sources":["src/index.js"],"sourcesContent":["class MarqueeContent extends HTMLElement {\n static registerGSAP(gsap) {\n MarqueeContent.gsap = gsap\n }\n\n constructor(query) {\n super()\n\n this.gsap = MarqueeContent.gsap || window.gsap\n this.MM = this.gsap.matchMedia(query)\n this.dataSkew = this.dataset.mcSkew\n this.dataDuration = this.dataset.mcDuration || 20\n this.dataDirection = this.dataset.mcDirection\n this.dataMaxWidth = this.dataset.mcMax\n this.dataMinWidth = this.dataset.mcMin\n this.breakpoint = this.dataMaxWidth\n ? `(max-width: ${this.dataMaxWidth - 0.02}px)`\n : this.dataMinWidth\n ? `(min-width: ${this.dataMinWidth}px)`\n : ''\n this.debounce()\n }\n\n debounce(fn, delay) {\n let timer\n\n return (...args) => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => fn(...args), delay)\n }\n }\n\n templates() {\n const div = document.createElement('div')\n\n div.style.display = 'inline-block'\n div.style.whiteSpace = 'nowrap'\n\n while (this.firstChild) {\n div.appendChild(this.firstChild)\n }\n\n this.appendChild(div)\n }\n\n 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 let requiredQuantity = Math.ceil(this.scrollWidth / this.firstElementChild.clientWidth + 2)\n\n if (this.childElementCount < requiredQuantity) {\n for (let i = 1; i < requiredQuantity; i++) {\n let cloned = this.firstElementChild\n let clone = cloned.cloneNode(true)\n cloned.parentNode.append(clone)\n }\n }\n\n return () => {\n removingClones()\n }\n })\n }\n\n skewed() {\n if (!this.dataSkew) return\n\n const abs = Math.abs(parseInt(this.dataSkew))\n const style = this.style\n\n this.MM.add(this.breakpoint, () => {\n style.transformOrigin = 'center center'\n style.transform = `skew(0deg, ${this.dataSkew}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\n animation() {\n let timeLine = this.gsap.timeline()\n\n timeLine.kill()\n timeLine = null\n\n this.gsap.set(this.children, { clearProps: true })\n\n this.MM.add(this.breakpoint, () => {\n this.gsap.set(this.children, { 'will-change': 'transform' })\n\n const tween = this.gsap.to(this.children, {\n duration: this.dataDuration,\n x: '-100%',\n ease: 'none',\n repeat: -1,\n scrollTrigger: {\n trigger: this,\n start: '-=50% bottom',\n end: 'bottom top',\n toggleActions: 'resume pause resume pause',\n },\n }).totalProgress(0.5)\n\n const ltrDirection = () => {\n this.gsap.to(tween, {\n timeScale: -1,\n overwrite: true\n })\n }\n\n const autoDirection = () => {\n let previousScrollPosition = 0\n\n const isScrollingDown = () => {\n const scrollPosition = window.pageYOffset || document.documentElement.scrollTop\n\n let direction = false\n\n if (scrollPosition > previousScrollPosition) {\n direction = true\n } else if (scrollPosition < previousScrollPosition) {\n direction = false\n }\n\n previousScrollPosition = scrollPosition <= 0 ? 0 : scrollPosition\n\n return direction\n }\n\n addEventListener('scroll', this.debounce(() => {\n const scrollDirection = isScrollingDown()\n\n this.gsap.to(tween, {\n timeScale: scrollDirection ? 1 : -1,\n overwrite: true,\n })\n }, 50), {\n capture: true, passive: true\n })\n }\n\n if (this.dataDirection === 'ltr') {\n ltrDirection()\n } else if (this.dataDirection === 'auto') {\n autoDirection()\n }\n\n return () => {\n this.gsap.set(this.children, { clearProps: true })\n }\n })\n }\n\n onResize() {\n cancelAnimationFrame(this.af)\n\n this.af = requestAnimationFrame(() => {\n this.cloning()\n this.animation()\n })\n }\n\n onUpdate() {\n this.templates()\n this.cloning()\n this.skewed()\n this.animation()\n\n this.onResize = this.onResize.bind(this)\n this.resizeObserver = new ResizeObserver(this.debounce(this.onResize.bind(this), 150))\n this.resizeObserver.observe(this)\n }\n\n connectedCallback() {\n this.onUpdate()\n }\n\n disconnectedCallback() {\n this.MM.remove()\n\n document.fonts.removeEventListener('loadingdone', this.onUpdate)\n }\n}\n\ncustomElements.define('marquee-content', MarqueeContent)"],"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": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Infinite marquee animation with GSAP",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
@@ -8,37 +8,34 @@
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/ux-ui-pro/marquee-content.git"
10
10
  },
11
- "files": [
12
- "dist",
13
- "src"
14
- ],
15
- "main": "src/js/marquee-content.js",
16
11
  "bugs": {
17
12
  "url": "https://github.com/ux-ui-pro/marquee-content/issues"
18
13
  },
19
- "type": "module",
14
+ "source": "src/index.js",
15
+ "main": "dist/index.js",
16
+ "module": "dist/index.module.js",
20
17
  "scripts": {
21
- "serve": "gulp",
22
- "build": "gulp build --build"
23
- },
24
- "dependencies": {
25
- "gsap": "^3.11.5"
18
+ "serve": "parcel watch",
19
+ "build": "parcel build",
20
+ "clean": "rm -rf dist .parcel-cache"
26
21
  },
27
22
  "devDependencies": {
28
- "browser-sync": "^2.27.7",
29
- "del": "^6.0.0",
30
- "gulp": "^4.0.2",
31
- "gulp-file-include": "^2.3.0",
32
- "gulp-if": "^3.0.0",
33
- "gulp-newer": "^1.4.0",
34
- "gulp-rename": "^2.0.0",
35
- "gulp-replace": "^1.1.3",
36
- "webpack": "^5.69.1",
37
- "webpack-stream": "^7.0.0"
23
+ "parcel": "^2.8.3"
38
24
  },
39
25
  "keywords": [
40
26
  "marquee",
41
27
  "scroller",
42
- "GSAP"
28
+ "animation",
29
+ "ticker",
30
+ "reel",
31
+ "running text",
32
+ "scrolling text",
33
+ "ui",
34
+ "custom",
35
+ "clones",
36
+ "filler",
37
+ "css",
38
+ "effects",
39
+ "gsap"
43
40
  ]
44
- }
41
+ }