Merge branch 'feat/math-converter' into chore/all-my-stuffs

# Conflicts:
#	package.json
#	pnpm-lock.yaml
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 21:02:12 +01:00
commit c03fe5ac5b
5 files changed
+113 -2

No files matched your search

+1
View File
@@ -45,6 +45,7 @@
"@regexper/render": "^1.0.0",
"@kenjiuno/decompressrtf": "^0.1.4",
"@kenjiuno/msgreader": "^1.22.0",
"@plurimath/plurimath": "^0.2.0",
"@sindresorhus/slugify": "^2.2.1",
"@tabler/icons-vue": "^3.20.0",
"@tiptap/pm": "2.1.6",
+8 -1
View File
@@ -29,6 +29,9 @@ dependencies:
'@kenjiuno/msgreader':
specifier: ^1.22.0
version: 1.22.0
'@plurimath/plurimath':
specifier: ^0.2.0
version: 0.2.0
'@regexper/render':
specifier: ^1.0.0
version: 1.0.0
@@ -3101,6 +3104,10 @@ packages:
fsevents: 2.3.2
dev: true
/@plurimath/plurimath@0.2.0:
resolution: {integrity: sha512-5ca7O58sq/PHA7zZHDjDrg8pr1u9FPRNWOy8nqADKrExw9LHAwHX2FuvU3sz51liNZpwZ1KC5Nwy5U48S6Y5Xw==}
dev: false
/@polka/url@1.0.0-next.21:
resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==}
dev: true
@@ -4976,7 +4983,7 @@ packages:
/@vueuse/shared@10.0.0(vue@3.3.4):
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
dependencies:
vue-demi: 0.14.10(vue@3.3.4)
vue-demi: 0.14.5(vue@3.3.4)
transitivePeerDependencies:
- '@vue/composition-api'
- vue
+7 -1
View File
@@ -26,6 +26,7 @@ import { tool as jsonSizeAnalyzer } from './json-size-analyzer';
import { tool as jsonToCsharp } from './json-to-csharp';
import { tool as luhnValidator } from './luhn-validator';
import { tool as maliciousLinksTester } from './malicious-links-tester';
import { tool as mathFormatsConverter } from './math-formats-converter';
import { tool as cssXpathConverter } from './css-xpath-converter';
import { tool as cssSelectorsMemo } from './css-selectors-memo';
@@ -290,7 +291,12 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Math',
components: [mathEvaluator, etaCalculator, percentageCalculator],
components: [
mathEvaluator,
etaCalculator,
percentageCalculator,
mathFormatsConverter,
],
},
{
name: 'Measurement',
+12
View File
@@ -0,0 +1,12 @@
import { EqualNot } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Math Formats Converter',
path: '/math-formats-converter',
description: 'Convert mathematical expression between formats',
keywords: ['math', 'formats', 'converter', 'latex', 'mathml', 'asciimath', 'omml', 'html'],
component: () => import('./math-formats-converter.vue'),
icon: EqualNot,
createdAt: new Date('2024-05-11'),
});
@@ -0,0 +1,85 @@
<script setup lang="ts">
import Plurimath from '@plurimath/plurimath';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const formats = [
{ value: 'asciimath', label: 'AsciiMath' },
{ value: 'latex', label: 'Latex' },
{ value: 'mathml', label: 'MathML' },
{ value: 'html', label: 'Html' },
{ value: 'omml', label: 'OOML' },
];
const source = ref('');
const sourceFormat = useQueryParamOrStorage({ name: 'src', storageName: 'math-fmts-conv:src', defaultValue: 'latex' });
const targetFormat = useQueryParamOrStorage({ name: 'target', storageName: 'math-fmts-conv:target', defaultValue: 'mathml' });
const target = computedAsync(async () => {
const sourceValue = source.value;
const sourceFormatValue = sourceFormat.value;
const targetFormatValue = targetFormat.value;
if (sourceValue === '') {
return '';
}
if (sourceFormatValue === targetFormatValue) {
return sourceValue;
}
return new Promise<string>((resolve, _reject) => {
try {
const formula = new Plurimath(sourceValue, sourceFormatValue);
let result;
switch (targetFormatValue) {
case 'asciimath':
result = formula.toAsciimath();
break;
case 'latex':
result = formula.toLatex();
break;
case 'mathml':
result = formula.toMathml();
break;
case 'html':
result = formula.toHtml();
break;
case 'omml':
result = formula.toOmml();
break;
default:
result = '# unknown format';
break;
}
resolve(result);
}
catch (e: any) {
resolve(`# error converting formula: ${e.toString()}`);
}
});
});
</script>
<template>
<div>
<c-input-text
v-model:value="source"
multiline
placeholder="Put your math expression here..."
rows="5"
label="Mathematical expression to convert"
raw-text
mb-5
/>
<c-select
v-model:value="sourceFormat"
:options="formats"
placeholder="Source format"
/>
<n-divider />
<c-select
v-model:value="targetFormat"
:options="formats"
placeholder="Source format"
/>
<textarea-copyable v-if="target !== ''" :value="target" :language="targetFormat" />
</div>
</template>