@vmz/plugin-mathjax 0.0.0 → 0.0.3

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/README.md CHANGED
@@ -1,3 +1,32 @@
1
1
  # @vmz/plugin-mathjax
2
2
 
3
- Placeholder package (0.0.0). Reserved for the VMZ project.
3
+ ## Broad TeX support when mathematics is the product
4
+
5
+ `@vmz/plugin-mathjax` connects MathJax to VMZ for applications whose mathematical content needs deeper TeX coverage,
6
+ richer notation, or compatibility with existing scholarly material.
7
+
8
+ ## The tradeoff
9
+
10
+ MathJax is the capability-first choice. It can handle cases that a lightweight typesetter may not, but it carries a
11
+ higher cost than KaTeX. For a documentation-heavy or formula-intensive product, that trade can be exactly right. For
12
+ common formulas on performance-sensitive pages, `@vmz/plugin-katex` is usually the better default.
13
+
14
+ VMZ keeps that choice explicit. The formula engine changes the presentation capability, not the application's state,
15
+ server, route, or deployment semantics. SSR and progressive interaction remain part of the VMZ application plan.
16
+
17
+ Think of MathJax as the right specialist tool when formula fidelity is worth a heavier delivery budget. 📐
18
+
19
+ ## Where it earns its weight
20
+
21
+ - Scholarly material imported from established TeX sources.
22
+ - Products where advanced notation is central to the experience.
23
+ - Documentation that cannot accept a smaller supported syntax surface.
24
+ - Mathematical publishing that depends on the broader MathJax ecosystem.
25
+
26
+ | Product priority | Better starting point |
27
+ |------------------------------------------------|-----------------------|
28
+ | Fast common formulas and compact delivery | KaTeX |
29
+ | Broad TeX compatibility and specialist content | MathJax |
30
+
31
+ The choice remains local to mathematical presentation. It does not force a different VMZ routing, state, testing, or
32
+ deployment model.
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <div class="mathjax-host" html={html != null ? html : fallback(tex)}></div>
3
+ </template>
4
+
5
+ <script client>
6
+ import { renderMathjax, renderMathjaxFallback } from '@vmz/plugin-mathjax/runtime';
7
+
8
+ function fallback(tex) {
9
+ return renderMathjaxFallback(tex);
10
+ }
11
+
12
+ export default class Mathjax {
13
+ public tex: string = '';
14
+ public display: boolean = false;
15
+ html: string | null = null;
16
+
17
+ async onMount() {
18
+ try {
19
+ this.html = await renderMathjax(this.tex, this.display);
20
+ } catch {
21
+ this.html = renderMathjaxFallback(this.tex);
22
+ }
23
+ }
24
+ }
25
+ </script>
package/package.json CHANGED
@@ -1,10 +1,38 @@
1
1
  {
2
2
  "name": "@vmz/plugin-mathjax",
3
- "version": "0.0.0",
4
- "description": "VMZ placeholder — not for production use.",
3
+ "version": "0.0.3",
4
+ "type": "module",
5
+ "description": "VMZ MathJax adapter - <Mathjax> + math engine",
5
6
  "license": "MIT",
6
- "private": false,
7
- "files": [
8
- "README.md"
9
- ]
7
+ "main": "./vmz.plugin.ts",
8
+ "types": "./vmz.plugin.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./vmz.plugin.ts",
12
+ "default": "./vmz.plugin.ts"
13
+ },
14
+ "./runtime": {
15
+ "types": "./runtime.ts",
16
+ "default": "./runtime.ts"
17
+ }
18
+ },
19
+ "dependencies": {
20
+ "@vmz/plugin": "0.0.3"
21
+ },
22
+ "peerDependencies": {
23
+ "mathjax-full": ">=3"
24
+ },
25
+ "keywords": [
26
+ "vmz",
27
+ "plugin",
28
+ "mathjax",
29
+ "math"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/doki-land/vmz-framework.git"
37
+ }
10
38
  }
package/runtime.ts ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * MathJax TeX → HTML/SVG helper.
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
+ async function getConvert(): Promise<TexConvert> {
11
+ if (tex2svg) return tex2svg;
12
+ const { mathjax } = await import('mathjax-full/js/mathjax.js');
13
+ const { TeX } = await import('mathjax-full/js/input/tex.js');
14
+ const { SVG } = await import('mathjax-full/js/output/svg.js');
15
+ const { liteAdaptor } = await import('mathjax-full/js/adaptors/liteAdaptor.js');
16
+ const { RegisterHTMLHandler } = await import('mathjax-full/js/handlers/html.js');
17
+ const adaptor = liteAdaptor();
18
+ RegisterHTMLHandler(adaptor);
19
+ const html = mathjax.document('', {
20
+ InputJax: new TeX({ packages: ['base', 'ams'] }),
21
+ OutputJax: new SVG({ fontCache: 'none' }),
22
+ });
23
+ tex2svg = (tex, display) => {
24
+ const node = html.convert(tex ?? '', { display: !!display });
25
+ return adaptor.outerHTML(node);
26
+ };
27
+ return tex2svg;
28
+ }
29
+
30
+ export async function renderMathjax(tex: string, display = false): Promise<string> {
31
+ const convert = await getConvert();
32
+ return convert(tex, display);
33
+ }
34
+
35
+ export function renderMathjaxFallback(tex: string): string {
36
+ const escaped = String(tex ?? '')
37
+ .replace(/&/g, '&amp;')
38
+ .replace(/</g, '&lt;')
39
+ .replace(/>/g, '&gt;');
40
+ return `<span class="mathjax-fallback">${escaped}</span>`;
41
+ }
package/vmz.plugin.ts ADDED
@@ -0,0 +1,50 @@
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
+ });