@vutex/wetex 0.0.0-stage → 0.0.0

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 CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
+ "dependencies": {
3
+ "@vutex/vutex-unknown-wasm32": "0.0.0"
4
+ },
5
+ "description": "WeTeX: VuTeX formula rendering for browser and Node (Rust/WASM)",
6
+ "devDependencies": {
7
+ "@types/node": "^22.13.10",
8
+ "tsx": "^4.19.3",
9
+ "typescript": "^5.8.3"
10
+ },
11
+ "engines": {
12
+ "node": ">=20"
13
+ },
14
+ "exports": {
15
+ ".": "./src/index.ts",
16
+ "./wasm": "./src/wasm/index.ts"
17
+ },
18
+ "files": [
19
+ "readme.md",
20
+ "src"
21
+ ],
22
+ "license": "MPL-2.0",
2
23
  "name": "@vutex/wetex",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "test": "tsx --test tests/smoke.test.ts",
29
+ "typecheck": "tsc --noEmit"
30
+ },
31
+ "type": "module",
32
+ "version": "0.0.0"
33
+ }
package/readme.md ADDED
@@ -0,0 +1,13 @@
1
+ # @vutex/wetex
2
+
3
+ **WeTeX** exports VuTeX formula rendering to JavaScript hosts through WASM.
4
+
5
+ ```ts
6
+ import { loadWeTeX, renderSvg } from "@vutex/wetex";
7
+
8
+ const wetex = await loadWeTeX();
9
+ const result = renderSvg(wetex, "x^2 + y^2 = z^2");
10
+ console.log(result.svg);
11
+ ```
12
+
13
+ Standalone **web** package: only `@vutex/vutex-unknown-wasm32` + thin TypeScript over `wetex-wasm`. Does **not** depend on `@vutex/vutex`.
package/src/index.ts ADDED
@@ -0,0 +1,96 @@
1
+ import { loadWeTeX } from "./wasm/load.js";
2
+ import type { FormulaRender, RenderOptions, WeTeXBindings, WeTeXWasmOptions } from "./types.js";
3
+
4
+ export type {
5
+ DisplayMode,
6
+ FormulaDiagnostic,
7
+ FormulaMetrics,
8
+ FormulaRender,
9
+ RenderOptions,
10
+ WeTeXBindings,
11
+ WeTeXWasmOptions,
12
+ } from "./types.js";
13
+
14
+ export { loadWeTeX } from "./wasm/index.js";
15
+
16
+ let defaultBindings: WeTeXBindings | undefined;
17
+
18
+ async function bindings(options?: WeTeXWasmOptions): Promise<WeTeXBindings> {
19
+ if (!defaultBindings) {
20
+ defaultBindings = await loadWeTeX(options);
21
+ }
22
+ return defaultBindings;
23
+ }
24
+
25
+ /** Measure formula metrics through the default WASM binding. */
26
+ export async function measure(
27
+ source: string,
28
+ options?: RenderOptions,
29
+ wasmOptions?: WeTeXWasmOptions,
30
+ ): Promise<FormulaRender> {
31
+ const wetex = await bindings(wasmOptions);
32
+ return wetex.measureFormula(source, options);
33
+ }
34
+
35
+ /** Render a formula to SVG through the default WASM binding. */
36
+ export async function renderSvg(
37
+ source: string,
38
+ options?: RenderOptions,
39
+ wasmOptions?: WeTeXWasmOptions,
40
+ ): Promise<FormulaRender> {
41
+ const wetex = await bindings(wasmOptions);
42
+ return wetex.renderSvg(source, options);
43
+ }
44
+
45
+ /** Render a formula to MathML through the default WASM binding. */
46
+ export async function renderMathml(
47
+ source: string,
48
+ options?: RenderOptions,
49
+ wasmOptions?: WeTeXWasmOptions,
50
+ ): Promise<FormulaRender> {
51
+ const wetex = await bindings(wasmOptions);
52
+ return wetex.renderMathml(source, options);
53
+ }
54
+
55
+ /** Render a formula with SVG and MathML through the default WASM binding. */
56
+ export async function render(
57
+ source: string,
58
+ options?: RenderOptions,
59
+ wasmOptions?: WeTeXWasmOptions,
60
+ ): Promise<FormulaRender> {
61
+ const wetex = await bindings(wasmOptions);
62
+ return wetex.renderFormula(source, options);
63
+ }
64
+
65
+ /** Convenience helpers when bindings are already loaded. */
66
+ export function measureWith(
67
+ wetex: WeTeXBindings,
68
+ source: string,
69
+ options?: RenderOptions,
70
+ ): FormulaRender {
71
+ return wetex.measureFormula(source, options);
72
+ }
73
+
74
+ export function renderSvgWith(
75
+ wetex: WeTeXBindings,
76
+ source: string,
77
+ options?: RenderOptions,
78
+ ): FormulaRender {
79
+ return wetex.renderSvg(source, options);
80
+ }
81
+
82
+ export function renderMathmlWith(
83
+ wetex: WeTeXBindings,
84
+ source: string,
85
+ options?: RenderOptions,
86
+ ): FormulaRender {
87
+ return wetex.renderMathml(source, options);
88
+ }
89
+
90
+ export function renderWith(
91
+ wetex: WeTeXBindings,
92
+ source: string,
93
+ options?: RenderOptions,
94
+ ): FormulaRender {
95
+ return wetex.renderFormula(source, options);
96
+ }
package/src/types.ts ADDED
@@ -0,0 +1,39 @@
1
+ export type DisplayMode = "inline" | "block";
2
+
3
+ export type RenderOptions = {
4
+ displayMode?: DisplayMode;
5
+ };
6
+
7
+ export type FormulaMetrics = {
8
+ width: number;
9
+ height: number;
10
+ depth: number;
11
+ baseline: number;
12
+ };
13
+
14
+ export type FormulaDiagnostic = {
15
+ code: string;
16
+ severity: "info" | "warning" | "error";
17
+ message: string;
18
+ start?: number;
19
+ end?: number;
20
+ };
21
+
22
+ export type FormulaRender = {
23
+ metrics: FormulaMetrics;
24
+ svg: string;
25
+ mathml?: string;
26
+ diagnostics: FormulaDiagnostic[];
27
+ };
28
+
29
+ export type WeTeXWasmOptions = {
30
+ url?: string | URL;
31
+ };
32
+
33
+ export type WeTeXBindings = {
34
+ wetexVersion: () => string;
35
+ measureFormula: (source: string, options?: RenderOptions) => FormulaRender;
36
+ renderSvg: (source: string, options?: RenderOptions) => FormulaRender;
37
+ renderMathml: (source: string, options?: RenderOptions) => FormulaRender;
38
+ renderFormula: (source: string, options?: RenderOptions) => FormulaRender;
39
+ };
@@ -0,0 +1 @@
1
+ export { loadWeTeX } from "./load.js";
@@ -0,0 +1,48 @@
1
+ import type { FormulaRender, RenderOptions, WeTeXBindings, WeTeXWasmOptions } from "../types.js";
2
+
3
+ const ARTIFACT_PACKAGE = "@vutex/vutex-unknown-wasm32";
4
+
5
+ type WasmBinding = {
6
+ default: (input?: { module_or_path?: string | URL }) => Promise<unknown>;
7
+ wetexVersion: () => string;
8
+ measureFormula: (source: string, optionsJson?: string) => string;
9
+ renderSvg: (source: string, optionsJson?: string) => string;
10
+ renderMathml: (source: string, optionsJson?: string) => string;
11
+ renderFormula: (source: string, optionsJson?: string) => string;
12
+ };
13
+
14
+ function encodeOptions(options?: RenderOptions): string | undefined {
15
+ if (!options) {
16
+ return undefined;
17
+ }
18
+ return JSON.stringify(options);
19
+ }
20
+
21
+ function decodeResult(raw: string): FormulaRender {
22
+ return JSON.parse(raw) as FormulaRender;
23
+ }
24
+
25
+ function wrap(binding: WasmBinding): WeTeXBindings {
26
+ return {
27
+ wetexVersion: () => binding.wetexVersion(),
28
+ measureFormula: (source, options) =>
29
+ decodeResult(binding.measureFormula(source, encodeOptions(options))),
30
+ renderSvg: (source, options) =>
31
+ decodeResult(binding.renderSvg(source, encodeOptions(options))),
32
+ renderMathml: (source, options) =>
33
+ decodeResult(binding.renderMathml(source, encodeOptions(options))),
34
+ renderFormula: (source, options) =>
35
+ decodeResult(binding.renderFormula(source, encodeOptions(options))),
36
+ };
37
+ }
38
+
39
+ /** Load the WASM artifact from `@vutex/vutex-unknown-wasm32`. */
40
+ export async function loadWeTeX(options: WeTeXWasmOptions = {}): Promise<WeTeXBindings> {
41
+ const binding = (await import(ARTIFACT_PACKAGE)) as WasmBinding;
42
+ if (options.url) {
43
+ await binding.default({ module_or_path: options.url });
44
+ } else {
45
+ await binding.default();
46
+ }
47
+ return wrap(binding);
48
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.