mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
feat(Math OCR): replace MathJAX by Katex
This commit is contained in:
1 parent
c4f7ded565
commit
b1d3849f87
5 files changed
+95
-56
No files matched your search
+2
-1
@@ -261,6 +261,7 @@
|
||||
"jsvat-next": "^3.0.4",
|
||||
"jszip": "^3.10.1",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"katex": "^0.17.0",
|
||||
"korean-unpacker": "^1.0.3",
|
||||
"langs": "^2.0.0",
|
||||
"leaflet": "^1.9.4",
|
||||
@@ -385,11 +386,11 @@
|
||||
"vue-i18n": "^11.4.6",
|
||||
"vue-loading-overlay": "^6.0.6",
|
||||
"vue-markdown-render": "^2.3.1",
|
||||
"vue-mathjax-next": "^0.0.6",
|
||||
"vue-router": "^5.1.0",
|
||||
"vue-shadow-dom": "^4.2.0",
|
||||
"vue-tsc": "^3.3.6",
|
||||
"vue3-flip-countdown": "^0.1.6",
|
||||
"vue3-katex": "^0.8.1",
|
||||
"vuedraggable": "^4.1.0",
|
||||
"vuex": "^4.1.0",
|
||||
"w-websocket-client": "^1.0.29",
|
||||
|
||||
Generated
+37
-8
@@ -672,6 +672,9 @@ importers:
|
||||
jwt-decode:
|
||||
specifier: ^4.0.0
|
||||
version: 4.0.0
|
||||
katex:
|
||||
specifier: ^0.17.0
|
||||
version: 0.17.0
|
||||
korean-unpacker:
|
||||
specifier: ^1.0.3
|
||||
version: 1.0.3
|
||||
@@ -1044,9 +1047,6 @@ importers:
|
||||
vue-markdown-render:
|
||||
specifier: ^2.3.1
|
||||
version: 2.3.1(vue@3.5.39(typescript@6.0.3))
|
||||
vue-mathjax-next:
|
||||
specifier: ^0.0.6
|
||||
version: 0.0.6
|
||||
vue-router:
|
||||
specifier: ^5.1.0
|
||||
version: 5.1.0(@vue/compiler-sfc@3.5.39)(pinia@3.0.4(typescript@6.0.3)(vue@3.5.39(typescript@6.0.3)))(rolldown@1.1.4)(rollup@4.62.2)(vite@8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0))(vue@3.5.39(typescript@6.0.3))(webpack@5.108.3(postcss@8.5.16))
|
||||
@@ -1059,6 +1059,9 @@ importers:
|
||||
vue3-flip-countdown:
|
||||
specifier: ^0.1.6
|
||||
version: 0.1.6(typescript@6.0.3)
|
||||
vue3-katex:
|
||||
specifier: ^0.8.1
|
||||
version: 0.8.1(katex@0.17.0)(vue@3.5.39(typescript@6.0.3))
|
||||
vuedraggable:
|
||||
specifier: ^4.1.0
|
||||
version: 4.1.0(vue@3.5.39(typescript@6.0.3))
|
||||
@@ -8188,6 +8191,10 @@ packages:
|
||||
resolution: {integrity: sha512-Eeo8Ys1doU1z+x8AZsPpQu+p/QcZBI5PeOo7QGQdy2x2m0MU/hYagBbGOmXwr5KVbEfVuWv9LpnQWeehogurjg==}
|
||||
hasBin: true
|
||||
|
||||
katex@0.17.0:
|
||||
resolution: {integrity: sha512-Vdw0ATsQ9V+LuegM/BTwQqV/6cTl5lbGcIrU+BCgLxyf6bo38ybOr372tuSIxir3CN720flu1meYR6XzNMwQnw==}
|
||||
hasBin: true
|
||||
|
||||
keycode@2.2.1:
|
||||
resolution: {integrity: sha512-Rdgz9Hl9Iv4QKi8b0OlCRQEzp4AgVxyCtz5S/+VIHezDmrDhkp2N2TqBWOLz0/gbeREXOOiI9/4b8BY9uw2vFg==}
|
||||
|
||||
@@ -11128,6 +11135,11 @@ packages:
|
||||
'@vue/composition-api':
|
||||
optional: true
|
||||
|
||||
vue-dompurify-html@5.3.0:
|
||||
resolution: {integrity: sha512-HJQGBHbfSPcb6Mu97McdKbX7TqRHZa6Ji8OCpCNyuHca5QvQZ8IiuwghFPSO8OkSQfqXPNPKFMZdCOrnGGmOSQ==}
|
||||
peerDependencies:
|
||||
vue: ^3.4.36
|
||||
|
||||
vue-i18n-extract@2.0.7:
|
||||
resolution: {integrity: sha512-i1NW5R58S720iQ1BEk+6ILo3hT6UA8mtYNNolSH4rt9345qvXdvA6GHy2+jHozdDAKHwlu9VvS/+vIMKs1UYQw==}
|
||||
hasBin: true
|
||||
@@ -11149,9 +11161,6 @@ packages:
|
||||
peerDependencies:
|
||||
vue: ^3.3.4
|
||||
|
||||
vue-mathjax-next@0.0.6:
|
||||
resolution: {integrity: sha512-H4nZ8t31TmBJgiR6pHrOGz+RWhlw34d0yhD8fi8CnXoGOydGFreNH/Crd/9Jfd2IMSu/I0AC3ymT9D09JRMIrw==}
|
||||
|
||||
vue-router@5.1.0:
|
||||
resolution: {integrity: sha512-HAbiLzLEHQwxPgvsbOJDAwtavszEgLwri6XfyrsPECIFez8+59xc9LofWVdc/HEaSRT822lJ8H9Ns38VVond5g==}
|
||||
peerDependencies:
|
||||
@@ -11185,6 +11194,12 @@ packages:
|
||||
vue3-flip-countdown@0.1.6:
|
||||
resolution: {integrity: sha512-RRz+iZ7Zvr1U9mrZRya7I5815jboDyRJz9vzgILq8ZCc2fQ6SxZPYwOr3pD5oWCDBprAEsPF9x4fsTtEitSmXw==}
|
||||
|
||||
vue3-katex@0.8.1:
|
||||
resolution: {integrity: sha512-d6wxMHHaogxk6BZ+Ek/sY4AJPGfwebtCtvKWtQY+paqzhA8DpRW3gHFv9fnCxsPEXLKuYcNCqFgekJ4k8S6EKw==}
|
||||
peerDependencies:
|
||||
katex: ^0.17.0
|
||||
vue: ^3.2.22
|
||||
|
||||
vue@3.5.39:
|
||||
resolution: {integrity: sha512-xmZCYabFGcirU8r0fTuvl/LICc1OU620rnqepaJDL/a141ZigkG7AyaxQLdqJ02ZRYzWe6YPaDHeQx7MfknQfA==}
|
||||
peerDependencies:
|
||||
@@ -19001,6 +19016,10 @@ snapshots:
|
||||
dependencies:
|
||||
commander: 8.3.0
|
||||
|
||||
katex@0.17.0:
|
||||
dependencies:
|
||||
commander: 8.3.0
|
||||
|
||||
keycode@2.2.1: {}
|
||||
|
||||
keycon@1.4.0:
|
||||
@@ -22309,6 +22328,11 @@ snapshots:
|
||||
dependencies:
|
||||
vue: 3.5.39(typescript@6.0.3)
|
||||
|
||||
vue-dompurify-html@5.3.0(vue@3.5.39(typescript@6.0.3)):
|
||||
dependencies:
|
||||
dompurify: 3.4.12
|
||||
vue: 3.5.39(typescript@6.0.3)
|
||||
|
||||
vue-i18n-extract@2.0.7:
|
||||
dependencies:
|
||||
cac: 6.7.14
|
||||
@@ -22334,8 +22358,6 @@ snapshots:
|
||||
markdown-it: 14.3.0
|
||||
vue: 3.5.39(typescript@6.0.3)
|
||||
|
||||
vue-mathjax-next@0.0.6: {}
|
||||
|
||||
vue-router@5.1.0(@vue/compiler-sfc@3.5.39)(pinia@3.0.4(typescript@6.0.3)(vue@3.5.39(typescript@6.0.3)))(rolldown@1.1.4)(rollup@4.62.2)(vite@8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0))(vue@3.5.39(typescript@6.0.3))(webpack@5.108.3(postcss@8.5.16)):
|
||||
dependencies:
|
||||
'@babel/generator': 8.0.0
|
||||
@@ -22386,6 +22408,13 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- typescript
|
||||
|
||||
vue3-katex@0.8.1(katex@0.17.0)(vue@3.5.39(typescript@6.0.3)):
|
||||
dependencies:
|
||||
deepmerge: 4.3.1
|
||||
katex: 0.17.0
|
||||
vue: 3.5.39(typescript@6.0.3)
|
||||
vue-dompurify-html: 5.3.0(vue@3.5.39(typescript@6.0.3))
|
||||
|
||||
vue@3.5.39(typescript@6.0.3):
|
||||
dependencies:
|
||||
'@vue/compiler-dom': 3.5.39
|
||||
|
||||
@@ -11,6 +11,9 @@ import { plausible } from './plugins/plausible.plugin';
|
||||
import '@/utils/json5-bigint';
|
||||
import '@/utils/json5-bignum';
|
||||
|
||||
import Vue3Katex from 'vue3-katex';
|
||||
import 'katex/dist/katex.min.css';
|
||||
|
||||
import 'virtual:uno.css';
|
||||
|
||||
import { naive } from './plugins/naive.plugin';
|
||||
@@ -49,5 +52,6 @@ app.use(naive);
|
||||
app.use(plausible);
|
||||
app.use(shadow);
|
||||
app.use(store, 'pomodoro-store');
|
||||
app.use(Vue3Katex);
|
||||
|
||||
app.mount('#app');
|
||||
Vendored
+38
-30
@@ -1,11 +1,11 @@
|
||||
declare module '*.vue' {
|
||||
import type { ComponentOptions } from 'vue';
|
||||
import type { ComponentOptions } from 'vue';
|
||||
const Component: ComponentOptions;
|
||||
export default Component;
|
||||
}
|
||||
|
||||
declare module '*.md' {
|
||||
import type { ComponentOptions } from 'vue';
|
||||
import type { ComponentOptions } from 'vue';
|
||||
const Component: ComponentOptions;
|
||||
export default Component;
|
||||
}
|
||||
@@ -27,31 +27,34 @@ declare module 'emojilib' {
|
||||
}
|
||||
|
||||
declare module 'unicode-emoji-json' {
|
||||
const emoji: Record<string, {
|
||||
name: string;
|
||||
slug: string;
|
||||
group: string;
|
||||
emoji_version: string;
|
||||
unicode_version: string;
|
||||
skin_tone_support: boolean;
|
||||
skin_tone_support_unicode_version: string;
|
||||
}>;
|
||||
|
||||
const emoji: Record<
|
||||
string,
|
||||
{
|
||||
name: string;
|
||||
slug: string;
|
||||
group: string;
|
||||
emoji_version: string;
|
||||
unicode_version: string;
|
||||
skin_tone_support: boolean;
|
||||
skin_tone_support_unicode_version: string;
|
||||
}
|
||||
>;
|
||||
|
||||
export default emoji;
|
||||
}
|
||||
|
||||
declare module 'pdf-signature-reader' {
|
||||
const verifySignature: (pdf: ArrayBuffer) => ({signatures: SignatureInfo[]});
|
||||
const verifySignature: (pdf: ArrayBuffer) => { signatures: SignatureInfo[] };
|
||||
|
||||
export default verifySignature;
|
||||
}
|
||||
|
||||
declare module 'units-converter' {
|
||||
interface ITo{
|
||||
to(unit: string): { value: number }
|
||||
interface ITo {
|
||||
to(unit: string): { value: number };
|
||||
}
|
||||
interface IFrom{
|
||||
from(unit: string): ITo
|
||||
interface IFrom {
|
||||
from(unit: string): ITo;
|
||||
}
|
||||
export function frequency(value: number): IFrom;
|
||||
export function volumeFlowRate(value: number): IFrom;
|
||||
@@ -64,7 +67,7 @@ interface BigInt {
|
||||
}
|
||||
|
||||
interface JSON {
|
||||
parseBigInt: (jsonStr: string, options?: { minDigits?: number; }) => any;
|
||||
parseBigInt: (jsonStr: string, options?: { minDigits?: number }) => any;
|
||||
parseBigNum: (jsonStr: string) => any;
|
||||
rawJSON(value: string): any;
|
||||
}
|
||||
@@ -74,7 +77,7 @@ interface Navigator {
|
||||
}
|
||||
|
||||
interface FontFaceSet {
|
||||
add(fontFace: FontFace)
|
||||
add(fontFace: FontFace);
|
||||
}
|
||||
|
||||
// TODO remove once https://github.com/microsoft/TypeScript/issues/60608 is resolved
|
||||
@@ -88,8 +91,8 @@ namespace Intl {
|
||||
|
||||
declare module '@vueuse/integrations/useIDBKeyval' {
|
||||
interface Serializer<T> {
|
||||
read: (raw: unknown) => T
|
||||
write: (value: T) => unknown
|
||||
read: (raw: unknown) => T;
|
||||
write: (value: T) => unknown;
|
||||
}
|
||||
export interface UseIDBOptions<T> extends ConfigurableFlush {
|
||||
/**
|
||||
@@ -97,34 +100,34 @@ declare module '@vueuse/integrations/useIDBKeyval' {
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
deep?: boolean
|
||||
deep?: boolean;
|
||||
/**
|
||||
* On error callback
|
||||
*
|
||||
* Default log error to `console.error`
|
||||
*/
|
||||
onError?: (error: unknown) => void
|
||||
onError?: (error: unknown) => void;
|
||||
/**
|
||||
* Use shallow ref as reference
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
shallow?: boolean
|
||||
shallow?: boolean;
|
||||
/**
|
||||
* Write the default value to the storage when it does not exist
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
writeDefaults?: boolean
|
||||
writeDefaults?: boolean;
|
||||
/**
|
||||
* Custom data serialization
|
||||
*/
|
||||
serializer?: Serializer<T>
|
||||
serializer?: Serializer<T>;
|
||||
}
|
||||
export interface UseIDBKeyvalReturn<T> {
|
||||
data: RemovableRef<T>
|
||||
isFinished: ShallowRef<boolean>
|
||||
set: (value: T) => Promise<void>
|
||||
data: RemovableRef<T>;
|
||||
isFinished: ShallowRef<boolean>;
|
||||
set: (value: T) => Promise<void>;
|
||||
}
|
||||
/**
|
||||
*
|
||||
@@ -136,5 +139,10 @@ declare module '@vueuse/integrations/useIDBKeyval' {
|
||||
key: IDBValidKey,
|
||||
initialValue: MaybeRefOrGetter<T>,
|
||||
options?: UseIDBOptions<T>,
|
||||
): UseIDBKeyvalReturn<T>
|
||||
): UseIDBKeyvalReturn<T>;
|
||||
}
|
||||
|
||||
declare module 'vue3-katex' {
|
||||
const Vue3Katex: (app: App, props?: Props, slots?: Slots) => void;
|
||||
export default Vue3Katex;
|
||||
}
|
||||
@@ -2,21 +2,17 @@
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { Ref } from 'vue';
|
||||
import { pipeline } from '@huggingface/transformers';
|
||||
import VueMathjax from 'vue-mathjax-next';
|
||||
import { useScriptTag } from '@vueuse/core';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
useScriptTag('//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-AMS_HTML');
|
||||
|
||||
const ocrInProgress = ref(false);
|
||||
const fileInput = ref() as Ref<File>;
|
||||
const latexResult = computedAsync(async () => {
|
||||
try {
|
||||
return (await ocr(fileInput.value));
|
||||
}
|
||||
catch (e: any) {
|
||||
return await ocr(fileInput.value);
|
||||
} catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
@@ -32,7 +28,7 @@ function toBase64(file: File) {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = () => resolve(reader.result?.toString() ?? '');
|
||||
reader.onerror = error => reject(error);
|
||||
reader.onerror = (error) => reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,14 +46,15 @@ async function ocr(file: File) {
|
||||
const out: TexifyResult = (await pipe(imgBase64, { max_new_tokens: 384 })) as TexifyResult;
|
||||
|
||||
ocrInProgress.value = false;
|
||||
return out.map(t => t.generated_text).join('\n');
|
||||
};
|
||||
return out.map((t) => t.generated_text).join('\n');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-alert type="warning" mb-2>
|
||||
{{ t('tools.math-ocr.texts.tag-nb-processing-is-done-in-your-browser-so-be-patient-processing-can-take-a-while') }}<br>{{ t('tools.math-ocr.texts.tag-this-tool-required-internet-connection-to-access-models') }}
|
||||
{{ t('tools.math-ocr.texts.tag-nb-processing-is-done-in-your-browser-so-be-patient-processing-can-take-a-while')
|
||||
}}<br />{{ t('tools.math-ocr.texts.tag-this-tool-required-internet-connection-to-access-models') }}
|
||||
</c-alert>
|
||||
|
||||
<c-file-upload
|
||||
@@ -73,21 +70,21 @@ async function ocr(file: File) {
|
||||
<TextareaCopyable
|
||||
v-if="!ocrInProgress"
|
||||
v-model:value="latexResult"
|
||||
:word-wrap="true" mb-2
|
||||
:word-wrap="true"
|
||||
mb-2
|
||||
download-file-name="output.tex"
|
||||
/>
|
||||
|
||||
<div style="text-align: center">
|
||||
<VueMathjax
|
||||
<katex-element
|
||||
v-if="!ocrInProgress"
|
||||
:formula="latexResult"
|
||||
:expression="latexResult?.replace(/\$\$$|^\$\$/g, '')"
|
||||
:throw-on-error="false"
|
||||
:strict="false"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<n-spin
|
||||
v-if="ocrInProgress"
|
||||
size="small"
|
||||
/>
|
||||
<n-spin v-if="ocrInProgress" size="small" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in new issue
Block a user