Skip to content

Commit bdcb8dd

Browse files
Nikola HristovNikola Hristov
authored andcommitted
1 parent 2085df0 commit bdcb8dd

File tree

10 files changed

+685
-4171
lines changed

10 files changed

+685
-4171
lines changed

.cache/Commit/Cache.json

Lines changed: 43 additions & 3803 deletions
Large diffs are not rendered by default.

Source/Function/Scroll/Code.tsx

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Mouse } from "@Function/Scroll/Code/Pixel.js";
2-
import type { JSX } from "solid-js";
1+
import { type Mouse } from "@Function/Scroll/Type.js";
2+
import { type JSX } from "solid-js";
33

44
export default ({
55
Text = "",
@@ -12,11 +12,17 @@ export default ({
1212
}): JSX.Element => {
1313
const [Mouse, _Mouse] = createSignal<Mouse>({
1414
X: 0,
15+
1516
Y: 0,
17+
1618
XPrevious: 0,
19+
1720
YPrevious: 0,
21+
1822
Velocity: 0,
23+
1924
Last: 0,
25+
2026
Active: false,
2127
});
2228

@@ -26,6 +32,8 @@ export default ({
2632

2733
const [Count, _Count] = createSignal(10);
2834

35+
const [CurrentTime, _CurrentTime] = createSignal(performance.now());
36+
2937
const Width = 4;
3038

3139
const [_Text] = createSignal(Text);
@@ -43,46 +51,62 @@ export default ({
4351

4452
_Mouse((prev) => {
4553
const dx = e.clientX - prev.X;
54+
4655
const dy = e.clientY - prev.Y;
4756

4857
return {
4958
XPrevious: prev.X,
59+
5060
YPrevious: prev.Y,
61+
5162
X: e.clientX,
63+
5264
Y: e.clientY,
65+
5366
Velocity: Math.sqrt(dx * dx + dy * dy),
67+
5468
Last: currentTime,
69+
5570
Active: true,
5671
};
5772
});
5873
};
5974

6075
onMount(() => {
61-
if (Element()) {
62-
Element()?.addEventListener("mousemove", Move);
76+
const _Element = Element();
6377

64-
Element()?.addEventListener("mouseleave", () =>
65-
_Mouse((Previous) => ({ ...Previous, Active: false })),
66-
);
78+
if (!_Element) {
79+
return;
6780
}
6881

69-
const Factor = (): void => {
70-
if (Element()) {
71-
_Count(
72-
Math.max(
73-
1,
82+
_Element.addEventListener("mousemove", Move);
7483

75-
Math.floor((Element()?.offsetWidth ?? 100) / 32),
76-
),
77-
);
78-
}
79-
};
84+
_Element.addEventListener("mouseleave", () =>
85+
_Mouse((Previous) => ({ ...Previous, Active: false })),
86+
);
87+
88+
const Factor = (): number =>
89+
_Count(
90+
Math.max(
91+
1,
92+
93+
Math.floor((_Element.offsetWidth ?? 100) / 32),
94+
),
95+
);
8096

8197
Factor();
8298

8399
window.addEventListener("resize", Factor);
84100

85-
return (): void => window.removeEventListener("resize", Factor);
101+
onCleanup(() => {
102+
_Element.removeEventListener("mousemove", Move);
103+
104+
_Element.removeEventListener("mouseleave", () =>
105+
_Mouse((Previous) => ({ ...Previous, Active: false })),
106+
);
107+
108+
window.removeEventListener("resize", Factor);
109+
});
86110
});
87111

88112
createEffect(() => {
@@ -92,23 +116,30 @@ export default ({
92116

93117
let ID: number;
94118

95-
const Size = Padded().length * Width;
119+
const Scroll = (Time: number): void => {
120+
_CurrentTime(Time);
96121

97-
const Roll = (Current: number): void => {
98-
const Past = Current - LastTimestamp();
122+
// Text scroll animation
123+
if (Animate()) {
124+
const Past = Time - LastTimestamp();
99125

100-
if (Past >= Time) {
101-
_Offset((prev) => (prev - 0.2 + Size) % Size);
126+
if (Past >= Time) {
127+
_Offset(
128+
(prev) =>
129+
(prev - 0.2 + Padded().length * Width) %
130+
(Padded().length * Width),
131+
);
102132

103-
_LastTimestamp(Current);
133+
_LastTimestamp(Time);
134+
}
104135
}
105136

106-
ID = requestAnimationFrame(Roll);
137+
ID = requestAnimationFrame(Scroll);
107138
};
108139

109-
ID = requestAnimationFrame(Roll);
140+
ID = requestAnimationFrame(Scroll);
110141

111-
return (): void => cancelAnimationFrame(ID);
142+
onCleanup(() => cancelAnimationFrame(ID));
112143
});
113144

114145
const Display = (): string => {
@@ -139,25 +170,22 @@ export default ({
139170
{(
140171
Matrix[Position.toUpperCase()] ||
141172
Matrix[" "]
142-
)?.map((Row) => (
173+
)?.map((Row, RowIndex) => (
143174
<div class="Row flex">
144-
{Row.map((Show, IndexPixel) =>
145-
Pixel(
146-
Font,
147-
148-
IndexChar,
149-
150-
IndexPixel,
151-
152-
Show,
153-
154-
Display().length,
155-
156-
Mouse,
157-
158-
Element,
159-
),
160-
)}
175+
{Row.map((Show, Index) => (
176+
<Pixel
177+
Font={Font}
178+
Character={IndexChar}
179+
Index={Index}
180+
Show={Show}
181+
Text={Display().length}
182+
Mouse={Mouse}
183+
Container={Element()?.getBoundingClientRect()}
184+
CurrentTime={CurrentTime()}
185+
Row={RowIndex}
186+
Column={Index % 3}
187+
/>
188+
))}
161189
</div>
162190
))}
163191
</div>
@@ -169,12 +197,12 @@ export default ({
169197
);
170198
};
171199

200+
export const { default: Pixel } = await import(
201+
"@Function/Scroll/Code/Pixel.js"
202+
);
203+
172204
export const { default: Matrix } = await import("@Variable/Scroll/Matrix.js");
173205

174-
export const { createEffect, createSignal, onMount, onCleanup } = await import(
206+
export const { createEffect, createSignal, onCleanup, onMount } = await import(
175207
"solid-js"
176208
);
177-
178-
export const { default: Pixel } = await import(
179-
"@Function/Scroll/Code/Pixel.js"
180-
);

0 commit comments

Comments
 (0)