offline edition

This commit is contained in:
Skye 2024-11-01 15:24:14 +09:00
parent 4deb52028a
commit 7907bf7120
Signed by: me
GPG key ID: 0104BC05F41B77B8
3 changed files with 58 additions and 67 deletions

View file

@ -39,8 +39,10 @@
"@sapphi-red/web-noise-suppressor": "0.3.5",
"@vap/core": "0.0.12",
"@vap/shiki": "0.10.5",
"dompurify": "^3.1.7",
"fflate": "^0.8.2",
"gifenc": "github:mattdesl/gifenc#64842fca317b112a8590f8fef2bf3825da8f6fe3",
"katex": "^0.16.11",
"monaco-editor": "^0.50.0",
"nanoid": "^5.0.7",
"virtual-merge": "^1.0.1"
@ -49,6 +51,8 @@
"@stylistic/eslint-plugin": "^2.6.1",
"@types/chrome": "^0.0.269",
"@types/diff": "^5.2.1",
"@types/dompurify": "^3.0.5",
"@types/katex": "^0.16.7",
"@types/lodash": "^4.17.7",
"@types/node": "^22.0.3",
"@types/react": "^18.3.3",

View file

@ -28,12 +28,18 @@ importers:
'@vap/shiki':
specifier: 0.10.5
version: 0.10.5
dompurify:
specifier: ^3.1.7
version: 3.1.7
fflate:
specifier: ^0.8.2
version: 0.8.2
gifenc:
specifier: github:mattdesl/gifenc#64842fca317b112a8590f8fef2bf3825da8f6fe3
version: https://codeload.github.com/mattdesl/gifenc/tar.gz/64842fca317b112a8590f8fef2bf3825da8f6fe3
katex:
specifier: ^0.16.11
version: 0.16.11
monaco-editor:
specifier: ^0.50.0
version: 0.50.0
@ -53,6 +59,12 @@ importers:
'@types/diff':
specifier: ^5.2.1
version: 5.2.1
'@types/dompurify':
specifier: ^3.0.5
version: 3.0.5
'@types/katex':
specifier: ^0.16.7
version: 0.16.7
'@types/lodash':
specifier: ^4.17.7
version: 4.17.7
@ -622,6 +634,9 @@ packages:
'@types/diff@5.2.1':
resolution: {integrity: sha512-uxpcuwWJGhe2AR1g8hD9F5OYGCqjqWnBUQFD8gMZsDbv8oPHzxJF6iMO6n8Tk0AdzlxoaaoQhOYlIg/PukVU8g==}
'@types/dompurify@3.0.5':
resolution: {integrity: sha512-1Wg0g3BtQF7sSb27fJQAKck1HECM6zV1EB66j8JH9i3LCjYabJa0FSdiSgsD5K/RbrsR0SiraKacLB+T8ZVYAg==}
'@types/eslint@9.6.0':
resolution: {integrity: sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg==}
@ -649,6 +664,9 @@ packages:
'@types/jsonfile@6.1.4':
resolution: {integrity: sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==}
'@types/katex@0.16.7':
resolution: {integrity: sha512-HMwFiRujE5PjrgwHQ25+bsLJgowjGjm5Z8FVSf0N6PwgJrwxH0QxzHYDcKsTfV3wva0vzrpqMTJS2jXPr5BMEQ==}
'@types/lodash@4.14.194':
resolution: {integrity: sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==}
@ -688,6 +706,9 @@ packages:
'@types/scheduler@0.16.3':
resolution: {integrity: sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==}
'@types/trusted-types@2.0.7':
resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==}
'@types/yauzl@2.10.3':
resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==}
@ -995,6 +1016,10 @@ packages:
commander@2.20.3:
resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==}
commander@8.3.0:
resolution: {integrity: sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==}
engines: {node: '>= 12'}
component-emitter@1.3.0:
resolution: {integrity: sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==}
@ -1127,6 +1152,9 @@ packages:
resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==}
engines: {node: '>=0.10.0'}
dompurify@3.1.7:
resolution: {integrity: sha512-VaTstWtsneJY8xzy7DekmYWEOZcmzIe3Qb3zPd4STve1OBTa+e+WmS1ITQec1fZYXI3HCsOZZiSMpG6oxoWMWQ==}
dot-case@3.0.4:
resolution: {integrity: sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==}
@ -1945,6 +1973,10 @@ packages:
jszip@2.7.0:
resolution: {integrity: sha512-JIsRKRVC3gTRo2vM4Wy9WBC3TRcfnIZU8k65Phi3izkvPH975FowRYtKGT6PxevA0XnJ/yO8b0QwV0ydVyQwfw==}
katex@0.16.11:
resolution: {integrity: sha512-RQrI8rlHY92OLf3rho/Ts8i/XvjgguEjOkO1BEXcU3N8BqPpSzBNwV/G0Ukr+P/l3ivvJUE/Fa/CwbS6HesGNQ==}
hasBin: true
keyv@4.5.4:
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
@ -3052,6 +3084,10 @@ snapshots:
'@types/diff@5.2.1': {}
'@types/dompurify@3.0.5':
dependencies:
'@types/trusted-types': 2.0.7
'@types/eslint@9.6.0':
dependencies:
'@types/estree': 1.0.5
@ -3080,6 +3116,8 @@ snapshots:
dependencies:
'@types/node': 18.16.3
'@types/katex@0.16.7': {}
'@types/lodash@4.14.194': {}
'@types/lodash@4.17.7': {}
@ -3124,6 +3162,8 @@ snapshots:
'@types/scheduler@0.16.3': {}
'@types/trusted-types@2.0.7': {}
'@types/yauzl@2.10.3':
dependencies:
'@types/node': 22.0.3
@ -3494,6 +3534,8 @@ snapshots:
commander@2.20.3: {}
commander@8.3.0: {}
component-emitter@1.3.0: {}
concat-map@0.0.1: {}
@ -3612,6 +3654,8 @@ snapshots:
dependencies:
esutils: 2.0.3
dompurify@3.1.7: {}
dot-case@3.0.4:
dependencies:
no-case: 3.0.4
@ -4503,6 +4547,10 @@ snapshots:
dependencies:
pako: 1.0.11
katex@0.16.11:
dependencies:
commander: 8.3.0
keyv@4.5.4:
dependencies:
json-buffer: 3.0.1

