@temelj/mdx 0.14.0 → 0.15.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 (373) hide show
  1. package/README.md +468 -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 +185 -418
  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.d.mts +15 -0
  75. package/dist/frontmatter.d.mts.map +1 -0
  76. package/dist/frontmatter.mjs +187 -0
  77. package/dist/frontmatter.mjs.map +1 -0
  78. package/dist/heading.d.mts +6 -0
  79. package/dist/heading.d.mts.map +1 -0
  80. package/dist/heading.mjs +19 -0
  81. package/dist/heading.mjs.map +1 -0
  82. package/dist/html-format.d.mts +32 -0
  83. package/dist/html-format.d.mts.map +1 -0
  84. package/dist/html-format.mjs +127 -0
  85. package/dist/html-format.mjs.map +1 -0
  86. package/dist/html-lower.d.mts +78 -0
  87. package/dist/html-lower.d.mts.map +1 -0
  88. package/dist/html-lower.mjs +583 -0
  89. package/dist/html-lower.mjs.map +1 -0
  90. package/dist/html-stream.d.mts +13 -0
  91. package/dist/html-stream.d.mts.map +1 -0
  92. package/dist/html-stream.mjs +32 -0
  93. package/dist/html-stream.mjs.map +1 -0
  94. package/dist/html.d.mts +120 -0
  95. package/dist/html.d.mts.map +1 -0
  96. package/dist/html.mjs +77 -0
  97. package/dist/html.mjs.map +1 -0
  98. package/dist/identifier.d.mts +4 -0
  99. package/dist/identifier.d.mts.map +1 -0
  100. package/dist/identifier.mjs +8 -0
  101. package/dist/identifier.mjs.map +1 -0
  102. package/dist/javascript-ast.d.mts +16 -0
  103. package/dist/javascript-ast.d.mts.map +1 -0
  104. package/dist/javascript-ast.mjs +39 -0
  105. package/dist/javascript-ast.mjs.map +1 -0
  106. package/dist/javascript-jsx.d.mts +24 -0
  107. package/dist/javascript-jsx.d.mts.map +1 -0
  108. package/dist/javascript-jsx.mjs +189 -0
  109. package/dist/javascript-jsx.mjs.map +1 -0
  110. package/dist/javascript.d.mts +9 -0
  111. package/dist/javascript.d.mts.map +1 -0
  112. package/dist/javascript.mjs +31 -0
  113. package/dist/javascript.mjs.map +1 -0
  114. package/dist/jsx-reference.d.mts +15 -0
  115. package/dist/jsx-reference.d.mts.map +1 -0
  116. package/dist/jsx-reference.mjs +31 -0
  117. package/dist/jsx-reference.mjs.map +1 -0
  118. package/dist/mod.d.mts +25 -9
  119. package/dist/mod.mjs +19 -8
  120. package/dist/model.d.mts +196 -0
  121. package/dist/model.d.mts.map +1 -0
  122. package/dist/model.mjs +113 -0
  123. package/dist/model.mjs.map +1 -0
  124. package/dist/parser/block-container-recognizers.d.mts +40 -0
  125. package/dist/parser/block-container-recognizers.d.mts.map +1 -0
  126. package/dist/parser/block-container-recognizers.mjs +90 -0
  127. package/dist/parser/block-container-recognizers.mjs.map +1 -0
  128. package/dist/parser/block-directive-recognizers.d.mts +22 -0
  129. package/dist/parser/block-directive-recognizers.d.mts.map +1 -0
  130. package/dist/parser/block-directive-recognizers.mjs +77 -0
  131. package/dist/parser/block-directive-recognizers.mjs.map +1 -0
  132. package/dist/parser/block-leaf-recognizers.d.mts +53 -0
  133. package/dist/parser/block-leaf-recognizers.d.mts.map +1 -0
  134. package/dist/parser/block-leaf-recognizers.mjs +386 -0
  135. package/dist/parser/block-leaf-recognizers.mjs.map +1 -0
  136. package/dist/parser/block-parser.d.mts +38 -0
  137. package/dist/parser/block-parser.d.mts.map +1 -0
  138. package/dist/parser/block-parser.mjs +895 -0
  139. package/dist/parser/block-parser.mjs.map +1 -0
  140. package/dist/parser/block-syntax.d.mts +240 -0
  141. package/dist/parser/block-syntax.d.mts.map +1 -0
  142. package/dist/parser/characters.d.mts +19 -0
  143. package/dist/parser/characters.d.mts.map +1 -0
  144. package/dist/parser/characters.mjs +52 -0
  145. package/dist/parser/characters.mjs.map +1 -0
  146. package/dist/parser/config.d.mts +16 -0
  147. package/dist/parser/config.d.mts.map +1 -0
  148. package/dist/parser/config.mjs +25 -0
  149. package/dist/parser/config.mjs.map +1 -0
  150. package/dist/parser/directive-attributes.d.mts +9 -0
  151. package/dist/parser/directive-attributes.d.mts.map +1 -0
  152. package/dist/parser/directive-attributes.mjs +24 -0
  153. package/dist/parser/directive-attributes.mjs.map +1 -0
  154. package/dist/parser/embedded-scanner.d.mts +18 -0
  155. package/dist/parser/embedded-scanner.d.mts.map +1 -0
  156. package/dist/parser/embedded-scanner.mjs +199 -0
  157. package/dist/parser/embedded-scanner.mjs.map +1 -0
  158. package/dist/parser/inline-autolink.d.mts +7 -0
  159. package/dist/parser/inline-autolink.d.mts.map +1 -0
  160. package/dist/parser/inline-autolink.mjs +42 -0
  161. package/dist/parser/inline-autolink.mjs.map +1 -0
  162. package/dist/parser/inline-character-reference.d.mts +7 -0
  163. package/dist/parser/inline-character-reference.d.mts.map +1 -0
  164. package/dist/parser/inline-character-reference.mjs +22 -0
  165. package/dist/parser/inline-character-reference.mjs.map +1 -0
  166. package/dist/parser/inline-code.d.mts +7 -0
  167. package/dist/parser/inline-code.d.mts.map +1 -0
  168. package/dist/parser/inline-code.mjs +29 -0
  169. package/dist/parser/inline-code.mjs.map +1 -0
  170. package/dist/parser/inline-directive.d.mts +9 -0
  171. package/dist/parser/inline-directive.d.mts.map +1 -0
  172. package/dist/parser/inline-directive.mjs +45 -0
  173. package/dist/parser/inline-directive.mjs.map +1 -0
  174. package/dist/parser/inline-embedded.d.mts +19 -0
  175. package/dist/parser/inline-embedded.d.mts.map +1 -0
  176. package/dist/parser/inline-embedded.mjs +92 -0
  177. package/dist/parser/inline-embedded.mjs.map +1 -0
  178. package/dist/parser/inline-emphasis.d.mts +11 -0
  179. package/dist/parser/inline-emphasis.d.mts.map +1 -0
  180. package/dist/parser/inline-emphasis.mjs +79 -0
  181. package/dist/parser/inline-emphasis.mjs.map +1 -0
  182. package/dist/parser/inline-input.d.mts +46 -0
  183. package/dist/parser/inline-input.d.mts.map +1 -0
  184. package/dist/parser/inline-input.mjs +137 -0
  185. package/dist/parser/inline-input.mjs.map +1 -0
  186. package/dist/parser/inline-link.d.mts +12 -0
  187. package/dist/parser/inline-link.d.mts.map +1 -0
  188. package/dist/parser/inline-link.mjs +187 -0
  189. package/dist/parser/inline-link.mjs.map +1 -0
  190. package/dist/parser/inline-math.d.mts +10 -0
  191. package/dist/parser/inline-math.d.mts.map +1 -0
  192. package/dist/parser/inline-math.mjs +46 -0
  193. package/dist/parser/inline-math.mjs.map +1 -0
  194. package/dist/parser/inline-output.d.mts +34 -0
  195. package/dist/parser/inline-output.d.mts.map +1 -0
  196. package/dist/parser/inline-output.mjs +62 -0
  197. package/dist/parser/inline-output.mjs.map +1 -0
  198. package/dist/parser/inline-parser.d.mts +14 -0
  199. package/dist/parser/inline-parser.d.mts.map +1 -0
  200. package/dist/parser/inline-parser.mjs +328 -0
  201. package/dist/parser/inline-parser.mjs.map +1 -0
  202. package/dist/parser/inline-pending.d.mts +23 -0
  203. package/dist/parser/inline-pending.d.mts.map +1 -0
  204. package/dist/parser/inline-pending.mjs +100 -0
  205. package/dist/parser/inline-pending.mjs.map +1 -0
  206. package/dist/parser/inline-syntax.d.mts +118 -0
  207. package/dist/parser/inline-syntax.d.mts.map +1 -0
  208. package/dist/parser/inline-syntax.mjs +1 -0
  209. package/dist/parser/javascript-boundary.d.mts +16 -0
  210. package/dist/parser/javascript-boundary.d.mts.map +1 -0
  211. package/dist/parser/javascript-boundary.mjs +42 -0
  212. package/dist/parser/javascript-boundary.mjs.map +1 -0
  213. package/dist/parser/javascript-scanner.d.mts +22 -0
  214. package/dist/parser/javascript-scanner.d.mts.map +1 -0
  215. package/dist/parser/javascript-scanner.mjs +122 -0
  216. package/dist/parser/javascript-scanner.mjs.map +1 -0
  217. package/dist/parser/materialize-cache.d.mts +34 -0
  218. package/dist/parser/materialize-cache.d.mts.map +1 -0
  219. package/dist/parser/materialize-cache.mjs +12 -0
  220. package/dist/parser/materialize-cache.mjs.map +1 -0
  221. package/dist/parser/materialize-jsx.d.mts +14 -0
  222. package/dist/parser/materialize-jsx.d.mts.map +1 -0
  223. package/dist/parser/materialize-jsx.mjs +76 -0
  224. package/dist/parser/materialize-jsx.mjs.map +1 -0
  225. package/dist/parser/materialize.d.mts +61 -0
  226. package/dist/parser/materialize.d.mts.map +1 -0
  227. package/dist/parser/materialize.mjs +736 -0
  228. package/dist/parser/materialize.mjs.map +1 -0
  229. package/dist/parser/recognizer.d.mts +20 -0
  230. package/dist/parser/recognizer.d.mts.map +1 -0
  231. package/dist/parser/recognizer.mjs +24 -0
  232. package/dist/parser/recognizer.mjs.map +1 -0
  233. package/dist/parser/session.d.mts +42 -0
  234. package/dist/parser/session.d.mts.map +1 -0
  235. package/dist/parser/session.mjs +89 -0
  236. package/dist/parser/session.mjs.map +1 -0
  237. package/dist/parser.d.mts +25 -0
  238. package/dist/parser.d.mts.map +1 -0
  239. package/dist/parser.mjs +37 -0
  240. package/dist/parser.mjs.map +1 -0
  241. package/dist/plugin-internal.d.mts +25 -0
  242. package/dist/plugin-internal.d.mts.map +1 -0
  243. package/dist/plugin-internal.mjs +99 -0
  244. package/dist/plugin-internal.mjs.map +1 -0
  245. package/dist/plugin.d.mts +37 -0
  246. package/dist/plugin.d.mts.map +1 -0
  247. package/dist/plugin.mjs +1 -0
  248. package/dist/plugins/code-block-metadata.d.mts +42 -0
  249. package/dist/plugins/code-block-metadata.d.mts.map +1 -0
  250. package/dist/plugins/code-block-metadata.mjs +133 -0
  251. package/dist/plugins/code-block-metadata.mjs.map +1 -0
  252. package/dist/plugins/heading-id.d.mts +15 -0
  253. package/dist/plugins/heading-id.d.mts.map +1 -0
  254. package/dist/plugins/heading-id.mjs +45 -0
  255. package/dist/plugins/heading-id.mjs.map +1 -0
  256. package/dist/plugins/lower-heading.d.mts +16 -0
  257. package/dist/plugins/lower-heading.d.mts.map +1 -0
  258. package/dist/plugins/lower-heading.mjs +28 -0
  259. package/dist/plugins/lower-heading.mjs.map +1 -0
  260. package/dist/plugins/math-render.d.mts +26 -0
  261. package/dist/plugins/math-render.d.mts.map +1 -0
  262. package/dist/plugins/math-render.mjs +51 -0
  263. package/dist/plugins/math-render.mjs.map +1 -0
  264. package/dist/plugins/mod.d.mts +9 -6
  265. package/dist/plugins/mod.mjs +8 -6
  266. package/dist/plugins/remove-esm.d.mts +10 -0
  267. package/dist/plugins/remove-esm.d.mts.map +1 -0
  268. package/dist/plugins/remove-esm.mjs +12 -0
  269. package/dist/plugins/remove-esm.mjs.map +1 -0
  270. package/dist/plugins/shiki.d.mts +21 -0
  271. package/dist/plugins/shiki.d.mts.map +1 -0
  272. package/dist/plugins/shiki.mjs +144 -0
  273. package/dist/plugins/shiki.mjs.map +1 -0
  274. package/dist/plugins/syntax-highlight.d.mts +38 -0
  275. package/dist/plugins/syntax-highlight.d.mts.map +1 -0
  276. package/dist/plugins/syntax-highlight.mjs +106 -0
  277. package/dist/plugins/syntax-highlight.mjs.map +1 -0
  278. package/dist/processor.d.mts +60 -0
  279. package/dist/processor.d.mts.map +1 -0
  280. package/dist/processor.mjs +106 -0
  281. package/dist/processor.mjs.map +1 -0
  282. package/dist/ranges.d.mts +10 -0
  283. package/dist/ranges.d.mts.map +1 -0
  284. package/dist/ranges.mjs +22 -0
  285. package/dist/ranges.mjs.map +1 -0
  286. package/dist/source-map.d.mts +28 -0
  287. package/dist/source-map.d.mts.map +1 -0
  288. package/dist/source-map.mjs +90 -0
  289. package/dist/source-map.mjs.map +1 -0
  290. package/dist/source-text.d.mts +35 -0
  291. package/dist/source-text.d.mts.map +1 -0
  292. package/dist/source-text.mjs +132 -0
  293. package/dist/source-text.mjs.map +1 -0
  294. package/dist/source.d.mts +86 -0
  295. package/dist/source.d.mts.map +1 -0
  296. package/dist/source.mjs +264 -0
  297. package/dist/source.mjs.map +1 -0
  298. package/dist/stream-events.d.mts +59 -0
  299. package/dist/stream-events.d.mts.map +1 -0
  300. package/dist/stream-events.mjs +115 -0
  301. package/dist/stream-events.mjs.map +1 -0
  302. package/dist/stream-session.d.mts +79 -0
  303. package/dist/stream-session.d.mts.map +1 -0
  304. package/dist/stream-session.mjs +904 -0
  305. package/dist/stream-session.mjs.map +1 -0
  306. package/dist/stream-tail.d.mts +84 -0
  307. package/dist/stream-tail.d.mts.map +1 -0
  308. package/dist/stream-tail.mjs +359 -0
  309. package/dist/stream-tail.mjs.map +1 -0
  310. package/dist/stream-types.d.mts +89 -0
  311. package/dist/stream-types.d.mts.map +1 -0
  312. package/dist/stream-types.mjs +1 -0
  313. package/dist/stream.d.mts +28 -0
  314. package/dist/stream.d.mts.map +1 -0
  315. package/dist/stream.mjs +68 -0
  316. package/dist/stream.mjs.map +1 -0
  317. package/dist/syntax-options.d.mts +21 -0
  318. package/dist/syntax-options.d.mts.map +1 -0
  319. package/dist/syntax-options.mjs +26 -0
  320. package/dist/syntax-options.mjs.map +1 -0
  321. package/dist/traversal.d.mts +25 -0
  322. package/dist/traversal.d.mts.map +1 -0
  323. package/dist/traversal.mjs +136 -0
  324. package/dist/traversal.mjs.map +1 -0
  325. package/dist/tree.d.mts +18 -0
  326. package/dist/tree.d.mts.map +1 -0
  327. package/dist/tree.mjs +43 -0
  328. package/dist/tree.mjs.map +1 -0
  329. package/dist/unified/adapter.d.mts +24 -0
  330. package/dist/unified/adapter.d.mts.map +1 -0
  331. package/dist/unified/adapter.mjs +44 -0
  332. package/dist/unified/adapter.mjs.map +1 -0
  333. package/dist/unified/mod.d.mts +2 -0
  334. package/dist/unified/mod.mjs +1 -0
  335. package/dist/unified/runtime.d.mts +10 -0
  336. package/dist/unified/runtime.d.mts.map +1 -0
  337. package/dist/unified/runtime.mjs +115 -0
  338. package/dist/unified/runtime.mjs.map +1 -0
  339. package/dist/unified/tree-bridge.d.mts +63 -0
  340. package/dist/unified/tree-bridge.d.mts.map +1 -0
  341. package/dist/unified/tree-bridge.mjs +876 -0
  342. package/dist/unified/tree-bridge.mjs.map +1 -0
  343. package/dist/uri.d.mts +5 -0
  344. package/dist/uri.d.mts.map +1 -0
  345. package/dist/uri.mjs +32 -0
  346. package/dist/uri.mjs.map +1 -0
  347. package/package.json +56 -30
  348. package/dist/plugins/heading-id/plugin.d.mts +0 -17
  349. package/dist/plugins/heading-id/plugin.d.mts.map +0 -1
  350. package/dist/plugins/heading-id/plugin.mjs +0 -23
  351. package/dist/plugins/heading-id/plugin.mjs.map +0 -1
  352. package/dist/plugins/katex/plugin.d.mts +0 -39
  353. package/dist/plugins/katex/plugin.d.mts.map +0 -1
  354. package/dist/plugins/katex/plugin.mjs +0 -107
  355. package/dist/plugins/katex/plugin.mjs.map +0 -1
  356. package/dist/plugins/remove-imports-exports.d.mts +0 -10
  357. package/dist/plugins/remove-imports-exports.d.mts.map +0 -1
  358. package/dist/plugins/remove-imports-exports.mjs +0 -15
  359. package/dist/plugins/remove-imports-exports.mjs.map +0 -1
  360. package/dist/plugins/syntax-highlight/code-meta.d.mts +0 -22
  361. package/dist/plugins/syntax-highlight/code-meta.d.mts.map +0 -1
  362. package/dist/plugins/syntax-highlight/code-meta.mjs +0 -38
  363. package/dist/plugins/syntax-highlight/code-meta.mjs.map +0 -1
  364. package/dist/plugins/syntax-highlight/plugin.d.mts +0 -57
  365. package/dist/plugins/syntax-highlight/plugin.d.mts.map +0 -1
  366. package/dist/plugins/syntax-highlight/plugin.mjs +0 -93
  367. package/dist/plugins/syntax-highlight/plugin.mjs.map +0 -1
  368. package/dist/plugins/tree-processor/plugin.d.mts +0 -19
  369. package/dist/plugins/tree-processor/plugin.d.mts.map +0 -1
  370. package/dist/plugins/tree-processor/plugin.mjs +0 -21
  371. package/dist/plugins/tree-processor/plugin.mjs.map +0 -1
  372. package/dist/types.d.mts +0 -2
  373. /package/dist/{types.mjs → parser/block-syntax.mjs} +0 -0
