feat: add performant webgl loading screens

This commit is contained in:
AdenMGB committed 2026-08-18 18:47:12 +09:30
1 parent ddbccecda2
commit 07b29c8d31
8 files changed
+868 -90

No files matched your search

BIN
View File
Binary file not shown.
+3 -1
View File
@@ -19,7 +19,7 @@ import { AddBetterSEQTAElements } from "@/seqta/ui/AddBetterSEQTAElements";
import { updateAllColors } from "@/seqta/ui/colors/Manager";
import { applySelectedFont } from "@/seqta/ui/fonts/Manager";
import { verboseInfo, verboseLog } from "@/utils/verboseLog";
import loading from "@/seqta/ui/Loading";
import loading, { stopLoadingAnimation } from "@/seqta/ui/Loading";
import { SendNewsPage } from "@/seqta/utils/SendNewsPage";
import { getEngageRoutePage } from "@/seqta/utils/engageRoute";
import {
@@ -78,6 +78,7 @@ let engageHashListenerAttached = false;
export async function finishLoad() {
if (betterSeqtaFinishLoadDone) return;
betterSeqtaFinishLoadDone = true;
try {
@@ -93,6 +94,7 @@ export async function finishLoad() {
const loadingbk = document.getElementById("loading");
loadingbk?.classList.add("closeLoading");
stopLoadingAnimation();
await delay(501);
loadingbk?.remove();
} catch (err) {
+20
View File
@@ -0,0 +1,20 @@
import { getEngageRoutePage } from "@/seqta/utils/engageRoute";
import {
loadEngageHomePage,
updateEngageHomeMenuActive,
} from "@/seqta/utils/Loaders/LoadEngageHomePage";
import { isSeqtaEngageExperience } from "@/seqta/utils/isSeqtaEngage";
let engageHashListenerAttached = false;
export function attachEngageHashListenerIfNeeded(): void {
if (!isSeqtaEngageExperience() || engageHashListenerAttached) return;
engageHashListenerAttached = true;
window.addEventListener("hashchange", () => {
if (getEngageRoutePage() === "home") {
void loadEngageHomePage();
} else {
updateEngageHomeMenuActive(false);
}
});
}
+224 -88
View File
@@ -1,102 +1,238 @@
import browser from "webextension-polyfill";
import stringToHTML from "@/seqta/utils/stringToHTML";
import loadingSpinner from "./loading-spinner.html?raw";
import loadingOverlay from "./loading-overlay.html?raw";
import { startLoadingCanvas } from "./loadingCanvas";
import {
pickLoadingVariant,
type LoadingVariant,
} from "./loadingVariants";
export function AppendLoadingSymbol(givenID: any, position: any) {
let loadingsymbol = stringToHTML(/* html */ `
<div id="${givenID}">
let stopCanvas: (() => void) | null = null;
const loadingStyles = /* css */ `
.bkloading {
--bk-line-color: rgba(255, 255, 255, 0.08);
--bk-line-accent: rgba(255, 255, 255, 0.15);
--bk-line-blue: rgba(96, 165, 250, 0.42);
--bk-grid-color: rgba(255, 255, 255, 0.028);
--bk-spin-outer: 1s;
--bk-spin-inner: 3s;
--bk-spin-small: 3s;
--bk-stage-name: bkloading-stage-in;
--bk-stage-duration: 0.85s;
position: absolute;
inset: 0;
z-index: 1000000;
overflow: hidden;
contain: strict;
color: #f4f4f5;
background:
radial-gradient(ellipse 70% 45% at 50% 95%, rgba(37, 99, 235, 0.12), transparent 62%),
linear-gradient(180deg, #010101 0%, #040404 50%, #080808 100%);
opacity: 1;
transition: opacity 0.85s cubic-bezier(0.4, 0, 0.2, 1);
}
.bkloading.closeLoading {
opacity: 0;
pointer-events: none;
}
.bkloading__canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.bkloading__vignette {
position: absolute;
inset: 0;
pointer-events: none;
background: radial-gradient(ellipse at center, transparent 32%, rgba(0, 0, 0, 0.75) 100%);
opacity: 0.88;
}
.bkloading__content {
position: absolute;
inset: 0;
display: grid;
place-items: center;
pointer-events: none;
}
.bkloading__logo-stage,
.bkloading-inline {
position: relative;
}
.bkloading__logo-stage {
width: 220px;
height: 220px;
animation-name: var(--bk-stage-name);
animation-duration: var(--bk-stage-duration);
animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
animation-fill-mode: both;
}
.bkloading-inline {
width: 120px;
height: 120px;
margin: 0 auto;
}
.bkloading__logo-stage .svg,
.bkloading-inline .svg {
transform-origin: center center;
position: absolute;
top: 50%;
left: 50%;
backface-visibility: hidden;
will-change: transform;
}
.bkloading__logo-stage .logo,
.bkloading-inline .logo {
transform: translate3d(-50%, -50%, 0);
}
.bkloading__logo-stage .logo {
z-index: 2;
}
.bkloading__logo-stage .big-circle {
margin: -90px;
animation: bkloading-spin var(--bk-spin-inner) linear infinite;
}
.bkloading__logo-stage .small-circle {
margin: -67px;
animation: bkloading-spin var(--bk-spin-small) linear infinite;
}
.bkloading__logo-stage .outer-circle {
margin: -110px;
animation: bkloading-spin-reverse var(--bk-spin-outer) linear infinite;
}
.bkloading-inline .big-circle {
margin: -88px;
animation: bkloading-spin 3s linear infinite;
}
.bkloading-inline .small-circle {
margin: -66px;
animation: bkloading-spin-reverse 3s linear infinite;
}
.bkloading-inline .outer-circle {
margin: -108px;
animation: bkloading-spin 4.5s linear infinite;
}
.bkloading__version {
position: absolute;
right: 12px;
bottom: 10px;
font-size: 0.95rem;
letter-spacing: 0.02em;
color: rgba(255, 255, 255, 0.35);
pointer-events: none;
}
@keyframes bkloading-stage-in {
from {
opacity: 0;
transform: translate3d(0, 12px, 0) scale(0.94);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0) scale(1);
}
}
@keyframes bkloading-spin {
to {
transform: rotate(360deg);
}
}
@keyframes bkloading-spin-reverse {
to {
transform: rotate(-360deg);
}
}
@media (prefers-reduced-motion: reduce) {
.bkloading__logo-stage .big-circle,
.bkloading__logo-stage .small-circle,
.bkloading__logo-stage .outer-circle,
.bkloading-inline .big-circle,
.bkloading-inline .small-circle,
.bkloading-inline .outer-circle {
animation: none !important;
}
}
`;
function overlayWithSpinner(): string {
return loadingOverlay.replace(
"<div class=\"bkloading__logo-stage\"></div>",
`<div class="bkloading__logo-stage">${loadingSpinner}</div>`,
);
}
function applyVariantTheme(root: HTMLElement, variant: LoadingVariant) {
const { theme } = variant;
root.dataset.variant = variant.id;
root.style.background = theme.background;
root.style.setProperty("--bk-spin-outer", theme.spinOuter);
root.style.setProperty("--bk-spin-inner", theme.spinInner);
root.style.setProperty("--bk-spin-small", theme.spinSmall);
root.style.setProperty("--bk-stage-name", theme.stageName);
root.style.setProperty("--bk-stage-duration", theme.stageDuration);
const vignette = root.querySelector(".bkloading__vignette") as HTMLElement | null;
if (vignette) vignette.style.opacity = String(theme.vignetteOpacity);
}
function startCanvasForRoot(root: HTMLElement, variant: LoadingVariant) {
stopCanvas?.();
const canvas = root.querySelector(".bkloading__canvas") as HTMLCanvasElement | null;
stopCanvas = canvas ? startLoadingCanvas(canvas, root, variant) : null;
}
export function AppendLoadingSymbol(givenID: string, position: string) {
const loadingsymbol = stringToHTML(/* html */ `
<div id="${givenID}" class="bkloading-inline">
${loadingSpinner}
</div>`).firstChild;
document.querySelector(position).appendChild(loadingsymbol);
document.querySelector(position)?.appendChild(loadingsymbol!);
}
export function stopLoadingAnimation() {
stopCanvas?.();
stopCanvas = null;
}
export default function loading() {
let loadinghtml = stringToHTML(/* html */ `
<div class="bkloading" id="loading">
<style>
.bkloading {
transition: color 1ms linear, opacity 1s ease-in-out;
background-color: rgb(229, 231, 235);
color: black;
width: 100%;
overflow: hidden;
opacity: 1;
transition: 1s;
height: 100%;
z-index: 1000000;
position: absolute;
left: 0;
top: 0;
}
stopLoadingAnimation();
.closeLoading {
opacity: 0;
}
const variant = pickLoadingVariant();
.dark .bkloading {
background-color: rgb(26, 26, 26);
color: white;
}
const loadinghtml = stringToHTML(/* html */ `
<div class="bkloading" id="loading" data-variant="${variant.id}">
<style>${loadingStyles}</style>
${overlayWithSpinner()}
<div class="bkloading__version">v${browser.runtime.getManifest().version}</div>
</div>`);
.svg {
transform-origin: center;
position: absolute;
top: 50%;
left: 50%;
will-change: transform;
}
.logo {
transform: translate(-50%, -50%);
}
.big-circle {
margin: -88px;
will-change: transform;
animation-timing-function: ease;
animation: spin 3s linear infinite;
-moz-animation: spin 3s linear infinite;
}
.small-circle {
margin: -66px;
will-change: transform;
animation-timing-function: ease;
animation: spin 3s linear infinite;
-moz-animation: spin 3s linear infinite;
}
.outer-circle {
margin: -108px;
will-change: transform;
animation-direction: alternate-reverse;
animation: spinback 1s linear infinite;
-moz-animation: spinback 1s linear infinite;
}
@-moz-keyframes spin {
100% {
-moz-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes spinback {
100% {
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
}
}
</style>
${loadingSpinner}
<div style="position: absolute;bottom: 0;right: 0;padding: 10px;color: #4f4f4f;text-anchor: middle;font-size: 20px;">v${
browser.runtime.getManifest().version
}</div></div>`);
var html = document.getElementsByTagName("html")[0];
html.append(loadinghtml.firstChild!);
const root = loadinghtml.firstChild as HTMLElement;
document.documentElement.append(root);
applyVariantTheme(root, variant);
startCanvasForRoot(root, variant);
}
+5
View File
@@ -0,0 +1,5 @@
<canvas class="bkloading__canvas" aria-hidden="true"></canvas>
<div class="bkloading__vignette" aria-hidden="true"></div>
<div class="bkloading__content">
<div class="bkloading__logo-stage"></div>
</div>
+1 -1
View File
@@ -1,4 +1,4 @@
<svg height="120" width="120" viewBox="0 0 400 400" class="logo svg"><path xmlns="http://www.w3.org/2000/svg" id="path0" style="fill:currentColor; stroke:none;" d="M186.505 87.037 C 182.415 87.344,173.998 88.440,173.252 88.762 C 172.985 88.877,172.274 89.020,171.672 89.079 C 170.442 89.200,168.636 89.622,167.903 89.959 C 167.635 90.082,167.033 90.234,166.565 90.296 C 165.612 90.422,163.779 90.882,163.040 91.179 C 162.772 91.287,162.061 91.507,161.459 91.668 C 160.857 91.829,160.036 92.098,159.635 92.265 C 159.234 92.432,158.249 92.769,157.447 93.014 C 156.644 93.259,155.884 93.550,155.757 93.660 C 155.630 93.770,155.327 93.860,155.085 93.860 C 154.842 93.860,154.454 93.965,154.222 94.093 C 153.400 94.545,150.479 95.805,150.253 95.805 C 150.016 95.805,149.771 95.915,148.328 96.665 C 147.860 96.908,147.313 97.182,147.112 97.273 C 146.912 97.364,146.365 97.637,145.897 97.881 C 145.429 98.124,144.881 98.397,144.681 98.488 C 144.480 98.579,143.933 98.853,143.465 99.096 C 142.997 99.340,142.395 99.646,142.128 99.777 C 141.860 99.908,141.477 100.108,141.277 100.222 C 141.076 100.336,140.748 100.499,140.547 100.585 C 140.347 100.670,139.854 100.978,139.453 101.269 C 139.052 101.560,138.213 102.041,137.590 102.338 C 136.967 102.636,136.396 103.039,136.321 103.233 C 136.247 103.428,136.030 103.587,135.841 103.587 C 135.550 103.587,132.653 105.358,132.280 105.764 C 132.213 105.837,131.983 106.006,131.768 106.140 C 130.923 106.668,127.533 109.285,127.457 109.470 C 127.412 109.577,127.268 109.666,127.135 109.666 C 126.540 109.666,121.820 113.892,117.087 118.663 C 112.078 123.712,111.261 124.586,110.692 125.504 C 110.412 125.954,109.794 126.699,109.317 127.160 C 108.840 127.621,108.450 128.132,108.450 128.295 C 108.450 128.458,108.365 128.628,108.262 128.673 C 107.951 128.807,105.015 132.816,104.785 133.420 C 104.667 133.729,104.457 133.982,104.317 133.982 C 104.177 133.982,103.932 134.283,103.773 134.650 C 103.614 135.018,103.234 135.628,102.927 136.006 C 102.621 136.385,102.371 136.812,102.371 136.956 C 102.371 137.100,102.086 137.592,101.737 138.049 C 101.389 138.506,100.664 139.720,100.128 140.747 C 99.591 141.774,98.966 142.888,98.738 143.222 C 98.356 143.783,96.170 148.220,95.444 149.909 C 95.271 150.310,94.844 151.251,94.495 152.000 C 94.146 152.749,93.860 153.542,93.860 153.763 C 93.860 153.984,93.764 154.164,93.645 154.164 C 93.527 154.164,93.374 154.410,93.305 154.711 C 93.161 155.340,92.710 156.616,92.240 157.727 C 92.061 158.148,91.915 158.661,91.915 158.867 C 91.915 159.073,91.805 159.309,91.672 159.392 C 91.538 159.475,91.429 159.797,91.429 160.108 C 91.429 160.419,91.265 160.987,91.065 161.370 C 90.866 161.753,90.701 162.252,90.701 162.478 C 90.700 162.704,90.590 162.957,90.456 163.040 C 90.322 163.122,90.213 163.493,90.213 163.864 C 90.213 164.235,90.138 164.614,90.046 164.706 C 89.824 164.927,89.029 167.996,89.011 168.696 C 89.003 168.999,88.893 169.437,88.765 169.669 C 88.508 170.137,88.048 172.415,87.871 174.103 C 87.808 174.705,87.662 175.416,87.548 175.684 C 87.266 176.343,86.617 181.044,86.457 183.587 C 86.385 184.723,86.222 186.529,86.094 187.599 C 85.788 190.163,85.798 198.120,86.112 201.337 C 86.249 202.742,86.453 205.040,86.565 206.444 C 86.838 209.853,87.280 212.835,87.557 213.119 C 87.680 213.246,87.781 213.924,87.781 214.627 C 87.781 215.329,87.883 216.156,88.007 216.463 C 88.131 216.770,88.415 217.897,88.639 218.967 C 89.146 221.396,89.699 223.457,89.990 224.009 C 90.112 224.241,90.213 224.584,90.213 224.771 C 90.213 225.098,90.801 227.195,91.176 228.207 C 91.698 229.617,91.977 230.450,92.089 230.942 C 92.158 231.243,92.311 231.489,92.430 231.489 C 92.548 231.489,92.648 231.681,92.652 231.915 C 92.663 232.514,93.402 234.579,94.046 235.813 C 94.345 236.385,94.590 236.997,94.590 237.173 C 94.590 237.553,99.750 247.882,100.233 248.468 C 100.417 248.692,100.726 249.204,100.919 249.605 C 101.375 250.552,103.155 253.229,103.398 253.333 C 103.502 253.378,103.587 253.532,103.587 253.675 C 103.587 253.819,103.860 254.295,104.195 254.733 C 104.529 255.171,104.802 255.620,104.802 255.731 C 104.802 255.842,105.076 256.227,105.410 256.588 C 105.745 256.948,106.018 257.310,106.018 257.393 C 106.018 257.475,106.443 258.054,106.961 258.680 C 107.480 259.306,107.945 259.938,107.995 260.085 C 108.100 260.395,109.505 262.079,112.158 265.073 C 113.195 266.243,114.043 267.295,114.043 267.411 C 114.043 267.745,120.539 273.957,123.266 276.231 C 124.629 277.368,126.093 278.604,126.519 278.979 C 126.946 279.354,127.842 280.020,128.511 280.459 C 129.179 280.898,129.877 281.439,130.060 281.662 C 130.244 281.885,130.495 282.067,130.618 282.067 C 130.741 282.067,131.137 282.340,131.497 282.675 C 131.858 283.009,132.244 283.283,132.354 283.283 C 132.465 283.283,132.914 283.556,133.352 283.891 C 133.791 284.225,134.226 284.498,134.319 284.498 C 134.413 284.498,134.784 284.772,135.145 285.106 C 135.505 285.441,135.930 285.714,136.088 285.714 C 136.247 285.714,136.685 285.967,137.063 286.275 C 137.441 286.584,138.407 287.1Line truncated
<svg height="120" width="120" viewBox="0 0 400 400" class="logo svg"><path xmlns="http://www.w3.org/2000/svg" id="path0" style="fill:currentColor; stroke:none;" d="M186.505 87.037 C 182.415 87.344,173.998 88.440,173.252 88.762 C 172.985 88.877,172.274 89.020,171.672 89.079 C 170.442 89.200,168.636 89.622,167.903 89.959 C 167.635 90.082,167.033 90.234,166.565 90.296 C 165.612 90.422,163.779 90.882,163.040 91.179 C 162.772 91.287,162.061 91.507,161.459 91.668 C 160.857 91.829,160.036 92.098,159.635 92.265 C 159.234 92.432,158.249 92.769,157.447 93.014 C 156.644 93.259,155.884 93.550,155.757 93.660 C 155.630 93.770,155.327 93.860,155.085 93.860 C 154.842 93.860,154.454 93.965,154.222 94.093 C 153.400 94.545,150.479 95.805,150.253 95.805 C 150.016 95.805,149.771 95.915,148.328 96.665 C 147.860 96.908,147.313 97.182,147.112 97.273 C 146.912 97.364,146.365 97.637,145.897 97.881 C 145.429 98.124,144.881 98.397,144.681 98.488 C 144.480 98.579,143.933 98.853,143.465 99.096 C 142.997 99.340,142.395 99.646,142.128 99.777 C 141.860 99.908,141.477 100.108,141.277 100.222 C 141.076 100.336,140.748 100.499,140.547 100.585 C 140.347 100.670,139.854 100.978,139.453 101.269 C 139.052 101.560,138.213 102.041,137.590 102.338 C 136.967 102.636,136.396 103.039,136.321 103.233 C 136.247 103.428,136.030 103.587,135.841 103.587 C 135.550 103.587,132.653 105.358,132.280 105.764 C 132.213 105.837,131.983 106.006,131.768 106.140 C 130.923 106.668,127.533 109.285,127.457 109.470 C 127.412 109.577,127.268 109.666,127.135 109.666 C 126.540 109.666,121.820 113.892,117.087 118.663 C 112.078 123.712,111.261 124.586,110.692 125.504 C 110.412 125.954,109.794 126.699,109.317 127.160 C 108.840 127.621,108.450 128.132,108.450 128.295 C 108.450 128.458,108.365 128.628,108.262 128.673 C 107.951 128.807,105.015 132.816,104.785 133.420 C 104.667 133.729,104.457 133.982,104.317 133.982 C 104.177 133.982,103.932 134.283,103.773 134.650 C 103.614 135.018,103.234 135.628,102.927 136.006 C 102.621 136.385,102.371 136.812,102.371 136.956 C 102.371 137.100,102.086 137.592,101.737 138.049 C 101.389 138.506,100.664 139.720,100.128 140.747 C 99.591 141.774,98.966 142.888,98.738 143.222 C 98.356 143.783,96.170 148.220,95.444 149.909 C 95.271 150.310,94.844 151.251,94.495 152.000 C 94.146 152.749,93.860 153.542,93.860 153.763 C 93.860 153.984,93.764 154.164,93.645 154.164 C 93.527 154.164,93.374 154.410,93.305 154.711 C 93.161 155.340,92.710 156.616,92.240 157.727 C 92.061 158.148,91.915 158.661,91.915 158.867 C 91.915 159.073,91.805 159.309,91.672 159.392 C 91.538 159.475,91.429 159.797,91.429 160.108 C 91.429 160.419,91.265 160.987,91.065 161.370 C 90.866 161.753,90.701 162.252,90.701 162.478 C 90.700 162.704,90.590 162.957,90.456 163.040 C 90.322 163.122,90.213 163.493,90.213 163.864 C 90.213 164.235,90.138 164.614,90.046 164.706 C 89.824 164.927,89.029 167.996,89.011 168.696 C 89.003 168.999,88.893 169.437,88.765 169.669 C 88.508 170.137,88.048 172.415,87.871 174.103 C 87.808 174.705,87.662 175.416,87.548 175.684 C 87.266 176.343,86.617 181.044,86.457 183.587 C 86.385 184.723,86.222 186.529,86.094 187.599 C 85.788 190.163,85.798 198.120,86.112 201.337 C 86.249 202.742,86.453 205.040,86.565 206.444 C 86.838 209.853,87.280 212.835,87.557 213.119 C 87.680 213.246,87.781 213.924,87.781 214.627 C 87.781 215.329,87.883 216.156,88.007 216.463 C 88.131 216.770,88.415 217.897,88.639 218.967 C 89.146 221.396,89.699 223.457,89.990 224.009 C 90.112 224.241,90.213 224.584,90.213 224.771 C 90.213 225.098,90.801 227.195,91.176 228.207 C 91.698 229.617,91.977 230.450,92.089 230.942 C 92.158 231.243,92.311 231.489,92.430 231.489 C 92.548 231.489,92.648 231.681,92.652 231.915 C 92.663 232.514,93.402 234.579,94.046 235.813 C 94.345 236.385,94.590 236.997,94.590 237.173 C 94.590 237.553,99.750 247.882,100.233 248.468 C 100.417 248.692,100.726 249.204,100.919 249.605 C 101.375 250.552,103.155 253.229,103.398 253.333 C 103.502 253.378,103.587 253.532,103.587 253.675 C 103.587 253.819,103.860 254.295,104.195 254.733 C 104.529 255.171,104.802 255.620,104.802 255.731 C 104.802 255.842,105.076 256.227,105.410 256.588 C 105.745 256.948,106.018 257.310,106.018 257.393 C 106.018 257.475,106.443 258.054,106.961 258.680 C 107.480 259.306,107.945 259.938,107.995 260.085 C 108.100 260.395,109.505 262.079,112.158 265.073 C 113.195 266.243,114.043 267.295,114.043 267.411 C 114.043 267.745,120.539 273.957,123.266 276.231 C 124.629 277.368,126.093 278.604,126.519 278.979 C 126.946 279.354,127.842 280.020,128.511 280.459 C 129.179 280.898,129.877 281.439,130.060 281.662 C 130.244 281.885,130.495 282.067,130.618 282.067 C 130.741 282.067,131.137 282.340,131.497 282.675 C 131.858 283.009,132.244 283.283,132.354 283.283 C 132.465 283.283,132.914 283.556,133.352 283.891 C 133.791 284.225,134.226 284.498,134.319 284.498 C 134.413 284.498,134.784 284.772,135.145 285.106 C 135.505 285.441,135.930 285.714,136.088 285.714 C 136.247 285.714,136.685 285.967,137.063 286.275 C 137.441 286.584,138.407 287.1Line truncated
<svg height="135" width="135" viewBox="0 0 1000 1000" class="small-circle svg"><path xmlns="http://www.w3.org/2000/svg" style="fill:currentColor; stroke:none;" d="M456 954L455.999 938C455.986 936.008 456.301 933.282 454.972 931.603C453.594 929.862 450.977 930.062 448.999 929.835C443.991 929.258 438.987 928.463 434 927.728C414.788 924.898 395.564 920.733 377 915.025C300.826 891.602 231.835 849.314 178.17 790C106.263 710.526 63.7248 603.522 65.0039 496C65.7806 430.71 81.6532 365.691 110.259 307C130.156 266.177 157.727 228.746 189.039 196C222.33 161.185 262.986 132.26 306 110.753C345.737 90.8846 389.756 75.6209 434 70L434 48C417.656 48.1353 400.764 53.1855 385 57.1265C338.501 68.7513 294.622 88.2739 254 113.576C215.656 137.46 181.298 167.82 151.87 202C33.2034 339.827 7.62905 544.971 91.2585 707C112.853 748.839 140.699 787.699 174 821C210.688 857.688 253.047 888.542 300 910.781C332.493 926.171 365.923 937.713 401 945.65C418.745 949.666 437.768 953.624 456 954z"/></svg>
<svg height="180" width="180" viewBox="0 0 1000 1000" class="big-circle svg"><path xmlns="http://www.w3.org/2000/svg" style="fill:currentColor; stroke:none;" d="M454 952L454 887C441.324 886.456 428.346 883.444 416 880.65C389.799 874.722 364.497 866.349 340 855.306C205.92 794.861 116.45 660.408 110.039 514C108.593 480.976 112.302 447.246 119.424 415C144.931 299.518 226.1 198.275 333 147.781C389.157 121.255 450.99 108.496 513 110.015C612.241 112.446 711.495 157.399 779.961 229C839.544 291.312 879.215 372.892 887.831 459C893.323 513.894 887.624 569.466 870.329 622C836.537 724.647 758.42 810.937 660 855.306C635.503 866.349 610.201 874.722 584 880.65C571.383 883.505 557.974 886.732 545 887L545 952C562.916 951.63 581.566 947.595 599 943.65C637.149 935.018 673.043 921.725 708 904.247C753.184 881.655 792.42 850.594 828 815C859.416 783.572 885.414 745.666 905.247 706C933.723 649.048 949.566 588.445 953.911 525C963.014 392.066 906.622 254.399 808 165.17C769.47 130.31 725.8 101.975 678 81.5787C629.733 60.9833 575.64 47.3041 523 46.0146C469.032 44.6927 415.748 49.9443 364 66.0255C223.375 109.726 109.726 223.376 66.0255 364C14.4181 530.066 63.7205 715.347 191 833.911C229.196 869.491 274.051 897.962 322 918.421C362.806 935.833 409.371 950.084 454 952z"/></svg>
<svg height="220" width="220" viewBox="0 0 1000 1000" class="outer-circle svg"><path xmlns="http://www.w3.org/2000/svg" style="fill:currentColor; stroke:none;" d="M456 954L456 946C438.715 945.258 420.843 941.462 404 937.65C369.403 929.822 335.739 918.116 304 902.247C255.981 878.237 211.768 846.374 175.09 807C62.5744 686.214 23.1598 509.033 78.6921 353C96.4653 303.062 122.84 256.974 156.424 216C207.709 153.43 278.099 103.658 355 78C372.453 72.1767 389.992 67.0399 408 63.2107C413.31 62.0816 418.647 60.9853 424 60.0811C426.508 59.6575 430.352 59.6852 432.397 57.9869C434.897 55.9098 434 50.8766 434 48C417.656 48.1353 400.764 53.1855 385 57.1265C338.517 68.7473 294.608 88.2827 254 113.576C215.673 137.45 181.285 167.835 151.87 202C33.9725 338.933 8.37009 541.243 89.2485 703C110.949 746.4 139.693 786.693 174 821C210.688 857.688 253.047 888.542 300 910.781C332.484 926.167 365.934 937.716 401 945.65C418.745 949.666 437.768 953.624 456 954z"/></svg>

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

+364
View File
@@ -0,0 +1,364 @@
import { pickLoadingVariant, variantRevealMs } from "./loadingVariants";
const smooth = (t: number) => t * t * (3 - 2 * t);
type SoftBlob = {
cx: number;
cy: number;
rx: number;
ry: number;
rgb: string;
phase: number;
speed: number;
amp?: number;
rot?: number;
drift?: number;
};
const DIFFUSE: SoftBlob[] = [
{ cx: 0.26, cy: 1.14, rx: 0.4, ry: 0.34, rgb: "37, 99, 235", phase: 0, speed: 1, amp: 0.26, rot: 0.38 },
{ cx: 0.58, cy: 1.2, rx: 0.44, ry: 0.38, rgb: "59, 130, 246", phase: 2.2, speed: 0.82, amp: 0.3, rot: -0.32 },
{ cx: 0.46, cy: 1.1, rx: 0.36, ry: 0.28, rgb: "29, 78, 216", phase: 4.4, speed: 1.12, amp: 0.22, rot: 0.45 },
{ cx: 0.8, cy: 1.08, rx: 0.3, ry: 0.3, rgb: "96, 165, 250", phase: 1.5, speed: 0.74, amp: 0.24, rot: -0.4 },
{ cx: 0.12, cy: 1.12, rx: 0.32, ry: 0.32, rgb: "37, 99, 235", phase: 3.6, speed: 0.96, amp: 0.25, rot: 0.34 },
{ cx: 0.68, cy: 1.06, rx: 0.26, ry: 0.24, rgb: "14, 116, 244", phase: 5.1, speed: 0.88, amp: 0.18, rot: -0.28 },
];
const TIDE: SoftBlob[] = [
{ cx: 0.5, cy: 0.68, rx: 0.72, ry: 0.11, rgb: "37, 99, 235", phase: 0, speed: 0.42, drift: 0.08 },
{ cx: 0.32, cy: 0.8, rx: 0.58, ry: 0.09, rgb: "59, 130, 246", phase: 2.4, speed: 0.36, drift: 0.06 },
{ cx: 0.68, cy: 0.86, rx: 0.64, ry: 0.12, rgb: "29, 78, 216", phase: 4.6, speed: 0.4, drift: 0.07 },
{ cx: 0.5, cy: 0.96, rx: 0.78, ry: 0.1, rgb: "96, 165, 250", phase: 1.1, speed: 0.33, drift: 0.05 },
];
const GLOBE_STAGGER_MS = 720;
const GLOBE_DOT_DUR_MS = 260;
const GLOBE_REVEAL_MS = GLOBE_STAGGER_MS + GLOBE_DOT_DUR_MS;
const GLOBE_DOTS = (() => {
const n = 360;
const golden = Math.PI * (3 - Math.sqrt(5));
return Array.from({ length: n }, (_, i) => {
const y = 1 - (2 * i) / (n - 1);
const ring = Math.sqrt(Math.max(0, 1 - y * y));
const theta = golden * i;
const x = Math.cos(theta) * ring;
const z = Math.sin(theta) * ring;
return { x, y, z, theta, rank: (x + 1 - y + 2) / 4 };
});
})();
function stagger(
elapsed: number,
delay: number,
dur: number,
fade: boolean,
reduced: boolean,
): number {
if (reduced) return 1;
if (elapsed < delay) return fade ? 1 : 0;
const t = smooth(Math.min(1, (elapsed - delay) / dur));
return fade ? 1 - t : t;
}
function cycle(
elapsed: number,
revealMs: number,
holdMs: number,
): { t: number; fade: boolean; ambient: number } {
const len = revealMs * 2 + holdMs;
const tick = elapsed % len;
if (tick < revealMs) {
return { t: tick, fade: false, ambient: smooth(tick / revealMs) };
}
if (tick < revealMs + holdMs) {
return { t: revealMs, fade: false, ambient: 1 };
}
const fadeT = tick - revealMs - holdMs;
return { t: fadeT, fade: true, ambient: smooth((len - tick) / revealMs) };
}
function cssVar(root: HTMLElement, name: string, fallback: string): string {
return getComputedStyle(root).getPropertyValue(name).trim() || fallback;
}
function drawGrid(
ctx: CanvasRenderingContext2D,
color: string,
w: number,
h: number,
a: number,
cols: number,
rows: number,
) {
if (cols <= 0 || rows <= 0) return;
ctx.save();
ctx.strokeStyle = color;
ctx.globalAlpha = a;
for (let c = 1; c < cols; c++) {
const x = (w / cols) * c;
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, h);
ctx.stroke();
}
for (let r = 1; r < rows; r++) {
const y = (h / rows) * r;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(w, y);
ctx.stroke();
}
ctx.restore();
}
function drawSoftBlobs(
ctx: CanvasRenderingContext2D,
w: number,
h: number,
elapsed: number,
reduced: boolean,
blobs: SoftBlob[],
blur: number,
fadeMs: number,
tide: boolean,
) {
const time = reduced ? 0 : elapsed * 0.001;
const fadeIn = reduced ? 1 : smooth(Math.min(1, elapsed / fadeMs));
ctx.save();
ctx.globalAlpha = fadeIn;
ctx.filter = `blur(${blur}px)`;
for (const b of blobs) {
const t = time * b.speed + b.phase;
let x: number;
let y: number;
let rx: number;
let ry: number;
let a0: number;
let a1: number;
if (tide) {
const breathe = 1 + Math.sin(t * 1.1) * 0.14;
x = b.cx * w + Math.sin(t * 0.65) * w * (b.drift ?? 0);
y = b.cy * h + Math.sin(t * 0.48 + b.phase) * h * 0.025;
rx = b.rx * w;
ry = b.ry * h * breathe;
a0 = 0.38;
a1 = 0.14;
} else {
const amp = b.amp ?? 0.2;
const scale = 1 + Math.sin(t * 1.35) * amp;
const stretch = 1 + Math.cos(t * 0.88) * amp * 0.55;
x = b.cx * w + Math.sin(t * 0.52) * w * 0.04;
y = b.cy * h + Math.sin(t * 0.41) * h * 0.01;
rx = b.rx * w * scale;
ry = b.ry * h * stretch;
a0 = 0.5;
a1 = 0.18;
ctx.save();
ctx.translate(x, y);
ctx.rotate(t * (b.rot ?? 0));
x = 0;
y = 0;
}
const radius = Math.max(rx, ry);
const grad = ctx.createRadialGradient(x, y, 0, x, y, radius);
grad.addColorStop(0, `rgba(${b.rgb}, ${a0})`);
grad.addColorStop(tide ? 0.45 : 0.4, `rgba(${b.rgb}, ${a1})`);
grad.addColorStop(1, `rgba(${b.rgb}, 0)`);
ctx.fillStyle = grad;
ctx.fillRect(x - rx, y - ry, rx * 2, ry * 2);
if (!tide) ctx.restore();
}
ctx.filter = "none";
ctx.restore();
}
function drawDotGlobe(
ctx: CanvasRenderingContext2D,
w: number,
h: number,
elapsed: number,
reduced: boolean,
phaseElapsed: number,
fade: boolean,
ambient: number,
) {
const time = reduced ? 0 : elapsed * 0.001;
const cx = w * 0.5;
const cy = h * 0.5;
const radius = Math.min(w, h) * 0.4;
const yaw = time * 0.38;
const pitch = Math.sin(time * 0.22) * 0.18;
const cosYaw = Math.cos(yaw);
const sinYaw = Math.sin(yaw);
const cosPitch = Math.cos(pitch);
const sinPitch = Math.sin(pitch);
const lx = Math.cos(time * 0.5);
const ly = Math.sin(time * 0.32) * 0.45 + 0.35;
const lz = Math.sin(time * 0.5);
const lLen = Math.hypot(lx, ly, lz) || 1;
ctx.save();
ctx.globalAlpha = ambient;
const glow = ctx.createRadialGradient(cx, cy, 0, cx, cy, radius * 1.15);
glow.addColorStop(0, "rgba(37, 99, 235, 0.1)");
glow.addColorStop(0.55, "rgba(37, 99, 235, 0.03)");
glow.addColorStop(1, "rgba(37, 99, 235, 0)");
ctx.fillStyle = glow;
ctx.fillRect(cx - radius * 1.2, cy - radius * 1.2, radius * 2.4, radius * 2.4);
const dots: {
px: number;
py: number;
z: number;
theta: number;
nx: number;
ny: number;
nz: number;
p: number;
}[] = [];
for (const dot of GLOBE_DOTS) {
const p = stagger(phaseElapsed, dot.rank * GLOBE_STAGGER_MS, GLOBE_DOT_DUR_MS, fade, reduced);
if (p <= 0) continue;
const x = cosYaw * dot.x + sinYaw * dot.z;
const z0 = -sinYaw * dot.x + cosYaw * dot.z;
const y = cosPitch * dot.y - sinPitch * z0;
const z = sinPitch * dot.y + cosPitch * z0;
dots.push({
px: cx + x * radius,
py: cy - y * radius,
z,
theta: dot.theta,
nx: x,
ny: y,
nz: z,
p,
});
}
dots.sort((a, b) => a.z - b.z);
for (const dot of dots) {
const nLen = Math.hypot(dot.nx, dot.ny, dot.nz) || 1;
const facing = (dot.nx * lx + dot.ny * ly + dot.nz * lz) / (lLen * nLen);
const wave = Math.sin(dot.theta * 2.8 - time * 1.6) * 0.28;
const glowWave = Math.sin(dot.theta * 1.4 + time * 2.1) * 0.15;
const brightness = Math.min(1, 0.18 + Math.max(0, facing) * 0.62 + wave + glowWave);
const depth = (dot.z + 1) * 0.5;
const size = (1.2 + depth * 2.2) * dot.p;
const alpha = (0.12 + brightness * 0.75) * dot.p;
ctx.fillStyle =
brightness > 0.52
? `rgba(96, 165, 250, ${alpha})`
: `rgba(255, 255, 255, ${0.08 + brightness * 0.22 * dot.p})`;
ctx.beginPath();
ctx.arc(dot.px, dot.py, size, 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
}
export function startLoadingCanvas(
canvas: HTMLCanvasElement,
root: HTMLElement,
variant = pickLoadingVariant(),
): () => void {
const ctx = canvas.getContext("2d", { alpha: true, desynchronized: true });
if (!ctx) return () => undefined;
const visual = variant.visual ?? "lines";
const { lines, holdMs, grid } = variant;
const revealMs = visual === "globe" ? GLOBE_REVEAL_MS : variantRevealMs(variant);
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const start = performance.now();
let raf = 0;
let w = 0;
let h = 0;
const resize = () => {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
w = canvas.clientWidth;
h = canvas.clientHeight;
canvas.width = Math.max(1, Math.floor(w * dpr));
canvas.height = Math.max(1, Math.floor(h * dpr));
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
};
const ro = new ResizeObserver(resize);
ro.observe(canvas);
resize();
const frame = (now: number) => {
if (!canvas.isConnected) return;
const elapsed = now - start;
ctx.clearRect(0, 0, w, h);
if (visual === "globe") {
const { t, fade, ambient } = cycle(elapsed, revealMs, holdMs);
drawDotGlobe(ctx, w, h, elapsed, reduced, t, fade, reduced ? 1 : ambient);
} else if (visual === "blobs") {
const tide = variant.blobStyle === "tide";
drawSoftBlobs(
ctx,
w,
h,
elapsed,
reduced,
tide ? TIDE : DIFFUSE,
tide ? 58 : 52,
tide ? 1800 : 1600,
tide,
);
} else {
const { t, fade } = cycle(elapsed, revealMs, holdMs);
const gridA = reduced ? 1 : smooth(Math.min(1, elapsed / 1400)) * 0.7;
drawGrid(
ctx,
cssVar(root, "--bk-grid-color", "rgba(255,255,255,0.03)"),
w,
h,
gridA,
grid.cols,
grid.rows,
);
const lineColor = cssVar(root, "--bk-line-color", "rgba(255,255,255,0.08)");
const lineAccent = cssVar(root, "--bk-line-accent", "rgba(255,255,255,0.15)");
const lineBlue = cssVar(root, "--bk-line-blue", "rgba(96,165,250,0.4)");
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.lineWidth = 1;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const p = stagger(t, line.delay, line.dur, fade, reduced);
if (p <= 0) continue;
ctx.strokeStyle = line.blue ? lineBlue : i % 2 ? lineColor : lineAccent;
ctx.setLineDash(line.dashed ? [8, 11] : []);
line.stroke(ctx, p, w, h);
}
}
raf = requestAnimationFrame(frame);
};
raf = requestAnimationFrame(frame);
return () => {
cancelAnimationFrame(raf);
ro.disconnect();
};
}
+251
View File
@@ -0,0 +1,251 @@
export type Line = {
delay: number;
dur: number;
dashed?: boolean;
blue?: boolean;
stroke: (
ctx: CanvasRenderingContext2D,
p: number,
w: number,
h: number,
) => void;
};
export type LoadingVariant = {
id: string;
visual?: "lines" | "blobs" | "globe";
blobStyle?: "diffuse" | "tide";
holdMs: number;
grid: { cols: number; rows: number };
lines: Line[];
theme: {
background: string;
vignetteOpacity: number;
spinOuter: string;
spinInner: string;
spinSmall: string;
stageName: string;
stageDuration: string;
};
};
const curve = (
sample: (t: number, w: number, h: number) => { x: number; y: number },
): Line["stroke"] => {
return (ctx, p, w, h) => {
const steps = Math.max(24, Math.floor(140 * p));
if (steps <= 1) return;
ctx.beginPath();
for (let i = 0; i <= steps; i++) {
const t = (i / 140) * p;
const { x, y } = sample(Math.min(1, t), w, h);
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
};
};
const segment = (x1: number, y1: number, x2: number, y2: number): Line["stroke"] => {
return (ctx, p, w, h) => {
const ax = x1 * w;
const ay = y1 * h;
const bx = x2 * w;
const by = y2 * h;
ctx.beginPath();
ctx.moveTo(ax, ay);
ctx.lineTo(ax + (bx - ax) * p, ay + (by - ay) * p);
ctx.stroke();
};
};
const BASE = "linear-gradient(180deg, #010101 0%, #040404 50%, #080808 100%)";
const STAGE = "bkloading-stage-in";
function theme(
background: string,
vignetteOpacity: number,
spinOuter: string,
spinInner: string,
spinSmall: string,
stageDuration: string,
) {
return {
background,
vignetteOpacity,
spinOuter,
spinInner,
spinSmall,
stageName: STAGE,
stageDuration,
};
}
function canvasVariant(
id: string,
visual: "blobs" | "globe",
holdMs: number,
t: ReturnType<typeof theme>,
blobStyle?: "diffuse" | "tide",
): LoadingVariant {
return {
id,
visual,
blobStyle,
holdMs,
grid: { cols: 0, rows: 0 },
lines: [],
theme: t,
};
}
const VARIANTS: LoadingVariant[] = [
{
id: "sweep",
holdMs: 2200,
grid: { cols: 10, rows: 6 },
theme: theme(
`radial-gradient(ellipse 70% 45% at 50% 95%, rgba(37, 99, 235, 0.12), transparent 62%), ${BASE}`,
0.88,
"1s",
"3s",
"3s",
"0.85s",
),
lines: [
{
delay: 0,
dur: 1500,
stroke: curve((t, w, h) => ({
x: w * (0.06 + t * 0.78),
y: h * (0.9 - Math.sin(t * Math.PI) * 0.55),
})),
},
{
delay: 100,
dur: 1600,
dashed: true,
blue: true,
stroke: curve((t, w, h) => {
const a = Math.PI * 0.12 + t * Math.PI;
return {
x: w * 0.74 + Math.cos(a) * w * 0.34,
y: h * 0.56 + Math.sin(a) * h * 0.42,
};
}),
},
{
delay: 200,
dur: 1400,
dashed: true,
stroke: curve((t, w, h) => {
const a = Math.PI * 1.05 - t * Math.PI * 0.8;
return {
x: w * 0.28 + Math.cos(a) * w * 0.28,
y: h * 0.34 + Math.sin(a) * h * 0.3,
};
}),
},
{ delay: 60, dur: 900, stroke: segment(0.4, 0.1, 0.4, 0.94) },
{ delay: 160, dur: 1100, stroke: segment(0.04, 0.64, 0.96, 0.64) },
{
delay: 280,
dur: 1700,
stroke: curve((t, w, h) => ({
x: w * (0.52 + t * 0.4),
y: h * (0.14 + t * t * 0.7),
})),
},
{
delay: 240,
dur: 900,
dashed: true,
blue: true,
stroke: segment(0.1, 0.2, 0.5, 0.48),
},
],
},
{
id: "cross",
holdMs: 2000,
grid: { cols: 12, rows: 8 },
theme: theme(
`radial-gradient(ellipse 40% 30% at 80% 20%, rgba(59, 130, 246, 0.08), transparent 70%), ${BASE}`,
0.9,
"0.85s",
"2.6s",
"2.6s",
"0.75s",
),
lines: [
{ delay: 0, dur: 1200, stroke: segment(0.5, 0.06, 0.5, 0.94) },
{ delay: 80, dur: 1200, stroke: segment(0.04, 0.5, 0.96, 0.5) },
{
delay: 160,
dur: 1000,
dashed: true,
blue: true,
stroke: segment(0.08, 0.12, 0.92, 0.88),
},
{
delay: 240,
dur: 1000,
dashed: true,
stroke: segment(0.92, 0.12, 0.08, 0.88),
},
{ delay: 320, dur: 900, stroke: segment(0.5, 0.06, 0.72, 0.28) },
{ delay: 400, dur: 900, stroke: segment(0.5, 0.94, 0.28, 0.72) },
],
},
canvasVariant(
"diffuse",
"blobs",
0,
theme(BASE, 0.78, "1.3s", "3.8s", "3.8s", "0.9s"),
"diffuse",
),
canvasVariant(
"tide",
"blobs",
0,
theme(
`radial-gradient(ellipse 85% 45% at 50% 100%, rgba(37, 99, 235, 0.09), transparent 72%), ${BASE}`,
0.8,
"1.5s",
"4.2s",
"4.2s",
"1s",
),
"tide",
),
canvasVariant(
"globe",
"globe",
2500,
theme(
`radial-gradient(ellipse 55% 50% at 50% 48%, rgba(37, 99, 235, 0.1), transparent 70%), ${BASE}`,
0.86,
"1.2s",
"3.5s",
"3.5s",
"0.9s",
),
),
];
export function listLoadingVariants(): LoadingVariant[] {
return VARIANTS;
}
export function getLoadingVariant(id: string): LoadingVariant | undefined {
return VARIANTS.find((v) => v.id === id);
}
export function pickLoadingVariant(): LoadingVariant {
return VARIANTS[Math.floor(Math.random() * VARIANTS.length)];
}
export function variantRevealMs(variant: LoadingVariant): number {
if (variant.lines.length === 0) return 0;
return Math.max(...variant.lines.map((l) => l.delay + l.dur));
}