@vmz/plugin-mathjax 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +22 -9
- package/runtime.ts +0 -56
- package/vmz.plugin.ts +0 -50
package/package.json
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@vmz/plugin": "0.3.
|
|
3
|
+
"@vmz/plugin": "0.3.7"
|
|
4
4
|
},
|
|
5
5
|
"description": "VMZ MathJax adapter - <Mathjax> + math engine",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@mathjax/src": "^4.1.3"
|
|
7
|
+
"@mathjax/src": "^4.1.3",
|
|
8
|
+
"@types/node": "^22.15.0",
|
|
9
|
+
"typescript": "^5.8.3"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24.12.0"
|
|
8
13
|
},
|
|
9
14
|
"exports": {
|
|
10
15
|
".": {
|
|
11
|
-
"default": "./vmz.plugin.
|
|
12
|
-
"types": "./vmz.plugin.ts"
|
|
16
|
+
"default": "./dist/vmz.plugin.js",
|
|
17
|
+
"types": "./dist/vmz.plugin.d.ts"
|
|
13
18
|
},
|
|
14
19
|
"./runtime": {
|
|
15
|
-
"default": "./runtime.
|
|
16
|
-
"types": "./runtime.ts"
|
|
20
|
+
"default": "./dist/runtime.js",
|
|
21
|
+
"types": "./dist/runtime.d.ts"
|
|
17
22
|
}
|
|
18
23
|
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"components",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
19
29
|
"keywords": [
|
|
20
30
|
"vmz",
|
|
21
31
|
"plugin",
|
|
@@ -23,7 +33,7 @@
|
|
|
23
33
|
"math"
|
|
24
34
|
],
|
|
25
35
|
"license": "MIT",
|
|
26
|
-
"main": "./vmz.plugin.
|
|
36
|
+
"main": "./dist/vmz.plugin.js",
|
|
27
37
|
"name": "@vmz/plugin-mathjax",
|
|
28
38
|
"peerDependencies": {
|
|
29
39
|
"@mathjax/src": ">=4"
|
|
@@ -41,7 +51,10 @@
|
|
|
41
51
|
"type": "git",
|
|
42
52
|
"url": "git+https://github.com/doki-land/vmz-framework.git"
|
|
43
53
|
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc -p tsconfig.json"
|
|
56
|
+
},
|
|
44
57
|
"type": "module",
|
|
45
|
-
"types": "./vmz.plugin.ts",
|
|
46
|
-
"version": "0.3.
|
|
58
|
+
"types": "./dist/vmz.plugin.d.ts",
|
|
59
|
+
"version": "0.3.7"
|
|
47
60
|
}
|
package/runtime.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MathJax TeX -> SVG helper (MathJax v4 / `@mathjax/src`).
|
|
3
|
-
* Prefer KaTeX for common docs; MathJax for heavier TeX coverage.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
type TexConvert = (tex: string, display: boolean) => string;
|
|
7
|
-
|
|
8
|
-
let tex2svg: TexConvert | null = null;
|
|
9
|
-
|
|
10
|
-
const EM = 16;
|
|
11
|
-
const EX = 8;
|
|
12
|
-
|
|
13
|
-
async function getConvert(): Promise<TexConvert> {
|
|
14
|
-
if (tex2svg) return tex2svg;
|
|
15
|
-
|
|
16
|
-
const { mathjax } = await import('@mathjax/src/js/mathjax.js');
|
|
17
|
-
const { TeX } = await import('@mathjax/src/js/input/tex.js');
|
|
18
|
-
const { SVG } = await import('@mathjax/src/js/output/svg.js');
|
|
19
|
-
const { liteAdaptor } = await import('@mathjax/src/js/adaptors/liteAdaptor.js');
|
|
20
|
-
const { RegisterHTMLHandler } = await import('@mathjax/src/js/handlers/html.js');
|
|
21
|
-
await import('@mathjax/src/js/util/asyncLoad/esm.js');
|
|
22
|
-
await import('@mathjax/src/js/input/tex/base/BaseConfiguration.js');
|
|
23
|
-
await import('@mathjax/src/js/input/tex/ams/AmsConfiguration.js');
|
|
24
|
-
|
|
25
|
-
const adaptor = liteAdaptor({ fontSize: EM });
|
|
26
|
-
RegisterHTMLHandler(adaptor);
|
|
27
|
-
|
|
28
|
-
const html = mathjax.document('', {
|
|
29
|
-
InputJax: new TeX({ packages: ['base', 'ams'] }),
|
|
30
|
-
OutputJax: new SVG({ fontCache: 'none', exFactor: EX / EM }),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
tex2svg = (tex, display) => {
|
|
34
|
-
const node = html.convert(tex ?? '', {
|
|
35
|
-
display: !!display,
|
|
36
|
-
em: EM,
|
|
37
|
-
ex: EX,
|
|
38
|
-
containerWidth: 80 * EM,
|
|
39
|
-
});
|
|
40
|
-
return adaptor.outerHTML(node);
|
|
41
|
-
};
|
|
42
|
-
return tex2svg;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function renderMathjax(tex: string, display = false): Promise<string> {
|
|
46
|
-
const convert = await getConvert();
|
|
47
|
-
return convert(tex, display);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function renderMathjaxFallback(tex: string): string {
|
|
51
|
-
const escaped = String(tex ?? '')
|
|
52
|
-
.replace(/&/g, '&')
|
|
53
|
-
.replace(/</g, '<')
|
|
54
|
-
.replace(/>/g, '>');
|
|
55
|
-
return `<span class="mathjax-fallback">${escaped}</span>`;
|
|
56
|
-
}
|
package/vmz.plugin.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { definePlugin, loadPluginSource } from '@vmz/plugin';
|
|
2
|
-
|
|
3
|
-
const source = loadPluginSource(import.meta.url, 'components/Mathjax.vmz');
|
|
4
|
-
|
|
5
|
-
export default definePlugin({
|
|
6
|
-
name: '@vmz/plugin-mathjax',
|
|
7
|
-
version: '0.1.0',
|
|
8
|
-
protocol: '0.1.0',
|
|
9
|
-
stages: ['workspace_resolve', 'analyzer'],
|
|
10
|
-
deterministic: true,
|
|
11
|
-
async contribute(ctx) {
|
|
12
|
-
if (ctx.stage === 'workspace_resolve') {
|
|
13
|
-
return {
|
|
14
|
-
stage: 'workspace_resolve',
|
|
15
|
-
cacheKey: `@vmz/plugin-mathjax:Mathjax.vmz:${source.contentHash.slice(0, 12)}`,
|
|
16
|
-
items: [
|
|
17
|
-
{
|
|
18
|
-
id: 'component-mathjax',
|
|
19
|
-
kind: 'source',
|
|
20
|
-
path: 'src/components/Mathjax.vmz',
|
|
21
|
-
content: source.content,
|
|
22
|
-
contentHash: source.contentHash,
|
|
23
|
-
materialize: true,
|
|
24
|
-
engine: 'mathjax',
|
|
25
|
-
engineKind: 'math',
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
if (ctx.stage === 'analyzer') {
|
|
31
|
-
return {
|
|
32
|
-
stage: 'analyzer',
|
|
33
|
-
cacheKey: '@vmz/plugin-mathjax:analyzer',
|
|
34
|
-
items: [
|
|
35
|
-
{
|
|
36
|
-
id: 'engine-mathjax',
|
|
37
|
-
kind: 'analyzer',
|
|
38
|
-
path: 'src/components/Mathjax.vmz',
|
|
39
|
-
severity: 'advice',
|
|
40
|
-
message: 'math engine mathjax online',
|
|
41
|
-
code: 'vmz.engine.mathjax',
|
|
42
|
-
engine: 'mathjax',
|
|
43
|
-
engineKind: 'math',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return { stage: ctx.stage, items: [] };
|
|
49
|
-
},
|
|
50
|
-
});
|