mdream 1.7.2 → 2.0.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.
@@ -1,6 +1,9 @@
1
1
  /* @ts-self-types="./mdream_edge.d.ts" */
2
2
 
3
3
  export class MarkdownStream {
4
+ [Symbol.dispose]() {
5
+ this.free();
6
+ }
4
7
  __destroy_into_raw() {
5
8
  const ptr = this.__wbg_ptr;
6
9
  this.__wbg_ptr = 0;
@@ -40,6 +43,33 @@ export class MarkdownStream {
40
43
  return this;
41
44
  }
42
45
  /**
46
+ * Byte chunk in, string out, skipping the transcode per chunk. A sequence
47
+ * split across chunks carries to the next call rather than decoding early,
48
+ * matching `TextDecoder({ stream: true })`; invalid bytes become U+FFFD.
49
+ * @param {Uint8Array} chunk
50
+ * @returns {string}
51
+ */
52
+ processChunkBytes(chunk) {
53
+ let deferred2_0;
54
+ let deferred2_1;
55
+ try {
56
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
57
+ const ptr0 = passArray8ToWasm0(chunk, wasm.__wbindgen_export);
58
+ const len0 = WASM_VECTOR_LEN;
59
+ wasm.markdownstream_processChunkBytes(retptr, this.__wbg_ptr, ptr0, len0);
60
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
61
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
62
+ deferred2_0 = r0;
63
+ deferred2_1 = r1;
64
+ return getStringFromWasm0(r0, r1);
65
+ } finally {
66
+ wasm.__wbindgen_add_to_stack_pointer(16);
67
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
68
+ }
69
+ }
70
+ /**
71
+ * A carried byte tail cannot be completed by a string chunk, so it is
72
+ * flushed first. Byte and string chunks may be mixed freely.
43
73
  * @param {string} chunk
44
74
  * @returns {string}
45
75
  */
@@ -61,8 +91,17 @@ export class MarkdownStream {
61
91
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
62
92
  }
63
93
  }
94
+ /**
95
+ * Frontmatter and extracted elements collected so far, as
96
+ * `{ frontmatter?, extracted? }`. Call after `finish()` for the complete
97
+ * data. Extracted elements drain on each call.
98
+ * @returns {any}
99
+ */
100
+ takeData() {
101
+ const ret = wasm.markdownstream_takeData(this.__wbg_ptr);
102
+ return takeObject(ret);
103
+ }
64
104
  }
65
- if (Symbol.dispose) MarkdownStream.prototype[Symbol.dispose] = MarkdownStream.prototype.free;
66
105
 
