@quillmark/wasm 0.131.0 → 0.133.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/render/wasm.js CHANGED
@@ -444,8 +444,9 @@ export class Document {
444
444
  * The newest storage version this build writes via
445
445
  * [`toStored`](Document::to_stored): a document spelling a font mark, a
446
446
  * `table` element, a merged table cell or a table head 0.130 cannot draw
447
- * carries it, every other the tag before it, which a 0.130 build reads. The tag advances only when the wire format changes, not on
448
- * every release.
447
+ * carries it, every other the tag before it, which a 0.130 build reads.
448
+ * The tag advances only when the wire format changes, not on every
449
+ * release.
449
450
  * @returns {string}
450
451
  */
451
452
  static currentStorageVersion() {
@@ -713,8 +714,9 @@ export class Document {
713
714
  /**
714
715
  * **Overwrite** the content value at `addr` with exactly `rt`: value
715
716
  * semantics, so the identity anchors of any previous value are gone. By
716
- * anchor fate `overwrite` destroys, [`revise`](Document::revise) rebases,
717
- * and [`applyChange`](Document::apply_change) preserves. An absent
717
+ * anchor fate `overwrite` destroys, [`revise`](Document::revise) and
718
+ * [`reviseContent`](Document::revise_content) rebase, and
719
+ * [`applyChange`](Document::apply_change) preserves. An absent
718
720
  * `addr.field` targets the body, an absent `addr.card` the main card.
719
721
  *
720
722
  * Throws on an out-of-range card, a malformed field name, or an `rt` that is
@@ -903,6 +905,40 @@ export class Document {
903
905
  wasm.__wbindgen_add_to_stack_pointer(16);
904
906
  }
905
907
  }
908
+ /**
909
+ * **Revise** the richtext value at `addr` to `rt`, keeping each stored prose
910
+ * anchor whose id `rt` does not hold: the content twin of
911
+ * [`revise`](Document::revise), for a value built elsewhere such as a
912
+ * merge's projection. Diffs `rt` against the current value, carries those
913
+ * anchors through the diff, and returns the
914
+ * `Revised` receipt, whose `delta` an editor bridge maps its own positions
915
+ * through and whose `warnings` is empty. `rt`'s own anchors and island ids
916
+ * land as they are. An absent `addr.field` targets the body, an absent
917
+ * `addr.card` the main card; an absent field diffs from empty. Richtext
918
+ * only: a `text` field takes `overwrite`.
919
+ *
920
+ * Throws on an out-of-range card, a malformed field name, a present
921
+ * non-content field value, or an `rt` that is not a canonical content
922
+ * object.
923
+ * @param {Addr | string} addr
924
+ * @param {Content} rt
925
+ * @returns {Revised}
926
+ */
927
+ reviseContent(addr, rt) {
928
+ try {
929
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
930
+ wasm.document_reviseContent(retptr, this.__wbg_ptr, addHeapObject(addr), addHeapObject(rt));
931
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
932
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
933
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
934
+ if (r2) {
935
+ throw takeObject(r1);
936
+ }
937
+ return takeObject(r0);
938
+ } finally {
939
+ wasm.__wbindgen_add_to_stack_pointer(16);
940
+ }
941
+ }
906
942
  /**
907
943
  * **Revise** the richtext value at `addr` from a markdown string: the
908
944
  * default write path. Imports the markdown, diffs it against the current
@@ -1727,35 +1763,38 @@ export class Quill {
1727
1763
  }
1728
1764
  }
1729
1765
  /**
1730
- * The *declared* backend identifier (e.g. `"typst"`): intent, not a
1731
- * resolved capability. Capability is read from the engine.
1732
- * @returns {string}
1766
+ * JSON Schema (draft 2020-12) of the quill's authoring document: the
1767
+ * shape `fromAuthoring` takes and `toAuthoring` returns, every content
1768
+ * leaf a Markdown or literal string, each card kind under `$defs`
1769
+ * selected by `kind`.
1770
+ * @returns {Record<string, unknown>}
1733
1771
  */
1734
- get backendId() {
1735
- let deferred1_0;
1736
- let deferred1_1;
1772
+ get authoringSchema() {
1737
1773
  try {
1738
1774
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1739
- wasm.quill_backendId(retptr, this.__wbg_ptr);
1775
+ wasm.quill_authoringSchema(retptr, this.__wbg_ptr);
1740
1776
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1741
1777
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1742
- deferred1_0 = r0;
1743
- deferred1_1 = r1;
1744
- return getStringFromWasm0(r0, r1);
1778
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1779
+ if (r2) {
1780
+ throw takeObject(r1);
1781
+ }
1782
+ return takeObject(r0);
1745
1783
  } finally {
1746
1784
  wasm.__wbindgen_add_to_stack_pointer(16);
1747
- wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
1748
1785
  }
1749
1786
  }
1750
1787
  /**
1788
+ * The *declared* backend identifier (e.g. `"typst"`): intent, not a
1789
+ * resolved capability. Capability is read from the engine.
1751
1790
  * @returns {string}
1752
1791
  */
1753
- get blueprint() {
1792
+ get backendId() {
1754
1793
  let deferred1_0;
1755
1794
  let deferred1_1;
1756
1795
  try {
1757
1796
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1758
- wasm.quill_blueprint(retptr, this.__wbg_ptr);
1797
+ wasm.quill_backendId(retptr, this.__wbg_ptr);
1759
1798
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1760
1799
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1761
1800
  deferred1_0 = r0;
@@ -1799,7 +1838,7 @@ export class Quill {
1799
1838
  * The empty document: a main card carrying this quill's `$quill` and
1800
1839
  * `$kind: main`, no field committed, no composable card, no body. The
1801
1840
  * type-minimal valid input, and the document a plate is bound to render
1802
- * (the quill authoring contract). `new Document(ref)` is the same document
1841
+ * (the plate contract). `new Document(ref)` is the same document
1803
1842
  * reached by spelling the reference.
1804
1843
  * @returns {Document}
1805
1844
  */
@@ -1808,25 +1847,63 @@ export class Quill {
1808
1847
  return Document.__wrap(ret);
1809
1848
  }
1810
1849
  /**
1811
- * The quill's example document, `undefined` when the quill has no
1812
- * `example.md` at its root: a filled-in page whose values are made up to show the
1813
- * quill in use, never kept. It comes back pinned to this quill's
1814
- * `name@MAJOR.MINOR` and conformed as `parse` conforms, its parse and
1815
- * `conform::*` warnings on `doc.warnings`. Throws when the file does not
1816
- * parse or its `$quill` is not this quill's bare name.
1850
+ * The quill's example document, `undefined` when no slot or body declares
1851
+ * an example: the seeded document with every declared `example` committed
1852
+ * as its cell's value and each kind's `body.example` as its body. A
1853
+ * filled-in page whose values are made up to show the quill in use, never
1854
+ * kept.
1817
1855
  * @returns {Document | undefined}
1818
1856
  */
1819
1857
  exampleDocument() {
1858
+ const ret = wasm.quill_exampleDocument(this.__wbg_ptr);
1859
+ return ret === 0 ? undefined : Document.__wrap(ret);
1860
+ }
1861
+ /**
1862
+ * A document from an authoring document, conformed against this quill:
1863
+ * the JSON twin of `parse`. A `null` is absent; the document carries this
1864
+ * quill's `$quill`. A value the schema refuses lands with a `conform::*`
1865
+ * warning on `doc.warnings`, and `validate` reports the rest at document
1866
+ * paths. Throws, with every error found, on a value that is not the
1867
+ * authoring document's shape (`authoring::invalid_shape`) or a name or
1868
+ * kind no card can store (`edit::*`).
1869
+ * @param {AuthoringDocument} value
1870
+ * @returns {Document}
1871
+ */
1872
+ fromAuthoring(value) {
1873
+ try {
1874
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1875
+ wasm.quill_fromAuthoring(retptr, this.__wbg_ptr, addHeapObject(value));
1876
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1877
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1878
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1879
+ if (r2) {
1880
+ throw takeObject(r1);
1881
+ }
1882
+ return Document.__wrap(r0);
1883
+ } finally {
1884
+ wasm.__wbindgen_add_to_stack_pointer(16);
1885
+ }
1886
+ }
1887
+ /**
1888
+ * Read a `.quill` bundle, the zip archive holding one quill's file tree.
1889
+ * Pure, as [`fromTree`](Self::from_tree) is. A bundle outside the format
1890
+ * throws one `quill::bundle_*` diagnostic.
1891
+ * @param {Uint8Array} bytes
1892
+ * @returns {Quill}
1893
+ */
1894
+ static fromBundle(bytes) {
1820
1895
  try {
1821
1896
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1822
- wasm.quill_exampleDocument(retptr, this.__wbg_ptr);
1897
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
1898
+ const len0 = WASM_VECTOR_LEN;
1899
+ wasm.quill_fromBundle(retptr, ptr0, len0);
1823
1900
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1824
1901
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1825
1902
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1826
1903
  if (r2) {
1827
1904
  throw takeObject(r1);
1828
1905
  }
1829
- return r0 === 0 ? undefined : Document.__wrap(r0);
1906
+ return Quill.__wrap(r0);
1830
1907
  } finally {
1831
1908
  wasm.__wbindgen_add_to_stack_pointer(16);
1832
1909
  }
@@ -1987,6 +2064,53 @@ export class Quill {
1987
2064
  wasm.__wbindgen_add_to_stack_pointer(16);
1988
2065
  }
1989
2066
  }
2067
+ /**
2068
+ * `doc` as an authoring document: every field in the values form (each
2069
+ * content leaf its codec's text), every body as Markdown, each card
2070
+ * `{kind, fields, body}`. Sparse: an absent or `null` field stays absent. A
2071
+ * content leaf that decodes under neither encoding exports as stored.
2072
+ * @param {Document} doc
2073
+ * @returns {AuthoringDocument}
2074
+ */
2075
+ toAuthoring(doc) {
2076
+ try {
2077
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2078
+ _assertClass(doc, Document);
2079
+ wasm.quill_toAuthoring(retptr, this.__wbg_ptr, doc.__wbg_ptr);
2080
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2081
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2082
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
2083
+ if (r2) {
2084
+ throw takeObject(r1);
2085
+ }
2086
+ return takeObject(r0);
2087
+ } finally {
2088
+ wasm.__wbindgen_add_to_stack_pointer(16);
2089
+ }
2090
+ }
2091
+ /**
2092
+ * This quill's file tree as a `.quill` bundle, the bytes
2093
+ * [`fromBundle`](Self::from_bundle) reads.
2094
+ * @returns {Uint8Array}
2095
+ */
2096
+ toBundle() {
2097
+ try {
2098
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2099
+ wasm.quill_toBundle(retptr, this.__wbg_ptr);
2100
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2101
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2102
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
2103
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
2104
+ if (r3) {
2105
+ throw takeObject(r2);
2106
+ }
2107
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
2108
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
2109
+ return v1;
2110
+ } finally {
2111
+ wasm.__wbindgen_add_to_stack_pointer(16);
2112
+ }
2113
+ }
1990
2114
  /**
1991
2115
  * Flatten this quill back into its canonical file tree, the inverse of
1992
2116
  * [`fromTree`](Self::from_tree). Keys are `"/"`-joined relative paths.
@@ -2288,6 +2412,30 @@ export function mapPos(delta, pos, assoc) {
2288
2412
  }
2289
2413
  }
2290
2414
 
2415
+ /**
2416
+ * The canonical form of `rt`: the content `overwrite` stores from it, read
2417
+ * without a document. Normalizing rewrites structure, never the text, so the
2418
+ * answer's `text` is `rt.text`. Throws where `overwrite` would, with the same
2419
+ * error under this verb's name.
2420
+ * @param {Content} rt
2421
+ * @returns {Content}
2422
+ */
2423
+ export function normalize(rt) {
2424
+ try {
2425
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2426
+ wasm.normalize(retptr, addHeapObject(rt));
2427
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2428
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2429
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
2430
+ if (r2) {
2431
+ throw takeObject(r1);
2432
+ }
2433
+ return takeObject(r0);
2434
+ } finally {
2435
+ wasm.__wbindgen_add_to_stack_pointer(16);
2436
+ }
2437
+ }
2438
+
2291
2439
  /**
2292
2440
  * Parse a canonical document-model `Diagnostic.path` (`cards.<kind>[<i>].<field>`,
2293
2441
  * `main.body`, `recipients[0].name`) into structured `DocPathSeg` segments, so
@@ -2899,6 +3047,13 @@ function isLikeNone(x) {
2899
3047
  return x === undefined || x === null;
2900
3048
  }
2901
3049
 
3050
+ function passArray8ToWasm0(arg, malloc) {
3051
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
3052
+ getUint8ArrayMemory0().set(arg, ptr / 1);
3053
+ WASM_VECTOR_LEN = arg.length;
3054
+ return ptr;
3055
+ }
3056
+
2902
3057
  function passStringToWasm0(arg, malloc, realloc) {
2903
3058
  if (realloc === undefined) {
2904
3059
  const buf = cachedTextEncoder.encode(arg);
Binary file
@@ -41,6 +41,7 @@ export const document_removeExt: (a: number, b: number, c: number) => void;
41
41
  export const document_removeField: (a: number, b: number, c: number) => void;
42
42
  export const document_removeSeedOverlay: (a: number, b: number, c: number, d: number) => void;
43
43
  export const document_revise: (a: number, b: number, c: number, d: number, e: number) => void;
44
+ export const document_reviseContent: (a: number, b: number, c: number, d: number) => void;
44
45
  export const document_seedOverlay: (a: number, b: number, c: number, d: number) => void;
45
46
  export const document_setQuillRef: (a: number, b: number, c: number, d: number) => void;
46
47
  export const document_storageVersionOf: (a: number, b: number, c: number) => void;
@@ -78,13 +79,16 @@ export const livesession_update: (a: number, b: number, c: number) => void;
78
79
  export const livesession_warnings: (a: number, b: number) => void;
79
80
  export const mapMarks: (a: number, b: number, c: number) => void;
80
81
  export const mapPos: (a: number, b: number, c: number, d: number) => void;
82
+ export const normalize: (a: number, b: number) => void;
81
83
  export const parseDocPath: (a: number, b: number, c: number) => void;
82
84
  export const quill__resolve: (a: number, b: number, c: number, d: number, e: number) => void;
85
+ export const quill_authoringSchema: (a: number, b: number) => void;
83
86
  export const quill_backendId: (a: number, b: number) => void;
84
- export const quill_blueprint: (a: number, b: number) => void;
85
87
  export const quill_conform: (a: number, b: number, c: number) => void;
86
88
  export const quill_emptyDocument: (a: number) => number;
87
- export const quill_exampleDocument: (a: number, b: number) => void;
89
+ export const quill_exampleDocument: (a: number) => number;
90
+ export const quill_fromAuthoring: (a: number, b: number, c: number) => void;
91
+ export const quill_fromBundle: (a: number, b: number, c: number) => void;
88
92
  export const quill_fromTree: (a: number, b: number) => void;
89
93
  export const quill_metadata: (a: number, b: number) => void;
90
94
  export const quill_parse: (a: number, b: number, c: number, d: number) => void;
@@ -92,6 +96,8 @@ export const quill_schema: (a: number, b: number) => void;
92
96
  export const quill_seedCard: (a: number, b: number, c: number, d: number, e: number) => void;
93
97
  export const quill_seedDocument: (a: number) => number;
94
98
  export const quill_seedMain: (a: number, b: number) => void;
99
+ export const quill_toAuthoring: (a: number, b: number, c: number) => void;
100
+ export const quill_toBundle: (a: number, b: number) => void;
95
101
  export const quill_toTree: (a: number) => number;
96
102
  export const quill_validate: (a: number, b: number, c: number) => void;
97
103
  export const quill_warnings: (a: number, b: number) => void;
@@ -18,6 +18,7 @@ import type {
18
18
  Document as CoreDocument,
19
19
  importMarkdown,
20
20
  exportMarkdown,
21
+ normalize,
21
22
  rebase,
22
23
  mapPos,
23
24
  mapMarks,
@@ -40,6 +41,7 @@ export interface CoreSurface {
40
41
  Document: typeof CoreDocument;
41
42
  importMarkdown: typeof importMarkdown;
42
43
  exportMarkdown: typeof exportMarkdown;
44
+ normalize: typeof normalize;
43
45
  rebase: typeof rebase;
44
46
  mapPos: typeof mapPos;
45
47
  mapMarks: typeof mapMarks;
@@ -113,7 +115,9 @@ export type {
113
115
  QuillFieldUi,
114
116
  QuillCardUi,
115
117
  QuillGroupUi,
116
- QuillMetadata
118
+ QuillMetadata,
119
+ AuthoringDocument,
120
+ AuthoringCard
117
121
  } from '../core/wasm.js';
118
122
 
119
123
  // Content edit vocabulary: the op-grained content model `Document`'s methods
@@ -267,6 +271,12 @@ export interface RenderOptions {
267
271
  * consumers without a live session. Defaults to `false`.
268
272
  */
269
273
  regions?: boolean;
274
+ /**
275
+ * The PDF document title, over the plate's own `set document(title: ..)`
276
+ * and then the quill's `description`. A blank title counts as absent;
277
+ * ignored by PNG and SVG.
278
+ */
279
+ title?: string;
270
280
  }
271
281
 
272
282
  /**
@@ -19,7 +19,7 @@ import initCore, { Quill, Document } from '../core/wasm.js';
19
19
  // itself), a `node:fs` read under Node, whose `fetch` rejects `file:` URLs.
20
20
  // Resolution-time, so `node:fs` never enters a browser graph.
21
21
  import { toModuleSource } from '#quillmark-env';
22
- import { importMarkdown, exportMarkdown, rebase, mapPos, mapMarks } from '../core/wasm.js';
22
+ import { importMarkdown, exportMarkdown, normalize, rebase, mapPos, mapMarks } from '../core/wasm.js';
23
23
  import { isInline, isPlain } from '../core/wasm.js';
24
24
  import { parseDocPath, formatDocPath, formatDiagnostic } from '../core/wasm.js';
25
25
 
@@ -47,6 +47,7 @@ const CORE_SURFACE = Object.freeze({
47
47
  Document,
48
48
  importMarkdown,
49
49
  exportMarkdown,
50
+ normalize,
50
51
  rebase,
51
52
  mapPos,
52
53
  mapMarks,
@@ -278,7 +279,7 @@ const HANDLE_KINDS = {
278
279
  },
279
280
  Document: {
280
281
  code: 'runtime::not_a_document',
281
- hint: 'Pass a Document built by Document.fromMarkdown / fromStored or quill.seedDocument / emptyDocument. A Document from another copy of @quillmark/wasm is refused too — each copy is its own WASM linear memory and its own class — so run `npm ls @quillmark/wasm` and dedupe to one.'
282
+ hint: 'Pass a Document built by Document.fromMarkdown / fromStored or quill.seedDocument / emptyDocument / fromAuthoring. A Document from another copy of @quillmark/wasm is refused too — each copy is its own WASM linear memory and its own class — so run `npm ls @quillmark/wasm` and dedupe to one.'
282
283
  }
283
284
  };
284
285
 
@@ -331,10 +332,9 @@ function requireLocalQuill(quill, method) {
331
332
  // `runtime.test.js` § "container run boundaries" stamps a pair and re-imports
332
333
  // it, where `Content::normalize` re-mints against the Rust predicate. A tag the
333
334
  // table omits welds with nothing, so `tests/known_names_drift.rs` pins that
334
- // every container has an entry. An entry of `'*'` welds on the whole bag: an
335
- // element's attributes are open, its name among them.
335
+ // every container has an entry.
336
336
 
337
- const WELD_KEYS = { list_item: ['ordered'], quote: [], description: [], element: '*' };
337
+ const WELD_KEYS = { list_item: ['ordered'], quote: [] };
338
338
 
339
339
  /**
340
340
  * @param {import('../core/wasm.js').ContentContainer} a
@@ -347,20 +347,7 @@ function weldsWith(a, b) {
347
347
  // `hasOwn`, so a tag colliding with an `Object.prototype` member answers
348
348
  // `false` rather than reaching a function.
349
349
  if (!Object.hasOwn(WELD_KEYS, a.container)) return false;
350
- const keys = WELD_KEYS[a.container];
351
- if (keys === '*') return sameBag(a.attrs, b.attrs);
352
- return keys.every((k) => a.attrs?.[k] === b.attrs?.[k]);
353
- }
354
-
355
- /**
356
- * @param {Record<string, unknown> | undefined} a
357
- * @param {Record<string, unknown> | undefined} b
358
- * @returns {boolean}
359
- */
360
- function sameBag(a, b) {
361
- const [x, y] = [a ?? {}, b ?? {}];
362
- const keys = Object.keys(x);
363
- return keys.length === Object.keys(y).length && keys.every((k) => Object.hasOwn(y, k) && x[k] === y[k]);
350
+ return WELD_KEYS[a.container].every((k) => a.attrs?.[k] === b.attrs?.[k]);
364
351
  }
365
352
 
366
353
  /**
@@ -654,7 +641,7 @@ export class Engine {
654
641
  /**
655
642
  * @param {Quill} quill
656
643
  * @param {Document} doc
657
- * @param {object} [options] render options (`{ format, ppi, pages, regions }`)
644
+ * @param {object} [options] render options (`{ format, ppi, pages, regions, title }`)
658
645
  * @param {string} [today] the render date, `YYYY-MM-DD`
659
646
  * @returns {Promise<import('./runtime.js').RenderResult>}
660
647
  */