nuxt-ai-ready 2.5.2 → 3.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.
Files changed (282) hide show
  1. package/README.md +13 -12
  2. package/dist/chunks/agent-skills.mjs +35 -12
  3. package/dist/chunks/prerender.mjs +35 -24
  4. package/dist/cli.mjs +5 -2
  5. package/dist/module.d.mts +4 -0
  6. package/dist/module.json +2 -2
  7. package/dist/module.mjs +8 -4
  8. package/dist/runtime/app/index.d.ts +3 -0
  9. package/dist/runtime/app/index.js +2 -0
  10. package/dist/runtime/cache-control.d.ts +2 -0
  11. package/dist/runtime/cache-control.js +11 -0
  12. package/dist/runtime/llms-txt-utils.js +1 -1
  13. package/dist/runtime/server/db/context.d.ts +13 -0
  14. package/dist/runtime/server/db/drizzle/client.d.ts +6 -7
  15. package/dist/runtime/server/db/drizzle/client.js +13 -2
  16. package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -2
  17. package/dist/runtime/server/db/drizzle/providers/bun.js +2 -2
  18. package/dist/runtime/server/db/drizzle/providers/d1.d.ts +2 -2
  19. package/dist/runtime/server/db/drizzle/providers/d1.js +3 -2
  20. package/dist/runtime/server/db/drizzle/providers/libsql.d.ts +2 -2
  21. package/dist/runtime/server/db/drizzle/providers/libsql.js +2 -2
  22. package/dist/runtime/server/db/drizzle/providers/neon.d.ts +2 -2
  23. package/dist/runtime/server/db/drizzle/providers/neon.js +2 -2
  24. package/dist/runtime/server/db/drizzle/providers/node-sqlite.d.ts +2 -2
  25. package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +2 -2
  26. package/dist/runtime/server/db/drizzle/providers/postgres.d.ts +2 -2
  27. package/dist/runtime/server/db/drizzle/providers/postgres.js +2 -2
  28. package/dist/runtime/server/db/drizzle/queries.d.ts +27 -27
  29. package/dist/runtime/server/db/drizzle/queries.js +6 -5
  30. package/dist/runtime/server/db/drizzle/raw.d.ts +2 -6
  31. package/dist/runtime/server/db/index.d.ts +1 -1
  32. package/dist/runtime/server/db/index.js +1 -1
  33. package/dist/runtime/server/db/queries.d.ts +36 -36
  34. package/dist/runtime/server/db/queries.js +8 -9
  35. package/dist/runtime/server/db/seed.d.ts +2 -2
  36. package/dist/runtime/server/db/seed.js +4 -3
  37. package/dist/runtime/server/db/shared.d.ts +8 -0
  38. package/dist/runtime/server/db/shared.js +8 -2
  39. package/dist/runtime/server/index.d.ts +2 -0
  40. package/dist/runtime/server/index.js +17 -0
  41. package/dist/runtime/server/mcp/tools/get-page-markdown.js +1 -1
  42. package/dist/runtime/server/mcp/tools/list-pages.js +1 -1
  43. package/dist/runtime/server/mcp/tools/search-pages.js +1 -1
  44. package/dist/runtime/server/middleware/markdown.js +3 -3
  45. package/dist/runtime/server/middleware/markdown.prerender.js +1 -1
  46. package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +2 -0
  47. package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +16 -0
  48. package/dist/runtime/server/plugins/html-capture.prerender.js +6 -4
  49. package/dist/runtime/server/plugins/link-header-nitro3.d.ts +2 -0
  50. package/dist/runtime/server/plugins/link-header-nitro3.js +20 -0
  51. package/dist/runtime/server/plugins/link-header.d.ts +6 -0
  52. package/dist/runtime/server/plugins/link-header.js +7 -11
  53. package/dist/runtime/server/plugins/markdown-negotiation.js +8 -1
  54. package/dist/runtime/server/plugins/sitemap-seeder.js +3 -3
  55. package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
  56. package/dist/runtime/server/routes/agent-skills-artifact.js +10 -10
  57. package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
  58. package/dist/runtime/server/routes/agent-skills-index.js +7 -6
  59. package/dist/runtime/server/routes/ai-catalog.d.ts +2 -1
  60. package/dist/runtime/server/routes/ai-catalog.js +7 -8
  61. package/dist/runtime/server/routes/api-catalog.d.ts +3 -1
  62. package/dist/runtime/server/routes/api-catalog.js +12 -12
  63. package/dist/runtime/server/routes/llms-full.txt.get.js +1 -1
  64. package/dist/runtime/server/routes/mcp-server-card.d.ts +1 -1
  65. package/dist/runtime/server/routes/mcp-server-card.js +7 -8
  66. package/dist/runtime/server/utils/checkStale.d.ts +2 -2
  67. package/dist/runtime/server/utils/cloudflare-prerendered.d.ts +3 -0
  68. package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -0
  69. package/dist/runtime/server/utils/cloudflare.d.ts +5 -5
  70. package/dist/runtime/server/utils/cloudflare.js +31 -7
  71. package/dist/runtime/server/utils/content-negotiation.d.ts +5 -3
  72. package/dist/runtime/server/utils/content-negotiation.js +8 -7
  73. package/dist/runtime/server/utils/context.d.ts +3 -3
  74. package/dist/runtime/server/utils/context.js +1 -1
  75. package/dist/runtime/server/utils/discovery-response.d.ts +2 -0
  76. package/dist/runtime/server/utils/link-header.d.ts +5 -3
  77. package/dist/runtime/server/utils/link-header.js +26 -2
  78. package/dist/runtime/server/utils/markdown-request.d.ts +4 -3
  79. package/dist/runtime/server/utils/markdown-request.js +15 -13
  80. package/dist/runtime/server/utils/negotiation-decision.d.ts +4 -0
  81. package/dist/runtime/server/utils/negotiation-decision.js +6 -5
  82. package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
  83. package/dist/runtime/server/utils/negotiation-response.js +63 -23
  84. package/dist/runtime/server/utils/prerender-html.d.ts +2 -1
  85. package/dist/runtime/server/utils/prerender-html.js +3 -1
  86. package/dist/runtime/types.d.ts +15 -7
  87. package/dist/shared/nuxt-ai-ready.B3hAuOLQ.mjs +29 -0
  88. package/dist/shared/{nuxt-ai-ready.CLSWou20.mjs → nuxt-ai-ready.C34F0LJo.mjs} +560 -219
  89. package/package.json +85 -20
  90. package/skills/nuxt-ai-ready/SKILL.md +26 -12
  91. package/skills/nuxt-ai-ready/references/runtime-indexing.md +7 -6
  92. package/dist/runtime/server/db/drizzle/providers/sqlite.d.ts +0 -8
  93. package/dist/runtime/server/db/drizzle/providers/sqlite.js +0 -15
  94. package/node_modules/@mdream/js/LICENSE.md +0 -9
  95. package/node_modules/@mdream/js/README.md +0 -792
  96. package/node_modules/@mdream/js/bin/mdream.mjs +0 -2
  97. package/node_modules/@mdream/js/dist/_chunks/const.mjs +0 -134
  98. package/node_modules/@mdream/js/dist/_chunks/index.d.mts +0 -9
  99. package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +0 -1968
  100. package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +0 -6
  101. package/node_modules/@mdream/js/dist/_chunks/parse.mjs +0 -2756
  102. package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +0 -725
  103. package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +0 -44
  104. package/node_modules/@mdream/js/dist/_chunks/stream.mjs +0 -37
  105. package/node_modules/@mdream/js/dist/_chunks/types.d.mts +0 -473
  106. package/node_modules/@mdream/js/dist/cli.d.mts +0 -1
  107. package/node_modules/@mdream/js/dist/cli.mjs +0 -32
  108. package/node_modules/@mdream/js/dist/core.d.mts +0 -15
  109. package/node_modules/@mdream/js/dist/core.mjs +0 -28
  110. package/node_modules/@mdream/js/dist/index.d.mts +0 -4
  111. package/node_modules/@mdream/js/dist/index.mjs +0 -58
  112. package/node_modules/@mdream/js/dist/llms-txt.d.mts +0 -86
  113. package/node_modules/@mdream/js/dist/llms-txt.mjs +0 -308
  114. package/node_modules/@mdream/js/dist/negotiate.d.mts +0 -35
  115. package/node_modules/@mdream/js/dist/negotiate.mjs +0 -121
  116. package/node_modules/@mdream/js/dist/parse.d.mts +0 -90
  117. package/node_modules/@mdream/js/dist/parse.mjs +0 -2
  118. package/node_modules/@mdream/js/dist/plugins.d.mts +0 -85
  119. package/node_modules/@mdream/js/dist/plugins.mjs +0 -2
  120. package/node_modules/@mdream/js/dist/preset/minimal.d.mts +0 -2
  121. package/node_modules/@mdream/js/dist/preset/minimal.mjs +0 -33
  122. package/node_modules/@mdream/js/dist/splitter.d.mts +0 -18
  123. package/node_modules/@mdream/js/dist/splitter.mjs +0 -194
  124. package/node_modules/@mdream/js/package.json +0 -103
  125. package/node_modules/cac/LICENSE +0 -21
  126. package/node_modules/cac/README.md +0 -492
  127. package/node_modules/cac/dist/index.d.ts +0 -196
  128. package/node_modules/cac/dist/index.js +0 -638
  129. package/node_modules/cac/package.json +0 -72
  130. package/node_modules/mdream/LICENSE.md +0 -9
  131. package/node_modules/mdream/README.md +0 -1091
  132. package/node_modules/mdream/bin/mdream.mjs +0 -46
  133. package/node_modules/mdream/dist/browser.d.mts +0 -105
  134. package/node_modules/mdream/dist/browser.mjs +0 -262
  135. package/node_modules/mdream/dist/edge.d.mts +0 -100
  136. package/node_modules/mdream/dist/edge.mjs +0 -250
  137. package/node_modules/mdream/dist/iife.js +0 -605
  138. package/node_modules/mdream/dist/index.d.mts +0 -89
  139. package/node_modules/mdream/dist/index.mjs +0 -184
  140. package/node_modules/mdream/dist/wasm.d.mts +0 -100
  141. package/node_modules/mdream/dist/wasm.mjs +0 -140
  142. package/node_modules/mdream/dist/worker.d.mts +0 -101
  143. package/node_modules/mdream/dist/worker.mjs +0 -217
  144. package/node_modules/mdream/napi/index.d.mts +0 -127
  145. package/node_modules/mdream/napi/index.d.ts +0 -127
  146. package/node_modules/mdream/napi/index.mjs +0 -725
  147. package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
  148. package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
  149. package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
  150. package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
  151. package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
  152. package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
  153. package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
  154. package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
  155. package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
  156. package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
  157. package/node_modules/mdream/napi/rust.wasi.cjs +0 -2144
  158. package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
  159. package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
  160. package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
  161. package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +0 -21
  162. package/node_modules/mdream/node_modules/@emnapi/core/README.md +0 -1
  163. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +0 -392
  164. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +0 -392
  165. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +0 -8351
  166. package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +0 -7268
  167. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +0 -5
  168. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +0 -843
  169. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +0 -4
  170. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +0 -3
  171. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +0 -5
  172. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +0 -1010
  173. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +0 -5
  174. package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +0 -1446
  175. package/node_modules/mdream/node_modules/@emnapi/core/package.json +0 -39
  176. package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +0 -60
  177. package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +0 -21
  178. package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +0 -1
  179. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +0 -833
  180. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +0 -2306
  181. package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +0 -1
  182. package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +0 -63
  183. package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +0 -39
  184. package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +0 -25
  185. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +0 -21
  186. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +0 -203
  187. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +0 -236
  188. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +0 -1086
  189. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +0 -35
  190. package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +0 -6
  191. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +0 -1472
  192. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +0 -1470
  193. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +0 -237
  194. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +0 -18260
  195. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +0 -317
  196. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +0 -67
  197. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +0 -39
  198. package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +0 -36
  199. package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +0 -21
  200. package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +0 -193
  201. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +0 -11
  202. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +0 -423
  203. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +0 -2932
  204. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +0 -2932
  205. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +0 -1
  206. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +0 -2954
  207. package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +0 -1
  208. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +0 -158
  209. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +0 -13
  210. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +0 -46
  211. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +0 -97
  212. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +0 -35
  213. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +0 -103
  214. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +0 -268
  215. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +0 -3
  216. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +0 -192
  217. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +0 -316
  218. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +0 -1599
  219. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +0 -141
  220. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +0 -220
  221. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +0 -128
  222. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +0 -13
  223. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +0 -153
  224. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +0 -9
  225. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +0 -39
  226. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +0 -89
  227. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +0 -28
  228. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +0 -97
  229. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +0 -256
  230. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +0 -1
  231. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +0 -186
  232. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +0 -310
  233. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +0 -1593
  234. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +0 -135
  235. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +0 -216
  236. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +0 -113
  237. package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +0 -9
  238. package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +0 -58
  239. package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +0 -15
  240. package/node_modules/mdream/node_modules/tslib/LICENSE.txt +0 -12
  241. package/node_modules/mdream/node_modules/tslib/README.md +0 -164
  242. package/node_modules/mdream/node_modules/tslib/SECURITY.md +0 -41
  243. package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +0 -38
  244. package/node_modules/mdream/node_modules/tslib/modules/index.js +0 -70
  245. package/node_modules/mdream/node_modules/tslib/modules/package.json +0 -3
  246. package/node_modules/mdream/node_modules/tslib/package.json +0 -47
  247. package/node_modules/mdream/node_modules/tslib/tslib.d.ts +0 -460
  248. package/node_modules/mdream/node_modules/tslib/tslib.es6.html +0 -1
  249. package/node_modules/mdream/node_modules/tslib/tslib.es6.js +0 -402
  250. package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +0 -401
  251. package/node_modules/mdream/node_modules/tslib/tslib.html +0 -1
  252. package/node_modules/mdream/node_modules/tslib/tslib.js +0 -484
  253. package/node_modules/mdream/package.json +0 -110
  254. package/node_modules/mdream/skills/mdream/SKILL.md +0 -124
  255. package/node_modules/mdream/skills/mdream/references/runtimes.md +0 -49
  256. package/node_modules/mdream/wasm/mdream_edge.d.ts +0 -90
  257. package/node_modules/mdream/wasm/mdream_edge.js +0 -517
  258. package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
  259. package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +0 -20
  260. package/node_modules/mdream/wasm/package.json +0 -17
  261. package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +0 -45
  262. package/node_modules/mdream/wasm-bundler/mdream_edge.js +0 -13
  263. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +0 -413
  264. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
  265. package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +0 -20
  266. package/node_modules/mdream/wasm-bundler/package.json +0 -19
  267. package/node_modules/pathe/LICENSE +0 -70
  268. package/node_modules/pathe/README.md +0 -73
  269. package/node_modules/pathe/dist/index.cjs +0 -39
  270. package/node_modules/pathe/dist/index.d.cts +0 -47
  271. package/node_modules/pathe/dist/index.d.mts +0 -47
  272. package/node_modules/pathe/dist/index.d.ts +0 -47
  273. package/node_modules/pathe/dist/index.mjs +0 -19
  274. package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +0 -266
  275. package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -249
  276. package/node_modules/pathe/dist/utils.cjs +0 -82
  277. package/node_modules/pathe/dist/utils.d.cts +0 -32
  278. package/node_modules/pathe/dist/utils.d.mts +0 -32
  279. package/node_modules/pathe/dist/utils.d.ts +0 -32
  280. package/node_modules/pathe/dist/utils.mjs +0 -77
  281. package/node_modules/pathe/package.json +0 -61
  282. package/node_modules/pathe/utils.d.ts +0 -1
