@quillmark/wasm 0.67.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.
@@ -1,464 +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
- * Returned by `RenderSession.pageSize`. Use these to size a canvas backing
21
- * store (`widthPt * scale × heightPt * scale`) before calling `paint`.
22
- */
23
- export interface PageSize {
24
- widthPt: number;
25
- heightPt: number;
26
- }
27
-
28
-
29
- export interface Artifact {
30
- format: OutputFormat;
31
- bytes: Uint8Array;
32
- mimeType: string;
33
- }
34
-
35
- export interface Card {
36
- sentinel: string;
37
- tag: string;
38
- frontmatter: Record<string, unknown>;
39
- frontmatterItems: FrontmatterItem[];
40
- body: string;
41
- }
42
-
43
- export interface Diagnostic {
44
- severity: Severity;
45
- code?: string;
46
- message: string;
47
- location?: Location;
48
- hint?: string;
49
- sourceChain: string[];
50
- }
51
-
52
- export interface Location {
53
- file: string;
54
- line: number;
55
- column: number;
56
- }
57
-
58
- export interface RenderOptions {
59
- format?: OutputFormat;
60
- ppi?: number;
61
- pages?: number[];
62
- }
63
-
64
- export interface RenderResult {
65
- artifacts: Artifact[];
66
- warnings: Diagnostic[];
67
- outputFormat: OutputFormat;
68
- renderTimeMs: number;
69
- }
70
-
71
- export type FrontmatterItem = { kind: "field"; key: string; value: unknown; fill?: boolean } | { kind: "comment"; text: string };
72
-
73
- export type OutputFormat = "pdf" | "svg" | "txt" | "png";
74
-
75
- export type Severity = "error" | "warning" | "note";
76
-
77
-
78
- /**
79
- * Typed in-memory Quillmark document.
80
- *
81
- * Created via `Document.fromMarkdown(markdown)`. Exposes:
82
- * - `quillRef` (string)
83
- * - `frontmatter` (JS object/Record)
84
- * - `body` (string)
85
- * - `cards` (array of Card objects)
86
- * - `warnings` (array of Diagnostic objects)
87
- *
88
- * `toMarkdown()` emits canonical Quillmark Markdown that round-trips back to
89
- * an equal `Document` by value and by type.
90
- */
91
- export class Document {
92
- private constructor();
93
- free(): void;
94
- [Symbol.dispose](): void;
95
- /**
96
- * Return a fresh `Document` handle with the same parse state.
97
- *
98
- * Mutations on the returned handle do not affect the original and
99
- * vice versa. Parse-time warnings are snapshotted alongside the
100
- * document — they describe the original parse, not the edit
101
- * history of either handle.
102
- */
103
- clone(): Document;
104
- /**
105
- * Structural equality against another `Document`.
106
- *
107
- * Compares `main` and `cards` by value (matching core's [`PartialEq`]).
108
- * Parse-time `warnings` are intentionally excluded — they describe the
109
- * source text, not the document's content.
110
- *
111
- * Use this to debounce upstream prop updates: keep the last parsed
112
- * `Document` and compare instead of re-parsing on every keystroke.
113
- */
114
- equals(other: Document): boolean;
115
- /**
116
- * Parse markdown into a typed Document.
117
- *
118
- * Returns the document with any parse-time warnings accessible via `.warnings`.
119
- * Throws on parse errors.
120
- */
121
- static fromMarkdown(markdown: string): Document;
122
- /**
123
- * Insert a card at the given index.
124
- *
125
- * `index` must be in `0..=cards.length`. Out-of-range throws an `Error`.
126
- *
127
- * Mutators never modify `warnings`.
128
- */
129
- insertCard(index: number, card: CardInput): void;
130
- /**
131
- * Move the card at `from` to position `to`.
132
- *
133
- * `from == to` is a no-op. Both indices must be in `0..cards.length`.
134
- * Out-of-range throws an `Error`.
135
- *
136
- * Mutators never modify `warnings`.
137
- */
138
- moveCard(from: number, to: number): void;
139
- /**
140
- * Append a card to the end of the card list.
141
- *
142
- * `card` must be a JS object with a `tag` string field and optional
143
- * `fields` (object) and `body` (string).
144
- *
145
- * Throws an `Error` if `card.tag` is not a valid tag name.
146
- *
147
- * Mutators never modify `warnings`.
148
- */
149
- pushCard(card: CardInput): void;
150
- /**
151
- * Remove the card at `index` and return it, or `undefined` if out of range.
152
- *
153
- * Mutators never modify `warnings`.
154
- */
155
- removeCard(index: number): Card | undefined;
156
- /**
157
- * Remove a frontmatter field on the card at `index`, returning the
158
- * removed value or `undefined` if the field was absent.
159
- *
160
- * Throws if `index` is out of range, `name` is reserved, or `name` does
161
- * not match `[a-z_][a-z0-9_]*`.
162
- *
163
- * Mutators never modify `warnings`.
164
- */
165
- removeCardField(index: number, name: string): any;
166
- /**
167
- * Remove a frontmatter field on the main card, returning the removed value or `undefined`.
168
- *
169
- * Throws an `Error` whose message includes the `EditError` variant name
170
- * and details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`)
171
- * or does not match `[a-z_][a-z0-9_]*`. Absence of an otherwise-valid
172
- * name returns `undefined`.
173
- *
174
- * Mutators never modify `warnings`.
175
- */
176
- removeField(name: string): any;
177
- /**
178
- * Replace the main card's body (the global Markdown body).
179
- *
180
- * Mutators never modify `warnings`.
181
- */
182
- replaceBody(body: string): void;
183
- /**
184
- * Replace the tag of the composable card at `index`.
185
- *
186
- * Mutates only the sentinel — the card's frontmatter and body are
187
- * untouched. Schema-aware migration (clearing orphan fields, applying
188
- * new defaults) is the caller's responsibility; `setCardTag` is a
189
- * structural primitive.
190
- *
191
- * Throws if `index` is out of range or if `newTag` does not match
192
- * `[a-z_][a-z0-9_]*`.
193
- *
194
- * Mutators never modify `warnings`.
195
- */
196
- setCardTag(index: number, new_tag: string): void;
197
- /**
198
- * Update a frontmatter field on the main card.
199
- *
200
- * Convenience method: equivalent to `doc.mainMut().setField(name, value)`.
201
- * Clears any existing `!fill` marker on the field.
202
- *
203
- * Throws an `Error` whose message includes the `EditError` variant name and
204
- * details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
205
- * not match `[a-z_][a-z0-9_]*`.
206
- *
207
- * Mutators never modify `warnings`.
208
- */
209
- setField(name: string, value: any): void;
210
- /**
211
- * Update a frontmatter field on the main card AND mark it as `!fill`.
212
- *
213
- * Convenience method: equivalent to `doc.mainMut().setFill(name, value)`.
214
- *
215
- * Throws on invalid name (see [`setField`](Document::set_field)).
216
- *
217
- * Mutators never modify `warnings`.
218
- */
219
- setFill(name: string, value: any): void;
220
- /**
221
- * Replace the QUILL reference string.
222
- *
223
- * Throws if `ref_str` is not a valid `QuillReference`.
224
- *
225
- * Mutators never modify `warnings`.
226
- */
227
- setQuillRef(ref_str: string): void;
228
- /**
229
- * Emit canonical Quillmark Markdown.
230
- *
231
- * Returns the document serialised as a Quillmark Markdown string.
232
- * The output is type-fidelity round-trip safe: re-parsing the result
233
- * produces a `Document` equal to `self` by value and by type.
234
- */
235
- toMarkdown(): string;
236
- /**
237
- * Replace the body of the card at `index`.
238
- *
239
- * Throws if `index` is out of range.
240
- *
241
- * Mutators never modify `warnings`.
242
- */
243
- updateCardBody(index: number, body: string): void;
244
- /**
245
- * Update a field on the card at `index`.
246
- *
247
- * Convenience method: equivalent to `doc.card_mut(index)?.set_field(name, value)`.
248
- *
249
- * Throws if `index` is out of range, `name` is reserved or invalid, or
250
- * `value` cannot be serialized.
251
- *
252
- * Mutators never modify `warnings`.
253
- */
254
- updateCardField(index: number, name: string, value: any): void;
255
- /**
256
- * Number of composable cards (excludes the main card).
257
- *
258
- * O(1). Use this to validate indices before calling card mutators
259
- * instead of allocating the full `cards` array.
260
- */
261
- readonly cardCount: number;
262
- /**
263
- * Ordered list of composable card blocks as typed `Card` objects.
264
- */
265
- readonly cards: Card[];
266
- /**
267
- * The document's main (entry) card.
268
- *
269
- * Carries the QUILL sentinel, the document-level frontmatter, and the
270
- * global body. Frontmatter/body reads and mutations go through this
271
- * handle — there are no document-level shortcuts after the rework.
272
- *
273
- * Allocates and serializes on each call — cache locally if read in a hot loop.
274
- */
275
- readonly main: Card;
276
- /**
277
- * The QUILL reference string (e.g. `"usaf_memo@0.1"`).
278
- */
279
- readonly quillRef: string;
280
- /**
281
- * Non-fatal parse-time warnings as an array of typed `Diagnostic` objects.
282
- */
283
- readonly warnings: Diagnostic[];
284
- }
285
-
286
- /**
287
- * Opaque, shareable Quill handle.
288
- */
289
- export class Quill {
290
- private constructor();
291
- free(): void;
292
- [Symbol.dispose](): void;
293
- /**
294
- * A blank form for a card of the given type — no document values supplied.
295
- *
296
- * Returns `null` if `cardType` is not declared in this quill's schema.
297
- * Otherwise returns a plain JS object shaped like a single entry in
298
- * [`Form::cards`].
299
- *
300
- * [`Form::cards`]: quillmark::form::Form::cards
301
- */
302
- blankCard(card_type: string): any;
303
- /**
304
- * A blank form for the main card — no document values supplied.
305
- *
306
- * Returns a plain JS object with the same shape as one entry in
307
- * [`Form::main`]. Every declared field's `source` is `"default"` (when
308
- * the schema declares a default) or `"missing"`.
309
- *
310
- * [`Form::main`]: quillmark::form::Form::main
311
- */
312
- blankMain(): any;
313
- /**
314
- * The schema-aware form view of `doc`.
315
- *
316
- * Returns a plain JS object (not a class) that is immediately
317
- * `JSON.stringify`-able. The shape mirrors [`Form`]:
318
- *
319
- * ```json
320
- * {
321
- * "main": { "schema": {...}, "values": { "field": {...} } },
322
- * "cards": [ ... ],
323
- * "diagnostics": [ ... ]
324
- * }
325
- * ```
326
- *
327
- * **Snapshot semantics.** This is a read-only snapshot of the document
328
- * at call time. Subsequent edits to `doc` require calling `form` again.
329
- *
330
- * [`Form`]: quillmark::form::Form
331
- */
332
- form(doc: Document): any;
333
- /**
334
- * Open an iterative render session for page-selective rendering.
335
- */
336
- open(doc: Document): RenderSession;
337
- /**
338
- * Render a document to final artifacts.
339
- */
340
- render(doc: Document, opts?: RenderOptions | null): RenderResult;
341
- /**
342
- * The resolved backend identifier (e.g. `"typst"`).
343
- */
344
- readonly backendId: string;
345
- /**
346
- * Read-only snapshot of the loaded quill's engine info and declared schema.
347
- *
348
- * Returns a plain JS object with:
349
- * - `schema` — the quill's public schema contract, identical to
350
- * `QuillConfig::public_schema()`. Top-level keys: `name`, `main`,
351
- * optional `card_types` (map keyed by card name, omitted when empty),
352
- * optional `example`. `main` and each card under `card_types` share
353
- * the same shape: `fields` (map keyed by field name), optional
354
- * `title`, `description`, `ui`.
355
- * - `backend`, `version`, `author`, `description` — quill identity
356
- * declared in `Quill.yaml`'s `quill:` section. `description` describes
357
- * the quill itself; if the author also declared `main.description` (the
358
- * schema description of the entry-point card), it lives at
359
- * `schema.main.description` and is independent.
360
- * - `supportedFormats` — output formats the backend produces, as
361
- * lowercase strings.
362
- * - Any additional unstructured keys declared under `quill:`.
363
- *
364
- * Consumers that need validation run their own validator against
365
- * `metadata.schema`.
366
- *
367
- * Equivalent by value for the lifetime of the handle; the quill is
368
- * immutable once constructed.
369
- */
370
- readonly metadata: any;
371
- }
372
-
373
- /**
374
- * Quillmark WASM Engine
375
- */
376
- export class Quillmark {
377
- free(): void;
378
- [Symbol.dispose](): void;
379
- /**
380
- * JavaScript constructor: `new Quillmark()`
381
- */
382
- constructor();
383
- /**
384
- * Load a quill from a file tree and attach the appropriate backend.
385
- *
386
- * Accepts either a `Map<string, Uint8Array>` or a plain object
387
- * (`Record<string, Uint8Array>`). Plain objects are walked via
388
- * `Object.entries` at the boundary; the Rust side sees a single
389
- * canonical shape.
390
- */
391
- quill(tree: Map<string, Uint8Array>): Quill;
392
- }
393
-
394
- export class RenderSession {
395
- private constructor();
396
- free(): void;
397
- [Symbol.dispose](): void;
398
- /**
399
- * Page dimensions in Typst points (1 pt = 1/72 inch).
400
- *
401
- * Stable for a given `page` across the session's lifetime — the
402
- * compiled document is an immutable snapshot, so callers can cache
403
- * results.
404
- *
405
- * Throws if the underlying backend has no canvas painter (i.e. is not
406
- * the Typst backend) or if `page` is out of range.
407
- */
408
- pageSize(page: number): PageSize;
409
- /**
410
- * Paint `page` into a 2D canvas context.
411
- *
412
- * `scale` multiplies Typst's natural 72 ppi (1 pt → 1 device pixel at
413
- * `scale = 1`). Typical usage:
414
- * `scale = (window.devicePixelRatio || 1) * userZoom`.
415
- *
416
- * The caller must size `ctx.canvas` so that
417
- * `canvas.width === round(widthPt * scale)` and `canvas.height ===
418
- * round(heightPt * scale)` *before* calling `paint`. Setting
419
- * `canvas.width` / `canvas.height` clears the backing store, which is
420
- * the recommended way to handle page-to-page transitions; if you
421
- * reuse a canvas without resizing, call
422
- * `ctx.clearRect(0, 0, canvas.width, canvas.height)` first to avoid
423
- * stale pixels showing through transparent regions.
424
- *
425
- * `paint` writes into the backing store at origin `(0, 0)` and does
426
- * not clear outside the rendered region.
427
- *
428
- * Throws if the backend does not support canvas preview (the message
429
- * includes the resolved `backendId` for debugging), or if `page` is
430
- * out of range.
431
- */
432
- paint(ctx: CanvasRenderingContext2D, page: number, scale: number): void;
433
- /**
434
- * Render all or selected pages from this session.
435
- */
436
- render(opts?: RenderOptions | null): RenderResult;
437
- /**
438
- * The backend that produced this session (e.g. `"typst"`).
439
- */
440
- readonly backendId: string;
441
- /**
442
- * Number of pages in this render session.
443
- *
444
- * Stable for the lifetime of the session — the underlying compiled
445
- * document is an immutable snapshot.
446
- */
447
- readonly pageCount: number;
448
- /**
449
- * Session-level warnings attached at `quill.open(...)` time.
450
- *
451
- * Snapshot of any non-fatal diagnostics emitted while opening the
452
- * session (e.g. version compatibility shims). Stable across the
453
- * session's lifetime. These are also appended to
454
- * [`RenderResult.warnings`] on every `render()` call; the accessor
455
- * surfaces them to canvas-preview consumers that don't go through
456
- * `render()`.
457
- */
458
- readonly warnings: Diagnostic[];
459
- }
460
-
461
- /**
462
- * Initialize the WASM module with panic hooks for better error messages
463
- */
464
- export function init(): void;