@vedivad/typst-web-service 0.9.3 → 0.10.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.
Files changed (2) hide show
  1. package/README.md +19 -14
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # @vedivad/typst-web-service
2
2
 
3
- Editor-agnostic Typst services for the web — compile, render, analyze, and format via WASM.
3
+ Editor-agnostic Typst services for the web — compile, render, analyze, and
4
+ format via WASM.
4
5
 
5
- Four independent classes, each created via async `create()` factory methods. Import only what you need.
6
+ Four independent classes. Import only what you need.
7
+
8
+ `TypstCompiler.create()` and `TypstAnalyzer.create()` are async because they
9
+ initialize worker-backed WASM services up front. `TypstRenderer.create()` and
10
+ `TypstFormatter.create()` are sync wrappers; their WASM work is awaited by
11
+ methods like `renderSvgPages()` and `format()`.
6
12
 
7
13
  ## Install
8
14
 
@@ -18,19 +24,19 @@ npm install @vedivad/typst-web-service
18
24
  import { TypstCompiler, TypstRenderer } from "@vedivad/typst-web-service";
19
25
 
20
26
  const compiler = await TypstCompiler.create();
21
- const renderer = await TypstRenderer.create();
27
+ const renderer = TypstRenderer.create();
22
28
 
23
29
  // Populate the VFS, then compile
24
30
  await compiler.setText("/main.typ", "= Hello, Typst");
25
- const result = await compiler.compile();
26
- if (result.vector) {
27
- const pages = await renderer.renderSvgPages(result.vector);
31
+ const firstResult = await compiler.compile();
32
+ if (firstResult.vector) {
33
+ const pages = await renderer.renderSvgPages(firstResult.vector);
28
34
  document.querySelector("#preview")!.innerHTML = pages
29
35
  .map((page) => `<div class="page">${page.svg}</div>`)
30
36
  .join("");
31
37
  }
32
38
 
33
- // result.diagnostics are returned in deterministic order
39
+ // firstResult.diagnostics are returned in deterministic order
34
40
  // (path, start position, end position, message)
35
41
 
36
42
  // Multi-file
@@ -38,7 +44,7 @@ await compiler.setMany({
38
44
  "/main.typ": '#import "template.typ": greet\n#greet("World")',
39
45
  "/template.typ": "#let greet(name) = [Hello, #name!]",
40
46
  });
41
- const result = await compiler.compile();
47
+ const multiFileResult = await compiler.compile();
42
48
 
43
49
  // PDF export — operates on the same VFS state
44
50
  const pdf = await compiler.compilePdf();
@@ -54,7 +60,7 @@ Requires a bundler that supports WASM imports (e.g. Vite + `vite-plugin-wasm`).
54
60
  ```ts
55
61
  import { TypstFormatter } from "@vedivad/typst-web-service";
56
62
 
57
- const formatter = await TypstFormatter.create({ tab_spaces: 2, max_width: 80 });
63
+ const formatter = TypstFormatter.create({ tab_spaces: 2, max_width: 80 });
58
64
  const formatted = await formatter.format(source);
59
65
  const rangeResult = await formatter.formatRange(source, start, end);
60
66
  ```
@@ -83,14 +89,13 @@ const analyzer = await TypstAnalyzer.create({ wasmUrl: tinymistWasmUrl });
83
89
  await analyzer.didChange("untitled:project/main.typ", source);
84
90
  const completions = await analyzer.completion(
85
91
  "untitled:project/main.typ",
86
- line,
87
- character,
92
+ source,
93
+ { line, character },
88
94
  );
89
- const hover = await analyzer.hover(
90
- "untitled:project/main.typ",
95
+ const hover = await analyzer.hover("untitled:project/main.typ", source, {
91
96
  line,
92
97
  character,
93
- );
98
+ });
94
99
 
95
100
  analyzer.destroy();
96
101
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vedivad/typst-web-service",
3
- "version": "0.9.3",
3
+ "version": "0.10.1",
4
4
  "description": "Editor-agnostic Typst compilation service running in a Web Worker",
5
5
  "license": "MIT",
6
6
  "repository": {