mdream 2.0.3 → 2.2.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/dist/index.mjs CHANGED
@@ -120,16 +120,23 @@ function deliverPluginData(data, { frontmatterCallback, extractionHandlers }) {
120
120
  function hasCallbacks({ frontmatterCallback, extractionHandlers }) {
121
121
  return !!frontmatterCallback || !!extractionHandlers;
122
122
  }
123
+ new TextEncoder();
123
124
  function convertResult(convert, html, options = {}) {
124
125
  const resolved = resolveOptions(options);
125
126
  const result = convert(html, resolved.napiOpts);
126
127
  deliverPluginData(result, resolved);
127
128
  return result;
128
129
  }
130
+ function freeStream(stream) {
131
+ try {
132
+ stream.free?.();
133
+ } catch {}
134
+ }
129
135
  async function* pumpStream(stream, htmlStream, callbacks, { mapError = (error) => error } = {}) {
130
- const reader = htmlStream.getReader();
131
136
  const decoder = stream.processChunkBytes ? void 0 : new TextDecoder();
137
+ let reader;
132
138
  try {
139
+ reader = htmlStream.getReader();
133
140
  while (true) {
134
141
  const { done, value } = await reader.read();
135
142
  if (done) break;
@@ -149,7 +156,8 @@ async function* pumpStream(stream, htmlStream, callbacks, { mapError = (error) =
149
156
  } catch (error) {
150
157
  throw mapError(error);
151
158
  } finally {
152
- reader.releaseLock();
159
+ freeStream(stream);
160
+ reader?.releaseLock();
153
161
  }
154
162
  }
155
163
  function createSurrogateCarry() {
package/dist/wasm.mjs CHANGED
@@ -117,14 +117,60 @@ function deliverPluginData(data, { frontmatterCallback, extractionHandlers }) {
117
117
  if (data.frontmatter && frontmatterCallback) frontmatterCallback(data.frontmatter);
118
118
  if (data.extracted?.length && extractionHandlers) for (const element of data.extracted) extractionHandlers[element.selector]?.(element);
119
119
  }
120
+ const utf8 = new TextEncoder();
121
+ const WASM_CHUNK_BYTES = 16384;
122
+ const WASM_ONE_SHOT_MAX = 256;
123
+ function convertWasm(html, napiOpts, engine) {
124
+ if (html.length <= WASM_ONE_SHOT_MAX) return engine.oneShot(html, napiOpts);
125
+ return withWasmStream(engine, napiOpts, (stream) => {
126
+ let markdown = "";
127
+ if (html.charCodeAt(0) === 65279) {
128
+ markdown += stream.processChunk(String.fromCharCode(65279));
129
+ html = html.slice(1);
130
+ }
131
+ const bytes = new Uint8Array(WASM_CHUNK_BYTES);
132
+ for (let start = 0; start < html.length;) {
133
+ const { read, written } = utf8.encodeInto(html.slice(start, start + WASM_CHUNK_BYTES), bytes);
134
+ markdown += stream.processChunkBytes(bytes.subarray(0, written));
135
+ start += read;
136
+ }
137
+ return {
138
+ markdown: markdown + stream.finish(),
139
+ ...stream.takeData()
140
+ };
141
+ });
142
+ }
143
+ function convertWasmBytes(html, napiOpts, engine) {
144
+ if (html.length <= WASM_ONE_SHOT_MAX && engine.bytes) return engine.bytes(html, napiOpts);
145
+ return withWasmStream(engine, napiOpts, (stream) => {
146
+ let markdown = "";
147
+ for (let start = 0; start < html.length; start += WASM_CHUNK_BYTES) markdown += stream.processChunkBytes(html.subarray(start, start + WASM_CHUNK_BYTES));
148
+ return markdown + stream.finish();
149
+ });
150
+ }
151
+ function withWasmStream(engine, napiOpts, use) {
152
+ const stream = new engine.Stream(napiOpts);
153
+ try {
154
+ return use(stream);
155
+ } finally {
156
+ try {
157
+ stream.free();
158
+ } catch {}
159
+ }
160
+ }
120
161
  function convertResult(convert, html, options = {}) {
121
162
  const resolved = resolveOptions(options);
122
163
  const result = convert(html, resolved.napiOpts);
123
164
  deliverPluginData(result, resolved);
124
165
  return result;
125
166
  }
167
+ const engine = {
168
+ oneShot: htmlToMarkdownResult$1,
169
+ bytes: htmlToMarkdownBytes$1,
170
+ Stream: MarkdownStream$1
171
+ };
126
172
  function htmlToMarkdownResult(html, options = {}) {
127
- return convertResult(htmlToMarkdownResult$1, html, options);
173
+ return convertResult((text, napiOpts) => convertWasm(text, napiOpts, engine), html, options);
128
174
  }
129
175
  function htmlToMarkdown(html, options = {}) {
130
176
  return htmlToMarkdownResult(html, options).markdown || "";
@@ -132,7 +178,7 @@ function htmlToMarkdown(html, options = {}) {
132
178
  function htmlToMarkdownBytes(html, options = {}) {
133
179
  const resolved = resolveOptions(options);
134
180
  if (resolved.frontmatterCallback || resolved.extractionHandlers) return htmlToMarkdown(new TextDecoder().decode(html), options);
135
- return htmlToMarkdownBytes$1(html, resolved.napiOpts);
181
+ return convertWasmBytes(html, resolved.napiOpts, engine);
136
182
  }
137
183
  var MarkdownStream = class extends MarkdownStream$1 {
138
184
  _callbacks;
package/napi/index.mjs CHANGED
@@ -9,8 +9,13 @@ const { readFileSync } = require('fs')
9
9
  let nativeBinding = null
10
10
  // Which artifact actually loaded. The WASI fallback chain overwrites it with
11
11
  // the flavor it resolved; the late native retry below leaves it alone because
12
- // it only runs while no WASI candidate has been loaded.
12
+ // it only runs while no WASI candidate has been loaded. The take-over check
13
+ // after the load-failure block can also set it.
13
14
  let __napiLoadedBindingTarget = 'native'
15
+ // What this loader's own `requireNative()` calls returned. The check after
16
+ // the load-failure block compares it with `nativeBinding` to tell a binding
17
+ // this loader loaded from one that code outside it put in its place.
18
+ let __napiRequiredNativeBinding = null
14
19
  const loadErrors = []
15
20
 
16
21
  const isMusl = () => {
@@ -92,8 +97,8 @@ function requireNative() {
92
97
  try {
93
98
  const binding = require('@mdream/rust-android-arm64')
94
99
  const bindingPackageVersion = require('@mdream/rust-android-arm64/package.json').version
95
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
96
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
100
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
97
102
  }
98
103
  return binding
99
104
  } catch (e) {
@@ -108,8 +113,8 @@ function requireNative() {
108
113
  try {
109
114
  const binding = require('@mdream/rust-android-arm-eabi')
110
115
  const bindingPackageVersion = require('@mdream/rust-android-arm-eabi/package.json').version
111
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
112
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
116
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
117
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
113
118
  }
114
119
  return binding
115
120
  } catch (e) {
@@ -129,8 +134,8 @@ function requireNative() {
129
134
  try {
130
135
  const binding = require('@mdream/rust-win32-x64-gnu')
131
136
  const bindingPackageVersion = require('@mdream/rust-win32-x64-gnu/package.json').version
132
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
133
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
137
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
134
139
  }
135
140
  return binding
136
141
  } catch (e) {
@@ -145,8 +150,8 @@ function requireNative() {
145
150
  try {
146
151
  const binding = require('@mdream/rust-win32-x64-msvc')
147
152
  const bindingPackageVersion = require('@mdream/rust-win32-x64-msvc/package.json').version
148
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
149
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
153
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
154
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
155
  }
151
156
  return binding
152
157
  } catch (e) {
@@ -162,8 +167,8 @@ function requireNative() {
162
167
  try {
163
168
  const binding = require('@mdream/rust-win32-ia32-msvc')
164
169
  const bindingPackageVersion = require('@mdream/rust-win32-ia32-msvc/package.json').version
165
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
166
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
170
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
167
172
  }
168
173
  return binding
169
174
  } catch (e) {
@@ -178,8 +183,8 @@ function requireNative() {
178
183
  try {
179
184
  const binding = require('@mdream/rust-win32-arm64-msvc')
180
185
  const bindingPackageVersion = require('@mdream/rust-win32-arm64-msvc/package.json').version
181
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
182
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
186
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
187
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
183
188
  }
184
189
  return binding
185
190
  } catch (e) {
@@ -197,8 +202,8 @@ function requireNative() {
197
202
  try {
198
203
  const binding = require('@mdream/rust-darwin-universal')
199
204
  const bindingPackageVersion = require('@mdream/rust-darwin-universal/package.json').version
200
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
201
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
205
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
202
207
  }
203
208
  return binding
204
209
  } catch (e) {
@@ -213,8 +218,8 @@ function requireNative() {
213
218
  try {
214
219
  const binding = require('@mdream/rust-darwin-x64')
215
220
  const bindingPackageVersion = require('@mdream/rust-darwin-x64/package.json').version
216
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
217
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
221
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
218
223
  }
219
224
  return binding
220
225
  } catch (e) {
@@ -229,8 +234,8 @@ function requireNative() {
229
234
  try {
230
235
  const binding = require('@mdream/rust-darwin-arm64')
231
236
  const bindingPackageVersion = require('@mdream/rust-darwin-arm64/package.json').version
232
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
233
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
234
239
  }
235
240
  return binding
236
241
  } catch (e) {
@@ -249,8 +254,8 @@ function requireNative() {
249
254
  try {
250
255
  const binding = require('@mdream/rust-freebsd-x64')
251
256
  const bindingPackageVersion = require('@mdream/rust-freebsd-x64/package.json').version
252
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
253
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
257
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
254
259
  }
255
260
  return binding
256
261
  } catch (e) {
@@ -265,8 +270,24 @@ function requireNative() {
265
270
  try {
266
271
  const binding = require('@mdream/rust-freebsd-arm64')
267
272
  const bindingPackageVersion = require('@mdream/rust-freebsd-arm64/package.json').version
268
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
269
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
273
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
274
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
275
+ }
276
+ return binding
277
+ } catch (e) {
278
+ loadErrors.push(e)
279
+ }
280
+ } else if (process.arch === 'ppc64') {
281
+ try {
282
+ return require('./rust.freebsd-ppc64.node')
283
+ } catch (e) {
284
+ loadErrors.push(e)
285
+ }
286
+ try {
287
+ const binding = require('@mdream/rust-freebsd-ppc64')
288
+ const bindingPackageVersion = require('@mdream/rust-freebsd-ppc64/package.json').version
289
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
290
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
270
291
  }
271
292
  return binding
272
293
  } catch (e) {
@@ -286,8 +307,8 @@ function requireNative() {
286
307
  try {
287
308
  const binding = require('@mdream/rust-linux-x64-musl')
288
309
  const bindingPackageVersion = require('@mdream/rust-linux-x64-musl/package.json').version
289
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
290
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
311
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
291
312
  }
292
313
  return binding
293
314
  } catch (e) {
@@ -302,8 +323,8 @@ function requireNative() {
302
323
  try {
303
324
  const binding = require('@mdream/rust-linux-x64-gnu')
304
325
  const bindingPackageVersion = require('@mdream/rust-linux-x64-gnu/package.json').version
305
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
306
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
327
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
307
328
  }
308
329
  return binding
309
330
  } catch (e) {
@@ -320,8 +341,8 @@ function requireNative() {
320
341
  try {
321
342
  const binding = require('@mdream/rust-linux-arm64-musl')
322
343
  const bindingPackageVersion = require('@mdream/rust-linux-arm64-musl/package.json').version
323
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
324
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
345
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
325
346
  }
326
347
  return binding
327
348
  } catch (e) {
@@ -336,8 +357,8 @@ function requireNative() {
336
357
  try {
337
358
  const binding = require('@mdream/rust-linux-arm64-gnu')
338
359
  const bindingPackageVersion = require('@mdream/rust-linux-arm64-gnu/package.json').version
339
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
340
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
361
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
341
362
  }
342
363
  return binding
343
364
  } catch (e) {
@@ -354,8 +375,8 @@ function requireNative() {
354
375
  try {
355
376
  const binding = require('@mdream/rust-linux-arm-musleabihf')
356
377
  const bindingPackageVersion = require('@mdream/rust-linux-arm-musleabihf/package.json').version
357
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
358
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
379
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
359
380
  }
360
381
  return binding
361
382
  } catch (e) {
@@ -370,8 +391,8 @@ function requireNative() {
370
391
  try {
371
392
  const binding = require('@mdream/rust-linux-arm-gnueabihf')
372
393
  const bindingPackageVersion = require('@mdream/rust-linux-arm-gnueabihf/package.json').version
373
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
374
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
395
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
375
396
  }
376
397
  return binding
377
398
  } catch (e) {
@@ -388,8 +409,8 @@ function requireNative() {
388
409
  try {
389
410
  const binding = require('@mdream/rust-linux-loong64-musl')
390
411
  const bindingPackageVersion = require('@mdream/rust-linux-loong64-musl/package.json').version
391
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
392
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
413
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
393
414
  }
394
415
  return binding
395
416
  } catch (e) {
@@ -404,8 +425,8 @@ function requireNative() {
404
425
  try {
405
426
  const binding = require('@mdream/rust-linux-loong64-gnu')
406
427
  const bindingPackageVersion = require('@mdream/rust-linux-loong64-gnu/package.json').version
407
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
408
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
429
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
409
430
  }
410
431
  return binding
411
432
  } catch (e) {
@@ -422,8 +443,8 @@ function requireNative() {
422
443
  try {
423
444
  const binding = require('@mdream/rust-linux-riscv64-musl')
424
445
  const bindingPackageVersion = require('@mdream/rust-linux-riscv64-musl/package.json').version
425
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
426
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
446
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
447
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
427
448
  }
428
449
  return binding
429
450
  } catch (e) {
@@ -438,8 +459,8 @@ function requireNative() {
438
459
  try {
439
460
  const binding = require('@mdream/rust-linux-riscv64-gnu')
440
461
  const bindingPackageVersion = require('@mdream/rust-linux-riscv64-gnu/package.json').version
441
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
442
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
462
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
463
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
464
  }
444
465
  return binding
445
466
  } catch (e) {
@@ -455,8 +476,8 @@ function requireNative() {
455
476
  try {
456
477
  const binding = require('@mdream/rust-linux-ppc64-gnu')
457
478
  const bindingPackageVersion = require('@mdream/rust-linux-ppc64-gnu/package.json').version
458
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
459
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
460
481
  }
461
482
  return binding
462
483
  } catch (e) {
@@ -471,8 +492,8 @@ function requireNative() {
471
492
  try {
472
493
  const binding = require('@mdream/rust-linux-s390x-gnu')
473
494
  const bindingPackageVersion = require('@mdream/rust-linux-s390x-gnu/package.json').version
474
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
475
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
476
497
  }
477
498
  return binding
478
499
  } catch (e) {
@@ -491,8 +512,8 @@ function requireNative() {
491
512
  try {
492
513
  const binding = require('@mdream/rust-openharmony-arm64')
493
514
  const bindingPackageVersion = require('@mdream/rust-openharmony-arm64/package.json').version
494
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
495
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
515
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
496
517
  }
497
518
  return binding
498
519
  } catch (e) {
@@ -507,8 +528,8 @@ function requireNative() {
507
528
  try {
508
529
  const binding = require('@mdream/rust-openharmony-x64')
509
530
  const bindingPackageVersion = require('@mdream/rust-openharmony-x64/package.json').version
510
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
511
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
531
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
532
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
512
533
  }
513
534
  return binding
514
535
  } catch (e) {
@@ -523,8 +544,8 @@ function requireNative() {
523
544
  try {
524
545
  const binding = require('@mdream/rust-openharmony-arm')
525
546
  const bindingPackageVersion = require('@mdream/rust-openharmony-arm/package.json').version
526
- if (bindingPackageVersion !== '2.0.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
527
- throw new Error(`Native binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
547
+ if (bindingPackageVersion !== '2.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
548
+ throw new Error(`Native binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
528
549
  }
529
550
  return binding
530
551
  } catch (e) {
@@ -588,6 +609,7 @@ const forceWasi =
588
609
 
589
610
  if (!forceWasi) {
590
611
  nativeBinding = requireNative()
612
+ __napiRequiredNativeBinding = nativeBinding
591
613
  }
592
614
 
593
615
  if (!nativeBinding || forceWasi) {
@@ -664,8 +686,8 @@ if (!nativeBinding || forceWasi) {
664
686
  if (!candidateFailed) {
665
687
  if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
666
688
  const bindingPackageVersion = require('@mdream/rust-wasm32-wasi/package.json').version
667
- if (bindingPackageVersion !== '2.0.3') {
668
- throw new Error(`WASI binding package version mismatch, expected 2.0.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
689
+ if (bindingPackageVersion !== '2.2.0') {
690
+ throw new Error(`WASI binding package version mismatch, expected 2.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
669
691
  }
670
692
  }
671
693
  wasiBinding = require('@mdream/rust-wasm32-wasi')
@@ -689,6 +711,7 @@ if (!nativeBinding || forceWasi) {
689
711
  !__napiWasiFlavorRequested
690
712
  ) {
691
713
  nativeBinding = requireNative()
714
+ __napiRequiredNativeBinding = nativeBinding
692
715
  }
693
716
  if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
694
717
  const error = new Error(
@@ -716,6 +739,40 @@ if (!nativeBinding) {
716
739
  throw new Error(`Failed to load native binding`)
717
740
  }
718
741
 
742
+ // A package can patch its own fallback in front of the load-failure check
743
+ // above, e.g. a WebContainer download through `napi-postinstall/fallback`.
744
+ // That fallback swaps `nativeBinding` for a generated WASI loader, which has
745
+ // already stamped its own flavor, while the target above still says 'native'.
746
+ // Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
747
+ // export reports the wrong artifact. Three limits keep the conflict check:
748
+ // - only a binding this loader did not load itself, so a native addon whose
749
+ // `#[napi(module_exports)]` hook claims the name is still rejected;
750
+ // - only an own data property, read through its descriptor, so no addon
751
+ // getter runs here, and it must read back the same, as the stamp reads it;
752
+ // - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
753
+ // chain can report ('wasm32-wasi' for a package without a WASI target).
754
+ // This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
755
+ if (
756
+ __napiLoadedBindingTarget === 'native' &&
757
+ nativeBinding !== __napiRequiredNativeBinding
758
+ ) {
759
+ try {
760
+ const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(
761
+ nativeBinding,
762
+ '__napiBindingTarget',
763
+ )
764
+ if (
765
+ __napiBindingTargetDescriptor &&
766
+ __napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
767
+ nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
768
+ ) {
769
+ __napiLoadedBindingTarget = __napiBindingTargetDescriptor.value
770
+ }
771
+ } catch {
772
+ // keep 'native'
773
+ }
774
+ }
775
+
719
776
  const { MarkdownStream, htmlToMarkdown } = nativeBinding
720
777
  export { MarkdownStream }
721
778
  export { htmlToMarkdown }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mdream",
3
3
  "type": "module",
4
- "version": "2.0.3",
4
+ "version": "2.2.0",
5
5
  "description": "Ultra-performant HTML to Markdown Convertor Optimized for LLMs and llm.txt artifacts.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -25,15 +25,24 @@
25
25
  "directory": "packages/mdream"
26
26
  },
27
27
  "sideEffects": [
28
- "./wasm-bundler/mdream_edge.js"
28
+ "./wasm-bundler/mdream_edge.js",
29
+ "./wasm-bundler/mdream_markdown.js"
29
30
  ],
30
31
  "exports": {
31
32
  ".": {
32
33
  "workerd": {
34
+ "mdream-markdown": {
35
+ "types": "./dist/edge-markdown.d.mts",
36
+ "default": "./dist/edge-markdown.mjs"
37
+ },
33
38
  "types": "./dist/edge.d.mts",
34
39
  "default": "./dist/edge.mjs"
35
40
  },
36
41
  "edge-light": {
42
+ "mdream-markdown": {
43
+ "types": "./dist/edge-markdown.d.mts",
44
+ "default": "./dist/edge-markdown.mjs"
45
+ },
37
46
  "types": "./dist/edge.d.mts",
38
47
  "default": "./dist/edge.mjs"
39
48
  },
@@ -46,6 +55,10 @@
46
55
  "default": "./dist/index.mjs"
47
56
  },
48
57
  "./browser": {
58
+ "mdream-markdown": {
59
+ "types": "./dist/browser-markdown.d.mts",
60
+ "default": "./dist/browser-markdown.mjs"
61
+ },
49
62
  "types": "./dist/browser.d.mts",
50
63
  "default": "./dist/browser.mjs"
51
64
  },
@@ -72,24 +85,24 @@
72
85
  ],
73
86
  "dependencies": {},
74
87
  "optionalDependencies": {
75
- "@mdream/rust-android-arm-eabi": "2.0.3",
76
- "@mdream/rust-android-arm64": "2.0.3",
77
- "@mdream/rust-darwin-arm64": "2.0.3",
78
- "@mdream/rust-darwin-x64": "2.0.3",
79
- "@mdream/rust-freebsd-x64": "2.0.3",
80
- "@mdream/rust-linux-arm-gnueabihf": "2.0.3",
81
- "@mdream/rust-linux-arm64-gnu": "2.0.3",
82
- "@mdream/rust-linux-arm64-musl": "2.0.3",
83
- "@mdream/rust-linux-x64-gnu": "2.0.3",
84
- "@mdream/rust-linux-x64-musl": "2.0.3",
85
- "@mdream/rust-wasm32-wasi": "2.0.3",
86
- "@mdream/rust-win32-arm64-msvc": "2.0.3",
87
- "@mdream/rust-win32-x64-msvc": "2.0.3"
88
+ "@mdream/rust-android-arm-eabi": "2.2.0",
89
+ "@mdream/rust-android-arm64": "2.2.0",
90
+ "@mdream/rust-darwin-arm64": "2.2.0",
91
+ "@mdream/rust-darwin-x64": "2.2.0",
92
+ "@mdream/rust-freebsd-x64": "2.2.0",
93
+ "@mdream/rust-linux-arm-gnueabihf": "2.2.0",
94
+ "@mdream/rust-linux-arm64-gnu": "2.2.0",
95
+ "@mdream/rust-linux-arm64-musl": "2.2.0",
96
+ "@mdream/rust-linux-x64-gnu": "2.2.0",
97
+ "@mdream/rust-linux-x64-musl": "2.2.0",
98
+ "@mdream/rust-wasm32-wasi": "2.2.0",
99
+ "@mdream/rust-win32-arm64-msvc": "2.2.0",
100
+ "@mdream/rust-win32-x64-msvc": "2.2.0"
88
101
  },
89
102
  "devDependencies": {
90
- "@mdream/js": "2.0.3",
91
- "@mdream/rust-build": "2.0.3",
92
- "rolldown": "^1.2.13"
103
+ "@mdream/js": "2.2.0",
104
+ "@mdream/rust-build": "2.2.0",
105
+ "rolldown": "^1.3.2"
93
106
  },
94
107
  "scripts": {
95
108
  "ts": "node --experimental-strip-types",
@@ -101,9 +114,10 @@
101
114
  "test:wiki-small:file": "cat test/fixtures/wikipedia-small.html | node ./bin/mdream.mjs --origin https://en.wikipedia.org | tee test/wiki-markdown.md",
102
115
  "build": "obuild",
103
116
  "build:native": "pnpm --dir ../../crates/node run build:platform",
104
- "build:edge": "node ../../scripts/build-wasm-edge.mjs --target web --out-dir ../../packages/mdream/wasm --out-name mdream_edge && node ../../scripts/build-wasm-edge.mjs --target bundler --out-dir ../../packages/mdream/wasm-bundler --out-name mdream_edge",
117
+ "build:edge": "node ../../scripts/build-wasm-edge.mjs --target web --out-dir wasm && node ../../scripts/build-wasm-edge.mjs --target bundler --out-dir wasm-bundler --shared-wasm-dir wasm",
105
118
  "typecheck": "tsc --noEmit",
106
119
  "dev:prepare": "obuild --stub",
120
+ "postbuild:edge": "node ../../scripts/build-wasm-markdown.ts",
107
121
  "test": "vitest test",
108
122
  "test:attw": "attw --pack"
109
123
  }
@@ -199,10 +199,19 @@ function __wbg_get_imports() {
199
199
  const ret = typeof(v) === 'boolean' ? v : undefined;
200
200
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
201
201
  },
202
+ __wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
203
+ const ret = typeof(getObject(arg0)) === 'function';
204
+ return ret;
205
+ },
202
206
  __wbg___wbindgen_is_null_e343b7d08827ba72: function(arg0) {
203
207
  const ret = getObject(arg0) === null;
204
208
  return ret;
205
209
  },
210
+ __wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
211
+ const val = getObject(arg0);
212
+ const ret = typeof(val) === 'object' && val !== null;
213
+ return ret;
214
+ },
206
215
  __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
207
216
  const ret = getObject(arg0) === undefined;
208
217
  return ret;
@@ -194,10 +194,19 @@ export function __wbg___wbindgen_boolean_get_5b446f51afd21013(arg0) {
194
194
  const ret = typeof(v) === 'boolean' ? v : undefined;
195
195
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
196
196
  }
197
+ export function __wbg___wbindgen_is_function_1f9d30630b8b1d3d(arg0) {
198
+ const ret = typeof(getObject(arg0)) === 'function';
199
+ return ret;
200
+ }
197
201
  export function __wbg___wbindgen_is_null_e343b7d08827ba72(arg0) {
198
202
  const ret = getObject(arg0) === null;
199
203
  return ret;
200
204
  }
205
+ export function __wbg___wbindgen_is_object_3c45d4f2dde4e749(arg0) {
206
+ const val = getObject(arg0);
207
+ const ret = typeof(val) === 'object' && val !== null;
208
+ return ret;
209
+ }
201
210
  export function __wbg___wbindgen_is_undefined_8865fb403f8fe9d8(arg0) {
202
211
  const ret = getObject(arg0) === undefined;
203
212
  return ret;
Binary file
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": "2.0.3",
5
+ "version": "2.2.0",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "mdream_edge_bg.wasm",