@r4ai/typst-ast-node 0.0.0 → 0.1.1

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 ADDED
@@ -0,0 +1,118 @@
1
+ # typst-ast
2
+
3
+ A WebAssembly library that parses [Typst](https://typst.app/) source code and returns its AST as a JSON-serializable object. Built with Rust and [`typst-syntax`](https://crates.io/crates/typst-syntax), distributed as npm packages via `wasm-pack`.
4
+
5
+ ## Packages
6
+
7
+ | Package | Target |
8
+ | ---------------------------------------------------------------------------- | ------------- |
9
+ | [`@r4ai/typst-ast-web`](https://www.npmjs.com/package/@r4ai/typst-ast-web) | Web (ESM, Browser) |
10
+ | [`@r4ai/typst-ast-node`](https://www.npmjs.com/package/@r4ai/typst-ast-node) | Node.js |
11
+
12
+ ## Usage
13
+
14
+ ### Browser
15
+
16
+ ```ts
17
+ import init, { parse } from "@r4ai/typst-ast-web";
18
+
19
+ await init();
20
+
21
+ const result = parse("= Hello\n\nThis is *typst*.", { mode: "markup" });
22
+ console.log(result);
23
+ // {
24
+ // root: { kind: "Markup", range: [0, 26], text: null, children: [...] },
25
+ // errors: []
26
+ // }
27
+ ```
28
+
29
+ ### Node.js
30
+
31
+ ```ts
32
+ import { parse } from "@r4ai/typst-ast-node";
33
+
34
+ const result = parse("#let x = 1 + 2", { mode: "code" });
35
+ console.log(result);
36
+ ```
37
+
38
+ ### API
39
+
40
+ #### `parse(text, options?)`
41
+
42
+ Parses Typst source text and returns the AST.
43
+
44
+ **Parameters**
45
+
46
+ - `text: string` — Typst source code to parse
47
+ - `options.mode?: "markup" | "code" | "math"` — Parse mode (default: `"markup"`)
48
+
49
+ **Return value**
50
+
51
+ ```ts
52
+ type ParseResult = {
53
+ root: Node;
54
+ errors: ParseError[];
55
+ };
56
+
57
+ type Node = {
58
+ kind: string; // SyntaxKind variant name (e.g. "Markup", "Heading", "Strong")
59
+ range: [number, number]; // [start, end] byte offsets
60
+ text: string | null; // leaf node text, null for inner nodes
61
+ children: Node[];
62
+ };
63
+
64
+ type ParseError = {
65
+ message: string;
66
+ range: [number, number];
67
+ };
68
+ ```
69
+
70
+ ## Development
71
+
72
+ ### Prerequisites
73
+
74
+ - Rust (stable) with `wasm32-unknown-unknown` target
75
+ - Node.js 24
76
+ - pnpm 10
77
+ - [`wasm-pack`](https://rustwasm.github.io/wasm-pack/)
78
+
79
+ ### Commands
80
+
81
+ ```sh
82
+ # Install Node.js and pnpm via mise
83
+ mise install
84
+
85
+ # Install JS dependencies
86
+ pnpm install
87
+
88
+ # Build WASM packages (outputs to dist/web and dist/node)
89
+ pnpm run build:lib
90
+
91
+ # Lint
92
+ cargo fmt --check
93
+ cargo clippy -- -D warnings
94
+ pnpm run check
95
+ ```
96
+
97
+ ### Release
98
+
99
+ ```sh
100
+ # Bump version and create a release commit + tag
101
+ bash scripts/release.sh 1.2.3
102
+ ```
103
+
104
+ ## Examples
105
+
106
+ ### React app
107
+
108
+ A React-based example app is located at [`examples/app`](./examples/app).
109
+
110
+ ```sh
111
+ cd examples/app
112
+ pnpm install
113
+ pnpm dev
114
+ ```
115
+
116
+ ## License
117
+
118
+ MIT
package/package.json CHANGED
@@ -3,8 +3,12 @@
3
3
  "collaborators": [
4
4
  "r4ai"
5
5
  ],
6
- "version": "0.0.0",
6
+ "version": "0.1.1",
7
7
  "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/r4ai/typst-ast"
11
+ },
8
12
  "files": [
9
13
  "typst_ast_bg.wasm",
10
14
  "typst_ast.js",
package/typst_ast_bg.wasm CHANGED
Binary file