67
106
  /**
68
107
  * Consumes the message of the panic that aborted the last export call.
@@ -109,6 +148,34 @@ export function htmlToMarkdown(html, options) {
109
148
  }
110
149
  }
111
150
 
151
+ /**
152
+ * Bytes in, string out: skips the transcode (~14% of a convert) for a
153
+ * caller already holding UTF-8 bytes. Encoding a string to get here
154
+ * measures 1-16% *slower* than [`html_to_markdown`] — only worth it when
155
+ * the bytes are already in hand.
156
+ * @param {Uint8Array} html
157
+ * @param {any} options
158
+ * @returns {string}
159
+ */
160
+ export function htmlToMarkdownBytes(html, options) {
161
+ let deferred2_0;
162
+ let deferred2_1;
163
+ try {
164
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
165
+ const ptr0 = passArray8ToWasm0(html, wasm.__wbindgen_export);
166
+ const len0 = WASM_VECTOR_LEN;
167
+ wasm.htmlToMarkdownBytes(retptr, ptr0, len0, addHeapObject(options));
168
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
169
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
170
+ deferred2_0 = r0;
171
+ deferred2_1 = r1;
172
+ return getStringFromWasm0(r0, r1);
173
+ } finally {
174
+ wasm.__wbindgen_add_to_stack_pointer(16);
175
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
176
+ }
177
+ }
178
+
112
179
  /**
113
180
  * @param {string} html
114
181
  * @param {any} options
@@ -127,26 +194,26 @@ export function install_panic_hook() {
127
194
  function __wbg_get_imports() {
128
195
  const import0 = {
129
196
  __proto__: null,
130
- __wbg___wbindgen_boolean_get_c9c83ebd41b34df3: function(arg0) {
197
+ __wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
131
198
  const v = getObject(arg0);
132
199
  const ret = typeof(v) === 'boolean' ? v : undefined;
133
200
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
134
201
  },
135
- __wbg___wbindgen_is_null_7d13f41e1a2d5140: function(arg0) {
202
+ __wbg___wbindgen_is_null_e343b7d08827ba72: function(arg0) {
136
203
  const ret = getObject(arg0) === null;
137
204
  return ret;
138
205
  },
139
- __wbg___wbindgen_is_undefined_6cff064c44e0d823: function(arg0) {
206
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
140
207
  const ret = getObject(arg0) === undefined;
141
208
  return ret;
142
209
  },
143
- __wbg___wbindgen_number_get_136b9679cab35cfb: function(arg0, arg1) {
210
+ __wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
144
211
  const obj = getObject(arg1);
145
212
  const ret = typeof(obj) === 'number' ? obj : undefined;
146
213
  getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
147
214
  getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
148
215
  },
149
- __wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
216
+ __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
150
217
  const obj = getObject(arg1);
151
218
  const ret = typeof(obj) === 'string' ? obj : undefined;
152
219
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -154,50 +221,50 @@ function __wbg_get_imports() {
154
221
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
155
222
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
156
223
  },
157
- __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
224
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
158
225
  throw new Error(getStringFromWasm0(arg0, arg1));
159
226
  },
160
- __wbg_entries_7774d489e1da5f4f: function(arg0) {
227
+ __wbg_entries_fb6397112b1de25f: function(arg0) {
161
228
  const ret = Object.entries(getObject(arg0));
162
229
  return addHeapObject(ret);
163
230
  },
164
- __wbg_from_74f3d90e0ff11240: function(arg0) {
231
+ __wbg_from_296ca31f8d0f1c52: function(arg0) {
165
232
  const ret = Array.from(getObject(arg0));
166
233
  return addHeapObject(ret);
167
234
  },
168
- __wbg_get_971a0c45d172643f: function() { return handleError(function (arg0, arg1) {
235
+ __wbg_get_31af05bd4842a84f: function() { return handleError(function (arg0, arg1) {
169
236
  const ret = Reflect.get(getObject(arg0), getObject(arg1));
170
237
  return addHeapObject(ret);
171
238
  }, arguments); },
172
- __wbg_get_c0c8f8d7da0c03dd: function(arg0, arg1) {
239
+ __wbg_get_6c896e0571ddae51: function(arg0, arg1) {
173
240
  const ret = getObject(arg0)[arg1 >>> 0];
174
241
  return addHeapObject(ret);
175
242
  },
176
- __wbg_isArray_6339f732981044bf: function(arg0) {
243
+ __wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
177
244
  const ret = Array.isArray(getObject(arg0));
178
245
  return ret;
179
246
  },
180
- __wbg_length_ecfa2c63d3d0d82c: function(arg0) {
247
+ __wbg_length_d4bdea10311bd9cf: function(arg0) {
181
248
  const ret = getObject(arg0).length;
182
249
  return ret;
183
250
  },
184
- __wbg_new_116be93542d39019: function() {
185
- const ret = new Array();
251
+ __wbg_new_617a8cdb8bb1130e: function() {
252
+ const ret = new Object();
186
253
  return addHeapObject(ret);
187
254
  },
188
- __wbg_new_ebe3e0f6837f0879: function() {
189
- const ret = new Object();
255
+ __wbg_new_ee2291f50781bf1d: function() {
256
+ const ret = new Array();
190
257
  return addHeapObject(ret);
191
258
  },
192
- __wbg_push_adb0107829f02d75: function(arg0, arg1) {
259
+ __wbg_push_2baf45db356cf468: function(arg0, arg1) {
193
260
  const ret = getObject(arg0).push(getObject(arg1));
194
261
  return ret;
195
262
  },
196
- __wbg_set_8155bb79a948541b: function() { return handleError(function (arg0, arg1, arg2) {
263
+ __wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
197
264
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
198
265
  return ret;
199
266
  }, arguments); },
200
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
267
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
201
268
  // Cast intrinsic for `Ref(String) -> Externref`.
202
269
  const ret = getStringFromWasm0(arg0, arg1);
203
270
  return addHeapObject(ret);
@@ -274,6 +341,13 @@ function isLikeNone(x) {
274
341
  return x === undefined || x === null;
275
342
  }
276
343
 
344
+ function passArray8ToWasm0(arg, malloc) {
345
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
346
+ getUint8ArrayMemory0().set(arg, ptr / 1);
347
+ WASM_VECTOR_LEN = arg.length;
348
+ return ptr;
349
+ }
350
+
277
351
  function passStringToWasm0(arg, malloc, realloc) {
278
352
  if (realloc === undefined) {
279
353
  const buf = cachedTextEncoder.encode(arg);
Binary file
@@ -4,11 +4,14 @@ export const memory: WebAssembly.Memory;
4
4
  export const __mdreamTakePanicMessage: (a: number) => void;
5
5
  export const __wbg_markdownstream_free: (a: number, b: number) => void;
6
6
  export const htmlToMarkdown: (a: number, b: number, c: number, d: number) => void;
7
+ export const htmlToMarkdownBytes: (a: number, b: number, c: number, d: number) => void;
7
8
  export const htmlToMarkdownResult: (a: number, b: number, c: number) => number;
8
9
  export const install_panic_hook: () => void;
9
10
  export const markdownstream_finish: (a: number, b: number) => void;
10
11
  export const markdownstream_new: (a: number) => number;
11
12
  export const markdownstream_processChunk: (a: number, b: number, c: number, d: number) => void;
13
+ export const markdownstream_processChunkBytes: (a: number, b: number, c: number, d: number) => void;
14
+ export const markdownstream_takeData: (a: number) => number;
12
15
  export const __wbindgen_export: (a: number, b: number) => number;
13
16
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
14
17
  export const __wbindgen_export3: (a: number) => void;
package/wasm/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mdream-edge",
3
3
  "type": "module",
4
4
  "description": "WebAssembly edge runtime bindings for mdream HTML-to-Markdown converter",
5
- "version": "1.7.2",
5
+ "version": "2.0.0",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "mdream_edge_bg.wasm",
@@ -6,7 +6,23 @@ export class MarkdownStream {
6
6
  [Symbol.dispose](): void;
7
7
  finish(): string;
8
8
  constructor(options: any);
9
+ /**
10
+ * Byte chunk in, string out, skipping the transcode per chunk. A sequence
11
+ * split across chunks carries to the next call rather than decoding early,
12
+ * matching `TextDecoder({ stream: true })`; invalid bytes become U+FFFD.
13
+ */
14
+ processChunkBytes(chunk: Uint8Array): string;
15
+ /**
16
+ * A carried byte tail cannot be completed by a string chunk, so it is
17
+ * flushed first. Byte and string chunks may be mixed freely.
18
+ */
9
19
  processChunk(chunk: string): string;
