const init = () => { // initLoaders() }; const initLoaders = () => { function domReady(condition: DocumentReadyState[] = ["complete", "interactive"]) { return new Promise(resolve => { if (condition.includes(document.readyState)) { resolve(true); } else { document.addEventListener("readystatechange", () => { if (condition.includes(document.readyState)) { resolve(true); } }); } }); } const safeDOM = { append(parent: HTMLElement, child: HTMLElement) { if (!Array.from(parent.children).find(e => e === child)) { return parent.appendChild(child); } }, remove(parent: HTMLElement, child: HTMLElement) { if (Array.from(parent.children).find(e => e === child)) { return parent.removeChild(child); } }, }; /** * https://tobiasahlin.com/spinkit * https://connoratherton.com/loaders * https://projects.lukehaas.me/css-loaders * https://matejkustec.github.io/SpinThatShit */ function useLoading() { const className = `loaders-css__square-spin`; const styleContent = ` @keyframes loading-spin { 33%{background-size:calc(100%/3) 0% ,calc(100%/3) 100%,calc(100%/3) 100%} 50%{background-size:calc(100%/3) 100%,calc(100%/3) 0% ,calc(100%/3) 100%} 66%{background-size:calc(100%/3) 100%,calc(100%/3) 100%,calc(100%/3) 0% } } .${className} > div { width: 60px; aspect-ratio: 4; --_g: no-repeat radial-gradient(circle closest-side,#cbd5e1 90%,#cbd5e100); background: var(--_g) 0% 50%, var(--_g) 50% 50%, var(--_g) 100% 50%; background-size: calc(100%/3) 100%; animation: loading-spin 1s infinite linear; } .app-loading-wrap { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; background: #FFFFFF; z-index: 10000; } [data-theme="dark"] .app-loading-wrap { background: #17171A; } [data-theme="dark"] .${className} > div { --_g: no-repeat radial-gradient(circle closest-side,#2D3748 90%,#2D374800); } `; const oStyle = document.createElement("style"); const oDiv = document.createElement("div"); let hasLoading = false; let setLoadingTimer = null; oStyle.id = "app-loading-style"; oStyle.innerHTML = styleContent; oDiv.className = "app-loading-wrap"; oDiv.innerHTML = `