@@ -1,58 +0,0 @@
1
- import { ELEMENT_NODE, NodeEventEnter, NodeEventExit, TAG_H1, TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6, TEXT_NODE } from "./_chunks/const.mjs";
2
- import { buildTagOverrideHandlers } from "./_chunks/parse.mjs";
3
- import { applyClean, createMarkdownProcessor, resolveClean } from "./_chunks/markdown-processor.mjs";
4
- import { createPlugin } from "./_chunks/plugins.mjs";
5
- import { resolvePlugins } from "./_chunks/resolve-plugins.mjs";
6
- import { streamHtmlToMarkdown as streamHtmlToMarkdown$1 } from "./_chunks/stream.mjs";
7
- import { withMinimalPreset } from "./preset/minimal.mjs";
8
- const TOP_LEVEL_PLUGIN_KEYS = [
9
- "frontmatter",
10
- "isolateMain",
11
- "tailwind",
12
- "filter",
13
- "extraction",
14
- "tagOverrides"
15
- ];
16
- function assertEngineOptions(options) {
17
- if ("minimal" in options) throw new TypeError("@mdream/js has no `minimal` option. Use withMinimalPreset() from '@mdream/js/preset/minimal': htmlToMarkdown(html, withMinimalPreset({ origin })).");
18
- for (const key of TOP_LEVEL_PLUGIN_KEYS) if (key in options) throw new TypeError(`@mdream/js reads \`${key}\` from \`plugins\`. Pass { plugins: { ${key} } } instead of { ${key} }.`);
19
- }
20
- function resolveHooks(options) {
21
- return options.hooks?.length ? options.hooks : void 0;
22
- }
23
- function convert(html, options, hooks) {
24
- const { plugins, callExtractionHandlers, getFrontmatter, frontmatterCallback } = resolvePlugins(options, hooks);
25
- const tagOverrideHandlers = options.plugins?.tagOverrides ? buildTagOverrideHandlers(options.plugins.tagOverrides) : void 0;
26
- const processor = createMarkdownProcessor(options, plugins, tagOverrideHandlers);
27
- processor.processHtml(html);
28
- if (getFrontmatter && frontmatterCallback) {
29
- const fm = getFrontmatter();
30
- if (fm) frontmatterCallback(fm);
31
- }
32
- callExtractionHandlers?.();
33
- return processor.getMarkdown();
34
- }
35
- function htmlToMarkdown(html, options = {}) {
36
- assertEngineOptions(options);
37
- const markdown = convert(html, options, resolveHooks(options));
38
- if (options.clean && (options.format === void 0 || options.format === "markdown")) return applyClean(markdown, resolveClean(options.clean));
39
- return markdown;
40
- }
41
- function streamHtmlToMarkdown(htmlStream, options = {}) {
42
- assertEngineOptions(options);
43
- const hooks = resolveHooks(options);
44
- const { plugins, callExtractionHandlers, getFrontmatter, frontmatterCallback } = resolvePlugins(options, hooks);
45
- const tagOverrideHandlers = options.plugins?.tagOverrides ? buildTagOverrideHandlers(options.plugins.tagOverrides) : void 0;
46
- const stream = streamHtmlToMarkdown$1(htmlStream, options, plugins, tagOverrideHandlers);
47
- if (!callExtractionHandlers && !frontmatterCallback) return stream;
48
- return withCallbacks(stream, () => {
49
- const fm = getFrontmatter?.();
50
- if (fm && frontmatterCallback) frontmatterCallback(fm);
51
- callExtractionHandlers?.();
52
- });
53
- }
54
- async function* withCallbacks(stream, onEnd) {
55
- yield* stream;
56
- onEnd();
57
- }
58
- export { ELEMENT_NODE, NodeEventEnter, NodeEventExit, TAG_H1, TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6, TEXT_NODE, createPlugin, htmlToMarkdown, streamHtmlToMarkdown, withMinimalPreset };
@@ -1,86 +0,0 @@
1
- /**
2
- * Link in llms.txt section
3
- */
4
- export interface LlmsTxtLink {
5
- /** The title of the link */
6
- title: string;
7
- /** The description of the link */
8
- description?: string;
9
- /** The href of the link */
10
- href: string;
11
- }
12
- /**
13
- * Section in llms.txt
14
- */
15
- export interface LlmsTxtSection {
16
- /** The title of the section */
17
- title: string;
18
- /** The description of the section (can be array for multiple paragraphs) */
19
- description?: string | string[];
20
- /** The links of the section */
21
- links?: LlmsTxtLink[];
22
- }
23
- export interface LlmsTxtArtifactsOptions {
24
- files: ProcessedFile[];
25
- siteName?: string;
26
- description?: string;
27
- origin?: string;
28
- generateFull?: boolean;
29
- generateMarkdown?: boolean;
30
- outputDir?: string;
31
- /** The sections to write before pages */
32
- sections?: LlmsTxtSection[];
33
- /** Notes to write at the end */
34
- notes?: string | string[];
35
- }
36
- export interface ProcessedFile {
37
- filePath?: string;
38
- title: string;
39
- content: string;
40
- url: string;
41
- metadata?: {
42
- title?: string;
43
- description?: string;
44
- keywords?: string;
45
- author?: string;
46
- };
47
- }
48
- export interface LlmsTxtArtifactsResult {
49
- llmsTxt: string;
50
- llmsFullTxt?: string;
51
- markdownFiles?: {
52
- path: string;
53
- content: string;
54
- }[];
55
- processedFiles: ProcessedFile[];
56
- }
57
- /**
58
- * Main function to generate llms.txt artifacts from pre-processed files
59
- */
60
- export declare function generateLlmsTxtArtifacts(options: LlmsTxtArtifactsOptions): Promise<LlmsTxtArtifactsResult>;
61
- /**
62
- * Options for creating an llms.txt stream
63
- */
64
- export interface CreateLlmsTxtStreamOptions extends Omit<LlmsTxtArtifactsOptions, 'files' | 'generateMarkdown'> {
65
- /** Directory to write files to (defaults to process.cwd()) */
66
- outputDir?: string;
67
- /** Site name for the header (defaults to 'Site') */
68
- siteName?: string;
69
- /** Site description for the header */
70
- description?: string;
71
- /** Origin URL to prepend to relative URLs */
72
- origin?: string;
73
- /** Generate llms-full.txt with complete page content (defaults to false) */
74
- generateFull?: boolean;
75
- /** The sections to write before pages */
76
- sections?: LlmsTxtSection[];
77
- /** Notes to write at the end */
78
- notes?: string | string[];
79
- }
80
- /**
81
- * Create a WritableStream that generates llms.txt artifacts by streaming pages to disk.
82
- *
83
- * Writes llms.txt (and optionally llms-full.txt) incrementally as pages are written,
84
- * never keeping full content in memory. Creates outputDir recursively if needed.
85
- */
86
- export declare function createLlmsTxtStream(options: CreateLlmsTxtStreamOptions): WritableStream<ProcessedFile>;
@@ -1,308 +0,0 @@
1
- import { join, relative } from "pathe";
2
- import { mkdir, open } from "node:fs/promises";
3
- const FRONTMATTER_RE = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
4
- const ANCHOR_INVALID_CHARS_RE = /[^a-z0-9]/g;
5
- const LEADING_SLASH_RE = /^\//;
6
- const TRAILING_SLASH_RE = /\/$/;
7
- function generateLlmsTxtContent(files, options) {
8
- const { siteName = "Site", description, origin = "", sections, notes } = options;
9
- let content = `# ${siteName}\n\n`;
10
- if (description) content += `> ${description}\n\n`;
11
- if (origin) content += `Canonical Origin: ${origin}\n\n`;
12
- if (sections) for (const section of sections) content += formatSection(section);
13
- if (files.length > 0) {
14
- content += `## Pages\n\n`;
15
- for (const file of files) {
16
- const desc = file.metadata?.description;
17
- const descText = desc ? `: ${desc.substring(0, 100)}${desc.length > 100 ? "..." : ""}` : "";
18
- if (file.filePath && options.outputDir && file.filePath.endsWith(".md")) {
19
- const relativePath = relative(options.outputDir, file.filePath);
20
- content += `- [${file.title}](${relativePath})${descText}\n`;
21
- } else {
22
- const url = file.url.startsWith("http://") || file.url.startsWith("https://") ? file.url : origin ? origin + file.url : file.url;
23
- content += `- [${file.title}](${url})${descText}\n`;
24
- }
25
- }
26
- }
27
- if (notes) content += `\n${formatNotes(notes)}`;
28
- return content;
29
- }
30
- function parseFrontmatter(content) {
31
- const match = content.match(FRONTMATTER_RE);
32
- if (!match) return {
33
- frontmatter: null,
34
- body: content
35
- };
36
- const frontmatterContent = match[1];
37
- const body = match[2];
38
- const frontmatter = {};
39
- const lines = frontmatterContent.split("\n");
40
- for (const line of lines) {
41
- const colonIndex = line.indexOf(":");
42
- if (colonIndex > 0) {
43
- const key = line.substring(0, colonIndex).trim();
44
- frontmatter[key] = line.substring(colonIndex + 1).trim();
45
- }
46
- }
47
- return {
48
- frontmatter,
49
- body
50
- };
51
- }
52
- function serializeFrontmatter(data) {
53
- const lines = [];
54
- for (const [key, value] of Object.entries(data)) if (value !== void 0 && value !== null) lines.push(`${key}: ${String(value)}`);
55
- return lines.join("\n");
56
- }
57
- function generateLlmsFullTxtContent(files, options) {
58
- const { siteName = "Site", description, origin = "", sections, notes } = options;
59
- let content = `# ${siteName}\n\n`;
60
- if (description) content += `> ${description}\n\n`;
61
- if (origin) content += `Canonical Origin: ${origin}\n\n`;
62
- if (sections) for (const section of sections) content += formatSection(section);
63
- if (files.length > 0) {
64
- content += `## Table of Contents\n\n`;
65
- for (const file of files) {
66
- const anchor = file.title.toLowerCase().replace(ANCHOR_INVALID_CHARS_RE, "-");
67
- content += `- [${file.title}](#${anchor})\n`;
68
- }
69
- content += `\n---\n\n`;
70
- for (const file of files) {
71
- const url = file.url.startsWith("http://") || file.url.startsWith("https://") ? file.url : origin ? origin + file.url : file.url;
72
- const { frontmatter, body } = parseFrontmatter(file.content);
73
- const metadata = {
74
- title: file.title,
75
- url
76
- };
77
- if (file.filePath && options.outputDir) metadata.file = relative(options.outputDir, file.filePath);
78
- else if (file.filePath) metadata.file = file.filePath;
79
- if (file.metadata) {
80
- if (file.metadata.description) metadata.description = file.metadata.description;
81
- if (file.metadata.keywords) metadata.keywords = file.metadata.keywords;
82
- if (file.metadata.author) metadata.author = file.metadata.author;
83
- }
84
- const frontmatterString = serializeFrontmatter(frontmatter ? {
85
- ...frontmatter,
86
- ...metadata
87
- } : metadata);
88
- let contentBody = frontmatter ? body : file.content;
89
- const titleLine = contentBody.trim().split("\n")[0];
90
- if (titleLine === file.title || titleLine === `# ${file.title}`) contentBody = contentBody.trim().split("\n").slice(1).join("\n").trimStart();
91
- content += `---\n${frontmatterString}\n---\n\n${contentBody}\n\n---\n\n`;
92
- }
93
- }
94
- if (notes) content += `\n${formatNotes(notes)}`;
95
- return content;
96
- }
97
- function generateMarkdownFilesContent(files) {
98
- const markdownFiles = [];
99
- for (const file of files) {
100
- const mdPath = `md/${file.url === "/" ? "index" : file.url.replace(LEADING_SLASH_RE, "").replace(TRAILING_SLASH_RE, "")}.md`;
101
- markdownFiles.push({
102
- path: mdPath,
103
- content: file.content
104
- });
105
- }
106
- return markdownFiles;
107
- }
108
- async function generateLlmsTxtArtifacts(options) {
109
- const files = options.files;
110
- const llmsTxt = generateLlmsTxtContent(files, options);
111
- let llmsFullTxt;
112
- if (options.generateFull) llmsFullTxt = generateLlmsFullTxtContent(files, options);
113
- let markdownFiles;
114
- if (options.generateMarkdown) markdownFiles = generateMarkdownFilesContent(files);
115
- return {
116
- llmsTxt,
117
- llmsFullTxt,
118
- markdownFiles,
119
- processedFiles: files
120
- };
121
- }
122
- function formatSection(section) {
123
- let content = `## ${section.title}\n\n`;
124
- if (section.description) {
125
- const descriptions = Array.isArray(section.description) ? section.description : [section.description];
126
- for (const desc of descriptions) content += `${desc}\n\n`;
127
- }
128
- if (section.links?.length) {
129
- for (const link of section.links) {
130
- const desc = link.description ? `: ${link.description}` : "";
131
- content += `- [${link.title}](${link.href})${desc}\n`;
132
- }
133
- content += "\n";
134
- }
135
- return content;
136
- }
137
- function formatNotes(notes) {
138
- const noteLines = Array.isArray(notes) ? notes : [notes];
139
- let content = "";
140
- for (const note of noteLines) content += `${note}\n\n`;
141
- return content;
142
- }
143
- function getGroupPrefix(url, depth) {
144
- const segments = url.split("/").filter(Boolean);
145
- if (segments.length === 0) return "/";
146
- if (depth === 1 || segments.length === 1) return `/${segments[0]}`;
147
- return `/${segments[0]}/${segments[1]}`;
148
- }
149
- function sortPagesByPath(pages) {
150
- const twoSegmentCount = /* @__PURE__ */ new Map();
151
- for (const page of pages) {
152
- const prefix = getGroupPrefix(page.url, 2);
153
- twoSegmentCount.set(prefix, (twoSegmentCount.get(prefix) || 0) + 1);
154
- }
155
- const segmentHasNested = /* @__PURE__ */ new Map();
156
- for (const page of pages) {
157
- const segments = page.url.split("/").filter(Boolean);
158
- const firstSegment = segments.length > 0 ? segments[0] : "";
159
- if (!segmentHasNested.has(firstSegment)) segmentHasNested.set(firstSegment, false);
160
- if (segments.length > 1) segmentHasNested.set(firstSegment, true);
161
- }
162
- return pages.sort((a, b) => {
163
- const segmentsA = a.url.split("/").filter(Boolean);
164
- const segmentsB = b.url.split("/").filter(Boolean);
165
- const firstSegmentA = segmentsA.length > 0 ? segmentsA[0] : "";
166
- const firstSegmentB = segmentsB.length > 0 ? segmentsB[0] : "";
167
- const twoSegPrefixA = getGroupPrefix(a.url, 2);
168
- const twoSegPrefixB = getGroupPrefix(b.url, 2);
169
- const twoSegCountA = twoSegmentCount.get(twoSegPrefixA) || 0;
170
- const twoSegCountB = twoSegmentCount.get(twoSegPrefixB) || 0;
171
- let groupKeyA = twoSegCountA > 1 ? twoSegPrefixA : `/${firstSegmentA}`;
172
- let groupKeyB = twoSegCountB > 1 ? twoSegPrefixB : `/${firstSegmentB}`;
173
- const isRootLevelA = segmentsA.length <= 1;
174
- const isRootLevelB = segmentsB.length <= 1;
175
- const hasNestedA = segmentHasNested.get(firstSegmentA);
176
- const hasNestedB = segmentHasNested.get(firstSegmentB);
177
- if (isRootLevelA && !hasNestedA) groupKeyA = "";
178
- if (isRootLevelB && !hasNestedB) groupKeyB = "";
179
- if (groupKeyA === "" && groupKeyB !== "") return -1;
180
- if (groupKeyA !== "" && groupKeyB === "") return 1;
181
- if (groupKeyA !== groupKeyB) return groupKeyA.localeCompare(groupKeyB);
182
- if (segmentsA.length === 0) return -1;
183
- if (segmentsB.length === 0) return 1;
184
- const minLen = Math.min(segmentsA.length, segmentsB.length);
185
- for (let i = 0; i < minLen; i++) {
186
- const cmp = segmentsA[i].localeCompare(segmentsB[i]);
187
- if (cmp !== 0) return cmp;
188
- }
189
- return segmentsA.length - segmentsB.length;
190
- });
191
- }
192
- function createLlmsTxtStream(options) {
193
- const { siteName = "Site", description, origin = "", generateFull, outputDir = process.cwd(), sections, notes } = options;
194
- let llmsTxtHandle;
195
- let llmsFullTxtHandle;
196
- const bufferedPages = [];
197
- return new WritableStream({
198
- async start() {
199
- await mkdir(outputDir, { recursive: true });
200
- llmsTxtHandle = await open(join(outputDir, "llms.txt"), "w");
201
- let header = `# ${siteName}\n\n`;
202
- if (description) header += `> ${description}\n\n`;
203
- if (origin) header += `Canonical Origin: ${origin}\n\n`;
204
- if (sections) for (const section of sections) header += formatSection(section);
205
- await llmsTxtHandle.write(header);
206
- if (generateFull) {
207
- llmsFullTxtHandle = await open(join(outputDir, "llms-full.txt"), "w");
208
- let fullHeader = `# ${siteName}\n\n`;
209
- if (description) fullHeader += `> ${description}\n\n`;
210
- if (origin) fullHeader += `Canonical Origin: ${origin}\n\n`;
211
- if (sections) for (const section of sections) fullHeader += formatSection(section);
212
- await llmsFullTxtHandle.write(fullHeader);
213
- }
214
- },
215
- async write(file) {
216
- const desc = file.metadata?.description;
217
- bufferedPages.push({
218
- url: file.url,
219
- title: file.title,
220
- description: desc,
221
- filePath: file.filePath
222
- });
223
- if (generateFull && llmsFullTxtHandle) {
224
- const url = file.url.startsWith("http://") || file.url.startsWith("https://") ? file.url : origin ? origin + file.url : file.url;
225
- const { frontmatter, body } = parseFrontmatter(file.content);
226
- const metadata = {
227
- title: file.title,
228
- url
229
- };
230
- if (file.filePath) metadata.file = relative(outputDir, file.filePath);
231
- if (file.metadata) {
232
- if (file.metadata.description) metadata.description = file.metadata.description;
233
- if (file.metadata.keywords) metadata.keywords = file.metadata.keywords;
234
- if (file.metadata.author) metadata.author = file.metadata.author;
235
- }
236
- const frontmatterString = serializeFrontmatter(frontmatter ? {
237
- ...frontmatter,
238
- ...metadata
239
- } : metadata);
240
- let contentBody = frontmatter ? body : file.content;
241
- const titleLine = contentBody.trim().split("\n")[0];
242
- if (titleLine === file.title || titleLine === `# ${file.title}`) contentBody = contentBody.trim().split("\n").slice(1).join("\n").trimStart();
243
- const fullChunk = `---\n${frontmatterString}\n---\n\n${contentBody}\n\n---\n\n`;
244
- await llmsFullTxtHandle.write(fullChunk);
245
- }
246
- },
247
- async close() {
248
- const sortedPages = sortPagesByPath(bufferedPages);
249
- const twoSegmentCount = /* @__PURE__ */ new Map();
250
- for (const page of sortedPages) {
251
- const prefix = getGroupPrefix(page.url, 2);
252
- twoSegmentCount.set(prefix, (twoSegmentCount.get(prefix) || 0) + 1);
253
- }
254
- const segmentHasNested = /* @__PURE__ */ new Map();
255
- for (const page of sortedPages) {
256
- const segments = page.url.split("/").filter(Boolean);
257
- const firstSegment = segments.length > 0 ? segments[0] : "";
258
- if (!segmentHasNested.has(firstSegment)) segmentHasNested.set(firstSegment, false);
259
- if (segments.length > 1) segmentHasNested.set(firstSegment, true);
260
- }
261
- await llmsTxtHandle?.write(`## Pages\n\n`);
262
- let currentGroup = "";
263
- let segmentGroupIndex = 0;
264
- let urlsInCurrentGroup = 0;
265
- for (let i = 0; i < sortedPages.length; i++) {
266
- const page = sortedPages[i];
267
- const segments = page.url.split("/").filter(Boolean);
268
- const firstSegment = segments.length > 0 ? segments[0] : "";
269
- const twoSegPrefix = getGroupPrefix(page.url, 2);
270
- let groupKey = (twoSegmentCount.get(twoSegPrefix) || 0) > 1 ? twoSegPrefix : `/${firstSegment}`;
271
- const isRootLevel = segments.length <= 1;
272
- const hasNested = segmentHasNested.get(firstSegment);
273
- if (isRootLevel && !hasNested) groupKey = "";
274
- if (groupKey !== currentGroup) {
275
- if (urlsInCurrentGroup > 0) {
276
- if (segmentGroupIndex === 0 || segmentGroupIndex >= 1 && segmentGroupIndex <= 2 && urlsInCurrentGroup > 1) await llmsTxtHandle?.write("\n");
277
- }
278
- currentGroup = groupKey;
279
- segmentGroupIndex++;
280
- urlsInCurrentGroup = 0;
281
- }
282
- urlsInCurrentGroup++;
283
- const descText = page.description ? `: ${page.description.substring(0, 160)}${page.description.length > 160 ? "..." : ""}` : "";
284
- let chunk = "";
285
- if (page.filePath && page.filePath.endsWith(".md")) {
286
- const relativePath = relative(outputDir, page.filePath);
287
- chunk = `- [${page.title}](${relativePath})${descText}\n`;
288
- } else {
289
- const url = page.url.startsWith("http://") || page.url.startsWith("https://") ? page.url : origin ? origin + page.url : page.url;
290
- chunk = `- [${page.title}](${url})${descText}\n`;
291
- }
292
- await llmsTxtHandle?.write(chunk);
293
- }
294
- if (notes) {
295
- const notesContent = formatNotes(notes);
296
- await llmsTxtHandle?.write(`\n${notesContent}`);
297
- if (generateFull && llmsFullTxtHandle) await llmsFullTxtHandle.write(`\n${notesContent}`);
298
- }
299
- await llmsTxtHandle?.close();
300
- await llmsFullTxtHandle?.close();
301
- },
302
- async abort(_reason) {
303
- await llmsTxtHandle?.close();
304
- await llmsFullTxtHandle?.close();
305
- }
306
- });
307
- }
308
- export { createLlmsTxtStream, generateLlmsTxtArtifacts };
@@ -1,35 +0,0 @@
1
- export type ContentNegotiationResult = 'markdown' | 'html' | 'not-acceptable';
2
- interface AcceptEntry {
3
- type: string;
4
- q: number;
5
- position: number;
6
- }
7
- /**
8
- * Parse an HTTP Accept header into an ordered list of media types with quality values.
9
- * Supports quality weights (q=0.9) and preserves original position for tie-breaking.
10
- */
11
- export declare function parseAcceptHeader(accept: string): AcceptEntry[];
12
- /**
13
- * Perform RFC 7231 content negotiation for HTML vs Markdown.
14
- *
15
- * Resolution rules:
16
- * - `Sec-Fetch-Dest: document` always returns `'html'` (browser navigation).
17
- * - Missing or empty Accept header returns `'html'` (server picks default).
18
- * - q=0 entries are treated as explicit rejections and ignored for matching
19
- * (but still count towards "something was listed").
20
- * - `text/markdown` and `text/plain` are the markdown-capable types.
21
- * - `text/html` and `application/xhtml+xml` are the html-capable types.
22
- * - `*_/_*` and `text/*` are wildcards; they satisfy 406 but never on their
23
- * own tip negotiation towards markdown (preserves OG crawler behavior).
24
- * - If nothing in the Accept header can be served (no explicit match, no
25
- * wildcard), returns `'not-acceptable'` so the caller can send 406.
26
- * - Otherwise, compares best markdown entry vs best html-or-wildcard entry
27
- * by q, then by position.
28
- */
29
- export declare function negotiateContent(acceptHeader?: string, secFetchDest?: string): ContentNegotiationResult;
30
- /**
31
- * Determine if a client prefers markdown over HTML. Convenience wrapper over
32
- * {@link negotiateContent}; treats `'not-acceptable'` the same as `'html'`
33
- * (callers that want 406 semantics should use `negotiateContent` directly).
34
- */
35
- export declare function shouldServeMarkdown(acceptHeader?: string, secFetchDest?: string): boolean;
@@ -1,121 +0,0 @@
1
- function parseAcceptHeader(accept) {
2
- if (!accept) return [];
3
- const entries = [];
4
- const parts = accept.split(",");
5
- for (let i = 0; i < parts.length; i++) {
6
- const part = parts[i].trim();
7
- if (!part) continue;
8
- const semicolonIdx = part.indexOf(";");
9
- let type;
10
- let q = 1;
11
- if (semicolonIdx === -1) type = part;
12
- else {
13
- type = part.slice(0, semicolonIdx).trim();
14
- const paramStr = part.slice(semicolonIdx + 1);
15
- const qIdx = paramStr.indexOf("q=");
16
- if (qIdx !== -1) {
17
- const qStart = qIdx + 2;
18
- let qEnd = qStart;
19
- while (qEnd < paramStr.length && paramStr.charCodeAt(qEnd) !== 59 && paramStr.charCodeAt(qEnd) !== 32) qEnd++;
20
- q = +paramStr.slice(qStart, qEnd) || 0;
21
- }
22
- }
23
- entries.push({
24
- type,
25
- q,
26
- position: i
27
- });
28
- }
29
- return entries;
30
- }
31
- function negotiateContent(acceptHeader, secFetchDest) {
32
- if (secFetchDest === "document") return "html";
33
- const accept = acceptHeader || "";
34
- if (!accept) return "html";
35
- let bestMdQ = -1;
36
- let bestMdPos = -1;
37
- let bestHtmlQ = -1;
38
- let bestHtmlPos = -1;
39
- let bestWildcardQ = -1;
40
- let bestWildcardPos = -1;
41
- let sawAnyEntry = false;
42
- let sawAcceptable = false;
43
- let rejectedMd = false;
44
- let rejectedHtml = false;
45
- const parts = accept.split(",");
46
- for (let i = 0; i < parts.length; i++) {
47
- const part = parts[i].trim();
48
- if (!part) continue;
49
- sawAnyEntry = true;
50
- const semicolonIdx = part.indexOf(";");
51
- let type;
52
- let q = 1;
53
- if (semicolonIdx === -1) type = part;
54
- else {
55
- type = part.slice(0, semicolonIdx).trim();
56
- const paramStr = part.slice(semicolonIdx + 1);
57
- let qIdx = -1;
58
- for (let j = 0; j < paramStr.length - 1; j++) {
59
- const c = paramStr.charCodeAt(j);
60
- if ((c === 113 || c === 81) && paramStr.charCodeAt(j + 1) === 61) {
61
- qIdx = j;
62
- break;
63
- }
64
- }
65
- if (qIdx !== -1) {
66
- const qStart = qIdx + 2;
67
- let qEnd = qStart;
68
- while (qEnd < paramStr.length && paramStr.charCodeAt(qEnd) !== 59 && paramStr.charCodeAt(qEnd) !== 32) qEnd++;
69
- q = +paramStr.slice(qStart, qEnd) || 0;
70
- }
71
- }
72
- const normalized = type.toLowerCase();
73
- if (normalized === "text/markdown" || normalized === "text/plain") {
74
- if (q === 0) {
75
- rejectedMd = true;
76
- continue;
77
- }
78
- sawAcceptable = true;
79
- if (q > bestMdQ || q === bestMdQ && bestMdPos === -1) {
80
- bestMdQ = q;
81
- bestMdPos = i;
82
- }
83
- } else if (normalized === "text/html" || normalized === "application/xhtml+xml") {
84
- if (q === 0) {
85
- rejectedHtml = true;
86
- continue;
87
- }
88
- sawAcceptable = true;
89
- if (q > bestHtmlQ || q === bestHtmlQ && bestHtmlPos === -1) {
90
- bestHtmlQ = q;
91
- bestHtmlPos = i;
92
- }
93
- } else if (normalized === "*/*" || normalized === "text/*") {
94
- if (q === 0) continue;
95
- sawAcceptable = true;
96
- if (q > bestWildcardQ || q === bestWildcardQ && bestWildcardPos === -1) {
97
- bestWildcardQ = q;
98
- bestWildcardPos = i;
99
- }
100
- }
101
- }
102
- if (sawAnyEntry && !sawAcceptable) return "not-acceptable";
103
- if (bestMdPos === -1 && !rejectedMd && bestWildcardPos !== -1) {
104
- bestMdQ = bestWildcardQ;
105
- bestMdPos = bestWildcardPos;
106
- }
107
- if (bestHtmlPos === -1 && !rejectedHtml && bestWildcardPos !== -1) {
108
- bestHtmlQ = bestWildcardQ;
109
- bestHtmlPos = bestWildcardPos;
110
- }
111
- if (bestMdPos === -1 && bestHtmlPos === -1) return "not-acceptable";
112
- if (bestMdPos === -1) return "html";
113
- if (bestHtmlPos === -1) return "markdown";
114
- if (bestMdQ > bestHtmlQ) return "markdown";
115
- if (bestMdQ === bestHtmlQ && bestMdPos < bestHtmlPos) return "markdown";
116
- return "html";
117
- }
118
- function shouldServeMarkdown(acceptHeader, secFetchDest) {
119
- return negotiateContent(acceptHeader, secFetchDest) === "markdown";
120
- }
121
- export { negotiateContent, parseAcceptHeader, shouldServeMarkdown };