nuxt-ai-ready 2.5.0 → 2.5.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.
Files changed (206) hide show
  1. package/dist/chunks/agent-skills.mjs +1 -1
  2. package/dist/chunks/prerender.mjs +1 -1
  3. package/dist/cli.mjs +2 -0
  4. package/dist/module.json +1 -1
  5. package/dist/module.mjs +1 -1
  6. package/dist/runtime/server/db/drizzle/queries.js +0 -1
  7. package/dist/runtime/server/db/queries.d.ts +2 -0
  8. package/dist/runtime/server/db/queries.js +11 -5
  9. package/dist/runtime/server/db/seed.d.ts +2 -2
  10. package/dist/runtime/server/routes/__ai-ready/reindex.post.js +2 -0
  11. package/dist/runtime/server/utils/batchIndex.js +4 -2
  12. package/dist/runtime/server/utils/checkStale.d.ts +1 -1
  13. package/dist/runtime/server/utils/checkStale.js +1 -1
  14. package/dist/runtime/server/utils/indexPage.d.ts +8 -1
  15. package/dist/runtime/server/utils/indexPage.js +13 -5
  16. package/dist/shared/{nuxt-ai-ready.DsokNmXc.mjs → nuxt-ai-ready.CLSWou20.mjs} +2 -0
  17. package/node_modules/@mdream/js/LICENSE.md +9 -0
  18. package/node_modules/@mdream/js/README.md +792 -0
  19. package/node_modules/@mdream/js/bin/mdream.mjs +2 -0
  20. package/node_modules/@mdream/js/dist/_chunks/const.mjs +134 -0
  21. package/node_modules/@mdream/js/dist/_chunks/index.d.mts +9 -0
  22. package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +1968 -0
  23. package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +6 -0
  24. package/node_modules/@mdream/js/dist/_chunks/parse.mjs +2756 -0
  25. package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +725 -0
  26. package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +44 -0
  27. package/node_modules/@mdream/js/dist/_chunks/stream.mjs +37 -0
  28. package/node_modules/@mdream/js/dist/_chunks/types.d.mts +473 -0
  29. package/node_modules/@mdream/js/dist/cli.d.mts +1 -0
  30. package/node_modules/@mdream/js/dist/cli.mjs +32 -0
  31. package/node_modules/@mdream/js/dist/core.d.mts +15 -0
  32. package/node_modules/@mdream/js/dist/core.mjs +28 -0
  33. package/node_modules/@mdream/js/dist/index.d.mts +4 -0
  34. package/node_modules/@mdream/js/dist/index.mjs +58 -0
  35. package/node_modules/@mdream/js/dist/llms-txt.d.mts +86 -0
  36. package/node_modules/@mdream/js/dist/llms-txt.mjs +308 -0
  37. package/node_modules/@mdream/js/dist/negotiate.d.mts +35 -0
  38. package/node_modules/@mdream/js/dist/negotiate.mjs +121 -0
  39. package/node_modules/@mdream/js/dist/parse.d.mts +90 -0
  40. package/node_modules/@mdream/js/dist/parse.mjs +2 -0
  41. package/node_modules/@mdream/js/dist/plugins.d.mts +85 -0
  42. package/node_modules/@mdream/js/dist/plugins.mjs +2 -0
  43. package/node_modules/@mdream/js/dist/preset/minimal.d.mts +2 -0
  44. package/node_modules/@mdream/js/dist/preset/minimal.mjs +33 -0
  45. package/node_modules/@mdream/js/dist/splitter.d.mts +18 -0
  46. package/node_modules/@mdream/js/dist/splitter.mjs +194 -0
  47. package/node_modules/@mdream/js/package.json +103 -0
  48. package/node_modules/cac/LICENSE +21 -0
  49. package/node_modules/cac/README.md +492 -0
  50. package/node_modules/cac/dist/index.d.ts +196 -0
  51. package/node_modules/cac/dist/index.js +638 -0
  52. package/node_modules/cac/package.json +72 -0
  53. package/node_modules/mdream/LICENSE.md +9 -0
  54. package/node_modules/mdream/README.md +1091 -0
  55. package/node_modules/mdream/bin/mdream.mjs +46 -0
  56. package/node_modules/mdream/dist/browser.d.mts +105 -0
  57. package/node_modules/mdream/dist/browser.mjs +262 -0
  58. package/node_modules/mdream/dist/edge.d.mts +100 -0
  59. package/node_modules/mdream/dist/edge.mjs +250 -0
  60. package/node_modules/mdream/dist/iife.js +605 -0
  61. package/node_modules/mdream/dist/index.d.mts +89 -0
  62. package/node_modules/mdream/dist/index.mjs +184 -0
  63. package/node_modules/mdream/dist/wasm.d.mts +100 -0
  64. package/node_modules/mdream/dist/wasm.mjs +140 -0
  65. package/node_modules/mdream/dist/worker.d.mts +101 -0
  66. package/node_modules/mdream/dist/worker.mjs +217 -0
  67. package/node_modules/mdream/napi/index.d.mts +127 -0
  68. package/node_modules/mdream/napi/index.d.ts +127 -0
  69. package/node_modules/mdream/napi/index.mjs +725 -0
  70. package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
  71. package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
  72. package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
  73. package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
  74. package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
  75. package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
  76. package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
  77. package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
  78. package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
  79. package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
  80. package/node_modules/mdream/napi/rust.wasi.cjs +2144 -0
  81. package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
  82. package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
  83. package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
  84. package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +21 -0
  85. package/node_modules/mdream/node_modules/@emnapi/core/README.md +1 -0
  86. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +392 -0
  87. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +392 -0
  88. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +8351 -0
  89. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +7268 -0
  90. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +5 -0
  91. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +843 -0
  92. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +4 -0
  93. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +3 -0
  94. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +5 -0
  95. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +1010 -0
  96. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +5 -0
  97. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +1446 -0
  98. package/node_modules/mdream/node_modules/@emnapi/core/package.json +39 -0
  99. package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +60 -0
  100. package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +21 -0
  101. package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +1 -0
  102. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +833 -0
  103. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +2306 -0
  104. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +1 -0
  105. package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +63 -0
  106. package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +39 -0
  107. package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +25 -0
  108. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
  109. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +203 -0
  110. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +236 -0
  111. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +1086 -0
  112. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +35 -0
  113. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +6 -0
  114. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +1472 -0
  115. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +1470 -0
  116. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +237 -0
  117. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +18260 -0
  118. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +317 -0
  119. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +67 -0
  120. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +39 -0
  121. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +36 -0
  122. package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +21 -0
  123. package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +193 -0
  124. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
  125. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +423 -0
  126. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2932 -0
  127. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2932 -0
  128. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
  129. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +2954 -0
  130. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
  131. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
  132. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
  133. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
  134. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
  135. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
  136. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
  137. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
  138. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
  139. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +192 -0
  140. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +316 -0
  141. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1599 -0
  142. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
  143. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
  144. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
  145. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
  146. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
  147. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
  148. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
  149. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
  150. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
  151. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
  152. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
  153. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
  154. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +186 -0
  155. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +310 -0
  156. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1593 -0
  157. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
  158. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
  159. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
  160. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
  161. package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +58 -0
  162. package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +15 -0
  163. package/node_modules/mdream/node_modules/tslib/LICENSE.txt +12 -0
  164. package/node_modules/mdream/node_modules/tslib/README.md +164 -0
  165. package/node_modules/mdream/node_modules/tslib/SECURITY.md +41 -0
  166. package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +38 -0
  167. package/node_modules/mdream/node_modules/tslib/modules/index.js +70 -0
  168. package/node_modules/mdream/node_modules/tslib/modules/package.json +3 -0
  169. package/node_modules/mdream/node_modules/tslib/package.json +47 -0
  170. package/node_modules/mdream/node_modules/tslib/tslib.d.ts +460 -0
  171. package/node_modules/mdream/node_modules/tslib/tslib.es6.html +1 -0
  172. package/node_modules/mdream/node_modules/tslib/tslib.es6.js +402 -0
  173. package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +401 -0
  174. package/node_modules/mdream/node_modules/tslib/tslib.html +1 -0
  175. package/node_modules/mdream/node_modules/tslib/tslib.js +484 -0
  176. package/node_modules/mdream/package.json +110 -0
  177. package/node_modules/mdream/skills/mdream/SKILL.md +124 -0
  178. package/node_modules/mdream/skills/mdream/references/runtimes.md +49 -0
  179. package/node_modules/mdream/wasm/mdream_edge.d.ts +90 -0
  180. package/node_modules/mdream/wasm/mdream_edge.js +517 -0
  181. package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
  182. package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +20 -0
  183. package/node_modules/mdream/wasm/package.json +17 -0
  184. package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +45 -0
  185. package/node_modules/mdream/wasm-bundler/mdream_edge.js +13 -0
  186. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +413 -0
  187. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
  188. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +20 -0
  189. package/node_modules/mdream/wasm-bundler/package.json +19 -0
  190. package/node_modules/pathe/LICENSE +70 -0
  191. package/node_modules/pathe/README.md +73 -0
  192. package/node_modules/pathe/dist/index.cjs +39 -0
  193. package/node_modules/pathe/dist/index.d.cts +47 -0
  194. package/node_modules/pathe/dist/index.d.mts +47 -0
  195. package/node_modules/pathe/dist/index.d.ts +47 -0
  196. package/node_modules/pathe/dist/index.mjs +19 -0
  197. package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +266 -0
  198. package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
  199. package/node_modules/pathe/dist/utils.cjs +82 -0
  200. package/node_modules/pathe/dist/utils.d.cts +32 -0
  201. package/node_modules/pathe/dist/utils.d.mts +32 -0
  202. package/node_modules/pathe/dist/utils.d.ts +32 -0
  203. package/node_modules/pathe/dist/utils.mjs +77 -0
  204. package/node_modules/pathe/package.json +61 -0
  205. package/node_modules/pathe/utils.d.ts +1 -0
  206. package/package.json +8 -64
