@astryxdesign/core 0.6.2 → 0.6.3-canary.01fa439

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 (384) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/dist/BottomSheet/BottomSheet.d.ts +1 -1
  3. package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
  4. package/dist/BottomSheet/BottomSheet.js +3 -1
  5. package/dist/BottomSheet/BottomSheetPanel.d.ts +7 -5
  6. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  7. package/dist/BottomSheet/BottomSheetPanel.js +56 -19
  8. package/dist/Chat/ChatComposer.d.ts.map +1 -1
  9. package/dist/Chat/ChatComposer.js +10 -5
  10. package/dist/Chat/ChatComposerDrawer.d.ts +19 -5
  11. package/dist/Chat/ChatComposerDrawer.d.ts.map +1 -1
  12. package/dist/Chat/ChatComposerDrawer.js +48 -23
  13. package/dist/Chat/ChatComposerInput.d.ts +11 -3
  14. package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
  15. package/dist/Chat/ChatComposerInput.js +63 -16
  16. package/dist/Chat/ChatDictationButton.d.ts +3 -2
  17. package/dist/Chat/ChatDictationButton.d.ts.map +1 -1
  18. package/dist/Chat/ChatDictationButton.js +6 -4
  19. package/dist/Chat/ChatSendButton.js +1 -1
  20. package/dist/Chat/index.d.ts +1 -1
  21. package/dist/Chat/index.d.ts.map +1 -1
  22. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  23. package/dist/CheckboxInput/CheckboxInput.js +12 -2
  24. package/dist/Collapsible/Collapsible.d.ts.map +1 -1
  25. package/dist/Collapsible/Collapsible.js +6 -1
  26. package/dist/CommandPalette/CommandPaletteInput.d.ts.map +1 -1
  27. package/dist/CommandPalette/CommandPaletteInput.js +1 -1
  28. package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
  29. package/dist/ComplexSelector/ComplexSelector.js +1 -1
  30. package/dist/DateInput/DateInput.d.ts.map +1 -1
  31. package/dist/DateInput/DateInput.js +4 -4
  32. package/dist/DateInput/NativeDateField.d.ts.map +1 -1
  33. package/dist/DateInput/NativeDateField.js +16 -16
  34. package/dist/DateInput/TouchDateField.d.ts.map +1 -1
  35. package/dist/DateInput/TouchDateField.js +2 -2
  36. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  37. package/dist/DateRangeInput/DateRangeInput.js +4 -4
  38. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  39. package/dist/DateTimeInput/DateTimeInput.js +8 -8
  40. package/dist/DateTimeInput/TouchDateTimeField.d.ts.map +1 -1
  41. package/dist/DateTimeInput/TouchDateTimeField.js +4 -4
  42. package/dist/DateTimeInput/nativePickerSegmentStyles.d.ts +9 -3
  43. package/dist/DateTimeInput/nativePickerSegmentStyles.d.ts.map +1 -1
  44. package/dist/DateTimeInput/nativePickerSegmentStyles.js +3 -3
  45. package/dist/Dialog/DialogHeader.d.ts +8 -1
  46. package/dist/Dialog/DialogHeader.d.ts.map +1 -1
  47. package/dist/Dialog/DialogHeader.js +10 -1
  48. package/dist/Field/InputClearButton.d.ts +4 -2
  49. package/dist/Field/InputClearButton.d.ts.map +1 -1
  50. package/dist/Field/InputClearButton.js +4 -2
  51. package/dist/Field/PanelSearchInput.d.ts.map +1 -1
  52. package/dist/Field/PanelSearchInput.js +1 -1
  53. package/dist/FileInput/FileInput.d.ts.map +1 -1
  54. package/dist/FileInput/FileInput.js +7 -7
  55. package/dist/Kbd/Kbd.d.ts +5 -3
  56. package/dist/Kbd/Kbd.d.ts.map +1 -1
  57. package/dist/Kbd/Kbd.js +36 -42
  58. package/dist/Link/Link.d.ts.map +1 -1
  59. package/dist/Link/Link.js +6 -2
  60. package/dist/Markdown/Markdown.d.ts +8 -2
  61. package/dist/Markdown/Markdown.d.ts.map +1 -1
  62. package/dist/Markdown/Markdown.fr23.bench.d.ts +2 -0
  63. package/dist/Markdown/Markdown.fr23.bench.d.ts.map +1 -0
  64. package/dist/Markdown/Markdown.fr23.bench.js +150 -0
  65. package/dist/Markdown/Markdown.fr23.sampling.d.ts +2 -0
  66. package/dist/Markdown/Markdown.fr23.sampling.d.ts.map +1 -0
  67. package/dist/Markdown/Markdown.fr23.sampling.js +43 -0
  68. package/dist/Markdown/Markdown.js +262 -109
  69. package/dist/Markdown/ast.d.ts +162 -0
  70. package/dist/Markdown/ast.d.ts.map +1 -0
  71. package/dist/Markdown/ast.js +74 -0
  72. package/dist/Markdown/index.d.ts +5 -3
  73. package/dist/Markdown/index.d.ts.map +1 -1
  74. package/dist/Markdown/index.js +3 -2
  75. package/dist/Markdown/parser/index.d.ts +10 -0
  76. package/dist/Markdown/parser/index.d.ts.map +1 -0
  77. package/dist/Markdown/parser/index.js +10 -0
  78. package/dist/Markdown/parser.d.ts +126 -58
  79. package/dist/Markdown/parser.d.ts.map +1 -1
  80. package/dist/Markdown/parser.js +716 -167
  81. package/dist/Markdown/plugins/frontmatter.d.ts +32 -0
  82. package/dist/Markdown/plugins/frontmatter.d.ts.map +1 -0
  83. package/dist/Markdown/plugins/frontmatter.js +132 -0
  84. package/dist/Markdown/plugins/index.d.ts +16 -0
  85. package/dist/Markdown/plugins/index.d.ts.map +1 -0
  86. package/dist/Markdown/plugins/index.js +13 -0
  87. package/dist/Markdown/plugins/protocol.d.ts +191 -0
  88. package/dist/Markdown/plugins/protocol.d.ts.map +1 -0
  89. package/dist/Markdown/plugins/protocol.js +957 -0
  90. package/dist/Markdown/plugins/semanticFence.d.ts +36 -0
  91. package/dist/Markdown/plugins/semanticFence.d.ts.map +1 -0
  92. package/dist/Markdown/plugins/semanticFence.js +213 -0
  93. package/dist/Markdown/plugins/sourceDecoration.d.ts +76 -0
  94. package/dist/Markdown/plugins/sourceDecoration.d.ts.map +1 -0
  95. package/dist/Markdown/plugins/sourceDecoration.js +393 -0
  96. package/dist/Markdown/plugins/textTransform.d.ts +30 -0
  97. package/dist/Markdown/plugins/textTransform.d.ts.map +1 -0
  98. package/dist/Markdown/plugins/textTransform.js +374 -0
  99. package/dist/Markdown/remark.d.ts +196 -0
  100. package/dist/Markdown/remark.d.ts.map +1 -0
  101. package/dist/Markdown/remark.js +1062 -0
  102. package/dist/Markdown/url.d.ts +4 -0
  103. package/dist/Markdown/url.d.ts.map +1 -0
  104. package/dist/Markdown/url.js +25 -0
  105. package/dist/Markdown/utils.d.ts +4 -2
  106. package/dist/Markdown/utils.d.ts.map +1 -1
  107. package/dist/Markdown/utils.js +2 -1
  108. package/dist/NumberInput/NumberInput.d.ts.map +1 -1
  109. package/dist/NumberInput/NumberInput.js +4 -4
  110. package/dist/Outline/index.d.ts +1 -0
  111. package/dist/Outline/index.d.ts.map +1 -1
  112. package/dist/Outline/parseOutlineFromMarkdown.d.ts +7 -1
  113. package/dist/Outline/parseOutlineFromMarkdown.d.ts.map +1 -1
  114. package/dist/Outline/parseOutlineFromMarkdown.js +14 -8
  115. package/dist/Outline/useOutlineFromMarkdown.d.ts +3 -1
  116. package/dist/Outline/useOutlineFromMarkdown.d.ts.map +1 -1
  117. package/dist/Outline/useOutlineFromMarkdown.js +8 -3
  118. package/dist/PowerSearch/PowerSearchEditPopover.d.ts.map +1 -1
  119. package/dist/PowerSearch/PowerSearchEditPopover.js +46 -30
  120. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  121. package/dist/ProgressBar/ProgressBar.js +36 -31
  122. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  123. package/dist/RadioList/RadioListItem.js +13 -1
  124. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  125. package/dist/SegmentedControl/SegmentedControlItem.js +5 -5
  126. package/dist/Selector/Selector.d.ts +9 -7
  127. package/dist/Selector/Selector.d.ts.map +1 -1
  128. package/dist/Selector/Selector.js +7 -5
  129. package/dist/SideNav/SideNav.d.ts +2 -1
  130. package/dist/SideNav/SideNav.d.ts.map +1 -1
  131. package/dist/SideNav/SideNav.js +9 -3
  132. package/dist/Slider/Slider.d.ts.map +1 -1
  133. package/dist/Slider/Slider.js +28 -12
  134. package/dist/Spinner/Spinner.d.ts.map +1 -1
  135. package/dist/Spinner/Spinner.js +23 -7
  136. package/dist/Switch/Switch.d.ts.map +1 -1
  137. package/dist/Switch/Switch.js +11 -0
  138. package/dist/TabList/Tab.d.ts +1 -1
  139. package/dist/TabList/Tab.d.ts.map +1 -1
  140. package/dist/TabList/Tab.js +20 -7
  141. package/dist/Table/Table.d.ts +1 -0
  142. package/dist/Table/Table.d.ts.map +1 -1
  143. package/dist/Table/Table.js +29 -13
  144. package/dist/TextArea/TextArea.d.ts.map +1 -1
  145. package/dist/TextArea/TextArea.js +1 -1
  146. package/dist/TextInput/TextInput.d.ts.map +1 -1
  147. package/dist/TextInput/TextInput.js +2 -2
  148. package/dist/TimeInput/TimeInput.d.ts.map +1 -1
  149. package/dist/TimeInput/TimeInput.js +4 -4
  150. package/dist/ToggleButton/ToggleButton.d.ts +9 -6
  151. package/dist/ToggleButton/ToggleButton.d.ts.map +1 -1
  152. package/dist/ToggleButton/ToggleButton.js +15 -27
  153. package/dist/TreeList/TreeList.d.ts.map +1 -1
  154. package/dist/TreeList/TreeList.js +3 -0
  155. package/dist/TreeList/TreeListItem.d.ts +6 -1
  156. package/dist/TreeList/TreeListItem.d.ts.map +1 -1
  157. package/dist/TreeList/TreeListItem.js +12 -2
  158. package/dist/TreeList/TreeListTypes.d.ts +8 -1
  159. package/dist/TreeList/TreeListTypes.d.ts.map +1 -1
  160. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  161. package/dist/Typeahead/BaseTypeahead.js +16 -7
  162. package/dist/astryx.css +18 -7
  163. package/dist/hooks/scrollKeyboardDelegation.d.ts +3 -0
  164. package/dist/hooks/scrollKeyboardDelegation.d.ts.map +1 -0
  165. package/dist/hooks/scrollKeyboardDelegation.js +146 -0
  166. package/dist/hooks/useScrollableArea.d.ts +6 -2
  167. package/dist/hooks/useScrollableArea.d.ts.map +1 -1
  168. package/dist/hooks/useScrollableArea.js +17 -5
  169. package/dist/theme/generateThemeRules.d.ts.map +1 -1
  170. package/dist/theme/generateThemeRules.js +10 -0
  171. package/dist/utils/interactionOverlay.stylex.d.ts +8 -0
  172. package/dist/utils/interactionOverlay.stylex.d.ts.map +1 -1
  173. package/dist/utils/interactionOverlay.stylex.js +9 -0
  174. package/locales/af-ZA.json +530 -1
  175. package/locales/ar-SA.json +490 -1
  176. package/locales/ca-ES.json +514 -1
  177. package/locales/cs-CZ.json +498 -1
  178. package/locales/da-DK.json +522 -1
  179. package/locales/de-DE.json +522 -1
  180. package/locales/el-GR.json +498 -1
  181. package/locales/es-ES.json +510 -1
  182. package/locales/fi-FI.json +498 -1
  183. package/locales/fr-FR.json +534 -1
  184. package/locales/he-IL.json +498 -1
  185. package/locales/hu-HU.json +498 -1
  186. package/locales/it-IT.json +510 -1
  187. package/locales/ja-JP.json +490 -1
  188. package/locales/ko-KR.json +498 -1
  189. package/locales/nl-NL.json +534 -1
  190. package/locales/no-NO.json +510 -1
  191. package/locales/pl-PL.json +506 -1
  192. package/locales/pt-BR.json +506 -1
  193. package/locales/pt-PT.json +506 -1
  194. package/locales/ro-RO.json +506 -1
  195. package/locales/ru-RU.json +498 -1
  196. package/locales/sr-SP.json +498 -1
  197. package/locales/sv-SE.json +502 -1
  198. package/locales/tr-TR.json +498 -1
  199. package/locales/uk-UA.json +498 -1
  200. package/locales/vi-VN.json +502 -1
  201. package/locales/zh-CN.json +490 -1
  202. package/locales/zh-TW.json +490 -1
  203. package/package.json +19 -4
  204. package/src/BottomSheet/BottomSheet.doc.mjs +8 -1
  205. package/src/BottomSheet/BottomSheet.spec.md +46 -20
  206. package/src/BottomSheet/BottomSheet.test.tsx +6 -3
  207. package/src/BottomSheet/BottomSheet.tsx +3 -1
  208. package/src/BottomSheet/BottomSheetKeyboard.test.tsx +195 -0
  209. package/src/BottomSheet/BottomSheetPanel.test.tsx +11 -1
  210. package/src/BottomSheet/BottomSheetPanel.tsx +49 -16
  211. package/src/BottomSheet/__tests__/BottomSheetKeyboard.a11y.browser.spec.ts +344 -0
  212. package/src/Button/__tests__/Button.a11y.chromium.spec.ts +17 -1
  213. package/src/Button/__tests__/Button.a11y.known-failures.ts +0 -29
  214. package/src/Button/__tests__/Button.a11y.renders.tsx +9 -2
  215. package/src/Button/__tests__/Button.a11y.states.ts +9 -0
  216. package/src/Chat/ChatComposer.doc.mjs +14 -0
  217. package/src/Chat/ChatComposer.spec.md +230 -0
  218. package/src/Chat/ChatComposer.test.tsx +57 -0
  219. package/src/Chat/ChatComposer.tsx +21 -9
  220. package/src/Chat/ChatComposerDrawer.doc.mjs +63 -5
  221. package/src/Chat/ChatComposerDrawer.spec.md +267 -0
  222. package/src/Chat/ChatComposerDrawer.test.tsx +81 -12
  223. package/src/Chat/ChatComposerDrawer.tsx +38 -9
  224. package/src/Chat/ChatComposerInput.doc.mjs +114 -26
  225. package/src/Chat/ChatComposerInput.spec.md +185 -0
  226. package/src/Chat/ChatComposerInput.test.tsx +113 -3
  227. package/src/Chat/ChatComposerInput.tsx +78 -13
  228. package/src/Chat/ChatComposerTokenElement.spec.md +152 -0
  229. package/src/Chat/ChatComposerTokenElement.test.tsx +85 -0
  230. package/src/Chat/ChatDictationButton.doc.mjs +3 -3
  231. package/src/Chat/ChatDictationButton.spec.md +160 -0
  232. package/src/Chat/ChatDictationButton.test.tsx +92 -27
  233. package/src/Chat/ChatDictationButton.tsx +8 -6
  234. package/src/Chat/ChatSendButton.test.tsx +1 -4
  235. package/src/Chat/ChatSendButton.tsx +1 -1
  236. package/src/Chat/index.ts +1 -0
  237. package/src/CheckboxInput/CheckboxInput.doc.mjs +11 -0
  238. package/src/CheckboxInput/CheckboxInput.test.tsx +34 -0
  239. package/src/CheckboxInput/CheckboxInput.tsx +21 -1
  240. package/src/ClickableCard/ClickableCard.test.tsx +102 -5
  241. package/src/Collapsible/Collapsible.doc.mjs +11 -0
  242. package/src/Collapsible/Collapsible.test.tsx +21 -0
  243. package/src/Collapsible/Collapsible.tsx +5 -0
  244. package/src/CommandPalette/CommandPaletteInput.tsx +6 -1
  245. package/src/ComplexSelector/ComplexSelector.tsx +6 -1
  246. package/src/DateInput/DateInput.tsx +6 -1
  247. package/src/DateInput/NativeDateField.tsx +24 -8
  248. package/src/DateInput/TouchDateField.tsx +6 -2
  249. package/src/DateRangeInput/DateRangeInput.tsx +6 -1
  250. package/src/DateTimeInput/DateTimeInput.tsx +6 -1
  251. package/src/DateTimeInput/TouchDateTimeField.tsx +6 -1
  252. package/src/DateTimeInput/nativePickerSegmentStyles.ts +24 -8
  253. package/src/Dialog/DialogHeader.doc.mjs +12 -0
  254. package/src/Dialog/DialogHeader.test.tsx +97 -0
  255. package/src/Dialog/DialogHeader.tsx +25 -3
  256. package/src/Dialog/modules/DialogHeader.spec.md +75 -38
  257. package/src/Field/InputClearButton.test.tsx +17 -3
  258. package/src/Field/InputClearButton.tsx +5 -2
  259. package/src/Field/PanelSearchInput.tsx +5 -2
  260. package/src/FieldStatus/__tests__/StatusMessage.a11y.states.ts +1 -1
  261. package/src/FileInput/FileInput.tsx +11 -2
  262. package/src/Kbd/Kbd.doc.mjs +3 -3
  263. package/src/Kbd/Kbd.test.tsx +57 -1
  264. package/src/Kbd/Kbd.tsx +57 -37
  265. package/src/Layout/LayoutFooter.doc.mjs +17 -0
  266. package/src/Link/Link.doc.mjs +11 -0
  267. package/src/Link/Link.test.tsx +24 -0
  268. package/src/Link/Link.tsx +5 -0
  269. package/src/List/List.spec.md +200 -0
  270. package/src/Markdown/Markdown.doc.mjs +272 -0
  271. package/src/Markdown/Markdown.fr23.bench.ts +174 -0
  272. package/src/Markdown/Markdown.fr23.perf.test.ts +249 -0
  273. package/src/Markdown/Markdown.fr23.sampling.ts +49 -0
  274. package/src/Markdown/Markdown.helpers.perf.test.ts +489 -0
  275. package/src/Markdown/Markdown.public.test.ts +126 -3
  276. package/src/Markdown/Markdown.spec.md +197 -44
  277. package/src/Markdown/Markdown.test.tsx +11 -0
  278. package/src/Markdown/Markdown.tsx +414 -135
  279. package/src/Markdown/ast.test.ts +307 -0
  280. package/src/Markdown/ast.ts +337 -0
  281. package/src/Markdown/incremental.test.ts +12 -0
  282. package/src/Markdown/index.ts +37 -1
  283. package/src/Markdown/modules/remark.spec.md +269 -0
  284. package/src/Markdown/parser/index.ts +64 -0
  285. package/src/Markdown/parser.public.test.ts +103 -0
  286. package/src/Markdown/parser.ts +1180 -235
  287. package/src/Markdown/plugins/frontmatter.test.tsx +125 -0
  288. package/src/Markdown/plugins/frontmatter.ts +198 -0
  289. package/src/Markdown/plugins/index.ts +53 -0
  290. package/src/Markdown/plugins/protocol.test.tsx +1022 -0
  291. package/src/Markdown/plugins/protocol.ts +1618 -0
  292. package/src/Markdown/plugins/semanticFence.test.tsx +546 -0
  293. package/src/Markdown/plugins/semanticFence.ts +424 -0
  294. package/src/Markdown/plugins/sourceDecoration.test.tsx +799 -0
  295. package/src/Markdown/plugins/sourceDecoration.ts +539 -0
  296. package/src/Markdown/plugins/textTransform.test.ts +467 -0
  297. package/src/Markdown/plugins/textTransform.ts +554 -0
  298. package/src/Markdown/remark.test.tsx +1877 -0
  299. package/src/Markdown/remark.ts +1574 -0
  300. package/src/Markdown/url.ts +30 -0
  301. package/src/Markdown/utils.ts +13 -1
  302. package/src/MultiSelector/MultiSelector.test.tsx +1 -35
  303. package/src/MultiSelector/__tests__/MultiSelector.listbox.a11y.test.tsx +128 -0
  304. package/src/NumberInput/NumberInput.tsx +6 -1
  305. package/src/Outline/Outline.doc.mjs +7 -5
  306. package/src/Outline/Outline.spec.md +1 -1
  307. package/src/Outline/index.ts +1 -0
  308. package/src/Outline/modules/parseOutlineFromMarkdown.spec.md +142 -0
  309. package/src/Outline/parseOutlineFromMarkdown.ts +40 -10
  310. package/src/Outline/useOutlineFromMarkdown.ts +15 -3
  311. package/src/PowerSearch/PowerSearch.doc.mjs +2 -2
  312. package/src/PowerSearch/PowerSearchEditPopover.test.tsx +150 -1
  313. package/src/PowerSearch/PowerSearchEditPopover.tsx +51 -28
  314. package/src/ProgressBar/ProgressBar.test.tsx +29 -11
  315. package/src/ProgressBar/ProgressBar.tsx +59 -72
  316. package/src/RadioList/RadioList.doc.mjs +11 -0
  317. package/src/RadioList/RadioList.test.tsx +32 -0
  318. package/src/RadioList/RadioListItem.tsx +25 -1
  319. package/src/ScrollableArea/modules/useScrollableArea.spec.md +50 -22
  320. package/src/SegmentedControl/SegmentedControl.doc.mjs +2 -2
  321. package/src/SegmentedControl/SegmentedControl.test.tsx +31 -0
  322. package/src/SegmentedControl/SegmentedControlItem.tsx +6 -9
  323. package/src/Selector/Selector.doc.mjs +2 -2
  324. package/src/Selector/Selector.spec.md +51 -49
  325. package/src/Selector/Selector.test.tsx +61 -55
  326. package/src/Selector/Selector.tsx +23 -14
  327. package/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts +130 -0
  328. package/src/Selector/__tests__/Listbox.a11y.dom.ts +38 -0
  329. package/src/Selector/__tests__/Listbox.a11y.inventory.test.ts +63 -0
  330. package/src/Selector/__tests__/Listbox.a11y.known-failures.ts +37 -0
  331. package/src/Selector/__tests__/Listbox.a11y.states.ts +232 -0
  332. package/src/Selector/__tests__/Selector.listbox.a11y.test.tsx +121 -0
  333. package/src/SideNav/SideNav.doc.mjs +1 -1
  334. package/src/SideNav/SideNav.test.tsx +10 -0
  335. package/src/SideNav/SideNav.tsx +14 -2
  336. package/src/Slider/Slider.doc.mjs +17 -3
  337. package/src/Slider/Slider.test.tsx +221 -0
  338. package/src/Slider/Slider.tsx +40 -9
  339. package/src/Spinner/Spinner.test.tsx +4 -0
  340. package/src/Spinner/Spinner.tsx +31 -18
  341. package/src/Switch/Switch.doc.mjs +11 -0
  342. package/src/Switch/Switch.test.tsx +16 -0
  343. package/src/Switch/Switch.tsx +28 -0
  344. package/src/TabList/Tab.tsx +35 -7
  345. package/src/TabList/TabList.doc.mjs +11 -0
  346. package/src/TabList/TabList.spec.md +204 -0
  347. package/src/TabList/TabList.test.tsx +66 -0
  348. package/src/TabList/__tests__/Tabs.a11y.known-failures.ts +1 -34
  349. package/src/Table/Table.doc.mjs +1 -1
  350. package/src/Table/Table.spec.md +54 -40
  351. package/src/Table/Table.test.tsx +83 -10
  352. package/src/Table/Table.tsx +30 -22
  353. package/src/Table/__tests__/TableScroll.a11y.chromium.spec.ts +137 -0
  354. package/src/TextArea/TextArea.tsx +6 -1
  355. package/src/TextInput/TextInput.test.tsx +20 -1
  356. package/src/TextInput/TextInput.tsx +6 -1
  357. package/src/TimeInput/TimeInput.tsx +6 -1
  358. package/src/ToggleButton/ToggleButton.doc.mjs +3 -3
  359. package/src/ToggleButton/ToggleButton.test.tsx +299 -4
  360. package/src/ToggleButton/ToggleButton.tsx +26 -33
  361. package/src/ToggleButton/ToggleButtonGroup.doc.mjs +3 -3
  362. package/src/ToggleButton/__tests__/ToggleButton.a11y.chromium.spec.ts +209 -0
  363. package/src/Tokenizer/Tokenizer.spec.md +142 -75
  364. package/src/TreeList/TreeList.doc.mjs +3 -3
  365. package/src/TreeList/TreeList.spec.md +123 -75
  366. package/src/TreeList/TreeList.test.tsx +29 -0
  367. package/src/TreeList/TreeList.tsx +3 -0
  368. package/src/TreeList/TreeListItem.tsx +15 -1
  369. package/src/TreeList/TreeListTypes.ts +11 -1
  370. package/src/Typeahead/BaseTypeahead.spec.md +4 -3
  371. package/src/Typeahead/BaseTypeahead.tsx +21 -7
  372. package/src/Typeahead/Typeahead.test.tsx +53 -0
  373. package/src/__tests__/PressedState.a11y.chromium.spec.ts +813 -0
  374. package/src/__tests__/pressState.ts +93 -0
  375. package/src/hooks/scrollKeyboardDelegation.test.ts +155 -0
  376. package/src/hooks/scrollKeyboardDelegation.ts +233 -0
  377. package/src/hooks/useScrollableArea.doc.mjs +15 -3
  378. package/src/hooks/useScrollableArea.test.tsx +59 -1
  379. package/src/hooks/useScrollableArea.ts +34 -10
  380. package/src/inputFontFloor.test.ts +106 -0
  381. package/src/tailwind-theme.css +0 -6
  382. package/src/theme/generateThemeRules.test.ts +30 -0
  383. package/src/theme/generateThemeRules.ts +10 -0
  384. package/src/utils/interactionOverlay.stylex.ts +20 -0
