@quillmark/wasm 0.81.0-rc.2 → 0.82.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 +13 -11
- package/bundler/wasm.d.ts +81 -356
- package/bundler/wasm_bg.js +82 -341
- package/bundler/wasm_bg.wasm +0 -0
- package/bundler/wasm_bg.wasm.d.ts +1 -1
- package/package.json +1 -1
package/bundler/wasm.d.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* Input shape for `Document.pushCard` and `Document.insertCard`.
|
|
6
6
|
*
|
|
7
|
-
* Only `
|
|
7
|
+
* Only `kind` is required. `fields` defaults to `{}`, `body` to `""`.
|
|
8
8
|
*/
|
|
9
9
|
export interface CardInput {
|
|
10
|
-
|
|
10
|
+
kind: string;
|
|
11
11
|
fields?: Record<string, unknown>;
|
|
12
12
|
body?: string;
|
|
13
13
|
}
|
|
@@ -131,7 +131,7 @@ export interface QuillCardSchema {
|
|
|
131
131
|
* Document schema returned by `Quill.schema`. Includes optional `ui` keys.
|
|
132
132
|
*
|
|
133
133
|
* `main.fields.QUILL` and `card_kinds[name].fields.CARD` are required
|
|
134
|
-
*
|
|
134
|
+
* reserved fields with `const` values telling consumers what to write.
|
|
135
135
|
*/
|
|
136
136
|
export interface QuillSchema {
|
|
137
137
|
main: QuillCardSchema;
|
|
@@ -183,8 +183,8 @@ export interface FormCard {
|
|
|
183
183
|
* Schema-aware form view of a document, returned by `Quill.form`.
|
|
184
184
|
*
|
|
185
185
|
* - `main` — the main card viewed through the quill's main schema.
|
|
186
|
-
* - `cards` — composable card blocks, in document order (unknown
|
|
187
|
-
* - `diagnostics` — diagnostics from unknown card
|
|
186
|
+
* - `cards` — composable card blocks, in document order (unknown kinds excluded).
|
|
187
|
+
* - `diagnostics` — diagnostics from unknown card kinds and validation.
|
|
188
188
|
*/
|
|
189
189
|
export interface Form {
|
|
190
190
|
main: FormCard;
|
|
@@ -200,10 +200,8 @@ export interface Artifact {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
export interface Card {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
frontmatter: Record<string, unknown>;
|
|
206
|
-
frontmatterItems: FrontmatterItem[];
|
|
203
|
+
kind: string;
|
|
204
|
+
payloadItems: PayloadItem[];
|
|
207
205
|
body: string;
|
|
208
206
|
}
|
|
209
207
|
|
|
@@ -236,372 +234,176 @@ export interface RenderResult {
|
|
|
236
234
|
renderTimeMs: number;
|
|
237
235
|
}
|
|
238
236
|
|
|
239
|
-
export type FrontmatterItem = { kind: "field"; key: string; value: unknown; fill?: boolean } | { kind: "comment"; text: string; inline?: boolean };
|
|
240
|
-
|
|
241
237
|
export type OutputFormat = "pdf" | "svg" | "txt" | "png";
|
|
242
238
|
|
|
239
|
+
export type PayloadItem = { type: "field"; key: string; value: unknown; fill?: boolean } | { type: "comment"; text: string; inline?: boolean };
|
|
240
|
+
|
|
243
241
|
export type Severity = "error" | "warning" | "note";
|
|
244
242
|
|
|
245
243
|
|
|
246
244
|
/**
|
|
247
245
|
* Typed in-memory Quillmark document.
|
|
248
|
-
*
|
|
249
|
-
* Created via `Document.fromMarkdown(markdown)`. Exposes:
|
|
250
|
-
* - `quillRef` (string)
|
|
251
|
-
* - `frontmatter` (JS object/Record)
|
|
252
|
-
* - `body` (string)
|
|
253
|
-
* - `cards` (array of Card objects)
|
|
254
|
-
* - `warnings` (array of Diagnostic objects)
|
|
255
|
-
*
|
|
256
|
-
* `toMarkdown()` emits canonical Quillmark Markdown that round-trips back to
|
|
257
|
-
* an equal `Document` by value and by type.
|
|
258
246
|
*/
|
|
259
247
|
export class Document {
|
|
260
248
|
private constructor();
|
|
261
249
|
free(): void;
|
|
262
250
|
[Symbol.dispose](): void;
|
|
263
|
-
/**
|
|
264
|
-
* Return a fresh `Document` handle with the same parse state.
|
|
265
|
-
*
|
|
266
|
-
* Mutations on the returned handle do not affect the original and
|
|
267
|
-
* vice versa. Parse-time warnings are snapshotted alongside the
|
|
268
|
-
* document — they describe the original parse, not the edit
|
|
269
|
-
* history of either handle.
|
|
270
|
-
*/
|
|
271
251
|
clone(): Document;
|
|
272
252
|
/**
|
|
273
253
|
* Schema version this build writes via [`toJson`](Document::to_json).
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* against this to detect mismatches before calling
|
|
277
|
-
* [`fromJson`](Document::from_json).
|
|
254
|
+
* Tracks the `Document` model version (not the running crate version):
|
|
255
|
+
* the tag advances only when the wire format changes, not on every release.
|
|
278
256
|
*/
|
|
279
257
|
static currentSchemaVersion(): string;
|
|
280
258
|
/**
|
|
281
|
-
* Structural equality
|
|
282
|
-
*
|
|
283
|
-
* Compares `main` and `cards` by value (matching core's [`PartialEq`]).
|
|
284
|
-
* Parse-time `warnings` are intentionally excluded — they describe the
|
|
285
|
-
* source text, not the document's content.
|
|
286
|
-
*
|
|
287
|
-
* Use this to debounce upstream prop updates: keep the last parsed
|
|
288
|
-
* `Document` and compare instead of re-parsing on every keystroke.
|
|
259
|
+
* Structural equality (parse-time `warnings` excluded). Use to debounce
|
|
260
|
+
* upstream prop updates instead of re-parsing on every keystroke.
|
|
289
261
|
*/
|
|
290
262
|
equals(other: Document): boolean;
|
|
291
263
|
/**
|
|
292
|
-
* Reconstruct a `Document` from
|
|
264
|
+
* Reconstruct a `Document` from a versioned storage DTO string produced
|
|
265
|
+
* by [`toJson`](Document::to_json). Unknown `schema` tags are rejected.
|
|
266
|
+
* The result carries no parse-time warnings (`.warnings` is always empty).
|
|
293
267
|
*
|
|
294
|
-
* `json`
|
|
295
|
-
*
|
|
296
|
-
* the module via `serde_json`; the JS `JSON` global is not involved.
|
|
297
|
-
* Unknown `schema` tags are rejected.
|
|
298
|
-
*
|
|
299
|
-
* The reconstructed document carries no parse-time warnings — the DTO
|
|
300
|
-
* describes content, not source text — so `.warnings` is always empty.
|
|
301
|
-
*
|
|
302
|
-
* Throws a JS `Error` if `json` is not a valid storage DTO (malformed
|
|
303
|
-
* JSON, unknown `schema`, missing fields, or an unparseable quill
|
|
304
|
-
* reference).
|
|
268
|
+
* Throws if `json` is not a valid storage DTO (malformed JSON, unknown
|
|
269
|
+
* `schema`, missing fields, or unparseable quill reference).
|
|
305
270
|
*/
|
|
306
271
|
static fromJson(json: string): Document;
|
|
307
272
|
/**
|
|
308
|
-
* Parse markdown into a typed Document.
|
|
309
|
-
*
|
|
310
|
-
* Returns the document with any parse-time warnings accessible via `.warnings`.
|
|
311
|
-
* Throws on parse errors.
|
|
273
|
+
* Parse markdown into a typed Document. Throws on parse errors.
|
|
312
274
|
*/
|
|
313
275
|
static fromMarkdown(markdown: string): Document;
|
|
314
276
|
/**
|
|
315
|
-
* Insert a card at
|
|
316
|
-
*
|
|
317
|
-
* `index` must be in `0..=cards.length`. Out-of-range throws an `Error`.
|
|
318
|
-
*
|
|
319
|
-
* Mutators never modify `warnings`.
|
|
277
|
+
* Insert a card at `index` (must be in `0..=cards.length`).
|
|
320
278
|
*/
|
|
321
279
|
insertCard(index: number, card: CardInput): void;
|
|
322
280
|
/**
|
|
323
|
-
* Move the card at `from` to position `to`.
|
|
324
|
-
*
|
|
325
|
-
* `from == to` is a no-op. Both indices must be in `0..cards.length`.
|
|
326
|
-
* Out-of-range throws an `Error`.
|
|
327
|
-
*
|
|
328
|
-
* Mutators never modify `warnings`.
|
|
281
|
+
* Move the card at `from` to position `to`. `from == to` is a no-op.
|
|
329
282
|
*/
|
|
330
283
|
moveCard(from: number, to: number): void;
|
|
331
284
|
/**
|
|
332
285
|
* Append a card to the end of the card list.
|
|
333
|
-
*
|
|
334
|
-
* `card` must be a JS object with a `tag` string field and optional
|
|
335
|
-
* `fields` (object) and `body` (string).
|
|
336
|
-
*
|
|
337
|
-
* Throws an `Error` if `card.tag` is not a valid tag name.
|
|
338
|
-
*
|
|
339
|
-
* Mutators never modify `warnings`.
|
|
286
|
+
* Throws if `card.kind` is not a valid kind name.
|
|
340
287
|
*/
|
|
341
288
|
pushCard(card: CardInput): void;
|
|
342
|
-
/**
|
|
343
|
-
* Remove the card at `index` and return it, or `undefined` if out of range.
|
|
344
|
-
*
|
|
345
|
-
* Mutators never modify `warnings`.
|
|
346
|
-
*/
|
|
347
289
|
removeCard(index: number): Card | undefined;
|
|
348
290
|
/**
|
|
349
|
-
* Remove a
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* Throws if `index` is out of range, `name` is reserved, or `name` does
|
|
353
|
-
* not match `[a-z_][a-z0-9_]*`.
|
|
354
|
-
*
|
|
355
|
-
* Mutators never modify `warnings`.
|
|
291
|
+
* Remove a field on the card at `index`. Returns the removed value or
|
|
292
|
+
* `undefined`. Throws if `index` is out of range or `name` is invalid.
|
|
356
293
|
*/
|
|
357
294
|
removeCardField(index: number, name: string): any;
|
|
358
295
|
/**
|
|
359
|
-
* Remove a
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
* and details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`)
|
|
363
|
-
* or does not match `[a-z_][a-z0-9_]*`. Absence of an otherwise-valid
|
|
364
|
-
* name returns `undefined`.
|
|
365
|
-
*
|
|
366
|
-
* Mutators never modify `warnings`.
|
|
296
|
+
* Remove a payload field on the main card, returning the removed value or
|
|
297
|
+
* `undefined`. Throws if `name` is reserved or does not match
|
|
298
|
+
* `[a-z_][a-z0-9_]*`.
|
|
367
299
|
*/
|
|
368
300
|
removeField(name: string): any;
|
|
369
|
-
/**
|
|
370
|
-
* Replace the main card's body (the global Markdown body).
|
|
371
|
-
*
|
|
372
|
-
* Mutators never modify `warnings`.
|
|
373
|
-
*/
|
|
374
301
|
replaceBody(body: string): void;
|
|
375
302
|
/**
|
|
376
|
-
* Read the schema version from a raw storage DTO string without
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* that `fromJson` would reject. Use this to distinguish "this build is
|
|
381
|
-
* too old for the payload" from "the payload is corrupt" when
|
|
382
|
-
* [`fromJson`](Document::from_json) throws:
|
|
383
|
-
*
|
|
384
|
-
* ```js
|
|
385
|
-
* const v = Document.schemaVersionOf(blob);
|
|
386
|
-
* if (v === undefined) {
|
|
387
|
-
* // not a stored DTO at all — try fromMarkdown
|
|
388
|
-
* } else if (v !== Document.currentSchemaVersion()) {
|
|
389
|
-
* // newer (or older unmigrated) schema — prompt the user to upgrade
|
|
390
|
-
* } else {
|
|
391
|
-
* doc = Document.fromJson(blob);
|
|
392
|
-
* }
|
|
393
|
-
* ```
|
|
303
|
+
* Read the `schema` version tag from a raw storage DTO string without a
|
|
304
|
+
* full parse, or `undefined`. Returns unknown future versions as-is —
|
|
305
|
+
* useful to distinguish "build too old" from "payload corrupt" when
|
|
306
|
+
* `fromJson` throws.
|
|
394
307
|
*/
|
|
395
308
|
static schemaVersionOf(json: string): string | undefined;
|
|
396
309
|
/**
|
|
397
|
-
* Replace the
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* untouched. Schema-aware migration (clearing orphan fields, applying
|
|
401
|
-
* new defaults) is the caller's responsibility; `setCardTag` is a
|
|
402
|
-
* structural primitive.
|
|
403
|
-
*
|
|
404
|
-
* Throws if `index` is out of range or if `newTag` does not match
|
|
405
|
-
* `[a-z_][a-z0-9_]*`.
|
|
406
|
-
*
|
|
407
|
-
* Mutators never modify `warnings`.
|
|
310
|
+
* Replace the kind of the card at `index`. Payload and body are untouched;
|
|
311
|
+
* schema-aware migration is the caller's responsibility.
|
|
312
|
+
* Throws if `index` is out of range or `newKind` is invalid.
|
|
408
313
|
*/
|
|
409
|
-
|
|
314
|
+
setCardKind(index: number, new_kind: string): void;
|
|
410
315
|
/**
|
|
411
|
-
* Update a
|
|
412
|
-
*
|
|
413
|
-
* Convenience method: equivalent to `doc.mainMut().setField(name, value)`.
|
|
414
|
-
* Clears any existing `!fill` marker on the field.
|
|
316
|
+
* Update a payload field on the main card. Clears any existing `!fill` marker.
|
|
415
317
|
*
|
|
416
|
-
* Throws
|
|
417
|
-
* details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
|
|
318
|
+
* Throws if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
|
|
418
319
|
* not match `[a-z_][a-z0-9_]*`.
|
|
419
|
-
*
|
|
420
|
-
* Mutators never modify `warnings`.
|
|
421
320
|
*/
|
|
422
321
|
setField(name: string, value: any): void;
|
|
423
322
|
/**
|
|
424
|
-
* Update a
|
|
425
|
-
*
|
|
426
|
-
* Convenience method: equivalent to `doc.mainMut().setFill(name, value)`.
|
|
427
|
-
*
|
|
323
|
+
* Update a payload field on the main card and mark it as `!fill`.
|
|
428
324
|
* Throws on invalid name (see [`setField`](Document::set_field)).
|
|
429
|
-
*
|
|
430
|
-
* Mutators never modify `warnings`.
|
|
431
325
|
*/
|
|
432
326
|
setFill(name: string, value: any): void;
|
|
433
327
|
/**
|
|
434
|
-
* Replace the QUILL reference string.
|
|
435
|
-
*
|
|
436
|
-
* Throws if `ref_str` is not a valid `QuillReference`.
|
|
437
|
-
*
|
|
438
|
-
* Mutators never modify `warnings`.
|
|
328
|
+
* Replace the QUILL reference string. Throws if `ref_str` is invalid.
|
|
439
329
|
*/
|
|
440
330
|
setQuillRef(ref_str: string): void;
|
|
441
331
|
/**
|
|
442
332
|
* Serialize this document to a versioned storage DTO string.
|
|
443
333
|
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
* [`fromJson`](Document::from_json) — the JS `JSON` global is not
|
|
448
|
-
* involved in either direction.
|
|
449
|
-
*
|
|
450
|
-
* Use this — not [`toMarkdown`](Document::to_markdown) — to persist a
|
|
451
|
-
* document across a process restart or crate upgrade; the wire format
|
|
452
|
-
* is frozen per `schema` version, whereas Markdown syntax evolves.
|
|
453
|
-
* Parse-time `warnings` are not part of the DTO.
|
|
334
|
+
* Prefer this over `toMarkdown` for persistence across restarts or crate
|
|
335
|
+
* upgrades — the wire format is frozen per `schema` version. Parse-time
|
|
336
|
+
* `warnings` are excluded from the DTO.
|
|
454
337
|
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
* intended use.
|
|
338
|
+
* Output is **byte-deterministic** within a `schema` version: equal
|
|
339
|
+
* documents produce byte-equal output, safe for content-hash use cases.
|
|
458
340
|
*/
|
|
459
341
|
toJson(): string;
|
|
460
342
|
/**
|
|
461
|
-
* Emit canonical Quillmark Markdown.
|
|
462
|
-
*
|
|
463
|
-
* Returns the document serialised as a Quillmark Markdown string.
|
|
464
|
-
* The output is type-fidelity round-trip safe: re-parsing the result
|
|
465
|
-
* produces a `Document` equal to `self` by value and by type.
|
|
343
|
+
* Emit canonical Quillmark Markdown. Round-trip safe: re-parsing the
|
|
344
|
+
* result produces a `Document` equal to `self` by value and by type.
|
|
466
345
|
*/
|
|
467
346
|
toMarkdown(): string;
|
|
468
347
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
* ```js
|
|
476
|
-
* const doc = Document.tryFromJson(content) ?? Document.fromMarkdown(content);
|
|
477
|
-
* ```
|
|
478
|
-
*
|
|
479
|
-
* `undefined` only ever means "not a storage DTO" — `fromMarkdown`
|
|
480
|
-
* still throws on genuinely malformed markdown.
|
|
348
|
+
* Like [`fromJson`](Document::from_json) but returns `undefined` instead
|
|
349
|
+
* of throwing when `json` is not a valid storage DTO — use to
|
|
350
|
+
* discriminate format without exceptions as control flow.
|
|
351
|
+
* `undefined` means "not a storage DTO"; `fromMarkdown` still throws on
|
|
352
|
+
* genuinely malformed markdown.
|
|
481
353
|
*/
|
|
482
354
|
static tryFromJson(json: string): Document | undefined;
|
|
483
355
|
/**
|
|
484
|
-
* Replace the body of the card at `index`.
|
|
485
|
-
*
|
|
486
|
-
* Throws if `index` is out of range.
|
|
487
|
-
*
|
|
488
|
-
* Mutators never modify `warnings`.
|
|
356
|
+
* Replace the body of the card at `index`. Throws if out of range.
|
|
489
357
|
*/
|
|
490
358
|
updateCardBody(index: number, body: string): void;
|
|
491
359
|
/**
|
|
492
360
|
* Update a field on the card at `index`.
|
|
493
|
-
*
|
|
494
|
-
* Convenience method: equivalent to `doc.card_mut(index)?.set_field(name, value)`.
|
|
495
|
-
*
|
|
496
|
-
* Throws if `index` is out of range, `name` is reserved or invalid, or
|
|
497
|
-
* `value` cannot be serialized.
|
|
498
|
-
*
|
|
499
|
-
* Mutators never modify `warnings`.
|
|
361
|
+
* Throws if `index` is out of range, `name` is reserved or invalid.
|
|
500
362
|
*/
|
|
501
363
|
updateCardField(index: number, name: string, value: any): void;
|
|
502
364
|
/**
|
|
503
|
-
* Number of composable cards (excludes the main card).
|
|
504
|
-
*
|
|
505
|
-
* O(1). Use this to validate indices before calling card mutators
|
|
506
|
-
* instead of allocating the full `cards` array.
|
|
365
|
+
* Number of composable cards (excludes the main card). O(1).
|
|
507
366
|
*/
|
|
508
367
|
readonly cardCount: number;
|
|
509
|
-
/**
|
|
510
|
-
* Ordered list of composable card blocks as typed `Card` objects.
|
|
511
|
-
*/
|
|
512
368
|
readonly cards: Card[];
|
|
513
369
|
/**
|
|
514
|
-
* The document's main (entry) card.
|
|
515
|
-
*
|
|
516
|
-
* Carries the QUILL sentinel, the document-level frontmatter, and the
|
|
517
|
-
* global body. Frontmatter/body reads and mutations go through this
|
|
518
|
-
* handle — there are no document-level shortcuts after the rework.
|
|
519
|
-
*
|
|
520
|
-
* Allocates and serializes on each call — cache locally if read in a hot loop.
|
|
370
|
+
* The document's main (entry) card. Allocates and serializes on each
|
|
371
|
+
* call — cache locally if read in a hot loop.
|
|
521
372
|
*/
|
|
522
373
|
readonly main: Card;
|
|
523
|
-
/**
|
|
524
|
-
* The QUILL reference string (e.g. `"usaf_memo@0.1"`).
|
|
525
|
-
*/
|
|
526
374
|
readonly quillRef: string;
|
|
527
|
-
/**
|
|
528
|
-
* Non-fatal parse-time warnings as an array of typed `Diagnostic` objects.
|
|
529
|
-
*/
|
|
530
375
|
readonly warnings: Diagnostic[];
|
|
531
376
|
}
|
|
532
377
|
|
|
533
|
-
/**
|
|
534
|
-
* Opaque, shareable Quill handle.
|
|
535
|
-
*/
|
|
536
378
|
export class Quill {
|
|
537
379
|
private constructor();
|
|
538
380
|
free(): void;
|
|
539
381
|
[Symbol.dispose](): void;
|
|
540
382
|
/**
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
* Returns `null` if `cardKind` is not declared in this quill's schema.
|
|
544
|
-
* Otherwise returns a plain JS object shaped like a single entry in
|
|
545
|
-
* [`Form::cards`].
|
|
546
|
-
*
|
|
547
|
-
* [`Form::cards`]: quillmark::form::Form::cards
|
|
383
|
+
* Blank `FormCard` for the given card kind. Returns `null` if `cardKind`
|
|
384
|
+
* is not declared in this quill's schema.
|
|
548
385
|
*/
|
|
549
386
|
blankCard(card_kind: string): FormCard | null;
|
|
550
387
|
/**
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
* Returns a plain JS object with the same shape as one entry in
|
|
554
|
-
* [`Form::main`]. Every declared field's `source` is `"default"` (when
|
|
555
|
-
* the schema declares a default) or `"missing"`.
|
|
556
|
-
*
|
|
557
|
-
* [`Form::main`]: quillmark::form::Form::main
|
|
388
|
+
* Blank `FormCard` for the main card with no document values.
|
|
389
|
+
* Every field's `source` is `"default"` or `"missing"`.
|
|
558
390
|
*/
|
|
559
391
|
blankMain(): FormCard;
|
|
560
392
|
/**
|
|
561
|
-
* The schema-aware form view of `doc`.
|
|
562
|
-
*
|
|
563
|
-
* Returns a plain JS object (not a class) that is immediately
|
|
564
|
-
* `JSON.stringify`-able. The shape mirrors [`Form`]:
|
|
565
|
-
*
|
|
566
|
-
* ```json
|
|
567
|
-
* {
|
|
568
|
-
* "main": { "schema": {...}, "values": { "field": {...} } },
|
|
569
|
-
* "cards": [ ... ],
|
|
570
|
-
* "diagnostics": [ ... ]
|
|
571
|
-
* }
|
|
572
|
-
* ```
|
|
573
|
-
*
|
|
574
|
-
* **Snapshot semantics.** This is a read-only snapshot of the document
|
|
575
|
-
* at call time. Subsequent edits to `doc` require calling `form` again.
|
|
576
|
-
*
|
|
577
|
-
* [`Form`]: quillmark::form::Form
|
|
393
|
+
* The schema-aware form view of `doc`. Read-only snapshot at call time;
|
|
394
|
+
* subsequent edits to `doc` require calling `form` again.
|
|
578
395
|
*/
|
|
579
396
|
form(doc: Document): Form;
|
|
580
|
-
/**
|
|
581
|
-
* Open an iterative render session for page-selective rendering.
|
|
582
|
-
*/
|
|
583
397
|
open(doc: Document): RenderSession;
|
|
584
|
-
/**
|
|
585
|
-
* Render a document to final artifacts.
|
|
586
|
-
*/
|
|
587
398
|
render(doc: Document, opts?: RenderOptions | null): RenderResult;
|
|
588
399
|
/**
|
|
589
400
|
* The resolved backend identifier (e.g. `"typst"`).
|
|
590
401
|
*/
|
|
591
402
|
readonly backendId: string;
|
|
592
|
-
/**
|
|
593
|
-
* Auto-generated annotated Markdown blueprint for LLM consumers.
|
|
594
|
-
*/
|
|
595
403
|
readonly blueprint: string;
|
|
596
404
|
/**
|
|
597
405
|
* Identity snapshot of the `quill:` section of `Quill.yaml`, plus
|
|
598
|
-
* `supportedFormats` and any
|
|
599
|
-
*
|
|
600
|
-
* Consumers that need validation run their own validator against
|
|
601
|
-
* `metadata.schema`.
|
|
602
|
-
*
|
|
603
|
-
* Equivalent by value for the lifetime of the handle; the quill is
|
|
604
|
-
* immutable once constructed.
|
|
406
|
+
* `supportedFormats` and any extra `quill:` keys.
|
|
605
407
|
*/
|
|
606
408
|
readonly metadata: QuillMetadata;
|
|
607
409
|
/**
|
|
@@ -609,25 +411,16 @@ export class Quill {
|
|
|
609
411
|
*/
|
|
610
412
|
readonly schema: QuillSchema;
|
|
611
413
|
/**
|
|
612
|
-
* Whether this quill's backend supports canvas preview.
|
|
613
|
-
*
|
|
614
414
|
* `true` iff `RenderSession.paint` and `RenderSession.pageSize` will
|
|
615
|
-
* succeed for sessions opened by this quill. Use
|
|
616
|
-
* probe before mounting a canvas-based preview UI
|
|
617
|
-
* remains the enforcement contract.
|
|
415
|
+
* succeed for sessions opened by this quill. Use as a precondition
|
|
416
|
+
* probe before mounting a canvas-based preview UI.
|
|
618
417
|
*/
|
|
619
418
|
readonly supportsCanvas: boolean;
|
|
620
419
|
}
|
|
621
420
|
|
|
622
|
-
/**
|
|
623
|
-
* Quillmark WASM Engine
|
|
624
|
-
*/
|
|
625
421
|
export class Quillmark {
|
|
626
422
|
free(): void;
|
|
627
423
|
[Symbol.dispose](): void;
|
|
628
|
-
/**
|
|
629
|
-
* JavaScript constructor: `new Quillmark()`
|
|
630
|
-
*/
|
|
631
424
|
constructor();
|
|
632
425
|
/**
|
|
633
426
|
* Load a quill from a file tree and attach the appropriate backend.
|
|
@@ -641,19 +434,12 @@ export class Quillmark {
|
|
|
641
434
|
}
|
|
642
435
|
|
|
643
436
|
/**
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
* Created via [`Quill::open`]. Holds the compiled output so that
|
|
647
|
-
* [`RenderSession::render`], [`RenderSession::paint`], and
|
|
648
|
-
* [`RenderSession::page_size`] can be called repeatedly without
|
|
649
|
-
* recompiling.
|
|
437
|
+
* Iterative render handle backed by an immutable compiled snapshot.
|
|
650
438
|
*
|
|
651
|
-
* **Empty documents.** A document
|
|
652
|
-
*
|
|
653
|
-
* `0
|
|
654
|
-
*
|
|
655
|
-
* (pageCount=0)"`. Hosts that surface "no pages to preview" UI should
|
|
656
|
-
* branch on `pageCount === 0` rather than on a thrown error.
|
|
439
|
+
* **Empty documents.** A zero-page document yields a valid session
|
|
440
|
+
* (`pageCount === 0`); `paint(ctx, 0)` or `pageSize(0)` throws with
|
|
441
|
+
* `"page index 0 out of range (pageCount=0)"`. Branch on `pageCount === 0`
|
|
442
|
+
* rather than catching the error.
|
|
657
443
|
*/
|
|
658
444
|
export class RenderSession {
|
|
659
445
|
private constructor();
|
|
@@ -661,94 +447,33 @@ export class RenderSession {
|
|
|
661
447
|
[Symbol.dispose](): void;
|
|
662
448
|
/**
|
|
663
449
|
* Page dimensions in Typst points (1 pt = 1/72 inch).
|
|
664
|
-
*
|
|
665
|
-
* Report-only: the painter sizes the canvas itself based on
|
|
666
|
-
* `PaintOptions`. Exposed for consumers that need page geometry
|
|
667
|
-
* up-front (e.g. to lay out a scrollable list of canvases before
|
|
668
|
-
* any pixels are rendered).
|
|
669
|
-
*
|
|
670
|
-
* Stable for a given `page` across the session's lifetime — the
|
|
671
|
-
* compiled document is an immutable snapshot, so callers can cache
|
|
672
|
-
* results.
|
|
673
|
-
*
|
|
674
|
-
* Throws if the underlying backend has no canvas painter (i.e. is not
|
|
675
|
-
* the Typst backend) or if `page` is out of range.
|
|
450
|
+
* Throws if the backend has no canvas painter or `page` is out of range.
|
|
676
451
|
*/
|
|
677
452
|
pageSize(page: number): PageSize;
|
|
678
453
|
/**
|
|
679
|
-
* Paint `page` into a
|
|
454
|
+
* Paint `page` into a `CanvasRenderingContext2D` or
|
|
455
|
+
* `OffscreenCanvasRenderingContext2D`. The painter owns
|
|
456
|
+
* `canvas.width`/`height` (no `clearRect` needed); consumers own
|
|
457
|
+
* `canvas.style.*`. If `layoutScale * densityScale` exceeds 16384 px
|
|
458
|
+
* per side, `densityScale` is clamped — detect via `PaintResult.pixelWidth`.
|
|
680
459
|
*
|
|
681
|
-
*
|
|
682
|
-
* `
|
|
683
|
-
* Both dispatch to the same Rust rasterizer; the dispatch happens at
|
|
684
|
-
* the JS boundary so neither context type is privileged.
|
|
685
|
-
*
|
|
686
|
-
* The painter owns `canvas.width` / `canvas.height` and writes them
|
|
687
|
-
* itself; consumers must not. The painter does not touch
|
|
688
|
-
* `canvas.style.*` — that's layout, owned by the consumer (see
|
|
689
|
-
* `PaintResult.layoutWidth` / `layoutHeight`).
|
|
690
|
-
*
|
|
691
|
-
* `opts.layoutScale` (default 1.0) is layout-space pixels per Typst
|
|
692
|
-
* point and determines the canvas's display-box size. `opts.densityScale`
|
|
693
|
-
* (default 1.0) is the rasterization density multiplier the consumer
|
|
694
|
-
* folds `window.devicePixelRatio`, in-app zoom, and
|
|
695
|
-
* `visualViewport.scale` (pinch-zoom) into. The effective
|
|
696
|
-
* rasterization scale is `layoutScale * densityScale`.
|
|
697
|
-
*
|
|
698
|
-
* If `layoutScale * densityScale` would exceed the safe backing-store
|
|
699
|
-
* maximum (16384 px per side), `densityScale` is clamped
|
|
700
|
-
* proportionally so the largest dimension fits. The actual
|
|
701
|
-
* backing-store dimensions are reported in the returned
|
|
702
|
-
* `PaintResult` — compare against
|
|
703
|
-
* `round(layoutWidth * densityScale)` to detect clamping.
|
|
704
|
-
*
|
|
705
|
-
* Each call resets the backing store (`paint` is always a full
|
|
706
|
-
* repaint). Consumers do not need to call `clearRect`.
|
|
707
|
-
*
|
|
708
|
-
* Throws when:
|
|
709
|
-
* - the backend does not support canvas preview (message includes the
|
|
710
|
-
* resolved `backendId`),
|
|
711
|
-
* - `page` is out of range,
|
|
712
|
-
* - `ctx` is neither `CanvasRenderingContext2D` nor
|
|
713
|
-
* `OffscreenCanvasRenderingContext2D`,
|
|
714
|
-
* - `opts.layoutScale` or `opts.densityScale` is non-finite or `<= 0`.
|
|
460
|
+
* Throws if the backend has no canvas painter, `page` is out of range,
|
|
461
|
+
* `ctx` is the wrong type, or either scale is non-finite or `<= 0`.
|
|
715
462
|
*/
|
|
716
463
|
paint(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, page: number, opts: PaintOptions | undefined): PaintResult;
|
|
717
|
-
/**
|
|
718
|
-
* Render all or selected pages from this session.
|
|
719
|
-
*/
|
|
720
464
|
render(opts?: RenderOptions | null): RenderResult;
|
|
721
465
|
/**
|
|
722
466
|
* The backend that produced this session (e.g. `"typst"`).
|
|
723
|
-
*
|
|
724
|
-
* Equal to the `backendId` of the [`Quill`] that opened this session
|
|
725
|
-
* (sessions inherit their quill's backend), so checking either is fine.
|
|
726
467
|
*/
|
|
727
468
|
readonly backendId: string;
|
|
728
|
-
/**
|
|
729
|
-
* Number of pages in this render session.
|
|
730
|
-
*
|
|
731
|
-
* Stable for the lifetime of the session — the underlying compiled
|
|
732
|
-
* document is an immutable snapshot.
|
|
733
|
-
*/
|
|
734
469
|
readonly pageCount: number;
|
|
735
470
|
/**
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
* `true` iff [`paint`](Self::paint) and [`page_size`](Self::page_size)
|
|
739
|
-
* will succeed. Equal to `Quill.supportsCanvas` for the quill that
|
|
740
|
-
* opened this session.
|
|
471
|
+
* `true` iff `paint` and `pageSize` will succeed for this session.
|
|
741
472
|
*/
|
|
742
473
|
readonly supportsCanvas: boolean;
|
|
743
474
|
/**
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
* Snapshot of any non-fatal diagnostics emitted while opening the
|
|
747
|
-
* session (e.g. version compatibility shims). Stable across the
|
|
748
|
-
* session's lifetime. These are also appended to
|
|
749
|
-
* [`RenderResult.warnings`] on every `render()` call; the accessor
|
|
750
|
-
* surfaces them to canvas-preview consumers that don't go through
|
|
751
|
-
* `render()`.
|
|
475
|
+
* Non-fatal diagnostics emitted when opening the session. Also appended
|
|
476
|
+
* to `RenderResult.warnings` on each `render()` call.
|
|
752
477
|
*/
|
|
753
478
|
readonly warnings: Diagnostic[];
|
|
754
479
|
}
|