20
+ /**
21
+ * Frontmatter and extracted elements collected so far, as
22
+ * `{ frontmatter?, extracted? }`. Call after `finish()` for the complete
23
+ * data. Extracted elements drain on each call.
24
+ */
25
+ takeData(): any;
10
26
  }
11
27
 
12
28
  /**
@@ -16,6 +32,14 @@ export function __mdreamTakePanicMessage(): string | undefined;
16
32
 
17
33
  export function htmlToMarkdown(html: string, options: any): string;
18
34
 
35
+ /**
36
+ * Bytes in, string out: skips the transcode (~14% of a convert) for a
37
+ * caller already holding UTF-8 bytes. Encoding a string to get here
38
+ * measures 1-16% *slower* than [`html_to_markdown`] — only worth it when
39
+ * the bytes are already in hand.
40
+ */
41
+ export function htmlToMarkdownBytes(html: Uint8Array, options: any): string;
42
+
19
43
  export function htmlToMarkdownResult(html: string, options: any): any;
20
44
 
21
45
  export function install_panic_hook(): void;
@@ -1,9 +1,13 @@
1
1
  /* @ts-self-types="./mdream_edge.d.ts" */
2
- import * as wasm from "./mdream_edge_bg.wasm";
2
+ import wasmModule from "./mdream_edge_bg.wasm";
3
+ import * as imports from "./mdream_edge_bg.js";
4
+ const wasm = wasmModule instanceof WebAssembly.Module
5
+ ? new WebAssembly.Instance(wasmModule, { "./mdream_edge_bg.js": imports }).exports
6
+ : wasmModule;
3
7
  import { __wbg_set_wasm } from "./mdream_edge_bg.js";