@@ -0,0 +1,250 @@
1
+ import { MarkdownStream as MarkdownStream$1, __mdreamTakePanicMessage, htmlToMarkdownResult } from "../wasm-bundler/mdream_edge.js";
2
+ const MINIMAL_FILTER_EXCLUDE = [
3
+ "form",
4
+ "fieldset",
5
+ "object",
6
+ "embed",
7
+ "footer",
8
+ "aside",
9
+ "iframe",
10
+ "input",
11
+ "textarea",
12
+ "select",
13
+ "button",
14
+ "nav"
15
+ ];
16
+ const CLEAN_ALL = {
17
+ urls: true,
18
+ fragments: true,
19
+ emptyLinks: true,
20
+ redundantLinks: true,
21
+ selfLinkHeadings: true,
22
+ emptyImages: true,
23
+ emptyLinkText: true
24
+ };
25
+ function resolveCleanConfig(options, minimal) {
26
+ const cleanUrls = options.cleanUrls === true;
27
+ let cleanOpt = options.clean;
28
+ if (cleanOpt === void 0) {
29
+ if (!minimal) return { cleanUrls };
30
+ cleanOpt = true;
31
+ }
32
+ if (!cleanOpt) return { cleanUrls };
33
+ const resolved = cleanOpt === true ? CLEAN_ALL : cleanOpt;
34
+ return {
35
+ cleanUrls: cleanUrls || resolved.urls === true,
36
+ clean: resolved
37
+ };
38
+ }
39
+ function resolveFrontmatter(opt) {
40
+ if (typeof opt === "function") return {
41
+ config: {},
42
+ callback: opt
43
+ };
44
+ if (opt && typeof opt === "object") {
45
+ const { onExtract, ...config } = opt;
46
+ return {
47
+ config,
48
+ callback: onExtract
49
+ };
50
+ }
51
+ return { config: {} };
52
+ }
53
+ function resolveOptions(options) {
54
+ if (Array.isArray(options.plugins)) throw new TypeError("Custom hook plugins require @mdream/js. Pass declarative config (e.g. { frontmatter: true }) to the Rust engine, or import { htmlToMarkdown } from '@mdream/js' for hook-based plugins. See https://mdream.dev/v1-migration#custom-plugins");
55
+ const minimal = options.minimal === true;
56
+ const plugins = options.plugins ? { ...options.plugins } : {};
57
+ let frontmatterCallback;
58
+ const frontmatterDisabled = options.frontmatter === false;
59
+ if (minimal ? !frontmatterDisabled : !!options.frontmatter) {
60
+ const fm = resolveFrontmatter(options.frontmatter);
61
+ plugins.frontmatter = fm.config;
62
+ frontmatterCallback = fm.callback;
63
+ } else if (frontmatterDisabled) delete plugins.frontmatter;
64
+ const isolateMainDisabled = options.isolateMain === false;
65
+ if (minimal ? !isolateMainDisabled : options.isolateMain) plugins.isolateMain = true;
66
+ else if (isolateMainDisabled) delete plugins.isolateMain;
67
+ const tailwindDisabled = options.tailwind === false;
68
+ if (minimal ? !tailwindDisabled : options.tailwind) plugins.tailwind = true;
69
+ else if (tailwindDisabled) delete plugins.tailwind;
70
+ if (options.filter === false) delete plugins.filter;
71
+ else if (minimal) plugins.filter = {
72
+ ...options.filter,
73
+ exclude: [...MINIMAL_FILTER_EXCLUDE, ...options.filter?.exclude ?? []]
74
+ };
75
+ else if (options.filter) plugins.filter = options.filter;
76
+ const extraction = options.extraction;
77
+ let extractionHandlers;
78
+ if (extraction) {
79
+ plugins.extraction = { selectors: Object.keys(extraction) };
80
+ extractionHandlers = extraction;
81
+ }
82
+ const tagOverrides = options.tagOverrides;
83
+ if (tagOverrides) {
84
+ const overrides = {};
85
+ for (const tag in tagOverrides) {
86
+ const value = tagOverrides[tag];
87
+ if (value) overrides[tag] = typeof value === "string" ? { alias: value } : value;
88
+ }
89
+ plugins.tagOverrides = overrides;
90
+ }
91
+ const { cleanUrls, clean } = resolveCleanConfig(options, minimal);
92
+ return {
93
+ napiOpts: {
94
+ origin: options.origin,
95
+ cleanUrls,
96
+ clean,
97
+ plugins,
98
+ wrapWidth: options.wrapWidth,
99
+ format: options.format
100
+ },
101
+ extractionHandlers,
102
+ frontmatterCallback
103
+ };
104
+ }
105
+ function deliverPluginData(data, { frontmatterCallback, extractionHandlers }) {
106
+ if (data.frontmatter && frontmatterCallback) frontmatterCallback(data.frontmatter);
107
+ if (data.extracted?.length && extractionHandlers) for (const element of data.extracted) extractionHandlers[element.selector]?.(element);
108
+ }
109
+ function hasCallbacks({ frontmatterCallback, extractionHandlers }) {
110
+ return !!frontmatterCallback || !!extractionHandlers;
111
+ }
112
+ function convertResult(convert, html, options = {}) {
113
+ const resolved = resolveOptions(options);
114
+ const result = convert(html, resolved.napiOpts);
115
+ deliverPluginData(result, resolved);
116
+ return result;
117
+ }
118
+ async function* pumpStream(stream, htmlStream, callbacks, { decodeInJs = false, mapError = (error) => error } = {}) {
119
+ const reader = htmlStream.getReader();
120
+ const decoder = decodeInJs ? new TextDecoder() : void 0;
121
+ try {
122
+ while (true) {
123
+ const { done, value } = await reader.read();
124
+ if (done) break;
125
+ let processed;
126
+ if (typeof value === "string") processed = stream.processChunk(decoder ? decoder.decode() + value : value);
127
+ else processed = decoder ? stream.processChunk(decoder.decode(value, { stream: true })) : stream.processChunkBytes(value);
128
+ if (processed) yield processed;
129
+ }
130
+ const decoderTail = decoder?.decode();
131
+ if (decoderTail) {
132
+ const processed = stream.processChunk(decoderTail);
133
+ if (processed) yield processed;
134
+ }
135
+ const final_ = stream.finish();
136
+ if (hasCallbacks(callbacks)) deliverPluginData(stream.takeData(), callbacks);
137
+ if (final_) yield final_;
138
+ } catch (error) {
139
+ throw mapError(error);
140
+ } finally {
141
+ reader.releaseLock();
142
+ }
143
+ }
144
+ function createSurrogateCarry() {
145
+ let held = "";
146
+ return {
147
+ take(chunk) {
148
+ if (held) {
149
+ chunk = held + chunk;
150
+ held = "";
151
+ }
152
+ const last = chunk.charCodeAt(chunk.length - 1);
153
+ if (last >= 55296 && last <= 56319) {
154
+ held = chunk.slice(-1);
155
+ return chunk.slice(0, -1);
156
+ }
157
+ return chunk;
158
+ },
159
+ flush() {
160
+ const value = held;
161
+ held = "";
162
+ return value;
163
+ }
164
+ };
165
+ }
166
+ function wasmPanicError(error, takeMessage) {
167
+ if (!(error instanceof WebAssembly.RuntimeError)) return error;
168
+ let message;
169
+ try {
170
+ message = takeMessage();
171
+ } catch {
172
+ return error;
173
+ }
174
+ if (!message) return error;
175
+ return new Error(`mdream WASM panic, please report this at https://github.com/harlan-zw/mdream/issues\n${message}`, { cause: error });
176
+ }
177
+ function convert(html, napiOpts) {
178
+ try {
179
+ return htmlToMarkdownResult(html, napiOpts);
180
+ } catch (error) {
181
+ throw wasmPanicError(error, __mdreamTakePanicMessage);
182
+ }
183
+ }
184
+ function htmlToMarkdown(html, options = {}) {
185
+ return convertResult(convert, html, options).markdown || "";
186
+ }
187
+ var MarkdownStream = class {
188
+ _inner;
189
+ _carry = createSurrogateCarry();
190
+ _callbacks;
191
+ constructor(options = {}) {
192
+ const resolved = resolveOptions(options);
193
+ this._callbacks = resolved;
194
+ try {
195
+ this._inner = new MarkdownStream$1(resolved.napiOpts);
196
+ } catch (error) {
197
+ throw wasmPanicError(error, __mdreamTakePanicMessage);
198
+ }
199
+ }
200
+ processChunk(chunk) {
201
+ try {
202
+ return this._inner.processChunk(this._carry.take(chunk));
203
+ } catch (error) {
204
+ throw wasmPanicError(error, __mdreamTakePanicMessage);
205
+ }
206
+ }
207
+ processChunkBytes(chunk) {
208
+ try {
209
+ const held = this._carry.flush();
210
+ return held ? this._inner.processChunk(held) + this._inner.processChunkBytes(chunk) : this._inner.processChunkBytes(chunk);
211
+ } catch (error) {
212
+ throw wasmPanicError(error, __mdreamTakePanicMessage);
213
+ }
214
+ }
215
+ finish() {
216
+ let markdown;
217
+ try {
218
+ const held = this._carry.flush();
219
+ markdown = held ? this._inner.processChunk(held) + this._inner.finish() : this._inner.finish();
220
+ } catch (error) {
221
+ throw wasmPanicError(error, __mdreamTakePanicMessage);
222
+ }
223
+ if (this._callbacks.frontmatterCallback || this._callbacks.extractionHandlers) deliverPluginData(this._inner.takeData(), this._callbacks);
224
+ return markdown;
225
+ }
226
+ };
227
+ async function* streamHtmlToMarkdown(htmlStream, options = {}) {
228
+ if (!htmlStream) throw new Error("Invalid HTML stream provided");
229
+ const resolved = resolveOptions(options);
230
+ const carry = createSurrogateCarry();
231
+ let stream;
232
+ try {
233
+ stream = new MarkdownStream$1(resolved.napiOpts);
234
+ } catch (error) {
235
+ throw wasmPanicError(error, __mdreamTakePanicMessage);
236
+ }
237
+ yield* pumpStream({
238
+ processChunk: (chunk) => stream.processChunk(carry.take(chunk)),
239
+ processChunkBytes: (chunk) => {
240
+ const held = carry.flush();
241
+ return held ? stream.processChunk(held) + stream.processChunkBytes(chunk) : stream.processChunkBytes(chunk);
242
+ },
243
+ finish: () => {
244
+ const held = carry.flush();
245
+ return held ? stream.processChunk(held) + stream.finish() : stream.finish();
246
+ },
247
+ takeData: () => stream.takeData()
248
+ }, htmlStream, resolved, { mapError: (error) => wasmPanicError(error, __mdreamTakePanicMessage) });
249
+ }
250
+ export { MarkdownStream, htmlToMarkdown, streamHtmlToMarkdown };