@quillmark/wasm 0.68.0 → 0.69.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 +12 -0
- package/bundler/wasm.d.ts +111 -4
- package/bundler/wasm_bg.js +4 -4
- package/bundler/wasm_bg.wasm +0 -0
- package/package.json +7 -10
- package/node-esm/wasm.d.ts +0 -577
- package/node-esm/wasm.js +0 -1577
- package/node-esm/wasm_bg.wasm +0 -0
- package/node-esm/wasm_bg.wasm.d.ts +0 -66
package/node-esm/wasm.d.ts
DELETED
|
@@ -1,577 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Input shape for `Document.pushCard` and `Document.insertCard`.
|
|
6
|
-
*
|
|
7
|
-
* Only `tag` is required. `fields` defaults to `{}`, `body` to `""`.
|
|
8
|
-
*/
|
|
9
|
-
export interface CardInput {
|
|
10
|
-
tag: string;
|
|
11
|
-
fields?: Record<string, unknown>;
|
|
12
|
-
body?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Page dimensions in Typst points (1 pt = 1/72 inch).
|
|
19
|
-
*
|
|
20
|
-
* Report-only: the painter sizes the canvas itself based on
|
|
21
|
-
* `PaintOptions`. `pageSize` is exposed for callers that need page
|
|
22
|
-
* geometry up-front (e.g. to lay out a scrollable list of canvases
|
|
23
|
-
* before any pixels are rendered).
|
|
24
|
-
*/
|
|
25
|
-
export interface PageSize {
|
|
26
|
-
widthPt: number;
|
|
27
|
-
heightPt: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Inputs to `RenderSession.paint`. Both fields are optional and default
|
|
32
|
-
* to `1`.
|
|
33
|
-
*
|
|
34
|
-
* - `layoutScale` — layout-space pixels per Typst point. For on-screen
|
|
35
|
-
* canvases this is CSS pixels per pt; the page's layout-pixel size is
|
|
36
|
-
* `widthPt * layoutScale × heightPt * layoutScale`. The painter
|
|
37
|
-
* surfaces these dimensions as `layoutWidth` / `layoutHeight` so
|
|
38
|
-
* consumers can drive `canvas.style.*` (or any layout system).
|
|
39
|
-
* - `densityScale` — backing-store density multiplier. Fold
|
|
40
|
-
* `window.devicePixelRatio`, in-app zoom, and `visualViewport.scale`
|
|
41
|
-
* (pinch-zoom) into a single value here. Defaults to `1`, which
|
|
42
|
-
* produces a non-retina backing store — pass `window.devicePixelRatio`
|
|
43
|
-
* for crisp output on high-DPI displays.
|
|
44
|
-
*
|
|
45
|
-
* The effective rasterization scale is `layoutScale * densityScale`.
|
|
46
|
-
* Both must be finite and `> 0`. For `OffscreenCanvasRenderingContext2D`
|
|
47
|
-
* the two collapse to a single scalar; folding everything into
|
|
48
|
-
* `densityScale` is the simplest convention.
|
|
49
|
-
*/
|
|
50
|
-
export interface PaintOptions {
|
|
51
|
-
layoutScale?: number;
|
|
52
|
-
densityScale?: number;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Returned by `RenderSession.paint`.
|
|
57
|
-
*
|
|
58
|
-
* - `layoutWidth` / `layoutHeight` — layout-pixel dimensions of the
|
|
59
|
-
* canvas's display box. For on-screen canvases this is CSS pixels:
|
|
60
|
-
* set `canvas.style.width = layoutWidth + "px"` and
|
|
61
|
-
* `canvas.style.height = layoutHeight + "px"` (or feed these into
|
|
62
|
-
* your layout system). Independent of `densityScale`.
|
|
63
|
-
* - `pixelWidth` / `pixelHeight` — integer backing-store pixel
|
|
64
|
-
* dimensions the painter wrote to `canvas.width` / `canvas.height`.
|
|
65
|
-
* Equal to `round(layoutWidth * densityScale)` ×
|
|
66
|
-
* `round(layoutHeight * densityScale)` *unless* the requested backing
|
|
67
|
-
* exceeded the painter's safe maximum (16384 px per side), in which
|
|
68
|
-
* case `densityScale` was clamped to fit. Detect clamping via
|
|
69
|
-
* `pixelWidth < round(layoutWidth * densityScale)`.
|
|
70
|
-
*
|
|
71
|
-
* The painter owns `canvas.width` / `canvas.height`; consumers must not
|
|
72
|
-
* write to them. The painter does **not** touch `canvas.style.*`;
|
|
73
|
-
* consumers own layout.
|
|
74
|
-
*
|
|
75
|
-
* For `OffscreenCanvasRenderingContext2D` (Worker rasterization, no
|
|
76
|
-
* DOM), `layoutWidth` / `layoutHeight` are informational — there's no
|
|
77
|
-
* CSS layout box to apply them to.
|
|
78
|
-
*/
|
|
79
|
-
export interface PaintResult {
|
|
80
|
-
layoutWidth: number;
|
|
81
|
-
layoutHeight: number;
|
|
82
|
-
pixelWidth: number;
|
|
83
|
-
pixelHeight: number;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export interface Artifact {
|
|
88
|
-
format: OutputFormat;
|
|
89
|
-
bytes: Uint8Array;
|
|
90
|
-
mimeType: string;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface Card {
|
|
94
|
-
sentinel: string;
|
|
95
|
-
tag: string;
|
|
96
|
-
frontmatter: Record<string, unknown>;
|
|
97
|
-
frontmatterItems: FrontmatterItem[];
|
|
98
|
-
body: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface Diagnostic {
|
|
102
|
-
severity: Severity;
|
|
103
|
-
code?: string;
|
|
104
|
-
message: string;
|
|
105
|
-
location?: Location;
|
|
106
|
-
hint?: string;
|
|
107
|
-
sourceChain: string[];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface Location {
|
|
111
|
-
file: string;
|
|
112
|
-
line: number;
|
|
113
|
-
column: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface RenderOptions {
|
|
117
|
-
format?: OutputFormat;
|
|
118
|
-
ppi?: number;
|
|
119
|
-
pages?: number[];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface RenderResult {
|
|
123
|
-
artifacts: Artifact[];
|
|
124
|
-
warnings: Diagnostic[];
|
|
125
|
-
outputFormat: OutputFormat;
|
|
126
|
-
renderTimeMs: number;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export type FrontmatterItem = { kind: "field"; key: string; value: unknown; fill?: boolean } | { kind: "comment"; text: string };
|
|
130
|
-
|
|
131
|
-
export type OutputFormat = "pdf" | "svg" | "txt" | "png";
|
|
132
|
-
|
|
133
|
-
export type Severity = "error" | "warning" | "note";
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Typed in-memory Quillmark document.
|
|
138
|
-
*
|
|
139
|
-
* Created via `Document.fromMarkdown(markdown)`. Exposes:
|
|
140
|
-
* - `quillRef` (string)
|
|
141
|
-
* - `frontmatter` (JS object/Record)
|
|
142
|
-
* - `body` (string)
|
|
143
|
-
* - `cards` (array of Card objects)
|
|
144
|
-
* - `warnings` (array of Diagnostic objects)
|
|
145
|
-
*
|
|
146
|
-
* `toMarkdown()` emits canonical Quillmark Markdown that round-trips back to
|
|
147
|
-
* an equal `Document` by value and by type.
|
|
148
|
-
*/
|
|
149
|
-
export class Document {
|
|
150
|
-
private constructor();
|
|
151
|
-
free(): void;
|
|
152
|
-
[Symbol.dispose](): void;
|
|
153
|
-
/**
|
|
154
|
-
* Return a fresh `Document` handle with the same parse state.
|
|
155
|
-
*
|
|
156
|
-
* Mutations on the returned handle do not affect the original and
|
|
157
|
-
* vice versa. Parse-time warnings are snapshotted alongside the
|
|
158
|
-
* document — they describe the original parse, not the edit
|
|
159
|
-
* history of either handle.
|
|
160
|
-
*/
|
|
161
|
-
clone(): Document;
|
|
162
|
-
/**
|
|
163
|
-
* Structural equality against another `Document`.
|
|
164
|
-
*
|
|
165
|
-
* Compares `main` and `cards` by value (matching core's [`PartialEq`]).
|
|
166
|
-
* Parse-time `warnings` are intentionally excluded — they describe the
|
|
167
|
-
* source text, not the document's content.
|
|
168
|
-
*
|
|
169
|
-
* Use this to debounce upstream prop updates: keep the last parsed
|
|
170
|
-
* `Document` and compare instead of re-parsing on every keystroke.
|
|
171
|
-
*/
|
|
172
|
-
equals(other: Document): boolean;
|
|
173
|
-
/**
|
|
174
|
-
* Parse markdown into a typed Document.
|
|
175
|
-
*
|
|
176
|
-
* Returns the document with any parse-time warnings accessible via `.warnings`.
|
|
177
|
-
* Throws on parse errors.
|
|
178
|
-
*/
|
|
179
|
-
static fromMarkdown(markdown: string): Document;
|
|
180
|
-
/**
|
|
181
|
-
* Insert a card at the given index.
|
|
182
|
-
*
|
|
183
|
-
* `index` must be in `0..=cards.length`. Out-of-range throws an `Error`.
|
|
184
|
-
*
|
|
185
|
-
* Mutators never modify `warnings`.
|
|
186
|
-
*/
|
|
187
|
-
insertCard(index: number, card: CardInput): void;
|
|
188
|
-
/**
|
|
189
|
-
* Move the card at `from` to position `to`.
|
|
190
|
-
*
|
|
191
|
-
* `from == to` is a no-op. Both indices must be in `0..cards.length`.
|
|
192
|
-
* Out-of-range throws an `Error`.
|
|
193
|
-
*
|
|
194
|
-
* Mutators never modify `warnings`.
|
|
195
|
-
*/
|
|
196
|
-
moveCard(from: number, to: number): void;
|
|
197
|
-
/**
|
|
198
|
-
* Append a card to the end of the card list.
|
|
199
|
-
*
|
|
200
|
-
* `card` must be a JS object with a `tag` string field and optional
|
|
201
|
-
* `fields` (object) and `body` (string).
|
|
202
|
-
*
|
|
203
|
-
* Throws an `Error` if `card.tag` is not a valid tag name.
|
|
204
|
-
*
|
|
205
|
-
* Mutators never modify `warnings`.
|
|
206
|
-
*/
|
|
207
|
-
pushCard(card: CardInput): void;
|
|
208
|
-
/**
|
|
209
|
-
* Remove the card at `index` and return it, or `undefined` if out of range.
|
|
210
|
-
*
|
|
211
|
-
* Mutators never modify `warnings`.
|
|
212
|
-
*/
|
|
213
|
-
removeCard(index: number): Card | undefined;
|
|
214
|
-
/**
|
|
215
|
-
* Remove a frontmatter field on the card at `index`, returning the
|
|
216
|
-
* removed value or `undefined` if the field was absent.
|
|
217
|
-
*
|
|
218
|
-
* Throws if `index` is out of range, `name` is reserved, or `name` does
|
|
219
|
-
* not match `[a-z_][a-z0-9_]*`.
|
|
220
|
-
*
|
|
221
|
-
* Mutators never modify `warnings`.
|
|
222
|
-
*/
|
|
223
|
-
removeCardField(index: number, name: string): any;
|
|
224
|
-
/**
|
|
225
|
-
* Remove a frontmatter field on the main card, returning the removed value or `undefined`.
|
|
226
|
-
*
|
|
227
|
-
* Throws an `Error` whose message includes the `EditError` variant name
|
|
228
|
-
* and details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`)
|
|
229
|
-
* or does not match `[a-z_][a-z0-9_]*`. Absence of an otherwise-valid
|
|
230
|
-
* name returns `undefined`.
|
|
231
|
-
*
|
|
232
|
-
* Mutators never modify `warnings`.
|
|
233
|
-
*/
|
|
234
|
-
removeField(name: string): any;
|
|
235
|
-
/**
|
|
236
|
-
* Replace the main card's body (the global Markdown body).
|
|
237
|
-
*
|
|
238
|
-
* Mutators never modify `warnings`.
|
|
239
|
-
*/
|
|
240
|
-
replaceBody(body: string): void;
|
|
241
|
-
/**
|
|
242
|
-
* Replace the tag of the composable card at `index`.
|
|
243
|
-
*
|
|
244
|
-
* Mutates only the sentinel — the card's frontmatter and body are
|
|
245
|
-
* untouched. Schema-aware migration (clearing orphan fields, applying
|
|
246
|
-
* new defaults) is the caller's responsibility; `setCardTag` is a
|
|
247
|
-
* structural primitive.
|
|
248
|
-
*
|
|
249
|
-
* Throws if `index` is out of range or if `newTag` does not match
|
|
250
|
-
* `[a-z_][a-z0-9_]*`.
|
|
251
|
-
*
|
|
252
|
-
* Mutators never modify `warnings`.
|
|
253
|
-
*/
|
|
254
|
-
setCardTag(index: number, new_tag: string): void;
|
|
255
|
-
/**
|
|
256
|
-
* Update a frontmatter field on the main card.
|
|
257
|
-
*
|
|
258
|
-
* Convenience method: equivalent to `doc.mainMut().setField(name, value)`.
|
|
259
|
-
* Clears any existing `!fill` marker on the field.
|
|
260
|
-
*
|
|
261
|
-
* Throws an `Error` whose message includes the `EditError` variant name and
|
|
262
|
-
* details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
|
|
263
|
-
* not match `[a-z_][a-z0-9_]*`.
|
|
264
|
-
*
|
|
265
|
-
* Mutators never modify `warnings`.
|
|
266
|
-
*/
|
|
267
|
-
setField(name: string, value: any): void;
|
|
268
|
-
/**
|
|
269
|
-
* Update a frontmatter field on the main card AND mark it as `!fill`.
|
|
270
|
-
*
|
|
271
|
-
* Convenience method: equivalent to `doc.mainMut().setFill(name, value)`.
|
|
272
|
-
*
|
|
273
|
-
* Throws on invalid name (see [`setField`](Document::set_field)).
|
|
274
|
-
*
|
|
275
|
-
* Mutators never modify `warnings`.
|
|
276
|
-
*/
|
|
277
|
-
setFill(name: string, value: any): void;
|
|
278
|
-
/**
|
|
279
|
-
* Replace the QUILL reference string.
|
|
280
|
-
*
|
|
281
|
-
* Throws if `ref_str` is not a valid `QuillReference`.
|
|
282
|
-
*
|
|
283
|
-
* Mutators never modify `warnings`.
|
|
284
|
-
*/
|
|
285
|
-
setQuillRef(ref_str: string): void;
|
|
286
|
-
/**
|
|
287
|
-
* Emit canonical Quillmark Markdown.
|
|
288
|
-
*
|
|
289
|
-
* Returns the document serialised as a Quillmark Markdown string.
|
|
290
|
-
* The output is type-fidelity round-trip safe: re-parsing the result
|
|
291
|
-
* produces a `Document` equal to `self` by value and by type.
|
|
292
|
-
*/
|
|
293
|
-
toMarkdown(): string;
|
|
294
|
-
/**
|
|
295
|
-
* Replace the body of the card at `index`.
|
|
296
|
-
*
|
|
297
|
-
* Throws if `index` is out of range.
|
|
298
|
-
*
|
|
299
|
-
* Mutators never modify `warnings`.
|
|
300
|
-
*/
|
|
301
|
-
updateCardBody(index: number, body: string): void;
|
|
302
|
-
/**
|
|
303
|
-
* Update a field on the card at `index`.
|
|
304
|
-
*
|
|
305
|
-
* Convenience method: equivalent to `doc.card_mut(index)?.set_field(name, value)`.
|
|
306
|
-
*
|
|
307
|
-
* Throws if `index` is out of range, `name` is reserved or invalid, or
|
|
308
|
-
* `value` cannot be serialized.
|
|
309
|
-
*
|
|
310
|
-
* Mutators never modify `warnings`.
|
|
311
|
-
*/
|
|
312
|
-
updateCardField(index: number, name: string, value: any): void;
|
|
313
|
-
/**
|
|
314
|
-
* Number of composable cards (excludes the main card).
|
|
315
|
-
*
|
|
316
|
-
* O(1). Use this to validate indices before calling card mutators
|
|
317
|
-
* instead of allocating the full `cards` array.
|
|
318
|
-
*/
|
|
319
|
-
readonly cardCount: number;
|
|
320
|
-
/**
|
|
321
|
-
* Ordered list of composable card blocks as typed `Card` objects.
|
|
322
|
-
*/
|
|
323
|
-
readonly cards: Card[];
|
|
324
|
-
/**
|
|
325
|
-
* The document's main (entry) card.
|
|
326
|
-
*
|
|
327
|
-
* Carries the QUILL sentinel, the document-level frontmatter, and the
|
|
328
|
-
* global body. Frontmatter/body reads and mutations go through this
|
|
329
|
-
* handle — there are no document-level shortcuts after the rework.
|
|
330
|
-
*
|
|
331
|
-
* Allocates and serializes on each call — cache locally if read in a hot loop.
|
|
332
|
-
*/
|
|
333
|
-
readonly main: Card;
|
|
334
|
-
/**
|
|
335
|
-
* The QUILL reference string (e.g. `"usaf_memo@0.1"`).
|
|
336
|
-
*/
|
|
337
|
-
readonly quillRef: string;
|
|
338
|
-
/**
|
|
339
|
-
* Non-fatal parse-time warnings as an array of typed `Diagnostic` objects.
|
|
340
|
-
*/
|
|
341
|
-
readonly warnings: Diagnostic[];
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Opaque, shareable Quill handle.
|
|
346
|
-
*/
|
|
347
|
-
export class Quill {
|
|
348
|
-
private constructor();
|
|
349
|
-
free(): void;
|
|
350
|
-
[Symbol.dispose](): void;
|
|
351
|
-
/**
|
|
352
|
-
* A blank form for a card of the given type — no document values supplied.
|
|
353
|
-
*
|
|
354
|
-
* Returns `null` if `cardType` is not declared in this quill's schema.
|
|
355
|
-
* Otherwise returns a plain JS object shaped like a single entry in
|
|
356
|
-
* [`Form::cards`].
|
|
357
|
-
*
|
|
358
|
-
* [`Form::cards`]: quillmark::form::Form::cards
|
|
359
|
-
*/
|
|
360
|
-
blankCard(card_type: string): any;
|
|
361
|
-
/**
|
|
362
|
-
* A blank form for the main card — no document values supplied.
|
|
363
|
-
*
|
|
364
|
-
* Returns a plain JS object with the same shape as one entry in
|
|
365
|
-
* [`Form::main`]. Every declared field's `source` is `"default"` (when
|
|
366
|
-
* the schema declares a default) or `"missing"`.
|
|
367
|
-
*
|
|
368
|
-
* [`Form::main`]: quillmark::form::Form::main
|
|
369
|
-
*/
|
|
370
|
-
blankMain(): any;
|
|
371
|
-
/**
|
|
372
|
-
* The schema-aware form view of `doc`.
|
|
373
|
-
*
|
|
374
|
-
* Returns a plain JS object (not a class) that is immediately
|
|
375
|
-
* `JSON.stringify`-able. The shape mirrors [`Form`]:
|
|
376
|
-
*
|
|
377
|
-
* ```json
|
|
378
|
-
* {
|
|
379
|
-
* "main": { "schema": {...}, "values": { "field": {...} } },
|
|
380
|
-
* "cards": [ ... ],
|
|
381
|
-
* "diagnostics": [ ... ]
|
|
382
|
-
* }
|
|
383
|
-
* ```
|
|
384
|
-
*
|
|
385
|
-
* **Snapshot semantics.** This is a read-only snapshot of the document
|
|
386
|
-
* at call time. Subsequent edits to `doc` require calling `form` again.
|
|
387
|
-
*
|
|
388
|
-
* [`Form`]: quillmark::form::Form
|
|
389
|
-
*/
|
|
390
|
-
form(doc: Document): any;
|
|
391
|
-
/**
|
|
392
|
-
* Open an iterative render session for page-selective rendering.
|
|
393
|
-
*/
|
|
394
|
-
open(doc: Document): RenderSession;
|
|
395
|
-
/**
|
|
396
|
-
* Render a document to final artifacts.
|
|
397
|
-
*/
|
|
398
|
-
render(doc: Document, opts?: RenderOptions | null): RenderResult;
|
|
399
|
-
/**
|
|
400
|
-
* The resolved backend identifier (e.g. `"typst"`).
|
|
401
|
-
*/
|
|
402
|
-
readonly backendId: string;
|
|
403
|
-
/**
|
|
404
|
-
* Read-only snapshot of the loaded quill's engine info and declared schema.
|
|
405
|
-
*
|
|
406
|
-
* Returns a plain JS object with:
|
|
407
|
-
* - `schema` — the quill's public schema contract, identical to
|
|
408
|
-
* `QuillConfig::public_schema()`. Top-level keys: `name`, `main`,
|
|
409
|
-
* optional `card_types` (map keyed by card name, omitted when empty),
|
|
410
|
-
* optional `example`. `main` and each card under `card_types` share
|
|
411
|
-
* the same shape: `fields` (map keyed by field name), optional
|
|
412
|
-
* `title`, `description`, `ui`.
|
|
413
|
-
* - `backend`, `version`, `author`, `description` — quill identity
|
|
414
|
-
* declared in `Quill.yaml`'s `quill:` section. `description` describes
|
|
415
|
-
* the quill itself; if the author also declared `main.description` (the
|
|
416
|
-
* schema description of the entry-point card), it lives at
|
|
417
|
-
* `schema.main.description` and is independent.
|
|
418
|
-
* - `supportedFormats` — output formats the backend produces, as
|
|
419
|
-
* lowercase strings.
|
|
420
|
-
* - Any additional unstructured keys declared under `quill:`.
|
|
421
|
-
*
|
|
422
|
-
* Consumers that need validation run their own validator against
|
|
423
|
-
* `metadata.schema`.
|
|
424
|
-
*
|
|
425
|
-
* Equivalent by value for the lifetime of the handle; the quill is
|
|
426
|
-
* immutable once constructed.
|
|
427
|
-
*/
|
|
428
|
-
readonly metadata: any;
|
|
429
|
-
/**
|
|
430
|
-
* Whether this quill's backend supports canvas preview.
|
|
431
|
-
*
|
|
432
|
-
* `true` iff `RenderSession.paint` and `RenderSession.pageSize` will
|
|
433
|
-
* succeed for sessions opened by this quill. Use this as a precondition
|
|
434
|
-
* probe before mounting a canvas-based preview UI; the throw on `paint`
|
|
435
|
-
* remains the enforcement contract.
|
|
436
|
-
*/
|
|
437
|
-
readonly supportsCanvas: boolean;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Quillmark WASM Engine
|
|
442
|
-
*/
|
|
443
|
-
export class Quillmark {
|
|
444
|
-
free(): void;
|
|
445
|
-
[Symbol.dispose](): void;
|
|
446
|
-
/**
|
|
447
|
-
* JavaScript constructor: `new Quillmark()`
|
|
448
|
-
*/
|
|
449
|
-
constructor();
|
|
450
|
-
/**
|
|
451
|
-
* Load a quill from a file tree and attach the appropriate backend.
|
|
452
|
-
*
|
|
453
|
-
* Accepts either a `Map<string, Uint8Array>` or a plain object
|
|
454
|
-
* (`Record<string, Uint8Array>`). Plain objects are walked via
|
|
455
|
-
* `Object.entries` at the boundary; the Rust side sees a single
|
|
456
|
-
* canonical shape.
|
|
457
|
-
*/
|
|
458
|
-
quill(tree: Map<string, Uint8Array>): Quill;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* An iterative render handle backed by an immutable compiled snapshot.
|
|
463
|
-
*
|
|
464
|
-
* Created via [`Quill::open`]. Holds the compiled output so that
|
|
465
|
-
* [`RenderSession::render`], [`RenderSession::paint`], and
|
|
466
|
-
* [`RenderSession::page_size`] can be called repeatedly without
|
|
467
|
-
* recompiling.
|
|
468
|
-
*
|
|
469
|
-
* **Empty documents.** A document that compiles to zero pages still
|
|
470
|
-
* produces a valid session (`pageCount === 0`). Iterating
|
|
471
|
-
* `0..pageCount` is then a no-op; calling `paint(ctx, 0)` or
|
|
472
|
-
* `pageSize(0)` throws `"... page index 0 out of range
|
|
473
|
-
* (pageCount=0)"`. Hosts that surface "no pages to preview" UI should
|
|
474
|
-
* branch on `pageCount === 0` rather than on a thrown error.
|
|
475
|
-
*/
|
|
476
|
-
export class RenderSession {
|
|
477
|
-
private constructor();
|
|
478
|
-
free(): void;
|
|
479
|
-
[Symbol.dispose](): void;
|
|
480
|
-
/**
|
|
481
|
-
* Page dimensions in Typst points (1 pt = 1/72 inch).
|
|
482
|
-
*
|
|
483
|
-
* Report-only: the painter sizes the canvas itself based on
|
|
484
|
-
* `PaintOptions`. Exposed for consumers that need page geometry
|
|
485
|
-
* up-front (e.g. to lay out a scrollable list of canvases before
|
|
486
|
-
* any pixels are rendered).
|
|
487
|
-
*
|
|
488
|
-
* Stable for a given `page` across the session's lifetime — the
|
|
489
|
-
* compiled document is an immutable snapshot, so callers can cache
|
|
490
|
-
* results.
|
|
491
|
-
*
|
|
492
|
-
* Throws if the underlying backend has no canvas painter (i.e. is not
|
|
493
|
-
* the Typst backend) or if `page` is out of range.
|
|
494
|
-
*/
|
|
495
|
-
pageSize(page: number): PageSize;
|
|
496
|
-
/**
|
|
497
|
-
* Paint `page` into a 2D canvas context.
|
|
498
|
-
*
|
|
499
|
-
* Accepts either a `CanvasRenderingContext2D` (main thread) or an
|
|
500
|
-
* `OffscreenCanvasRenderingContext2D` (Worker / off-DOM rasterization).
|
|
501
|
-
* Both dispatch to the same Rust rasterizer; the dispatch happens at
|
|
502
|
-
* the JS boundary so neither context type is privileged.
|
|
503
|
-
*
|
|
504
|
-
* The painter owns `canvas.width` / `canvas.height` and writes them
|
|
505
|
-
* itself; consumers must not. The painter does not touch
|
|
506
|
-
* `canvas.style.*` — that's layout, owned by the consumer (see
|
|
507
|
-
* `PaintResult.layoutWidth` / `layoutHeight`).
|
|
508
|
-
*
|
|
509
|
-
* `opts.layoutScale` (default 1.0) is layout-space pixels per Typst
|
|
510
|
-
* point and determines the canvas's display-box size. `opts.densityScale`
|
|
511
|
-
* (default 1.0) is the rasterization density multiplier the consumer
|
|
512
|
-
* folds `window.devicePixelRatio`, in-app zoom, and
|
|
513
|
-
* `visualViewport.scale` (pinch-zoom) into. The effective
|
|
514
|
-
* rasterization scale is `layoutScale * densityScale`.
|
|
515
|
-
*
|
|
516
|
-
* If `layoutScale * densityScale` would exceed the safe backing-store
|
|
517
|
-
* maximum (16384 px per side), `densityScale` is clamped
|
|
518
|
-
* proportionally so the largest dimension fits. The actual
|
|
519
|
-
* backing-store dimensions are reported in the returned
|
|
520
|
-
* `PaintResult` — compare against
|
|
521
|
-
* `round(layoutWidth * densityScale)` to detect clamping.
|
|
522
|
-
*
|
|
523
|
-
* Each call resets the backing store (`paint` is always a full
|
|
524
|
-
* repaint). Consumers do not need to call `clearRect`.
|
|
525
|
-
*
|
|
526
|
-
* Throws when:
|
|
527
|
-
* - the backend does not support canvas preview (message includes the
|
|
528
|
-
* resolved `backendId`),
|
|
529
|
-
* - `page` is out of range,
|
|
530
|
-
* - `ctx` is neither `CanvasRenderingContext2D` nor
|
|
531
|
-
* `OffscreenCanvasRenderingContext2D`,
|
|
532
|
-
* - `opts.layoutScale` or `opts.densityScale` is non-finite or `<= 0`.
|
|
533
|
-
*/
|
|
534
|
-
paint(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, page: number, opts: PaintOptions | undefined): PaintResult;
|
|
535
|
-
/**
|
|
536
|
-
* Render all or selected pages from this session.
|
|
537
|
-
*/
|
|
538
|
-
render(opts?: RenderOptions | null): RenderResult;
|
|
539
|
-
/**
|
|
540
|
-
* The backend that produced this session (e.g. `"typst"`).
|
|
541
|
-
*
|
|
542
|
-
* Equal to the `backendId` of the [`Quill`] that opened this session
|
|
543
|
-
* (sessions inherit their quill's backend), so checking either is fine.
|
|
544
|
-
*/
|
|
545
|
-
readonly backendId: string;
|
|
546
|
-
/**
|
|
547
|
-
* Number of pages in this render session.
|
|
548
|
-
*
|
|
549
|
-
* Stable for the lifetime of the session — the underlying compiled
|
|
550
|
-
* document is an immutable snapshot.
|
|
551
|
-
*/
|
|
552
|
-
readonly pageCount: number;
|
|
553
|
-
/**
|
|
554
|
-
* Whether this session's backend supports canvas preview.
|
|
555
|
-
*
|
|
556
|
-
* `true` iff [`paint`](Self::paint) and [`page_size`](Self::page_size)
|
|
557
|
-
* will succeed. Equal to `Quill.supportsCanvas` for the quill that
|
|
558
|
-
* opened this session.
|
|
559
|
-
*/
|
|
560
|
-
readonly supportsCanvas: boolean;
|
|
561
|
-
/**
|
|
562
|
-
* Session-level warnings attached at `quill.open(...)` time.
|
|
563
|
-
*
|
|
564
|
-
* Snapshot of any non-fatal diagnostics emitted while opening the
|
|
565
|
-
* session (e.g. version compatibility shims). Stable across the
|
|
566
|
-
* session's lifetime. These are also appended to
|
|
567
|
-
* [`RenderResult.warnings`] on every `render()` call; the accessor
|
|
568
|
-
* surfaces them to canvas-preview consumers that don't go through
|
|
569
|
-
* `render()`.
|
|
570
|
-
*/
|
|
571
|
-
readonly warnings: Diagnostic[];
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Initialize the WASM module with panic hooks for better error messages
|
|
576
|
-
*/
|
|
577
|
-
export function init(): void;
|