mirror of
https://github.com/Equicord/Equicord.git
synced 2025-02-23 08:39:24 -05:00
30 lines
904 B
TypeScript
30 lines
904 B
TypeScript
|
/*
|
||
|
* Vencord, a Discord client mod
|
||
|
* Copyright (c) 2024 Vendicated and contributors
|
||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
*/
|
||
|
|
||
|
import { makeLazy } from "@utils/lazy";
|
||
|
import { useEffect, useState } from "@webpack/common";
|
||
|
|
||
|
const SCRIPT_URL = "https://unpkg.com/katex@0.16.9/dist/katex.mjs";
|
||
|
const STYLE_URL = "https://unpkg.com/katex@0.16.9/dist/katex.min.css";
|
||
|
|
||
|
let theKatex: undefined | any = undefined;
|
||
|
export const loadKatex = makeLazy(async () => {
|
||
|
const style = document.createElement("link");
|
||
|
style.setAttribute("rel", "stylesheet");
|
||
|
style.setAttribute("href", STYLE_URL);
|
||
|
document.head.appendChild(style);
|
||
|
return theKatex = (await import(SCRIPT_URL)).default;
|
||
|
});
|
||
|
|
||
|
export function useKatex() {
|
||
|
const [katex, setKatex] = useState(theKatex);
|
||
|
useEffect(() => {
|
||
|
if (katex === undefined)
|
||
|
loadKatex().then(setKatex);
|
||
|
});
|
||
|
return katex;
|
||
|
}
|