@vmz/plugin-katex 0.0.1 → 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,37 @@
1
1
  # @vmz/plugin-katex
2
2
 
3
- Placeholder package (0.0.1). Reserved for the VMZ project.
3
+ ## Fast mathematical typesetting for VMZ documents and products
4
+
5
+ `@vmz/plugin-katex` brings KaTeX into VMZ for applications that need clear, high-quality formulas without making
6
+ mathematics a heavy client-side feature. It is the default choice for most technical documentation, educational content,
7
+ dashboards, and product UI that renders common TeX notation.
8
+
9
+ ## Why choose KaTeX
10
+
11
+ KaTeX prioritizes speed and compact output. That makes it well suited to VMZ's SSR-first and progressive-interaction
12
+ direction: formulas can be part of the readable page rather than a reason to delay content behind a large browser
13
+ dependency.
14
+
15
+ Choose this plugin when your content uses mainstream TeX and you value predictable, lightweight rendering. Choose
16
+ `@vmz/plugin-mathjax` instead when the breadth of TeX compatibility matters more than payload and execution cost.
17
+
18
+ | Choose KaTeX when... | Choose MathJax when... |
19
+ |--------------------------------------------------------|--------------------------------------------------------|
20
+ | Fast, common formula rendering is the priority | Advanced TeX compatibility is the priority |
21
+ | Documentation and product pages need a lighter default | The mathematical surface is central and more demanding |
22
+
23
+ ## VMZ boundary
24
+
25
+ KaTeX supplies typesetting. VMZ still owns application compilation, document structure, server rendering, testing, and
26
+ deployment. Using formulas should not create a separate rendering or state model inside the application.
27
+
28
+ ## Where it shines ✨
29
+
30
+ - API references that include mathematical notation.
31
+ - Educational products with many short formulas.
32
+ - Technical articles that must remain readable in SSR output.
33
+ - Dashboards and scientific tools where formulas support, rather than dominate, the interface.
34
+
35
+ KaTeX keeps the common path simple: polished mathematics without turning an otherwise lightweight page into a
36
+ mathematics runtime. Start here when you are unsure; move to MathJax when a real content requirement exceeds its
37
+ coverage.
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <div class="katex-host" html={format(tex, display)}></div>
3
+ </template>
4
+
5
+ <script client>
6
+ import katex from 'katex';
7
+
8
+ function format(tex, display) {
9
+ try {
10
+ return katex.renderToString(tex ?? '', {
11
+ displayMode: !!display,
12
+ throwOnError: false,
13
+ });
14
+ } catch {
15
+ return '';
16
+ }
17
+ }
18
+
19
+ export default class Katex {
20
+ public tex: string = '';
21
+ public display: boolean = false;
22
+ }
23
+ </script>
package/package.json CHANGED
@@ -1,12 +1,41 @@
1
1
  {
2
2
  "name": "@vmz/plugin-katex",
3
- "version": "0.0.1",
4
- "description": "VMZ placeholder 鈥?not for production use.",
3
+ "version": "0.0.3",
4
+ "type": "module",
5
+ "description": "VMZ KaTeX adapter - <Katex> + math engine registration",
5
6
  "license": "MIT",
6
- "private": false,
7
- "files": [
8
- "README.md"
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
+ "katex": ">=0.16"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "katex": {
27
+ "optional": false
28
+ }
29
+ },
30
+ "keywords": [
31
+ "vmz",
32
+ "plugin",
33
+ "katex",
34
+ "math"
9
35
  ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
10
39
  "repository": {
11
40
  "type": "git",
12
41
  "url": "git+https://github.com/doki-land/vmz-framework.git"
package/runtime.ts ADDED
@@ -0,0 +1,10 @@
1
+ /** Optional helpers for apps that want KaTeX outside the materialized component. */
2
+
3
+ export async function renderKatex(tex: string, display = false): Promise<string> {
4
+ const mod = await import('katex');
5
+ const katex = mod.default ?? mod;
6
+ return katex.renderToString(tex ?? '', {
7
+ displayMode: !!display,
8
+ throwOnError: false,
9
+ });
10
+ }
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/Katex.vmz');
4
+
5
+ export default definePlugin({
6
+ name: '@vmz/plugin-katex',
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-katex:Katex.vmz:${source.contentHash.slice(0, 12)}`,
16
+ items: [
17
+ {
18
+ id: 'component-katex',
19
+ kind: 'source',
20
+ path: 'src/components/Katex.vmz',
21
+ content: source.content,
22
+ contentHash: source.contentHash,
23
+ materialize: true,
24
+ engine: 'katex',
25
+ engineKind: 'math',
26
+ },
27
+ ],
28
+ };
29
+ }
30
+ if (ctx.stage === 'analyzer') {
31
+ return {
32
+ stage: 'analyzer',
33
+ cacheKey: '@vmz/plugin-katex:analyzer',
34
+ items: [
35
+ {
36
+ id: 'engine-katex',
37
+ kind: 'analyzer',
38
+ path: 'src/components/Katex.vmz',
39
+ severity: 'advice',
40
+ message: 'math engine katex online',
41
+ code: 'vmz.engine.katex',
42
+ engine: 'katex',
43
+ engineKind: 'math',
44
+ },
45
+ ],
46
+ };
47
+ }
48
+ return { stage: ctx.stage, items: [] };
49
+ },
50
+ });