4
8
 
5
9
  __wbg_set_wasm(wasm);
6
10
  wasm.__wbindgen_start();
7
11
  export {
8
- MarkdownStream, __mdreamTakePanicMessage, htmlToMarkdown, htmlToMarkdownResult, install_panic_hook
12
+ MarkdownStream, __mdreamTakePanicMessage, htmlToMarkdown, htmlToMarkdownBytes, htmlToMarkdownResult, install_panic_hook
9
13
  } from "./mdream_edge_bg.js";
@@ -1,4 +1,7 @@
1
1
  export class MarkdownStream {
2
+ [Symbol.dispose]() {
3
+ this.free();
4
+ }
2
5
  __destroy_into_raw() {
3
6
  const ptr = this.__wbg_ptr;
4
7
  this.__wbg_ptr = 0;
@@ -38,6 +41,33 @@ export class MarkdownStream {
38
41
  return this;
39
42
  }
40
43
  /**
44
+ * Byte chunk in, string out, skipping the transcode per chunk. A sequence
45
+ * split across chunks carries to the next call rather than decoding early,
46
+ * matching `TextDecoder({ stream: true })`; invalid bytes become U+FFFD.
47
+ * @param {Uint8Array} chunk
48
+ * @returns {string}
49
+ */
50
+ processChunkBytes(chunk) {
51
+ let deferred2_0;
52
+ let deferred2_1;
53
+ try {
54
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
55
+ const ptr0 = passArray8ToWasm0(chunk, wasm.__wbindgen_export);
56
+ const len0 = WASM_VECTOR_LEN;
57
+ wasm.markdownstream_processChunkBytes(retptr, this.__wbg_ptr, ptr0, len0);
58
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
59
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
60
+ deferred2_0 = r0;
61
+ deferred2_1 = r1;
62
+ return getStringFromWasm0(r0, r1);
63
+ } finally {
64
+ wasm.__wbindgen_add_to_stack_pointer(16);
65
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
66
+ }
67
+ }
68
+ /**
69
+ * A carried byte tail cannot be completed by a string chunk, so it is
70
+ * flushed first. Byte and string chunks may be mixed freely.
41
71
  * @param {string} chunk
42
72
  * @returns {string}
43
73
  */
@@ -59,8 +89,17 @@ export class MarkdownStream {
59
89
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
60
90
  }
61
91
  }
92
+ /**
93
+ * Frontmatter and extracted elements collected so far, as
94
+ * `{ frontmatter?, extracted? }`. Call after `finish()` for the complete
95
+ * data. Extracted elements drain on each call.
96
+ * @returns {any}
97
+ */
98
+ takeData() {
99
+ const ret = wasm.markdownstream_takeData(this.__wbg_ptr);
100
+ return takeObject(ret);
101
+ }
62
102
  }
63
- if (Symbol.dispose) MarkdownStream.prototype[Symbol.dispose] = MarkdownStream.prototype.free;
64
103
 
