@quillmark/wasm 0.81.0 → 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 -378
- package/bundler/wasm_bg.js +76 -349
- package/bundler/wasm_bg.wasm +0 -0
- package/bundler/wasm_bg.wasm.d.ts +1 -1
- package/package.json +1 -1
package/bundler/wasm_bg.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed in-memory Quillmark document.
|
|
3
|
-
*
|
|
4
|
-
* Created via `Document.fromMarkdown(markdown)`. Exposes:
|
|
5
|
-
* - `quillRef` (string)
|
|
6
|
-
* - `frontmatter` (JS object/Record)
|
|
7
|
-
* - `body` (string)
|
|
8
|
-
* - `cards` (array of Card objects)
|
|
9
|
-
* - `warnings` (array of Diagnostic objects)
|
|
10
|
-
*
|
|
11
|
-
* `toMarkdown()` emits canonical Quillmark Markdown that round-trips back to
|
|
12
|
-
* an equal `Document` by value and by type.
|
|
13
3
|
*/
|
|
14
4
|
export class Document {
|
|
15
5
|
static __wrap(ptr) {
|
|
@@ -30,10 +20,7 @@ export class Document {
|
|
|
30
20
|
wasm.__wbg_document_free(ptr, 0);
|
|
31
21
|
}
|
|
32
22
|
/**
|
|
33
|
-
* Number of composable cards (excludes the main card).
|
|
34
|
-
*
|
|
35
|
-
* O(1). Use this to validate indices before calling card mutators
|
|
36
|
-
* instead of allocating the full `cards` array.
|
|
23
|
+
* Number of composable cards (excludes the main card). O(1).
|
|
37
24
|
* @returns {number}
|
|
38
25
|
*/
|
|
39
26
|
get cardCount() {
|
|
@@ -41,7 +28,6 @@ export class Document {
|
|
|
41
28
|
return ret >>> 0;
|
|
42
29
|
}
|
|
43
30
|
/**
|
|
44
|
-
* Ordered list of composable card blocks as typed `Card` objects.
|
|
45
31
|
* @returns {Card[]}
|
|
46
32
|
*/
|
|
47
33
|
get cards() {
|
|
@@ -49,12 +35,6 @@ export class Document {
|
|
|
49
35
|
return takeObject(ret);
|
|
50
36
|
}
|
|
51
37
|
/**
|
|
52
|
-
* Return a fresh `Document` handle with the same parse state.
|
|
53
|
-
*
|
|
54
|
-
* Mutations on the returned handle do not affect the original and
|
|
55
|
-
* vice versa. Parse-time warnings are snapshotted alongside the
|
|
56
|
-
* document — they describe the original parse, not the edit
|
|
57
|
-
* history of either handle.
|
|
58
38
|
* @returns {Document}
|
|
59
39
|
*/
|
|
60
40
|
clone() {
|
|
@@ -63,16 +43,8 @@ export class Document {
|
|
|
63
43
|
}
|
|
64
44
|
/**
|
|
65
45
|
* Schema version this build writes via [`toJson`](Document::to_json).
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* against this to detect mismatches before calling
|
|
69
|
-
* [`fromJson`](Document::from_json).
|
|
70
|
-
*
|
|
71
|
-
* The tag tracks the **`Document` model version** — the crate version
|
|
72
|
-
* at which the wire format was last changed — not the running crate
|
|
73
|
-
* version. Every patch and minor release within the same model
|
|
74
|
-
* generation returns the same string; the tag advances only when a
|
|
75
|
-
* new schema variant ships.
|
|
46
|
+
* Tracks the `Document` model version (not the running crate version):
|
|
47
|
+
* the tag advances only when the wire format changes, not on every release.
|
|
76
48
|
* @returns {string}
|
|
77
49
|
*/
|
|
78
50
|
static currentSchemaVersion() {
|
|
@@ -92,14 +64,8 @@ export class Document {
|
|
|
92
64
|
}
|
|
93
65
|
}
|
|
94
66
|
/**
|
|
95
|
-
* Structural equality
|
|
96
|
-
*
|
|
97
|
-
* Compares `main` and `cards` by value (matching core's [`PartialEq`]).
|
|
98
|
-
* Parse-time `warnings` are intentionally excluded — they describe the
|
|
99
|
-
* source text, not the document's content.
|
|
100
|
-
*
|
|
101
|
-
* Use this to debounce upstream prop updates: keep the last parsed
|
|
102
|
-
* `Document` and compare instead of re-parsing on every keystroke.
|
|
67
|
+
* Structural equality (parse-time `warnings` excluded). Use to debounce
|
|
68
|
+
* upstream prop updates instead of re-parsing on every keystroke.
|
|
103
69
|
* @param {Document} other
|
|
104
70
|
* @returns {boolean}
|
|
105
71
|
*/
|
|
@@ -109,19 +75,12 @@ export class Document {
|
|
|
109
75
|
return ret !== 0;
|
|
110
76
|
}
|
|
111
77
|
/**
|
|
112
|
-
* Reconstruct a `Document` from
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* the versioned storage DTO. Parsing and schema dispatch happen inside
|
|
116
|
-
* the module via `serde_json`; the JS `JSON` global is not involved.
|
|
117
|
-
* Unknown `schema` tags are rejected.
|
|
78
|
+
* Reconstruct a `Document` from a versioned storage DTO string produced
|
|
79
|
+
* by [`toJson`](Document::to_json). Unknown `schema` tags are rejected.
|
|
80
|
+
* The result carries no parse-time warnings (`.warnings` is always empty).
|
|
118
81
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* Throws a JS `Error` if `json` is not a valid storage DTO (malformed
|
|
123
|
-
* JSON, unknown `schema`, missing fields, or an unparseable quill
|
|
124
|
-
* reference).
|
|
82
|
+
* Throws if `json` is not a valid storage DTO (malformed JSON, unknown
|
|
83
|
+
* `schema`, missing fields, or unparseable quill reference).
|
|
125
84
|
* @param {string} json
|
|
126
85
|
* @returns {Document}
|
|
127
86
|
*/
|
|
@@ -143,10 +102,7 @@ export class Document {
|
|
|
143
102
|
}
|
|
144
103
|
}
|
|
145
104
|
/**
|
|
146
|
-
* Parse markdown into a typed Document.
|
|
147
|
-
*
|
|
148
|
-
* Returns the document with any parse-time warnings accessible via `.warnings`.
|
|
149
|
-
* Throws on parse errors.
|
|
105
|
+
* Parse markdown into a typed Document. Throws on parse errors.
|
|
150
106
|
* @param {string} markdown
|
|
151
107
|
* @returns {Document}
|
|
152
108
|
*/
|
|
@@ -168,11 +124,7 @@ export class Document {
|
|
|
168
124
|
}
|
|
169
125
|
}
|
|
170
126
|
/**
|
|
171
|
-
* Insert a card at
|
|
172
|
-
*
|
|
173
|
-
* `index` must be in `0..=cards.length`. Out-of-range throws an `Error`.
|
|
174
|
-
*
|
|
175
|
-
* Mutators never modify `warnings`.
|
|
127
|
+
* Insert a card at `index` (must be in `0..=cards.length`).
|
|
176
128
|
* @param {number} index
|
|
177
129
|
* @param {CardInput} card
|
|
178
130
|
*/
|
|
@@ -190,13 +142,8 @@ export class Document {
|
|
|
190
142
|
}
|
|
191
143
|
}
|
|
192
144
|
/**
|
|
193
|
-
* The document's main (entry) card.
|
|
194
|
-
*
|
|
195
|
-
* Carries the QUILL sentinel, the document-level frontmatter, and the
|
|
196
|
-
* global body. Frontmatter/body reads and mutations go through this
|
|
197
|
-
* handle — there are no document-level shortcuts after the rework.
|
|
198
|
-
*
|
|
199
|
-
* Allocates and serializes on each call — cache locally if read in a hot loop.
|
|
145
|
+
* The document's main (entry) card. Allocates and serializes on each
|
|
146
|
+
* call — cache locally if read in a hot loop.
|
|
200
147
|
* @returns {Card}
|
|
201
148
|
*/
|
|
202
149
|
get main() {
|
|
@@ -204,12 +151,7 @@ export class Document {
|
|
|
204
151
|
return takeObject(ret);
|
|
205
152
|
}
|
|
206
153
|
/**
|
|
207
|
-
* Move the card at `from` to position `to`.
|
|
208
|
-
*
|
|
209
|
-
* `from == to` is a no-op. Both indices must be in `0..cards.length`.
|
|
210
|
-
* Out-of-range throws an `Error`.
|
|
211
|
-
*
|
|
212
|
-
* Mutators never modify `warnings`.
|
|
154
|
+
* Move the card at `from` to position `to`. `from == to` is a no-op.
|
|
213
155
|
* @param {number} from
|
|
214
156
|
* @param {number} to
|
|
215
157
|
*/
|
|
@@ -228,13 +170,7 @@ export class Document {
|
|
|
228
170
|
}
|
|
229
171
|
/**
|
|
230
172
|
* Append a card to the end of the card list.
|
|
231
|
-
*
|
|
232
|
-
* `card` must be a JS object with a `tag` string field and optional
|
|
233
|
-
* `fields` (object) and `body` (string).
|
|
234
|
-
*
|
|
235
|
-
* Throws an `Error` if `card.tag` is not a valid tag name.
|
|
236
|
-
*
|
|
237
|
-
* Mutators never modify `warnings`.
|
|
173
|
+
* Throws if `card.kind` is not a valid kind name.
|
|
238
174
|
* @param {CardInput} card
|
|
239
175
|
*/
|
|
240
176
|
pushCard(card) {
|
|
@@ -251,7 +187,6 @@ export class Document {
|
|
|
251
187
|
}
|
|
252
188
|
}
|
|
253
189
|
/**
|
|
254
|
-
* The QUILL reference string (e.g. `"usaf_memo@0.1"`).
|
|
255
190
|
* @returns {string}
|
|
256
191
|
*/
|
|
257
192
|
get quillRef() {
|
|
@@ -271,9 +206,6 @@ export class Document {
|
|
|
271
206
|
}
|
|
272
207
|
}
|
|
273
208
|
/**
|
|
274
|
-
* Remove the card at `index` and return it, or `undefined` if out of range.
|
|
275
|
-
*
|
|
276
|
-
* Mutators never modify `warnings`.
|
|
277
209
|
* @param {number} index
|
|
278
210
|
* @returns {Card | undefined}
|
|
279
211
|
*/
|
|
@@ -282,13 +214,8 @@ export class Document {
|
|
|
282
214
|
return takeObject(ret);
|
|
283
215
|
}
|
|
284
216
|
/**
|
|
285
|
-
* Remove a
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* Throws if `index` is out of range, `name` is reserved, or `name` does
|
|
289
|
-
* not match `[a-z_][a-z0-9_]*`.
|
|
290
|
-
*
|
|
291
|
-
* Mutators never modify `warnings`.
|
|
217
|
+
* Remove a field on the card at `index`. Returns the removed value or
|
|
218
|
+
* `undefined`. Throws if `index` is out of range or `name` is invalid.
|
|
292
219
|
* @param {number} index
|
|
293
220
|
* @param {string} name
|
|
294
221
|
* @returns {any}
|
|
@@ -311,14 +238,9 @@ export class Document {
|
|
|
311
238
|
}
|
|
312
239
|
}
|
|
313
240
|
/**
|
|
314
|
-
* Remove a
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* and details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`)
|
|
318
|
-
* or does not match `[a-z_][a-z0-9_]*`. Absence of an otherwise-valid
|
|
319
|
-
* name returns `undefined`.
|
|
320
|
-
*
|
|
321
|
-
* Mutators never modify `warnings`.
|
|
241
|
+
* Remove a payload field on the main card, returning the removed value or
|
|
242
|
+
* `undefined`. Throws if `name` is reserved or does not match
|
|
243
|
+
* `[a-z_][a-z0-9_]*`.
|
|
322
244
|
* @param {string} name
|
|
323
245
|
* @returns {any}
|
|
324
246
|
*/
|
|
@@ -340,9 +262,6 @@ export class Document {
|
|
|
340
262
|
}
|
|
341
263
|
}
|
|
342
264
|
/**
|
|
343
|
-
* Replace the main card's body (the global Markdown body).
|
|
344
|
-
*
|
|
345
|
-
* Mutators never modify `warnings`.
|
|
346
265
|
* @param {string} body
|
|
347
266
|
*/
|
|
348
267
|
replaceBody(body) {
|
|
@@ -351,24 +270,10 @@ export class Document {
|
|
|
351
270
|
wasm.document_replaceBody(this.__wbg_ptr, ptr0, len0);
|
|
352
271
|
}
|
|
353
272
|
/**
|
|
354
|
-
* Read the schema version from a raw storage DTO string without
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
* that `fromJson` would reject. Use this to distinguish "this build is
|
|
359
|
-
* too old for the payload" from "the payload is corrupt" when
|
|
360
|
-
* [`fromJson`](Document::from_json) throws:
|
|
361
|
-
*
|
|
362
|
-
* ```js
|
|
363
|
-
* const v = Document.schemaVersionOf(blob);
|
|
364
|
-
* if (v === undefined) {
|
|
365
|
-
* // not a stored DTO at all — try fromMarkdown
|
|
366
|
-
* } else if (v !== Document.currentSchemaVersion()) {
|
|
367
|
-
* // newer (or older unmigrated) schema — prompt the user to upgrade
|
|
368
|
-
* } else {
|
|
369
|
-
* doc = Document.fromJson(blob);
|
|
370
|
-
* }
|
|
371
|
-
* ```
|
|
273
|
+
* Read the `schema` version tag from a raw storage DTO string without a
|
|
274
|
+
* full parse, or `undefined`. Returns unknown future versions as-is —
|
|
275
|
+
* useful to distinguish "build too old" from "payload corrupt" when
|
|
276
|
+
* `fromJson` throws.
|
|
372
277
|
* @param {string} json
|
|
373
278
|
* @returns {string | undefined}
|
|
374
279
|
*/
|
|
@@ -391,26 +296,18 @@ export class Document {
|
|
|
391
296
|
}
|
|
392
297
|
}
|
|
393
298
|
/**
|
|
394
|
-
* Replace the
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
* untouched. Schema-aware migration (clearing orphan fields, applying
|
|
398
|
-
* new defaults) is the caller's responsibility; `setCardTag` is a
|
|
399
|
-
* structural primitive.
|
|
400
|
-
*
|
|
401
|
-
* Throws if `index` is out of range or if `newTag` does not match
|
|
402
|
-
* `[a-z_][a-z0-9_]*`.
|
|
403
|
-
*
|
|
404
|
-
* Mutators never modify `warnings`.
|
|
299
|
+
* Replace the kind of the card at `index`. Payload and body are untouched;
|
|
300
|
+
* schema-aware migration is the caller's responsibility.
|
|
301
|
+
* Throws if `index` is out of range or `newKind` is invalid.
|
|
405
302
|
* @param {number} index
|
|
406
|
-
* @param {string}
|
|
303
|
+
* @param {string} new_kind
|
|
407
304
|
*/
|
|
408
|
-
|
|
305
|
+
setCardKind(index, new_kind) {
|
|
409
306
|
try {
|
|
410
307
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
411
|
-
const ptr0 = passStringToWasm0(
|
|
308
|
+
const ptr0 = passStringToWasm0(new_kind, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
412
309
|
const len0 = WASM_VECTOR_LEN;
|
|
413
|
-
wasm.
|
|
310
|
+
wasm.document_setCardKind(retptr, this.__wbg_ptr, index, ptr0, len0);
|
|
414
311
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
415
312
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
416
313
|
if (r1) {
|
|
@@ -421,16 +318,10 @@ export class Document {
|
|
|
421
318
|
}
|
|
422
319
|
}
|
|
423
320
|
/**
|
|
424
|
-
* Update a
|
|
425
|
-
*
|
|
426
|
-
* Convenience method: equivalent to `doc.mainMut().setField(name, value)`.
|
|
427
|
-
* Clears any existing `!fill` marker on the field.
|
|
321
|
+
* Update a payload field on the main card. Clears any existing `!fill` marker.
|
|
428
322
|
*
|
|
429
|
-
* Throws
|
|
430
|
-
* details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
|
|
323
|
+
* Throws if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
|
|
431
324
|
* not match `[a-z_][a-z0-9_]*`.
|
|
432
|
-
*
|
|
433
|
-
* Mutators never modify `warnings`.
|
|
434
325
|
* @param {string} name
|
|
435
326
|
* @param {any} value
|
|
436
327
|
*/
|
|
@@ -450,13 +341,8 @@ export class Document {
|
|
|
450
341
|
}
|
|
451
342
|
}
|
|
452
343
|
/**
|
|
453
|
-
* Update a
|
|
454
|
-
*
|
|
455
|
-
* Convenience method: equivalent to `doc.mainMut().setFill(name, value)`.
|
|
456
|
-
*
|
|
344
|
+
* Update a payload field on the main card and mark it as `!fill`.
|
|
457
345
|
* Throws on invalid name (see [`setField`](Document::set_field)).
|
|
458
|
-
*
|
|
459
|
-
* Mutators never modify `warnings`.
|
|
460
346
|
* @param {string} name
|
|
461
347
|
* @param {any} value
|
|
462
348
|
*/
|
|
@@ -476,11 +362,7 @@ export class Document {
|
|
|
476
362
|
}
|
|
477
363
|
}
|
|
478
364
|
/**
|
|
479
|
-
* Replace the QUILL reference string.
|
|
480
|
-
*
|
|
481
|
-
* Throws if `ref_str` is not a valid `QuillReference`.
|
|
482
|
-
*
|
|
483
|
-
* Mutators never modify `warnings`.
|
|
365
|
+
* Replace the QUILL reference string. Throws if `ref_str` is invalid.
|
|
484
366
|
* @param {string} ref_str
|
|
485
367
|
*/
|
|
486
368
|
setQuillRef(ref_str) {
|
|
@@ -501,36 +383,12 @@ export class Document {
|
|
|
501
383
|
/**
|
|
502
384
|
* Serialize this document to a versioned storage DTO string.
|
|
503
385
|
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
* [`fromJson`](Document::from_json) — the JS `JSON` global is not
|
|
508
|
-
* involved in either direction.
|
|
509
|
-
*
|
|
510
|
-
* Use this — not [`toMarkdown`](Document::to_markdown) — to persist a
|
|
511
|
-
* document across a process restart or crate upgrade; the wire format
|
|
512
|
-
* is frozen per `schema` version, whereas Markdown syntax evolves.
|
|
513
|
-
* Parse-time `warnings` are not part of the DTO.
|
|
514
|
-
*
|
|
515
|
-
* The result is standard JSON text, so callers that want to inspect it
|
|
516
|
-
* may `JSON.parse` it — but treating it as an opaque blob is the
|
|
517
|
-
* intended use.
|
|
386
|
+
* Prefer this over `toMarkdown` for persistence across restarts or crate
|
|
387
|
+
* upgrades — the wire format is frozen per `schema` version. Parse-time
|
|
388
|
+
* `warnings` are excluded from the DTO.
|
|
518
389
|
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* The output is a **byte-deterministic** function of the document's
|
|
522
|
-
* value within a given `schema` version: two documents that compare
|
|
523
|
-
* equal under [`equals`](Document::equals) serialize to byte-equal
|
|
524
|
-
* strings, and the same document re-serialized in a later patch or
|
|
525
|
-
* minor release of this crate (same `schema`) produces the same bytes.
|
|
526
|
-
* Content-hash use cases (template-divergence detection, cache keys)
|
|
527
|
-
* can rely on this without re-canonicalizing.
|
|
528
|
-
*
|
|
529
|
-
* Specifics: object fields are emitted in struct-declaration order;
|
|
530
|
-
* frontmatter field values preserve their YAML insertion order (no
|
|
531
|
-
* key sorting); whitespace is `serde_json`'s compact form (no spaces
|
|
532
|
-
* between tokens, no trailing newline); strings use `serde_json`'s
|
|
533
|
-
* standard escape set. A schema-version bump may change any of these.
|
|
390
|
+
* Output is **byte-deterministic** within a `schema` version: equal
|
|
391
|
+
* documents produce byte-equal output, safe for content-hash use cases.
|
|
534
392
|
* @returns {string}
|
|
535
393
|
*/
|
|
536
394
|
toJson() {
|
|
@@ -550,11 +408,8 @@ export class Document {
|
|
|
550
408
|
}
|
|
551
409
|
}
|
|
552
410
|
/**
|
|
553
|
-
* Emit canonical Quillmark Markdown.
|
|
554
|
-
*
|
|
555
|
-
* Returns the document serialised as a Quillmark Markdown string.
|
|
556
|
-
* The output is type-fidelity round-trip safe: re-parsing the result
|
|
557
|
-
* produces a `Document` equal to `self` by value and by type.
|
|
411
|
+
* Emit canonical Quillmark Markdown. Round-trip safe: re-parsing the
|
|
412
|
+
* result produces a `Document` equal to `self` by value and by type.
|
|
558
413
|
* @returns {string}
|
|
559
414
|
*/
|
|
560
415
|
toMarkdown() {
|
|
@@ -574,18 +429,11 @@ export class Document {
|
|
|
574
429
|
}
|
|
575
430
|
}
|
|
576
431
|
/**
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
* ```js
|
|
584
|
-
* const doc = Document.tryFromJson(content) ?? Document.fromMarkdown(content);
|
|
585
|
-
* ```
|
|
586
|
-
*
|
|
587
|
-
* `undefined` only ever means "not a storage DTO" — `fromMarkdown`
|
|
588
|
-
* still throws on genuinely malformed markdown.
|
|
432
|
+
* Like [`fromJson`](Document::from_json) but returns `undefined` instead
|
|
433
|
+
* of throwing when `json` is not a valid storage DTO — use to
|
|
434
|
+
* discriminate format without exceptions as control flow.
|
|
435
|
+
* `undefined` means "not a storage DTO"; `fromMarkdown` still throws on
|
|
436
|
+
* genuinely malformed markdown.
|
|
589
437
|
* @param {string} json
|
|
590
438
|
* @returns {Document | undefined}
|
|
591
439
|
*/
|
|
@@ -596,11 +444,7 @@ export class Document {
|
|
|
596
444
|
return ret === 0 ? undefined : Document.__wrap(ret);
|
|
597
445
|
}
|
|
598
446
|
/**
|
|
599
|
-
* Replace the body of the card at `index`.
|
|
600
|
-
*
|
|
601
|
-
* Throws if `index` is out of range.
|
|
602
|
-
*
|
|
603
|
-
* Mutators never modify `warnings`.
|
|
447
|
+
* Replace the body of the card at `index`. Throws if out of range.
|
|
604
448
|
* @param {number} index
|
|
605
449
|
* @param {string} body
|
|
606
450
|
*/
|
|
@@ -621,13 +465,7 @@ export class Document {
|
|
|
621
465
|
}
|
|
622
466
|
/**
|
|
623
467
|
* Update a field on the card at `index`.
|
|
624
|
-
*
|
|
625
|
-
* Convenience method: equivalent to `doc.card_mut(index)?.set_field(name, value)`.
|
|
626
|
-
*
|
|
627
|
-
* Throws if `index` is out of range, `name` is reserved or invalid, or
|
|
628
|
-
* `value` cannot be serialized.
|
|
629
|
-
*
|
|
630
|
-
* Mutators never modify `warnings`.
|
|
468
|
+
* Throws if `index` is out of range, `name` is reserved or invalid.
|
|
631
469
|
* @param {number} index
|
|
632
470
|
* @param {string} name
|
|
633
471
|
* @param {any} value
|
|
@@ -648,7 +486,6 @@ export class Document {
|
|
|
648
486
|
}
|
|
649
487
|
}
|
|
650
488
|
/**
|
|
651
|
-
* Non-fatal parse-time warnings as an array of typed `Diagnostic` objects.
|
|
652
489
|
* @returns {Diagnostic[]}
|
|
653
490
|
*/
|
|
654
491
|
get warnings() {
|
|
@@ -658,9 +495,6 @@ export class Document {
|
|
|
658
495
|
}
|
|
659
496
|
if (Symbol.dispose) Document.prototype[Symbol.dispose] = Document.prototype.free;
|
|
660
497
|
|
|
661
|
-
/**
|
|
662
|
-
* Opaque, shareable Quill handle.
|
|
663
|
-
*/
|
|
664
498
|
export class Quill {
|
|
665
499
|
static __wrap(ptr) {
|
|
666
500
|
ptr = ptr >>> 0;
|
|
@@ -700,13 +534,8 @@ export class Quill {
|
|
|
700
534
|
}
|
|
701
535
|
}
|
|
702
536
|
/**
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
* Returns `null` if `cardKind` is not declared in this quill's schema.
|
|
706
|
-
* Otherwise returns a plain JS object shaped like a single entry in
|
|
707
|
-
* [`Form::cards`].
|
|
708
|
-
*
|
|
709
|
-
* [`Form::cards`]: quillmark::form::Form::cards
|
|
537
|
+
* Blank `FormCard` for the given card kind. Returns `null` if `cardKind`
|
|
538
|
+
* is not declared in this quill's schema.
|
|
710
539
|
* @param {string} card_kind
|
|
711
540
|
* @returns {FormCard | null}
|
|
712
541
|
*/
|
|
@@ -728,13 +557,8 @@ export class Quill {
|
|
|
728
557
|
}
|
|
729
558
|
}
|
|
730
559
|
/**
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
* Returns a plain JS object with the same shape as one entry in
|
|
734
|
-
* [`Form::main`]. Every declared field's `source` is `"default"` (when
|
|
735
|
-
* the schema declares a default) or `"missing"`.
|
|
736
|
-
*
|
|
737
|
-
* [`Form::main`]: quillmark::form::Form::main
|
|
560
|
+
* Blank `FormCard` for the main card with no document values.
|
|
561
|
+
* Every field's `source` is `"default"` or `"missing"`.
|
|
738
562
|
* @returns {FormCard}
|
|
739
563
|
*/
|
|
740
564
|
blankMain() {
|
|
@@ -753,7 +577,6 @@ export class Quill {
|
|
|
753
577
|
}
|
|
754
578
|
}
|
|
755
579
|
/**
|
|
756
|
-
* Auto-generated annotated Markdown blueprint for LLM consumers.
|
|
757
580
|
* @returns {string}
|
|
758
581
|
*/
|
|
759
582
|
get blueprint() {
|
|
@@ -773,23 +596,8 @@ export class Quill {
|
|
|
773
596
|
}
|
|
774
597
|
}
|
|
775
598
|
/**
|
|
776
|
-
* The schema-aware form view of `doc`.
|
|
777
|
-
*
|
|
778
|
-
* Returns a plain JS object (not a class) that is immediately
|
|
779
|
-
* `JSON.stringify`-able. The shape mirrors [`Form`]:
|
|
780
|
-
*
|
|
781
|
-
* ```json
|
|
782
|
-
* {
|
|
783
|
-
* "main": { "schema": {...}, "values": { "field": {...} } },
|
|
784
|
-
* "cards": [ ... ],
|
|
785
|
-
* "diagnostics": [ ... ]
|
|
786
|
-
* }
|
|
787
|
-
* ```
|
|
788
|
-
*
|
|
789
|
-
* **Snapshot semantics.** This is a read-only snapshot of the document
|
|
790
|
-
* at call time. Subsequent edits to `doc` require calling `form` again.
|
|
791
|
-
*
|
|
792
|
-
* [`Form`]: quillmark::form::Form
|
|
599
|
+
* The schema-aware form view of `doc`. Read-only snapshot at call time;
|
|
600
|
+
* subsequent edits to `doc` require calling `form` again.
|
|
793
601
|
* @param {Document} doc
|
|
794
602
|
* @returns {Form}
|
|
795
603
|
*/
|
|
@@ -811,13 +619,7 @@ export class Quill {
|
|
|
811
619
|
}
|
|
812
620
|
/**
|
|
813
621
|
* Identity snapshot of the `quill:` section of `Quill.yaml`, plus
|
|
814
|
-
* `supportedFormats` and any
|
|
815
|
-
*
|
|
816
|
-
* Consumers that need validation run their own validator against
|
|
817
|
-
* `metadata.schema`.
|
|
818
|
-
*
|
|
819
|
-
* Equivalent by value for the lifetime of the handle; the quill is
|
|
820
|
-
* immutable once constructed.
|
|
622
|
+
* `supportedFormats` and any extra `quill:` keys.
|
|
821
623
|
* @returns {QuillMetadata}
|
|
822
624
|
*/
|
|
823
625
|
get metadata() {
|
|
@@ -825,7 +627,6 @@ export class Quill {
|
|
|
825
627
|
return takeObject(ret);
|
|
826
628
|
}
|
|
827
629
|
/**
|
|
828
|
-
* Open an iterative render session for page-selective rendering.
|
|
829
630
|
* @param {Document} doc
|
|
830
631
|
* @returns {RenderSession}
|
|
831
632
|
*/
|
|
@@ -846,7 +647,6 @@ export class Quill {
|
|
|
846
647
|
}
|
|
847
648
|
}
|
|
848
649
|
/**
|
|
849
|
-
* Render a document to final artifacts.
|
|
850
650
|
* @param {Document} doc
|
|
851
651
|
* @param {RenderOptions | null} [opts]
|
|
852
652
|
* @returns {RenderResult}
|
|
@@ -876,12 +676,9 @@ export class Quill {
|
|
|
876
676
|
return takeObject(ret);
|
|
877
677
|
}
|
|
878
678
|
/**
|
|
879
|
-
* Whether this quill's backend supports canvas preview.
|
|
880
|
-
*
|
|
881
679
|
* `true` iff `RenderSession.paint` and `RenderSession.pageSize` will
|
|
882
|
-
* succeed for sessions opened by this quill. Use
|
|
883
|
-
* probe before mounting a canvas-based preview UI
|
|
884
|
-
* remains the enforcement contract.
|
|
680
|
+
* succeed for sessions opened by this quill. Use as a precondition
|
|
681
|
+
* probe before mounting a canvas-based preview UI.
|
|
885
682
|
* @returns {boolean}
|
|
886
683
|
*/
|
|
887
684
|
get supportsCanvas() {
|
|
@@ -891,9 +688,6 @@ export class Quill {
|
|
|
891
688
|
}
|
|
892
689
|
if (Symbol.dispose) Quill.prototype[Symbol.dispose] = Quill.prototype.free;
|
|
893
690
|
|
|
894
|
-
/**
|
|
895
|
-
* Quillmark WASM Engine
|
|
896
|
-
*/
|
|
897
691
|
export class Quillmark {
|
|
898
692
|
__destroy_into_raw() {
|
|
899
693
|
const ptr = this.__wbg_ptr;
|
|
@@ -905,9 +699,6 @@ export class Quillmark {
|
|
|
905
699
|
const ptr = this.__destroy_into_raw();
|
|
906
700
|
wasm.__wbg_quillmark_free(ptr, 0);
|
|
907
701
|
}
|
|
908
|
-
/**
|
|
909
|
-
* JavaScript constructor: `new Quillmark()`
|
|
910
|
-
*/
|
|
911
702
|
constructor() {
|
|
912
703
|
const ret = wasm.quillmark_new();
|
|
913
704
|
this.__wbg_ptr = ret >>> 0;
|
|
@@ -943,19 +734,12 @@ export class Quillmark {
|
|
|
943
734
|
if (Symbol.dispose) Quillmark.prototype[Symbol.dispose] = Quillmark.prototype.free;
|
|
944
735
|
|
|
945
736
|
/**
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
* Created via [`Quill::open`]. Holds the compiled output so that
|
|
949
|
-
* [`RenderSession::render`], [`RenderSession::paint`], and
|
|
950
|
-
* [`RenderSession::page_size`] can be called repeatedly without
|
|
951
|
-
* recompiling.
|
|
737
|
+
* Iterative render handle backed by an immutable compiled snapshot.
|
|
952
738
|
*
|
|
953
|
-
* **Empty documents.** A document
|
|
954
|
-
*
|
|
955
|
-
* `0
|
|
956
|
-
*
|
|
957
|
-
* (pageCount=0)"`. Hosts that surface "no pages to preview" UI should
|
|
958
|
-
* branch on `pageCount === 0` rather than on a thrown error.
|
|
739
|
+
* **Empty documents.** A zero-page document yields a valid session
|
|
740
|
+
* (`pageCount === 0`); `paint(ctx, 0)` or `pageSize(0)` throws with
|
|
741
|
+
* `"page index 0 out of range (pageCount=0)"`. Branch on `pageCount === 0`
|
|
742
|
+
* rather than catching the error.
|
|
959
743
|
*/
|
|
960
744
|
export class RenderSession {
|
|
961
745
|
static __wrap(ptr) {
|
|
@@ -977,9 +761,6 @@ export class RenderSession {
|
|
|
977
761
|
}
|
|
978
762
|
/**
|
|
979
763
|
* The backend that produced this session (e.g. `"typst"`).
|
|
980
|
-
*
|
|
981
|
-
* Equal to the `backendId` of the [`Quill`] that opened this session
|
|
982
|
-
* (sessions inherit their quill's backend), so checking either is fine.
|
|
983
764
|
* @returns {string}
|
|
984
765
|
*/
|
|
985
766
|
get backendId() {
|
|
@@ -999,10 +780,6 @@ export class RenderSession {
|
|
|
999
780
|
}
|
|
1000
781
|
}
|
|
1001
782
|
/**
|
|
1002
|
-
* Number of pages in this render session.
|
|
1003
|
-
*
|
|
1004
|
-
* Stable for the lifetime of the session — the underlying compiled
|
|
1005
|
-
* document is an immutable snapshot.
|
|
1006
783
|
* @returns {number}
|
|
1007
784
|
*/
|
|
1008
785
|
get pageCount() {
|
|
@@ -1011,18 +788,7 @@ export class RenderSession {
|
|
|
1011
788
|
}
|
|
1012
789
|
/**
|
|
1013
790
|
* Page dimensions in Typst points (1 pt = 1/72 inch).
|
|
1014
|
-
*
|
|
1015
|
-
* Report-only: the painter sizes the canvas itself based on
|
|
1016
|
-
* `PaintOptions`. Exposed for consumers that need page geometry
|
|
1017
|
-
* up-front (e.g. to lay out a scrollable list of canvases before
|
|
1018
|
-
* any pixels are rendered).
|
|
1019
|
-
*
|
|
1020
|
-
* Stable for a given `page` across the session's lifetime — the
|
|
1021
|
-
* compiled document is an immutable snapshot, so callers can cache
|
|
1022
|
-
* results.
|
|
1023
|
-
*
|
|
1024
|
-
* Throws if the underlying backend has no canvas painter (i.e. is not
|
|
1025
|
-
* the Typst backend) or if `page` is out of range.
|
|
791
|
+
* Throws if the backend has no canvas painter or `page` is out of range.
|
|
1026
792
|
* @param {number} page
|
|
1027
793
|
* @returns {PageSize}
|
|
1028
794
|
*/
|
|
@@ -1042,42 +808,14 @@ export class RenderSession {
|
|
|
1042
808
|
}
|
|
1043
809
|
}
|
|
1044
810
|
/**
|
|
1045
|
-
* Paint `page` into a
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
* `
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
* itself; consumers must not. The painter does not touch
|
|
1054
|
-
* `canvas.style.*` — that's layout, owned by the consumer (see
|
|
1055
|
-
* `PaintResult.layoutWidth` / `layoutHeight`).
|
|
1056
|
-
*
|
|
1057
|
-
* `opts.layoutScale` (default 1.0) is layout-space pixels per Typst
|
|
1058
|
-
* point and determines the canvas's display-box size. `opts.densityScale`
|
|
1059
|
-
* (default 1.0) is the rasterization density multiplier the consumer
|
|
1060
|
-
* folds `window.devicePixelRatio`, in-app zoom, and
|
|
1061
|
-
* `visualViewport.scale` (pinch-zoom) into. The effective
|
|
1062
|
-
* rasterization scale is `layoutScale * densityScale`.
|
|
1063
|
-
*
|
|
1064
|
-
* If `layoutScale * densityScale` would exceed the safe backing-store
|
|
1065
|
-
* maximum (16384 px per side), `densityScale` is clamped
|
|
1066
|
-
* proportionally so the largest dimension fits. The actual
|
|
1067
|
-
* backing-store dimensions are reported in the returned
|
|
1068
|
-
* `PaintResult` — compare against
|
|
1069
|
-
* `round(layoutWidth * densityScale)` to detect clamping.
|
|
1070
|
-
*
|
|
1071
|
-
* Each call resets the backing store (`paint` is always a full
|
|
1072
|
-
* repaint). Consumers do not need to call `clearRect`.
|
|
1073
|
-
*
|
|
1074
|
-
* Throws when:
|
|
1075
|
-
* - the backend does not support canvas preview (message includes the
|
|
1076
|
-
* resolved `backendId`),
|
|
1077
|
-
* - `page` is out of range,
|
|
1078
|
-
* - `ctx` is neither `CanvasRenderingContext2D` nor
|
|
1079
|
-
* `OffscreenCanvasRenderingContext2D`,
|
|
1080
|
-
* - `opts.layoutScale` or `opts.densityScale` is non-finite or `<= 0`.
|
|
811
|
+
* Paint `page` into a `CanvasRenderingContext2D` or
|
|
812
|
+
* `OffscreenCanvasRenderingContext2D`. The painter owns
|
|
813
|
+
* `canvas.width`/`height` (no `clearRect` needed); consumers own
|
|
814
|
+
* `canvas.style.*`. If `layoutScale * densityScale` exceeds 16384 px
|
|
815
|
+
* per side, `densityScale` is clamped — detect via `PaintResult.pixelWidth`.
|
|
816
|
+
*
|
|
817
|
+
* Throws if the backend has no canvas painter, `page` is out of range,
|
|
818
|
+
* `ctx` is the wrong type, or either scale is non-finite or `<= 0`.
|
|
1081
819
|
* @param {CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D} ctx
|
|
1082
820
|
* @param {number} page
|
|
1083
821
|
* @param {PaintOptions | undefined} opts
|
|
@@ -1099,7 +837,6 @@ export class RenderSession {
|
|
|
1099
837
|
}
|
|
1100
838
|
}
|
|
1101
839
|
/**
|
|
1102
|
-
* Render all or selected pages from this session.
|
|
1103
840
|
* @param {RenderOptions | null} [opts]
|
|
1104
841
|
* @returns {RenderResult}
|
|
1105
842
|
*/
|
|
@@ -1119,11 +856,7 @@ export class RenderSession {
|
|
|
1119
856
|
}
|
|
1120
857
|
}
|
|
1121
858
|
/**
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
1124
|
-
* `true` iff [`paint`](Self::paint) and [`page_size`](Self::page_size)
|
|
1125
|
-
* will succeed. Equal to `Quill.supportsCanvas` for the quill that
|
|
1126
|
-
* opened this session.
|
|
859
|
+
* `true` iff `paint` and `pageSize` will succeed for this session.
|
|
1127
860
|
* @returns {boolean}
|
|
1128
861
|
*/
|
|
1129
862
|
get supportsCanvas() {
|
|
@@ -1131,14 +864,8 @@ export class RenderSession {
|
|
|
1131
864
|
return ret !== 0;
|
|
1132
865
|
}
|
|
1133
866
|
/**
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
1136
|
-
* Snapshot of any non-fatal diagnostics emitted while opening the
|
|
1137
|
-
* session (e.g. version compatibility shims). Stable across the
|
|
1138
|
-
* session's lifetime. These are also appended to
|
|
1139
|
-
* [`RenderResult.warnings`] on every `render()` call; the accessor
|
|
1140
|
-
* surfaces them to canvas-preview consumers that don't go through
|
|
1141
|
-
* `render()`.
|
|
867
|
+
* Non-fatal diagnostics emitted when opening the session. Also appended
|
|
868
|
+
* to `RenderResult.warnings` on each `render()` call.
|
|
1142
869
|
* @returns {Diagnostic[]}
|
|
1143
870
|
*/
|
|
1144
871
|
get warnings() {
|