Skip to content

Commit 2536087

Browse files
authored
refactor: use animejs instead of jquery (@Miodec) (#7101)
Also changes how slow timer is handled - now the animation frame rate is reduced to 30fps instead of disabling them entirely.
1 parent 1009791 commit 2536087

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1039
-1131
lines changed

frontend/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"@sentry/browser": "9.14.0",
9494
"@sentry/vite-plugin": "3.3.1",
9595
"@ts-rest/core": "3.52.1",
96+
"animejs": "4.2.2",
9697
"balloon-css": "1.2.0",
9798
"canvas-confetti": "1.5.1",
9899
"chart.js": "3.7.1",
@@ -108,8 +109,6 @@
108109
"howler": "2.2.3",
109110
"idb": "8.0.3",
110111
"jquery": "3.7.1",
111-
"jquery-color": "2.2.0",
112-
"jquery.easing": "1.4.1",
113112
"konami": "1.7.0",
114113
"lz-ts": "1.1.2",
115114
"modern-screenshot": "4.6.5",

frontend/src/html/pages/settings.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,35 @@
18871887
<button>open</button>
18881888
</div>
18891889
</div>
1890+
<div class="section fpsLimit">
1891+
<div class="groupTitle">
1892+
<i class="fas fa-video"></i>
1893+
<span>animation fps limit</span>
1894+
<button class="text" tabindex="-1">
1895+
<i class="fas fa-fw fa-link"></i>
1896+
</button>
1897+
</div>
1898+
<div class="text">
1899+
Limit the maximum fps for animations. Setting this to "native" will run
1900+
the animations as fast as possible (at your monitor's refresh rate).
1901+
Setting this above your monitor's refresh rate will have no effect.
1902+
</div>
1903+
<!-- <div class="inputs">
1904+
<div class="rangeGroup">
1905+
<div class="value">---</div>
1906+
<input type="range" min="30" max="1000" step="10" />
1907+
</div>
1908+
</div> -->
1909+
<div class="inputs">
1910+
<button data-fpsLimit="native">native</button>
1911+
<div class="separator">
1912+
<div class="line"></div>
1913+
or
1914+
<div class="line"></div>
1915+
</div>
1916+
<input type="number" placeholder="custom limit" min="30" max="1000" />
1917+
</div>
1918+
</div>
18901919
<div class="section resetSettings" data-section-id="resetSettings">
18911920
<div class="groupTitle">
18921921
<i class="fas fa-redo-alt"></i>

frontend/src/styles/account.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
}
194194

195195
.active {
196-
animation: accountRowHighlight 4s linear 0s 1;
196+
animation: accountRowHighlight 5s linear 0s 1;
197197
}
198198

199199
.loadMoreButton {

frontend/src/styles/nav.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ nav {
6969
}
7070

7171
.level {
72-
transition: 0.125s;
7372
width: max-content;
7473
font-size: 0.65em;
7574
line-height: 0.65em;

frontend/src/styles/notifications.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
width: 350px;
33
z-index: 99999999;
44
display: grid;
5-
gap: 1rem;
5+
// gap: 1rem;
6+
// margin-top: 1rem;
7+
padding-top: 1rem;
68
position: fixed;
79
right: 1rem;
8-
top: 1rem;
10+
// top: 1rem;
911
transition: 0.125s opacity;
1012

1113
.clearAll.button {
1214
font-size: 0.75em;
15+
margin-bottom: 1rem;
1316
}
1417
&.focus .clearAll {
1518
visibility: hidden;
@@ -22,13 +25,14 @@
2225
}
2326
.history {
2427
display: grid;
25-
gap: 1rem;
28+
// gap: 1rem;
2629
}
2730

2831
.notif {
2932
--notif-border-color: rgba(0, 130, 251, 0.985);
3033
--notif-background-color: rgba(0, 77, 148, 0.9);
3134
transition: 0.125s background;
35+
margin-bottom: 1rem;
3236

3337
-webkit-user-select: none;
3438
user-select: none;

frontend/src/styles/settings.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@
169169
}
170170

171171
&[data-config-name="fontFamily"],
172-
&[data-config-name="customBackgroundSize"] {
172+
&[data-config-name="customBackgroundSize"],
173+
&.fpsLimit {
173174
.separator {
174175
margin-bottom: 0.5rem;
176+
margin-top: 0.5rem;
175177
grid-column: span 2;
176178
// color: var(--sub-color);
177179
display: grid;
@@ -187,6 +189,15 @@
187189
}
188190
}
189191

192+
&.fpsLimit {
193+
.inputs {
194+
button,
195+
input {
196+
width: 100%;
197+
}
198+
}
199+
}
200+
190201
&[data-config-name="fontFamily"] {
191202
grid-template-areas:
192203
"title title"

frontend/src/styles/test.scss

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,18 +1264,14 @@
12641264
border-radius: var(--roundness);
12651265
z-index: 2;
12661266
// width: max-content;
1267+
overflow: hidden;
12671268
}
12681269
.spacer {
12691270
height: auto;
12701271
width: 0.5em;
12711272
border-radius: calc(var(--roundness) / 2);
12721273
background: var(--bg-color);
12731274
margin: 0.75em 0;
1274-
transition: 250ms;
1275-
&.scrolled {
1276-
opacity: 0;
1277-
width: 0;
1278-
}
12791275
}
12801276

12811277
.wordCount,
@@ -1334,6 +1330,12 @@
13341330
transition: opacity 0.25s, right 0.25s;
13351331
opacity: 0;
13361332
}
1333+
1334+
.mode {
1335+
background: var(--sub-alt-color);
1336+
z-index: 2;
1337+
}
1338+
13371339
&:hover {
13381340
.shareButton {
13391341
opacity: 1;

frontend/src/ts/anim.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { engine } from "animejs";
2+
import { LocalStorageWithSchema } from "./utils/local-storage-with-schema";
3+
import { z } from "zod";
4+
5+
export const fpsLimitSchema = z.number().int().min(30).max(1000);
6+
7+
const fpsLimit = new LocalStorageWithSchema({
8+
key: "fpsLimit",
9+
schema: fpsLimitSchema,
10+
fallback: 1000,
11+
});
12+
13+
export function setfpsLimit(fps: number): boolean {
14+
const result = fpsLimit.set(fps);
15+
applyEngineSettings();
16+
return result;
17+
}
18+
19+
export function getfpsLimit(): number {
20+
return fpsLimit.get();
21+
}
22+
23+
export function applyEngineSettings(): void {
24+
engine.pauseOnDocumentHidden = false;
25+
engine.fps = fpsLimit.get();
26+
engine.defaults.frameRate = fpsLimit.get();
27+
}
28+
29+
export function setLowFpsMode(): void {
30+
engine.fps = 30;
31+
engine.defaults.frameRate = 30;
32+
}
33+
34+
export function clearLowFpsMode(): void {
35+
engine.fps = fpsLimit.get();
36+
engine.defaults.frameRate = fpsLimit.get();
37+
}

frontend/src/ts/commandline/commandline.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ async function updateActiveCommand(): Promise<void> {
577577
command.hover?.();
578578
}
579579

580+
let shakeTimeout: null | NodeJS.Timeout;
581+
580582
function handleInputSubmit(): void {
581583
if (isAnimating) return;
582584
if (inputModeParams.command === null) {
@@ -587,13 +589,13 @@ function handleInputSubmit(): void {
587589
//validation ongoing, ignore the submit
588590
return;
589591
} else if (inputModeParams.validation?.status === "failed") {
590-
const cmdLine = $("#commandLine .modal");
591-
cmdLine
592-
.stop(true, true)
593-
.addClass("hasError")
594-
.animate({ undefined: 1 }, 500, () => {
595-
cmdLine.removeClass("hasError");
596-
});
592+
modal.getModal().classList.add("hasError");
593+
if (shakeTimeout !== null) {
594+
clearTimeout(shakeTimeout);
595+
}
596+
shakeTimeout = setTimeout(() => {
597+
modal.getModal().classList.remove("hasError");
598+
}, 500);
597599
return;
598600
}
599601

frontend/src/ts/controllers/page-controller.ts

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ function updateTitle(nextPage: { id: string; display?: string }): void {
5454
async function showSyncLoading({
5555
loadingOptions,
5656
totalDuration,
57-
easingMethod,
5857
}: {
5958
loadingOptions: LoadingOptions[];
6059
totalDuration: number;
61-
easingMethod: Misc.JQueryEasing;
6260
}): Promise<void> {
6361
PageLoading.page.element.removeClass("hidden").css("opacity", 0);
6462
await PageLoading.page.beforeShow({});
@@ -67,14 +65,10 @@ async function showSyncLoading({
6765
const fillOffset = 100 / fillDivider;
6866

6967
//void here to run the loading promise as soon as possible
70-
void Misc.promiseAnimation(
71-
PageLoading.page.element,
72-
{
73-
opacity: "1",
74-
},
75-
totalDuration / 2,
76-
easingMethod
77-
);
68+
void Misc.promiseAnimate(PageLoading.page.element[0] as HTMLElement, {
69+
opacity: "1",
70+
duration: totalDuration / 2,
71+
});
7872

7973
for (let i = 0; i < loadingOptions.length; i++) {
8074
const currentOffset = fillOffset * i;
@@ -102,14 +96,10 @@ async function showSyncLoading({
10296
}
10397
}
10498

105-
await Misc.promiseAnimation(
106-
PageLoading.page.element,
107-
{
108-
opacity: "0",
109-
},
110-
totalDuration / 2,
111-
easingMethod
112-
);
99+
await Misc.promiseAnimate(PageLoading.page.element[0] as HTMLElement, {
100+
opacity: "0",
101+
duration: totalDuration / 2,
102+
});
113103

114104
await PageLoading.page.afterHide();
115105
PageLoading.page.element.addClass("hidden");
@@ -208,7 +198,6 @@ export async function change(
208198
const previousPage = pages[ActivePage.get()];
209199
const nextPage = pages[pageName];
210200
const totalDuration = Misc.applyReducedMotion(250);
211-
const easingMethod: Misc.JQueryEasing = "swing";
212201

213202
//start
214203
PageTransition.set(true);
@@ -217,14 +206,10 @@ export async function change(
217206
//previous page
218207
await previousPage?.beforeHide?.();
219208
previousPage.element.removeClass("hidden").css("opacity", 1);
220-
await Misc.promiseAnimation(
221-
previousPage.element,
222-
{
223-
opacity: "0",
224-
},
225-
totalDuration / 2,
226-
easingMethod
227-
);
209+
await Misc.promiseAnimate(previousPage.element[0] as HTMLElement, {
210+
opacity: "0",
211+
duration: totalDuration / 2,
212+
});
228213
previousPage.element.addClass("hidden");
229214
await previousPage?.afterHide();
230215

@@ -245,7 +230,6 @@ export async function change(
245230
await showSyncLoading({
246231
loadingOptions: syncLoadingOptions,
247232
totalDuration,
248-
easingMethod,
249233
});
250234
}
251235

@@ -297,14 +281,10 @@ export async function change(
297281
}
298282

299283
nextPage.element.removeClass("hidden").css("opacity", 0);
300-
await Misc.promiseAnimation(
301-
nextPage.element,
302-
{
303-
opacity: "1",
304-
},
305-
totalDuration / 2,
306-
easingMethod
307-
);
284+
await Misc.promiseAnimate(nextPage.element[0] as HTMLElement, {
285+
opacity: "1",
286+
duration: totalDuration / 2,
287+
});
308288
nextPage.element.addClass("active");
309289
await nextPage?.afterShow();
310290

0 commit comments

Comments
 (0)