@@ -0,0 +1,876 @@
1
+ import { htmlChildren, htmlFallback, htmlText } from "../html.mjs";
2
+ import { normalizeIdentifier } from "../identifier.mjs";
3
+ import { isFlowContent, isPhrasingContent } from "../model.mjs";
4
+ import { isHeadingDepth } from "../heading.mjs";
5
+ import { isBoolean, isNumber, isPlainObject, isString } from "@temelj/value";
6
+ import { find, html, svg } from "property-information";
7
+ //#region src/unified/tree-bridge.ts
8
+ const unifiedDataKeys = {
9
+ directiveLabel: "temeljDirectiveLabel",
10
+ htmlNode: "temeljHtmlNode",
11
+ mathFormat: "temeljMathFormat"
12
+ };
13
+ var UnifiedBoundaryError = class extends Error {
14
+ constructor(message) {
15
+ super(message);
16
+ this.name = "UnifiedBoundaryError";
17
+ }
18
+ };
19
+ var UnifiedTreeBridge = class {
20
+ file;
21
+ visiting = /* @__PURE__ */ new WeakSet();
22
+ /** Semantic HTML nodes sent to rehype. HAST data refers to them by index. */
23
+ #owned = [];
24
+ constructor(file) {
25
+ this.file = file;
26
+ }
27
+ toMdast(document) {
28
+ const node = this.mdxToUnist(document);
29
+ if (node.type !== "root") throw new UnifiedBoundaryError("The document bridge did not produce an mdast root");
30
+ return node;
31
+ }
32
+ fromMdast(root) {
33
+ const node = this.unistToMdx(root);
34
+ if (node.kind !== "document") throw new UnifiedBoundaryError(`Remark returned a ${node.kind} node instead of an mdast root`);
35
+ return node;
36
+ }
37
+ toHast(document) {
38
+ const node = this.htmlToUnist(document);
39
+ if (node.type !== "root") throw new UnifiedBoundaryError("The HTML bridge did not produce a HAST root");
40
+ return node;
41
+ }
42
+ fromHast(root) {
43
+ const node = this.unistToHtml(root, false);
44
+ if (node.kind !== "root") throw new UnifiedBoundaryError(`Rehype returned a ${node.kind} node instead of a HAST root`);
45
+ return node;
46
+ }
47
+ mdxToUnist(node) {
48
+ const base = this.positionBase(node.origin);
49
+ const children = () => "children" in node ? node.children.map((child) => this.mdxToUnist(child)) : [];
50
+ switch (node.kind) {
51
+ case "document": return {
52
+ type: "root",
53
+ children: children(),
54
+ ...base
55
+ };
56
+ case "text": return {
57
+ type: "text",
58
+ value: node.value,
59
+ ...base
60
+ };
61
+ case "emphasis": return {
62
+ type: "emphasis",
63
+ children: children(),
64
+ ...base
65
+ };
66
+ case "strong": return {
67
+ type: "strong",
68
+ children: children(),
69
+ ...base
70
+ };
71
+ case "delete": return {
72
+ type: "delete",
73
+ children: children(),
74
+ ...base
75
+ };
76
+ case "inlineCode": return {
77
+ type: "inlineCode",
78
+ value: node.value,
79
+ ...base
80
+ };
81
+ case "link": return {
82
+ type: "link",
83
+ url: node.url,
84
+ title: node.title ?? null,
85
+ children: children(),
86
+ ...base
87
+ };
88
+ case "image": return {
89
+ type: "image",
90
+ url: node.url,
91
+ alt: node.alt,
92
+ title: node.title ?? null,
93
+ ...base
94
+ };
95
+ case "linkReference": return {
96
+ type: "linkReference",
97
+ identifier: node.identifier,
98
+ referenceType: node.referenceKind,
99
+ children: children(),
100
+ ...base
101
+ };
102
+ case "imageReference": return {
103
+ type: "imageReference",
104
+ identifier: node.identifier,
105
+ referenceType: node.referenceKind,
106
+ alt: node.alt,
107
+ ...base
108
+ };
109
+ case "hardBreak": return {
110
+ type: "break",
111
+ ...base
112
+ };
113
+ case "rawHtmlInline":
114
+ case "rawHtmlBlock": return {
115
+ type: "html",
116
+ value: node.value,
117
+ ...base
118
+ };
119
+ case "footnoteReference": return {
120
+ type: "footnoteReference",
121
+ identifier: node.identifier,
122
+ label: node.label,
123
+ ...base
124
+ };
125
+ case "definition": return {
126
+ type: "definition",
127
+ identifier: node.identifier,
128
+ url: node.url,
129
+ title: node.title ?? null,
130
+ ...base
131
+ };
132
+ case "footnoteDefinition": return {
133
+ type: "footnoteDefinition",
134
+ identifier: node.identifier,
135
+ label: node.label,
136
+ children: children(),
137
+ ...base
138
+ };
139
+ case "frontmatter": return {
140
+ type: node.format,
141
+ value: node.value,
142
+ ...base
143
+ };
144
+ case "inlineMath": return {
145
+ type: "inlineMath",
146
+ value: node.value,
147
+ data: { [unifiedDataKeys.mathFormat]: node.format },
148
+ ...base
149
+ };
150
+ case "displayMath": return {
151
+ type: "math",
152
+ value: node.value,
153
+ meta: node.meta ?? null,
154
+ data: { [unifiedDataKeys.mathFormat]: node.format },
155
+ ...base
156
+ };
157
+ case "paragraph": return {
158
+ type: "paragraph",
159
+ children: children(),
160
+ ...base
161
+ };
162
+ case "heading": return {
163
+ type: "heading",
164
+ depth: node.depth,
165
+ children: children(),
166
+ ...base
167
+ };
168
+ case "codeBlock": return {
169
+ type: "code",
170
+ value: node.value,
171
+ lang: node.language ?? null,
172
+ meta: node.meta ?? null,
173
+ ...base
174
+ };
175
+ case "thematicBreak": return {
176
+ type: "thematicBreak",
177
+ ...base
178
+ };
179
+ case "blockquote": return {
180
+ type: "blockquote",
181
+ children: children(),
182
+ ...base
183
+ };
184
+ case "listItem": return {
185
+ type: "listItem",
186
+ checked: node.checked ?? null,
187
+ spread: node.spread,
188
+ children: children(),
189
+ ...base
190
+ };
191
+ case "list": return {
192
+ type: "list",
193
+ ordered: node.ordered,
194
+ start: node.ordered ? node.start : null,
195
+ spread: node.spread,
196
+ children: children(),
197
+ ...base
198
+ };
199
+ case "tableCell": return {
200
+ type: "tableCell",
201
+ children: children(),
202
+ ...base
203
+ };
204
+ case "tableRow": return {
205
+ type: "tableRow",
206
+ children: children(),
207
+ ...base
208
+ };
209
+ case "table": return {
210
+ type: "table",
211
+ align: node.alignments.map((value) => value === "none" ? null : value),
212
+ children: children(),
213
+ ...base
214
+ };
215
+ case "directiveLabel": return {
216
+ type: "temeljDirectiveLabel",
217
+ children: children(),
218
+ ...base
219
+ };
220
+ case "textDirective": return directiveToUnist("textDirective", node, base, this);
221
+ case "leafDirective": return directiveToUnist("leafDirective", node, base, this);
222
+ case "containerDirective": {
223
+ const value = directiveToUnist("containerDirective", node, base, this);
224
+ value.children = children();
225
+ if (node.label !== void 0) value.data = { [unifiedDataKeys.directiveLabel]: this.mdxToUnist(node.label) };
226
+ return value;
227
+ }
228
+ case "inlineExpression": return {
229
+ type: "mdxTextExpression",
230
+ value: node.code,
231
+ ...base
232
+ };
233
+ case "blockExpression": return {
234
+ type: "mdxFlowExpression",
235
+ value: node.code,
236
+ ...base
237
+ };
238
+ case "esm": return {
239
+ type: "mdxjsEsm",
240
+ value: node.code,
241
+ ...base
242
+ };
243
+ case "jsxTextElement": return jsxElementToUnist("mdxJsxTextElement", node, base, this);
244
+ case "jsxFlowElement": return jsxElementToUnist("mdxJsxFlowElement", node, base, this);
245
+ default: return node;
246
+ }
247
+ }
248
+ unistToMdx(value, mode = "flow") {
249
+ const node = this.nodeRecord(value);
250
+ const origin = this.origin(node.position);
251
+ const children = (childMode = "flow") => this.nodeChildren(node).map((child) => this.unistToMdx(child, childMode));
252
+ const phrasingChildren = () => phrasing(children("phrasing"), node.type);
253
+ const flowChildren = () => flow(children(), node.type);
254
+ let result;
255
+ switch (node.type) {
256
+ case "root":
257
+ result = {
258
+ kind: "document",
259
+ children: flowChildren(),
260
+ origin
261
+ };
262
+ break;
263
+ case "text":
264
+ result = {
265
+ kind: "text",
266
+ value: stringField(node, "value"),
267
+ origin
268
+ };
269
+ break;
270
+ case "emphasis":
271
+ case "strong":
272
+ case "delete":
273
+ result = {
274
+ kind: node.type,
275
+ children: phrasingChildren(),
276
+ origin
277
+ };
278
+ break;
279
+ case "inlineCode":
280
+ result = {
281
+ kind: "inlineCode",
282
+ value: stringField(node, "value"),
283
+ origin
284
+ };
285
+ break;
286
+ case "link":
287
+ result = {
288
+ kind: "link",
289
+ url: stringField(node, "url"),
290
+ title: nullableString(node.title),
291
+ children: phrasingChildren(),
292
+ origin
293
+ };
294
+ break;
295
+ case "image":
296
+ result = {
297
+ kind: "image",
298
+ url: stringField(node, "url"),
299
+ alt: nullableString(node.alt) ?? "",
300
+ title: nullableString(node.title),
301
+ origin
302
+ };
303
+ break;
304
+ case "linkReference":
305
+ result = {
306
+ kind: "linkReference",
307
+ identifier: normalizeIdentifier(stringField(node, "identifier")),
308
+ referenceKind: referenceKind(node.referenceType),
309
+ children: phrasingChildren(),
310
+ origin
311
+ };
312
+ break;
313
+ case "imageReference":
314
+ result = {
315
+ kind: "imageReference",
316
+ identifier: normalizeIdentifier(stringField(node, "identifier")),
317
+ alt: nullableString(node.alt) ?? "",
318
+ referenceKind: referenceKind(node.referenceType),
319
+ origin
320
+ };
321
+ break;
322
+ case "break":
323
+ result = {
324
+ kind: "hardBreak",
325
+ origin
326
+ };
327
+ break;
328
+ case "html":
329
+ result = {
330
+ kind: mode === "phrasing" ? "rawHtmlInline" : "rawHtmlBlock",
331
+ value: stringField(node, "value"),
332
+ origin
333
+ };
334
+ break;
335
+ case "footnoteReference": {
336
+ const identifier = stringField(node, "identifier");
337
+ result = {
338
+ kind: "footnoteReference",
339
+ identifier: normalizeIdentifier(identifier),
340
+ label: nullableString(node.label) ?? identifier,
341
+ origin
342
+ };
343
+ break;
344
+ }
345
+ case "definition":
346
+ result = {
347
+ kind: "definition",
348
+ identifier: normalizeIdentifier(stringField(node, "identifier")),
349
+ url: stringField(node, "url"),
350
+ title: nullableString(node.title),
351
+ origin
352
+ };
353
+ break;
354
+ case "footnoteDefinition": {
355
+ const identifier = stringField(node, "identifier");
356
+ result = {
357
+ kind: "footnoteDefinition",
358
+ identifier: normalizeIdentifier(identifier),
359
+ label: nullableString(node.label) ?? identifier,
360
+ children: flowChildren(),
361
+ origin
362
+ };
363
+ break;
364
+ }
365
+ case "yaml":
366
+ case "toml":
367
+ result = {
368
+ kind: "frontmatter",
369
+ format: node.type,
370
+ value: stringField(node, "value"),
371
+ origin
372
+ };
373
+ break;
374
+ case "inlineMath":
375
+ result = {
376
+ kind: "inlineMath",
377
+ value: stringField(node, "value"),
378
+ format: mathFormat(node),
379
+ origin
380
+ };
381
+ break;
382
+ case "math": {
383
+ const format = mathFormat(node);
384
+ result = {
385
+ kind: "displayMath",
386
+ value: stringField(node, "value"),
387
+ format,
388
+ meta: format === "dollar" ? nullableString(node.meta) : void 0,
389
+ origin
390
+ };
391
+ break;
392
+ }
393
+ case "paragraph":
394
+ result = {
395
+ kind: "paragraph",
396
+ children: phrasingChildren(),
397
+ origin
398
+ };
399
+ break;
400
+ case "heading":
401
+ result = {
402
+ kind: "heading",
403
+ depth: headingDepth(node.depth),
404
+ children: phrasingChildren(),
405
+ origin
406
+ };
407
+ break;
408
+ case "code":
409
+ result = {
410
+ kind: "codeBlock",
411
+ value: stringField(node, "value"),
412
+ language: nullableString(node.lang),
413
+ meta: nullableString(node.meta),
414
+ origin
415
+ };
416
+ break;
417
+ case "thematicBreak":
418
+ result = {
419
+ kind: "thematicBreak",
420
+ origin
421
+ };
422
+ break;
423
+ case "blockquote":
424
+ result = {
425
+ kind: "blockquote",
426
+ children: flowChildren(),
427
+ origin
428
+ };
429
+ break;
430
+ case "listItem":
431
+ result = {
432
+ kind: "listItem",
433
+ checked: nullableBoolean(node.checked),
434
+ spread: booleanField(node.spread, false),
435
+ children: flowChildren(),
436
+ origin
437
+ };
438
+ break;
439
+ case "list":
440
+ result = {
441
+ kind: "list",
442
+ ordered: booleanField(node.ordered, false),
443
+ start: nullableNumber(node.start) ?? 1,
444
+ spread: booleanField(node.spread, false),
445
+ children: listItems(children(), node.type),
446
+ origin
447
+ };
448
+ break;
449
+ case "tableCell":
450
+ result = {
451
+ kind: "tableCell",
452
+ children: phrasingChildren(),
453
+ origin
454
+ };
455
+ break;
456
+ case "tableRow":
457
+ result = {
458
+ kind: "tableRow",
459
+ children: tableCells(children(), node.type),
460
+ origin
461
+ };
462
+ break;
463
+ case "table":
464
+ result = {
465
+ kind: "table",
466
+ alignments: tableAlignments(node.align),
467
+ children: tableRows(children(), node.type),
468
+ origin
469
+ };
470
+ break;
471
+ case "temeljDirectiveLabel":
472
+ result = {
473
+ kind: "directiveLabel",
474
+ children: phrasingChildren(),
475
+ origin
476
+ };
477
+ break;
478
+ case "textDirective":
479
+ case "leafDirective":
480
+ result = {
481
+ kind: node.type,
482
+ name: stringField(node, "name"),
483
+ attributes: directiveAttributes(node.attributes),
484
+ label: directiveLabel(children("phrasing"), node.type),
485
+ origin
486
+ };
487
+ break;
488
+ case "containerDirective":
489
+ result = {
490
+ kind: "containerDirective",
491
+ name: stringField(node, "name"),
492
+ attributes: directiveAttributes(node.attributes),
493
+ label: directiveDataLabel(node.data, this),
494
+ children: flowChildren(),
495
+ origin
496
+ };
497
+ break;
498
+ case "mdxTextExpression":
499
+ result = {
500
+ kind: "inlineExpression",
501
+ code: stringField(node, "value"),
502
+ origin
503
+ };
504
+ break;
505
+ case "mdxFlowExpression":
506
+ result = {
507
+ kind: "blockExpression",
508
+ code: stringField(node, "value"),
509
+ origin
510
+ };
511
+ break;
512
+ case "mdxjsEsm":
513
+ result = {
514
+ kind: "esm",
515
+ code: stringField(node, "value"),
516
+ origin
517
+ };
518
+ break;
519
+ case "mdxJsxTextElement":
520
+ result = {
521
+ kind: "jsxTextElement",
522
+ name: nullableString(node.name),
523
+ attributes: jsxAttributes(node.attributes, this),
524
+ children: phrasingChildren(),
525
+ origin
526
+ };
527
+ break;
528
+ case "mdxJsxFlowElement":
529
+ result = {
530
+ kind: "jsxFlowElement",
531
+ name: nullableString(node.name),
532
+ attributes: jsxAttributes(node.attributes, this),
533
+ children: flowChildren(),
534
+ origin
535
+ };
536
+ break;
537
+ default: throw new UnifiedBoundaryError(`Unsupported mdast node type: ${node.type}`);
538
+ }
539
+ this.visiting.delete(node);
540
+ return result;
541
+ }
542
+ htmlToUnist(node) {
543
+ const base = this.positionBase(node.origin);
544
+ const children = () => htmlChildren(node).map((child) => this.htmlToUnist(child));
545
+ switch (node.kind) {
546
+ case "root": return {
547
+ type: "root",
548
+ children: children(),
549
+ ...base
550
+ };
551
+ case "text": return {
552
+ type: "text",
553
+ value: node.value,
554
+ ...base
555
+ };
556
+ case "raw": return {
557
+ type: "raw",
558
+ value: node.value,
559
+ ...base
560
+ };
561
+ case "comment": return {
562
+ type: "comment",
563
+ value: node.value,
564
+ ...base
565
+ };
566
+ case "doctype": return {
567
+ type: "doctype",
568
+ ...base
569
+ };
570
+ case "element": return {
571
+ type: "element",
572
+ tagName: node.tagName,
573
+ properties: propertiesToHast(node.attributes, node.tagName === "svg" ? svg : html),
574
+ children: children(),
575
+ ...base
576
+ };
577
+ case "jsx":
578
+ case "expression":
579
+ case "pending":
580
+ case "unresolvedReference": return {
581
+ type: "text",
582
+ value: htmlText(node),
583
+ data: { [unifiedDataKeys.htmlNode]: this.#owned.push(node) - 1 },
584
+ ...base
585
+ };
586
+ case "codeBlock":
587
+ case "math":
588
+ case "footnoteReference":
589
+ case "footnoteSection": return {
590
+ ...this.htmlToUnist({
591
+ ...htmlFallback(node),
592
+ origin: node.origin
593
+ }),
594
+ data: { [unifiedDataKeys.htmlNode]: this.#owned.push(node) - 1 }
595
+ };
596
+ default: return node;
597
+ }
598
+ }
599
+ unistToHtml(value, inSvg) {
600
+ const node = this.nodeRecord(value);
601
+ const origin = this.origin(node.position);
602
+ let result;
603
+ switch (node.type) {
604
+ case "root":
605
+ result = {
606
+ kind: "root",
607
+ children: this.nodeChildren(node).map((child) => this.unistToHtml(child, inSvg)),
608
+ origin
609
+ };
610
+ break;
611
+ case "text":
612
+ result = {
613
+ kind: "text",
614
+ value: stringField(node, "value"),
615
+ origin
616
+ };
617
+ break;
618
+ case "raw":
619
+ result = {
620
+ kind: "raw",
621
+ value: stringField(node, "value"),
622
+ origin
623
+ };
624
+ break;
625
+ case "comment":
626
+ result = {
627
+ kind: "comment",
628
+ value: stringField(node, "value"),
629
+ origin
630
+ };
631
+ break;
632
+ case "doctype":
633
+ result = {
634
+ kind: "doctype",
635
+ origin
636
+ };
637
+ break;
638
+ case "element": {
639
+ const tagName = stringField(node, "tagName");
640
+ const svgElement = inSvg || tagName === "svg";
641
+ const childSvg = svgElement && tagName !== "foreignObject";
642
+ result = {
643
+ kind: "element",
644
+ tagName,
645
+ attributes: propertiesFromHast(node.properties ?? {}, svgElement ? svg : html),
646
+ children: this.nodeChildren(node).map((child) => this.unistToHtml(child, childSvg)),
647
+ origin
648
+ };
649
+ break;
650
+ }
651
+ default: throw new UnifiedBoundaryError(`Unsupported HAST node type: ${node.type}`);
652
+ }
653
+ this.visiting.delete(node);
654
+ return this.restoredHtmlNode(node.data, result);
655
+ }
656
+ /** Restores a semantic node whose inert fallback came back from rehype unchanged. */
657
+ restoredHtmlNode(data, result) {
658
+ const index = isPlainObject(data) && unifiedDataKeys.htmlNode in data ? data[unifiedDataKeys.htmlNode] : void 0;
659
+ const owned = isNumber(index) ? this.#owned.at(index) : void 0;
660
+ if (owned === void 0) return result;
661
+ return owned.origin?.start === result.origin?.start && owned.origin?.end === result.origin?.end && htmlText(stripSemantic(owned)) === htmlText(result) ? owned : result;
662
+ }
663
+ nodeRecord(value) {
664
+ if (!isUnistNode(value)) throw new UnifiedBoundaryError("Unified returned a malformed node without a string type");
665
+ if (this.visiting.has(value)) throw new UnifiedBoundaryError(`Unified returned a cyclic ${value.type} tree`);
666
+ this.visiting.add(value);
667
+ return value;
668
+ }
669
+ nodeChildren(node) {
670
+ if (!Array.isArray(node.children)) throw new UnifiedBoundaryError(`${node.type} must have a children array`);
671
+ return node.children;
672
+ }
673
+ positionBase(origin) {
674
+ return origin === void 0 ? {} : { position: {
675
+ start: this.file.location(origin.start),
676
+ end: this.file.location(origin.end)
677
+ } };
678
+ }
679
+ origin(position) {
680
+ if (position === void 0) return;
681
+ if (!isPlainObject(position) || !("start" in position) || !("end" in position) || !isPlainObject(position.start) || !isPlainObject(position.end)) throw new UnifiedBoundaryError("A returned Unist position is malformed");
682
+ const start = "offset" in position.start ? position.start.offset : void 0;
683
+ const end = "offset" in position.end ? position.end.offset : void 0;
684
+ if (!Number.isInteger(start) || !Number.isInteger(end) || !isNumber(start) || !isNumber(end) || start < 0 || end < start || end > this.file.length) throw new UnifiedBoundaryError("A returned Unist position has invalid UTF-16 offsets");
685
+ return {
686
+ start,
687
+ end
688
+ };
689
+ }
690
+ };
691
+ function stripSemantic(node) {
692
+ return node.kind === "codeBlock" || node.kind === "math" || node.kind === "footnoteReference" || node.kind === "footnoteSection" ? htmlFallback(node) : node;
693
+ }
694
+ function directiveToUnist(type, node, base, bridge) {
695
+ return {
696
+ type,
697
+ name: node.name,
698
+ attributes: Object.fromEntries(node.attributes.map((entry) => [entry.name, entry.value])),
699
+ children: node.label === void 0 ? [] : node.label.children.map((child) => bridge.mdxToUnist(child)),
700
+ ...base
701
+ };
702
+ }
703
+ function jsxElementToUnist(type, node, base, bridge) {
704
+ return {
705
+ type,
706
+ name: node.name ?? null,
707
+ attributes: node.attributes.map((attribute) => jsxAttributeToUnist(attribute, bridge)),
708
+ children: node.children.map((child) => bridge.mdxToUnist(child)),
709
+ ...base
710
+ };
711
+ }
712
+ function jsxAttributeToUnist(node, bridge) {
713
+ const base = bridge.positionBase(node.origin);
714
+ if (node.kind === "jsxSpreadAttribute") return {
715
+ type: "mdxJsxExpressionAttribute",
716
+ value: `...${node.code}`,
717
+ ...base
718
+ };
719
+ const value = jsxAttributeValueToUnist(node);
720
+ return {
721
+ type: "mdxJsxAttribute",
722
+ name: node.name,
723
+ value,
724
+ ...base
725
+ };
726
+ }
727
+ function jsxAttributeValueToUnist(node) {
728
+ if (node.value === void 0) return null;
729
+ return isString(node.value) ? node.value : {
730
+ type: "mdxJsxAttributeValueExpression",
731
+ value: node.value.code
732
+ };
733
+ }
734
+ function propertiesToHast(attributes, schema) {
735
+ const result = Object.create(null);
736
+ for (const [name, value] of Object.entries(attributes)) result[find(schema, name).property] = value;
737
+ return result;
738
+ }
739
+ function propertiesFromHast(value, schema) {
740
+ if (!isPlainObject(value)) throw new UnifiedBoundaryError("HAST properties must be an object");
741
+ const result = Object.create(null);
742
+ for (const [name, item] of Object.entries(value)) {
743
+ if (item === null || item === void 0) continue;
744
+ if (isBoolean(item) || isString(item) || isNumber(item) && Number.isFinite(item)) {
745
+ result[find(schema, name).attribute] = item;
746
+ continue;
747
+ }
748
+ if (Array.isArray(item) && item.every((entry) => isString(entry) || isNumber(entry) && Number.isFinite(entry))) {
749
+ result[find(schema, name).attribute] = [...item];
750
+ continue;
751
+ }
752
+ throw new UnifiedBoundaryError(`Unsupported HAST property value for ${JSON.stringify(name)}`);
753
+ }
754
+ return result;
755
+ }
756
+ function stringField(node, name) {
757
+ const value = node[name];
758
+ if (!isString(value)) throw new UnifiedBoundaryError(`${node.type}.${name} must be a string`);
759
+ return value;
760
+ }
761
+ function nullableString(value) {
762
+ if (value === null || value === void 0) return;
763
+ if (!isString(value)) throw new UnifiedBoundaryError("Expected a string or null");
764
+ return value;
765
+ }
766
+ function nullableBoolean(value) {
767
+ if (value === null || value === void 0) return;
768
+ if (!isBoolean(value)) throw new UnifiedBoundaryError("Expected a boolean or null");
769
+ return value;
770
+ }
771
+ function booleanField(value, fallback) {
772
+ return value === void 0 || value === null ? fallback : nullableBoolean(value) ?? fallback;
773
+ }
774
+ function nullableNumber(value) {
775
+ if (value === null || value === void 0) return;
776
+ if (!isNumber(value) || !Number.isSafeInteger(value)) throw new UnifiedBoundaryError("Expected a safe integer or null");
777
+ return value;
778
+ }
779
+ function headingDepth(value) {
780
+ if (isHeadingDepth(value)) return value;
781
+ throw new UnifiedBoundaryError("heading.depth must be between 1 and 6");
782
+ }
783
+ function referenceKind(value) {
784
+ if (value === "full" || value === "collapsed" || value === "shortcut") return value;
785
+ throw new UnifiedBoundaryError("A reference has an invalid referenceType");
786
+ }
787
+ function mathFormat(node) {
788
+ return isPlainObject(node.data) && unifiedDataKeys.mathFormat in node.data && node.data[unifiedDataKeys.mathFormat] === "tex" ? "tex" : "dollar";
789
+ }
790
+ function tableAlignments(value) {
791
+ if (!Array.isArray(value)) return [];
792
+ return value.map((item) => item === null ? "none" : item === "left" || item === "right" || item === "center" ? item : (() => {
793
+ throw new UnifiedBoundaryError("table.align contains an invalid value");
794
+ })());
795
+ }
796
+ function directiveAttributes(value) {
797
+ if (value === null || value === void 0) return [];
798
+ if (!isPlainObject(value)) throw new UnifiedBoundaryError("Directive attributes must be an object");
799
+ return Object.entries(value).map(([name, item]) => ({
800
+ name,
801
+ value: nullableString(item) ?? ""
802
+ }));
803
+ }
804
+ function directiveLabel(values, type) {
805
+ return values.length === 0 ? void 0 : {
806
+ kind: "directiveLabel",
807
+ children: phrasing(values, type)
808
+ };
809
+ }
810
+ function directiveDataLabel(value, bridge) {
811
+ if (!isPlainObject(value) || !(unifiedDataKeys.directiveLabel in value) || value[unifiedDataKeys.directiveLabel] === void 0) return;
812
+ const label = bridge.unistToMdx(value[unifiedDataKeys.directiveLabel]);
813
+ if (label.kind !== "directiveLabel") throw new UnifiedBoundaryError("Container directive label is malformed");
814
+ return label;
815
+ }
816
+ function jsxAttributes(value, bridge) {
817
+ if (!Array.isArray(value)) throw new UnifiedBoundaryError("MDX JSX attributes must be an array");
818
+ return value.map((item) => {
819
+ const node = bridge.nodeRecord(item);
820
+ const origin = bridge.origin(node.position);
821
+ bridge.visiting.delete(node);
822
+ if (node.type === "mdxJsxExpressionAttribute") return {
823
+ kind: "jsxSpreadAttribute",
824
+ code: stringField(node, "value").replace(/^\s*\.\.\./u, ""),
825
+ origin
826
+ };
827
+ if (node.type !== "mdxJsxAttribute") throw new UnifiedBoundaryError(`Unsupported MDX JSX attribute type: ${node.type}`);
828
+ const name = stringField(node, "name");
829
+ if (node.value === null || node.value === void 0 || isString(node.value)) return {
830
+ kind: "jsxAttribute",
831
+ name,
832
+ value: node.value ?? void 0,
833
+ origin
834
+ };
835
+ const expression = bridge.nodeRecord(node.value);
836
+ if (expression.type !== "mdxJsxAttributeValueExpression") throw new UnifiedBoundaryError("Unsupported MDX JSX attribute value");
837
+ bridge.visiting.delete(expression);
838
+ return {
839
+ kind: "jsxAttribute",
840
+ name,
841
+ value: {
842
+ kind: "jsxAttributeValueExpression",
843
+ code: stringField(expression, "value"),
844
+ origin: bridge.origin(expression.position)
845
+ },
846
+ origin
847
+ };
848
+ });
849
+ }
850
+ function phrasing(values, parent) {
851
+ if (!values.every(isPhrasingContent)) throw new UnifiedBoundaryError(`${parent} contains non-phrasing content`);
852
+ return values;
853
+ }
854
+ function flow(values, parent) {
855
+ if (!values.every(isFlowContent)) throw new UnifiedBoundaryError(`${parent} contains non-flow content`);
856
+ return values;
857
+ }
858
+ function listItems(values, parent) {
859
+ if (!values.every((node) => node.kind === "listItem")) throw new UnifiedBoundaryError(`${parent} contains a non-list-item child`);
860
+ return values;
861
+ }
862
+ function tableCells(values, parent) {
863
+ if (!values.every((node) => node.kind === "tableCell")) throw new UnifiedBoundaryError(`${parent} contains a non-table-cell child`);
864
+ return values;
865
+ }
866
+ function tableRows(values, parent) {
867
+ if (!values.every((node) => node.kind === "tableRow")) throw new UnifiedBoundaryError(`${parent} contains a non-table-row child`);
868
+ return values;
869
+ }
870
+ function isUnistNode(value) {
871
+ return isPlainObject(value) && "type" in value && isString(value.type);
872
+ }
873
+ //#endregion
874
+ export { UnifiedBoundaryError, UnifiedTreeBridge };
875
+
876
+ //# sourceMappingURL=tree-bridge.mjs.map