65
104
  /**
66
105
  * Consumes the message of the panic that aborted the last export call.
@@ -107,6 +146,34 @@ export function htmlToMarkdown(html, options) {
107
146
  }
108
147
  }
109
148
 
149
+ /**
150
+ * Bytes in, string out: skips the transcode (~14% of a convert) for a
151
+ * caller already holding UTF-8 bytes. Encoding a string to get here
152
+ * measures 1-16% *slower* than [`html_to_markdown`] — only worth it when
153
+ * the bytes are already in hand.
154
+ * @param {Uint8Array} html
155
+ * @param {any} options
156
+ * @returns {string}
157
+ */
158
+ export function htmlToMarkdownBytes(html, options) {
159
+ let deferred2_0;
160
+ let deferred2_1;
161
+ try {
162
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
163
+ const ptr0 = passArray8ToWasm0(html, wasm.__wbindgen_export);
164
+ const len0 = WASM_VECTOR_LEN;
165
+ wasm.htmlToMarkdownBytes(retptr, ptr0, len0, addHeapObject(options));
166
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
167
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
168
+ deferred2_0 = r0;
169
+ deferred2_1 = r1;
170
+ return getStringFromWasm0(r0, r1);
171
+ } finally {
172
+ wasm.__wbindgen_add_to_stack_pointer(16);
173
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
174
+ }
175
+ }
176
+
110
177
  /**
111
178
  * @param {string} html
112
179
  * @param {any} options
@@ -122,26 +189,26 @@ export function htmlToMarkdownResult(html, options) {
122
189
  export function install_panic_hook() {
123
190
  wasm.install_panic_hook();
124
191
  }
125
- export function __wbg___wbindgen_boolean_get_c9c83ebd41b34df3(arg0) {
192
+ export function __wbg___wbindgen_boolean_get_5b446f51afd21013(arg0) {
126
193
  const v = getObject(arg0);
127
194
  const ret = typeof(v) === 'boolean' ? v : undefined;
128
195
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
129
196
  }
130
- export function __wbg___wbindgen_is_null_7d13f41e1a2d5140(arg0) {
197
+ export function __wbg___wbindgen_is_null_e343b7d08827ba72(arg0) {
131
198
  const ret = getObject(arg0) === null;
132
199
  return ret;
133
200
  }
134
- export function __wbg___wbindgen_is_undefined_6cff064c44e0d823(arg0) {
201
+ export function __wbg___wbindgen_is_undefined_8865fb403f8fe9d8(arg0) {
135
202
  const ret = getObject(arg0) === undefined;
136
203
  return ret;
137
204
  }
138
- export function __wbg___wbindgen_number_get_136b9679cab35cfb(arg0, arg1) {
205
+ export function __wbg___wbindgen_number_get_2e0e7dee9f701a71(arg0, arg1) {
139
206
  const obj = getObject(arg1);
140
207
  const ret = typeof(obj) === 'number' ? obj : undefined;
141
208
  getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
142
209
  getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
143
210
  }
144
- export function __wbg___wbindgen_string_get_d154f1e671052120(arg0, arg1) {
211
+ export function __wbg___wbindgen_string_get_0380ccaa2f57f0d9(arg0, arg1) {
145
212
  const obj = getObject(arg1);
146
213
  const ret = typeof(obj) === 'string' ? obj : undefined;
147
214
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -149,50 +216,50 @@ export function __wbg___wbindgen_string_get_d154f1e671052120(arg0, arg1) {
149
216
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
150
217
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
151
218
  }
152
- export function __wbg___wbindgen_throw_bb96b2010945f0bc(arg0, arg1) {
219
+ export function __wbg___wbindgen_throw_41e9ee4f547fc59a(arg0, arg1) {
153
220
  throw new Error(getStringFromWasm0(arg0, arg1));
154
221
  }
155
- export function __wbg_entries_7774d489e1da5f4f(arg0) {
222
+ export function __wbg_entries_fb6397112b1de25f(arg0) {
156
223
  const ret = Object.entries(getObject(arg0));
157
224
  return addHeapObject(ret);
158
225
  }
159
- export function __wbg_from_74f3d90e0ff11240(arg0) {
226
+ export function __wbg_from_296ca31f8d0f1c52(arg0) {
160
227
  const ret = Array.from(getObject(arg0));
161
228
  return addHeapObject(ret);
162
229
  }
163
- export function __wbg_get_971a0c45d172643f() { return handleError(function (arg0, arg1) {
230
+ export function __wbg_get_31af05bd4842a84f() { return handleError(function (arg0, arg1) {
164
231
  const ret = Reflect.get(getObject(arg0), getObject(arg1));
165
232
  return addHeapObject(ret);
166
233
  }, arguments); }
167
- export function __wbg_get_c0c8f8d7da0c03dd(arg0, arg1) {
234
+ export function __wbg_get_6c896e0571ddae51(arg0, arg1) {
168
235
  const ret = getObject(arg0)[arg1 >>> 0];
169
236
  return addHeapObject(ret);
170
237
  }
171
- export function __wbg_isArray_6339f732981044bf(arg0) {
238
+ export function __wbg_isArray_e15a2ff68ffdbef2(arg0) {
172
239
  const ret = Array.isArray(getObject(arg0));
173
240
  return ret;
174
241
  }
175
- export function __wbg_length_ecfa2c63d3d0d82c(arg0) {
242
+ export function __wbg_length_d4bdea10311bd9cf(arg0) {
176
243
  const ret = getObject(arg0).length;
177
244
  return ret;
178
245
  }
179
- export function __wbg_new_116be93542d39019() {
180
- const ret = new Array();
246
+ export function __wbg_new_617a8cdb8bb1130e() {
247
+ const ret = new Object();
181
248
  return addHeapObject(ret);
182
249
  }
183
- export function __wbg_new_ebe3e0f6837f0879() {
184
- const ret = new Object();
250
+ export function __wbg_new_ee2291f50781bf1d() {
251
+ const ret = new Array();
185
252
  return addHeapObject(ret);
186
253
  }
187
- export function __wbg_push_adb0107829f02d75(arg0, arg1) {
254
+ export function __wbg_push_2baf45db356cf468(arg0, arg1) {
188
255
  const ret = getObject(arg0).push(getObject(arg1));
189
256
  return ret;
190
257
  }
191
- export function __wbg_set_8155bb79a948541b() { return handleError(function (arg0, arg1, arg2) {
258
+ export function __wbg_set_145a351398b48c65() { return handleError(function (arg0, arg1, arg2) {
192
259
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
193
260
  return ret;
194
261
  }, arguments); }
195
- export function __wbindgen_cast_0000000000000001(arg0, arg1) {
262
+ export function __wbindgen_generic_0000000000000001(arg0, arg1) {
196
263
  // Cast intrinsic for `Ref(String) -> Externref`.
197
264
  const ret = getStringFromWasm0(arg0, arg1);
198
265
  return addHeapObject(ret);
@@ -262,6 +329,13 @@ function isLikeNone(x) {
262
329
  return x === undefined || x === null;
263
330
  }
264
331
 
332
+ function passArray8ToWasm0(arg, malloc) {
333
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
334
+ getUint8ArrayMemory0().set(arg, ptr / 1);
335
+ WASM_VECTOR_LEN = arg.length;
336
+ return ptr;
337
+ }
338
+
265
339
  function passStringToWasm0(arg, malloc, realloc) {
266
340
  if (realloc === undefined) {
267
341
  const buf = cachedTextEncoder.encode(arg);
Binary file
@@ -4,11 +4,14 @@ export const memory: WebAssembly.Memory;
4
4
  export const __mdreamTakePanicMessage: (a: number) => void;
5
5
  export const __wbg_markdownstream_free: (a: number, b: number) => void;
6
6
  export const htmlToMarkdown: (a: number, b: number, c: number, d: number) => void;
7
+ export const htmlToMarkdownBytes: (a: number, b: number, c: number, d: number) => void;
7
8
  export const htmlToMarkdownResult: (a: number, b: number, c: number) => number;
8
9
  export const install_panic_hook: () => void;
9
10
  export const markdownstream_finish: (a: number, b: number) => void;
10
11
  export const markdownstream_new: (a: number) => number;
11
12
  export const markdownstream_processChunk: (a: number, b: number, c: number, d: number) => void;
13
+ export const markdownstream_processChunkBytes: (a: number, b: number, c: number, d: number) => void;
14
+ export const markdownstream_takeData: (a: number) => number;
12
15
  export const __wbindgen_export: (a: number, b: number) => number;
13
16
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
14
17
  export const __wbindgen_export3: (a: number) => void;
@@ -2,7 +2,7 @@
2
2
  "name": "mdream-edge",
3
3
  "type": "module",
4
4
  "description": "WebAssembly edge runtime bindings for mdream HTML-to-Markdown converter",
5
- "version": "1.7.2",
5
+ "version": "2.0.0",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "mdream_edge_bg.wasm",
package/dist/worker.mjs DELETED
@@ -1,100 +0,0 @@
1
- let _worker = null;
2
- let _ready = null;
3
- let _idCounter = 0;
4
- const _pending = /* @__PURE__ */ new Map();
5
- const WASM_RE = /\.wasm$/;
6
- function getWorkerBlob(wasmUrl) {
7
- const code = `
8
- // namespace import: the URL is caller-supplied and may point at an older build
9
- import init, * as engine from '${wasmUrl.replace(WASM_RE, ".js")}';
10
- const { htmlToMarkdownResult } = engine;
11
-
12
- let ready = false;
13
-
14
- async function initialize() {
15
- await init('${wasmUrl}');
16
- ready = true;
17
- self.postMessage({ type: 'ready' });
18
- }
19
-
20
- initialize().catch(e => {
21
- self.postMessage({ type: 'error', id: -1, message: 'WASM init failed: ' + e.message });
22
- });
23
-
24
- self.onmessage = function(e) {
25
- const msg = e.data;
26
- if (msg.type === 'convert') {
27
- if (!ready) {
28
- self.postMessage({ id: msg.id, type: 'error', message: 'Worker not ready' });
29
- return;
30
- }
31
- try {
32
- const result = htmlToMarkdownResult(msg.html, msg.options || {});
33
- self.postMessage({ id: msg.id, type: 'result', data: result.markdown || '' });
34
- } catch (err) {
35
- // WASM aborts on panic (#195): the message is stashed by the panic hook
36
- const panic = engine.__mdreamTakePanicMessage?.();
37
- self.postMessage({ id: msg.id, type: 'error', message: panic || err.message });
38
- }
39
- }
40
- };`;
41
- return new Blob([code], { type: "application/javascript" });
42
- }
43
- function onMessage(e) {
44
- const msg = e.data;
45
- if (msg.type === "ready") return;
46
- if ("id" in msg) {
47
- const pending = _pending.get(msg.id);
48
- if (!pending) return;
49
- _pending.delete(msg.id);
50
- if (msg.type === "result") pending.resolve(msg.data);
51
- else pending.reject(new Error(msg.message));
52
- }
53
- }
54
- function initWorker(wasmUrl) {
55
- if (_ready) return _ready;
56
- _ready = new Promise((resolve, reject) => {
57
- const blob = getWorkerBlob(wasmUrl);
58
- const url = URL.createObjectURL(blob);
59
- _worker = new Worker(url, { type: "module" });
60
- _worker.onmessage = (e) => {
61
- if (e.data.type === "ready") {
62
- _worker.onmessage = onMessage;
63
- URL.revokeObjectURL(url);
64
- resolve();
65
- } else if (e.data.type === "error") reject(new Error(e.data.message));
66
- };
67
- _worker.onerror = (e) => {
68
- reject(/* @__PURE__ */ new Error(`Worker error: ${e.message}`));
69
- };
70
- });
71
- return _ready;
72
- }
73
- function htmlToMarkdown(html, options) {
74
- if (!_worker || !_ready) return Promise.reject(/* @__PURE__ */ new Error("Call initWorker() before htmlToMarkdown()"));
75
- return _ready.then(() => {
76
- const id = _idCounter++;
77
- return new Promise((resolve, reject) => {
78
- _pending.set(id, {
79
- resolve,
80
- reject
81
- });
82
- _worker.postMessage({
83
- id,
84
- type: "convert",
85
- html,
86
- options
87
- });
88
- });
89
- });
90
- }
91
- function terminateWorker() {
92
- if (_worker) {
93
- _worker.terminate();
94
- _worker = null;
95
- }
96
- _ready = null;
97
- for (const [, pending] of _pending) pending.reject(/* @__PURE__ */ new Error("Worker terminated"));
98
- _pending.clear();
99
- }
100
- export { htmlToMarkdown, initWorker, terminateWorker };