@temelj/mdx 0.14.0 → 0.16.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 (381) hide show
  1. package/README.md +470 -82
  2. package/dist/character-entities.d.mts +4 -0
  3. package/dist/character-entities.d.mts.map +1 -0
  4. package/dist/character-entities.mjs +2132 -0
  5. package/dist/character-entities.mjs.map +1 -0
  6. package/dist/character-reference.d.mts +6 -0
  7. package/dist/character-reference.d.mts.map +1 -0
  8. package/dist/character-reference.mjs +18 -0
  9. package/dist/character-reference.mjs.map +1 -0
  10. package/dist/compile-analysis.d.mts +28 -0
  11. package/dist/compile-analysis.d.mts.map +1 -0
  12. package/dist/compile-analysis.mjs +74 -0
  13. package/dist/compile-analysis.mjs.map +1 -0
  14. package/dist/compile-emit.d.mts +9 -0
  15. package/dist/compile-emit.d.mts.map +1 -0
  16. package/dist/compile-emit.mjs +187 -0
  17. package/dist/compile-emit.mjs.map +1 -0
  18. package/dist/compile-esm.d.mts +34 -0
  19. package/dist/compile-esm.d.mts.map +1 -0
  20. package/dist/compile-esm.mjs +187 -0
  21. package/dist/compile-esm.mjs.map +1 -0
  22. package/dist/compile-names.d.mts +13 -0
  23. package/dist/compile-names.d.mts.map +1 -0
  24. package/dist/compile-names.mjs +32 -0
  25. package/dist/compile-names.mjs.map +1 -0
  26. package/dist/compiler.d.mts +69 -85
  27. package/dist/compiler.d.mts.map +1 -1
  28. package/dist/compiler.mjs +167 -420
  29. package/dist/compiler.mjs.map +1 -1
  30. package/dist/diagnostics.d.mts +37 -0
  31. package/dist/diagnostics.d.mts.map +1 -0
  32. package/dist/diagnostics.mjs +57 -0
  33. package/dist/diagnostics.mjs.map +1 -0
  34. package/dist/errors.d.mts +157 -0
  35. package/dist/errors.d.mts.map +1 -0
  36. package/dist/errors.mjs +263 -0
  37. package/dist/errors.mjs.map +1 -0
  38. package/dist/footnote-numbering.d.mts +27 -0
  39. package/dist/footnote-numbering.d.mts.map +1 -0
  40. package/dist/footnote-numbering.mjs +49 -0
  41. package/dist/footnote-numbering.mjs.map +1 -0
  42. package/dist/format-context.d.mts +46 -0
  43. package/dist/format-context.d.mts.map +1 -0
  44. package/dist/format-context.mjs +26 -0
  45. package/dist/format-context.mjs.map +1 -0
  46. package/dist/format-directive.d.mts +9 -0
  47. package/dist/format-directive.d.mts.map +1 -0
  48. package/dist/format-directive.mjs +99 -0
  49. package/dist/format-directive.mjs.map +1 -0
  50. package/dist/format-jsx.d.mts +8 -0
  51. package/dist/format-jsx.d.mts.map +1 -0
  52. package/dist/format-jsx.mjs +47 -0
  53. package/dist/format-jsx.mjs.map +1 -0
  54. package/dist/format-math.d.mts +9 -0
  55. package/dist/format-math.d.mts.map +1 -0
  56. package/dist/format-math.mjs +79 -0
  57. package/dist/format-math.mjs.map +1 -0
  58. package/dist/format-safe.d.mts +25 -0
  59. package/dist/format-safe.d.mts.map +1 -0
  60. package/dist/format-safe.mjs +366 -0
  61. package/dist/format-safe.mjs.map +1 -0
  62. package/dist/format-table.d.mts +8 -0
  63. package/dist/format-table.d.mts.map +1 -0
  64. package/dist/format-table.mjs +55 -0
  65. package/dist/format-table.mjs.map +1 -0
  66. package/dist/format-track.d.mts +18 -0
  67. package/dist/format-track.d.mts.map +1 -0
  68. package/dist/format-track.mjs +34 -0
  69. package/dist/format-track.mjs.map +1 -0
  70. package/dist/format.d.mts +7 -0
  71. package/dist/format.d.mts.map +1 -0
  72. package/dist/format.mjs +549 -0
  73. package/dist/format.mjs.map +1 -0
  74. package/dist/frontmatter-decode.d.mts +15 -0
  75. package/dist/frontmatter-decode.d.mts.map +1 -0
  76. package/dist/frontmatter-decode.mjs +187 -0
  77. package/dist/frontmatter-decode.mjs.map +1 -0
  78. package/dist/frontmatter-schema.d.mts +8 -0
  79. package/dist/frontmatter-schema.d.mts.map +1 -0
  80. package/dist/frontmatter-schema.mjs +28 -0
  81. package/dist/frontmatter-schema.mjs.map +1 -0
  82. package/dist/frontmatter.d.mts +40 -0
  83. package/dist/frontmatter.d.mts.map +1 -0
  84. package/dist/frontmatter.mjs +109 -0
  85. package/dist/frontmatter.mjs.map +1 -0
  86. package/dist/heading.d.mts +6 -0
  87. package/dist/heading.d.mts.map +1 -0
  88. package/dist/heading.mjs +19 -0
  89. package/dist/heading.mjs.map +1 -0
  90. package/dist/html-format.d.mts +32 -0
  91. package/dist/html-format.d.mts.map +1 -0
  92. package/dist/html-format.mjs +127 -0
  93. package/dist/html-format.mjs.map +1 -0
  94. package/dist/html-lower.d.mts +78 -0
  95. package/dist/html-lower.d.mts.map +1 -0
  96. package/dist/html-lower.mjs +583 -0
  97. package/dist/html-lower.mjs.map +1 -0
  98. package/dist/html-stream.d.mts +13 -0
  99. package/dist/html-stream.d.mts.map +1 -0
  100. package/dist/html-stream.mjs +32 -0
  101. package/dist/html-stream.mjs.map +1 -0
  102. package/dist/html.d.mts +120 -0
  103. package/dist/html.d.mts.map +1 -0
  104. package/dist/html.mjs +77 -0
  105. package/dist/html.mjs.map +1 -0
  106. package/dist/identifier.d.mts +4 -0
  107. package/dist/identifier.d.mts.map +1 -0
  108. package/dist/identifier.mjs +8 -0
  109. package/dist/identifier.mjs.map +1 -0
  110. package/dist/javascript-ast.d.mts +16 -0
  111. package/dist/javascript-ast.d.mts.map +1 -0
  112. package/dist/javascript-ast.mjs +39 -0
  113. package/dist/javascript-ast.mjs.map +1 -0
  114. package/dist/javascript-jsx.d.mts +24 -0
  115. package/dist/javascript-jsx.d.mts.map +1 -0
  116. package/dist/javascript-jsx.mjs +189 -0
  117. package/dist/javascript-jsx.mjs.map +1 -0
  118. package/dist/javascript.d.mts +9 -0
  119. package/dist/javascript.d.mts.map +1 -0
  120. package/dist/javascript.mjs +31 -0
  121. package/dist/javascript.mjs.map +1 -0
  122. package/dist/jsx-reference.d.mts +15 -0
  123. package/dist/jsx-reference.d.mts.map +1 -0
  124. package/dist/jsx-reference.mjs +31 -0
  125. package/dist/jsx-reference.mjs.map +1 -0
  126. package/dist/mod.d.mts +26 -9
  127. package/dist/mod.mjs +20 -8
  128. package/dist/model.d.mts +196 -0
  129. package/dist/model.d.mts.map +1 -0
  130. package/dist/model.mjs +113 -0
  131. package/dist/model.mjs.map +1 -0
  132. package/dist/parser/block-container-recognizers.d.mts +40 -0
  133. package/dist/parser/block-container-recognizers.d.mts.map +1 -0
  134. package/dist/parser/block-container-recognizers.mjs +90 -0
  135. package/dist/parser/block-container-recognizers.mjs.map +1 -0
  136. package/dist/parser/block-directive-recognizers.d.mts +22 -0
  137. package/dist/parser/block-directive-recognizers.d.mts.map +1 -0
  138. package/dist/parser/block-directive-recognizers.mjs +77 -0
  139. package/dist/parser/block-directive-recognizers.mjs.map +1 -0
  140. package/dist/parser/block-leaf-recognizers.d.mts +53 -0
  141. package/dist/parser/block-leaf-recognizers.d.mts.map +1 -0
  142. package/dist/parser/block-leaf-recognizers.mjs +386 -0
  143. package/dist/parser/block-leaf-recognizers.mjs.map +1 -0
  144. package/dist/parser/block-parser.d.mts +38 -0
  145. package/dist/parser/block-parser.d.mts.map +1 -0
  146. package/dist/parser/block-parser.mjs +895 -0
  147. package/dist/parser/block-parser.mjs.map +1 -0
  148. package/dist/parser/block-syntax.d.mts +240 -0
  149. package/dist/parser/block-syntax.d.mts.map +1 -0
  150. package/dist/parser/characters.d.mts +19 -0
  151. package/dist/parser/characters.d.mts.map +1 -0
  152. package/dist/parser/characters.mjs +52 -0
  153. package/dist/parser/characters.mjs.map +1 -0
  154. package/dist/parser/config.d.mts +16 -0
  155. package/dist/parser/config.d.mts.map +1 -0
  156. package/dist/parser/config.mjs +25 -0
  157. package/dist/parser/config.mjs.map +1 -0
  158. package/dist/parser/directive-attributes.d.mts +9 -0
  159. package/dist/parser/directive-attributes.d.mts.map +1 -0
  160. package/dist/parser/directive-attributes.mjs +24 -0
  161. package/dist/parser/directive-attributes.mjs.map +1 -0
  162. package/dist/parser/embedded-scanner.d.mts +18 -0
  163. package/dist/parser/embedded-scanner.d.mts.map +1 -0
  164. package/dist/parser/embedded-scanner.mjs +199 -0
  165. package/dist/parser/embedded-scanner.mjs.map +1 -0
  166. package/dist/parser/inline-autolink.d.mts +7 -0
  167. package/dist/parser/inline-autolink.d.mts.map +1 -0
  168. package/dist/parser/inline-autolink.mjs +42 -0
  169. package/dist/parser/inline-autolink.mjs.map +1 -0
  170. package/dist/parser/inline-character-reference.d.mts +7 -0
  171. package/dist/parser/inline-character-reference.d.mts.map +1 -0
  172. package/dist/parser/inline-character-reference.mjs +22 -0
  173. package/dist/parser/inline-character-reference.mjs.map +1 -0
  174. package/dist/parser/inline-code.d.mts +7 -0
  175. package/dist/parser/inline-code.d.mts.map +1 -0
  176. package/dist/parser/inline-code.mjs +29 -0
  177. package/dist/parser/inline-code.mjs.map +1 -0
  178. package/dist/parser/inline-directive.d.mts +9 -0
  179. package/dist/parser/inline-directive.d.mts.map +1 -0
  180. package/dist/parser/inline-directive.mjs +45 -0
  181. package/dist/parser/inline-directive.mjs.map +1 -0
  182. package/dist/parser/inline-embedded.d.mts +19 -0
  183. package/dist/parser/inline-embedded.d.mts.map +1 -0
  184. package/dist/parser/inline-embedded.mjs +92 -0
  185. package/dist/parser/inline-embedded.mjs.map +1 -0
  186. package/dist/parser/inline-emphasis.d.mts +11 -0
  187. package/dist/parser/inline-emphasis.d.mts.map +1 -0
  188. package/dist/parser/inline-emphasis.mjs +79 -0
  189. package/dist/parser/inline-emphasis.mjs.map +1 -0
  190. package/dist/parser/inline-input.d.mts +46 -0
  191. package/dist/parser/inline-input.d.mts.map +1 -0
  192. package/dist/parser/inline-input.mjs +137 -0
  193. package/dist/parser/inline-input.mjs.map +1 -0
  194. package/dist/parser/inline-link.d.mts +12 -0
  195. package/dist/parser/inline-link.d.mts.map +1 -0
  196. package/dist/parser/inline-link.mjs +187 -0
  197. package/dist/parser/inline-link.mjs.map +1 -0
  198. package/dist/parser/inline-math.d.mts +10 -0
  199. package/dist/parser/inline-math.d.mts.map +1 -0
  200. package/dist/parser/inline-math.mjs +46 -0
  201. package/dist/parser/inline-math.mjs.map +1 -0
  202. package/dist/parser/inline-output.d.mts +34 -0
  203. package/dist/parser/inline-output.d.mts.map +1 -0
  204. package/dist/parser/inline-output.mjs +62 -0
  205. package/dist/parser/inline-output.mjs.map +1 -0
  206. package/dist/parser/inline-parser.d.mts +14 -0
  207. package/dist/parser/inline-parser.d.mts.map +1 -0
  208. package/dist/parser/inline-parser.mjs +328 -0
  209. package/dist/parser/inline-parser.mjs.map +1 -0
  210. package/dist/parser/inline-pending.d.mts +23 -0
  211. package/dist/parser/inline-pending.d.mts.map +1 -0
  212. package/dist/parser/inline-pending.mjs +100 -0
  213. package/dist/parser/inline-pending.mjs.map +1 -0
  214. package/dist/parser/inline-syntax.d.mts +118 -0
  215. package/dist/parser/inline-syntax.d.mts.map +1 -0
  216. package/dist/parser/inline-syntax.mjs +1 -0
  217. package/dist/parser/javascript-boundary.d.mts +16 -0
  218. package/dist/parser/javascript-boundary.d.mts.map +1 -0
  219. package/dist/parser/javascript-boundary.mjs +42 -0
  220. package/dist/parser/javascript-boundary.mjs.map +1 -0
  221. package/dist/parser/javascript-scanner.d.mts +22 -0
  222. package/dist/parser/javascript-scanner.d.mts.map +1 -0
  223. package/dist/parser/javascript-scanner.mjs +122 -0
  224. package/dist/parser/javascript-scanner.mjs.map +1 -0
  225. package/dist/parser/materialize-cache.d.mts +34 -0
  226. package/dist/parser/materialize-cache.d.mts.map +1 -0
  227. package/dist/parser/materialize-cache.mjs +12 -0
  228. package/dist/parser/materialize-cache.mjs.map +1 -0
  229. package/dist/parser/materialize-jsx.d.mts +14 -0
  230. package/dist/parser/materialize-jsx.d.mts.map +1 -0
  231. package/dist/parser/materialize-jsx.mjs +76 -0
  232. package/dist/parser/materialize-jsx.mjs.map +1 -0
  233. package/dist/parser/materialize.d.mts +61 -0
  234. package/dist/parser/materialize.d.mts.map +1 -0
  235. package/dist/parser/materialize.mjs +736 -0
  236. package/dist/parser/materialize.mjs.map +1 -0
  237. package/dist/parser/recognizer.d.mts +20 -0
  238. package/dist/parser/recognizer.d.mts.map +1 -0
  239. package/dist/parser/recognizer.mjs +24 -0
  240. package/dist/parser/recognizer.mjs.map +1 -0
  241. package/dist/parser/session.d.mts +42 -0
  242. package/dist/parser/session.d.mts.map +1 -0
  243. package/dist/parser/session.mjs +89 -0
  244. package/dist/parser/session.mjs.map +1 -0
  245. package/dist/parser.d.mts +25 -0
  246. package/dist/parser.d.mts.map +1 -0
  247. package/dist/parser.mjs +37 -0
  248. package/dist/parser.mjs.map +1 -0
  249. package/dist/plugin-internal.d.mts +25 -0
  250. package/dist/plugin-internal.d.mts.map +1 -0
  251. package/dist/plugin-internal.mjs +99 -0
  252. package/dist/plugin-internal.mjs.map +1 -0
  253. package/dist/plugin.d.mts +37 -0
  254. package/dist/plugin.d.mts.map +1 -0
  255. package/dist/plugin.mjs +1 -0
  256. package/dist/plugins/code-block-metadata.d.mts +42 -0
  257. package/dist/plugins/code-block-metadata.d.mts.map +1 -0
  258. package/dist/plugins/code-block-metadata.mjs +133 -0
  259. package/dist/plugins/code-block-metadata.mjs.map +1 -0
  260. package/dist/plugins/heading-id.d.mts +15 -0
  261. package/dist/plugins/heading-id.d.mts.map +1 -0
  262. package/dist/plugins/heading-id.mjs +45 -0
  263. package/dist/plugins/heading-id.mjs.map +1 -0
  264. package/dist/plugins/lower-heading.d.mts +16 -0
  265. package/dist/plugins/lower-heading.d.mts.map +1 -0
  266. package/dist/plugins/lower-heading.mjs +28 -0
  267. package/dist/plugins/lower-heading.mjs.map +1 -0
  268. package/dist/plugins/math-render.d.mts +26 -0
  269. package/dist/plugins/math-render.d.mts.map +1 -0
  270. package/dist/plugins/math-render.mjs +51 -0
  271. package/dist/plugins/math-render.mjs.map +1 -0
  272. package/dist/plugins/mod.d.mts +9 -6
  273. package/dist/plugins/mod.mjs +8 -6
  274. package/dist/plugins/remove-esm.d.mts +10 -0
  275. package/dist/plugins/remove-esm.d.mts.map +1 -0
  276. package/dist/plugins/remove-esm.mjs +12 -0
  277. package/dist/plugins/remove-esm.mjs.map +1 -0
  278. package/dist/plugins/shiki.d.mts +21 -0
  279. package/dist/plugins/shiki.d.mts.map +1 -0
  280. package/dist/plugins/shiki.mjs +144 -0
  281. package/dist/plugins/shiki.mjs.map +1 -0
  282. package/dist/plugins/syntax-highlight.d.mts +38 -0
  283. package/dist/plugins/syntax-highlight.d.mts.map +1 -0
  284. package/dist/plugins/syntax-highlight.mjs +106 -0
  285. package/dist/plugins/syntax-highlight.mjs.map +1 -0
  286. package/dist/processor.d.mts +60 -0
  287. package/dist/processor.d.mts.map +1 -0
  288. package/dist/processor.mjs +106 -0
  289. package/dist/processor.mjs.map +1 -0
  290. package/dist/ranges.d.mts +10 -0
  291. package/dist/ranges.d.mts.map +1 -0
  292. package/dist/ranges.mjs +22 -0
  293. package/dist/ranges.mjs.map +1 -0
  294. package/dist/source-map.d.mts +28 -0
  295. package/dist/source-map.d.mts.map +1 -0
  296. package/dist/source-map.mjs +90 -0
  297. package/dist/source-map.mjs.map +1 -0
  298. package/dist/source-text.d.mts +35 -0
  299. package/dist/source-text.d.mts.map +1 -0
  300. package/dist/source-text.mjs +136 -0
  301. package/dist/source-text.mjs.map +1 -0
  302. package/dist/source.d.mts +86 -0
  303. package/dist/source.d.mts.map +1 -0
  304. package/dist/source.mjs +264 -0
  305. package/dist/source.mjs.map +1 -0
  306. package/dist/stream-events.d.mts +59 -0
  307. package/dist/stream-events.d.mts.map +1 -0
  308. package/dist/stream-events.mjs +115 -0
  309. package/dist/stream-events.mjs.map +1 -0
  310. package/dist/stream-session.d.mts +79 -0
  311. package/dist/stream-session.d.mts.map +1 -0
  312. package/dist/stream-session.mjs +904 -0
  313. package/dist/stream-session.mjs.map +1 -0
  314. package/dist/stream-tail.d.mts +84 -0
  315. package/dist/stream-tail.d.mts.map +1 -0
  316. package/dist/stream-tail.mjs +359 -0
  317. package/dist/stream-tail.mjs.map +1 -0
  318. package/dist/stream-types.d.mts +89 -0
  319. package/dist/stream-types.d.mts.map +1 -0
  320. package/dist/stream-types.mjs +1 -0
  321. package/dist/stream.d.mts +28 -0
  322. package/dist/stream.d.mts.map +1 -0
  323. package/dist/stream.mjs +68 -0
  324. package/dist/stream.mjs.map +1 -0
  325. package/dist/syntax-options.d.mts +21 -0
  326. package/dist/syntax-options.d.mts.map +1 -0
  327. package/dist/syntax-options.mjs +26 -0
  328. package/dist/syntax-options.mjs.map +1 -0
  329. package/dist/traversal.d.mts +25 -0
  330. package/dist/traversal.d.mts.map +1 -0
  331. package/dist/traversal.mjs +136 -0
  332. package/dist/traversal.mjs.map +1 -0
  333. package/dist/tree.d.mts +18 -0
  334. package/dist/tree.d.mts.map +1 -0
  335. package/dist/tree.mjs +43 -0
  336. package/dist/tree.mjs.map +1 -0
  337. package/dist/unified/adapter.d.mts +24 -0
  338. package/dist/unified/adapter.d.mts.map +1 -0
  339. package/dist/unified/adapter.mjs +44 -0
  340. package/dist/unified/adapter.mjs.map +1 -0
  341. package/dist/unified/mod.d.mts +2 -0
  342. package/dist/unified/mod.mjs +1 -0
  343. package/dist/unified/runtime.d.mts +10 -0
  344. package/dist/unified/runtime.d.mts.map +1 -0
  345. package/dist/unified/runtime.mjs +115 -0
  346. package/dist/unified/runtime.mjs.map +1 -0
  347. package/dist/unified/tree-bridge.d.mts +63 -0
  348. package/dist/unified/tree-bridge.d.mts.map +1 -0
  349. package/dist/unified/tree-bridge.mjs +876 -0
  350. package/dist/unified/tree-bridge.mjs.map +1 -0
  351. package/dist/uri.d.mts +5 -0
  352. package/dist/uri.d.mts.map +1 -0
  353. package/dist/uri.mjs +32 -0
  354. package/dist/uri.mjs.map +1 -0
  355. package/package.json +56 -30
  356. package/dist/plugins/heading-id/plugin.d.mts +0 -17
  357. package/dist/plugins/heading-id/plugin.d.mts.map +0 -1
  358. package/dist/plugins/heading-id/plugin.mjs +0 -23
  359. package/dist/plugins/heading-id/plugin.mjs.map +0 -1
  360. package/dist/plugins/katex/plugin.d.mts +0 -39
  361. package/dist/plugins/katex/plugin.d.mts.map +0 -1
  362. package/dist/plugins/katex/plugin.mjs +0 -107
  363. package/dist/plugins/katex/plugin.mjs.map +0 -1
  364. package/dist/plugins/remove-imports-exports.d.mts +0 -10
  365. package/dist/plugins/remove-imports-exports.d.mts.map +0 -1
  366. package/dist/plugins/remove-imports-exports.mjs +0 -15
  367. package/dist/plugins/remove-imports-exports.mjs.map +0 -1
  368. package/dist/plugins/syntax-highlight/code-meta.d.mts +0 -22
  369. package/dist/plugins/syntax-highlight/code-meta.d.mts.map +0 -1
  370. package/dist/plugins/syntax-highlight/code-meta.mjs +0 -38
  371. package/dist/plugins/syntax-highlight/code-meta.mjs.map +0 -1
  372. package/dist/plugins/syntax-highlight/plugin.d.mts +0 -57
  373. package/dist/plugins/syntax-highlight/plugin.d.mts.map +0 -1
  374. package/dist/plugins/syntax-highlight/plugin.mjs +0 -93
  375. package/dist/plugins/syntax-highlight/plugin.mjs.map +0 -1
  376. package/dist/plugins/tree-processor/plugin.d.mts +0 -19
  377. package/dist/plugins/tree-processor/plugin.d.mts.map +0 -1
  378. package/dist/plugins/tree-processor/plugin.mjs +0 -21
  379. package/dist/plugins/tree-processor/plugin.mjs.map +0 -1
  380. package/dist/types.d.mts +0 -2
  381. /package/dist/{types.mjs → parser/block-syntax.mjs} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.mjs","names":[],"sources":["../src/source.ts"],"sourcesContent":["import { isString } from \"@temelj/value\";\n\nimport type { SourceRange } from \"./ranges.ts\";\n\nimport { InputError } from \"./errors.ts\";\nimport { sourceRange } from \"./ranges.ts\";\nimport { SourceText } from \"./source-text.ts\";\n\nexport interface SourceFileInput {\n readonly name?: string;\n readonly text: string;\n}\n\nexport interface SourceLocation {\n readonly offset: number;\n readonly line: number;\n readonly column: number;\n}\n\n/** A range in a specific source file. Diagnostics carry spans because they outlive trees. */\nexport interface SourceSpan {\n readonly file: SourceFile;\n readonly start: number;\n readonly end: number;\n}\n\nexport interface PhysicalLine {\n readonly line: number;\n readonly range: SourceRange;\n readonly content: SourceRange;\n readonly ending: \"\" | \"\\n\" | \"\\r\" | \"\\r\\n\";\n}\n\n/** The semantic character represented by NUL in parsed source. */\nexport const REPLACEMENT_CHARACTER = \"\\uFFFD\";\n\nexport function semanticCharacter(value: string): string {\n return value === \"\\0\" ? REPLACEMENT_CHARACTER : value;\n}\n\n/** The column after a tab, with four-column tab stops. */\nexport function nextTabColumn(column: number): number {\n return column + (4 - ((column - 1) % 4));\n}\n\n/**\n * Physical lines of a text that only grows. The files of one buffer generation\n * share one index, which scans each character once instead of once per file.\n */\nclass LineIndex {\n readonly lines: PhysicalLine[] = [];\n readonly #scanner = new PhysicalLineScanner();\n #length = 0;\n\n /** Scans `text`, which extends every text scanned before, from where the last scan ended. */\n public extend(text: SourceText): void {\n if (text.length > this.#length) {\n this.lines.push(...this.#scanner.append(text.slice(this.#length)));\n this.#length = text.length;\n }\n }\n}\n\n/** A file's lines: the index's complete lines it contains, then its own last lines. */\ninterface LineTable {\n readonly complete: readonly PhysicalLine[];\n readonly count: number;\n readonly tail: readonly PhysicalLine[];\n}\n\nlet createFile: (name: string, text: SourceText, index: LineIndex) => SourceFile;\n\nlet readText: (file: SourceFile) => SourceText;\n\n/**\n * Immutable authored source with UTF-16 offsets and exact physical line\n * boundaries. Files from a `SourceBuffer` share text chunks and a line index,\n * so reading a growing document never copies it whole.\n */\nexport class SourceFile {\n #source: SourceText;\n #index: LineIndex | undefined;\n #table: LineTable | undefined;\n public readonly name: string;\n\n static {\n createFile = (name, text, index) => {\n const file = new SourceFile({ name, text: \"\" });\n file.#source = text;\n file.#index = index;\n\n return file;\n };\n\n readText = (file) => file.#source;\n }\n\n public constructor(input: string | SourceFileInput) {\n this.#source = SourceText.of(isString(input) ? input : input.text);\n this.name = isString(input) ? \"source.mdx\" : (input.name ?? \"source.mdx\");\n Object.freeze(this);\n }\n\n /** The whole text. Prefer `slice` and `length`, which do not join a growing text. */\n public get text(): string {\n return this.#source.toString();\n }\n\n public get length(): number {\n return this.#source.length;\n }\n\n /**\n * Whether `other` is known to start with this file's text: both come from\n * the same `SourceBuffer` with only appends between them.\n */\n public isPrefixOf(other: SourceFile): boolean {\n return (\n this === other ||\n (this.#index !== undefined && this.#index === other.#index && this.length <= other.length)\n );\n }\n\n public location(offset: number): SourceLocation {\n if (!Number.isInteger(offset) || offset < 0 || offset > this.length) {\n throw InputError.sourceOffsetOutsideFile(offset, this.length);\n }\n\n let low = 0;\n let high = this.lineCount;\n\n while (low + 1 < high) {\n const middle = Math.floor((low + high) / 2);\n\n if (this.physicalLine(middle).range.start <= offset) {\n low = middle;\n } else {\n high = middle;\n }\n }\n\n let column = 1;\n\n for (let index = this.physicalLine(low).range.start; index < offset; index++) {\n column = this.#source.char(index) === \"\\t\" ? nextTabColumn(column) : column + 1;\n }\n\n return Object.freeze({ offset, line: low + 1, column });\n }\n\n public lineStart(line: number): number | undefined {\n return this.line(line)?.range.start;\n }\n\n public get lineCount(): number {\n const table = this.table();\n\n return table.count + table.tail.length;\n }\n\n public line(line: number): PhysicalLine | undefined {\n return line >= 1 && line <= this.lineCount ? this.physicalLine(line - 1) : undefined;\n }\n\n public lineAt(offset: number): PhysicalLine {\n return this.physicalLine(this.location(offset).line - 1);\n }\n\n public character(offset: number): string | undefined {\n if (!Number.isSafeInteger(offset) || offset < 0 || offset > this.length) {\n throw InputError.sourceOffsetOutsideFile(offset, this.length);\n }\n\n const value = this.#source.char(offset);\n\n return value === undefined ? undefined : semanticCharacter(value);\n }\n\n public slice(range: SourceRange): string {\n if (\n !Number.isSafeInteger(range.start) ||\n !Number.isSafeInteger(range.end) ||\n range.start < 0 ||\n range.end < range.start ||\n range.end > this.length\n ) {\n throw InputError.replacementRangeOutsideSource(range.start, range.end, this.length);\n }\n\n return this.#source.slice(range.start, range.end);\n }\n\n public semanticSlice(range: SourceRange): string {\n return this.slice(range).replaceAll(\"\\0\", \"\\uFFFD\");\n }\n\n private physicalLine(index: number): PhysicalLine {\n const table = this.table();\n\n return index < table.count ? table.complete[index] : table.tail[index - table.count];\n }\n\n private table(): LineTable {\n if (this.#table !== undefined) {\n return this.#table;\n }\n\n const index = this.#index;\n\n if (index === undefined) {\n const lines = Object.freeze(indexLines(this.text));\n this.#table = { complete: lines, count: lines.length, tail: [] };\n\n return this.#table;\n }\n\n index.extend(this.#source);\n const { lines } = index;\n let count = lines.length;\n\n // An earlier file in the chain holds a prefix of the indexed text.\n while (count > 0 && lines[count - 1].range.end > this.length) {\n count--;\n }\n\n const last = lines[count - 1];\n\n const scanner = new PhysicalLineScanner({\n offset: last?.range.end ?? 0,\n line: (last?.line ?? 0) + 1,\n });\n\n const tail = Object.freeze([\n ...scanner.append(this.#source.slice(last?.range.end ?? 0)),\n ...scanner.complete(),\n ]);\n\n this.#table = { complete: lines, count, tail };\n\n return this.#table;\n }\n}\n\n/**\n * Source that a stream owns and changes. Appends keep one line index, so\n * successive files do not rescan their lines; an edit starts a new generation.\n * Each change returns an immutable `SourceFile` for that version.\n */\nexport class SourceBuffer {\n readonly #name: string;\n #index = new LineIndex();\n #text: SourceText;\n #file: SourceFile;\n\n public constructor(input: SourceFileInput) {\n this.#name = input.name ?? \"source.mdx\";\n this.#text = SourceText.of(input.text);\n this.#file = createFile(this.#name, this.#text, this.#index);\n }\n\n public get file(): SourceFile {\n return this.#file;\n }\n\n public append(text: string): SourceFile {\n this.#text = this.#text.append(text);\n this.#file = createFile(this.#name, this.#text, this.#index);\n\n return this.#file;\n }\n\n /** Replaces `start..end` with `text`. Earlier files keep their own lines. */\n public replace(start: number, end: number, text: string): SourceFile {\n const previous = this.#text;\n this.#text = SourceText.of(previous.slice(0, start) + text + previous.slice(end));\n this.#index = new LineIndex();\n this.#file = createFile(this.#name, this.#text, this.#index);\n\n return this.#file;\n }\n}\n\n/** The chunked text behind a file, for readers that index it by offset. */\nexport function sourceText(file: SourceFile): SourceText {\n return readText(file);\n}\n\nfunction indexLines(source: string): PhysicalLine[] {\n const scanner = new PhysicalLineScanner();\n\n return [...scanner.append(source), ...scanner.complete()];\n}\n\nfunction physicalLine(\n line: number,\n start: number,\n contentEnd: number,\n end: number,\n ending: PhysicalLine[\"ending\"],\n): PhysicalLine {\n return Object.freeze({\n line,\n range: sourceRange(start, end),\n content: sourceRange(start, contentEnd),\n ending,\n });\n}\n\n/** Incremental physical-line scanner. Each appended code unit is visited once. */\nexport class PhysicalLineScanner {\n #complete = false;\n #length: number;\n #line: number;\n #lineStart: number;\n #pendingCarriageReturn: number | undefined;\n\n public constructor(options: Readonly<{ offset?: number; line?: number }> = {}) {\n const offset = options.offset ?? 0;\n const line = options.line ?? 1;\n\n if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(line) || line < 1) {\n throw new RangeError(\"Invalid physical-line scanner origin\");\n }\n\n this.#length = offset;\n this.#lineStart = offset;\n this.#line = line;\n }\n\n public append(text: string): readonly PhysicalLine[] {\n if (this.#complete) {\n throw new Error(\"Cannot append to a completed physical-line scanner\");\n }\n\n const lines: PhysicalLine[] = [];\n\n const endings = /\\r\\n|[\\r\\n]/gu;\n\n if (text.length > 0 && this.#pendingCarriageReturn !== undefined) {\n const offset = this.#pendingCarriageReturn;\n\n if (text[0] === \"\\n\") {\n lines.push(this.emit(offset, this.#length + 1, \"\\r\\n\"));\n endings.lastIndex = 1;\n } else {\n lines.push(this.emit(offset, offset + 1, \"\\r\"));\n }\n\n this.#pendingCarriageReturn = undefined;\n }\n\n for (let match = endings.exec(text); match !== null; match = endings.exec(text)) {\n const offset = this.#length + match.index;\n const ending = match[0];\n\n if (ending === \"\\r\" && match.index === text.length - 1) {\n this.#pendingCarriageReturn = offset;\n } else {\n lines.push(\n this.emit(\n offset,\n offset + ending.length,\n ending === \"\\r\\n\" ? \"\\r\\n\" : ending === \"\\r\" ? \"\\r\" : \"\\n\",\n ),\n );\n }\n }\n\n this.#length += text.length;\n\n return Object.freeze(lines);\n }\n\n public clone(): PhysicalLineScanner {\n const copy = new PhysicalLineScanner({ offset: this.#length, line: this.#line });\n copy.#complete = this.#complete;\n copy.#lineStart = this.#lineStart;\n copy.#pendingCarriageReturn = this.#pendingCarriageReturn;\n\n return copy;\n }\n\n public complete(): readonly PhysicalLine[] {\n if (this.#complete) {\n throw new Error(\"Physical-line scanner is already complete\");\n }\n\n this.#complete = true;\n const lines: PhysicalLine[] = [];\n\n if (this.#pendingCarriageReturn !== undefined) {\n lines.push(this.emit(this.#pendingCarriageReturn, this.#pendingCarriageReturn + 1, \"\\r\"));\n this.#pendingCarriageReturn = undefined;\n }\n\n lines.push(physicalLine(this.#line, this.#lineStart, this.#length, this.#length, \"\"));\n\n return Object.freeze(lines);\n }\n\n private emit(\n contentEnd: number,\n end: number,\n ending: Exclude<PhysicalLine[\"ending\"], \"\">,\n ): PhysicalLine {\n const line = physicalLine(this.#line++, this.#lineStart, contentEnd, end, ending);\n this.#lineStart = end;\n\n return line;\n }\n}\n"],"mappings":";;;;;;AAkCA,MAAa,wBAAwB;AAErC,SAAgB,kBAAkB,OAAuB;CACvD,OAAO,UAAU,OAAA,MAA+B;AAClD;;AAGA,SAAgB,cAAc,QAAwB;CACpD,OAAO,UAAU,KAAM,SAAS,KAAK;AACvC;;;;;AAMA,IAAM,YAAN,MAAgB;CACd,QAAiC,CAAC;CAClC,WAAoB,IAAI,oBAAoB;CAC5C,UAAU;;CAGV,OAAc,MAAwB;EACpC,IAAI,KAAK,SAAS,KAAK,SAAS;GAC9B,KAAK,MAAM,KAAK,GAAG,KAAK,SAAS,OAAO,KAAK,MAAM,KAAK,OAAO,CAAC,CAAC;GACjE,KAAK,UAAU,KAAK;EACtB;CACF;AACF;AASA,IAAI;AAEJ,IAAI;;;;;;AAOJ,IAAa,aAAb,MAAa,WAAW;CACtB;CACA;CACA;CACA;CAEA;EACE,cAAc,MAAM,MAAM,UAAU;GAClC,MAAM,OAAO,IAAI,WAAW;IAAE;IAAM,MAAM;GAAG,CAAC;GAC9C,KAAK,UAAU;GACf,KAAK,SAAS;GAEd,OAAO;EACT;EAEA,YAAY,SAAS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U,KAAK,SAAS,GACnD,KAAK,yBAAyB;QAE9B,MAAM,KACJ,KAAK,KACH,QACA,SAAS,OAAO,QAChB,WAAW,SAAS,SAAS,WAAW,OAAO,OAAO,IACxD,CACF;EAEJ;EAEA,KAAK,WAAW,KAAK;EAErB,OAAO,OAAO,OAAO,KAAK;CAC5B;CAEA,QAAoC;EAClC,MAAM,OAAO,IAAI,oBAAoB;GAAE,QAAQ,KAAK;GAAS,MAAM,KAAK;EAAM,CAAC;EAC/E,KAAK,YAAY,KAAK;EACtB,KAAK,aAAa,KAAK;EACvB,KAAK,yBAAyB,KAAK;EAEnC,OAAO;CACT;CAEA,WAA2C;EACzC,IAAI,KAAK,WACP,MAAM,IAAI,MAAM,2CAA2C;EAG7D,KAAK,YAAY;EACjB,MAAM,QAAwB,CAAC;EAE/B,IAAI,KAAK,2BAA2B,KAAA,GAAW;GAC7C,MAAM,KAAK,KAAK,KAAK,KAAK,wBAAwB,KAAK,yBAAyB,GAAG,IAAI,CAAC;GACxF,KAAK,yBAAyB,KAAA;EAChC;EAEA,MAAM,KAAK,aAAa,KAAK,OAAO,KAAK,YAAY,KAAK,SAAS,KAAK,SAAS,EAAE,CAAC;EAEpF,OAAO,OAAO,OAAO,KAAK;CAC5B;CAEA,KACE,YACA,KACA,QACc;EACd,MAAM,OAAO,aAAa,KAAK,SAAS,KAAK,YAAY,YAAY,KAAK,MAAM;EAChF,KAAK,aAAa;EAElB,OAAO;CACT;AACF"}
