@vedivad/typst-web-service 0.7.12 → 0.8.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/README.md +5 -6
- package/dist/analyzer-worker.js +45 -33
- package/dist/analyzer-worker.js.map +1 -1
- package/dist/index.d.ts +125 -111
- package/dist/index.js +239 -233
- package/dist/index.js.map +1 -1
- package/dist/worker.js +28 -15
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
/** LSP Diagnostic as returned by tinymist. */
|
|
2
|
-
interface LspDiagnostic {
|
|
3
|
-
range: {
|
|
4
|
-
start: {
|
|
5
|
-
line: number;
|
|
6
|
-
character: number;
|
|
7
|
-
};
|
|
8
|
-
end: {
|
|
9
|
-
line: number;
|
|
10
|
-
character: number;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
severity?: number;
|
|
14
|
-
message: string;
|
|
15
|
-
source?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type DiagnosticsListener = (uri: string, diagnostics: LspDiagnostic[]) => void;
|
|
19
1
|
interface TypstAnalyzerOptions {
|
|
20
2
|
/**
|
|
21
3
|
* Explicit Worker instance. When omitted, an inlined blob worker is created automatically.
|
|
@@ -31,106 +13,53 @@ interface TypstAnalyzerOptions {
|
|
|
31
13
|
}
|
|
32
14
|
/**
|
|
33
15
|
* Manages a tinymist language server in a Web Worker. Provides LSP-based
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* Diagnostics are push-based: call `didChange()` to notify the analyzer of
|
|
37
|
-
* content changes, and receive diagnostics via `onDiagnostics()` listeners
|
|
38
|
-
* whenever tinymist publishes them.
|
|
16
|
+
* completion and hover for Typst documents.
|
|
39
17
|
*
|
|
40
18
|
* const analyzer = await TypstAnalyzer.create({ wasmUrl: '...' });
|
|
41
|
-
* analyzer.onDiagnostics((uri, diags) => { ... });
|
|
42
19
|
*/
|
|
43
20
|
declare class TypstAnalyzer {
|
|
44
21
|
private readonly proxy;
|
|
45
22
|
private readonly worker;
|
|
46
23
|
private versionCounter;
|
|
47
24
|
private openedUris;
|
|
48
|
-
private diagnosticsListeners;
|
|
49
25
|
private constructor();
|
|
50
26
|
static create(options: TypstAnalyzerOptions): Promise<TypstAnalyzer>;
|
|
51
|
-
/**
|
|
52
|
-
* Register a listener for push-based diagnostics.
|
|
53
|
-
* Returns an unsubscribe function.
|
|
54
|
-
*/
|
|
55
|
-
onDiagnostics(listener: DiagnosticsListener): () => void;
|
|
56
27
|
didOpen(uri: string, content: string): Promise<void>;
|
|
57
28
|
didClose(uri: string): Promise<void>;
|
|
58
29
|
/**
|
|
59
30
|
* Notify the analyzer that a document has changed.
|
|
60
|
-
* Diagnostics will arrive asynchronously via `onDiagnostics()` listeners.
|
|
61
31
|
*/
|
|
62
32
|
didChange(uri: string, content: string): Promise<void>;
|
|
63
|
-
completion(uri: string, line: number, character: number): Promise<unknown>;
|
|
64
|
-
hover(uri: string, line: number, character: number): Promise<unknown>;
|
|
65
|
-
destroy(): void;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type DiagnosticsSubscriber = (diagnostics: LspDiagnostic[]) => void;
|
|
69
|
-
interface AnalyzerSessionOptions {
|
|
70
|
-
analyzer: Pick<TypstAnalyzer, "didOpen" | "didChange" | "completion" | "hover" | "onDiagnostics">;
|
|
71
|
-
/** Project root used to build stable in-memory analyzer URIs. Default: "/project". */
|
|
72
|
-
rootPath?: string;
|
|
73
|
-
/** Entry file path within the project. Synced last to ensure dependencies load first. Default: "/main.typ". */
|
|
74
|
-
entryPath?: string;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Synchronizes an in-memory Typst project with a TypstAnalyzer.
|
|
78
|
-
* Handles multi-file ordering, request queueing, and diagnostic subscriptions.
|
|
79
|
-
*
|
|
80
|
-
* Diagnostics arrive via the analyzer's push mechanism and are forwarded
|
|
81
|
-
* to subscribers registered with `subscribe()`.
|
|
82
|
-
*
|
|
83
|
-
* const session = new AnalyzerSession({ analyzer });
|
|
84
|
-
* session.subscribe("/main.typ", (diags) => { ... });
|
|
85
|
-
* await session.sync("/main.typ", files);
|
|
86
|
-
*/
|
|
87
|
-
declare class AnalyzerSession {
|
|
88
|
-
private readonly analyzer;
|
|
89
|
-
private readonly rootPath;
|
|
90
|
-
private readonly entryPath;
|
|
91
|
-
private readonly syncedFiles;
|
|
92
|
-
private queue;
|
|
93
|
-
private readonly listenersByUri;
|
|
94
|
-
/** Last push received per URI. Replayed on subscribe() so tab-back shows correct diagnostics instantly. */
|
|
95
|
-
private readonly diagnosticsCache;
|
|
96
|
-
private readonly unsubscribeAnalyzer;
|
|
97
|
-
constructor(options: AnalyzerSessionOptions);
|
|
98
|
-
/** Build a tinymist URI from a project-relative path. */
|
|
99
|
-
toUri(path: string): string;
|
|
100
33
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
34
|
+
* Batch document changes. Splits inputs into opens (first-time URIs) and
|
|
35
|
+
* changes (already-open URIs) and sends them in a single worker roundtrip.
|
|
103
36
|
*/
|
|
104
|
-
|
|
37
|
+
didChangeMany(docs: Record<string, string>): Promise<void>;
|
|
105
38
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* If the active file's content hasn't changed since the last sync, a
|
|
110
|
-
* lightweight hover is triggered to ensure the analyzer re-analyzes with
|
|
111
|
-
* the current project state and publishes fresh diagnostics.
|
|
39
|
+
* Batch document closes. Filters to currently-open URIs and sends the set
|
|
40
|
+
* in a single worker roundtrip.
|
|
112
41
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* Returns the raw LSP CompletionList/CompletionItem[] from tinymist.
|
|
117
|
-
*/
|
|
118
|
-
completion(path: string, files: Record<string, string>, line: number, character: number): Promise<unknown>;
|
|
119
|
-
/**
|
|
120
|
-
* Sync files and request hover info at the given position.
|
|
121
|
-
* Returns the raw LSP Hover result from tinymist.
|
|
122
|
-
*/
|
|
123
|
-
hover(path: string, files: Record<string, string>, line: number, character: number): Promise<unknown>;
|
|
42
|
+
didCloseMany(uris: string[]): Promise<void>;
|
|
43
|
+
completion(uri: string, line: number, character: number): Promise<unknown>;
|
|
44
|
+
hover(uri: string, line: number, character: number): Promise<unknown>;
|
|
124
45
|
destroy(): void;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** LSP Diagnostic as returned by tinymist. */
|
|
49
|
+
interface LspDiagnostic {
|
|
50
|
+
range: {
|
|
51
|
+
start: {
|
|
52
|
+
line: number;
|
|
53
|
+
character: number;
|
|
54
|
+
};
|
|
55
|
+
end: {
|
|
56
|
+
line: number;
|
|
57
|
+
character: number;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
severity?: number;
|
|
61
|
+
message: string;
|
|
62
|
+
source?: string;
|
|
134
63
|
}
|
|
135
64
|
|
|
136
65
|
declare function normalizeUntitledUri(uri: string): string;
|
|
@@ -196,25 +125,30 @@ declare class TypstCompiler {
|
|
|
196
125
|
lastVector?: Uint8Array;
|
|
197
126
|
private constructor();
|
|
198
127
|
static create(options?: TypstCompilerOptions): Promise<TypstCompiler>;
|
|
199
|
-
/** Compile a single source string (treated as /main.typ) or a map of files. */
|
|
200
|
-
compile(source: string | Record<string, string>): Promise<CompileResult>;
|
|
201
|
-
/** Compile to PDF from a single source string (treated as /main.typ) or a map of files. */
|
|
202
|
-
compilePdf(source: string | Record<string, string>): Promise<Uint8Array>;
|
|
203
|
-
/** Add or overwrite a text source file. */
|
|
204
|
-
addSource(path: string, source: string): Promise<void>;
|
|
205
|
-
/** Add or overwrite an in-memory shadow file (text or binary). */
|
|
206
|
-
mapShadow(path: string, content: Uint8Array): Promise<void>;
|
|
207
|
-
/** Remove an in-memory shadow file by path. */
|
|
208
|
-
unmapShadow(path: string): Promise<void>;
|
|
209
128
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
129
|
+
* Compile. Pass a source string (written to the entry path) or a map of
|
|
130
|
+
* files to register before compiling; omit to compile whatever is currently
|
|
131
|
+
* in the VFS (populated via setText/setBinary/setJson/setMany).
|
|
132
|
+
* Defaults to compiling "/main.typ"; override with `entry`.
|
|
133
|
+
*/
|
|
134
|
+
compile(source?: string | Record<string, string>, entry?: string): Promise<CompileResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Compile to PDF. Pass a source string (written to the entry path) or a map
|
|
137
|
+
* of files to register before compiling; omit to compile whatever is
|
|
138
|
+
* currently in the VFS (populated via setText/setBinary/setJson/setMany).
|
|
139
|
+
* Defaults to compiling "/main.typ"; override with `entry`.
|
|
212
140
|
*/
|
|
213
|
-
|
|
141
|
+
compilePdf(source?: string | Record<string, string>, entry?: string): Promise<Uint8Array>;
|
|
214
142
|
/** Add or overwrite a text file in the virtual compiler filesystem. */
|
|
215
143
|
setText(path: string, source: string): Promise<void>;
|
|
216
144
|
/** Add or overwrite a JSON file in the virtual compiler filesystem. */
|
|
217
145
|
setJson(path: string, value: unknown, replacer?: (this: unknown, key: string, value: unknown) => unknown, space?: string | number): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Add or overwrite multiple files in the virtual compiler filesystem in a
|
|
148
|
+
* single worker roundtrip. Strings are UTF-8 encoded; Uint8Arrays are passed
|
|
149
|
+
* through.
|
|
150
|
+
*/
|
|
151
|
+
setMany(files: Record<string, string | Uint8Array>): Promise<void>;
|
|
218
152
|
/** Add or overwrite a binary file in the virtual compiler filesystem. */
|
|
219
153
|
setBinary(path: string, content: ArrayBuffer | ArrayBufferView): Promise<void>;
|
|
220
154
|
/** Remove a file from the virtual compiler filesystem. */
|
|
@@ -266,6 +200,86 @@ declare class TypstFormatter {
|
|
|
266
200
|
formatRange(source: string, start: number, end: number): Promise<FormatRangeResult>;
|
|
267
201
|
}
|
|
268
202
|
|
|
203
|
+
interface TypstProjectOptions {
|
|
204
|
+
compiler: TypstCompiler;
|
|
205
|
+
/**
|
|
206
|
+
* Optional analyzer. When provided, text file operations also sync with the
|
|
207
|
+
* analyzer so completions / hover reflect the current state.
|
|
208
|
+
*/
|
|
209
|
+
analyzer?: TypstAnalyzer;
|
|
210
|
+
/** Default entry file path. Default: "/main.typ". */
|
|
211
|
+
entry?: string;
|
|
212
|
+
/**
|
|
213
|
+
* Project root used to build stable analyzer URIs. Default: "/project".
|
|
214
|
+
* URIs are formed as `untitled:<root-without-leading-slash><path>` — so
|
|
215
|
+
* `/main.typ` becomes `untitled:project/main.typ`.
|
|
216
|
+
*/
|
|
217
|
+
rootPath?: string;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Coordinates a compiler + analyzer pair for multi-file Typst projects.
|
|
221
|
+
*
|
|
222
|
+
* Owns the project's virtual filesystem state. Editors push incremental
|
|
223
|
+
* `setText` updates as the user types; the project mirrors those edits to
|
|
224
|
+
* both the compiler's shadow VFS and the analyzer's open-document set, then
|
|
225
|
+
* compiles or services LSP requests against the current state.
|
|
226
|
+
*
|
|
227
|
+
* const project = new TypstProject({ compiler, analyzer });
|
|
228
|
+
* await project.setMany({ "/main.typ": "...", "/utils.typ": "..." });
|
|
229
|
+
* const result = await project.compile();
|
|
230
|
+
*/
|
|
231
|
+
declare class TypstProject {
|
|
232
|
+
private readonly compiler;
|
|
233
|
+
private readonly analyzer?;
|
|
234
|
+
private readonly rootPath;
|
|
235
|
+
private readonly trackedTextPaths;
|
|
236
|
+
/** Last content written via setText/setMany, per path. Used to skip redundant writes to compiler + analyzer. */
|
|
237
|
+
private readonly lastSyncedContent;
|
|
238
|
+
private _entry;
|
|
239
|
+
constructor(options: TypstProjectOptions);
|
|
240
|
+
/** Current entry file path. */
|
|
241
|
+
get entry(): string;
|
|
242
|
+
/** Whether an analyzer is attached. */
|
|
243
|
+
get hasAnalyzer(): boolean;
|
|
244
|
+
/** Change the sticky entry file used by subsequent compile() calls. */
|
|
245
|
+
setEntry(path: string): void;
|
|
246
|
+
/**
|
|
247
|
+
* Add or overwrite a text file. Goes to the compiler's VFS and, when an
|
|
248
|
+
* analyzer is attached, to the analyzer as a document change. Redundant
|
|
249
|
+
* calls with unchanged content are skipped.
|
|
250
|
+
*/
|
|
251
|
+
setText(path: string, content: string): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Add or overwrite a JSON file. Compiler-only — the analyzer does not track
|
|
254
|
+
* data files.
|
|
255
|
+
*/
|
|
256
|
+
setJson(path: string, value: unknown): Promise<void>;
|
|
257
|
+
/** Add or overwrite a binary file. Compiler-only. */
|
|
258
|
+
setBinary(path: string, content: ArrayBuffer | ArrayBufferView): Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Batch set multiple files. Strings route to both compiler and analyzer;
|
|
261
|
+
* Uint8Array entries go to the compiler only.
|
|
262
|
+
*/
|
|
263
|
+
setMany(files: Record<string, string | Uint8Array>): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* Remove a file. Always removed from the compiler's VFS; also closed on the
|
|
266
|
+
* analyzer when it was previously tracked as text.
|
|
267
|
+
*/
|
|
268
|
+
remove(path: string): Promise<void>;
|
|
269
|
+
/** Clear all files from both compiler VFS and analyzer document set. */
|
|
270
|
+
clear(): Promise<void>;
|
|
271
|
+
/** Compile the current VFS state using the sticky entry. */
|
|
272
|
+
compile(): Promise<CompileResult>;
|
|
273
|
+
/** Compile the current VFS state to PDF using the sticky entry. */
|
|
274
|
+
compilePdf(): Promise<Uint8Array>;
|
|
275
|
+
private requireAnalyzer;
|
|
276
|
+
/** Request completions at the given position. Throws when no analyzer is attached. */
|
|
277
|
+
completion(path: string, line: number, character: number): Promise<unknown>;
|
|
278
|
+
/** Request hover info at the given position. Throws when no analyzer is attached. */
|
|
279
|
+
hover(path: string, line: number, character: number): Promise<unknown>;
|
|
280
|
+
private toUri;
|
|
281
|
+
}
|
|
282
|
+
|
|
269
283
|
interface TypstRendererOptions {
|
|
270
284
|
/** URL to the typst-ts-renderer WASM binary. Defaults to jsDelivr CDN. */
|
|
271
285
|
wasmUrl?: string;
|
|
@@ -291,4 +305,4 @@ declare class TypstRenderer {
|
|
|
291
305
|
renderSvg(vector: Uint8Array): Promise<string>;
|
|
292
306
|
}
|
|
293
307
|
|
|
294
|
-
export {
|
|
308
|
+
export { type CompileResult, type DiagnosticMessage, type DiagnosticRange, type FormatConfig, type FormatRangeResult, type LspDiagnostic, TypstAnalyzer, type TypstAnalyzerOptions, TypstCompiler, type TypstCompilerOptions, TypstFormatter, TypstProject, type TypstProjectOptions, TypstRenderer, normalizePath, normalizeRoot, normalizeUntitledUri };
|