@quillmark/wasm 0.58.0 → 0.58.2-rc.4

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.
@@ -6,6 +6,12 @@ export interface Artifact {
6
6
  mimeType: string;
7
7
  }
8
8
 
9
+ export interface Card {
10
+ tag: string;
11
+ fields: Record<string, unknown>;
12
+ body: string;
13
+ }
14
+
9
15
  export interface Diagnostic {
10
16
  severity: Severity;
11
17
  code?: string;
@@ -21,14 +27,8 @@ export interface Location {
21
27
  column: number;
22
28
  }
23
29
 
24
- export interface ParsedDocument {
25
- fields: Record<string, any>;
26
- quillRef: string;
27
- }
28
-
29
30
  export interface RenderOptions {
30
31
  format?: OutputFormat;
31
- assets?: Record<string, Uint8Array | number[]>;
32
32
  ppi?: number;
33
33
  pages?: number[];
34
34
  }
@@ -45,6 +45,148 @@ export type OutputFormat = "pdf" | "svg" | "txt" | "png";
45
45
  export type Severity = "error" | "warning" | "note";
46
46
 
47
47
 
48
+ /**
49
+ * Typed in-memory Quillmark document.
50
+ *
51
+ * Created via `Document.fromMarkdown(markdown)`. Exposes:
52
+ * - `quillRef` (string)
53
+ * - `frontmatter` (JS object/Record)
54
+ * - `body` (string)
55
+ * - `cards` (array of Card objects)
56
+ * - `warnings` (array of Diagnostic objects)
57
+ *
58
+ * `toMarkdown()` emits canonical Quillmark Markdown that round-trips back to
59
+ * an equal `Document` by value and by type.
60
+ */
61
+ export class Document {
62
+ private constructor();
63
+ free(): void;
64
+ [Symbol.dispose](): void;
65
+ /**
66
+ * Parse markdown into a typed Document.
67
+ *
68
+ * Returns the document with any parse-time warnings accessible via `.warnings`.
69
+ * Throws on parse errors.
70
+ */
71
+ static fromMarkdown(markdown: string): Document;
72
+ /**
73
+ * Insert a card at the given index.
74
+ *
75
+ * `index` must be in `0..=cards.length`. Out-of-range throws an `Error`.
76
+ *
77
+ * Mutators never modify `warnings`.
78
+ */
79
+ insertCard(index: number, card: any): void;
80
+ /**
81
+ * Move the card at `from` to position `to`.
82
+ *
83
+ * `from == to` is a no-op. Both indices must be in `0..cards.length`.
84
+ * Out-of-range throws an `Error`.
85
+ *
86
+ * Mutators never modify `warnings`.
87
+ */
88
+ moveCard(from: number, to: number): void;
89
+ /**
90
+ * Append a card to the end of the card list.
91
+ *
92
+ * `card` must be a JS object with a `tag` string field and optional
93
+ * `fields` (object) and `body` (string).
94
+ *
95
+ * Throws an `Error` if `card.tag` is not a valid tag name.
96
+ *
97
+ * Mutators never modify `warnings`.
98
+ */
99
+ pushCard(card: any): void;
100
+ /**
101
+ * Remove the card at `index` and return it, or `undefined` if out of range.
102
+ *
103
+ * Mutators never modify `warnings`.
104
+ */
105
+ removeCard(index: number): any;
106
+ /**
107
+ * Remove a frontmatter field, returning the removed value or `undefined`.
108
+ *
109
+ * Mutators never modify `warnings`.
110
+ */
111
+ removeField(name: string): any;
112
+ /**
113
+ * Replace the global Markdown body.
114
+ *
115
+ * Mutators never modify `warnings`.
116
+ */
117
+ replaceBody(body: string): void;
118
+ /**
119
+ * Set a frontmatter field.
120
+ *
121
+ * Throws an `Error` whose message includes the `EditError` variant name and
122
+ * details if `name` is reserved (`BODY`, `CARDS`, `QUILL`, `CARD`) or does
123
+ * not match `[a-z_][a-z0-9_]*`.
124
+ *
125
+ * Mutators never modify `warnings`.
126
+ */
127
+ setField(name: string, value: any): void;
128
+ /**
129
+ * Replace the QUILL reference string.
130
+ *
131
+ * Throws if `ref_str` is not a valid `QuillReference`.
132
+ *
133
+ * Mutators never modify `warnings`.
134
+ */
135
+ setQuillRef(ref_str: string): void;
136
+ /**
137
+ * Emit canonical Quillmark Markdown.
138
+ *
139
+ * Returns the document serialised as a Quillmark Markdown string.
140
+ * The output is type-fidelity round-trip safe: re-parsing the result
141
+ * produces a `Document` equal to `self` by value and by type.
142
+ */
143
+ toMarkdown(): string;
144
+ /**
145
+ * Replace the body of the card at `index`.
146
+ *
147
+ * Throws if `index` is out of range.
148
+ *
149
+ * Mutators never modify `warnings`.
150
+ */
151
+ updateCardBody(index: number, body: string): void;
152
+ /**
153
+ * Update a field on the card at `index`.
154
+ *
155
+ * Convenience method: equivalent to `doc.card_mut(index)?.set_field(name, value)`.
156
+ *
157
+ * Throws if `index` is out of range, `name` is reserved or invalid, or
158
+ * `value` cannot be serialized.
159
+ *
160
+ * Mutators never modify `warnings`.
161
+ */
162
+ updateCardField(index: number, name: string, value: any): void;
163
+ /**
164
+ * Global Markdown body between frontmatter and the first card.
165
+ *
166
+ * Trailing newlines are stripped — those are structural separators in
167
+ * the Markdown wire format, not content the consumer wrote.
168
+ *
169
+ * Empty string when no body is present.
170
+ */
171
+ readonly body: string;
172
+ /**
173
+ * Ordered list of card blocks as JS objects with `tag`, `fields`, and `body`.
174
+ */
175
+ readonly cards: any;
176
+ /**
177
+ * Typed YAML frontmatter fields as a JS object (no QUILL, BODY, or CARDS keys).
178
+ */
179
+ readonly frontmatter: any;
180
+ /**
181
+ * The QUILL reference string (e.g. `"usaf_memo@0.1"`).
182
+ */
183
+ readonly quillRef: string;
184
+ /**
185
+ * Non-fatal parse-time warnings as a JS array of Diagnostic objects.
186
+ */
187
+ readonly warnings: any;
188
+ }
189
+
48
190
  /**
49
191
  * Opaque, shareable Quill handle.
50
192
  */
@@ -55,11 +197,36 @@ export class Quill {
55
197
  /**
56
198
  * Open an iterative render session for page-selective rendering.
57
199
  */
58
- open(parsed: ParsedDocument): RenderSession;
200
+ open(doc: Document): RenderSession;
201
+ /**
202
+ * Project a document through this quill's schema.
203
+ *
204
+ * Returns a plain JS object (not a class) that is immediately
205
+ * `JSON.stringify`-able. The shape mirrors [`FormProjection`]:
206
+ *
207
+ * ```json
208
+ * {
209
+ * "main": { "schema": {...}, "values": { "field": {...} } },
210
+ * "cards": [ ... ],
211
+ * "diagnostics": [ ... ]
212
+ * }
213
+ * ```
214
+ *
215
+ * **Snapshot semantics.** This is a read-only snapshot of the document
216
+ * at call time. Subsequent edits to `doc` require calling `projectForm`
217
+ * again.
218
+ *
219
+ * [`FormProjection`]: quillmark::form::FormProjection
220
+ */
221
+ projectForm(doc: Document): any;
59
222
  /**
60
223
  * Render a document to final artifacts.
61
224
  */
62
- render(parsed: ParsedDocument, opts: RenderOptions): RenderResult;
225
+ render(doc: Document, opts?: RenderOptions | null): RenderResult;
226
+ /**
227
+ * The resolved backend identifier (e.g. `"typst"`).
228
+ */
229
+ readonly backendId: string;
63
230
  }
64
231
 
65
232
  /**
@@ -87,7 +254,7 @@ export class RenderSession {
87
254
  /**
88
255
  * Render all or selected pages from this session.
89
256
  */
90
- render(opts: RenderOptions): RenderResult;
257
+ render(opts?: RenderOptions | null): RenderResult;
91
258
  /**
92
259
  * Number of pages in this render session.
93
260
  */