@@ -0,0 +1,59 @@
1
+ import { HtmlFootnoteSectionNode, HtmlRootNode } from "./html.mjs";
2
+ import { DiagnosticSeverity } from "./diagnostics.mjs";
3
+ import { ParserLimit } from "./parser/config.mjs";
4
+ import { CompletedBlock, MdxPreview, MdxStreamChange, MdxStreamCompletion, MdxStreamOptions, PreviewBlock } from "./stream-types.mjs";
5
+ //#region src/stream-events.d.ts
6
+ /** The preview as one HTML tree, joined like a lowered document. */
7
+ export declare function previewDocument(preview: MdxPreview): HtmlRootNode;
8
+ /** A diagnostic without its source file, so it can cross a network boundary. */
9
+ export interface MdxEventDiagnostic {
10
+ readonly severity: DiagnosticSeverity;
11
+ readonly code: string;
12
+ readonly message: string;
13
+ readonly start?: number;
14
+ readonly end?: number;
15
+ }
16
+ /**
17
+ * A JSON-serializable stream update. A server runs the stream and sends events;
18
+ * a client applies them with `applyBlockEvent` and renders without parsing.
19
+ */
20
+ export type MdxBlockEvent = Readonly<{
21
+ kind: "update";
22
+ /** Blocks before this index stay, except `refreshed`; `blocks` replaces the rest. */
23
+ start: number;
24
+ blocks: readonly PreviewBlock[];
25
+ refreshed: readonly PreviewBlock[];
26
+ /** Present when the section changed; `null` removes it. */
27
+ footnotes?: HtmlFootnoteSectionNode | null;
28
+ limit?: ParserLimit;
29
+ }> | Readonly<{
30
+ kind: "complete";
31
+ html: HtmlRootNode;
32
+ blocks: readonly CompletedBlock[];
33
+ }> | Readonly<{
34
+ kind: "failed";
35
+ diagnostics: readonly MdxEventDiagnostic[];
36
+ }>;
37
+ /** The update event for one stream change. */
38
+ export declare function blockEvent(change: MdxStreamChange): Extract<MdxBlockEvent, {
39
+ kind: "update";
40
+ }>;
41
+ /** The final event for a completion; `html` is the completed document's lowered HTML. */
42
+ export declare function completionEvent(completion: MdxStreamCompletion, html?: HtmlRootNode): MdxBlockEvent;
43
+ /** Applies an update event to the preview a client holds. */
44
+ export declare function applyBlockEvent(preview: MdxPreview, event: Extract<MdxBlockEvent, {
45
+ kind: "update";
46
+ }>): MdxPreview;
47
+ export interface StreamBlockEventsOptions extends MdxStreamOptions {
48
+ /** Lowers the completed document, for example through a `Processor` with HTML plugins. */
49
+ readonly html?: (completion: MdxStreamCompletion) => HtmlRootNode;
50
+ }
51
+ /**
52
+ * Streams text through an `MdxStream`.
53
+ * A server forwards the events to a client as JSON.
54
+ *
55
+ * @yields One update event per chunk, then a completion event.
56
+ */
57
+ export declare function streamBlockEvents(chunks: AsyncIterable<string>, options?: StreamBlockEventsOptions): AsyncGenerator<MdxBlockEvent>;
58
+ //#endregion
59
+ //# sourceMappingURL=stream-events.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-events.d.mts","names":[],"sources":["../src/stream-events.ts"],"mappings":";;;;;;wBAiBgB,gBAAgB,SAAS,aAAa;;iBAWrC;WACN,UAAU;WACV;WACA;WACA;WACA;;;;;;YAOC,gBACR;EACE;;EAEA;EACA,iBAAiB;EACjB,oBAAoB;;EAEpB,YAAY;EACZ,QAAQ;KAEV;EAAW;EAAkB,MAAM;EAAc,iBAAiB;KAClE;EAAW;EAAgB,sBAAsB;;;wBAGrC,WAAW,QAAQ,kBAAkB,QAAQ;EAAiB;;;wBAsB9D,gBACd,YAAY,qBACZ,OAAO,eACN;;wBASa,gBACd,SAAS,YACT,OAAO,QAAQ;EAAiB;KAC/B;iBAcc,iCAAiC;;WAEvC,QAAQ,YAAY,wBAAwB;;;;;;;;wBAShC,kBACrB,QAAQ,uBACR,UAAS,2BACR,eAAe"}
@@ -0,0 +1,115 @@
1
+ import { LimitError, ParseError } from "./errors.mjs";
2
+ import { joinBlocks, lowerHtml } from "./html-lower.mjs";
3
+ import { MdxStream } from "./stream.mjs";
4
+ //#region src/stream-events.ts
5
+ /** The preview as one HTML tree, joined like a lowered document. */
6
+ function previewDocument(preview) {
7
+ const children = preview.blocks.flatMap((block) => block.nodes);
8
+ if (preview.footnotes !== void 0) children.push(preview.footnotes);
9
+ return {
10
+ kind: "root",
11
+ children: joinBlocks(children)
12
+ };
13
+ }
14
+ /** The update event for one stream change. */
15
+ function blockEvent(change) {
16
+ const { snapshot } = change;
17
+ let event = {
18
+ kind: "update",
19
+ start: change.start,
20
+ blocks: snapshot.blocks.slice(change.start).map(previewBlock),
21
+ refreshed: change.refreshed.map(previewBlock)
22
+ };
23
+ if (change.footnotesChanged) event = {
24
+ ...event,
25
+ footnotes: snapshot.footnotes ?? null
26
+ };
27
+ if (snapshot.limit !== void 0) event = {
28
+ ...event,
29
+ limit: snapshot.limit
30
+ };
31
+ return event;
32
+ }
33
+ /** The final event for a completion; `html` is the completed document's lowered HTML. */
34
+ function completionEvent(completion, html) {
35
+ return {
36
+ kind: "complete",
37
+ html: html ?? lowerHtml(completion.document, { source: completion.file }),
38
+ blocks: completion.blocks
39
+ };
40
+ }
41
+ /** Applies an update event to the preview a client holds. */
42
+ function applyBlockEvent(preview, event) {
43
+ let kept = preview.blocks.slice(0, event.start);
44
+ if (event.refreshed.length > 0) {
45
+ const refreshed = new Map(event.refreshed.map((block) => [block.id, block]));
46
+ kept = kept.map((block) => refreshed.get(block.id) ?? block);
47
+ }
48
+ return Object.freeze({
49
+ blocks: Object.freeze([...kept, ...event.blocks]),
50
+ footnotes: event.footnotes === void 0 ? preview.footnotes : event.footnotes ?? void 0
51
+ });
52
+ }
53
+ /**
54
+ * Streams text through an `MdxStream`.
55
+ * A server forwards the events to a client as JSON.
56
+ *
57
+ * @yields One update event per chunk, then a completion event.
58
+ */
59
+ async function* streamBlockEvents(chunks, options = {}) {
60
+ const stream = new MdxStream(options);
61
+ const changes = [];
62
+ const unsubscribe = stream.subscribe((change) => changes.push(change));
63
+ try {
64
+ const initial = stream.snapshot();
65
+ if (initial.kind === "preview" && initial.file.length > 0) yield blockEvent({
66
+ snapshot: initial,
67
+ start: 0,
68
+ refreshed: [],
69
+ footnotesChanged: true
70
+ });
71
+ for await (const chunk of chunks) {
72
+ stream.append(chunk);
73
+ for (const change of changes.splice(0)) yield blockEvent(change);
74
+ }
75
+ } finally {
76
+ unsubscribe();
77
+ }
78
+ let completion;
79
+ try {
80
+ completion = stream.complete();
81
+ } catch (error) {
82
+ if (!(error instanceof ParseError) && !(error instanceof LimitError)) throw error;
83
+ yield {
84
+ kind: "failed",
85
+ diagnostics: error.diagnostics.map(eventDiagnostic)
86
+ };
87
+ return;
88
+ }
89
+ yield completionEvent(completion, options.html?.(completion));
90
+ }
91
+ function eventDiagnostic(diagnostic) {
92
+ const message = {
93
+ severity: diagnostic.severity,
94
+ code: diagnostic.code,
95
+ message: diagnostic.message
96
+ };
97
+ return diagnostic.span === void 0 ? message : {
98
+ ...message,
99
+ start: diagnostic.span.start,
100
+ end: diagnostic.span.end
101
+ };
102
+ }
103
+ function previewBlock(block) {
104
+ return {
105
+ id: block.id,
106
+ origin: block.origin,
107
+ nodes: block.nodes,
108
+ status: block.status,
109
+ settled: block.settled
110
+ };
111
+ }
112
+ //#endregion
113
+ export { applyBlockEvent, blockEvent, completionEvent, previewDocument, streamBlockEvents };
114
+
115
+ //# sourceMappingURL=stream-events.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-events.mjs","names":[],"sources":["../src/stream-events.ts"],"sourcesContent":["import type { Diagnostic, DiagnosticSeverity } from \"./diagnostics.ts\";\nimport type { HtmlFootnoteSectionNode, HtmlRootNode } from \"./html.ts\";\nimport type { ParserLimit } from \"./parser/config.ts\";\nimport type {\n CompletedBlock,\n MdxPreview,\n MdxStreamChange,\n MdxStreamCompletion,\n MdxStreamOptions,\n PreviewBlock,\n} from \"./stream-types.ts\";\n\nimport { LimitError, ParseError } from \"./errors.ts\";\nimport { joinBlocks, lowerHtml } from \"./html-lower.ts\";\nimport { MdxStream } from \"./stream.ts\";\n\n/** The preview as one HTML tree, joined like a lowered document. */\nexport function previewDocument(preview: MdxPreview): HtmlRootNode {\n const children = preview.blocks.flatMap((block) => block.nodes);\n\n if (preview.footnotes !== undefined) {\n children.push(preview.footnotes);\n }\n\n return { kind: \"root\", children: joinBlocks(children) };\n}\n\n/** A diagnostic without its source file, so it can cross a network boundary. */\nexport interface MdxEventDiagnostic {\n readonly severity: DiagnosticSeverity;\n readonly code: string;\n readonly message: string;\n readonly start?: number;\n readonly end?: number;\n}\n\n/**\n * A JSON-serializable stream update. A server runs the stream and sends events;\n * a client applies them with `applyBlockEvent` and renders without parsing.\n */\nexport type MdxBlockEvent =\n | Readonly<{\n kind: \"update\";\n /** Blocks before this index stay, except `refreshed`; `blocks` replaces the rest. */\n start: number;\n blocks: readonly PreviewBlock[];\n refreshed: readonly PreviewBlock[];\n /** Present when the section changed; `null` removes it. */\n footnotes?: HtmlFootnoteSectionNode | null;\n limit?: ParserLimit;\n }>\n | Readonly<{ kind: \"complete\"; html: HtmlRootNode; blocks: readonly CompletedBlock[] }>\n | Readonly<{ kind: \"failed\"; diagnostics: readonly MdxEventDiagnostic[] }>;\n\n/** The update event for one stream change. */\nexport function blockEvent(change: MdxStreamChange): Extract<MdxBlockEvent, { kind: \"update\" }> {\n const { snapshot } = change;\n\n let event: Extract<MdxBlockEvent, { kind: \"update\" }> = {\n kind: \"update\",\n start: change.start,\n blocks: snapshot.blocks.slice(change.start).map(previewBlock),\n refreshed: change.refreshed.map(previewBlock),\n };\n\n if (change.footnotesChanged) {\n event = { ...event, footnotes: snapshot.footnotes ?? null };\n }\n\n if (snapshot.limit !== undefined) {\n event = { ...event, limit: snapshot.limit };\n }\n\n return event;\n}\n\n/** The final event for a completion; `html` is the completed document's lowered HTML. */\nexport function completionEvent(\n completion: MdxStreamCompletion,\n html?: HtmlRootNode,\n): MdxBlockEvent {\n return {\n kind: \"complete\",\n html: html ?? lowerHtml(completion.document, { source: completion.file }),\n blocks: completion.blocks,\n };\n}\n\n/** Applies an update event to the preview a client holds. */\nexport function applyBlockEvent(\n preview: MdxPreview,\n event: Extract<MdxBlockEvent, { kind: \"update\" }>,\n): MdxPreview {\n let kept = preview.blocks.slice(0, event.start);\n\n if (event.refreshed.length > 0) {\n const refreshed = new Map(event.refreshed.map((block) => [block.id, block]));\n kept = kept.map((block) => refreshed.get(block.id) ?? block);\n }\n\n return Object.freeze({\n blocks: Object.freeze([...kept, ...event.blocks]),\n footnotes: event.footnotes === undefined ? preview.footnotes : (event.footnotes ?? undefined),\n });\n}\n\nexport interface StreamBlockEventsOptions extends MdxStreamOptions {\n /** Lowers the completed document, for example through a `Processor` with HTML plugins. */\n readonly html?: (completion: MdxStreamCompletion) => HtmlRootNode;\n}\n\n/**\n * Streams text through an `MdxStream`.\n * A server forwards the events to a client as JSON.\n *\n * @yields One update event per chunk, then a completion event.\n */\nexport async function* streamBlockEvents(\n chunks: AsyncIterable<string>,\n options: StreamBlockEventsOptions = {},\n): AsyncGenerator<MdxBlockEvent> {\n const stream = new MdxStream(options);\n const changes: MdxStreamChange[] = [];\n const unsubscribe = stream.subscribe((change) => changes.push(change));\n\n try {\n const initial = stream.snapshot();\n\n if (initial.kind === \"preview\" && initial.file.length > 0) {\n yield blockEvent({\n snapshot: initial,\n start: 0,\n refreshed: [],\n footnotesChanged: true,\n });\n }\n\n for await (const chunk of chunks) {\n stream.append(chunk);\n\n for (const change of changes.splice(0)) {\n yield blockEvent(change);\n }\n }\n } finally {\n unsubscribe();\n }\n\n let completion: MdxStreamCompletion;\n\n try {\n completion = stream.complete();\n } catch (error) {\n if (!(error instanceof ParseError) && !(error instanceof LimitError)) {\n throw error;\n }\n\n yield { kind: \"failed\", diagnostics: error.diagnostics.map(eventDiagnostic) };\n\n return;\n }\n\n yield completionEvent(completion, options.html?.(completion));\n}\n\nfunction eventDiagnostic(diagnostic: Diagnostic): MdxEventDiagnostic {\n const message = {\n severity: diagnostic.severity,\n code: diagnostic.code,\n message: diagnostic.message,\n };\n\n return diagnostic.span === undefined\n ? message\n : { ...message, start: diagnostic.span.start, end: diagnostic.span.end };\n}\n\nfunction previewBlock(block: PreviewBlock): PreviewBlock {\n return {\n id: block.id,\n origin: block.origin,\n nodes: block.nodes,\n status: block.status,\n settled: block.settled,\n };\n}\n"],"mappings":";;;;;AAiBA,SAAgB,gBAAgB,SAAmC;CACjE,MAAM,WAAW,QAAQ,OAAO,SAAS,UAAU,MAAM,KAAK;CAE9D,IAAI,QAAQ,cAAc,KAAA,GACxB,SAAS,KAAK,QAAQ,SAAS;CAGjC,OAAO;EAAE,MAAM;EAAQ,UAAU,WAAW,QAAQ;CAAE;AACxD;;AA8BA,SAAgB,WAAW,QAAqE;CAC9F,MAAM,EAAE,aAAa;CAErB,IAAI,QAAoD;EACtD,MAAM;EACN,OAAO,OAAO;EACd,QAAQ,SA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;EAGH,WAAW,MAAM,SAAS,QAAQ;GAChC,OAAO,OAAO,KAAK;GAEnB,KAAK,MAAM,UAAU,QAAQ,OAAO,CAAC,GACnC,MAAM,WAAW,MAAM;EAE3B;CACF,UAAU;EACR,YAAY;CACd;CAEA,IAAI;CAEJ,IAAI;EACF,aAAa,OAAO,SAAS;CAC/B,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,eAAe,EAAE,iBAAiB,aACvD,MAAM;EAGR,MAAM;GAAE,MAAM;GAAU,aAAa,MAAM,YAAY,IAAI,eAAe;EAAE;EAE5E;CACF;CAEA,MAAM,gBAAgB,YAAY,QAAQ,OAAO,UAAU,CAAC;AAC9D;AAEA,SAAS,gBAAgB,YAA4C;CACnE,MAAM,UAAU;EACd,UAAU,WAAW;EACrB,MAAM,WAAW;EACjB,SAAS,WAAW;CACtB;CAEA,OAAO,WAAW,SAAS,KAAA,IACvB,UACA;EAAE,GAAG;EAAS,OAAO,WAAW,KAAK;EAAO,KAAK,WAAW,KAAK;CAAI;AAC3E;AAEA,SAAS,aAAa,OAAmC;CACvD,OAAO;EACL,IAAI,MAAM;EACV,QAAQ,MAAM;EACd,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,SAAS,MAAM;CACjB;AACF"}
@@ -0,0 +1,79 @@
1
+ import { SyntaxOptions } from "./syntax-options.mjs";
2
+ import { ResolvedParserLimits } from "./parser/config.mjs";
3
+ import { MdxEdit, MdxStreamChange, MdxStreamCompletion } from "./stream-types.mjs";
4
+ //#region src/stream-session.d.ts
5
+ export interface StreamSessionOptions {
6
+ readonly name: string;
7
+ readonly source: string;
8
+ readonly syntax: SyntaxOptions | undefined;
9
+ readonly limits: ResolvedParserLimits;
10
+ readonly maximumPendingBlockLength: number;
11
+ }
12
+ /**
13
+ * Owns the parser and the rendered blocks of one stream. A top-level block
14
+ * settles once later input cannot change it, and then materializes and lowers
15
+ * once. Each append renders only the open tail; a settled block renders again
16
+ * only when a definition or footnote number it uses changes.
17
+ */
18
+ export declare class StreamSession {
19
+ #private;
20
+ constructor(options: StreamSessionOptions);
21
+ /** The latest change, whose snapshot is the current preview. */
22
+ get current(): MdxStreamChange;
23
+ append(text: string): MdxStreamChange;
24
+ edit(edit: MdxEdit): MdxStreamChange;
25
+ /**
26
+ * Finishes the tail strictly and assembles the document from the settled
27
+ * blocks' nodes, so only the tail materializes again.
28
+ */
29
+ complete(): MdxStreamCompletion;
30
+ /**
31
+ * Settles queued blocks, renders the blocks whose definitions or footnote
32
+ * numbers changed, renders the open tail, and assembles the snapshot.
33
+ */
34
+ private update;
35
+ /**
36
+ * Drops settled blocks that an edit replaced, which settle again from the
37
+ * queue, and returns how many settled blocks remain.
38
+ */
39
+ private dropChangedSettled;
40
+ /** Settles queued parser output and returns the indexes of blocks adopted from the tail. */
41
+ private settleQueued;
42
+ /**
43
+ * Renders newly settled blocks, and settled blocks whose definitions or
44
+ * footnote numbers changed. Returns the re-rendered blocks before `start`.
45
+ */
46
+ private refreshSettled;
47
+ /** Adopts the tail's rendering for a block that settled unchanged, or queues it to render. */
48
+ private settle;
49
+ private materializeTail;
50
+ private materialize;
51
+ /** Adds one settled block to the running totals. Its rendering may still be pending. */
52
+ private addSettled;
53
+ /** Drops the settled blocks from `length` on, after an edit before them. */
54
+ private truncate;
55
+ /**
56
+ * Numbers footnote references in settled blocks from `from` on, continuing
57
+ * the numbering before them, and returns the blocks whose numbers changed.
58
+ */
59
+ private renumber;
60
+ private renderTail;
61
+ /** Lowers one block in the stream's scope. */
62
+ private render;
63
+ private isFootnoteDefined;
64
+ private effectiveDefinitions;
65
+ /** The footnote section, rebuilt only when its numbering or definitions change. */
66
+ private footnoteSection;
67
+ /** The first limit the stream exceeds, if any. */
68
+ private limitState;
69
+ /** Keeps the last preview within limits, with its block identities. */
70
+ private limitChange;
71
+ private limitError;
72
+ /** A block keeps its identity across appends, and across edits that do not touch it. */
73
+ private blockId;
74
+ /** Identities of blocks an edit does not touch, keyed by their range after the edit. */
75
+ private retiredIds;
76
+ private newId;
77
+ }
78
+ //#endregion
79
+ //# sourceMappingURL=stream-session.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-session.d.mts","names":[],"sources":["../src/stream-session.ts"],"mappings":";;;;iBA6CiB;WACN;WACA;WACA,QAAQ;WACR,QAAQ;WACR;;;;;;;;qBA0EE;;EA6CX,YAAmB,SAAS;;MAgBjB,WAAW;EAIf,OAAO,eAAe;EAUtB,KAAK,MAAM,UAAU;;;;;EAarB,YAAY;;;;;UA4FX;;;;;UAiFA;;UAeA;;;;;UA6BA;;UAoIA;UA2BA;UAgBA;;UAuDA;;UA2CA;;;;;UA2BA;UA2BA;;UA6DA;UA2FA;UAMA;;UAgBA;;UAgCA;;UA4CA;UAoBA;;UAgBA;;UAaA;UAgBA"}