tiptap-rusty-parser 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex Casillas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # tiptap-rusty-parser (WASM)
2
+
3
+ WebAssembly bindings for [`tiptap-rusty-parser`](https://crates.io/crates/tiptap-rusty-parser) —
4
+ a fast, schema-agnostic parser/manipulator for Tiptap/ProseMirror `JSONContent`,
5
+ written in Rust and compiled to WASM.
6
+
7
+ ```bash
8
+ npm install tiptap-rusty-parser
9
+ ```
10
+
11
+ Built for the `bundler` target (Vite, webpack, Next, …).
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ import { TiptapDoc } from "tiptap-rusty-parser";
17
+
18
+ const doc = TiptapDoc.fromJSON({
19
+ type: "doc",
20
+ content: [
21
+ { type: "heading", content: [{ type: "text", text: "Title" }] },
22
+ { type: "paragraph", content: [{ type: "text", text: "Hello world" }] },
23
+ ],
24
+ });
25
+
26
+ doc.textContent(); // "TitleHello world"
27
+ doc.wordCount(); // 3
28
+
29
+ // Locate nodes by index path, then mutate by path
30
+ const [headingPath] = doc.pathsByType("heading"); // e.g. [0]
31
+ doc.setAttr(headingPath, "level", 1);
32
+ doc.addMark([0, 0], "bold"); // bold the heading text
33
+
34
+ // Validate (opt-in) against an allow-list schema
35
+ const schema = { nodes: { doc: { content: ["paragraph"] } } };
36
+ doc.isValid(schema); // false (heading not allowed under doc)
37
+ doc.validate(schema); // [{ path: [...], kind: ... }, ...]
38
+
39
+ const out = doc.toJSON(); // plain JSONContent object
40
+ ```
41
+
42
+ ## API (`TiptapDoc`)
43
+
44
+ The document tree stays owned by WASM; it's only serialized to JS at the
45
+ boundary. `path` arguments are plain `number[]` index paths (root = `[]`).
46
+
47
+ | Group | Methods |
48
+ |-------|---------|
49
+ | Lifecycle | `TiptapDoc.fromJSON(obj)`, `TiptapDoc.fromJSONString(str)`, `toJSON()`, `toJSONString()` |
50
+ | Read query | `byType(t)`, `firstByType(t)`, `byMark(t)`, `byAttr(key, value)` → node object(s) |
51
+ | Locate | `pathsByType(t)`, `pathsByMark(t)`, `pathsByAttr(key, value)` → `number[][]`; `nodeAt(path)`, `childCount(path)` |
52
+ | Mutate (by path) | `setAttr`, `removeAttr`, `setText`, `addMark`, `removeMark`, `pushChild`, `insertChild`, `removeChild` |
53
+ | Text | `textContent()`, `charCount()`, `wordCount()` |
54
+ | Validate | `validate(schema)`, `isValid(schema)` |
55
+
56
+ Methods throw on malformed input or a missing path target.
57
+
58
+ ## License
59
+
60
+ MIT
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "tiptap-rusty-parser",
3
+ "type": "module",
4
+ "description": "Fast WASM parser/manipulator for Tiptap/ProseMirror JSONContent",
5
+ "version": "0.1.2",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/alexvcasillas/tiptap-rusty-parser.git"
10
+ },
11
+ "files": [
12
+ "tiptap_rusty_parser_wasm_bg.wasm",
13
+ "tiptap_rusty_parser_wasm.js",
14
+ "tiptap_rusty_parser_wasm_bg.js",
15
+ "tiptap_rusty_parser_wasm.d.ts"
16
+ ],
17
+ "main": "tiptap_rusty_parser_wasm.js",
18
+ "types": "tiptap_rusty_parser_wasm.d.ts",
19
+ "sideEffects": [
20
+ "./tiptap_rusty_parser_wasm.js",
21
+ "./snippets/*"
22
+ ]
23
+ }
@@ -0,0 +1,118 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A Tiptap/ProseMirror document handle. Construct with [`TiptapDoc::from_json`]
6
+ * or [`TiptapDoc::from_json_string`].
7
+ */
8
+ export class TiptapDoc {
9
+ private constructor();
10
+ free(): void;
11
+ [Symbol.dispose](): void;
12
+ /**
13
+ * Add a mark of `mark_type` (optional `attrs` object) to the node at `path`;
14
+ * returns whether it was newly added.
15
+ */
16
+ addMark(path: any, mark_type: string, attrs: any): boolean;
17
+ /**
18
+ * All nodes whose attribute `key` equals `value`.
19
+ */
20
+ byAttr(key: string, value: any): any;
21
+ /**
22
+ * All nodes carrying a mark of `mark_type`.
23
+ */
24
+ byMark(mark_type: string): any;
25
+ /**
26
+ * All nodes of `node_type`, as an array of JS objects.
27
+ */
28
+ byType(node_type: string): any;
29
+ /**
30
+ * Unicode scalar count of the extracted text.
31
+ */
32
+ charCount(): number;
33
+ /**
34
+ * Child count of the node at `path`, or `undefined` if no such node.
35
+ */
36
+ childCount(path: any): number | undefined;
37
+ /**
38
+ * The first node of `node_type`, or `undefined`.
39
+ */
40
+ firstByType(node_type: string): any;
41
+ /**
42
+ * Build from a JS `JSONContent` object.
43
+ */
44
+ static fromJSON(value: any): TiptapDoc;
45
+ /**
46
+ * Build from a JSON string.
47
+ */
48
+ static fromJSONString(s: string): TiptapDoc;
49
+ /**
50
+ * Insert `child` at `index` under the node at `path` (index clamped).
51
+ */
52
+ insertChild(path: any, index: number, child: any): void;
53
+ /**
54
+ * True if the document has no schema violations.
55
+ */
56
+ isValid(schema: any): boolean;
57
+ /**
58
+ * The node at `path`, or `undefined`.
59
+ */
60
+ nodeAt(path: any): any;
61
+ /**
62
+ * Index paths of every node whose attribute `key` equals `value`.
63
+ */
64
+ pathsByAttr(key: string, value: any): any;
65
+ /**
66
+ * Index paths of every node carrying a mark of `mark_type`.
67
+ */
68
+ pathsByMark(mark_type: string): any;
69
+ /**
70
+ * Index paths (`number[][]`) of every node of `node_type`.
71
+ */
72
+ pathsByType(node_type: string): any;
73
+ /**
74
+ * Append `child` to the node at `path`.
75
+ */
76
+ pushChild(path: any, child: any): void;
77
+ /**
78
+ * Remove attribute `key` from the node at `path`; returns whether it existed.
79
+ */
80
+ removeAttr(path: any, key: string): boolean;
81
+ /**
82
+ * Remove the child at `index` under the node at `path`; returns it, or `undefined`.
83
+ */
84
+ removeChild(path: any, index: number): any;
85
+ /**
86
+ * Remove all marks of `mark_type` from the node at `path`; returns the count removed.
87
+ */
88
+ removeMark(path: any, mark_type: string): number;
89
+ /**
90
+ * Set attribute `key` to `value` on the node at `path`.
91
+ */
92
+ setAttr(path: any, key: string, value: any): void;
93
+ /**
94
+ * Set the `text` of the node at `path`.
95
+ */
96
+ setText(path: any, text: string): void;
97
+ /**
98
+ * Concatenated text of all descendant text nodes.
99
+ */
100
+ textContent(): string;
101
+ /**
102
+ * Serialize the document to a JS `JSONContent` object.
103
+ */
104
+ toJSON(): any;
105
+ /**
106
+ * Serialize the document to a JSON string.
107
+ */
108
+ toJSONString(): string;
109
+ /**
110
+ * Validate against a `schema` object; returns an array of violations
111
+ * (empty = valid).
112
+ */
113
+ validate(schema: any): any;
114
+ /**
115
+ * Word count of the extracted text.
116
+ */
117
+ wordCount(): number;
118
+ }
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./tiptap_rusty_parser_wasm.d.ts" */
2
+ import * as wasm from "./tiptap_rusty_parser_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./tiptap_rusty_parser_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ TiptapDoc
9
+ } from "./tiptap_rusty_parser_wasm_bg.js";
@@ -0,0 +1,798 @@
1
+ /**
2
+ * A Tiptap/ProseMirror document handle. Construct with [`TiptapDoc::from_json`]
3
+ * or [`TiptapDoc::from_json_string`].
4
+ */
5
+ export class TiptapDoc {
6
+ static __wrap(ptr) {
7
+ const obj = Object.create(TiptapDoc.prototype);
8
+ obj.__wbg_ptr = ptr;
9
+ TiptapDocFinalization.register(obj, obj.__wbg_ptr, obj);
10
+ return obj;
11
+ }
12
+ __destroy_into_raw() {
13
+ const ptr = this.__wbg_ptr;
14
+ this.__wbg_ptr = 0;
15
+ TiptapDocFinalization.unregister(this);
16
+ return ptr;
17
+ }
18
+ free() {
19
+ const ptr = this.__destroy_into_raw();
20
+ wasm.__wbg_tiptapdoc_free(ptr, 0);
21
+ }
22
+ /**
23
+ * Add a mark of `mark_type` (optional `attrs` object) to the node at `path`;
24
+ * returns whether it was newly added.
25
+ * @param {any} path
26
+ * @param {string} mark_type
27
+ * @param {any} attrs
28
+ * @returns {boolean}
29
+ */
30
+ addMark(path, mark_type, attrs) {
31
+ const ptr0 = passStringToWasm0(mark_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
32
+ const len0 = WASM_VECTOR_LEN;
33
+ const ret = wasm.tiptapdoc_addMark(this.__wbg_ptr, path, ptr0, len0, attrs);
34
+ if (ret[2]) {
35
+ throw takeFromExternrefTable0(ret[1]);
36
+ }
37
+ return ret[0] !== 0;
38
+ }
39
+ /**
40
+ * All nodes whose attribute `key` equals `value`.
41
+ * @param {string} key
42
+ * @param {any} value
43
+ * @returns {any}
44
+ */
45
+ byAttr(key, value) {
46
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
47
+ const len0 = WASM_VECTOR_LEN;
48
+ const ret = wasm.tiptapdoc_byAttr(this.__wbg_ptr, ptr0, len0, value);
49
+ if (ret[2]) {
50
+ throw takeFromExternrefTable0(ret[1]);
51
+ }
52
+ return takeFromExternrefTable0(ret[0]);
53
+ }
54
+ /**
55
+ * All nodes carrying a mark of `mark_type`.
56
+ * @param {string} mark_type
57
+ * @returns {any}
58
+ */
59
+ byMark(mark_type) {
60
+ const ptr0 = passStringToWasm0(mark_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
61
+ const len0 = WASM_VECTOR_LEN;
62
+ const ret = wasm.tiptapdoc_byMark(this.__wbg_ptr, ptr0, len0);
63
+ if (ret[2]) {
64
+ throw takeFromExternrefTable0(ret[1]);
65
+ }
66
+ return takeFromExternrefTable0(ret[0]);
67
+ }
68
+ /**
69
+ * All nodes of `node_type`, as an array of JS objects.
70
+ * @param {string} node_type
71
+ * @returns {any}
72
+ */
73
+ byType(node_type) {
74
+ const ptr0 = passStringToWasm0(node_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
75
+ const len0 = WASM_VECTOR_LEN;
76
+ const ret = wasm.tiptapdoc_byType(this.__wbg_ptr, ptr0, len0);
77
+ if (ret[2]) {
78
+ throw takeFromExternrefTable0(ret[1]);
79
+ }
80
+ return takeFromExternrefTable0(ret[0]);
81
+ }
82
+ /**
83
+ * Unicode scalar count of the extracted text.
84
+ * @returns {number}
85
+ */
86
+ charCount() {
87
+ const ret = wasm.tiptapdoc_charCount(this.__wbg_ptr);
88
+ return ret >>> 0;
89
+ }
90
+ /**
91
+ * Child count of the node at `path`, or `undefined` if no such node.
92
+ * @param {any} path
93
+ * @returns {number | undefined}
94
+ */
95
+ childCount(path) {
96
+ const ret = wasm.tiptapdoc_childCount(this.__wbg_ptr, path);
97
+ if (ret[2]) {
98
+ throw takeFromExternrefTable0(ret[1]);
99
+ }
100
+ return ret[0] === Number.MAX_SAFE_INTEGER ? undefined : ret[0];
101
+ }
102
+ /**
103
+ * The first node of `node_type`, or `undefined`.
104
+ * @param {string} node_type
105
+ * @returns {any}
106
+ */
107
+ firstByType(node_type) {
108
+ const ptr0 = passStringToWasm0(node_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
109
+ const len0 = WASM_VECTOR_LEN;
110
+ const ret = wasm.tiptapdoc_firstByType(this.__wbg_ptr, ptr0, len0);
111
+ if (ret[2]) {
112
+ throw takeFromExternrefTable0(ret[1]);
113
+ }
114
+ return takeFromExternrefTable0(ret[0]);
115
+ }
116
+ /**
117
+ * Build from a JS `JSONContent` object.
118
+ * @param {any} value
119
+ * @returns {TiptapDoc}
120
+ */
121
+ static fromJSON(value) {
122
+ const ret = wasm.tiptapdoc_fromJSON(value);
123
+ if (ret[2]) {
124
+ throw takeFromExternrefTable0(ret[1]);
125
+ }
126
+ return TiptapDoc.__wrap(ret[0]);
127
+ }
128
+ /**
129
+ * Build from a JSON string.
130
+ * @param {string} s
131
+ * @returns {TiptapDoc}
132
+ */
133
+ static fromJSONString(s) {
134
+ const ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
135
+ const len0 = WASM_VECTOR_LEN;
136
+ const ret = wasm.tiptapdoc_fromJSONString(ptr0, len0);
137
+ if (ret[2]) {
138
+ throw takeFromExternrefTable0(ret[1]);
139
+ }
140
+ return TiptapDoc.__wrap(ret[0]);
141
+ }
142
+ /**
143
+ * Insert `child` at `index` under the node at `path` (index clamped).
144
+ * @param {any} path
145
+ * @param {number} index
146
+ * @param {any} child
147
+ */
148
+ insertChild(path, index, child) {
149
+ const ret = wasm.tiptapdoc_insertChild(this.__wbg_ptr, path, index, child);
150
+ if (ret[1]) {
151
+ throw takeFromExternrefTable0(ret[0]);
152
+ }
153
+ }
154
+ /**
155
+ * True if the document has no schema violations.
156
+ * @param {any} schema
157
+ * @returns {boolean}
158
+ */
159
+ isValid(schema) {
160
+ const ret = wasm.tiptapdoc_isValid(this.__wbg_ptr, schema);
161
+ if (ret[2]) {
162
+ throw takeFromExternrefTable0(ret[1]);
163
+ }
164
+ return ret[0] !== 0;
165
+ }
166
+ /**
167
+ * The node at `path`, or `undefined`.
168
+ * @param {any} path
169
+ * @returns {any}
170
+ */
171
+ nodeAt(path) {
172
+ const ret = wasm.tiptapdoc_nodeAt(this.__wbg_ptr, path);
173
+ if (ret[2]) {
174
+ throw takeFromExternrefTable0(ret[1]);
175
+ }
176
+ return takeFromExternrefTable0(ret[0]);
177
+ }
178
+ /**
179
+ * Index paths of every node whose attribute `key` equals `value`.
180
+ * @param {string} key
181
+ * @param {any} value
182
+ * @returns {any}
183
+ */
184
+ pathsByAttr(key, value) {
185
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
186
+ const len0 = WASM_VECTOR_LEN;
187
+ const ret = wasm.tiptapdoc_pathsByAttr(this.__wbg_ptr, ptr0, len0, value);
188
+ if (ret[2]) {
189
+ throw takeFromExternrefTable0(ret[1]);
190
+ }
191
+ return takeFromExternrefTable0(ret[0]);
192
+ }
193
+ /**
194
+ * Index paths of every node carrying a mark of `mark_type`.
195
+ * @param {string} mark_type
196
+ * @returns {any}
197
+ */
198
+ pathsByMark(mark_type) {
199
+ const ptr0 = passStringToWasm0(mark_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
200
+ const len0 = WASM_VECTOR_LEN;
201
+ const ret = wasm.tiptapdoc_pathsByMark(this.__wbg_ptr, ptr0, len0);
202
+ if (ret[2]) {
203
+ throw takeFromExternrefTable0(ret[1]);
204
+ }
205
+ return takeFromExternrefTable0(ret[0]);
206
+ }
207
+ /**
208
+ * Index paths (`number[][]`) of every node of `node_type`.
209
+ * @param {string} node_type
210
+ * @returns {any}
211
+ */
212
+ pathsByType(node_type) {
213
+ const ptr0 = passStringToWasm0(node_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
214
+ const len0 = WASM_VECTOR_LEN;
215
+ const ret = wasm.tiptapdoc_pathsByType(this.__wbg_ptr, ptr0, len0);
216
+ if (ret[2]) {
217
+ throw takeFromExternrefTable0(ret[1]);
218
+ }
219
+ return takeFromExternrefTable0(ret[0]);
220
+ }
221
+ /**
222
+ * Append `child` to the node at `path`.
223
+ * @param {any} path
224
+ * @param {any} child
225
+ */
226
+ pushChild(path, child) {
227
+ const ret = wasm.tiptapdoc_pushChild(this.__wbg_ptr, path, child);
228
+ if (ret[1]) {
229
+ throw takeFromExternrefTable0(ret[0]);
230
+ }
231
+ }
232
+ /**
233
+ * Remove attribute `key` from the node at `path`; returns whether it existed.
234
+ * @param {any} path
235
+ * @param {string} key
236
+ * @returns {boolean}
237
+ */
238
+ removeAttr(path, key) {
239
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ const len0 = WASM_VECTOR_LEN;
241
+ const ret = wasm.tiptapdoc_removeAttr(this.__wbg_ptr, path, ptr0, len0);
242
+ if (ret[2]) {
243
+ throw takeFromExternrefTable0(ret[1]);
244
+ }
245
+ return ret[0] !== 0;
246
+ }
247
+ /**
248
+ * Remove the child at `index` under the node at `path`; returns it, or `undefined`.
249
+ * @param {any} path
250
+ * @param {number} index
251
+ * @returns {any}
252
+ */
253
+ removeChild(path, index) {
254
+ const ret = wasm.tiptapdoc_removeChild(this.__wbg_ptr, path, index);
255
+ if (ret[2]) {
256
+ throw takeFromExternrefTable0(ret[1]);
257
+ }
258
+ return takeFromExternrefTable0(ret[0]);
259
+ }
260
+ /**
261
+ * Remove all marks of `mark_type` from the node at `path`; returns the count removed.
262
+ * @param {any} path
263
+ * @param {string} mark_type
264
+ * @returns {number}
265
+ */
266
+ removeMark(path, mark_type) {
267
+ const ptr0 = passStringToWasm0(mark_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
268
+ const len0 = WASM_VECTOR_LEN;
269
+ const ret = wasm.tiptapdoc_removeMark(this.__wbg_ptr, path, ptr0, len0);
270
+ if (ret[2]) {
271
+ throw takeFromExternrefTable0(ret[1]);
272
+ }
273
+ return ret[0] >>> 0;
274
+ }
275
+ /**
276
+ * Set attribute `key` to `value` on the node at `path`.
277
+ * @param {any} path
278
+ * @param {string} key
279
+ * @param {any} value
280
+ */
281
+ setAttr(path, key, value) {
282
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
283
+ const len0 = WASM_VECTOR_LEN;
284
+ const ret = wasm.tiptapdoc_setAttr(this.__wbg_ptr, path, ptr0, len0, value);
285
+ if (ret[1]) {
286
+ throw takeFromExternrefTable0(ret[0]);
287
+ }
288
+ }
289
+ /**
290
+ * Set the `text` of the node at `path`.
291
+ * @param {any} path
292
+ * @param {string} text
293
+ */
294
+ setText(path, text) {
295
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
296
+ const len0 = WASM_VECTOR_LEN;
297
+ const ret = wasm.tiptapdoc_setText(this.__wbg_ptr, path, ptr0, len0);
298
+ if (ret[1]) {
299
+ throw takeFromExternrefTable0(ret[0]);
300
+ }
301
+ }
302
+ /**
303
+ * Concatenated text of all descendant text nodes.
304
+ * @returns {string}
305
+ */
306
+ textContent() {
307
+ let deferred1_0;
308
+ let deferred1_1;
309
+ try {
310
+ const ret = wasm.tiptapdoc_textContent(this.__wbg_ptr);
311
+ deferred1_0 = ret[0];
312
+ deferred1_1 = ret[1];
313
+ return getStringFromWasm0(ret[0], ret[1]);
314
+ } finally {
315
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
316
+ }
317
+ }
318
+ /**
319
+ * Serialize the document to a JS `JSONContent` object.
320
+ * @returns {any}
321
+ */
322
+ toJSON() {
323
+ const ret = wasm.tiptapdoc_toJSON(this.__wbg_ptr);
324
+ if (ret[2]) {
325
+ throw takeFromExternrefTable0(ret[1]);
326
+ }
327
+ return takeFromExternrefTable0(ret[0]);
328
+ }
329
+ /**
330
+ * Serialize the document to a JSON string.
331
+ * @returns {string}
332
+ */
333
+ toJSONString() {
334
+ let deferred2_0;
335
+ let deferred2_1;
336
+ try {
337
+ const ret = wasm.tiptapdoc_toJSONString(this.__wbg_ptr);
338
+ var ptr1 = ret[0];
339
+ var len1 = ret[1];
340
+ if (ret[3]) {
341
+ ptr1 = 0; len1 = 0;
342
+ throw takeFromExternrefTable0(ret[2]);
343
+ }
344
+ deferred2_0 = ptr1;
345
+ deferred2_1 = len1;
346
+ return getStringFromWasm0(ptr1, len1);
347
+ } finally {
348
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
349
+ }
350
+ }
351
+ /**
352
+ * Validate against a `schema` object; returns an array of violations
353
+ * (empty = valid).
354
+ * @param {any} schema
355
+ * @returns {any}
356
+ */
357
+ validate(schema) {
358
+ const ret = wasm.tiptapdoc_validate(this.__wbg_ptr, schema);
359
+ if (ret[2]) {
360
+ throw takeFromExternrefTable0(ret[1]);
361
+ }
362
+ return takeFromExternrefTable0(ret[0]);
363
+ }
364
+ /**
365
+ * Word count of the extracted text.
366
+ * @returns {number}
367
+ */
368
+ wordCount() {
369
+ const ret = wasm.tiptapdoc_wordCount(this.__wbg_ptr);
370
+ return ret >>> 0;
371
+ }
372
+ }
373
+ if (Symbol.dispose) TiptapDoc.prototype[Symbol.dispose] = TiptapDoc.prototype.free;
374
+ export function __wbg_Error_ef53bc310eb298a0(arg0, arg1) {
375
+ const ret = Error(getStringFromWasm0(arg0, arg1));
376
+ return ret;
377
+ }
378
+ export function __wbg_Number_6b506e6536831eaa(arg0) {
379
+ const ret = Number(arg0);
380
+ return ret;
381
+ }
382
+ export function __wbg_String_8564e559799eccda(arg0, arg1) {
383
+ const ret = String(arg1);
384
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
385
+ const len1 = WASM_VECTOR_LEN;
386
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
387
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
388
+ }
389
+ export function __wbg___wbindgen_bigint_get_as_i64_38130e98eecd467d(arg0, arg1) {
390
+ const v = arg1;
391
+ const ret = typeof(v) === 'bigint' ? v : undefined;
392
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
393
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
394
+ }
395
+ export function __wbg___wbindgen_boolean_get_1a45e2c38d4d41b9(arg0) {
396
+ const v = arg0;
397
+ const ret = typeof(v) === 'boolean' ? v : undefined;
398
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
399
+ }
400
+ export function __wbg___wbindgen_debug_string_0accd80f45e5faa2(arg0, arg1) {
401
+ const ret = debugString(arg1);
402
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
403
+ const len1 = WASM_VECTOR_LEN;
404
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
405
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
406
+ }
407
+ export function __wbg___wbindgen_in_70a403a56e771704(arg0, arg1) {
408
+ const ret = arg0 in arg1;
409
+ return ret;
410
+ }
411
+ export function __wbg___wbindgen_is_bigint_6ffd6468a9bc44b9(arg0) {
412
+ const ret = typeof(arg0) === 'bigint';
413
+ return ret;
414
+ }
415
+ export function __wbg___wbindgen_is_function_754e9f305ff6029e(arg0) {
416
+ const ret = typeof(arg0) === 'function';
417
+ return ret;
418
+ }
419
+ export function __wbg___wbindgen_is_null_87c3bfe968c6a5ad(arg0) {
420
+ const ret = arg0 === null;
421
+ return ret;
422
+ }
423
+ export function __wbg___wbindgen_is_object_56732c2bc353f41d(arg0) {
424
+ const val = arg0;
425
+ const ret = typeof(val) === 'object' && val !== null;
426
+ return ret;
427
+ }
428
+ export function __wbg___wbindgen_is_string_c236cabd84a4d769(arg0) {
429
+ const ret = typeof(arg0) === 'string';
430
+ return ret;
431
+ }
432
+ export function __wbg___wbindgen_is_undefined_67b456be8673d3d7(arg0) {
433
+ const ret = arg0 === undefined;
434
+ return ret;
435
+ }
436
+ export function __wbg___wbindgen_jsval_eq_1068e624fa87f6ab(arg0, arg1) {
437
+ const ret = arg0 === arg1;
438
+ return ret;
439
+ }
440
+ export function __wbg___wbindgen_jsval_loose_eq_2c56564c75129511(arg0, arg1) {
441
+ const ret = arg0 == arg1;
442
+ return ret;
443
+ }
444
+ export function __wbg___wbindgen_number_get_9bb1761122181af2(arg0, arg1) {
445
+ const obj = arg1;
446
+ const ret = typeof(obj) === 'number' ? obj : undefined;
447
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
448
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
449
+ }
450
+ export function __wbg___wbindgen_string_get_72bdf95d3ae505b1(arg0, arg1) {
451
+ const obj = arg1;
452
+ const ret = typeof(obj) === 'string' ? obj : undefined;
453
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
454
+ var len1 = WASM_VECTOR_LEN;
455
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
456
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
457
+ }
458
+ export function __wbg___wbindgen_throw_1506f2235d1bdba0(arg0, arg1) {
459
+ throw new Error(getStringFromWasm0(arg0, arg1));
460
+ }
461
+ export function __wbg_call_8a89609d89f6608a() { return handleError(function (arg0, arg1) {
462
+ const ret = arg0.call(arg1);
463
+ return ret;
464
+ }, arguments); }
465
+ export function __wbg_done_60cf307fcc680536(arg0) {
466
+ const ret = arg0.done;
467
+ return ret;
468
+ }
469
+ export function __wbg_entries_04b37a02507f1713(arg0) {
470
+ const ret = Object.entries(arg0);
471
+ return ret;
472
+ }
473
+ export function __wbg_get_1f8f054ddbaa7db2() { return handleError(function (arg0, arg1) {
474
+ const ret = Reflect.get(arg0, arg1);
475
+ return ret;
476
+ }, arguments); }
477
+ export function __wbg_get_2b48c7d0d006a781(arg0, arg1) {
478
+ const ret = arg0[arg1 >>> 0];
479
+ return ret;
480
+ }
481
+ export function __wbg_get_unchecked_33f6e5c9e2f2d6b2(arg0, arg1) {
482
+ const ret = arg0[arg1 >>> 0];
483
+ return ret;
484
+ }
485
+ export function __wbg_get_with_ref_key_6412cf3094599694(arg0, arg1) {
486
+ const ret = arg0[arg1];
487
+ return ret;
488
+ }
489
+ export function __wbg_instanceof_ArrayBuffer_8f49811467741499(arg0) {
490
+ let result;
491
+ try {
492
+ result = arg0 instanceof ArrayBuffer;
493
+ } catch (_) {
494
+ result = false;
495
+ }
496
+ const ret = result;
497
+ return ret;
498
+ }
499
+ export function __wbg_instanceof_Map_9fc06d9a951bcee6(arg0) {
500
+ let result;
501
+ try {
502
+ result = arg0 instanceof Map;
503
+ } catch (_) {
504
+ result = false;
505
+ }
506
+ const ret = result;
507
+ return ret;
508
+ }
509
+ export function __wbg_instanceof_Uint8Array_86f30649f63ef9c2(arg0) {
510
+ let result;
511
+ try {
512
+ result = arg0 instanceof Uint8Array;
513
+ } catch (_) {
514
+ result = false;
515
+ }
516
+ const ret = result;
517
+ return ret;
518
+ }
519
+ export function __wbg_isArray_67c2c9c4313f4448(arg0) {
520
+ const ret = Array.isArray(arg0);
521
+ return ret;
522
+ }
523
+ export function __wbg_isSafeInteger_66acec27e09e99a7(arg0) {
524
+ const ret = Number.isSafeInteger(arg0);
525
+ return ret;
526
+ }
527
+ export function __wbg_iterator_8732428d309e270e() {
528
+ const ret = Symbol.iterator;
529
+ return ret;
530
+ }
531
+ export function __wbg_length_4a591ecaa01354d9(arg0) {
532
+ const ret = arg0.length;
533
+ return ret;
534
+ }
535
+ export function __wbg_length_66f1a4b2e9026940(arg0) {
536
+ const ret = arg0.length;
537
+ return ret;
538
+ }
539
+ export function __wbg_new_578aeef4b6b94378(arg0) {
540
+ const ret = new Uint8Array(arg0);
541
+ return ret;
542
+ }
543
+ export function __wbg_new_622fc80556be2e26() {
544
+ const ret = new Map();
545
+ return ret;
546
+ }
547
+ export function __wbg_new_ce1ab61c1c2b300d() {
548
+ const ret = new Object();
549
+ return ret;
550
+ }
551
+ export function __wbg_new_d90091b82fdf5b91() {
552
+ const ret = new Array();
553
+ return ret;
554
+ }
555
+ export function __wbg_next_9e03acdf51c4960d(arg0) {
556
+ const ret = arg0.next;
557
+ return ret;
558
+ }
559
+ export function __wbg_next_eb8ca7351fa27906() { return handleError(function (arg0) {
560
+ const ret = arg0.next();
561
+ return ret;
562
+ }, arguments); }
563
+ export function __wbg_prototypesetcall_3249fc62a0fafa30(arg0, arg1, arg2) {
564
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
565
+ }
566
+ export function __wbg_set_52b1e1eb5bed906a(arg0, arg1, arg2) {
567
+ const ret = arg0.set(arg1, arg2);
568
+ return ret;
569
+ }
570
+ export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
571
+ arg0[arg1] = arg2;
572
+ }
573
+ export function __wbg_set_dca99999bba88a9a(arg0, arg1, arg2) {
574
+ arg0[arg1 >>> 0] = arg2;
575
+ }
576
+ export function __wbg_value_f3625092ee4b37f4(arg0) {
577
+ const ret = arg0.value;
578
+ return ret;
579
+ }
580
+ export function __wbindgen_cast_0000000000000001(arg0) {
581
+ // Cast intrinsic for `F64 -> Externref`.
582
+ const ret = arg0;
583
+ return ret;
584
+ }
585
+ export function __wbindgen_cast_0000000000000002(arg0) {
586
+ // Cast intrinsic for `I64 -> Externref`.
587
+ const ret = arg0;
588
+ return ret;
589
+ }
590
+ export function __wbindgen_cast_0000000000000003(arg0, arg1) {
591
+ // Cast intrinsic for `Ref(String) -> Externref`.
592
+ const ret = getStringFromWasm0(arg0, arg1);
593
+ return ret;
594
+ }
595
+ export function __wbindgen_cast_0000000000000004(arg0) {
596
+ // Cast intrinsic for `U64 -> Externref`.
597
+ const ret = BigInt.asUintN(64, arg0);
598
+ return ret;
599
+ }
600
+ export function __wbindgen_init_externref_table() {
601
+ const table = wasm.__wbindgen_externrefs;
602
+ const offset = table.grow(4);
603
+ table.set(0, undefined);
604
+ table.set(offset + 0, undefined);
605
+ table.set(offset + 1, null);
606
+ table.set(offset + 2, true);
607
+ table.set(offset + 3, false);
608
+ }
609
+ const TiptapDocFinalization = (typeof FinalizationRegistry === 'undefined')
610
+ ? { register: () => {}, unregister: () => {} }
611
+ : new FinalizationRegistry(ptr => wasm.__wbg_tiptapdoc_free(ptr, 1));
612
+
613
+ function addToExternrefTable0(obj) {
614
+ const idx = wasm.__externref_table_alloc();
615
+ wasm.__wbindgen_externrefs.set(idx, obj);
616
+ return idx;
617
+ }
618
+
619
+ function debugString(val) {
620
+ // primitive types
621
+ const type = typeof val;
622
+ if (type == 'number' || type == 'boolean' || val == null) {
623
+ return `${val}`;
624
+ }
625
+ if (type == 'string') {
626
+ return `"${val}"`;
627
+ }
628
+ if (type == 'symbol') {
629
+ const description = val.description;
630
+ if (description == null) {
631
+ return 'Symbol';
632
+ } else {
633
+ return `Symbol(${description})`;
634
+ }
635
+ }
636
+ if (type == 'function') {
637
+ const name = val.name;
638
+ if (typeof name == 'string' && name.length > 0) {
639
+ return `Function(${name})`;
640
+ } else {
641
+ return 'Function';
642
+ }
643
+ }
644
+ // objects
645
+ if (Array.isArray(val)) {
646
+ const length = val.length;
647
+ let debug = '[';
648
+ if (length > 0) {
649
+ debug += debugString(val[0]);
650
+ }
651
+ for(let i = 1; i < length; i++) {
652
+ debug += ', ' + debugString(val[i]);
653
+ }
654
+ debug += ']';
655
+ return debug;
656
+ }
657
+ // Test for built-in
658
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
659
+ let className;
660
+ if (builtInMatches && builtInMatches.length > 1) {
661
+ className = builtInMatches[1];
662
+ } else {
663
+ // Failed to match the standard '[object ClassName]'
664
+ return toString.call(val);
665
+ }
666
+ if (className == 'Object') {
667
+ // we're a user defined class or Object
668
+ // JSON.stringify avoids problems with cycles, and is generally much
669
+ // easier than looping through ownProperties of `val`.
670
+ try {
671
+ return 'Object(' + JSON.stringify(val) + ')';
672
+ } catch (_) {
673
+ return 'Object';
674
+ }
675
+ }
676
+ // errors
677
+ if (val instanceof Error) {
678
+ return `${val.name}: ${val.message}\n${val.stack}`;
679
+ }
680
+ // TODO we could test for more things here, like `Set`s and `Map`s.
681
+ return className;
682
+ }
683
+
684
+ function getArrayU8FromWasm0(ptr, len) {
685
+ ptr = ptr >>> 0;
686
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
687
+ }
688
+
689
+ let cachedDataViewMemory0 = null;
690
+ function getDataViewMemory0() {
691
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
692
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
693
+ }
694
+ return cachedDataViewMemory0;
695
+ }
696
+
697
+ function getStringFromWasm0(ptr, len) {
698
+ return decodeText(ptr >>> 0, len);
699
+ }
700
+
701
+ let cachedUint8ArrayMemory0 = null;
702
+ function getUint8ArrayMemory0() {
703
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
704
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
705
+ }
706
+ return cachedUint8ArrayMemory0;
707
+ }
708
+
709
+ function handleError(f, args) {
710
+ try {
711
+ return f.apply(this, args);
712
+ } catch (e) {
713
+ const idx = addToExternrefTable0(e);
714
+ wasm.__wbindgen_exn_store(idx);
715
+ }
716
+ }
717
+
718
+ function isLikeNone(x) {
719
+ return x === undefined || x === null;
720
+ }
721
+
722
+ function passStringToWasm0(arg, malloc, realloc) {
723
+ if (realloc === undefined) {
724
+ const buf = cachedTextEncoder.encode(arg);
725
+ const ptr = malloc(buf.length, 1) >>> 0;
726
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
727
+ WASM_VECTOR_LEN = buf.length;
728
+ return ptr;
729
+ }
730
+
731
+ let len = arg.length;
732
+ let ptr = malloc(len, 1) >>> 0;
733
+
734
+ const mem = getUint8ArrayMemory0();
735
+
736
+ let offset = 0;
737
+
738
+ for (; offset < len; offset++) {
739
+ const code = arg.charCodeAt(offset);
740
+ if (code > 0x7F) break;
741
+ mem[ptr + offset] = code;
742
+ }
743
+ if (offset !== len) {
744
+ if (offset !== 0) {
745
+ arg = arg.slice(offset);
746
+ }
747
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
748
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
749
+ const ret = cachedTextEncoder.encodeInto(arg, view);
750
+
751
+ offset += ret.written;
752
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
753
+ }
754
+
755
+ WASM_VECTOR_LEN = offset;
756
+ return ptr;
757
+ }
758
+
759
+ function takeFromExternrefTable0(idx) {
760
+ const value = wasm.__wbindgen_externrefs.get(idx);
761
+ wasm.__externref_table_dealloc(idx);
762
+ return value;
763
+ }
764
+
765
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
766
+ cachedTextDecoder.decode();
767
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
768
+ let numBytesDecoded = 0;
769
+ function decodeText(ptr, len) {
770
+ numBytesDecoded += len;
771
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
772
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
773
+ cachedTextDecoder.decode();
774
+ numBytesDecoded = len;
775
+ }
776
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
777
+ }
778
+
779
+ const cachedTextEncoder = new TextEncoder();
780
+
781
+ if (!('encodeInto' in cachedTextEncoder)) {
782
+ cachedTextEncoder.encodeInto = function (arg, view) {
783
+ const buf = cachedTextEncoder.encode(arg);
784
+ view.set(buf);
785
+ return {
786
+ read: arg.length,
787
+ written: buf.length
788
+ };
789
+ };
790
+ }
791
+
792
+ let WASM_VECTOR_LEN = 0;
793
+
794
+
795
+ let wasm;
796
+ export function __wbg_set_wasm(val) {
797
+ wasm = val;
798
+ }
Binary file