View file

@ -1,52 +1,10 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2022 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import "./katex.css";
import { Devs } from "@utils/constants";
import definePlugin, { ReporterTestable } from "@utils/types";
import { makeLazy } from "@utils/lazy";
import { classes } from "@utils/misc";
import { React, useEffect, useMemo, useState } from "@webpack/common";
// @ts-expect-error
export const getKatex = /* #__PURE__*/ makeLazy(async () => (await import("https://unpkg.com/katex@0.16.9/dist/katex.mjs")).default);
export function useKatex() {
const [katex, setKatex] = useState();
useEffect(() => {
if (katex === undefined)
getKatex().then(setKatex);
});
return katex;
}
// @ts-expect-error
export const getDomPurify = /* #__PURE__*/ makeLazy(async () => (await import("https://unpkg.com/dompurify@3.1.7/dist/purify.es.mjs")).default);
export function useDomPurify() {
const [domPurify, setDomPurify] = useState();
useEffect(() => {
if (domPurify === undefined)
getDomPurify().then(setDomPurify);
});
return domPurify;
}
import { React, useMemo } from "@webpack/common";
import katex from "katex";
import domPurify from "dompurify";
export interface HighlighterProps {
lang?: string;
@ -78,30 +36,19 @@ export default definePlugin({
}
],
start: async () => {
useKatex();
useDomPurify();
},
stop: () => {
},
createBlock: (props: HighlighterProps) => (
<LazyLatex displayMode formula={props.content} />
<Latex displayMode formula={props.content} />
),
createInline: (props: HighlighterProps) => (
<LazyLatex formula={props.content.substring(1, props.content.length - 1)} />
<Latex formula={props.content.substring(1, props.content.length - 1)} />
),
});
function LazyLatex(props) {
const { formula } = props;
const katex = useKatex();
const domPurify = useDomPurify();
return katex
? <Latex {...props} katex={katex} domPurify={domPurify} />
: <LatexPlaceholder className="vc-tex-loading">{formula}</LatexPlaceholder>;
}
function Latex({ katex, formula, displayMode, domPurify }) {
function Latex({ formula, displayMode }: { formula: string, displayMode?: boolean; }) {
const result = useMemo(() => {
const html = katex.renderToString(formula, {
displayMode,
@ -114,11 +61,3 @@ function Latex({ katex, formula, displayMode, domPurify }) {
? <div className="tex" dangerouslySetInnerHTML={{ __html: result }} />
: <span className="tex" dangerouslySetInnerHTML={{ __html: result }} />;
}
function LatexPlaceholder({ className, children, ...props }) {
return (
<code className={classes(className, "vc-tex-placeholder inline")} {...props}>
{children}
</code>
);
}