@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_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,10 +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).
|
|
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.
|
|
70
48
|
* @returns {string}
|
|
71
49
|
*/
|
|
72
50
|
static currentSchemaVersion() {
|
|
@@ -86,14 +64,8 @@ export class Document {
|
|
|
86
64
|
}
|
|
87
65
|
}
|
|
88
66
|
/**
|
|
89
|
-
* Structural equality
|
|
90
|
-
*
|
|
91
|
-
* Compares `main` and `cards` by value (matching core's [`PartialEq`]).
|
|
92
|
-
* Parse-time `warnings` are intentionally excluded — they describe the
|
|
93
|
-
* source text, not the document's content.
|
|
94
|
-
*
|
|
95
|
-
* Use this to debounce upstream prop updates: keep the last parsed
|
|
96
|
-
* `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.
|
|
97
69
|
* @param {Document} other
|
|
98
70
|
* @returns {boolean}
|
|
99
71
|
*/
|
|
@@ -103,19 +75,12 @@ export class Document {
|
|
|
103
75
|
return ret !== 0;
|
|
104
76
|
}
|
|
105
77
|
/**
|
|
106
|
-
* Reconstruct a `Document` from
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* the versioned storage DTO. Parsing and schema dispatch happen inside
|
|
110
|
-
* the module via `serde_json`; the JS `JSON` global is not involved.
|
|
111
|
-
* Unknown `schema` tags are rejected.
|
|
112
|
-
*
|
|
113
|
-
* The reconstructed document carries no parse-time warnings — the DTO
|
|
114
|
-
* describes content, not source text — so `.warnings` is always empty.
|
|
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).
|
|
115
81
|
*
|
|
116
|
-
* Throws
|
|
117
|
-
*
|
|
118
|
-
* reference).
|
|
82
|
+
* Throws if `json` is not a valid storage DTO (malformed JSON, unknown
|
|
83
|
+
* `schema`, missing fields, or unparseable quill reference).
|
|
119
84
|
* @param {string} json
|
|
120
85
|
* @returns {Document}
|
|
121
86
|
*/
|
|
@@ -137,10 +102,7 @@ export class Document {
|
|
|
137
102
|
}
|
|
138
103
|
}
|
|
139
104
|
/**
|
|
140
|
-
* Parse markdown into a typed Document.
|
|
141
|
-
*
|
|
142
|
-
* Returns the document with any parse-time warnings accessible via `.warnings`.
|
|
143
|
-
* Throws on parse errors.
|
|
105
|
+
* Parse markdown into a typed Document. Throws on parse errors.
|
|
144
106
|
* @param {string} markdown
|
|
145
107
|
* @returns {Document}
|
|
146
108
|
*/
|
|
@@ -162,11 +124,7 @@ export class Document {
|
|
|
162
124
|
}
|
|
163
125
|
}
|
|
164
126
|
/**
|
|
165
|
-
* Insert a card at
|
|
166
|
-
*
|
|
167
|
-
* `index` must be in `0..=cards.length`. Out-of-range throws an `Error`.
|
|
168
|
-
*
|
|
169
|
-
* Mutators never modify `warnings`.
|
|
127
|
+
* Insert a card at `index` (must be in `0..=cards.length`).
|
|
170
128
|
* @param {number} index
|
|
171
129
|
* @param {CardInput} card
|
|
172
130
|
*/
|
|
@@ -184,13 +142,8 @@ export class Document {
|
|
|
184
142
|
}
|
|
185
143
|
}
|
|
186
144
|
/**
|
|
187
|
-
* The document's main (entry) card.
|
|
188
|
-
*
|
|
189
|
-
* Carries the QUILL sentinel, the document-level frontmatter, and the
|
|
190
|
-
* global body. Frontmatter/body reads and mutations go through this
|
|
191
|
-
* handle — there are no document-level shortcuts after the rework.
|
|
192
|
-
*
|
|
193
|
-
* 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.
|
|
194
147
|
* @returns {Card}
|
|
195
148
|
*/
|
|
196
149
|
get main() {
|
|
@@ -198,12 +151,7 @@ export class Document {
|
|
|
198
151
|
return takeObject(ret);
|
|
199
152
|
}
|
|
200
153
|
/**
|
|
201
|
-
* Move the card at `from` to position `to`.
|
|
202
|
-
*
|
|
203
|
-
* `from == to` is a no-op. Both indices must be in `0..cards.length`.
|
|
204
|
-
* Out-of-range throws an `Error`.
|
|
205
|
-
*
|
|
206
|
-
* Mutators never modify `warnings`.
|
|
154
|
+
* Move the card at `from` to position `to`. `from == to` is a no-op.
|
|
207
155
|
* @param {number} from
|
|
208
156
|
* @param {number} to
|
|
209
157
|
*/
|
|
@@ -222,13 +170,7 @@ export class Document {
|
|
|
222
170
|
}
|
|
223
171
|
/**
|
|
224
172
|
* Append a card to the end of the card list.
|
|
225
|
-
*
|
|
226
|
-
* `card` must be a JS object with a `tag` string field and optional
|
|
227
|
-
* `fields` (object) and `body` (string).
|
|
228
|
-
*
|
|
229
|
-
* Throws an `Error` if `card.tag` is not a valid tag name.
|
|
230
|
-
*
|
|
231
|
-
* Mutators never modify `warnings`.
|
|
173
|
+
* Throws if `card.kind` is not a valid kind name.
|
|
232
174
|
* @param {CardInput} card
|
|
233
175
|
*/
|
|
234
176
|
pushCard(card) {
|
|
@@ -245,7 +187,6 @@ export class Document {
|
|
|
245
187
|
}
|
|
246
188
|
}
|
|
247
189
|
/**
|
|
248
|
-
* The QUILL reference string (e.g. `"usaf_memo@0.1"`).
|
|
249
190
|
* @returns {string}
|
|
250
191
|
*/
|
|
251
192
|
get quillRef() {
|
|
@@ -265,9 +206,6 @@ export class Document {
|
|
|
265
206
|
}
|
|
266
207
|
}
|
|
267
208
|
/**
|
|
268
|
-
* Remove the card at `index` and return it, or `undefined` if out of range.
|
|
269
|
-
*
|
|
270
|
-
* Mutators never modify `warnings`.
|
|
271
209
|
* @param {number} index
|
|
272
210
|
* @returns {Card | undefined}
|
|
273
211
|
*/
|
|
@@ -276,13 +214,8 @@ export class Document {
|
|
|
276
214
|
return takeObject(ret);
|
|
277
215
|
}
|
|
278
216
|
/**
|
|
279
|
-
* Remove a
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* Throws if `index` is out of range, `name` is reserved, or `name` does
|
|
283
|
-
* not match `[a-z_][a-z0-9_]*`.
|
|
284
|
-
*
|
|
285
|
-
* 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.
|
|
286
219
|
* @param {number} index
|
|
287
220
|
* @param {string} name
|
|
288
221
|
* @returns {any}
|
|
@@ -305,14 +238,9 @@ export class Document {
|
|
|
305
238
|
}
|
|
306
239
|
}
|
|
307
240
|
/**
|
|
308
|
-
* Remove a
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
* and details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`)
|
|
312
|
-
* or does not match `[a-z_][a-z0-9_]*`. Absence of an otherwise-valid
|
|
313
|
-
* name returns `undefined`.
|
|
314
|
-
*
|
|
315
|
-
* 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_]*`.
|
|
316
244
|
* @param {string} name
|
|
317
245
|
* @returns {any}
|
|
318
246
|
*/
|
|
@@ -334,9 +262,6 @@ export class Document {
|
|
|
334
262
|
}
|
|
335
263
|
}
|
|
336
264
|
/**
|
|
337
|
-
* Replace the main card's body (the global Markdown body).
|
|
338
|
-
*
|
|
339
|
-
* Mutators never modify `warnings`.
|
|
340
265
|
* @param {string} body
|
|
341
266
|
*/
|
|
342
267
|
replaceBody(body) {
|
|
@@ -345,24 +270,10 @@ export class Document {
|
|
|
345
270
|
wasm.document_replaceBody(this.__wbg_ptr, ptr0, len0);
|
|
346
271
|
}
|
|
347
272
|
/**
|
|
348
|
-
* Read the schema version from a raw storage DTO string without
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* that `fromJson` would reject. Use this to distinguish "this build is
|
|
353
|
-
* too old for the payload" from "the payload is corrupt" when
|
|
354
|
-
* [`fromJson`](Document::from_json) throws:
|
|
355
|
-
*
|
|
356
|
-
* ```js
|
|
357
|
-
* const v = Document.schemaVersionOf(blob);
|
|
358
|
-
* if (v === undefined) {
|
|
359
|
-
* // not a stored DTO at all — try fromMarkdown
|
|
360
|
-
* } else if (v !== Document.currentSchemaVersion()) {
|
|
361
|
-
* // newer (or older unmigrated) schema — prompt the user to upgrade
|
|
362
|
-
* } else {
|
|
363
|
-
* doc = Document.fromJson(blob);
|
|
364
|
-
* }
|
|
365
|
-
* ```
|
|
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.
|
|
366
277
|
* @param {string} json
|
|
367
278
|
* @returns {string | undefined}
|
|
368
279
|
*/
|
|
@@ -385,26 +296,18 @@ export class Document {
|
|
|
385
296
|
}
|
|
386
297
|
}
|
|
387
298
|
/**
|
|
388
|
-
* Replace the
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* untouched. Schema-aware migration (clearing orphan fields, applying
|
|
392
|
-
* new defaults) is the caller's responsibility; `setCardTag` is a
|
|
393
|
-
* structural primitive.
|
|
394
|
-
*
|
|
395
|
-
* Throws if `index` is out of range or if `newTag` does not match
|
|
396
|
-
* `[a-z_][a-z0-9_]*`.
|
|
397
|
-
*
|
|
398
|
-
* 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.
|
|
399
302
|
* @param {number} index
|
|
400
|
-
* @param {string}
|
|
303
|
+
* @param {string} new_kind
|
|
401
304
|
*/
|
|
402
|
-
|
|
305
|
+
setCardKind(index, new_kind) {
|
|
403
306
|
try {
|
|
404
307
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
405
|
-
const ptr0 = passStringToWasm0(
|
|
308
|
+
const ptr0 = passStringToWasm0(new_kind, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
406
309
|
const len0 = WASM_VECTOR_LEN;
|
|
407
|
-
wasm.
|
|
310
|
+
wasm.document_setCardKind(retptr, this.__wbg_ptr, index, ptr0, len0);
|
|
408
311
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
409
312
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
410
313
|
if (r1) {
|
|
@@ -415,16 +318,10 @@ export class Document {
|
|
|
415
318
|
}
|
|
416
319
|
}
|
|
417
320
|
/**
|
|
418
|
-
* Update a
|
|
419
|
-
*
|
|
420
|
-
* Convenience method: equivalent to `doc.mainMut().setField(name, value)`.
|
|
421
|
-
* Clears any existing `!fill` marker on the field.
|
|
321
|
+
* Update a payload field on the main card. Clears any existing `!fill` marker.
|
|
422
322
|
*
|
|
423
|
-
* Throws
|
|
424
|
-
* details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
|
|
323
|
+
* Throws if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
|
|
425
324
|
* not match `[a-z_][a-z0-9_]*`.
|
|
426
|
-
*
|
|
427
|
-
* Mutators never modify `warnings`.
|
|
428
325
|
* @param {string} name
|
|
429
326
|
* @param {any} value
|
|
430
327
|
*/
|
|
@@ -444,13 +341,8 @@ export class Document {
|
|
|
444
341
|
}
|
|
445
342
|
}
|
|
446
343
|
/**
|
|
447
|
-
* Update a
|
|
448
|
-
*
|
|
449
|
-
* Convenience method: equivalent to `doc.mainMut().setFill(name, value)`.
|
|
450
|
-
*
|
|
344
|
+
* Update a payload field on the main card and mark it as `!fill`.
|
|
451
345
|
* Throws on invalid name (see [`setField`](Document::set_field)).
|
|
452
|
-
*
|
|
453
|
-
* Mutators never modify `warnings`.
|
|
454
346
|
* @param {string} name
|
|
455
347
|
* @param {any} value
|
|
456
348
|
*/
|
|
@@ -470,11 +362,7 @@ export class Document {
|
|
|
470
362
|
}
|
|
471
363
|
}
|
|
472
364
|
/**
|
|
473
|
-
* Replace the QUILL reference string.
|
|
474
|
-
*
|
|
475
|
-
* Throws if `ref_str` is not a valid `QuillReference`.
|
|
476
|
-
*
|
|
477
|
-
* Mutators never modify `warnings`.
|
|
365
|
+
* Replace the QUILL reference string. Throws if `ref_str` is invalid.
|
|
478
366
|
* @param {string} ref_str
|
|
479
367
|
*/
|
|
480
368
|
setQuillRef(ref_str) {
|
|
@@ -495,52 +383,33 @@ export class Document {
|
|
|
495
383
|
/**
|
|
496
384
|
* Serialize this document to a versioned storage DTO string.
|
|
497
385
|
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
* [`fromJson`](Document::from_json) — the JS `JSON` global is not
|
|
502
|
-
* involved in either direction.
|
|
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.
|
|
503
389
|
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
* is frozen per `schema` version, whereas Markdown syntax evolves.
|
|
507
|
-
* Parse-time `warnings` are not part of the DTO.
|
|
508
|
-
*
|
|
509
|
-
* The result is standard JSON text, so callers that want to inspect it
|
|
510
|
-
* may `JSON.parse` it — but treating it as an opaque blob is the
|
|
511
|
-
* intended use.
|
|
390
|
+
* Output is **byte-deterministic** within a `schema` version: equal
|
|
391
|
+
* documents produce byte-equal output, safe for content-hash use cases.
|
|
512
392
|
* @returns {string}
|
|
513
393
|
*/
|
|
514
394
|
toJson() {
|
|
515
|
-
let
|
|
516
|
-
let
|
|
395
|
+
let deferred1_0;
|
|
396
|
+
let deferred1_1;
|
|
517
397
|
try {
|
|
518
398
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
519
399
|
wasm.document_toJson(retptr, this.__wbg_ptr);
|
|
520
400
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
521
401
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
var len1 = r1;
|
|
526
|
-
if (r3) {
|
|
527
|
-
ptr1 = 0; len1 = 0;
|
|
528
|
-
throw takeObject(r2);
|
|
529
|
-
}
|
|
530
|
-
deferred2_0 = ptr1;
|
|
531
|
-
deferred2_1 = len1;
|
|
532
|
-
return getStringFromWasm0(ptr1, len1);
|
|
402
|
+
deferred1_0 = r0;
|
|
403
|
+
deferred1_1 = r1;
|
|
404
|
+
return getStringFromWasm0(r0, r1);
|
|
533
405
|
} finally {
|
|
534
406
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
535
|
-
wasm.__wbindgen_export4(
|
|
407
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
536
408
|
}
|
|
537
409
|
}
|
|
538
410
|
/**
|
|
539
|
-
* Emit canonical Quillmark Markdown.
|
|
540
|
-
*
|
|
541
|
-
* Returns the document serialised as a Quillmark Markdown string.
|
|
542
|
-
* The output is type-fidelity round-trip safe: re-parsing the result
|
|
543
|
-
* 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.
|
|
544
413
|
* @returns {string}
|
|
545
414
|
*/
|
|
546
415
|
toMarkdown() {
|
|
@@ -560,18 +429,11 @@ export class Document {
|
|
|
560
429
|
}
|
|
561
430
|
}
|
|
562
431
|
/**
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* ```js
|
|
570
|
-
* const doc = Document.tryFromJson(content) ?? Document.fromMarkdown(content);
|
|
571
|
-
* ```
|
|
572
|
-
*
|
|
573
|
-
* `undefined` only ever means "not a storage DTO" — `fromMarkdown`
|
|
574
|
-
* 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.
|
|
575
437
|
* @param {string} json
|
|
576
438
|
* @returns {Document | undefined}
|
|
577
439
|
*/
|
|
@@ -582,11 +444,7 @@ export class Document {
|
|
|
582
444
|
return ret === 0 ? undefined : Document.__wrap(ret);
|
|
583
445
|
}
|
|
584
446
|
/**
|
|
585
|
-
* Replace the body of the card at `index`.
|
|
586
|
-
*
|
|
587
|
-
* Throws if `index` is out of range.
|
|
588
|
-
*
|
|
589
|
-
* Mutators never modify `warnings`.
|
|
447
|
+
* Replace the body of the card at `index`. Throws if out of range.
|
|
590
448
|
* @param {number} index
|
|
591
449
|
* @param {string} body
|
|
592
450
|
*/
|
|
@@ -607,13 +465,7 @@ export class Document {
|
|
|
607
465
|
}
|
|
608
466
|
/**
|
|
609
467
|
* Update a field on the card at `index`.
|
|
610
|
-
*
|
|
611
|
-
* Convenience method: equivalent to `doc.card_mut(index)?.set_field(name, value)`.
|
|
612
|
-
*
|
|
613
|
-
* Throws if `index` is out of range, `name` is reserved or invalid, or
|
|
614
|
-
* `value` cannot be serialized.
|
|
615
|
-
*
|
|
616
|
-
* Mutators never modify `warnings`.
|
|
468
|
+
* Throws if `index` is out of range, `name` is reserved or invalid.
|
|
617
469
|
* @param {number} index
|
|
618
470
|
* @param {string} name
|
|
619
471
|
* @param {any} value
|
|
@@ -634,7 +486,6 @@ export class Document {
|
|
|
634
486
|
}
|
|
635
487
|
}
|
|
636
488
|
/**
|
|
637
|
-
* Non-fatal parse-time warnings as an array of typed `Diagnostic` objects.
|
|
638
489
|
* @returns {Diagnostic[]}
|
|
639
490
|
*/
|
|
640
491
|
get warnings() {
|
|
@@ -644,9 +495,6 @@ export class Document {
|
|
|
644
495
|
}
|
|
645
496
|
if (Symbol.dispose) Document.prototype[Symbol.dispose] = Document.prototype.free;
|
|
646
497
|
|
|
647
|
-
/**
|
|
648
|
-
* Opaque, shareable Quill handle.
|
|
649
|
-
*/
|
|
650
498
|
export class Quill {
|
|
651
499
|
static __wrap(ptr) {
|
|
652
500
|
ptr = ptr >>> 0;
|
|
@@ -686,13 +534,8 @@ export class Quill {
|
|
|
686
534
|
}
|
|
687
535
|
}
|
|
688
536
|
/**
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* Returns `null` if `cardKind` is not declared in this quill's schema.
|
|
692
|
-
* Otherwise returns a plain JS object shaped like a single entry in
|
|
693
|
-
* [`Form::cards`].
|
|
694
|
-
*
|
|
695
|
-
* [`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.
|
|
696
539
|
* @param {string} card_kind
|
|
697
540
|
* @returns {FormCard | null}
|
|
698
541
|
*/
|
|
@@ -714,13 +557,8 @@ export class Quill {
|
|
|
714
557
|
}
|
|
715
558
|
}
|
|
716
559
|
/**
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
* Returns a plain JS object with the same shape as one entry in
|
|
720
|
-
* [`Form::main`]. Every declared field's `source` is `"default"` (when
|
|
721
|
-
* the schema declares a default) or `"missing"`.
|
|
722
|
-
*
|
|
723
|
-
* [`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"`.
|
|
724
562
|
* @returns {FormCard}
|
|
725
563
|
*/
|
|
726
564
|
blankMain() {
|
|
@@ -739,7 +577,6 @@ export class Quill {
|
|
|
739
577
|
}
|
|
740
578
|
}
|
|
741
579
|
/**
|
|
742
|
-
* Auto-generated annotated Markdown blueprint for LLM consumers.
|
|
743
580
|
* @returns {string}
|
|
744
581
|
*/
|
|
745
582
|
get blueprint() {
|
|
@@ -759,23 +596,8 @@ export class Quill {
|
|
|
759
596
|
}
|
|
760
597
|
}
|
|
761
598
|
/**
|
|
762
|
-
* The schema-aware form view of `doc`.
|
|
763
|
-
*
|
|
764
|
-
* Returns a plain JS object (not a class) that is immediately
|
|
765
|
-
* `JSON.stringify`-able. The shape mirrors [`Form`]:
|
|
766
|
-
*
|
|
767
|
-
* ```json
|
|
768
|
-
* {
|
|
769
|
-
* "main": { "schema": {...}, "values": { "field": {...} } },
|
|
770
|
-
* "cards": [ ... ],
|
|
771
|
-
* "diagnostics": [ ... ]
|
|
772
|
-
* }
|
|
773
|
-
* ```
|
|
774
|
-
*
|
|
775
|
-
* **Snapshot semantics.** This is a read-only snapshot of the document
|
|
776
|
-
* at call time. Subsequent edits to `doc` require calling `form` again.
|
|
777
|
-
*
|
|
778
|
-
* [`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.
|
|
779
601
|
* @param {Document} doc
|
|
780
602
|
* @returns {Form}
|
|
781
603
|
*/
|
|
@@ -797,13 +619,7 @@ export class Quill {
|
|
|
797
619
|
}
|
|
798
620
|
/**
|
|
799
621
|
* Identity snapshot of the `quill:` section of `Quill.yaml`, plus
|
|
800
|
-
* `supportedFormats` and any
|
|
801
|
-
*
|
|
802
|
-
* Consumers that need validation run their own validator against
|
|
803
|
-
* `metadata.schema`.
|
|
804
|
-
*
|
|
805
|
-
* Equivalent by value for the lifetime of the handle; the quill is
|
|
806
|
-
* immutable once constructed.
|
|
622
|
+
* `supportedFormats` and any extra `quill:` keys.
|
|
807
623
|
* @returns {QuillMetadata}
|
|
808
624
|
*/
|
|
809
625
|
get metadata() {
|
|
@@ -811,7 +627,6 @@ export class Quill {
|
|
|
811
627
|
return takeObject(ret);
|
|
812
628
|
}
|
|
813
629
|
/**
|
|
814
|
-
* Open an iterative render session for page-selective rendering.
|
|
815
630
|
* @param {Document} doc
|
|
816
631
|
* @returns {RenderSession}
|
|
817
632
|
*/
|
|
@@ -832,7 +647,6 @@ export class Quill {
|
|
|
832
647
|
}
|
|
833
648
|
}
|
|
834
649
|
/**
|
|
835
|
-
* Render a document to final artifacts.
|
|
836
650
|
* @param {Document} doc
|
|
837
651
|
* @param {RenderOptions | null} [opts]
|
|
838
652
|
* @returns {RenderResult}
|
|
@@ -862,12 +676,9 @@ export class Quill {
|
|
|
862
676
|
return takeObject(ret);
|
|
863
677
|
}
|
|
864
678
|
/**
|
|
865
|
-
* Whether this quill's backend supports canvas preview.
|
|
866
|
-
*
|
|
867
679
|
* `true` iff `RenderSession.paint` and `RenderSession.pageSize` will
|
|
868
|
-
* succeed for sessions opened by this quill. Use
|
|
869
|
-
* probe before mounting a canvas-based preview UI
|
|
870
|
-
* 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.
|
|
871
682
|
* @returns {boolean}
|
|
872
683
|
*/
|
|
873
684
|
get supportsCanvas() {
|
|
@@ -877,9 +688,6 @@ export class Quill {
|
|
|
877
688
|
}
|
|
878
689
|
if (Symbol.dispose) Quill.prototype[Symbol.dispose] = Quill.prototype.free;
|
|
879
690
|
|
|
880
|
-
/**
|
|
881
|
-
* Quillmark WASM Engine
|
|
882
|
-
*/
|
|
883
691
|
export class Quillmark {
|
|
884
692
|
__destroy_into_raw() {
|
|
885
693
|
const ptr = this.__wbg_ptr;
|
|
@@ -891,9 +699,6 @@ export class Quillmark {
|
|
|
891
699
|
const ptr = this.__destroy_into_raw();
|
|
892
700
|
wasm.__wbg_quillmark_free(ptr, 0);
|
|
893
701
|
}
|
|
894
|
-
/**
|
|
895
|
-
* JavaScript constructor: `new Quillmark()`
|
|
896
|
-
*/
|
|
897
702
|
constructor() {
|
|
898
703
|
const ret = wasm.quillmark_new();
|
|
899
704
|
this.__wbg_ptr = ret >>> 0;
|
|
@@ -929,19 +734,12 @@ export class Quillmark {
|
|
|
929
734
|
if (Symbol.dispose) Quillmark.prototype[Symbol.dispose] = Quillmark.prototype.free;
|
|
930
735
|
|
|
931
736
|
/**
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
* Created via [`Quill::open`]. Holds the compiled output so that
|
|
935
|
-
* [`RenderSession::render`], [`RenderSession::paint`], and
|
|
936
|
-
* [`RenderSession::page_size`] can be called repeatedly without
|
|
937
|
-
* recompiling.
|
|
737
|
+
* Iterative render handle backed by an immutable compiled snapshot.
|
|
938
738
|
*
|
|
939
|
-
* **Empty documents.** A document
|
|
940
|
-
*
|
|
941
|
-
* `0
|
|
942
|
-
*
|
|
943
|
-
* (pageCount=0)"`. Hosts that surface "no pages to preview" UI should
|
|
944
|
-
* 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.
|
|
945
743
|
*/
|
|
946
744
|
export class RenderSession {
|
|
947
745
|
static __wrap(ptr) {
|
|
@@ -963,9 +761,6 @@ export class RenderSession {
|
|
|
963
761
|
}
|
|
964
762
|
/**
|
|
965
763
|
* The backend that produced this session (e.g. `"typst"`).
|
|
966
|
-
*
|
|
967
|
-
* Equal to the `backendId` of the [`Quill`] that opened this session
|
|
968
|
-
* (sessions inherit their quill's backend), so checking either is fine.
|
|
969
764
|
* @returns {string}
|
|
970
765
|
*/
|
|
971
766
|
get backendId() {
|
|
@@ -985,10 +780,6 @@ export class RenderSession {
|
|
|
985
780
|
}
|
|
986
781
|
}
|
|
987
782
|
/**
|
|
988
|
-
* Number of pages in this render session.
|
|
989
|
-
*
|
|
990
|
-
* Stable for the lifetime of the session — the underlying compiled
|
|
991
|
-
* document is an immutable snapshot.
|
|
992
783
|
* @returns {number}
|
|
993
784
|
*/
|
|
994
785
|
get pageCount() {
|
|
@@ -997,18 +788,7 @@ export class RenderSession {
|
|
|
997
788
|
}
|
|
998
789
|
/**
|
|
999
790
|
* Page dimensions in Typst points (1 pt = 1/72 inch).
|
|
1000
|
-
*
|
|
1001
|
-
* Report-only: the painter sizes the canvas itself based on
|
|
1002
|
-
* `PaintOptions`. Exposed for consumers that need page geometry
|
|
1003
|
-
* up-front (e.g. to lay out a scrollable list of canvases before
|
|
1004
|
-
* any pixels are rendered).
|
|
1005
|
-
*
|
|
1006
|
-
* Stable for a given `page` across the session's lifetime — the
|
|
1007
|
-
* compiled document is an immutable snapshot, so callers can cache
|
|
1008
|
-
* results.
|
|
1009
|
-
*
|
|
1010
|
-
* Throws if the underlying backend has no canvas painter (i.e. is not
|
|
1011
|
-
* 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.
|
|
1012
792
|
* @param {number} page
|
|
1013
793
|
* @returns {PageSize}
|
|
1014
794
|
*/
|
|
@@ -1028,42 +808,14 @@ export class RenderSession {
|
|
|
1028
808
|
}
|
|
1029
809
|
}
|
|
1030
810
|
/**
|
|
1031
|
-
* Paint `page` into a
|
|
1032
|
-
*
|
|
1033
|
-
*
|
|
1034
|
-
* `
|
|
1035
|
-
*
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
*
|
|
1039
|
-
* itself; consumers must not. The painter does not touch
|
|
1040
|
-
* `canvas.style.*` — that's layout, owned by the consumer (see
|
|
1041
|
-
* `PaintResult.layoutWidth` / `layoutHeight`).
|
|
1042
|
-
*
|
|
1043
|
-
* `opts.layoutScale` (default 1.0) is layout-space pixels per Typst
|
|
1044
|
-
* point and determines the canvas's display-box size. `opts.densityScale`
|
|
1045
|
-
* (default 1.0) is the rasterization density multiplier the consumer
|
|
1046
|
-
* folds `window.devicePixelRatio`, in-app zoom, and
|
|
1047
|
-
* `visualViewport.scale` (pinch-zoom) into. The effective
|
|
1048
|
-
* rasterization scale is `layoutScale * densityScale`.
|
|
1049
|
-
*
|
|
1050
|
-
* If `layoutScale * densityScale` would exceed the safe backing-store
|
|
1051
|
-
* maximum (16384 px per side), `densityScale` is clamped
|
|
1052
|
-
* proportionally so the largest dimension fits. The actual
|
|
1053
|
-
* backing-store dimensions are reported in the returned
|
|
1054
|
-
* `PaintResult` — compare against
|
|
1055
|
-
* `round(layoutWidth * densityScale)` to detect clamping.
|
|
1056
|
-
*
|
|
1057
|
-
* Each call resets the backing store (`paint` is always a full
|
|
1058
|
-
* repaint). Consumers do not need to call `clearRect`.
|
|
1059
|
-
*
|
|
1060
|
-
* Throws when:
|
|
1061
|
-
* - the backend does not support canvas preview (message includes the
|
|
1062
|
-
* resolved `backendId`),
|
|
1063
|
-
* - `page` is out of range,
|
|
1064
|
-
* - `ctx` is neither `CanvasRenderingContext2D` nor
|
|
1065
|
-
* `OffscreenCanvasRenderingContext2D`,
|
|
1066
|
-
* - `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`.
|
|
1067
819
|
* @param {CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D} ctx
|
|
1068
820
|
* @param {number} page
|
|
1069
821
|
* @param {PaintOptions | undefined} opts
|
|
@@ -1085,7 +837,6 @@ export class RenderSession {
|
|
|
1085
837
|
}
|
|
1086
838
|
}
|
|
1087
839
|
/**
|
|
1088
|
-
* Render all or selected pages from this session.
|
|
1089
840
|
* @param {RenderOptions | null} [opts]
|
|
1090
841
|
* @returns {RenderResult}
|
|
1091
842
|
*/
|
|
@@ -1105,11 +856,7 @@ export class RenderSession {
|
|
|
1105
856
|
}
|
|
1106
857
|
}
|
|
1107
858
|
/**
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
* `true` iff [`paint`](Self::paint) and [`page_size`](Self::page_size)
|
|
1111
|
-
* will succeed. Equal to `Quill.supportsCanvas` for the quill that
|
|
1112
|
-
* opened this session.
|
|
859
|
+
* `true` iff `paint` and `pageSize` will succeed for this session.
|
|
1113
860
|
* @returns {boolean}
|
|
1114
861
|
*/
|
|
1115
862
|
get supportsCanvas() {
|
|
@@ -1117,14 +864,8 @@ export class RenderSession {
|
|
|
1117
864
|
return ret !== 0;
|
|
1118
865
|
}
|
|
1119
866
|
/**
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
* Snapshot of any non-fatal diagnostics emitted while opening the
|
|
1123
|
-
* session (e.g. version compatibility shims). Stable across the
|
|
1124
|
-
* session's lifetime. These are also appended to
|
|
1125
|
-
* [`RenderResult.warnings`] on every `render()` call; the accessor
|
|
1126
|
-
* surfaces them to canvas-preview consumers that don't go through
|
|
1127
|
-
* `render()`.
|
|
867
|
+
* Non-fatal diagnostics emitted when opening the session. Also appended
|
|
868
|
+
* to `RenderResult.warnings` on each `render()` call.
|
|
1128
869
|
* @returns {Diagnostic[]}
|
|
1129
870
|
*/
|
|
1130
871
|
get warnings() {
|