Compare commits

..
Author SHA1 Message Date
sharevb 6fbff77e92 feat(new tool): Math OCR to Latex
FIx #1009
2024-09-01 22:12:31 +02:00
15 changed files with 691 additions and 463 deletions

No files matched your search

-5
View File
@@ -121,7 +121,6 @@ declare module '@vue/runtime-core' {
LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default']
MacAddressGenerator: typeof import('./src/tools/mac-address-generator/mac-address-generator.vue')['default']
MacAddressLookup: typeof import('./src/tools/mac-address-lookup/mac-address-lookup.vue')['default']
MarkdownToHtml: typeof import('./src/tools/markdown-to-html/markdown-to-html.vue')['default']
MathEvaluator: typeof import('./src/tools/math-evaluator/math-evaluator.vue')['default']
MenuBar: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar.vue')['default']
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
@@ -130,10 +129,8 @@ declare module '@vue/runtime-core' {
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NButton: typeof import('naive-ui')['NButton']
NCode: typeof import('naive-ui')['NCode']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NForm: typeof import('naive-ui')['NForm']
@@ -141,7 +138,6 @@ declare module '@vue/runtime-core' {
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NImage: typeof import('naive-ui')['NImage']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
@@ -156,7 +152,6 @@ declare module '@vue/runtime-core' {
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
QrCodeDecoder: typeof import('./src/tools/qr-code-decoder/qr-code-decoder.vue')['default']
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default']
+2 -4
View File
@@ -35,13 +35,13 @@
"release": "node ./scripts/release.mjs"
},
"dependencies": {
"@huggingface/transformers": "3.0.0-alpha.14",
"@it-tools/bip39": "^0.0.4",
"@it-tools/oggen": "^1.3.0",
"@sindresorhus/slugify": "^2.2.1",
"@tiptap/pm": "2.1.6",
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/markdown-it": "^13.0.7",
"@types/figlet": "^1.5.8",
"@vicons/material": "^0.12.0",
"@vicons/tabler": "^0.12.0",
@@ -67,12 +67,10 @@
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"js-base64": "^3.7.6",
"ical.js": "^2.0.1",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.10.28",
"lodash": "^4.17.21",
"markdown-it": "^14.0.0",
"marked": "^10.0.0",
"mathjs": "^11.9.1",
"mime-types": "^2.1.35",
@@ -85,7 +83,6 @@
"pinia": "^2.0.34",
"plausible-tracker": "^0.3.8",
"qrcode": "^1.5.1",
"qrcode-parser": "^2.1.3",
"sql-formatter": "^13.0.0",
"ua-parser-js": "^1.0.35",
"ulid": "^2.3.0",
@@ -94,6 +91,7 @@
"uuid": "^9.0.0",
"vue": "^3.3.4",
"vue-i18n": "^9.9.1",
"vue-mathjax-next": "^0.0.6",
"vue-router": "^4.1.6",
"vue-tsc": "^1.8.1",
"xml-formatter": "^3.3.2",
+569 -72
View File
File diff suppressed because it is too large. Load diff
-2
View File
@@ -7,7 +7,6 @@ import sqlHljs from 'highlight.js/lib/languages/sql';
import xmlHljs from 'highlight.js/lib/languages/xml';
import yamlHljs from 'highlight.js/lib/languages/yaml';
import iniHljs from 'highlight.js/lib/languages/ini';
import markdownHljs from 'highlight.js/lib/languages/markdown';
import { useCopy } from '@/composable/copy';
const props = withDefaults(
@@ -31,7 +30,6 @@ hljs.registerLanguage('html', xmlHljs);
hljs.registerLanguage('xml', xmlHljs);
hljs.registerLanguage('yaml', yamlHljs);
hljs.registerLanguage('toml', iniHljs);
hljs.registerLanguage('markdown', markdownHljs);
const { value, language, followHeightOf, copyPlacement, copyMessage } = toRefs(props);
const { height } = followHeightOf.value ? useElementSize(followHeightOf) : { height: ref(null) };
+8 -11
View File
@@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as mathOcr } from './math-ocr';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
@@ -9,8 +10,6 @@ import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as xmlToJson } from './xml-to-json';
import { tool as jsonToXml } from './json-to-xml';
import { tool as qrCodeDecoder } from './qr-code-decoder';
import { tool as markdownToHtml } from './markdown-to-html';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -114,7 +113,6 @@ export const toolsByCategory: ToolCategory[] = [
tomlToYaml,
xmlToJson,
jsonToXml,
markdownToHtml,
],
},
{
@@ -140,13 +138,7 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Images and videos',
components: [
qrCodeGenerator,
wifiQrCodeGenerator,
qrCodeDecoder,
svgPlaceholderGenerator,
cameraRecorder,
],
components: [qrCodeGenerator, wifiQrCodeGenerator, svgPlaceholderGenerator, cameraRecorder],
},
{
name: 'Development',
@@ -171,7 +163,12 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Math',
components: [mathEvaluator, etaCalculator, percentageCalculator],
components: [
mathEvaluator,
etaCalculator,
percentageCalculator,
mathOcr,
],
},
{
name: 'Measurement',
-12
View File
@@ -1,12 +0,0 @@
import { Markdown } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Markdown to HTML',
path: '/markdown-to-html',
description: 'Convert Markdown to Html and allow to print (as PDF)',
keywords: ['markdown', 'html', 'converter', 'pdf'],
component: () => import('./markdown-to-html.vue'),
icon: Markdown,
createdAt: new Date('2024-08-25'),
});
@@ -1,44 +0,0 @@
<script setup lang="ts">
import markdownit from 'markdown-it';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const inputMarkdown = ref('');
const outputHtml = computed(() => {
const md = markdownit();
return md.render(inputMarkdown.value);
});
function printHtml() {
const w = window.open();
if (w === null) {
return;
}
w.document.body.innerHTML = outputHtml.value;
w.print();
}
</script>
<template>
<div>
<c-input-text
v-model:value="inputMarkdown"
multiline raw-text
placeholder="Your Markdown content..."
rows="8"
autofocus
label="Your Markdown to convert:"
/>
<n-divider />
<n-form-item label="Output HTML:">
<TextareaCopyable :value="outputHtml" :word-wrap="true" language="html" />
</n-form-item>
<div flex justify-center>
<n-button @click="printHtml">
Print as PDF
</n-button>
</div>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
import { MathSymbols } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Math OCR',
path: '/math-ocr',
description: 'Convert Math Formula images to Latex',
keywords: ['math', 'ocr', 'latex', 'formula', 'image'],
component: () => import('./math-ocr.vue'),
icon: MathSymbols,
createdAt: new Date('2024-08-15'),
});
+97
View File
@@ -0,0 +1,97 @@
<script setup lang="ts">
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';
useScriptTag('https://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 e.toString();
}
});
async function onUpload(file: File) {
if (file) {
fileInput.value = file;
}
}
function toBase64(file: File) {
return new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result?.toString() ?? '');
reader.onerror = error => reject(error);
});
}
type TexifyResult = Array<{ generated_text: string }>;
async function ocr(file: File) {
if (!file) {
return '';
}
ocrInProgress.value = true;
const imgBase64 = await toBase64(file);
const pipe = await pipeline('image-to-text', 'Xenova/texify');
const out: TexifyResult = (await pipe(imgBase64, { max_new_tokens: 384 })) as TexifyResult;
ocrInProgress.value = false;
return out.map(t => t.generated_text).join('\n');
};
</script>
<template>
<div style="max-width: 600px;">
<c-alert type="warning" mb-2>
NB: processing is done in your browser, so be patient, processing can take a while
<br>
This tool required internet connection (to access models)
</c-alert>
<c-file-upload
title="Drag and drop a Image here, or click to select a file"
paste-image
@file-upload="onUpload"
/>
<n-divider />
<div>
<h3>Latex Result</h3>
<TextareaCopyable
v-if="!ocrInProgress"
v-model:value="latexResult"
:word-wrap="true" mb-2
/>
<div style="text-align: center">
<VueMathjax
v-if="!ocrInProgress"
:formula="latexResult"
/>
</div>
<n-spin
v-if="ocrInProgress"
size="small"
/>
</div>
</div>
</template>
<style lang="less" scoped>
::v-deep(.n-upload-trigger) {
width: 100%;
}
</style>
+3
View File
@@ -0,0 +1,3 @@
declare module "vue-mathjax-next" {
}
-3
View File
@@ -1,3 +0,0 @@
declare module "ical.js" {
export function parse(content: string): object;
}
-12
View File
@@ -1,12 +0,0 @@
import { Qrcode } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'QR Code decoder',
path: '/qr-code-decoder',
description: 'QR Code Reader',
keywords: ['qrcode', 'qr-code', 'decoder', 'reader'],
component: () => import('./qr-code-decoder.vue'),
icon: Qrcode,
createdAt: new Date('2024-09-01'),
});
@@ -1,151 +0,0 @@
import { describe, expect, test } from 'vitest';
import { parseQRData } from './qr-code-decoder.service';
describe('qr-code-decoder', () => {
test('parseQRData should parse content correctly', () => {
expect(parseQRData(null)).toEqual({
type: 'Unknown',
value: '',
});
expect(parseQRData('')).toEqual({
type: 'Unknown',
value: '',
});
expect(parseQRData('TEL:+33123456')).toEqual({
type: 'Phone',
value: '+33123456',
});
expect(parseQRData('MATMSG:TO: email@example.com;SUB:email subject;BODY:Email text;;')).toEqual({
type: 'Email',
value: {
body: 'Email text',
subject: 'email subject',
to: 'email@example.com',
},
});
expect(parseQRData('mailto:email@example.com?subject=email subject&body=Email text')).toEqual({
type: 'Email',
value: {
body: 'Email text',
subject: 'email subject',
to: 'email@example.com',
},
});
expect(parseQRData('SMTP:email@example.com:email subject:Email text')).toEqual({
type: 'Email',
value: {
body: 'Email text',
subject: 'email subject',
to: 'email@example.com',
},
});
expect(parseQRData('smsto:+33315555:message')).toEqual({
type: 'SMS',
value: {
message: 'message',
to: '+33315555',
},
});
expect(parseQRData('WIFI:T:nopass;S:ssid;H:true;')).toEqual({
type: 'Wifi',
value: {
authentication: 'nopass',
hidden: 'true',
name: 'ssid',
password: undefined,
},
});
expect(parseQRData('WIFI:T:WPA;S:ssid;P:password;H:false;')).toEqual({
type: 'Wifi',
value: {
authentication: 'WPA',
hidden: 'false',
name: 'ssid',
password: 'password', // NOSONAR
},
});
expect(parseQRData('BEGIN:VCALENDAR\nPRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN\nVERSION:2.0\nBEGIN:VEVENT\nDTSTAMP:19960704T120000Z\nUID:uid1@example.com\nORGANIZER:mailto:jsmith@example.com\nDTSTART:19960918T143000Z\nDTEND:19960920T220000Z\nSTATUS:CONFIRMED\nCATEGORIES:CONFERENCE\nSUMMARY:Networld+Interop Conference\nDESCRIPTION:Networld+Interop Conference\n and Exhibit\\nAtlanta World Congress Center\\n\n Atlanta\\, Georgia\nEND:VEVENT\nEND:VCALENDAR'))
.toEqual({
type: 'iCal',
value: [
'vcalendar',
[
[
'prodid',
{},
'text',
'-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN',
],
[
'version',
{},
'text',
'2.0',
],
],
[
[
'vevent',
[
[
'dtstamp',
{},
'date-time',
'1996-07-04T12:00:00Z',
],
[
'uid',
{},
'text',
'uid1@example.com',
],
[
'organizer',
{},
'cal-address',
'mailto:jsmith@example.com',
],
[
'dtstart',
{},
'date-time',
'1996-09-18T14:30:00Z',
],
[
'dtend',
{},
'date-time',
'1996-09-20T22:00:00Z',
],
[
'status',
{},
'text',
'CONFIRMED',
],
[
'categories',
{},
'text',
'CONFERENCE',
],
[
'summary',
{},
'text',
'Networld+Interop Conference',
],
[
'description',
{},
'text',
'Networld+Interop Conference and Exhibit\nAtlanta World Congress Center\nAtlanta, Georgia',
],
],
[],
],
],
],
});
});
});
@@ -1,83 +0,0 @@
import ICAL from 'ical.js';
export function parseQRData(qrContent: string | null) {
if (!qrContent) {
return { type: 'Unknown', value: '' };
}
if (qrContent.startsWith('BEGIN:VCALENDAR')) {
return { type: 'iCal', value: ICAL.parse(qrContent?.trim()) };
}
if (qrContent.startsWith('TEL:')) {
return { type: 'Phone', value: qrContent.substring(4)?.trim() };
}
if (qrContent.startsWith('MATMSG:')) {
// MATMSG:TO: email@example.com;SUB:email subject;BODY:Email text;;
const parsing = /^MATMSG:(?:TO:([^;]*);)?(?:SUB:([^;]*);)?(?:BODY:([^;]*))?;;$/.exec(qrContent) || [];
return {
type: 'Email',
value: {
to: parsing[1]?.trim(),
subject: parsing[2]?.trim(),
body: parsing[3]?.trim(),
},
};
}
if (qrContent.startsWith('mailto:')) {
// mailto:email@example.com?subject=email subject&body=Email text
const parsing = /^mailto:([^\?]+)\?subject=([^\&]*)(?:&body=(.*))$/.exec(qrContent) || [];
return {
type: 'Email',
value: {
to: parsing[1]?.trim(),
subject: parsing[2]?.trim(),
body: parsing[3]?.trim(),
},
};
}
if (qrContent.startsWith('SMTP:')) {
// SMTP:email@example.com:email subject:Email text
const parsing = /^SMTP:([^:]+)(?::([^:]*))(?::([^:]*))?$/.exec(qrContent) || [];
return {
type: 'Email',
value: {
to: parsing[1]?.trim(),
subject: parsing[2]?.trim(),
body: parsing[3]?.trim(),
},
};
}
if (qrContent.startsWith('smsto:')) {
// smsto:${phoneNumber}:${message}
const parsing = /^smsto:([^:]+)(?::(.+))$/.exec(qrContent) || [];
return {
type: 'SMS',
value: {
to: parsing[1]?.trim(),
message: parsing[2]?.trim(),
},
};
}
if (qrContent.startsWith('WIFI:')) {
// WIFI:T:${authentication};S:${name};${authentication !== 'nopass' ? `P:${password};` : ''}H:${hidden};
const parsing = /^WIFI:T:([^;]+);S:([^;]+);(?:P:([^;]+);)?(?:H:([^;]+);)?$/.exec(qrContent) || [];
return {
type: 'Wifi',
value: {
authentication: parsing[1]?.trim(),
name: parsing[2]?.trim(),
password: parsing[3]?.trim(),
hidden: parsing[4]?.trim(),
},
};
}
if (/^(?:https?|ftp):\/\//.test(qrContent)) {
return {
type: 'Url',
value: qrContent,
};
}
return {
type: 'Text',
value: qrContent,
};
}
@@ -1,64 +0,0 @@
<script setup lang="ts">
import type { Ref } from 'vue';
import qrcodeParser from 'qrcode-parser';
import { parseQRData } from './qr-code-decoder.service';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const fileInput = ref() as Ref<File>;
const qrCode = computedAsync(async () => {
try {
return (await qrcodeParser(fileInput.value));
}
catch (e: any) {
return e.toString();
}
});
const qrCodeParsed = computed(() => {
try {
const parsed = parseQRData(qrCode.value);
return `Type: ${parsed.type}\nValue:${JSON.stringify(parsed.value, null, 2)}`;
}
catch (e: any) {
return e.toString();
}
});
async function onUpload(file: File) {
if (file) {
fileInput.value = file;
}
}
</script>
<template>
<div>
<c-file-upload
title="Drag and drop a QR Code here, or click to select a file"
:paste-image="true"
@file-upload="onUpload"
/>
<n-divider />
<div>
<h3>Decoded</h3>
<TextareaCopyable
:value="qrCode"
:word-wrap="true"
/>
</div>
<div>
<h3>Parsed</h3>
<TextareaCopyable
:value="qrCodeParsed"
:word-wrap="true"
/>
</div>
</div>
</template>
<style lang="less" scoped>
::v-deep(.n-upload-trigger) {
width: 100%;
}
</style>