@@ -0,0 +1,1877 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file remark.test.tsx
5
+ * @input Synchronous transform-only Remark plugins over the canonical Markdown tree
6
+ * @output Round-trip, rejection, diagnostic, rendering, and bundle-isolation coverage
7
+ * @position Compatibility evidence for the limited Remark profile in spec:AST-036
8
+ */
9
+
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import {renderToString} from 'react-dom/server';
13
+ import {render, screen} from '@testing-library/react';
14
+ import {describe, expect, expectTypeOf, it, vi} from 'vitest';
15
+ import {Markdown} from './Markdown';
16
+ import {parseInlineAst, parseMarkdown, parseMarkdownAst} from './parser';
17
+ import {createMarkdownPlugin} from './plugins';
18
+ import type {
19
+ MarkdownExtensionNode,
20
+ MarkdownPluginEntry,
21
+ MarkdownSyntaxPluginDefinition,
22
+ MarkdownTransformContext,
23
+ } from './plugins';
24
+ import type {MarkdownAstRoot} from './ast';
25
+ import type {MarkdownTransform} from './plugins';
26
+ import {createMarkdownRemarkTransform} from './remark';
27
+ import type {
28
+ MarkdownRemarkFile,
29
+ MarkdownRemarkPlugin,
30
+ MarkdownRemarkRoot,
31
+ } from './remark';
32
+ import {parseOutlineFromMarkdown} from '../Outline/parseOutlineFromMarkdown';
33
+
34
+ type MutableNode = {
35
+ type: string;
36
+ children?: MutableNode[];
37
+ [key: string]: unknown;
38
+ };
39
+
40
+ /** Minimal unist-style walk, matching how real Remark plugins traverse. */
41
+ function visit(node: MutableNode, visitor: (node: MutableNode) => void): void {
42
+ visitor(node);
43
+ if (Array.isArray(node.children)) {
44
+ for (const entry of [...node.children]) {
45
+ visit(entry, visitor);
46
+ }
47
+ }
48
+ }
49
+
50
+ function asTree(tree: MarkdownRemarkRoot): MutableNode {
51
+ return tree as unknown as MutableNode;
52
+ }
53
+
54
+ /** Reads a file key through the guard; the value itself is never used. */
55
+ function probe(file: MarkdownRemarkFile, key: string): void {
56
+ const record = file as unknown as Record<string, unknown>;
57
+ // A plain member access, so the Proxy sees an ordinary read.
58
+ void record[key];
59
+ }
60
+
61
+ /**
62
+ * A realistic transform-only plugin in Unified's attacher shape: it wraps a
63
+ * prose term in `strong` without touching code, link destinations, or any
64
+ * other protected value.
65
+ */
66
+ const remarkStrongTerm: MarkdownRemarkPlugin<[{term: string}]> =
67
+ ({term}) =>
68
+ (tree, file) => {
69
+ let matches = 0;
70
+ visit(asTree(tree), node => {
71
+ if (!Array.isArray(node.children) || node.type === 'strong') {
72
+ return;
73
+ }
74
+ node.children = node.children.flatMap(candidate => {
75
+ if (candidate.type !== 'text' || typeof candidate.value !== 'string') {
76
+ return [candidate];
77
+ }
78
+ const parts = candidate.value.split(term);
79
+ if (parts.length === 1) {
80
+ return [candidate];
81
+ }
82
+ matches += parts.length - 1;
83
+ return parts.flatMap((part, index) =>
84
+ index === 0
85
+ ? part === ''
86
+ ? []
87
+ : [{type: 'text', value: part}]
88
+ : [
89
+ {type: 'strong', children: [{type: 'text', value: term}]},
90
+ ...(part === '' ? [] : [{type: 'text', value: part}]),
91
+ ],
92
+ );
93
+ });
94
+ });
95
+ if (matches > 0) {
96
+ file.message(`wrapped ${matches} term(s)`);
97
+ }
98
+ };
99
+
100
+ /** A text-only rename, used to prove transformed heading identity. */
101
+ const remarkRenameTerm: MarkdownRemarkPlugin<[{from: string; to: string}]> =
102
+ ({from, to}) =>
103
+ tree => {
104
+ visit(asTree(tree), node => {
105
+ if (node.type === 'text' && typeof node.value === 'string') {
106
+ node.value = node.value.split(from).join(to);
107
+ }
108
+ });
109
+ };
110
+
111
+ const renameTermPlugin = createMarkdownPlugin({
112
+ name: 'remark-rename-term',
113
+ apiVersion: 1,
114
+ transform: createMarkdownRemarkTransform(remarkRenameTerm, {
115
+ from: 'Astryx',
116
+ to: 'Astryx Design',
117
+ }),
118
+ });
119
+
120
+ const removeFirstHeadingPlugin = createMarkdownPlugin({
121
+ name: 'remark-remove-first-heading',
122
+ apiVersion: 1,
123
+ transform: createMarkdownRemarkTransform(() => tree => {
124
+ const root = asTree(tree);
125
+ const headingIndex = root.children?.findIndex(
126
+ node => node.type === 'heading',
127
+ );
128
+ if (headingIndex != null && headingIndex >= 0) {
129
+ root.children?.splice(headingIndex, 1);
130
+ }
131
+ }),
132
+ });
133
+
134
+ const strongTermPlugin = createMarkdownPlugin({
135
+ name: 'remark-strong-term',
136
+ apiVersion: 1,
137
+ transform: createMarkdownRemarkTransform(remarkStrongTerm, {term: 'Astryx'}),
138
+ });
139
+
140
+ type NoteNode = MarkdownExtensionNode<
141
+ 'notes',
142
+ 'note',
143
+ {readonly body: string},
144
+ 'block'
145
+ >;
146
+
147
+ const notePlugin = createMarkdownPlugin<'notes', NoteNode>({
148
+ name: 'notes',
149
+ apiVersion: 1,
150
+ parseKey: 'v1',
151
+ syntax: {
152
+ block: [
153
+ {
154
+ startsWith: [':::note'],
155
+ maxSpan: 200,
156
+ tokenize({source, offset, end, isFinal}) {
157
+ const close = source.indexOf('\n:::', offset + 7);
158
+ if (close < 0 || close + 4 > end) {
159
+ return isFinal ? {status: 'no-match'} : {status: 'defer'};
160
+ }
161
+ return {
162
+ status: 'match',
163
+ end: close + 4,
164
+ node: {
165
+ type: 'extension',
166
+ plugin: 'notes',
167
+ name: 'note',
168
+ display: 'block',
169
+ data: {body: source.slice(offset + 7, close).trim()},
170
+ },
171
+ };
172
+ },
173
+ },
174
+ ],
175
+ },
176
+ renderers: {
177
+ note: {
178
+ render: ({node}) => <aside data-testid="note">{node.data.body}</aside>,
179
+ toText: node => node.data.body,
180
+ },
181
+ },
182
+ } satisfies MarkdownSyntaxPluginDefinition<'notes', NoteNode>);
183
+
184
+ function deepFreeze<T>(value: T, seen = new Set<object>()): T {
185
+ if (value != null && typeof value === 'object' && !seen.has(value)) {
186
+ seen.add(value);
187
+ for (const nested of Object.values(value)) {
188
+ deepFreeze(nested, seen);
189
+ }
190
+ Object.freeze(value);
191
+ }
192
+ return value;
193
+ }
194
+
195
+ interface RunResult {
196
+ readonly root: MarkdownAstRoot<MarkdownExtensionNode>;
197
+ readonly result: MarkdownAstRoot<MarkdownExtensionNode>;
198
+ readonly reports: string[];
199
+ }
200
+
201
+ function runAdapter(
202
+ source: string,
203
+ plugin: MarkdownRemarkPlugin<[]>,
204
+ options: {
205
+ display?: 'inline' | 'block';
206
+ sourceIds?: ReadonlySet<string>;
207
+ plugins?: ReadonlyArray<MarkdownPluginEntry>;
208
+ } = {},
209
+ ): RunResult {
210
+ const display = options.display ?? 'block';
211
+ const parsed =
212
+ display === 'inline'
213
+ ? ({
214
+ type: 'root',
215
+ children: [
216
+ {
217
+ type: 'paragraph',
218
+ children: parseInlineAst(source, options.sourceIds),
219
+ },
220
+ ],
221
+ } as MarkdownAstRoot<MarkdownExtensionNode>)
222
+ : (parseMarkdownAst(source, {
223
+ sourceRanges: true,
224
+ sourceIds: options.sourceIds,
225
+ plugins: options.plugins ?? [],
226
+ }) as MarkdownAstRoot<MarkdownExtensionNode>);
227
+ const root = deepFreeze(parsed);
228
+ const reports: string[] = [];
229
+ const context: MarkdownTransformContext = {
230
+ source,
231
+ isFinal: true,
232
+ display,
233
+ report: message => reports.push(message),
234
+ };
235
+ const result = createMarkdownRemarkTransform(plugin)(root, context);
236
+ return {root, result, reports};
237
+ }
238
+
239
+ const everyNodeSource = [
240
+ '# Heading with `code` and *emphasis*',
241
+ '',
242
+ 'Prose with **strong**, ~~struck~~, [a link](/docs), ![alt](/logo.png), a',
243
+ 'citation [ref], $x + y$ inline math, and a hard break. ',
244
+ 'Second line.',
245
+ '',
246
+ '![standalone](/hero.png)',
247
+ '',
248
+ '> Quoted prose',
249
+ '>',
250
+ '> - nested item',
251
+ '',
252
+ '1) First',
253
+ '2) Second',
254
+ '',
255
+ '- [ ] open task',
256
+ '- [x] done task',
257
+ '',
258
+ '| Left | Right |',
259
+ '| :--- | ----: |',
260
+ '| a | b |',
261
+ '',
262
+ '```ts title="example.ts" {1,3}',
263
+ 'const value = 1;',
264
+ '```',
265
+ '',
266
+ '```',
267
+ 'no language, no meta',
268
+ '```',
269
+ '',
270
+ '$$',
271
+ 'a^2 + b^2',
272
+ '$$',
273
+ '',
274
+ '---',
275
+ '',
276
+ ':::note',
277
+ 'An owned extension node.',
278
+ ':::',
279
+ ].join('\n');
280
+
281
+ describe('Remark adapter — supported round trip', () => {
282
+ it('returns the identical document when every supported node is untouched', () => {
283
+ const root = deepFreeze(
284
+ parseMarkdownAst(everyNodeSource, {
285
+ math: true,
286
+ sourceRanges: true,
287
+ sourceIds: new Set(['ref']),
288
+ plugins: [notePlugin],
289
+ }) as MarkdownAstRoot<MarkdownExtensionNode>,
290
+ );
291
+ const reports: string[] = [];
292
+ const transform = createMarkdownRemarkTransform(() => () => undefined);
293
+ const result = transform(root, {
294
+ source: everyNodeSource,
295
+ isFinal: true,
296
+ display: 'block',
297
+ report: message => reports.push(message),
298
+ });
299
+
300
+ // Identity, not just equality: every node round-tripped without loss, so
301
+ // the adapter reuses the canonical tree instead of allocating a copy.
302
+ expect(result).toBe(root);
303
+ expect(reports).toEqual([]);
304
+ });
305
+
306
+ it('exposes the supported subset as a mutable mdast tree', () => {
307
+ const seen: string[] = [];
308
+ const codeNodes: MutableNode[] = [];
309
+ runAdapter(everyNodeSource, () => tree => {
310
+ visit(asTree(tree), node => {
311
+ seen.push(node.type);
312
+ if (node.type === 'code') {
313
+ codeNodes.push(node);
314
+ }
315
+ });
316
+ });
317
+
318
+ expect(new Set(seen)).toEqual(
319
+ new Set([
320
+ 'root',
321
+ 'heading',
322
+ 'paragraph',
323
+ 'text',
324
+ 'inlineCode',
325
+ 'emphasis',
326
+ 'strong',
327
+ 'delete',
328
+ 'link',
329
+ 'image',
330
+ 'break',
331
+ 'blockquote',
332
+ 'list',
333
+ 'listItem',
334
+ 'table',
335
+ 'tableRow',
336
+ 'tableCell',
337
+ 'code',
338
+ 'thematicBreak',
339
+ ]),
340
+ );
341
+ // MDAST spelling on the way in: `meta` is the authored info string, or
342
+ // `null` when the fence had none.
343
+ expect(codeNodes[0]).toMatchObject({
344
+ type: 'code',
345
+ lang: 'ts',
346
+ meta: 'title="example.ts" {1,3}',
347
+ value: 'const value = 1;',
348
+ });
349
+ expect(codeNodes[1]).toMatchObject({
350
+ type: 'code',
351
+ lang: null,
352
+ meta: null,
353
+ value: 'no language, no meta',
354
+ });
355
+ });
356
+
357
+ it('applies a compatible transform and keeps protected contexts literal', () => {
358
+ const blocks = parseMarkdown(
359
+ 'Astryx ships `Astryx` and [Astryx](/astryx).',
360
+ {plugins: [strongTermPlugin]},
361
+ );
362
+
363
+ expect(blocks).toMatchObject([
364
+ {
365
+ type: 'paragraph',
366
+ children: [
367
+ {type: 'bold', children: [{type: 'text', content: 'Astryx'}]},
368
+ {type: 'text', content: ' ships '},
369
+ {type: 'code', content: 'Astryx'},
370
+ {type: 'text', content: ' and '},
371
+ {
372
+ type: 'link',
373
+ href: '/astryx',
374
+ children: [
375
+ {type: 'bold', children: [{type: 'text', content: 'Astryx'}]},
376
+ ],
377
+ },
378
+ {type: 'text', content: '.'},
379
+ ],
380
+ },
381
+ ]);
382
+ });
383
+
384
+ it('leaves fenced code copyable and renders adapted output in the browser and on the server', () => {
385
+ const source = 'Astryx docs\n\n```txt\nAstryx stays literal\n```';
386
+ render(<Markdown plugins={[strongTermPlugin]}>{source}</Markdown>);
387
+
388
+ expect(screen.getByText('Astryx')).toHaveRole('strong');
389
+ expect(screen.getByText('Astryx stays literal')).toBeInTheDocument();
390
+
391
+ const html = renderToString(
392
+ <Markdown plugins={[strongTermPlugin]}>{source}</Markdown>,
393
+ );
394
+ expect(html).toContain('<strong');
395
+ expect(html).toContain('Astryx stays literal');
396
+ });
397
+
398
+ it('shares transformed heading identity with Outline', () => {
399
+ const source = '# Astryx release\n\nBody.';
400
+ render(<Markdown plugins={[renameTermPlugin]}>{source}</Markdown>);
401
+ const [item] = parseOutlineFromMarkdown(source, {
402
+ plugins: [renameTermPlugin],
403
+ });
404
+
405
+ expect(item).toMatchObject({label: 'Astryx Design release', level: 1});
406
+ expect(screen.getByRole('heading', {level: 1})).toHaveTextContent(
407
+ 'Astryx Design release',
408
+ );
409
+ expect(screen.getByRole('heading', {level: 1})).toHaveAttribute(
410
+ 'id',
411
+ item.id,
412
+ );
413
+ });
414
+
415
+ it('lets a transform remove a heading while Markdown and Outline keep surviving identity', () => {
416
+ const source = '# Removed\n\n## Kept\n\nBody.';
417
+ render(<Markdown plugins={[removeFirstHeadingPlugin]}>{source}</Markdown>);
418
+ const outline = parseOutlineFromMarkdown(source, {
419
+ plugins: [removeFirstHeadingPlugin],
420
+ });
421
+
422
+ expect(
423
+ screen.queryByRole('heading', {name: 'Removed'}),
424
+ ).not.toBeInTheDocument();
425
+ expect(outline).toHaveLength(1);
426
+ expect(outline[0]).toMatchObject({label: 'Kept', level: 2});
427
+ expect(
428
+ screen.getByRole('heading', {name: 'Kept', level: 2}),
429
+ ).toHaveAttribute('id', outline[0].id);
430
+ });
431
+
432
+ it('reports exactly one fixed diagnostic that cannot carry plugin text', () => {
433
+ // Every channel a plugin could speak through quotes the document.
434
+ const {reports} = runAdapter(
435
+ 'Astryx confidential-token',
436
+ () => (tree, file) => {
437
+ file.message('saw confidential-token at line 1');
438
+ file.message('saw confidential-token again');
439
+ asTree(tree).children?.push({type: 'html', value: '<b>x</b>'});
440
+ },
441
+ );
442
+
443
+ expect(reports).toEqual([
444
+ 'Remark adapter: raw HTML has no Astryx representation',
445
+ ]);
446
+ expect(reports.join(' ')).not.toContain('confidential-token');
447
+ });
448
+
449
+ it('keeps a plugin-authored failure reason off the diagnostic', () => {
450
+ const {reports} = runAdapter(
451
+ 'Astryx confidential-token',
452
+ () => (_t, file) => file.fail('cannot handle "confidential-token"'),
453
+ );
454
+
455
+ expect(reports).toEqual([
456
+ 'Remark adapter: the plugin reported the document as unsupported',
457
+ ]);
458
+ expect(reports.join(' ')).not.toContain('confidential-token');
459
+ });
460
+
461
+ it('keeps a thrown error message off the diagnostic', () => {
462
+ const {reports} = runAdapter('Astryx confidential-token', () => () => {
463
+ throw new Error('failed parsing "confidential-token"');
464
+ });
465
+
466
+ expect(reports).toEqual(['Remark adapter: the plugin threw an error']);
467
+ expect(reports.join(' ')).not.toContain('confidential-token');
468
+ });
469
+
470
+ it('keeps a successful run quiet even when the plugin records messages', () => {
471
+ const {reports} = runAdapter(
472
+ 'Astryx prose',
473
+ () => (_tree, file) => void file.message('informational'),
474
+ );
475
+
476
+ expect(reports).toEqual([]);
477
+ });
478
+
479
+ it('makes provenance tamper-proof rather than trusting the plugin', () => {
480
+ let markers: symbol[] = [];
481
+ runAdapter('Prose.', () => tree => {
482
+ const paragraph = asTree(tree).children?.[0] ?? {};
483
+ markers = Object.getOwnPropertySymbols(paragraph);
484
+ for (const marker of markers) {
485
+ const descriptor = Object.getOwnPropertyDescriptor(paragraph, marker);
486
+ expect(descriptor).toMatchObject({
487
+ configurable: false,
488
+ writable: false,
489
+ });
490
+ }
491
+ });
492
+
493
+ expect(markers).toHaveLength(1);
494
+ });
495
+
496
+ it('gives every invocation a fresh tree and isolated file data', () => {
497
+ const observed: unknown[] = [];
498
+ const transform = createMarkdownRemarkTransform(
499
+ () => (tree: MarkdownRemarkRoot, file: MarkdownRemarkFile) => {
500
+ observed.push(file.data.runs);
501
+ file.data.runs = 'first';
502
+ asTree(tree).children?.push({type: 'thematicBreak'});
503
+ },
504
+ );
505
+ const source = 'Body text';
506
+ const root = deepFreeze(
507
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
508
+ );
509
+ const context: MarkdownTransformContext = {
510
+ source,
511
+ isFinal: true,
512
+ display: 'block',
513
+ report: () => {},
514
+ };
515
+
516
+ const first = transform(root, context);
517
+ const second = transform(root, context);
518
+
519
+ expect(observed).toEqual([undefined, undefined]);
520
+ expect(root.children).toHaveLength(1);
521
+ expect(first.children).toHaveLength(2);
522
+ expect(second).toEqual(first);
523
+ });
524
+ });
525
+
526
+ describe('Remark adapter — fenced code metadata', () => {
527
+ const fenceSource = [
528
+ '```ts title="example.ts" {1,3}',
529
+ 'const value = 1;',
530
+ '```',
531
+ '',
532
+ '```',
533
+ 'bare fence',
534
+ '```',
535
+ ].join('\n');
536
+
537
+ it('round-trips a parsed fence untouched, metadata included', () => {
538
+ const root = deepFreeze(
539
+ parseMarkdownAst(fenceSource, {
540
+ sourceRanges: true,
541
+ }) as MarkdownAstRoot<MarkdownExtensionNode>,
542
+ );
543
+ const reports: string[] = [];
544
+ const result = createMarkdownRemarkTransform(() => () => undefined)(root, {
545
+ source: fenceSource,
546
+ isFinal: true,
547
+ display: 'block',
548
+ report: message => reports.push(message),
549
+ });
550
+
551
+ // Identity: a dropped or re-added `meta` would rebuild the node.
552
+ expect(result).toBe(root);
553
+ expect(reports).toEqual([]);
554
+ });
555
+
556
+ it('keeps the released code projection for a fence it rewrites', () => {
557
+ const blocks = parseMarkdown(fenceSource, {
558
+ plugins: [
559
+ createMarkdownPlugin({
560
+ name: 'uppercase-code',
561
+ apiVersion: 1,
562
+ transform: createMarkdownRemarkTransform(() => tree => {
563
+ mutateFirst(tree, 'code', node => {
564
+ node.value = String(node.value).toUpperCase();
565
+ });
566
+ }),
567
+ }),
568
+ ],
569
+ });
570
+
571
+ // The rewritten node keeps lang, meta, and the released language
572
+ // projection the renderer reads.
573
+ expect(blocks[0]).toMatchObject({
574
+ type: 'codeblock',
575
+ language: 'ts',
576
+ content: 'CONST VALUE = 1;',
577
+ });
578
+ expect(blocks[1]).toMatchObject({
579
+ type: 'codeblock',
580
+ content: 'bare fence',
581
+ });
582
+ });
583
+
584
+ it('carries metadata into and back out of a transform', () => {
585
+ const seen: unknown[] = [];
586
+ const {result} = runAdapter(fenceSource, () => tree => {
587
+ visit(asTree(tree), node => {
588
+ if (node.type === 'code') {
589
+ seen.push(node.meta);
590
+ }
591
+ });
592
+ mutateFirst(tree, 'code', node => {
593
+ node.meta = 'title="renamed.ts"';
594
+ });
595
+ });
596
+
597
+ expect(seen).toEqual(['title="example.ts" {1,3}', null]);
598
+ expect(result.children[0]).toMatchObject({
599
+ type: 'code',
600
+ lang: 'ts',
601
+ meta: 'title="renamed.ts"',
602
+ });
603
+ });
604
+
605
+ it('rejects metadata Astryx cannot represent', () => {
606
+ const {root, result, reports} = runAdapter(
607
+ fenceSource,
608
+ () => tree =>
609
+ mutateFirst(tree, 'code', node => {
610
+ node.meta = {title: 'example.ts'};
611
+ }),
612
+ );
613
+
614
+ expect(result).toBe(root);
615
+ expect(reports).toEqual([
616
+ 'Remark adapter: a code node requires a string or null "meta"',
617
+ ]);
618
+ });
619
+ });
620
+
621
+ describe('Remark adapter — the constrained file fails closed', () => {
622
+ const unsupportedKeys = [
623
+ 'path',
624
+ 'cwd',
625
+ 'history',
626
+ 'basename',
627
+ 'dirname',
628
+ 'extname',
629
+ 'stem',
630
+ 'stored',
631
+ 'result',
632
+ 'map',
633
+ 'contents',
634
+ ];
635
+
636
+ it.each(unsupportedKeys)('rejects reading file.%s', key => {
637
+ const {root, result, reports} = runAdapter(
638
+ 'Prose.',
639
+ () => (_tree, file) => {
640
+ probe(file, key);
641
+ },
642
+ );
643
+
644
+ expect(result).toBe(root);
645
+ expect(reports).toEqual([
646
+ `Remark adapter: the file has no "${key}" in this profile`,
647
+ ]);
648
+ });
649
+
650
+ it('rejects reading an arbitrary key without echoing its name', () => {
651
+ const {reports} = runAdapter('Prose.', () => (_tree, file) => {
652
+ probe(file, 'secretProjectCodename');
653
+ });
654
+
655
+ expect(reports).toEqual([
656
+ 'Remark adapter: the file has no "unknown" in this profile',
657
+ ]);
658
+ expect(reports[0]).not.toContain('secretProjectCodename');
659
+ });
660
+
661
+ it.each(['path', 'cwd', 'value'])('rejects writing file.%s', key => {
662
+ const {root, result, reports} = runAdapter(
663
+ 'Prose.',
664
+ () => (_tree, file) => {
665
+ (file as unknown as Record<string, unknown>)[key] = 'anything';
666
+ },
667
+ );
668
+
669
+ expect(result).toBe(root);
670
+ expect(reports).toEqual([
671
+ `Remark adapter: the file's "${key}" cannot be assigned in this profile`,
672
+ ]);
673
+ });
674
+
675
+ it('rejects defining or deleting a file property', () => {
676
+ for (const mutate of [
677
+ (file: MarkdownRemarkFile) =>
678
+ Object.defineProperty(file, 'cwd', {value: '/'}),
679
+ (file: MarkdownRemarkFile) =>
680
+ delete (file as unknown as Record<string, unknown>).value,
681
+ ]) {
682
+ const {reports} = runAdapter('Prose.', () => (_tree, file) => {
683
+ mutate(file);
684
+ });
685
+ expect(reports).toEqual([
686
+ expect.stringMatching(/cannot be assigned in this profile$/),
687
+ ]);
688
+ }
689
+ });
690
+
691
+ it('lets a plugin feature-detect instead of failing', () => {
692
+ const detected: Record<string, boolean> = {};
693
+ const {root, result, reports} = runAdapter(
694
+ 'Prose.',
695
+ () => (_tree, file) => {
696
+ for (const key of ['cwd', 'path', 'data', 'message']) {
697
+ detected[key] = key in file;
698
+ }
699
+ expect(Object.keys(file).sort()).toEqual([
700
+ 'data',
701
+ 'fail',
702
+ 'message',
703
+ 'messages',
704
+ 'toString',
705
+ 'value',
706
+ ]);
707
+ },
708
+ );
709
+
710
+ expect(detected).toEqual({
711
+ cwd: false,
712
+ path: false,
713
+ data: true,
714
+ message: true,
715
+ });
716
+ expect(result).toBe(root);
717
+ expect(reports).toEqual([]);
718
+ });
719
+
720
+ it('serves the whole documented surface', () => {
721
+ const observed: Record<string, unknown> = {};
722
+ const {reports} = runAdapter('Document source.', () => (_tree, file) => {
723
+ observed.value = file.value;
724
+ observed.text = file.toString();
725
+ observed.data = file.data;
726
+ observed.messages = file.messages.length;
727
+ file.data.note = 'kept';
728
+ file.message('advisory');
729
+ observed.afterMessage = file.messages.length;
730
+ });
731
+
732
+ expect(observed).toEqual({
733
+ value: 'Document source.',
734
+ text: 'Document source.',
735
+ data: {note: 'kept'},
736
+ messages: 0,
737
+ afterMessage: 1,
738
+ });
739
+ expect(reports).toEqual([]);
740
+ });
741
+ });
742
+
743
+ describe('Remark adapter — a plugin cannot talk its way out of a failure', () => {
744
+ it('fails the run when the plugin swallows its own fail()', () => {
745
+ const {root, result, reports} = runAdapter(
746
+ 'Prose.',
747
+ () => (_tree, file) => {
748
+ try {
749
+ file.fail('cannot handle this document');
750
+ } catch {
751
+ // A plugin that carries on regardless has still declared the
752
+ // document unsupported.
753
+ }
754
+ },
755
+ );
756
+
757
+ expect(result).toBe(root);
758
+ expect(reports).toEqual([
759
+ 'Remark adapter: the plugin reported the document as unsupported',
760
+ ]);
761
+ });
762
+
763
+ it('keeps the verdict when the plugin swallows fail() and returns a tree', () => {
764
+ const {root, result, reports} = runAdapter('Prose.', () => (tree, file) => {
765
+ try {
766
+ file.fail('cannot handle this document');
767
+ } catch {
768
+ // ignored
769
+ }
770
+ return tree;
771
+ });
772
+
773
+ expect(result).toBe(root);
774
+ expect(reports).toEqual([
775
+ 'Remark adapter: the plugin reported the document as unsupported',
776
+ ]);
777
+ });
778
+
779
+ it('keeps the verdict when the plugin swallows fail() then throws its own error', () => {
780
+ const {result, root, reports} = runAdapter(
781
+ 'Prose.',
782
+ () => (_tree, file) => {
783
+ try {
784
+ file.fail('cannot handle this document');
785
+ } catch {
786
+ throw new Error('a different, friendlier-sounding message');
787
+ }
788
+ },
789
+ );
790
+
791
+ expect(result).toBe(root);
792
+ expect(reports).toEqual([
793
+ 'Remark adapter: the plugin reported the document as unsupported',
794
+ ]);
795
+ });
796
+
797
+ it('lets the original verdict stand when a plugin steals the rejection class', () => {
798
+ let stolen: (new (message: string) => Error) | undefined;
799
+ const {root, result, reports} = runAdapter(
800
+ 'Prose.',
801
+ () => (_tree, file) => {
802
+ try {
803
+ probe(file, 'cwd');
804
+ } catch (error) {
805
+ stolen = (error as Error).constructor as new (
806
+ message: string,
807
+ ) => Error;
808
+ }
809
+ // Carrying on after a guard fires does not clear the verdict.
810
+ },
811
+ );
812
+
813
+ expect(stolen).toBeTypeOf('function');
814
+ expect(result).toBe(root);
815
+ expect(reports).toEqual([
816
+ 'Remark adapter: the file has no "cwd" in this profile',
817
+ ]);
818
+ });
819
+
820
+ it('never echoes a rejection forged from the stolen class in a later run', () => {
821
+ let stolen: (new (message: string) => Error) | undefined;
822
+ const transform = createMarkdownRemarkTransform(
823
+ () => (_tree: MarkdownRemarkRoot, file: MarkdownRemarkFile) => {
824
+ if (stolen == null) {
825
+ try {
826
+ probe(file, 'cwd');
827
+ } catch (error) {
828
+ stolen = (error as Error).constructor as new (
829
+ message: string,
830
+ ) => Error;
831
+ }
832
+ return;
833
+ }
834
+ throw new stolen('the document is perfectly fine, carry on');
835
+ },
836
+ );
837
+ const reports: string[] = [];
838
+ const run = (): MarkdownAstRoot<MarkdownExtensionNode> => {
839
+ const source = 'Prose.';
840
+ const root = deepFreeze(
841
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
842
+ );
843
+ const result = transform(root, {
844
+ source,
845
+ isFinal: true,
846
+ display: 'block',
847
+ report: message => reports.push(message),
848
+ });
849
+ expect(result).toBe(root);
850
+ return result;
851
+ };
852
+
853
+ run();
854
+ run();
855
+
856
+ // The forged throw is an untracked instance, so only the generic reason
857
+ // is reported — its own wording never reaches the diagnostic.
858
+ expect(reports).toEqual([
859
+ 'Remark adapter: the file has no "cwd" in this profile',
860
+ 'Remark adapter: the plugin threw an error',
861
+ ]);
862
+ expect(reports.join(' ')).not.toContain('perfectly fine');
863
+ });
864
+
865
+ it('never echoes a rewritten message on a real rejection', () => {
866
+ const {reports} = runAdapter('Prose.', () => (_tree, file) => {
867
+ try {
868
+ probe(file, 'cwd');
869
+ } catch (error) {
870
+ (error as Error).message = 'everything is fine';
871
+ throw error;
872
+ }
873
+ });
874
+
875
+ expect(reports).toEqual([
876
+ 'Remark adapter: the file has no "cwd" in this profile',
877
+ ]);
878
+ });
879
+
880
+ it.each([
881
+ [
882
+ 'reading a prohibited key',
883
+ (file: MarkdownRemarkFile) => probe(file, 'cwd'),
884
+ ],
885
+ [
886
+ 'writing a prohibited key',
887
+ (file: MarkdownRemarkFile) => {
888
+ (file as unknown as Record<string, unknown>).cwd = '/tmp';
889
+ },
890
+ ],
891
+ [
892
+ 'defining a property',
893
+ (file: MarkdownRemarkFile) =>
894
+ Object.defineProperty(file, 'path', {value: '/tmp/doc.md'}),
895
+ ],
896
+ [
897
+ 'deleting a property',
898
+ (file: MarkdownRemarkFile) => {
899
+ delete (file as unknown as Record<string, unknown>).value;
900
+ },
901
+ ],
902
+ ])('fails the run when the plugin catches %s', (_name, trip) => {
903
+ const {root, result, reports} = runAdapter('Prose.', () => (tree, file) => {
904
+ try {
905
+ trip(file);
906
+ } catch {
907
+ // Swallowed, then the plugin carries on as if nothing happened.
908
+ }
909
+ return tree;
910
+ });
911
+
912
+ expect(result).toBe(root);
913
+ expect(reports).toHaveLength(1);
914
+ expect(reports[0]).toMatch(/^Remark adapter: the file\b/);
915
+ });
916
+
917
+ it('fails the attach when the plugin catches a processor access', () => {
918
+ const sneaky = function sneaky(this: {data(key: string): unknown}) {
919
+ try {
920
+ this.data('micromarkExtensions');
921
+ } catch {
922
+ // Swallowed; the attacher returns a perfectly ordinary transformer.
923
+ }
924
+ return (tree: MarkdownRemarkRoot) => tree;
925
+ };
926
+ const transform = createMarkdownRemarkTransform(
927
+ sneaky as unknown as MarkdownRemarkPlugin<[]>,
928
+ );
929
+ const source = 'Prose.';
930
+ const root = deepFreeze(
931
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
932
+ );
933
+ const reports: string[] = [];
934
+
935
+ expect(
936
+ transform(root, {
937
+ source,
938
+ isFinal: true,
939
+ display: 'block',
940
+ report: message => reports.push(message),
941
+ }),
942
+ ).toBe(root);
943
+ expect(reports).toEqual([
944
+ 'Remark adapter: processor registration is outside the adapter',
945
+ ]);
946
+ });
947
+
948
+ it('fails the run when the plugin catches a processor access at run time', () => {
949
+ const {root, result, reports} = runAdapter(
950
+ 'Prose.',
951
+ function attacher(this: {data(key: string): unknown}) {
952
+ // A real plugin closes over the processor at attach time and reaches
953
+ // for it later; the guard has to hold then too.
954
+ const data = this.data.bind(this);
955
+ return (tree: MarkdownRemarkRoot) => {
956
+ try {
957
+ data('micromarkExtensions');
958
+ } catch {
959
+ // Swallowed mid-transform.
960
+ }
961
+ return tree;
962
+ };
963
+ },
964
+ );
965
+
966
+ expect(result).toBe(root);
967
+ expect(reports).toEqual([
968
+ 'Remark adapter: processor registration is outside the adapter',
969
+ ]);
970
+ });
971
+
972
+ it('keeps the first verdict when a plugin catches a guard and then fails', () => {
973
+ const {reports} = runAdapter('Prose.', () => (_tree, file) => {
974
+ try {
975
+ probe(file, 'path');
976
+ } catch {
977
+ // ignored
978
+ }
979
+ file.fail('a different explanation');
980
+ });
981
+
982
+ expect(reports).toEqual([
983
+ 'Remark adapter: the file has no "path" in this profile',
984
+ ]);
985
+ });
986
+
987
+ it('rejects output when a hostile then accessor trips a guard late', () => {
988
+ // `then` is read after the transformer returns, so a guard that fires
989
+ // inside the accessor lands after the first sticky check. The validated
990
+ // output must still never be accepted.
991
+ const {root, result, reports} = runAdapter(
992
+ 'Prose.',
993
+ () => (tree: MarkdownRemarkRoot, file: MarkdownRemarkFile) => {
994
+ const hostile = asTree(tree) as unknown as Record<string, unknown>;
995
+ Object.defineProperty(hostile, 'then', {
996
+ configurable: true,
997
+ get() {
998
+ try {
999
+ probe(file, 'cwd');
1000
+ } catch {
1001
+ // Swallowed inside the accessor, mid-inspection.
1002
+ }
1003
+ return undefined;
1004
+ },
1005
+ });
1006
+ return tree;
1007
+ },
1008
+ );
1009
+
1010
+ expect(result).toBe(root);
1011
+ expect(reports).toEqual([
1012
+ 'Remark adapter: the file has no "cwd" in this profile',
1013
+ ]);
1014
+ });
1015
+
1016
+ it('rejects output when a guard fires while the result is being validated', () => {
1017
+ // A getter on a node the adapter reads during validation is the same
1018
+ // trap by another route: the refusal lands after every earlier check.
1019
+ const {root, result, reports} = runAdapter(
1020
+ 'Prose.',
1021
+ () => (tree: MarkdownRemarkRoot, file: MarkdownRemarkFile) => {
1022
+ const paragraph = asTree(tree).children?.[0] as unknown as Record<
1023
+ string,
1024
+ unknown
1025
+ >;
1026
+ let tripped = false;
1027
+ const actual = paragraph.children as unknown[];
1028
+ Object.defineProperty(paragraph, 'children', {
1029
+ configurable: true,
1030
+ get(): unknown[] {
1031
+ if (!tripped) {
1032
+ tripped = true;
1033
+ try {
1034
+ probe(file, 'path');
1035
+ } catch {
1036
+ // Swallowed during validation.
1037
+ }
1038
+ }
1039
+ return actual;
1040
+ },
1041
+ });
1042
+ return tree;
1043
+ },
1044
+ );
1045
+
1046
+ expect(result).toBe(root);
1047
+ expect(reports).toEqual([
1048
+ 'Remark adapter: the file has no "path" in this profile',
1049
+ ]);
1050
+ });
1051
+
1052
+ it('ignores a message a plugin marks fatal by hand', () => {
1053
+ const {root, result, reports} = runAdapter(
1054
+ 'Prose.',
1055
+ () => (_tree, file) => {
1056
+ const message = file.message('advisory');
1057
+ message.fatal = true;
1058
+ file.messages.push({
1059
+ reason: 'forged',
1060
+ fatal: true,
1061
+ place: null,
1062
+ ruleId: null,
1063
+ toString: () => 'forged',
1064
+ });
1065
+ },
1066
+ );
1067
+
1068
+ // A run that did not actually fail still succeeds, silently.
1069
+ expect(result).toBe(root);
1070
+ expect(reports).toEqual([]);
1071
+ });
1072
+ });
1073
+
1074
+ interface RejectionCase {
1075
+ readonly name: string;
1076
+ readonly plugin: MarkdownRemarkPlugin<[]>;
1077
+ readonly reason: RegExp;
1078
+ readonly source?: string;
1079
+ readonly display?: 'inline' | 'block';
1080
+ readonly sourceIds?: ReadonlySet<string>;
1081
+ readonly plugins?: ReadonlyArray<MarkdownPluginEntry>;
1082
+ }
1083
+
1084
+ const rejectionSource = '# Astryx heading\n\nProse with [a link](/docs).';
1085
+
1086
+ function mutateFirst(
1087
+ tree: MarkdownRemarkRoot,
1088
+ type: string,
1089
+ mutate: (node: MutableNode) => void,
1090
+ ): void {
1091
+ let done = false;
1092
+ visit(asTree(tree), node => {
1093
+ if (!done && node.type === type) {
1094
+ done = true;
1095
+ mutate(node);
1096
+ }
1097
+ });
1098
+ }
1099
+
1100
+ const rejectionCases: RejectionCase[] = [
1101
+ {
1102
+ name: 'an asynchronous transformer',
1103
+ plugin: () => async () => undefined,
1104
+ reason: /asynchronous transformer/,
1105
+ },
1106
+ {
1107
+ name: 'a callback-style transformer',
1108
+ plugin: () =>
1109
+ ((_tree: unknown, _file: unknown, _next: unknown) => undefined) as never,
1110
+ reason: /callback-style/,
1111
+ },
1112
+ {
1113
+ name: 'a parser or compiler plugin that registers processor state',
1114
+ plugin: function parserPlugin(this: {data(key: string): void}) {
1115
+ this.data('micromarkExtensions');
1116
+ return () => undefined;
1117
+ },
1118
+ reason: /processor registration/,
1119
+ },
1120
+ {
1121
+ name: 'a plugin that returns no transformer',
1122
+ plugin: () => undefined,
1123
+ reason: /transform-only plugin/,
1124
+ },
1125
+ {
1126
+ name: 'a plugin that returns a promise from its attacher',
1127
+ plugin: (() => ({then: () => undefined})) as never,
1128
+ reason: /asynchronous plugin/,
1129
+ },
1130
+ {
1131
+ name: 'raw HTML',
1132
+ plugin: () => tree =>
1133
+ void asTree(tree).children?.push({type: 'html', value: '<b>x</b>'}),
1134
+ reason: /raw HTML/,
1135
+ },
1136
+ {
1137
+ name: 'an unsupported node kind',
1138
+ plugin: () => tree =>
1139
+ void asTree(tree).children?.push({
1140
+ type: 'footnoteDefinition',
1141
+ identifier: 'a',
1142
+ children: [],
1143
+ }),
1144
+ reason: /"footnoteDefinition" is outside the supported MDAST subset/,
1145
+ },
1146
+ {
1147
+ name: 'a forged source position',
1148
+ plugin: () => tree =>
1149
+ void asTree(tree).children?.push({
1150
+ type: 'paragraph',
1151
+ children: [{type: 'text', value: 'forged'}],
1152
+ position: {start: {offset: 0}, end: {offset: 4}},
1153
+ }),
1154
+ reason: /cannot carry a source position/,
1155
+ },
1156
+ {
1157
+ name: 'a shifted source position',
1158
+ plugin: () => tree =>
1159
+ mutateFirst(tree, 'paragraph', node => {
1160
+ node.position = {start: {offset: 999}, end: {offset: 1200}};
1161
+ }),
1162
+ reason: /position must stay exactly as Core authored it/,
1163
+ },
1164
+ {
1165
+ name: 'a shifted line or column on an unchanged offset',
1166
+ plugin: () => tree =>
1167
+ mutateFirst(tree, 'paragraph', node => {
1168
+ const position = node.position as {
1169
+ start: {offset: number};
1170
+ end: {offset: number};
1171
+ };
1172
+ node.position = {
1173
+ start: {line: 99, column: 1, offset: position.start.offset},
1174
+ end: {line: 99, column: 9, offset: position.end.offset},
1175
+ };
1176
+ }),
1177
+ reason: /position must stay exactly as Core authored it/,
1178
+ },
1179
+ {
1180
+ name: 'a removed source position',
1181
+ plugin: () => tree =>
1182
+ mutateFirst(tree, 'paragraph', node => {
1183
+ delete node.position;
1184
+ }),
1185
+ reason: /position must stay exactly as Core authored it/,
1186
+ },
1187
+ {
1188
+ name: 'provenance rebuilt from a copied position',
1189
+ plugin: () => tree => {
1190
+ const root = asTree(tree);
1191
+ const paragraph = root.children?.find(node => node.type === 'paragraph');
1192
+ root.children = root.children?.map(node =>
1193
+ node === paragraph
1194
+ ? {
1195
+ type: 'paragraph',
1196
+ position: paragraph.position,
1197
+ children: [{type: 'text', value: 'rebuilt'}],
1198
+ }
1199
+ : node,
1200
+ );
1201
+ },
1202
+ reason: /cannot carry a source position/,
1203
+ },
1204
+
1205
+ {
1206
+ name: 'a changed source heading depth',
1207
+ plugin: () => tree =>
1208
+ mutateFirst(tree, 'heading', node => {
1209
+ node.depth = 4;
1210
+ }),
1211
+ reason: /heading's depth cannot change/,
1212
+ },
1213
+ {
1214
+ name: 'a retyped source node',
1215
+ plugin: () => tree =>
1216
+ mutateFirst(tree, 'paragraph', node => {
1217
+ node.type = 'blockquote';
1218
+ }),
1219
+ reason: /cannot be retyped/,
1220
+ },
1221
+ {
1222
+ name: 'a duplicated source node',
1223
+ plugin: () => tree => {
1224
+ const root = asTree(tree);
1225
+ const first = root.children?.[0];
1226
+ if (first != null) {
1227
+ root.children?.push(first);
1228
+ }
1229
+ },
1230
+ reason: /cannot be duplicated/,
1231
+ },
1232
+ {
1233
+ name: 'an authored Astryx extension node',
1234
+ plugin: () => tree =>
1235
+ void asTree(tree).children?.push({
1236
+ type: 'extension',
1237
+ plugin: 'notes',
1238
+ name: 'note',
1239
+ display: 'block',
1240
+ data: {body: 'forged'},
1241
+ }),
1242
+ reason: /"extension" node cannot be authored or changed/,
1243
+ },
1244
+ {
1245
+ name: 'a rewritten Astryx citation',
1246
+ source: 'Prose with a citation [ref].',
1247
+ sourceIds: new Set(['ref']),
1248
+ plugin: () => tree =>
1249
+ mutateFirst(tree, 'citation', node => {
1250
+ node.sourceId = 'other';
1251
+ }),
1252
+ reason: /"citation" node cannot be authored or changed/,
1253
+ },
1254
+ {
1255
+ name: "an edited Astryx extension node's data",
1256
+ source: ':::note\nOwned body.\n:::',
1257
+ plugins: [notePlugin],
1258
+ plugin: () => tree =>
1259
+ mutateFirst(tree, 'extension', node => {
1260
+ node.data = {body: 'rewritten'};
1261
+ }),
1262
+ reason: /"extension" node cannot be authored or changed/,
1263
+ },
1264
+ {
1265
+ name: "an edited Astryx extension node's authored source",
1266
+ source: ':::note\nOwned body.\n:::',
1267
+ plugins: [notePlugin],
1268
+ plugin: () => tree =>
1269
+ mutateFirst(tree, 'extension', node => {
1270
+ node.source = ':::note\nforged\n:::';
1271
+ }),
1272
+ reason: /"extension" node cannot be authored or changed/,
1273
+ },
1274
+ {
1275
+ name: 'a raw-markup data channel',
1276
+ plugin: () => tree =>
1277
+ mutateFirst(tree, 'paragraph', node => {
1278
+ node.data = {hName: 'section'};
1279
+ }),
1280
+ reason: /raw-markup data channel "hName"/,
1281
+ },
1282
+ {
1283
+ name: 'unrepresentable node data',
1284
+ plugin: () => tree =>
1285
+ mutateFirst(tree, 'paragraph', node => {
1286
+ node.data = {render: () => null};
1287
+ }),
1288
+ reason: /data must be finite JSON-like/,
1289
+ },
1290
+ {
1291
+ name: 'unrepresentable file data',
1292
+ plugin: () => (_tree, file) => {
1293
+ file.data.cache = () => null;
1294
+ },
1295
+ reason: /file data must be finite JSON-like/,
1296
+ },
1297
+ {
1298
+ name: 'non-string fence metadata',
1299
+ source: '```ts\nconst a = 1;\n```',
1300
+ plugin: () => tree =>
1301
+ mutateFirst(tree, 'code', node => {
1302
+ node.meta = 42;
1303
+ }),
1304
+ reason: /requires a string or null "meta"/,
1305
+ },
1306
+ {
1307
+ name: 'an unrepresentable link title',
1308
+ plugin: () => tree =>
1309
+ mutateFirst(tree, 'link', node => {
1310
+ node.title = 'Docs';
1311
+ }),
1312
+ reason: /"title" has no Astryx representation/,
1313
+ },
1314
+ {
1315
+ name: 'an unsupported field on a supported node',
1316
+ plugin: () => tree =>
1317
+ mutateFirst(tree, 'paragraph', node => {
1318
+ node.hProperties = {className: 'x'};
1319
+ }),
1320
+ reason: /unsupported field "hProperties"/,
1321
+ },
1322
+ {
1323
+ name: 'a rejected link destination',
1324
+ plugin: () => tree =>
1325
+ mutateFirst(tree, 'link', node => {
1326
+ node.url = 'javascript:alert(1)';
1327
+ }),
1328
+ reason: /rejected by the navigation owner/,
1329
+ },
1330
+ {
1331
+ name: 'an image without its text alternative',
1332
+ source: '![alt](/logo.png)',
1333
+ plugin: () => tree =>
1334
+ mutateFirst(tree, 'image', node => {
1335
+ node.alt = null;
1336
+ }),
1337
+ reason: /requires its text alternative/,
1338
+ },
1339
+ {
1340
+ name: 'invalid built-in structure',
1341
+ plugin: () => tree =>
1342
+ mutateFirst(tree, 'paragraph', node => {
1343
+ node.children?.push({type: 'thematicBreak'});
1344
+ }),
1345
+ reason: /cannot be a child of a "paragraph" node/,
1346
+ },
1347
+ {
1348
+ name: 'a nested link',
1349
+ plugin: () => tree =>
1350
+ mutateFirst(tree, 'link', node => {
1351
+ node.children = [
1352
+ {type: 'link', url: '/inner', title: null, children: []},
1353
+ ];
1354
+ }),
1355
+ reason: /nested inside another link/,
1356
+ },
1357
+ {
1358
+ name: 'a loose list item',
1359
+ source: '- one\n- two',
1360
+ plugin: () => tree =>
1361
+ mutateFirst(tree, 'listItem', node => {
1362
+ node.spread = true;
1363
+ }),
1364
+ reason: /loose list item/,
1365
+ },
1366
+ {
1367
+ name: 'a ragged transformed table',
1368
+ source: '| a | b |\n| - | - |\n| c | d |',
1369
+ plugin: () => tree =>
1370
+ mutateFirst(tree, 'tableRow', node => {
1371
+ node.children?.pop();
1372
+ }),
1373
+ reason: /ragged rows/,
1374
+ },
1375
+ {
1376
+ name: 'block output from an inline entry point',
1377
+ display: 'inline',
1378
+ source: 'Inline Astryx prose',
1379
+ plugin: () => tree =>
1380
+ void asTree(tree).children?.push({
1381
+ type: 'paragraph',
1382
+ children: [{type: 'text', value: 'extra'}],
1383
+ }),
1384
+ reason: /one paragraph of phrasing content/,
1385
+ },
1386
+ {
1387
+ name: 'a transformer that throws',
1388
+ plugin: () => () => {
1389
+ throw new Error('boom');
1390
+ },
1391
+ reason: /^Remark adapter: the plugin threw an error$/,
1392
+ },
1393
+ {
1394
+ name: 'a transformer that fails the file',
1395
+ plugin: () => (_tree, file) => file.fail('unsupported document'),
1396
+ reason: /^Remark adapter: the plugin reported the document as unsupported$/,
1397
+ },
1398
+ {
1399
+ name: 'a transformer that returns a non-root node',
1400
+ plugin: () => () => ({type: 'paragraph', children: []}) as never,
1401
+ reason: /cannot be a child of|must return the document root|unsupported/,
1402
+ },
1403
+ ];
1404
+
1405
+ describe('Remark adapter — rejection matrix', () => {
1406
+ it.each(rejectionCases)(
1407
+ 'keeps the last valid document after $name',
1408
+ ({plugin, reason, source, display, sourceIds, plugins}) => {
1409
+ const {root, result, reports} = runAdapter(
1410
+ source ?? rejectionSource,
1411
+ plugin,
1412
+ {display, sourceIds, plugins},
1413
+ );
1414
+
1415
+ expect(result).toBe(root);
1416
+ expect(reports).toHaveLength(1);
1417
+ expect(reports[0]).toMatch(/^Remark adapter: /);
1418
+ expect(reports[0]).toMatch(reason);
1419
+ // Diagnostics name contracts, never document source.
1420
+ expect(reports[0]).not.toContain('Astryx heading');
1421
+ },
1422
+ );
1423
+
1424
+ it('renders readable source after a rejected transform', () => {
1425
+ const warning = vi.spyOn(console, 'warn').mockImplementation(() => {});
1426
+ const broken = createMarkdownPlugin({
1427
+ name: 'broken-remark',
1428
+ apiVersion: 1,
1429
+ transform: createMarkdownRemarkTransform(() => tree => {
1430
+ asTree(tree).children?.push({
1431
+ type: 'html',
1432
+ value: '<script>x</script>',
1433
+ });
1434
+ }),
1435
+ });
1436
+
1437
+ render(
1438
+ <Markdown plugins={[broken]}>
1439
+ {'# Still readable\n\nProse survives.'}
1440
+ </Markdown>,
1441
+ );
1442
+
1443
+ expect(screen.getByRole('heading', {level: 1})).toHaveTextContent(
1444
+ 'Still readable',
1445
+ );
1446
+ expect(screen.getByText('Prose survives.')).toBeInTheDocument();
1447
+ expect(document.body.innerHTML).not.toContain('<script>');
1448
+ expect(warning).toHaveBeenCalled();
1449
+ warning.mockRestore();
1450
+ });
1451
+
1452
+ it('keeps later plugins running after one adapted plugin fails', () => {
1453
+ const warning = vi.spyOn(console, 'warn').mockImplementation(() => {});
1454
+ const failing = createMarkdownPlugin({
1455
+ name: 'failing-remark',
1456
+ apiVersion: 1,
1457
+ transform: createMarkdownRemarkTransform(() => () => {
1458
+ throw new Error('boom');
1459
+ }),
1460
+ });
1461
+
1462
+ const blocks = parseMarkdown('Astryx ships', {
1463
+ plugins: [failing, strongTermPlugin],
1464
+ });
1465
+
1466
+ expect(blocks).toMatchObject([
1467
+ {
1468
+ type: 'paragraph',
1469
+ children: [
1470
+ {type: 'bold', children: [{type: 'text', content: 'Astryx'}]},
1471
+ {type: 'text', content: ' ships'},
1472
+ ],
1473
+ },
1474
+ ]);
1475
+ warning.mockRestore();
1476
+ });
1477
+
1478
+ it('rejects provenance smuggled in from another document', () => {
1479
+ let stashed: MutableNode | undefined;
1480
+ const transform = createMarkdownRemarkTransform(() => tree => {
1481
+ const root = asTree(tree);
1482
+ if (stashed == null) {
1483
+ stashed = root.children?.[0];
1484
+ return;
1485
+ }
1486
+ root.children?.push(stashed);
1487
+ });
1488
+ const reports: string[] = [];
1489
+ const run = (source: string): MarkdownAstRoot<MarkdownExtensionNode> => {
1490
+ const root = deepFreeze(
1491
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1492
+ );
1493
+ const result = transform(root, {
1494
+ source,
1495
+ isFinal: true,
1496
+ display: 'block',
1497
+ report: message => reports.push(message),
1498
+ });
1499
+ expect(result).toBe(root);
1500
+ return result;
1501
+ };
1502
+
1503
+ run('First document.');
1504
+ run('Second document.');
1505
+
1506
+ expect(reports).toEqual([
1507
+ 'Remark adapter: a "paragraph" node carries forged provenance',
1508
+ ]);
1509
+ });
1510
+
1511
+ it('rejects a plugin value that is not a function', () => {
1512
+ expect(() =>
1513
+ createMarkdownRemarkTransform({} as unknown as MarkdownRemarkPlugin<[]>),
1514
+ ).toThrow(/plugin must be a function/);
1515
+ });
1516
+ });
1517
+
1518
+ /* ------------------------------------------------------------------ *
1519
+ * Compile fixture: a conventional Unified/Remark plugin type
1520
+ *
1521
+ * These declarations mirror `unified`'s own shapes without depending on the
1522
+ * package: an attacher bound to a processor, and a transformer that takes the
1523
+ * callback parameter and declares an asynchronous return union. Existing
1524
+ * typed plugins must type-check at the callsite; the run-time behavior for an
1525
+ * actual promise and for a callback-style transformer is asserted above.
1526
+ * ------------------------------------------------------------------ */
1527
+
1528
+ interface UnifiedPoint {
1529
+ line: number;
1530
+ column: number;
1531
+ offset?: number | undefined;
1532
+ }
1533
+
1534
+ interface UnifiedNode {
1535
+ type: string;
1536
+ children?: UnifiedNode[];
1537
+ value?: string;
1538
+ position?: {start: UnifiedPoint; end: UnifiedPoint} | undefined;
1539
+ data?: Record<string, unknown> | undefined;
1540
+ }
1541
+
1542
+ interface UnifiedRoot extends UnifiedNode {
1543
+ type: 'root';
1544
+ children: UnifiedNode[];
1545
+ }
1546
+
1547
+ interface UnifiedVFile {
1548
+ value: string | Uint8Array;
1549
+ data: Record<string, unknown>;
1550
+ cwd: string;
1551
+ message(reason: string | Error): {reason: string};
1552
+ fail(reason: string | Error): never;
1553
+ }
1554
+
1555
+ interface UnifiedProcessor {
1556
+ data(key: string): unknown;
1557
+ use(plugin: unknown): UnifiedProcessor;
1558
+ }
1559
+
1560
+ /* eslint-disable @typescript-eslint/no-invalid-void-type -- Unified's own
1561
+ transformer and attacher types include `void`; the fixture is only faithful
1562
+ if it keeps them. */
1563
+ type UnifiedTransformer = (
1564
+ tree: UnifiedRoot,
1565
+ file: UnifiedVFile,
1566
+ next: (error?: Error | null, tree?: UnifiedRoot) => undefined,
1567
+ ) => Promise<UnifiedRoot | undefined> | UnifiedRoot | undefined | void;
1568
+
1569
+ type UnifiedPlugin<Parameters extends unknown[] = []> = (
1570
+ this: UnifiedProcessor,
1571
+ ...parameters: Parameters
1572
+ ) => UnifiedTransformer | undefined | void;
1573
+ /* eslint-enable @typescript-eslint/no-invalid-void-type */
1574
+
1575
+ const remarkConventional: UnifiedPlugin<[{flag: boolean}?]> =
1576
+ options => tree => {
1577
+ if (options?.flag === true) {
1578
+ tree.children = [];
1579
+ }
1580
+ };
1581
+
1582
+ const remarkNoSettings: UnifiedPlugin = () => tree => tree;
1583
+
1584
+ describe('Remark adapter — conventional plugin types', () => {
1585
+ it('accepts a conventional Unified plugin at the callsite', () => {
1586
+ // Compile fixture: these calls failing to type-check is the regression.
1587
+ const withSettings = createMarkdownRemarkTransform(remarkConventional, {
1588
+ flag: false,
1589
+ });
1590
+ const withoutSettings = createMarkdownRemarkTransform(remarkNoSettings);
1591
+ const inlineAstryxPlugin = createMarkdownRemarkTransform(
1592
+ () => (tree, file) => {
1593
+ // The strict overload still types the tree and file for new plugins.
1594
+ expectTypeOf(tree).toEqualTypeOf<MarkdownRemarkRoot>();
1595
+ expectTypeOf(file).toEqualTypeOf<MarkdownRemarkFile>();
1596
+ return tree;
1597
+ },
1598
+ );
1599
+
1600
+ expectTypeOf(withSettings).toEqualTypeOf<MarkdownTransform<never>>();
1601
+ expectTypeOf(withoutSettings).toEqualTypeOf<MarkdownTransform<never>>();
1602
+ expectTypeOf(inlineAstryxPlugin).toEqualTypeOf<MarkdownTransform<never>>();
1603
+ expectTypeOf(createMarkdownRemarkTransform).parameter(0).not.toBeNever();
1604
+
1605
+ // A conventional plugin also runs: a no-op leaves the document identical.
1606
+ const source = 'Prose stays put.';
1607
+ const root = deepFreeze(
1608
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1609
+ );
1610
+ const reports: string[] = [];
1611
+ expect(
1612
+ withoutSettings(root, {
1613
+ source,
1614
+ isFinal: true,
1615
+ display: 'block',
1616
+ report: message => reports.push(message),
1617
+ }),
1618
+ ).toBe(root);
1619
+ expect(reports).toEqual([]);
1620
+ });
1621
+
1622
+ it('still rejects an actual promise from a conventional plugin', () => {
1623
+ const remarkAsync: UnifiedPlugin = () => async tree => tree;
1624
+ const transform = createMarkdownRemarkTransform(remarkAsync);
1625
+ const source = 'Prose stays put.';
1626
+ const root = deepFreeze(
1627
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1628
+ );
1629
+ const reports: string[] = [];
1630
+
1631
+ expect(
1632
+ transform(root, {
1633
+ source,
1634
+ isFinal: true,
1635
+ display: 'block',
1636
+ report: message => reports.push(message),
1637
+ }),
1638
+ ).toBe(root);
1639
+ expect(reports).toEqual([
1640
+ 'Remark adapter: an asynchronous transformer is outside the adapter',
1641
+ ]);
1642
+ });
1643
+ });
1644
+
1645
+ describe('Remark adapter — a refused promise is never left unhandled', () => {
1646
+ /** Collects unhandled rejections for the duration of `work`. */
1647
+ async function withUnhandledRejections(work: () => void): Promise<unknown[]> {
1648
+ const seen: unknown[] = [];
1649
+ const onUnhandled = (reason: unknown): void => {
1650
+ seen.push(reason);
1651
+ };
1652
+ process.on('unhandledRejection', onUnhandled);
1653
+ try {
1654
+ work();
1655
+ // Unhandled rejections are reported a macrotask later.
1656
+ await new Promise(resolve => setTimeout(resolve, 50));
1657
+ } finally {
1658
+ process.off('unhandledRejection', onUnhandled);
1659
+ }
1660
+ return seen;
1661
+ }
1662
+
1663
+ it('refuses an already-rejected transformer result without an unhandled rejection', async () => {
1664
+ const reports: string[] = [];
1665
+ const seen = await withUnhandledRejections(() => {
1666
+ const source = 'Astryx confidential-token';
1667
+ const root = deepFreeze(
1668
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1669
+ );
1670
+ const transform = createMarkdownRemarkTransform(
1671
+ () => () =>
1672
+ Promise.reject(
1673
+ new Error('failed on "confidential-token"'),
1674
+ ) as unknown as MarkdownRemarkRoot,
1675
+ );
1676
+ expect(
1677
+ transform(root, {
1678
+ source,
1679
+ isFinal: true,
1680
+ display: 'block',
1681
+ report: message => reports.push(message),
1682
+ }),
1683
+ ).toBe(root);
1684
+ });
1685
+
1686
+ expect(reports).toEqual([
1687
+ 'Remark adapter: an asynchronous transformer is outside the adapter',
1688
+ ]);
1689
+ expect(seen).toEqual([]);
1690
+ });
1691
+
1692
+ it('refuses a rejected attacher result without an unhandled rejection', async () => {
1693
+ const reports: string[] = [];
1694
+ const seen = await withUnhandledRejections(() => {
1695
+ const source = 'Astryx confidential-token';
1696
+ const root = deepFreeze(
1697
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1698
+ );
1699
+ const rejectingAttacher = async (): Promise<never> => {
1700
+ throw new Error('attach failed on "confidential-token"');
1701
+ };
1702
+ const transform = createMarkdownRemarkTransform(
1703
+ rejectingAttacher as unknown as MarkdownRemarkPlugin<[]>,
1704
+ );
1705
+ expect(
1706
+ transform(root, {
1707
+ source,
1708
+ isFinal: true,
1709
+ display: 'block',
1710
+ report: message => reports.push(message),
1711
+ }),
1712
+ ).toBe(root);
1713
+ });
1714
+
1715
+ expect(reports).toEqual([
1716
+ 'Remark adapter: an asynchronous plugin is outside the adapter',
1717
+ ]);
1718
+ expect(seen).toEqual([]);
1719
+ });
1720
+
1721
+ it('defuses a rejected promise even when a caught guard outranks it', async () => {
1722
+ // The ordering trap: the sticky verdict is reported, but the promise
1723
+ // must still be handled on the way past.
1724
+ const reports: string[] = [];
1725
+ const seen = await withUnhandledRejections(() => {
1726
+ const source = 'Astryx confidential-token';
1727
+ const root = deepFreeze(
1728
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1729
+ );
1730
+ const transform = createMarkdownRemarkTransform(
1731
+ () => (_tree: MarkdownRemarkRoot, file: MarkdownRemarkFile) => {
1732
+ try {
1733
+ probe(file, 'cwd');
1734
+ } catch {
1735
+ // Swallowed, then an async result on top of it.
1736
+ }
1737
+ return Promise.reject(
1738
+ new Error('async failure quoting confidential-token'),
1739
+ ) as unknown as MarkdownRemarkRoot;
1740
+ },
1741
+ );
1742
+ expect(
1743
+ transform(root, {
1744
+ source,
1745
+ isFinal: true,
1746
+ display: 'block',
1747
+ report: message => reports.push(message),
1748
+ }),
1749
+ ).toBe(root);
1750
+ });
1751
+
1752
+ // The caught guard is what gets reported...
1753
+ expect(reports).toEqual([
1754
+ 'Remark adapter: the file has no "cwd" in this profile',
1755
+ ]);
1756
+ // ...and the promise is still handled.
1757
+ expect(seen).toEqual([]);
1758
+ });
1759
+
1760
+ it('defuses a rejected promise even when the plugin also caught its own fail()', async () => {
1761
+ const reports: string[] = [];
1762
+ const seen = await withUnhandledRejections(() => {
1763
+ const source = 'Prose.';
1764
+ const root = deepFreeze(
1765
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1766
+ );
1767
+ const transform = createMarkdownRemarkTransform(
1768
+ () => (_tree: MarkdownRemarkRoot, file: MarkdownRemarkFile) => {
1769
+ try {
1770
+ file.fail('cannot handle "confidential-token"');
1771
+ } catch {
1772
+ // Swallowed.
1773
+ }
1774
+ return Promise.reject(
1775
+ new Error('and an async failure too'),
1776
+ ) as unknown as MarkdownRemarkRoot;
1777
+ },
1778
+ );
1779
+ expect(
1780
+ transform(root, {
1781
+ source,
1782
+ isFinal: true,
1783
+ display: 'block',
1784
+ report: message => reports.push(message),
1785
+ }),
1786
+ ).toBe(root);
1787
+ });
1788
+
1789
+ expect(reports).toEqual([
1790
+ 'Remark adapter: the plugin reported the document as unsupported',
1791
+ ]);
1792
+ expect(seen).toEqual([]);
1793
+ });
1794
+
1795
+ it('refuses a thenable whose then throws', async () => {
1796
+ const reports: string[] = [];
1797
+ const seen = await withUnhandledRejections(() => {
1798
+ const source = 'Prose.';
1799
+ const root = deepFreeze(
1800
+ parseMarkdownAst(source) as MarkdownAstRoot<MarkdownExtensionNode>,
1801
+ );
1802
+ const transform = createMarkdownRemarkTransform(
1803
+ () => () =>
1804
+ ({
1805
+ then() {
1806
+ throw new Error('hostile thenable');
1807
+ },
1808
+ }) as unknown as MarkdownRemarkRoot,
1809
+ );
1810
+ expect(
1811
+ transform(root, {
1812
+ source,
1813
+ isFinal: true,
1814
+ display: 'block',
1815
+ report: message => reports.push(message),
1816
+ }),
1817
+ ).toBe(root);
1818
+ });
1819
+
1820
+ expect(reports).toEqual([
1821
+ 'Remark adapter: an asynchronous transformer is outside the adapter',
1822
+ ]);
1823
+ expect(seen).toEqual([]);
1824
+ });
1825
+
1826
+ it('renders readable server output for a rejected async plugin, quietly', async () => {
1827
+ const asyncPlugin = createMarkdownPlugin({
1828
+ name: 'async-remark',
1829
+ apiVersion: 1,
1830
+ transform: createMarkdownRemarkTransform(
1831
+ () => () =>
1832
+ Promise.reject(
1833
+ new Error('server-side failure quoting confidential-token'),
1834
+ ) as unknown as MarkdownRemarkRoot,
1835
+ ),
1836
+ });
1837
+ const warning = vi.spyOn(console, 'warn').mockImplementation(() => {});
1838
+ let html = '';
1839
+ const seen = await withUnhandledRejections(() => {
1840
+ html = renderToString(
1841
+ <Markdown plugins={[asyncPlugin]}>
1842
+ {'# Still readable\n\nProse survives.'}
1843
+ </Markdown>,
1844
+ );
1845
+ });
1846
+
1847
+ expect(html).toContain('Still readable');
1848
+ expect(html).toContain('Prose survives.');
1849
+ expect(html).not.toContain('confidential-token');
1850
+ expect(seen).toEqual([]);
1851
+ warning.mockRestore();
1852
+ });
1853
+ });
1854
+
1855
+ describe('Remark adapter — optional by construction', () => {
1856
+ it('stays out of the Markdown entry point and parser modules', () => {
1857
+ for (const file of [
1858
+ 'index.ts',
1859
+ 'Markdown.tsx',
1860
+ 'parser.ts',
1861
+ 'plugins/protocol.ts',
1862
+ ]) {
1863
+ const contents = fs.readFileSync(path.join(__dirname, file), 'utf8');
1864
+ expect(contents).not.toContain('./remark');
1865
+ }
1866
+ });
1867
+
1868
+ it('is published as its own entry point', () => {
1869
+ const manifest = JSON.parse(
1870
+ fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf8'),
1871
+ ) as {exports: Record<string, {source?: string}>};
1872
+
1873
+ expect(manifest.exports['./Markdown/remark']).toMatchObject({
1874
+ source: './src/Markdown/remark.ts',
1875
+ });
1876
+ });
1877
+ });